Java 类org.hibernate.mapping.Collection 实例源码

项目:lams    文件:CollectionBinder.java   
private static void bindCollectionSecondPass(
        Collection collValue,
        PersistentClass collectionEntity,
        Ejb3JoinColumn[] joinColumns,
        boolean cascadeDeleteEnabled,
        XProperty property,
        Mappings mappings) {
    try {
        BinderHelper.createSyntheticPropertyReference(
                joinColumns, collValue.getOwner(), collectionEntity, collValue, false, mappings
        );
    }
    catch (AnnotationException ex) {
        throw new AnnotationException( "Unable to map collection " + collectionEntity.getClassName() + "." + property.getName(), ex );
    }
    SimpleValue key = buildCollectionKey( collValue, joinColumns, cascadeDeleteEnabled, property, mappings );
    if ( property.isAnnotationPresent( ElementCollection.class ) && joinColumns.length > 0 ) {
        joinColumns[0].setJPA2ElementCollection( true );
    }
    TableBinder.bindFk( collValue.getOwner(), collectionEntity, joinColumns, key, false, mappings );
}
项目:gorm-hibernate5    文件:GrailsDomainBinder.java   
@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
    MetadataBuildingOptions options = metadataCollector.getMetadataBuildingOptions();
    ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);

    final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(
            options.getTempClassLoader(),
            classLoaderService
    );

    this.metadataBuildingContext = new MetadataBuildingContextRootImpl(
            options,
            classLoaderAccess,
            metadataCollector
    );

        java.util.Collection<PersistentEntity> persistentEntities = hibernateMappingContext.getPersistentEntities();
    for (PersistentEntity persistentEntity : persistentEntities) {
        if(!persistentEntity.getJavaClass().isAnnotationPresent(Entity.class)) {
            if(ConnectionSourcesSupport.usesConnectionSource(persistentEntity, dataSourceName) && persistentEntity.isRoot()) {
                bindRoot((HibernatePersistentEntity) persistentEntity, metadataCollector, sessionFactoryName);
            }
        }
    }
}
项目:gorm-hibernate5    文件:GrailsDomainBinder.java   
/**
 * Creates the DependentValue object that forms a primary key reference for the collection.
 *
 * @param mappings
 * @param property          The grails property
 * @param collection        The collection object
 * @param persistentClasses
 * @return The DependantValue (key)
 */
protected DependantValue createPrimaryKeyValue(InFlightMetadataCollector mappings, PersistentProperty property,
                                               Collection collection, Map<?, ?> persistentClasses) {
    KeyValue keyValue;
    DependantValue key;
    String propertyRef = collection.getReferencedPropertyName();
    // this is to support mapping by a property
    if (propertyRef == null) {
        keyValue = collection.getOwner().getIdentifier();
    } else {
        keyValue = (KeyValue) collection.getOwner().getProperty(propertyRef).getValue();
    }

    if (LOG.isDebugEnabled())
        LOG.debug("[GrailsDomainBinder] creating dependant key value  to table [" + keyValue.getTable().getName() + "]");

    key = new DependantValue(mappings, collection.getCollectionTable(), keyValue);

    key.setTypeName(null);
    // make nullable and non-updateable
    key.setNullable(true);
    key.setUpdateable(false);
    return key;
}
项目:gorm-hibernate5    文件:GrailsDomainBinder.java   
/**
 * Binds a unidirectional one-to-many creating a psuedo back reference property in the process.
 *
 * @param property
 * @param mappings
 * @param collection
 */
protected void bindUnidirectionalOneToMany(org.grails.datastore.mapping.model.types.OneToMany property, InFlightMetadataCollector mappings, Collection collection) {
    Value v = collection.getElement();
    v.createForeignKey();
    String entityName;
    if (v instanceof ManyToOne) {
        ManyToOne manyToOne = (ManyToOne) v;

        entityName = manyToOne.getReferencedEntityName();
    } else {
        entityName = ((OneToMany) v).getReferencedEntityName();
    }
    collection.setInverse(false);
    PersistentClass referenced = mappings.getEntityBinding(entityName);
    Backref prop = new Backref();
    PersistentEntity owner = property.getOwner();
    prop.setEntityName(owner.getName());
    prop.setName(UNDERSCORE + addUnderscore(owner.getJavaClass().getSimpleName(), property.getName()) + "Backref");
    prop.setUpdateable(false);
    prop.setInsertable(true);
    prop.setCollectionRole(collection.getRole());
    prop.setValue(collection.getKey());
    prop.setOptional(true);

    referenced.addProperty(prop);
}
项目:hibernate-semantic-query    文件:PersisterHelper.java   
public OrmAttribute buildPluralAttribute(
        PersisterCreationContext creationContext,
        Collection collectionBinding,
        OrmNavigableSource source,
        String propertyName) {
    // todo : resolve cache access
    final CollectionRegionAccessStrategy cachingAccess = null;

    // need PersisterCreationContext - we should always have access to that when building persisters, through finalized initialization
    final CollectionPersister collectionPersister = creationContext.getPersisterFactory().createCollectionPersister(
            collectionBinding,
            (ManagedTypeImplementor) source,
            propertyName,
            cachingAccess,
            creationContext
    );
    creationContext.registerCollectionPersister( collectionPersister );
    return collectionPersister;
}
项目:hibernate-semantic-query    文件:OrmTypeHelper.java   
private static CollectionType convertCollection(
        PersisterCreationContext creationContext,
        ManagedTypeImplementor source,
        String navigableName,
        Collection collectionValue,
        TypeConfiguration typeConfiguration) {
    final String roleName = source.getRolePrefix() + navigableName;

    CollectionPersister<?, ?, ?> collectionPersister = typeConfiguration.findCollectionPersister( roleName );

    if ( collectionPersister == null ) {
        collectionPersister = creationContext.getPersisterFactory().createCollectionPersister(
                collectionValue,
                source,
                navigableName,
                null,
                creationContext
        );
    }

    return collectionPersister.getOrmType();
}
项目:hibernate-conventions    文件:DDLConventions.java   
private List<String> listTables() {

        List<String> results = new ArrayList<String>();

        Iterator<PersistentClass> iterator1 = configuration.getClassMappings();
        while (iterator1.hasNext()) {
            results.add(iterator1.next().getTable().getName());
        }

        Iterator<?> iterator2 = configuration.getCollectionMappings();
        while (iterator2.hasNext()) {
            results.add(((Collection) iterator2.next()).getTable().getName());
        }

        return results;

    }
项目:lams    文件:Configuration.java   
private void validate() throws MappingException {
    Iterator iter = classes.values().iterator();
    while ( iter.hasNext() ) {
        ( (PersistentClass) iter.next() ).validate( mapping );
    }
    iter = collections.values().iterator();
    while ( iter.hasNext() ) {
        ( (Collection) iter.next() ).validate( mapping );
    }
}
项目:lams    文件:Configuration.java   
private void applyCollectionCacheConcurrencyStrategy(CacheHolder holder) {
    Collection collection = getCollectionMapping( holder.role );
    if ( collection == null ) {
        throw new MappingException( "Cannot cache an unknown collection: " + holder.role );
    }
    collection.setCacheConcurrencyStrategy( holder.usage );
    collection.setCacheRegionName( holder.region );
}
项目:lams    文件:Configuration.java   
@Override
public java.util.Collection<AttributeConverterDefinition> getAttributeConverters() {
    if ( attributeConverterDefinitionsByClass == null ) {
        return Collections.emptyList();
    }
    return attributeConverterDefinitionsByClass.values();
}
项目:lams    文件:CollectionPropertyHolder.java   
public CollectionPropertyHolder(
        Collection collection,
        String path,
        XClass clazzToProcess,
        XProperty property,
        PropertyHolder parentPropertyHolder,
        Mappings mappings) {
    super( path, parentPropertyHolder, clazzToProcess, mappings );
    this.collection = collection;
    setCurrentProperty( property );

    this.elementAttributeConversionInfoMap = new HashMap<String, AttributeConversionInfo>();
    this.keyAttributeConversionInfoMap = new HashMap<String, AttributeConversionInfo>();
}
项目:lams    文件:PropertyHolderBuilder.java   
/**
 * buid a property holder on top of a collection
 */
public static CollectionPropertyHolder buildPropertyHolder(
        Collection collection,
        String path,
        XClass clazzToProcess,
        XProperty property,
        PropertyHolder parentPropertyHolder,
        Mappings mappings) {
    return new CollectionPropertyHolder(
            collection, path, clazzToProcess, property, parentPropertyHolder, mappings
    );
}
项目:lams    文件:CollectionBinder.java   
private static void checkFilterConditions(Collection collValue) {
    //for now it can't happen, but sometime soon...
    if ( ( collValue.getFilters().size() != 0 || StringHelper.isNotEmpty( collValue.getWhere() ) ) &&
            collValue.getFetchMode() == FetchMode.JOIN &&
            !( collValue.getElement() instanceof SimpleValue ) && //SimpleValue (CollectionOfElements) are always SELECT but it does not matter
            collValue.getElement().getFetchMode() != FetchMode.JOIN ) {
        throw new MappingException(
                "@ManyToMany or @CollectionOfElements defining filter or where without join fetching "
                        + "not valid within collection using join fetching[" + collValue.getRole() + "]"
        );
    }
}
项目:lams    文件:ListBinder.java   
private void bindIndex(final Mappings mappings) {
    if ( !indexColumn.isImplicit() ) {
        PropertyHolder valueHolder = PropertyHolderBuilder.buildPropertyHolder(
                this.collection,
                StringHelper.qualify( this.collection.getRole(), "key" ),
                null,
                null, propertyHolder, mappings
        );
        List list = (List) this.collection;
        if ( !list.isOneToMany() ) indexColumn.forceNotNull();
        indexColumn.setPropertyHolder( valueHolder );
        SimpleValueBinder value = new SimpleValueBinder();
        value.setColumns( new Ejb3Column[] { indexColumn } );
        value.setExplicitType( "integer" );
        value.setMappings( mappings );
        SimpleValue indexValue = value.make();
        indexColumn.linkWithValue( indexValue );
        list.setIndex( indexValue );
        list.setBaseIndex( indexColumn.getBase() );
        if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) {
            String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName();
            PersistentClass referenced = mappings.getClass( entityName );
            IndexBackref ib = new IndexBackref();
            ib.setName( '_' + propertyName + "IndexBackref" );
            ib.setUpdateable( false );
            ib.setSelectable( false );
            ib.setCollectionRole( list.getRole() );
            ib.setEntityName( list.getOwner().getEntityName() );
            ib.setValue( list.getIndex() );
            referenced.addProperty( ib );
        }
    }
    else {
        Collection coll = this.collection;
        throw new AnnotationException(
                "List/array has to be annotated with an @OrderColumn (or @IndexColumn): "
                        + coll.getRole()
        );
    }
}
项目:lams    文件:PersisterFactoryImpl.java   
@Override
@SuppressWarnings( {"unchecked"})
public CollectionPersister createCollectionPersister(
        Configuration cfg,
        Collection collectionMetadata,
        CollectionRegionAccessStrategy cacheAccessStrategy,
        SessionFactoryImplementor factory) throws HibernateException {
    Class<? extends CollectionPersister> persisterClass = collectionMetadata.getCollectionPersisterClass();
    if ( persisterClass == null ) {
        persisterClass = serviceRegistry.getService( PersisterClassResolver.class ).getCollectionPersisterClass( collectionMetadata );
    }

    return create( persisterClass, COLLECTION_PERSISTER_CONSTRUCTOR_ARGS, cfg, collectionMetadata, cacheAccessStrategy, factory );
}
项目:lams    文件:BasicCollectionPersister.java   
public BasicCollectionPersister(
        Collection collection,
        CollectionRegionAccessStrategy cacheAccessStrategy,
        Configuration cfg,
        SessionFactoryImplementor factory) throws MappingException, CacheException {
    super( collection, cacheAccessStrategy, cfg, factory );
}
项目:lams    文件:OneToManyPersister.java   
public OneToManyPersister(
        Collection collection,
        CollectionRegionAccessStrategy cacheAccessStrategy,
        Configuration cfg,
        SessionFactoryImplementor factory) throws MappingException, CacheException {
    super( collection, cacheAccessStrategy, cfg, factory );
    cascadeDeleteEnabled = collection.getKey().isCascadeDeleteEnabled() &&
            factory.getDialect().supportsCascadeDelete();
    keyIsNullable = collection.getKey().isNullable();
    keyIsUpdateable = collection.getKey().isUpdateable();
}
项目:lams    文件:CacheDataDescriptionImpl.java   
/**
 * Builds a CacheDataDescriptionImpl from the mapping model of a collection
 *
 * @param model The mapping model.
 *
 * @return The constructed CacheDataDescriptionImpl
 */
public static CacheDataDescriptionImpl decode(Collection model) {
    return new CacheDataDescriptionImpl(
            model.isMutable(),
            model.getOwner().isVersioned(),
            model.getOwner().isVersioned()
                    ? ( (VersionType) model.getOwner().getVersion().getType() ).getComparator()
                    : null
    );
}
项目:gorm-hibernate5    文件:GrailsDomainBinder.java   
protected void bindCollectionForPropertyConfig(Collection collection, PropertyConfig config) {
    if (config == null) {
        collection.setLazy(true);
        collection.setExtraLazy(false);
    } else {
        final FetchMode fetch = config.getFetchMode();
        if(!fetch.equals(FetchMode.JOIN) && !fetch.equals(FetchMode.EAGER)) {
            collection.setLazy(true);
        }
        final Boolean lazy = config.getLazy();
        if(lazy != null) {
            collection.setExtraLazy(lazy);
        }
    }
}
项目:gorm-hibernate5    文件:GrailsDomainBinder.java   
/**
 * Links a bidirectional one-to-many, configuring the inverse side and using a column copy to perform the link
 *
 * @param collection      The collection one-to-many
 * @param associatedClass The associated class
 * @param key             The key
 * @param otherSide       The other side of the relationship
 */
protected void linkBidirectionalOneToMany(Collection collection, PersistentClass associatedClass, DependantValue key, PersistentProperty otherSide) {
    collection.setInverse(true);

    // Iterator mappedByColumns = associatedClass.getProperty(otherSide.getName()).getValue().getColumnIterator();
    Iterator<?> mappedByColumns = getProperty(associatedClass, otherSide.getName()).getValue().getColumnIterator();
    while (mappedByColumns.hasNext()) {
        Column column = (Column) mappedByColumns.next();
        linkValueUsingAColumnCopy(otherSide, column, key);
    }
}
项目:gorm-hibernate5    文件:GrailsDomainBinder.java   
protected void bindCollectionTable(ToMany property, InFlightMetadataCollector mappings,
                                   Collection collection, Table ownerTable, String sessionFactoryBeanName) {

    String owningTableSchema = ownerTable.getSchema();
    PropertyConfig config = getPropertyConfig(property);
    JoinTable jt = config != null ? config.getJoinTable() : null;

    NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName);
    String tableName = (jt != null && jt.getName() != null ? jt.getName() : namingStrategy.tableName(calculateTableForMany(property, sessionFactoryBeanName)));
    String schemaName = getSchemaName(mappings);
    String catalogName = getCatalogName(mappings);
    if(jt != null) {
        if(jt.getSchema() != null) {
            schemaName = jt.getSchema();
        }
        if(jt.getCatalog() != null) {
            catalogName = jt.getCatalog();
        }
    }

    if(schemaName == null && owningTableSchema != null) {
        schemaName = owningTableSchema;
    }

    collection.setCollectionTable(mappings.addTable(
            schemaName, catalogName,
            tableName, null, false));
}
项目:gorm-hibernate5    文件:GrailsDomainBinder.java   
/**
 * Binds the sub classes of a root class using table-per-heirarchy inheritance mapping
 *
 * @param domainClass The root domain class to bind
 * @param parent      The parent class instance
 * @param mappings    The mappings instance
 * @param sessionFactoryBeanName  the session factory bean name
 */
protected void bindSubClasses(HibernatePersistentEntity domainClass, PersistentClass parent,
                              InFlightMetadataCollector mappings, String sessionFactoryBeanName) {
    final java.util.Collection<PersistentEntity> subClasses = domainClass.getMappingContext().getDirectChildEntities(domainClass);

    for (PersistentEntity sub : subClasses) {
        final Class javaClass = sub.getJavaClass();
        if (javaClass.getSuperclass().equals(domainClass.getJavaClass())) {
            bindSubClass((HibernatePersistentEntity)sub, parent, mappings, sessionFactoryBeanName);
        }
    }
}
项目:gorm-hibernate5    文件:GrailsDomainBinder.java   
public GrailsCollectionSecondPass(ToMany property, InFlightMetadataCollector mappings,
                                  Collection coll,  String sessionFactoryBeanName) {
    this.property = property;
    this.mappings = mappings;
    this.collection = coll;
    this.sessionFactoryBeanName = sessionFactoryBeanName;
}
项目:cacheonix-core    文件:Configuration.java   
private void validate() throws MappingException {
    Iterator iter = classes.values().iterator();
    while ( iter.hasNext() ) {
        ( (PersistentClass) iter.next() ).validate( mapping );
    }
    iter = collections.values().iterator();
    while ( iter.hasNext() ) {
        ( (Collection) iter.next() ).validate( mapping );
    }
}
项目:cacheonix-core    文件:Configuration.java   
public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String region)
        throws MappingException {
    Collection collection = getCollectionMapping( collectionRole );
    if ( collection == null ) {
        throw new MappingException( "Cannot cache an unknown collection: " + collectionRole );
    }
    collection.setCacheConcurrencyStrategy( concurrencyStrategy );
    collection.setCacheRegionName( region );
}
项目:cacheonix-core    文件:PersisterFactory.java   
public static CollectionPersister createCollectionPersister(Configuration cfg, Collection model, CacheConcurrencyStrategy cache, SessionFactoryImplementor factory)
throws HibernateException {
    Class persisterClass = model.getCollectionPersisterClass();
    if(persisterClass==null) { // default behavior
        return model.isOneToMany() ?
            (CollectionPersister) new OneToManyPersister(model, cache, cfg, factory) :
            (CollectionPersister) new BasicCollectionPersister(model, cache, cfg, factory);
    }
    else {
        return create(persisterClass, cfg, model, cache, factory);
    }

}
项目:cacheonix-core    文件:BasicCollectionPersister.java   
public BasicCollectionPersister(Collection collection,
                                CacheConcurrencyStrategy cache,
                                Configuration cfg,
                                SessionFactoryImplementor factory)
        throws MappingException, CacheException {
    super( collection, cache, cfg, factory );
}
项目:cacheonix-core    文件:OneToManyPersister.java   
public OneToManyPersister(Collection collection,
                          CacheConcurrencyStrategy cache,
                          Configuration cfg,
                          SessionFactoryImplementor factory)
        throws MappingException, CacheException {
    super( collection, cache, cfg, factory );
    cascadeDeleteEnabled = collection.getKey().isCascadeDeleteEnabled() &&
            factory.getDialect().supportsCascadeDelete();
    keyIsNullable = collection.getKey().isNullable();
    keyIsUpdateable = collection.getKey().isUpdateable();
}
项目:cacheonix-core    文件:ExecutionEnvironment.java   
private void applyCacheSettings(Configuration configuration) {
    if ( settings.getCacheConcurrencyStrategy() != null ) {
        Iterator iter = configuration.getClassMappings();
        while ( iter.hasNext() ) {
            PersistentClass clazz = (PersistentClass) iter.next();
            Iterator props = clazz.getPropertyClosureIterator();
            boolean hasLob = false;
            while ( props.hasNext() ) {
                Property prop = (Property) props.next();
                if ( prop.getValue().isSimpleValue() ) {
                    String type = ( ( SimpleValue ) prop.getValue() ).getTypeName();
                    if ( "blob".equals(type) || "clob".equals(type) ) {
                        hasLob = true;
                    }
                    if ( Blob.class.getName().equals(type) || Clob.class.getName().equals(type) ) {
                        hasLob = true;
                    }
                }
            }
            if ( !hasLob && !clazz.isInherited() && settings.overrideCacheStrategy() ) {
                configuration.setCacheConcurrencyStrategy( clazz.getEntityName(), settings.getCacheConcurrencyStrategy() );
            }
        }
        iter = configuration.getCollectionMappings();
        while ( iter.hasNext() ) {
            Collection coll = (Collection) iter.next();
            configuration.setCollectionCacheConcurrencyStrategy( coll.getRole(), settings.getCacheConcurrencyStrategy() );
        }
    }
}
项目:cacheonix-core    文件:NonReflectiveBinderTest.java   
public void testComparator() {
    PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked");

    Property property = cm.getProperty("sortedEmployee");
    Collection col = (Collection) property.getValue();
    assertEquals(col.getComparatorClassName(),"org.hibernate.test.legacy.NonExistingComparator");
}
项目:cacheonix-core    文件:CompositeElementTest.java   
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
    super.afterConfigurationBuilt( mappings, dialect );
    Collection children = mappings.getCollection( Parent.class.getName() + ".children" );
    Component childComponents = ( Component ) children.getElement();
    Formula f = ( Formula ) childComponents.getProperty( "bioLength" ).getValue().getColumnIterator().next();

    SQLFunction lengthFunction = ( SQLFunction ) dialect.getFunctions().get( "length" );
    if ( lengthFunction != null ) {
        ArrayList args = new ArrayList();
        args.add( "bio" );
        f.setFormula( lengthFunction.render( args, null ) );
    }
}
项目:UMLS-Terminology-Server    文件:ConfigUtility.java   
/**
 * Returns the first order field hash.
 *
 * @param c the c
 * @return the first order field hash
 * @throws Exception the exception
 */
public static String getFirstOrderFieldHash(Component c) throws Exception {
  final StringBuilder sb = new StringBuilder();
  for (final Method m : c.getClass().getMethods()) {
    if (!Collection.class.isAssignableFrom(m.getReturnType())
        && m.getParameterTypes().length == 0
        && m.getName().startsWith("get")) {
      sb.append(m.invoke(c, new Object[] {})).append(",");
    }
  }
  return "";
}
项目:hibernate-semantic-query    文件:PersisterFactoryImpl.java   
@Override
    @SuppressWarnings( {"unchecked"})
    public CollectionPersister createCollectionPersister(
            Collection collectionBinding,
            ManagedTypeImplementor source,
            String propertyName,
            CollectionRegionAccessStrategy cacheAccessStrategy,
            PersisterCreationContext creationContext) throws HibernateException {
//      // If the metadata for the collection specified an explicit persister class, use it
//      Class<? extends CollectionPersister> persisterClass = collectionBinding.getCollectionPersisterClass();
//      if ( persisterClass == null ) {
//          // Otherwise, use the persister class indicated by the PersisterClassResolver service
//          persisterClass = serviceRegistry.getService( PersisterClassResolver.class )
//                  .getCollectionPersisterClass( collectionBinding );
//      }
//      return createCollectionPersister( persisterClass, collectionBinding, source, propertyName, cacheAccessStrategy, creationContext );

        // todo : ^^ we need to make this fit the published ctor contract (as much as possible)
        //      for now just create a simpl testing stub
        return new CollectionPersisterImpl(
                collectionBinding,
                source,
                propertyName,
                null,
                creationContext
        );
    }
项目:hibernate-semantic-query    文件:PersisterFactoryImpl.java   
@Override
public void finishUp(PersisterCreationContext creationContext) {
    for ( EntityHierarchyNode root : roots ) {
        // todo : resolve any MappedSuperclasses for supers of the root entity
        EntityHierarchy entityHierarchy = new EntityHierarchyImpl(
                creationContext,
                (RootClass) root.mappingType,
                (EntityPersister) root.ormJpaType
        );

        finishSupers( root.superEntityNode, entityHierarchy, creationContext );

        root.finishUp( entityHierarchy, creationContext );

        entityHierarchy.finishInitialization( creationContext, (RootClass) root.mappingType );
    }

    // todo :
    for ( final Collection model : creationContext.getMetadata().getCollectionBindings() ) {
        final CollectionPersister collectionPersister = creationContext.getTypeConfiguration().findCollectionPersister( model.getRole() );
        if ( collectionPersister == null ) {
            throw new HibernateException( "Collection role not properly materialized to CollectionPersister : " + model.getRole() );
        }
        collectionPersister.finishInitialization( model, creationContext );
    }

    for ( EmbeddableMapper mapper : creationContext.getTypeConfiguration().getEmbeddablePersisters() ) {
        mapper.afterInitialization(
                embeddableComponentMap.get( mapper ),
                creationContext
        );
    }


    serviceRegistry = null;
    roots.clear();
    nameToHierarchyNodeMap.clear();
    embeddableComponentMap.clear();
}
项目:hibernate-semantic-query    文件:CollectionPersisterImpl.java   
public CollectionPersisterImpl(
            Collection collectionBinding,
            ManagedTypeImplementor source,
            String localName,
            CollectionRegionAccessStrategy collectionCaching,
            PersisterCreationContext creationContext) {
        super( source, localName, PropertyAccess.DUMMY );
        this.source = source;
        this.localName = localName;
        this.role = source.getNavigableName() + '.' + this.localName;
        this.collectionClassification = PersisterHelper.interpretCollectionClassification( collectionBinding );
        this.foreignKeyDescriptor = new CollectionKey( this );

        this.typeConfiguration = creationContext.getTypeConfiguration();

        this.collectionType = new CollectionTypeImpl(
                role,
                resolveCollectionJtd( creationContext, collectionClassification ),
                null,
                null
        );

        if ( collectionBinding instanceof IndexedCollection ) {
            final Value indexValueMapping = ( (IndexedCollection) collectionBinding ).getIndex();
            if ( indexValueMapping instanceof SimpleValue ) {
                final SimpleValue simpleIndexValueMapping = (SimpleValue) indexValueMapping;
//              indexAttributeConverter = simpleIndexValueMapping.getAttributeConverterDescriptor().getAttributeConverter();
            }
        }

        final Value elementValueMapping = collectionBinding.getElement();
        if ( elementValueMapping instanceof SimpleValue ) {
            final SimpleValue simpleElementValueMapping = (SimpleValue) elementValueMapping;
//          elementAttributeConverter = simpleElementValueMapping.getAttributeConverterDescriptor().getAttributeConverter();
        }
    }
项目:hibernate-semantic-query    文件:OrmTypeHelper.java   
public static <T> Type convert(
        PersisterCreationContext creationContext,
        ManagedTypeImplementor source,
        String navigableName,
        Value valueBinding,
        TypeConfiguration typeConfiguration) {
    if ( valueBinding.getType() == null ) {
        return null;
    }

    if ( valueBinding.getType() instanceof org.hibernate.type.BasicType ) {
        return convertBasic( (BasicType) valueBinding.getType(), typeConfiguration );
    }

    if ( valueBinding.getType() instanceof org.hibernate.type.CompositeType ) {
        return convertEmbedded( creationContext, source, navigableName, (Component) valueBinding, typeConfiguration );
    }

    if ( valueBinding.getType() instanceof org.hibernate.type.CollectionType ) {
        return convertCollection( creationContext, source, navigableName, (Collection) valueBinding, typeConfiguration );
    }

    if ( valueBinding.getType() instanceof org.hibernate.type.ManyToOneType ) {
        return convertEntity( creationContext, source, navigableName, (ToOne) valueBinding, typeConfiguration );
    }

    throw new NotYetImplementedException( "Converting " + valueBinding.getType().getClass().getName() + " -> org.hibernate.orm.type.spi.Type" );
}
项目:logical-delete    文件:DeleteHibernateFilterConfigurator.java   
private void enrichLogicalDeleteCollections(Configuration configuration) {
    Iterator<?> mappings = configuration.getCollectionMappings();
    while(mappings.hasNext()){
        Collection collection = (Collection) mappings.next();
        if (mustBeProcessed(collection.getOwner().getMappedClass()) && collection.isOneToMany()){
            log.debug("Enabling delete filter for collection class {}", collection.getRole());
            addFilter(collection);
        }
    }
}
项目:cagrid-core    文件:HibernateConfigTypesInformationResolver.java   
public String getEndName(String parentClassname, String childClassname) throws TypesInformationException {
    LOG.debug("Getting the association end name for " + parentClassname + " to " + childClassname);
    String identifier = getAssociationIdentifier(parentClassname, childClassname);
    String roleName = roleNames.get(identifier);
    if (roleName == null) {
        PersistentClass clazz = findPersistentClass(parentClassname);
        Iterator<?> propertyIter = clazz.getPropertyIterator();
        while (propertyIter.hasNext()) {
            Property prop = (Property) propertyIter.next();
            Value value = prop.getValue();
            String referencedEntity = null;
            if (value instanceof Collection) {
                Value element = ((Collection) value).getElement();
                if (element instanceof OneToMany) {
                    referencedEntity = ((OneToMany) element).getReferencedEntityName();
                } else if (element instanceof ToOne) {
                    referencedEntity = ((ToOne) element).getReferencedEntityName();
                }
            } else if (value instanceof ToOne) {
                referencedEntity = ((ToOne) value).getReferencedEntityName();
            }
            if (childClassname.equals(referencedEntity)) {
                if (roleName != null) {
                    // already found one association, so this is ambiguous
                    throw new TypesInformationException("Association from " + parentClassname + " to " 
                        + childClassname + " is ambiguous.  Please specify a valid role name");
                }
                roleName = prop.getName();
            }
        }
    }
    return roleName;
}
项目:lams    文件:HbmBinder.java   
private static void bindManyToManySubelements(
        Collection collection,
        Element manyToManyNode,
        Mappings model) throws MappingException {
    // Bind the where
    Attribute where = manyToManyNode.attribute( "where" );
    String whereCondition = where == null ? null : where.getValue();
    collection.setManyToManyWhere( whereCondition );

    // Bind the order-by
    Attribute order = manyToManyNode.attribute( "order-by" );
    String orderFragment = order == null ? null : order.getValue();
    collection.setManyToManyOrdering( orderFragment );

    // Bind the filters
    Iterator filters = manyToManyNode.elementIterator( "filter" );
    if ( ( filters.hasNext() || whereCondition != null ) &&
            collection.getFetchMode() == FetchMode.JOIN &&
            collection.getElement().getFetchMode() != FetchMode.JOIN ) {
        throw new MappingException(
                "many-to-many defining filter or where without join fetching " +
                "not valid within collection using join fetching [" + collection.getRole() + "]"
            );
    }
    final boolean debugEnabled = LOG.isDebugEnabled();
    while ( filters.hasNext() ) {
        final Element filterElement = ( Element ) filters.next();
        final String name = filterElement.attributeValue( "name" );
        String condition = filterElement.getTextTrim();
        if ( StringHelper.isEmpty(condition) ) condition = filterElement.attributeValue( "condition" );
        if ( StringHelper.isEmpty(condition) ) {
            condition = model.getFilterDefinition(name).getDefaultFilterCondition();
        }
        if ( condition==null) {
            throw new MappingException("no filter condition found for filter: " + name);
        }
        Iterator aliasesIterator = filterElement.elementIterator("aliases");
        java.util.Map<String, String> aliasTables = new HashMap<String, String>();
        while (aliasesIterator.hasNext()){
            Element alias = (Element) aliasesIterator.next();
            aliasTables.put(alias.attributeValue("alias"), alias.attributeValue("table"));
        }
        if ( debugEnabled ) {
            LOG.debugf( "Applying many-to-many filter [%s] as [%s] to role [%s]", name, condition, collection.getRole() );
        }
        String autoAliasInjectionText = filterElement.attributeValue("autoAliasInjection");
        boolean autoAliasInjection = StringHelper.isEmpty(autoAliasInjectionText) ? true : Boolean.parseBoolean(autoAliasInjectionText);
        collection.addManyToManyFilter(name, condition, autoAliasInjection, aliasTables, null);
    }
}
项目:lams    文件:HbmBinder.java   
CollectionSecondPass(Element node, Mappings mappings, Collection collection, java.util.Map inheritedMetas) {
    super(mappings, collection, inheritedMetas);
    this.node = node;
}