Java 类org.hibernate.type.ManyToOneType 实例源码

项目:sakai    文件:ExtendedTimeQueries.java   
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public  List<ExtendedTime>  getEntriesForAss        (AssessmentBaseIfc ass) {
    log.debug("getEntriesForAss " + ass.getAssessmentBaseId());

    try {
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(QUERY_GET_ENTRIES_FOR_ASSESSMENT);
            q.setParameter(ASSESSMENT_ID, ass, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.AssessmentBaseData"));
            return q.list();
        };
        return (List<ExtendedTime>) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get Extended TimeEntries for Assessment: " + ass.getAssessmentBaseId(), e);
        return null;
    }
}
项目:sakai    文件:ExtendedTimeQueries.java   
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public  List<ExtendedTime>  getEntriesForPub        (PublishedAssessmentIfc pub) {
    log.debug("getEntriesForPub " + pub.getPublishedAssessmentId());

    try {
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(QUERY_GET_ENTRIES_FOR_PUBLISHED);
            q.setParameter(PUBLISHED_ID, pub, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAssessmentData"));
            return q.list();
        };

        return (List<ExtendedTime>) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get Extended Time Entries for Published Assessment: " + pub.getPublishedAssessmentId(), e);
        return null;
    }
}
项目:sakai    文件:ExtendedTimeQueries.java   
@SuppressWarnings("unchecked")
private ExtendedTime        getPubAndX              (final String query, final PublishedAssessmentIfc pub, final String secondParam, final String secondParamValue) {
    try{
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(query);
            q.setParameter(PUBLISHED_ID, pub, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAssessmentData"));
            q.setParameter(secondParam, secondParamValue, new StringType());
            return q.uniqueResult();
        };

        return (ExtendedTime) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get extended time for pub: " + pub.getPublishedAssessmentId() + " and user/group: " + secondParamValue, e);
        return null;
    }
}
项目:sakai    文件:ExtendedTimeQueries.java   
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public  List<ExtendedTime>  getEntriesForAss        (AssessmentBaseIfc ass) {
    log.debug("getEntriesForAss " + ass.getAssessmentBaseId());

    try {
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(QUERY_GET_ENTRIES_FOR_ASSESSMENT);
            q.setParameter(ASSESSMENT_ID, ass, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.AssessmentBaseData"));
            return q.list();
        };
        return (List<ExtendedTime>) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get Extended TimeEntries for Assessment: " + ass.getAssessmentBaseId(), e);
        return null;
    }
}
项目:sakai    文件:ExtendedTimeQueries.java   
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public  List<ExtendedTime>  getEntriesForPub        (PublishedAssessmentIfc pub) {
    log.debug("getEntriesForPub " + pub.getPublishedAssessmentId());

    try {
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(QUERY_GET_ENTRIES_FOR_PUBLISHED);
            q.setParameter(PUBLISHED_ID, pub, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAssessmentData"));
            return q.list();
        };

        return (List<ExtendedTime>) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get Extended Time Entries for Published Assessment: " + pub.getPublishedAssessmentId(), e);
        return null;
    }
}
项目:sakai    文件:ExtendedTimeQueries.java   
@SuppressWarnings("unchecked")
private ExtendedTime        getPubAndX              (final String query, final PublishedAssessmentIfc pub, final String secondParam, final String secondParamValue) {
    try{
        HibernateCallback hcb = (Session s) -> {
            Query q = s.getNamedQuery(query);
            q.setParameter(PUBLISHED_ID, pub, new ManyToOneType(null, "org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAssessmentData"));
            q.setParameter(secondParam, secondParamValue, new StringType());
            return q.uniqueResult();
        };

        return (ExtendedTime) getHibernateTemplate().execute(hcb);
    } catch (DataAccessException e) {
        log.error("Failed to get extended time for pub: " + pub.getPublishedAssessmentId() + " and user/group: " + secondParamValue, e);
        return null;
    }
}
项目:geomajas-project-server    文件:HibernateEntityMapper.java   
/**
 * Construct a entity collection.
 *
 * @param parentMetadata parent meta data
 * @param childMetadata child meta data
 * @param parent parent object
 * @param objects child objects
 */
public HibernateEntityCollection(ClassMetadata parentMetadata, ClassMetadata childMetadata, Object parent,
        Collection<?> objects) {
    this.objects = objects;
    int i = 0;
    for (Type type : childMetadata.getPropertyTypes()) {
        if (type instanceof ManyToOneType) {
            ManyToOneType mto = (ManyToOneType) type;
            if (mto.getAssociatedEntityName().equals(parentMetadata.getEntityName())) {
                parentName = childMetadata.getPropertyNames()[i];
            }
        }
        i++;
    }
    this.metadata = childMetadata;
    this.parent = parent;
}
项目:engerek    文件:MidpointPersisterUtil.java   
private static void killUnwantedAssociationValues(String[] propertyNames, Type[] propertyTypes, Object[] values, int depth) {
    if (values == null) {
        return;
    }

    for (int i = 0; i < propertyTypes.length; i++) {
        String name = propertyNames[i];
        Type type = propertyTypes[i];
        Object value = values[i];
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("{}- killUnwantedAssociationValues processing #{}: {} (type={}, value={})",
                    StringUtils.repeat("  ", depth), i, name, type, value);
        }
        if (type instanceof ComponentType) {
            ComponentType componentType = (ComponentType) type;
            killUnwantedAssociationValues(componentType.getPropertyNames(), componentType.getSubtypes(), (Object[]) value, depth+1);
        } else if (type instanceof ManyToOneType) {
            if (ASSOCIATION_TO_REMOVE.equals(name)) {
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("{}- killUnwantedAssociationValues KILLED #{}: {} (type={}, value={})",
                            StringUtils.repeat("  ", depth), i, name, type, value);
                }
                values[i] = null;
            }
        }
    }
}
项目:cacheonix-core    文件:ASTParserLoadingTest.java   
public void testSelectClauseImplicitJoin() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Zoo zoo = new Zoo();
    zoo.setName("The Zoo");
    zoo.setMammals( new HashMap() );
    zoo.setAnimals( new HashMap() );
    Mammal plat = new Mammal();
    plat.setBodyWeight( 11f );
    plat.setDescription( "Platypus" );
    plat.setZoo(zoo);
    plat.setSerialNumber("plat123");
    zoo.getMammals().put("Platypus", plat);
    zoo.getAnimals().put("plat123", plat);
    s.persist( plat );
    s.persist(zoo);
    s.flush();
    s.clear();
    Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
    Type type = q.getReturnTypes()[0];
    assertTrue( type instanceof ManyToOneType );
    assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );
    zoo = (Zoo) q.list().get(0);
    assertEquals( zoo.getMammals().size(), 1 );
    assertEquals( zoo.getAnimals().size(), 1 );
    s.clear();
    s.delete(plat);
    s.delete(zoo);
    t.commit();
    s.close();
}
项目:cacheonix-core    文件:ASTParserLoadingTest.java   
public void testSelectClauseImplicitJoinWithIterate() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Zoo zoo = new Zoo();
    zoo.setName("The Zoo");
    zoo.setMammals( new HashMap() );
    zoo.setAnimals( new HashMap() );
    Mammal plat = new Mammal();
    plat.setBodyWeight( 11f );
    plat.setDescription( "Platypus" );
    plat.setZoo(zoo);
    plat.setSerialNumber("plat123");
    zoo.getMammals().put("Platypus", plat);
    zoo.getAnimals().put("plat123", plat);
    s.persist( plat );
    s.persist(zoo);
    s.flush();
    s.clear();
    Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
    Type type = q.getReturnTypes()[0];
    assertTrue( type instanceof ManyToOneType );
    assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );
    zoo = (Zoo) q
        .iterate().next();
    assertEquals( zoo.getMammals().size(), 1 );
    assertEquals( zoo.getAnimals().size(), 1 );
    s.clear();
    s.delete(plat);
    s.delete(zoo);
    t.commit();
    s.close();
}
项目:midpoint    文件:MidpointPersisterUtil.java   
private static void killUnwantedAssociationValues(String[] propertyNames, Type[] propertyTypes, Object[] values, int depth) {
    if (values == null) {
        return;
    }

    for (int i = 0; i < propertyTypes.length; i++) {
        String name = propertyNames[i];
        Type type = propertyTypes[i];
        Object value = values[i];
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("{}- killUnwantedAssociationValues processing #{}: {} (type={}, value={})",
                    StringUtils.repeat("  ", depth), i, name, type, value);
        }
        if (type instanceof ComponentType) {
            ComponentType componentType = (ComponentType) type;
            killUnwantedAssociationValues(componentType.getPropertyNames(), componentType.getSubtypes(), (Object[]) value, depth+1);
        } else if (type instanceof ManyToOneType) {
            if (ASSOCIATION_TO_REMOVE.equals(name)) {
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("{}- killUnwantedAssociationValues KILLED #{}: {} (type={}, value={})",
                            StringUtils.repeat("  ", depth), i, name, type, value);
                }
                values[i] = null;
            }
        }
    }
}
项目:midpoint    文件:MidpointPersisterUtil.java   
private static void killUnwantedAssociationValues(String[] propertyNames, Type[] propertyTypes, Object[] values, int depth) {
    if (values == null) {
        return;
    }

    for (int i = 0; i < propertyTypes.length; i++) {
        String name = propertyNames[i];
        Type type = propertyTypes[i];
        Object value = values[i];
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("{}- killUnwantedAssociationValues processing #{}: {} (type={}, value={})",
                    StringUtils.repeat("  ", depth), i, name, type, value);
        }
        if (type instanceof ComponentType) {
            ComponentType componentType = (ComponentType) type;
            killUnwantedAssociationValues(componentType.getPropertyNames(), componentType.getSubtypes(), (Object[]) value, depth+1);
        } else if (type instanceof ManyToOneType) {
            if (ASSOCIATION_TO_REMOVE.equals(name)) {
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("{}- killUnwantedAssociationValues KILLED #{}: {} (type={}, value={})",
                            StringUtils.repeat("  ", depth), i, name, type, value);
                }
                values[i] = null;
            }
        }
    }
}
项目:cacheonix-core    文件:Hibernate.java   
/**
 * A Hibernate persistent object (entity) type.
 *
 * @param persistentClass a mapped entity class
 */
public static Type entity(Class persistentClass) {
    // not really a many-to-one association *necessarily*
    return new ManyToOneType( persistentClass.getName() );
}
项目:cacheonix-core    文件:Hibernate.java   
/**
 * A Hibernate persistent object (entity) type.
 *
 * @param entityName a mapped entity class
 */
public static Type entity(String entityName) {
    // not really a many-to-one association *necessarily*
    return new ManyToOneType( entityName );
}