Java 类org.hibernate.id.IdentifierGenerator 实例源码

项目: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;
}
项目:lams    文件:IdentifierProperty.java   
/**
 * Construct a non-virtual identifier property.
 *
 * @param name The name of the property representing the identifier within
 * its owning entity.
 * @param node The node name to use for XML-based representation of this
 * property.
 * @param type The Hibernate Type for the identifier property.
 * @param embedded Is this an embedded identifier.
 * @param unsavedValue The value which, if found as the value on the identifier
 * property, represents new (i.e., un-saved) instances of the owning entity.
 * @param identifierGenerator The generator to use for id value generation.
 */
public IdentifierProperty(
        String name,
        String node,
        Type type,
        boolean embedded,
        IdentifierValue unsavedValue,
        IdentifierGenerator identifierGenerator) {
    super( name, type );
    this.virtual = false;
    this.embedded = embedded;
    this.hasIdentifierMapper = false;
    this.unsavedValue = unsavedValue;
    this.identifierGenerator = identifierGenerator;
    this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
项目:cacheonix-core    文件:IdentifierProperty.java   
/**
 * Construct a non-virtual identifier property.
 *
 * @param name The name of the property representing the identifier within
 * its owning entity.
 * @param node The node name to use for XML-based representation of this
 * property.
 * @param type The Hibernate Type for the identifier property.
 * @param embedded Is this an embedded identifier.
 * @param unsavedValue The value which, if found as the value on the identifier
 * property, represents new (i.e., un-saved) instances of the owning entity.
 * @param identifierGenerator The generator to use for id value generation.
 */
public IdentifierProperty(
        String name,
        String node,
        Type type,
        boolean embedded,
        IdentifierValue unsavedValue,
        IdentifierGenerator identifierGenerator) {
    super(name, node, type);
    this.virtual = false;
    this.embedded = embedded;
    this.hasIdentifierMapper = false;
    this.unsavedValue = unsavedValue;
    this.identifierGenerator = identifierGenerator;
    this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
项目:gomall.la    文件:UIDGenerator.java   
/**
 * The main method.
 * 
 * @param args
 *            the arguments
 * @throws Exception
 *             the exception
 */
public static void main(String[] args) throws Exception {
    Properties props = new Properties();
    props.setProperty("separator", "");
    IdentifierGenerator gen = new UIDGenerator();
    ((Configurable) gen).configure(Hibernate.STRING, props, null);
    IdentifierGenerator gen2 = new UIDGenerator();
    ((Configurable) gen2).configure(Hibernate.STRING, props, null);

    for (int i = 0; i < 10; i++) {
        String id = (String) gen.generate(null, gen);
        System.out.println(id);
        String id2 = (String) gen2.generate(null, gen2);
        System.out.println(id2);
    }

}
项目:dockyard-controller    文件:NewMetadataBuilder.java   
private String getGeneratorType(AbstractEntityPersister entityPersister) {

        String generatorType = null;

        IdentifierGenerator generator = entityPersister != null ? entityPersister.getIdentifierGenerator() : null;
        if (generator != null) {
            if (generator instanceof IdentityGenerator)
                generatorType = "Identity";
            else if (generator instanceof Assigned)
                generatorType = "None";
            else
                generatorType = "KeyGenerator";
        }

        return generatorType;

    }
项目:lams    文件:Component.java   
public ValueGenerationPlan(
        String propertyName,
        IdentifierGenerator subGenerator,
        Setter injector) {
    this.propertyName = propertyName;
    this.subGenerator = subGenerator;
    this.injector = injector;
}
项目:lams    文件:Binder.java   
private void bindSimpleIdentifier(SimpleIdentifierSource identifierSource, EntityBinding entityBinding) {
    final BasicAttributeBinding idAttributeBinding = doBasicSingularAttributeBindingCreation(
            identifierSource.getIdentifierAttributeSource(), entityBinding
    );

    entityBinding.getHierarchyDetails().getEntityIdentifier().setValueBinding( idAttributeBinding );
    IdGenerator generator = identifierSource.getIdentifierGeneratorDescriptor();
    if ( generator == null ) {
        Map<String, String> params = new HashMap<String, String>();
        params.put( IdentifierGenerator.ENTITY_NAME, entityBinding.getEntity().getName() );
        generator = new IdGenerator( "default_assign_identity_generator", "assigned", params );
    }
    entityBinding.getHierarchyDetails()
            .getEntityIdentifier()
            .setIdGenerator( generator );

    final org.hibernate.metamodel.relational.Value relationalValue = idAttributeBinding.getValue();

    if ( SimpleValue.class.isInstance( relationalValue ) ) {
        if ( !Column.class.isInstance( relationalValue ) ) {
            // this should never ever happen..
            throw new AssertionFailure( "Simple-id was not a column." );
        }
        entityBinding.getPrimaryTable().getPrimaryKey().addColumn( Column.class.cast( relationalValue ) );
    }
    else {
        for ( SimpleValue subValue : ( (Tuple) relationalValue ).values() ) {
            if ( Column.class.isInstance( subValue ) ) {
                entityBinding.getPrimaryTable().getPrimaryKey().addColumn( Column.class.cast( subValue ) );
            }
        }
    }
}
项目:lams    文件:IdentifierProperty.java   
/**
 * Construct a virtual IdentifierProperty.
 *
 * @param type The Hibernate Type for the identifier property.
 * @param embedded Is this an embedded identifier.
 * @param unsavedValue The value which, if found as the value on the identifier
 * property, represents new (i.e., un-saved) instances of the owning entity.
 * @param identifierGenerator The generator to use for id value generation.
 */
public IdentifierProperty(
        Type type,
        boolean embedded,
        boolean hasIdentifierMapper,
        IdentifierValue unsavedValue,
        IdentifierGenerator identifierGenerator) {
    super( null, type );
    this.virtual = true;
    this.embedded = embedded;
    this.hasIdentifierMapper = hasIdentifierMapper;
    this.unsavedValue = unsavedValue;
    this.identifierGenerator = identifierGenerator;
    this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
项目:lams    文件:PropertyFactory.java   
/**
 * Generates the attribute representation of the identifier for a given entity mapping.
 *
 * @param mappedEntity The mapping definition of the entity.
 * @param generator The identifier value generator to use for this identifier.
 * @return The appropriate IdentifierProperty definition.
 */
public static IdentifierProperty buildIdentifierAttribute(
        PersistentClass mappedEntity,
        IdentifierGenerator generator) {
    String mappedUnsavedValue = mappedEntity.getIdentifier().getNullValue();
    Type type = mappedEntity.getIdentifier().getType();
    Property property = mappedEntity.getIdentifierProperty();

    IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue(
            mappedUnsavedValue,
            getGetter( property ),
            type,
            getConstructor(mappedEntity)
        );

    if ( property == null ) {
        // this is a virtual id property...
        return new IdentifierProperty(
                type,
                mappedEntity.hasEmbeddedIdentifier(),
                mappedEntity.hasIdentifierMapper(),
                unsavedValue,
                generator
            );
    }
    else {
        return new IdentifierProperty(
                property.getName(),
                property.getNodeName(),
                type,
                mappedEntity.hasEmbeddedIdentifier(),
                unsavedValue,
                generator
            );
    }
}
项目:lams    文件:DefaultIdentifierGeneratorFactory.java   
@Override
public IdentifierGenerator createIdentifierGenerator(String strategy, Type type, Properties config) {
    try {
        Class clazz = getIdentifierGeneratorClass( strategy );
        IdentifierGenerator identifierGenerator = ( IdentifierGenerator ) clazz.newInstance();
        if ( identifierGenerator instanceof Configurable ) {
            ( ( Configurable ) identifierGenerator ).configure( type, config, dialect );
        }
        return identifierGenerator;
    }
    catch ( Exception e ) {
        final String entityName = config.getProperty( IdentifierGenerator.ENTITY_NAME );
        throw new MappingException( String.format( "Could not instantiate id generator [entity-name=%s]", entityName ), e );
    }
}
项目:lams    文件:FileUtil.java   
public static String generateUniqueContentFolderID() {
IdentifierGenerator uuidGen = new UUIDGenerator();
((Configurable) uuidGen).configure(StringType.INSTANCE, new Properties(), null);

// lowercase to resolve OS issues
return ((String) uuidGen.generate(null, null)).toLowerCase();
   }
项目:lams    文件:ForgotPasswordServlet.java   
/**
    * Generates the unique key used for the forgot password request
    *
    * @return a unique key
    * @throws FileUtilException
    * @throws IOException
    */
   public static String generateUniqueKey() {
Properties props = new Properties();

IdentifierGenerator uuidGen = new UUIDGenerator();
((Configurable) uuidGen).configure(StringType.INSTANCE, props, null);

return ((String) uuidGen.generate(null, null)).toLowerCase();
   }
项目:cacheonix-core    文件:IdentifierProperty.java   
/**
 * Construct a virtual IdentifierProperty.
 *
 * @param type The Hibernate Type for the identifier property.
 * @param embedded Is this an embedded identifier.
 * @param unsavedValue The value which, if found as the value on the identifier
 * property, represents new (i.e., un-saved) instances of the owning entity.
 * @param identifierGenerator The generator to use for id value generation.
 */
public IdentifierProperty(
        Type type,
        boolean embedded,
        boolean hasIdentifierMapper,
        IdentifierValue unsavedValue,
        IdentifierGenerator identifierGenerator) {
    super(null, null, type);
    this.virtual = true;
    this.embedded = embedded;
    this.hasIdentifierMapper = hasIdentifierMapper;
    this.unsavedValue = unsavedValue;
    this.identifierGenerator = identifierGenerator;
    this.identifierAssignedByInsert = identifierGenerator instanceof PostInsertIdentifierGenerator;
}
项目:cacheonix-core    文件:PropertyFactory.java   
/**
 * Generates an IdentifierProperty representation of the for a given entity mapping.
 *
 * @param mappedEntity The mapping definition of the entity.
 * @param generator The identifier value generator to use for this identifier.
 * @return The appropriate IdentifierProperty definition.
 */
public static IdentifierProperty buildIdentifierProperty(PersistentClass mappedEntity, IdentifierGenerator generator) {

    String mappedUnsavedValue = mappedEntity.getIdentifier().getNullValue();
    Type type = mappedEntity.getIdentifier().getType();
    Property property = mappedEntity.getIdentifierProperty();

    IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue(
            mappedUnsavedValue,
            getGetter( property ),
            type,
            getConstructor(mappedEntity)
        );

    if ( property == null ) {
        // this is a virtual id property...
        return new IdentifierProperty(
                type,
                mappedEntity.hasEmbeddedIdentifier(),
                mappedEntity.hasIdentifierMapper(),
                unsavedValue,
                generator
            );
    }
    else {
        return new IdentifierProperty(
                property.getName(),
                property.getNodeName(),
                type,
                mappedEntity.hasEmbeddedIdentifier(),
                unsavedValue,
                generator
            );
    }
}
项目:lemon    文件:SessionFactoryWrapper.java   
public IdentifierGenerator getIdentifierGenerator(String rootEntityName) {
    return sessionFactoryImplementor.getIdentifierGenerator(rootEntityName);
}
项目: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    文件: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    文件:EntityIdentifier.java   
public IdentifierGenerator getIdentifierGenerator() {
    return identifierGenerator;
}
项目:lams    文件:AbstractEntityPersister.java   
public IdentifierGenerator getIdentifierGenerator() throws HibernateException {
    return entityMetamodel.getIdentifierProperty().getIdentifierGenerator();
}
项目:lams    文件:AbstractCollectionPersister.java   
@Override
public IdentifierGenerator getIdentifierGenerator() {
    return identifierGenerator;
}
项目:lams    文件:IdentifierProperty.java   
@Override
public IdentifierGenerator getIdentifierGenerator() {
    return identifierGenerator;
}
项目:lams    文件:PropertyFactory.java   
/**
 * Generates an IdentifierProperty representation of the for a given entity mapping.
 *
 * @param mappedEntity The mapping definition of the entity.
 * @param generator The identifier value generator to use for this identifier.
 * @return The appropriate IdentifierProperty definition.
 */
public static IdentifierProperty buildIdentifierProperty(
        EntityBinding mappedEntity,
        IdentifierGenerator generator) {

    final BasicAttributeBinding property = mappedEntity.getHierarchyDetails().getEntityIdentifier().getValueBinding();

    // TODO: the following will cause an NPE with "virtual" IDs; how should they be set?
    // (steve) virtual attributes will still be attributes, they will simply be marked as virtual.
    //      see org.hibernate.metamodel.domain.AbstractAttributeContainer.locateOrCreateVirtualAttribute()

    final String mappedUnsavedValue = property.getUnsavedValue();
    final Type type = property.getHibernateTypeDescriptor().getResolvedTypeMapping();

    IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue(
            mappedUnsavedValue,
            getGetter( property ),
            type,
            getConstructor( mappedEntity )
        );

    if ( property == null ) {
        // this is a virtual id property...
        return new IdentifierProperty(
                type,
                mappedEntity.getHierarchyDetails().getEntityIdentifier().isEmbedded(),
                mappedEntity.getHierarchyDetails().getEntityIdentifier().isIdentifierMapper(),
                unsavedValue,
                generator
            );
    }
    else {
        return new IdentifierProperty(
                property.getAttribute().getName(),
                null,
                type,
                mappedEntity.getHierarchyDetails().getEntityIdentifier().isEmbedded(),
                unsavedValue,
                generator
            );
    }
}
项目:lams    文件:SessionFactoryImpl.java   
public IdentifierGenerator getIdentifierGenerator(String rootEntityName) {
    return identifierGenerators.get(rootEntityName);
}
项目:Layer-Query    文件:DinamicEntityPersister.java   
@Override
public IdentifierGenerator getIdentifierGenerator() {
    // TODO Auto-generated method stub
    return null;
}
项目:cacheonix-core    文件:KeyValue.java   
public IdentifierGenerator createIdentifierGenerator(
Dialect dialect, 
String defaultCatalog, 
String defaultSchema, 
RootClass rootClass) throws MappingException;
项目:cacheonix-core    文件:SimpleValue.java   
public IdentifierGenerator createIdentifierGenerator(
        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() );
    }

    //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) {
        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 );
    }

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

    return IdentifierGeneratorFactory.create(
            identifierGeneratorStrategy,
            getType(),
            params,
            dialect
        );

}
项目:cacheonix-core    文件:AbstractEntityPersister.java   
public IdentifierGenerator getIdentifierGenerator() throws HibernateException {
    return entityMetamodel.getIdentifierProperty().getIdentifierGenerator();
}
项目:cacheonix-core    文件:AbstractCollectionPersister.java   
public IdentifierGenerator getIdentifierGenerator() {
    return identifierGenerator;
}
项目:cacheonix-core    文件:IdentifierProperty.java   
public IdentifierGenerator getIdentifierGenerator() {
    return identifierGenerator;
}
项目:cacheonix-core    文件:SessionFactoryImpl.java   
public IdentifierGenerator getIdentifierGenerator(String rootEntityName) {
    return (IdentifierGenerator) identifierGenerators.get(rootEntityName);
}
项目:cacheonix-core    文件:HqlSqlWalker.java   
public static boolean supportsIdGenWithBulkInsertion(IdentifierGenerator generator) {
    return SequenceGenerator.class.isAssignableFrom( generator.getClass() )
            || PostInsertIdentifierGenerator.class.isAssignableFrom( generator.getClass() );
}
项目:cacheonix-core    文件:CustomPersister.java   
/**
 * @see EntityPersister#getIdentifierGenerator()
 */
public IdentifierGenerator getIdentifierGenerator()
throws HibernateException {
    return GENERATOR;
}
项目:cacheonix-core    文件:BulkManipulationTest.java   
public void testInsertWithGeneratedId() {
    // Make sure the env supports bulk inserts with generated ids...
    EntityPersister persister = sfi().getEntityPersister( PettingZoo.class.getName() );
    IdentifierGenerator generator = persister.getIdentifierGenerator();
    if ( !HqlSqlWalker.supportsIdGenWithBulkInsertion( generator ) ) {
        return;
    }

    // create a Zoo
    Zoo zoo = new Zoo();
    zoo.setName( "zoo" );

    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.save( zoo );
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    int count = s.createQuery( "insert into PettingZoo (name) select name from Zoo" ).executeUpdate();
    t.commit();
    s.close();

    assertEquals( "unexpected insertion count", 1, count );

    s = openSession();
    t = s.beginTransaction();
    PettingZoo pz = ( PettingZoo ) s.createQuery( "from PettingZoo" ).uniqueResult();
    t.commit();
    s.close();

    assertEquals( zoo.getName(), pz.getName() );
    assertTrue( zoo.getId() != pz.getId() );

    s = openSession();
    t = s.beginTransaction();
    s.createQuery( "delete Zoo" ).executeUpdate();
    t.commit();
    s.close();
}
项目:cacheonix-core    文件:BulkManipulationTest.java   
public void testInsertWithGeneratedVersionAndId() {
    // Make sure the env supports bulk inserts with generated ids...
    EntityPersister persister = sfi().getEntityPersister( IntegerVersioned.class.getName() );
    IdentifierGenerator generator = persister.getIdentifierGenerator();
    if ( !HqlSqlWalker.supportsIdGenWithBulkInsertion( generator ) ) {
        return;
    }

    Session s = openSession();
    Transaction t = s.beginTransaction();

    IntegerVersioned entity = new IntegerVersioned( "int-vers" );
    s.save( entity );
    s.createQuery( "select id, name, version from IntegerVersioned" ).list();
    t.commit();
    s.close();

    Long initialId = entity.getId();
    int initialVersion = entity.getVersion();

    s = openSession();
    t = s.beginTransaction();
    int count = s.createQuery( "insert into IntegerVersioned ( name ) select name from IntegerVersioned" ).executeUpdate();
    t.commit();
    s.close();

    assertEquals( "unexpected insertion count", 1, count );

    s = openSession();
    t = s.beginTransaction();
    IntegerVersioned created = ( IntegerVersioned ) s.createQuery( "from IntegerVersioned where id <> :initialId" )
            .setLong( "initialId", initialId.longValue() )
            .uniqueResult();
    t.commit();
    s.close();

    assertEquals( "version was not seeded", initialVersion, created.getVersion() );

    s = openSession();
    t = s.beginTransaction();
    s.createQuery( "delete IntegerVersioned" ).executeUpdate();
    t.commit();
    s.close();
}
项目:cacheonix-core    文件:BulkManipulationTest.java   
public void testInsertWithGeneratedTimestampVersion() {
    // Make sure the env supports bulk inserts with generated ids...
    EntityPersister persister = sfi().getEntityPersister( TimestampVersioned.class.getName() );
    IdentifierGenerator generator = persister.getIdentifierGenerator();
    if ( !HqlSqlWalker.supportsIdGenWithBulkInsertion( generator ) ) {
        return;
    }

    Session s = openSession();
    Transaction t = s.beginTransaction();

    TimestampVersioned entity = new TimestampVersioned( "int-vers" );
    s.save( entity );
    s.createQuery( "select id, name, version from TimestampVersioned" ).list();
    t.commit();
    s.close();

    Long initialId = entity.getId();
    //Date initialVersion = entity.getVersion();

    s = openSession();
    t = s.beginTransaction();
    int count = s.createQuery( "insert into TimestampVersioned ( name ) select name from TimestampVersioned" ).executeUpdate();
    t.commit();
    s.close();

    assertEquals( "unexpected insertion count", 1, count );

    s = openSession();
    t = s.beginTransaction();
    TimestampVersioned created = ( TimestampVersioned ) s.createQuery( "from TimestampVersioned where id <> :initialId" )
            .setLong( "initialId", initialId.longValue() )
            .uniqueResult();
    t.commit();
    s.close();

    assertNotNull( created.getVersion() );
    //assertEquals( "version was not seeded", initialVersion, created.getVersion() );

    s = openSession();
    t = s.beginTransaction();
    s.createQuery( "delete TimestampVersioned" ).executeUpdate();
    t.commit();
    s.close();
}
项目:hibernate-semantic-query    文件:CollectionId.java   
public CollectionId(BasicType type, IdentifierGenerator generator) {
    this.type = type;
    this.generator = generator;
}
项目:hibernate-semantic-query    文件:CollectionId.java   
public IdentifierGenerator getGenerator() {
    return generator;
}