Java 类org.hibernate.id.factory.IdentifierGeneratorFactory 实例源码

项目:lams    文件:Component.java   
@Override
public IdentifierGenerator createIdentifierGenerator(
        IdentifierGeneratorFactory identifierGeneratorFactory,
        Dialect dialect,
        String defaultCatalog,
        String defaultSchema,
        RootClass rootClass) throws MappingException {
    if ( builtIdentifierGenerator == null ) {
        builtIdentifierGenerator = buildIdentifierGenerator(
                identifierGeneratorFactory,
                dialect,
                defaultCatalog,
                defaultSchema,
                rootClass
        );
    }
    return builtIdentifierGenerator;
}
项目:lemon    文件:SessionFactoryWrapper.java   
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
    return sessionFactoryImplementor.getIdentifierGeneratorFactory();
}
项目:lams    文件:KeyValue.java   
public IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect,
String defaultCatalog,
String defaultSchema,
RootClass rootClass) throws MappingException;
项目:lams    文件:Component.java   
private IdentifierGenerator buildIdentifierGenerator(
        IdentifierGeneratorFactory identifierGeneratorFactory,
        Dialect dialect,
        String defaultCatalog,
        String defaultSchema,
        RootClass rootClass) throws MappingException {
    final boolean hasCustomGenerator = ! DEFAULT_ID_GEN_STRATEGY.equals( getIdentifierGeneratorStrategy() );
    if ( hasCustomGenerator ) {
        return super.createIdentifierGenerator(
                identifierGeneratorFactory, dialect, defaultCatalog, defaultSchema, rootClass
        );
    }

    final Class entityClass = rootClass.getMappedClass();
    final Class attributeDeclarer; // what class is the declarer of the composite pk attributes
    CompositeNestedGeneratedValueGenerator.GenerationContextLocator locator;

    // IMPL NOTE : See the javadoc discussion on CompositeNestedGeneratedValueGenerator wrt the
    //      various scenarios for which we need to account here
    if ( rootClass.getIdentifierMapper() != null ) {
        // we have the @IdClass / <composite-id mapped="true"/> case
        attributeDeclarer = resolveComponentClass();
    }
    else if ( rootClass.getIdentifierProperty() != null ) {
        // we have the "@EmbeddedId" / <composite-id name="idName"/> case
        attributeDeclarer = resolveComponentClass();
    }
    else {
        // we have the "straight up" embedded (again the hibernate term) component identifier
        attributeDeclarer = entityClass;
    }

    locator = new StandardGenerationContextLocator( rootClass.getEntityName() );
    final CompositeNestedGeneratedValueGenerator generator = new CompositeNestedGeneratedValueGenerator( locator );

    Iterator itr = getPropertyIterator();
    while ( itr.hasNext() ) {
        final Property property = (Property) itr.next();
        if ( property.getValue().isSimpleValue() ) {
            final SimpleValue value = (SimpleValue) property.getValue();

            if ( DEFAULT_ID_GEN_STRATEGY.equals( value.getIdentifierGeneratorStrategy() ) ) {
                // skip any 'assigned' generators, they would have been handled by
                // the StandardGenerationContextLocator
                continue;
            }

            final IdentifierGenerator valueGenerator = value.createIdentifierGenerator(
                    identifierGeneratorFactory,
                    dialect,
                    defaultCatalog,
                    defaultSchema,
                    rootClass
            );
            generator.addGeneratedValuePlan(
                    new ValueGenerationPlan(
                            property.getName(),
                            valueGenerator,
                            injector( property, attributeDeclarer )
                    )
            );
        }
    }
    return generator;
}
项目:lams    文件:SimpleValue.java   
public IdentifierGenerator createIdentifierGenerator(
        IdentifierGeneratorFactory identifierGeneratorFactory,
        Dialect dialect, 
        String defaultCatalog, 
        String defaultSchema, 
        RootClass rootClass) throws MappingException {

    Properties params = new Properties();

    //if the hibernate-mapping did not specify a schema/catalog, use the defaults
    //specified by properties - but note that if the schema/catalog were specified
    //in hibernate-mapping, or as params, they will already be initialized and
    //will override the values set here (they are in identifierGeneratorProperties)
    if ( defaultSchema!=null ) {
        params.setProperty(PersistentIdentifierGenerator.SCHEMA, defaultSchema);
    }
    if ( defaultCatalog!=null ) {
        params.setProperty(PersistentIdentifierGenerator.CATALOG, defaultCatalog);
    }

    //pass the entity-name, if not a collection-id
    if (rootClass!=null) {
        params.setProperty( IdentifierGenerator.ENTITY_NAME, rootClass.getEntityName() );
        params.setProperty( IdentifierGenerator.JPA_ENTITY_NAME, rootClass.getJpaEntityName() );
    }

    //init the table here instead of earlier, so that we can get a quoted table name
    //TODO: would it be better to simply pass the qualified table name, instead of
    //      splitting it up into schema/catalog/table names
    String tableName = getTable().getQuotedName(dialect);
    params.setProperty( PersistentIdentifierGenerator.TABLE, tableName );

    //pass the column name (a generated id almost always has a single column)
    String columnName = ( (Column) getColumnIterator().next() ).getQuotedName(dialect);
    params.setProperty( PersistentIdentifierGenerator.PK, columnName );

    if (rootClass!=null) {
        StringBuilder tables = new StringBuilder();
        Iterator iter = rootClass.getIdentityTables().iterator();
        while ( iter.hasNext() ) {
            Table table= (Table) iter.next();
            tables.append( table.getQuotedName(dialect) );
            if ( iter.hasNext() ) tables.append(", ");
        }
        params.setProperty( PersistentIdentifierGenerator.TABLES, tables.toString() );
    }
    else {
        params.setProperty( PersistentIdentifierGenerator.TABLES, tableName );
    }

    if (identifierGeneratorProperties!=null) {
        params.putAll(identifierGeneratorProperties);
    }

    // TODO : we should pass along all settings once "config lifecycle" is hashed out...
    params.put(
            Environment.PREFER_POOLED_VALUES_LO,
            mappings.getConfigurationProperties().getProperty( Environment.PREFER_POOLED_VALUES_LO, "false" )
    );

    identifierGeneratorFactory.setDialect( dialect );
    return identifierGeneratorFactory.createIdentifierGenerator( identifierGeneratorStrategy, getType(), params );

}
项目:lams    文件:SimpleValue.java   
public boolean isIdentityColumn(IdentifierGeneratorFactory identifierGeneratorFactory, Dialect dialect) {
    identifierGeneratorFactory.setDialect( dialect );
    return identifierGeneratorFactory.getIdentifierGeneratorClass( identifierGeneratorStrategy )
            .equals( IdentityGenerator.class );
}
项目:lams    文件:BasicAttributeBinding.java   
IdentifierGenerator createIdentifierGenerator(
        IdGenerator idGenerator,
        IdentifierGeneratorFactory identifierGeneratorFactory,
        Properties properties) {
    Properties params = new Properties();
    params.putAll( properties );

    // use the schema/catalog specified by getValue().getTable() - but note that
    // if the schema/catalog were specified as params, they will already be initialized and
    //will override the values set here (they are in idGenerator.getParameters().)
    Schema schema = getValue().getTable().getSchema();
    if ( schema != null ) {
        if ( schema.getName().getSchema() != null ) {
            params.setProperty( PersistentIdentifierGenerator.SCHEMA, schema.getName().getSchema().getName() );
        }
        if ( schema.getName().getCatalog() != null ) {
            params.setProperty( PersistentIdentifierGenerator.CATALOG, schema.getName().getCatalog().getName() );
        }
    }

    // TODO: not sure how this works for collection IDs...
    //pass the entity-name, if not a collection-id
    //if ( rootClass!=null) {
        params.setProperty( IdentifierGenerator.ENTITY_NAME, getContainer().seekEntityBinding().getEntity().getName() );
    //}

    //init the table here instead of earlier, so that we can get a quoted table name
    //TODO: would it be better to simply pass the qualified table name, instead of
    //      splitting it up into schema/catalog/table names
    String tableName = getValue().getTable().getQualifiedName( identifierGeneratorFactory.getDialect() );
    params.setProperty( PersistentIdentifierGenerator.TABLE, tableName );

    //pass the column name (a generated id almost always has a single column)
    if ( getSimpleValueSpan() > 1 ) {
        throw new MappingException(
                "A SimpleAttributeBinding used for an identifier has more than 1 Value: " + getAttribute().getName()
        );
    }
    SimpleValue simpleValue = (SimpleValue) getValue();
    if ( !Column.class.isInstance( simpleValue ) ) {
        throw new MappingException(
                "Cannot create an IdentifierGenerator because the value is not a column: " +
                        simpleValue.toLoggableString()
        );
    }
    params.setProperty(
            PersistentIdentifierGenerator.PK,
            ( (Column) simpleValue ).getColumnName().encloseInQuotesIfQuoted(
                    identifierGeneratorFactory.getDialect()
            )
    );

    // TODO: is this stuff necessary for SimpleValue???
    //if (rootClass!=null) {
    //  StringBuffer tables = new StringBuffer();
    //  Iterator iter = rootClass.getIdentityTables().iterator();
    //  while ( iter.hasNext() ) {
    //      Table table= (Table) iter.next();
    //      tables.append( table.getQuotedName(dialect) );
    //      if ( iter.hasNext() ) tables.append(", ");
    //  }
    //  params.setProperty( PersistentIdentifierGenerator.TABLES, tables.toString() );
    //}
    //else {
    params.setProperty( PersistentIdentifierGenerator.TABLES, tableName );
    //}

    params.putAll( idGenerator.getParameters() );

    return identifierGeneratorFactory.createIdentifierGenerator(
            idGenerator.getStrategy(), getHibernateTypeDescriptor().getResolvedTypeMapping(), params
    );
}
项目:lams    文件:EntityIdentifier.java   
public IdentifierGenerator createIdentifierGenerator(IdentifierGeneratorFactory factory, Properties properties) {
    if ( idGenerator != null ) {
        identifierGenerator = attributeBinding.createIdentifierGenerator( idGenerator, factory, properties );
    }
    return identifierGenerator;
}
项目:lams    文件:MetadataImpl.java   
@Override
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
    return identifierGeneratorFactory;
}
项目:lams    文件:SessionFactoryImpl.java   
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
    return null;
}
项目:hibernate-dynamic-dialects    文件:SessionFactoryImpl.java   
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
    return null;
}
项目:lams    文件:Mapping.java   
/**
 * Allow access to the id generator factory, though this is only needed/allowed from configuration.
 *
 * @return Access to the identifier generator factory
 *
 * @deprecated temporary solution 
 */
@Deprecated
public IdentifierGeneratorFactory getIdentifierGeneratorFactory();
项目:lams    文件:KeyValue.java   
public boolean isIdentityColumn(IdentifierGeneratorFactory identifierGeneratorFactory, Dialect dialect);