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

项目:lams    文件:DefaultIdentifierGeneratorFactory.java   
/**
 * Constructs a new DefaultIdentifierGeneratorFactory.
 */
public DefaultIdentifierGeneratorFactory() {
    register( "uuid2", UUIDGenerator.class );
    register( "guid", GUIDGenerator.class );            // can be done with UUIDGenerator + strategy
    register( "uuid", UUIDHexGenerator.class );         // "deprecated" for new use
    register( "uuid.hex", UUIDHexGenerator.class );     // uuid.hex is deprecated
    register( "hilo", TableHiLoGenerator.class );
    register( "assigned", Assigned.class );
    register( "identity", IdentityGenerator.class );
    register( "select", SelectGenerator.class );
    register( "sequence", SequenceGenerator.class );
    register( "seqhilo", SequenceHiLoGenerator.class );
    register( "increment", IncrementGenerator.class );
    register( "foreign", ForeignGenerator.class );
    register( "sequence-identity", SequenceIdentityGenerator.class );
    register( "enhanced-sequence", SequenceStyleGenerator.class );
    register( "enhanced-table", TableGenerator.class );
}
项目: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    文件:Dialect.java   
/**
 * The class (which implements {@link org.hibernate.id.IdentifierGenerator})
 * which acts as this dialects native generation strategy.
 * <p/>
 * Comes into play whenever the user specifies the native generator.
 *
 * @return The native generator class.
 */
public Class getNativeIdentifierGeneratorClass() {
    if ( supportsIdentityColumns() ) {
        return IdentityGenerator.class;
    }
    else if ( supportsSequences() ) {
        return SequenceGenerator.class;
    }
    else {
        return TableHiLoGenerator.class;
    }
}
项目:cacheonix-core    文件:Dialect.java   
/**
 * The class (which implements {@link org.hibernate.id.IdentifierGenerator})
 * which acts as this dialects native generation strategy.
 * <p/>
 * Comes into play whenever the user specifies the native generator.
 *
 * @return The native generator class.
 */
public Class getNativeIdentifierGeneratorClass() {
    if ( supportsIdentityColumns() ) {
        return IdentityGenerator.class;
    }
    else if ( supportsSequences() ) {
        return SequenceGenerator.class;
    }
    else {
        return TableHiLoGenerator.class;
    }
}
项目:lams    文件:SimpleValue.java   
public boolean isIdentityColumn(IdentifierGeneratorFactory identifierGeneratorFactory, Dialect dialect) {
    identifierGeneratorFactory.setDialect( dialect );
    return identifierGeneratorFactory.getIdentifierGeneratorClass( identifierGeneratorStrategy )
            .equals( IdentityGenerator.class );
}
项目:lams    文件:Cache71Dialect.java   
@Override
public Class getNativeIdentifierGeneratorClass() {
    return IdentityGenerator.class;
}
项目:cacheonix-core    文件:SimpleValue.java   
public boolean isIdentityColumn(Dialect dialect) {
    return IdentifierGeneratorFactory.getIdentifierGeneratorClass(identifierGeneratorStrategy, dialect)
            .equals(IdentityGenerator.class);
}
项目:cacheonix-core    文件:Cache71Dialect.java   
public Class getNativeIdentifierGeneratorClass() {
    return IdentityGenerator.class;
}
项目:breeze.server.java    文件:HibernateMetadata.java   
/**
 * Add the metadata for an entity.
 * 
 * @param meta
 */
void addClass(ClassMetadata meta) {
    Class type = meta.getMappedClass();

    String classKey = getEntityTypeName(type);
    HashMap<String, Object> cmap = new LinkedHashMap<String, Object>();
    _typeList.add(cmap);

    cmap.put("shortName", type.getSimpleName());
    cmap.put("namespace", type.getPackage().getName());

    EntityMetamodel metaModel = ((EntityPersister) meta).getEntityMetamodel();
    String superTypeName = metaModel.getSuperclass();
    if (superTypeName != null) {
        ClassMetadata superMeta = _sessionFactory.getClassMetadata(superTypeName);
        if (superMeta != null) {
            Class superClass = superMeta.getMappedClass();
            cmap.put("baseTypeName", getEntityTypeName(superClass));
        }
    }

    String genType = "None";
    if (meta instanceof EntityPersister) {
        EntityPersister entityPersister = (EntityPersister) meta;
        // multipart keys can never have an AutoGeneratedKeyType
        if (entityPersister.hasIdentifierProperty()) {
            IdentifierGenerator generator = entityPersister != null
                    ? entityPersister.getIdentifierGenerator()
                    : null;
            if (generator != null) {
                if (generator instanceof IdentityGenerator) {
                    genType = "Identity";
                } else if (generator instanceof Assigned || generator instanceof ForeignGenerator) {
                    genType = "None";
                } else {
                    genType = "KeyGenerator";
                }
                // TODO find the real generator
            }
        }
    }
    cmap.put("autoGeneratedKeyType", genType);

    String resourceName = pluralize(type.getSimpleName()); // TODO find the real name
    cmap.put("defaultResourceName", resourceName);
    _resourceMap.put(resourceName, classKey);

    ArrayList<HashMap<String, Object>> dataArrayList = new ArrayList<HashMap<String, Object>>();
    cmap.put("dataProperties", dataArrayList);
    ArrayList<HashMap<String, Object>> navArrayList = new ArrayList<HashMap<String, Object>>();
    cmap.put("navigationProperties", navArrayList);

    addClassProperties(meta, dataArrayList, navArrayList);
}
项目:dockyard-controller    文件:MetadataBuilder.java   
/**
 * Add the metadata for an entity.
 * @param meta
 */
void addClass(ClassMetadata meta) {

    Class type = meta.getMappedClass();

    String classKey = getEntityTypeName(type);
    HashMap<String, Object> cmap = new LinkedHashMap<String, Object>();
    typeList.add(cmap);

    cmap.put("shortName", type.getSimpleName());
    cmap.put("namespace", type.getPackage().getName());

    if (meta instanceof AbstractEntityPersister) {

        AbstractEntityPersister entityPersister = (AbstractEntityPersister) meta;
        String superClassEntityName = entityPersister.getMappedSuperclass();

        if (superClassEntityName != null) {
            Class superType = this.sessionFactory.getClassMetadata(superClassEntityName).getMappedClass();
            String baseTypeName = this.getEntityTypeName(superType);
            cmap.put("baseTypeName", baseTypeName);
        }

        IdentifierGenerator generator = entityPersister != null ? entityPersister.getIdentifierGenerator() : null;
        if (generator != null) {
            String genType = null;

            if (generator instanceof IdentityGenerator)
                genType = "Identity";
            else if (generator instanceof Assigned)
                genType = "None";
            else
                genType = "KeyGenerator";

            cmap.put("autoGeneratedKeyType", genType); // TODO find the real generator
        }
    }


    String resourceName = pluralize(type.getSimpleName()); // TODO find the real name
    cmap.put("defaultResourceName", resourceName);
    resourceMap.put(resourceName, classKey);

    ArrayList<HashMap<String, Object>> dataArrayList = new ArrayList<HashMap<String, Object>>();
    cmap.put("dataProperties", dataArrayList);

    ArrayList<HashMap<String, Object>> navArrayList = new ArrayList<HashMap<String, Object>>();
    cmap.put("navigationProperties", navArrayList);

    try {
        this.addClassProperties(meta, dataArrayList, navArrayList);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:parkingfriends    文件:JHipsterTableSnapshotGenerator.java   
@Override
protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException {
    HibernateDatabase database = (HibernateDatabase) snapshot.getDatabase();
    Configuration cfg = database.getConfiguration();

    Dialect dialect = database.getDialect();
    Mapping mapping = cfg.buildMapping();

    org.hibernate.mapping.Table hibernateTable = findHibernateTable(example, snapshot);
    if (hibernateTable == null) {
        return null;
    }

    Table table = new Table().setName(hibernateTable.getName());
    PrimaryKey primaryKey = null;
    int pkColumnPosition = 0;
    LOG.info("Found table " + table.getName());

    table.setSchema(example.getSchema());

    Iterator columnIterator = hibernateTable.getColumnIterator();
    while (columnIterator.hasNext()) {
        org.hibernate.mapping.Column hibernateColumn = (org.hibernate.mapping.Column) columnIterator.next();
        Column column = new Column();
        column.setName(hibernateColumn.getName());

        String hibernateType = hibernateColumn.getSqlType(dialect, mapping);
        DataType dataType = toDataType(hibernateType, hibernateColumn.getSqlTypeCode());
        if (dataType == null) {
            throw new DatabaseException("Unable to find column data type for column " + hibernateColumn.getName());
        }

        column.setType(dataType);
        LOG.info("Found column " + column.getName() + " " + column.getType().toString());

        column.setRemarks(hibernateColumn.getComment());
        column.setDefaultValue(hibernateColumn.getDefaultValue());
        column.setNullable(hibernateColumn.isNullable());
        column.setCertainDataType(false);

        org.hibernate.mapping.PrimaryKey hibernatePrimaryKey = hibernateTable.getPrimaryKey();
        if (hibernatePrimaryKey != null) {
            boolean isPrimaryKeyColumn = false;
            //noinspection unchecked
            for (org.hibernate.mapping.Column pkColumn : (List<org.hibernate.mapping.Column>) hibernatePrimaryKey.getColumns()) {
                if (pkColumn.getName().equals(hibernateColumn.getName())) {
                    isPrimaryKeyColumn = true;
                    break;
                }
            }

            if (isPrimaryKeyColumn) {
                if (primaryKey == null) {
                    primaryKey = new PrimaryKey();
                    primaryKey.setName(hibernatePrimaryKey.getName());
                }
                primaryKey.addColumnName(pkColumnPosition++, column.getName());

                LiquibaseDataType liquibaseDataType = DataTypeFactory
            .getInstance().from(column.getType());
    // only columns types supporting auto increment -
    // DataTypeFactory
    if (isAutoIncrement(liquibaseDataType)) {

        if (dialect.getNativeIdentifierGeneratorClass().equals(
                IdentityGenerator.class)) {
            column.setAutoIncrementInformation(new Column.AutoIncrementInformation());
        }
    }
            }
        }
        column.setRelation(table);

        table.setPrimaryKey(primaryKey);
        table.getColumns().add(column);

    }

    return table;
}