Example usage for javax.persistence GenerationType SEQUENCE

List of usage examples for javax.persistence GenerationType SEQUENCE

Introduction

In this page you can find the example usage for javax.persistence GenerationType SEQUENCE.

Prototype

GenerationType SEQUENCE

To view the source code for javax.persistence GenerationType SEQUENCE.

Click Source Link

Document

Indicates that the persistence provider must assign primary keys for the entity using a database sequence.

Usage

From source file:org.opennms.netmgt.model.OnmsEvent.java

/**
 * <p>getId</p>/*from   ww w.j  a v a  2  s  .  c o  m*/
 *
 * @return a {@link java.lang.Integer} object.
 */
@Id
@XmlAttribute(name = "id")
@Column(name = "eventId", nullable = false)
@SequenceGenerator(name = "eventSequence", sequenceName = "eventsNxtId")
@GeneratedValue(generator = "eventSequence", strategy = GenerationType.SEQUENCE)
public Integer getId() {
    return m_eventId;
}

From source file:com.mmnaseri.dragonfly.metadata.impl.AnnotationTableMetadataResolver.java

private ValueGenerationType determineValueGenerationType(Method method) {
    if (method.isAnnotationPresent(GeneratedValue.class)) {
        final GeneratedValue generatedValue = method.getAnnotation(GeneratedValue.class);
        return generatedValue.strategy().equals(GenerationType.AUTO) ? dialect.getDefaultGenerationType()
                : (generatedValue.strategy().equals(GenerationType.IDENTITY) ? ValueGenerationType.IDENTITY
                        : (generatedValue.strategy().equals(GenerationType.SEQUENCE)
                                ? ValueGenerationType.SEQUENCE
                                : (generatedValue.strategy().equals(GenerationType.TABLE)
                                        ? ValueGenerationType.TABLE
                                        : null)));
    } else {//  w  w  w  . j  a  v a 2  s .  c o  m
        return null;
    }
}

From source file:org.fao.geonet.domain.Address.java

/**
 * Id of the address. This is automatically generated so when creating a new object leave this
 * blank and allow the database or JPA set the value for you on save.
 *///from   w  w  w .j  av  a  2 s. c  o m
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = ID_SEQ_NAME)
public int getId() {
    return _id;
}

From source file:org.grails.datastore.gorm.jpa.GormToJpaTransform.java

public static void transformEntity(SourceUnit source, ClassNode classNode) {

    // add the JPA @Entity annotation
    classNode.addAnnotation(ANNOTATION_ENTITY);
    final AnnotationNode entityListenersAnnotation = new AnnotationNode(new ClassNode(EntityListeners.class));
    entityListenersAnnotation.addMember("value",
            new ClassExpression(new ClassNode(EntityInterceptorInvokingEntityListener.class)));
    classNode.addAnnotation(entityListenersAnnotation);

    PropertyNode mappingNode = classNode.getProperty(GrailsDomainClassProperty.MAPPING);
    Map<String, Map<String, ?>> propertyMappings = new HashMap<String, Map<String, ?>>();
    if (mappingNode != null && mappingNode.isStatic()) {
        populateConfigurationMapFromClosureExpression(classNode, mappingNode, propertyMappings);
    }//w  w w  .j a v  a 2 s  .com

    // annotate the id property with @Id
    String idPropertyName = GrailsDomainClassProperty.IDENTITY;
    String generationType = GenerationType.AUTO.toString();

    final PropertyNode errorsProperty = classNode.getProperty("errors");
    if (errorsProperty == null) {
        if (ClassUtils.isPresent("org.codehaus.groovy.grails.compiler.injection.ASTValidationErrorsHelper",
                Thread.currentThread().getContextClassLoader())) {
            addErrorsProperty(classNode);
        }
    }

    if (propertyMappings.containsKey(GrailsDomainClassProperty.IDENTITY)) {
        final Map<String, ?> idConfig = propertyMappings.get(GrailsDomainClassProperty.IDENTITY);
        if (idConfig.containsKey("name")) {
            idPropertyName = idConfig.get("name").toString();
        }
        if (idConfig.containsKey("generator")) {
            String generatorName = idConfig.get("generator").toString();
            if ("assigned".equals(generatorName)) {
                generationType = null;
            } else if ("sequence".equals(generatorName)) {
                generationType = GenerationType.SEQUENCE.toString();
            } else if ("identity".equals(generatorName)) {
                generationType = GenerationType.IDENTITY.toString();
            }
        }
    }

    PropertyNode idProperty = classNode.getProperty(idPropertyName);
    if (idProperty == null) {
        new DefaultGrailsDomainClassInjector().performInjectionOnAnnotatedEntity(classNode);
        idProperty = classNode.getProperty(GrailsDomainClassProperty.IDENTITY);
    }

    if (!idPropertyName.equals(GrailsDomainClassProperty.IDENTITY)) {
        PropertyNode toDiscard = classNode.getProperty(GrailsDomainClassProperty.IDENTITY);
        if (toDiscard != null && toDiscard.getType().equals("java.lang.Long")) {
            classNode.getProperties().remove(toDiscard);
        }
    }

    if (idProperty != null) {
        final FieldNode idField = idProperty.getField();

        idField.addAnnotation(ANNOTATION_ID);
        if (generationType != null) {
            final AnnotationNode generatedValueAnnotation = new AnnotationNode(
                    new ClassNode(GeneratedValue.class));
            generatedValueAnnotation.addMember("strategy", new PropertyExpression(
                    new ClassExpression(new ClassNode(GenerationType.class)), generationType));
            idField.addAnnotation(generatedValueAnnotation);
        }
    }

    // annotate the version property with @Version
    PropertyNode versionProperty = classNode.getProperty(GrailsDomainClassProperty.VERSION);
    if (versionProperty != null) {
        if (propertyMappings.containsKey(GrailsDomainClassProperty.VERSION)) {
            final Map<String, ?> versionSettings = propertyMappings.get(GrailsDomainClassProperty.VERSION);
            final Object enabledObject = versionSettings.get("enabled");
            if (enabledObject instanceof Boolean) {
                if (((Boolean) enabledObject).booleanValue()) {
                    versionProperty.addAnnotation(ANNOTATION_VERSION);
                }
            }
        } else {
            versionProperty.addAnnotation(ANNOTATION_VERSION);
        }
    }

    final List<MethodNode> methods = classNode.getMethods();
    for (MethodNode methodNode : methods) {
        if (methodNode.isStatic() || !methodNode.isPublic() || methodNode.isAbstract()) {
            continue;
        }

        final AnnotationNode annotationNode = gormEventMethodToJpaAnnotation.get(methodNode.getName());
        if (annotationNode == null) {
            continue;
        }

        //methodNode.setReturnType(new ClassNode(void.class));
        methodNode.addAnnotation(annotationNode);
    }

    Map<String, ClassNode> hasManyMap = lookupStringToClassNodeMap(classNode,
            GrailsDomainClassProperty.HAS_MANY);
    Map<String, ClassNode> hasOneMap = lookupStringToClassNodeMap(classNode, GrailsDomainClassProperty.HAS_ONE);
    Map<String, ClassNode> belongsToMap = lookupStringToClassNodeMap(classNode,
            GrailsDomainClassProperty.BELONGS_TO);
    Map<String, String> mappedByMap = lookupStringToStringMap(classNode, GrailsDomainClassProperty.MAPPED_BY);

    final List<PropertyNode> properties = classNode.getProperties();
    for (PropertyNode propertyNode : properties) {
        if (!propertyNode.isPublic() || propertyNode.isStatic()) {
            continue;
        }

        if (propertyNode == idProperty || propertyNode == versionProperty) {
            continue;
        }

        final String typeName = propertyNode.getType().getName();

        if (typeName.equals("java.util.Date") || typeName.equals("java.util.Calendar")) {
            AnnotationNode temporalAnnotation = new AnnotationNode(new ClassNode(Temporal.class));
            temporalAnnotation.addMember("value",
                    new PropertyExpression(new ClassExpression(new ClassNode(TemporalType.class)), "DATE"));
            propertyNode.getField().addAnnotation(temporalAnnotation);
        } else if (MappingFactory.isSimpleType(typeName)) {
            propertyNode.getField().addAnnotation(ANNOTATION_BASIC);
        } else {
            final String propertyName = propertyNode.getName();
            if (!belongsToMap.containsKey(propertyName) && !hasOneMap.containsKey(propertyName)
                    && !hasManyMap.containsKey(propertyName)) {
                handleToOne(classNode, belongsToMap, propertyName);
            }
        }
    }

    final PropertyNode transientsProp = classNode.getProperty(GrailsDomainClassProperty.TRANSIENT);
    List<String> propertyNameList = new ArrayList<String>();
    populateConstantList(propertyNameList, transientsProp);
    annotateAllProperties(classNode, propertyNameList, Transient.class);

    propertyNameList.clear();
    final PropertyNode embeddedProp = classNode.getProperty(GrailsDomainClassProperty.EMBEDDED);
    populateConstantList(propertyNameList, embeddedProp);
    annotateAllProperties(classNode, propertyNameList, Embedded.class);

    if (embeddedProp != null) {
        for (String propertyName : propertyNameList) {
            final PropertyNode property = classNode.getProperty(propertyName);
            if (property == null) {
                continue;
            }

            ClassNode embeddedType = property.getField().getType();
            annotateIfNecessary(embeddedType, Embeddable.class);
        }
    }

    if (!belongsToMap.isEmpty()) {
        for (String propertyName : belongsToMap.keySet()) {
            handleToOne(classNode, belongsToMap, propertyName);
        }
    }

    if (!hasOneMap.isEmpty()) {
        for (String propertyName : hasOneMap.keySet()) {
            final AnnotationNode oneToOneAnnotation = new AnnotationNode(new ClassNode(OneToOne.class));
            oneToOneAnnotation.addMember("optional", ConstantExpression.FALSE);
            oneToOneAnnotation.addMember("cascade", EXPR_CASCADE_ALL);
            annotateProperty(classNode, propertyName, oneToOneAnnotation);
        }
    }

    if (!hasManyMap.isEmpty()) {
        for (String propertyName : hasManyMap.keySet()) {
            ClassNode associatedClass = hasManyMap.get(propertyName);
            final Map<String, ClassNode> inverseBelongsToMap = lookupStringToClassNodeMap(associatedClass,
                    GrailsDomainClassProperty.BELONGS_TO);
            final Map<String, ClassNode> inverseHasManyMap = lookupStringToClassNodeMap(associatedClass,
                    GrailsDomainClassProperty.HAS_MANY);

            final AnnotationNode oneToManyAnnotation = new AnnotationNode(new ClassNode(OneToMany.class));
            oneToManyAnnotation.addMember("targetEntity", new ClassExpression(associatedClass));

            if (mappedByMap.containsKey(propertyName)) {
                oneToManyAnnotation.addMember("mappedBy",
                        new ConstantExpression(mappedByMap.get(propertyName)));
                oneToManyAnnotation.addMember("cascade", EXPR_CASCADE_PERSIST);
                annotateProperty(classNode, propertyName, oneToManyAnnotation);
            } else {
                if (inverseHasManyMap.containsValue(classNode)) {
                    // many-to-many association
                    List<ClassNode> belongsToList = getBelongsToList(classNode);

                    final AnnotationNode manyToManyAnnotation = new AnnotationNode(
                            new ClassNode(ManyToMany.class));
                    manyToManyAnnotation.addMember("targetEntity", new ClassExpression(associatedClass));
                    if (belongsToList.contains(associatedClass)) {
                        for (String inversePropertyName : inverseHasManyMap.keySet()) {
                            if (classNode.equals(inverseHasManyMap.get(inversePropertyName))) {
                                manyToManyAnnotation.addMember("mappedBy",
                                        new ConstantExpression(inversePropertyName));
                            }
                        }
                    } else {
                        manyToManyAnnotation.addMember("cascade", EXPR_CASCADE_ALL);
                    }
                    annotateProperty(classNode, propertyName, manyToManyAnnotation);
                }
                // Try work out the other side of the association
                else if (inverseBelongsToMap.containsValue(classNode)) {
                    for (String inversePropertyName : inverseBelongsToMap.keySet()) {
                        if (classNode.equals(inverseBelongsToMap.get(inversePropertyName))) {
                            oneToManyAnnotation.addMember("mappedBy",
                                    new ConstantExpression(inversePropertyName));
                            oneToManyAnnotation.addMember("cascade", EXPR_CASCADE_ALL);
                        }
                    }
                    annotateProperty(classNode, propertyName, oneToManyAnnotation);
                } else {
                    PropertyNode inverseClosestMatch = findClosestInverstTypeMatch(classNode, associatedClass);
                    if (inverseClosestMatch != null) {
                        oneToManyAnnotation.addMember("mappedBy",
                                new ConstantExpression(inverseClosestMatch.getName()));
                    }
                    // unidrectional one-to-many
                    oneToManyAnnotation.addMember("cascade", EXPR_CASCADE_ALL);
                    annotateProperty(classNode, propertyName, oneToManyAnnotation);
                }
            }
        }
    }
}

From source file:org.guzz.builder.JPA2AnnotationsBuilder.java

protected static void addIdMapping(GuzzContextImpl gf, POJOBasedObjectMapping map, SimpleTable st,
        DBGroup dbGroup, String name, Class domainClas, AnnotatedElement element) {
    javax.persistence.Column pc = (javax.persistence.Column) element
            .getAnnotation(javax.persistence.Column.class);
    org.guzz.annotations.Column gc = (org.guzz.annotations.Column) element
            .getAnnotation(org.guzz.annotations.Column.class);

    String type = gc == null ? null : gc.type();
    String column = pc == null ? null : pc.name();

    if (StringUtil.isEmpty(column)) {
        column = name;/*from  w  w w  .ja  v a 2s  .c om*/
    }

    TableColumn col = st.getColumnByPropName(name);
    boolean newId = false;

    if (col == null) {
        newId = true;
        col = new TableColumn(st);
    } else {
        log.info("override @Id in the parent class of [" + st.getBusinessName() + "].");
    }

    col.setColName(column);
    col.setPropName(name);
    col.setType(type);
    col.setAllowInsert(true);
    col.setAllowUpdate(true);
    col.setLazy(false);
    map.initColumnMapping(col, null);

    if (newId) {
        st.addPKColumn(col);
    }

    //@Id generator
    javax.persistence.GeneratedValue pgv = (javax.persistence.GeneratedValue) element
            .getAnnotation(javax.persistence.GeneratedValue.class);
    if (pgv == null) {
        pgv = (javax.persistence.GeneratedValue) domainClas
                .getAnnotation(javax.persistence.GeneratedValue.class);
    }

    //If @GeneratedValue is not defined, use auto.
    GenerationType gt = GenerationType.AUTO;
    String generatorName = null;

    if (pgv != null) {
        gt = pgv.strategy();
        generatorName = pgv.generator();
    }

    Properties idProperties = new Properties();
    String igCls;

    if (gt == GenerationType.AUTO) {
        //??guzz@GenericGenerator
        if (StringUtil.notEmpty(generatorName)) {
            GenericGenerator ggg = (GenericGenerator) element.getAnnotation(GenericGenerator.class);
            if (ggg != null && !generatorName.equals(ggg.name())) {
                ggg = null;
            }

            if (ggg == null) {
                //retreive @Id from GlobalContext
                Object g = gf.getGlobalIdGenerator(generatorName);

                //should be GenericGenerator
                if (!(g instanceof GenericGenerator)) {
                    throw new IllegalParameterException("The Id Generator [" + generatorName
                            + "] should be of type @org.guzz.annotations.GenericGenerator. domain class:"
                            + domainClas.getName());
                }

                ggg = (GenericGenerator) g;
            }

            igCls = ggg.strategy();
            Parameter[] ps = ggg.parameters();

            for (Parameter p : ps) {
                idProperties.setProperty(p.name(), p.value());
            }
        } else {
            //nativegeneratordialect?
            igCls = "native";
        }
    } else if (gt == GenerationType.IDENTITY) {
        igCls = "identity";
    } else if (gt == GenerationType.SEQUENCE) {
        igCls = "sequence";

        javax.persistence.SequenceGenerator psg = (javax.persistence.SequenceGenerator) element
                .getAnnotation(javax.persistence.SequenceGenerator.class);
        if (psg == null) {
            Object sg = gf.getGlobalIdGenerator(generatorName);
            Assert.assertNotNull(sg,
                    "@javax.persistence.SequenceGenerator not found for sequenced @Id. domain class:"
                            + domainClas.getName());

            if (sg instanceof SequenceGenerator) {
                psg = (SequenceGenerator) sg;
            } else {
                throw new IllegalParameterException("The Id Generator [" + generatorName
                        + "] should be of type @javax.persistence.SequenceGenerator. domain class:"
                        + domainClas.getName());
            }
        }

        idProperties.setProperty(SequenceIdGenerator.PARAM_SEQUENCE, psg.sequenceName());

        idProperties.setProperty("catalog", psg.catalog());
        idProperties.setProperty("allocationSize", String.valueOf(psg.allocationSize()));
        idProperties.setProperty("initialValue", String.valueOf(psg.initialValue()));

        //we need db_group param, but the JPA won't give us.
    } else if (gt == GenerationType.TABLE) {
        igCls = "hilo.multi";

        TableGenerator pst = (TableGenerator) element.getAnnotation(TableGenerator.class);
        if (pst == null) {
            Object sg = gf.getGlobalIdGenerator(generatorName);
            Assert.assertNotNull(sg,
                    "@javax.persistence.TableGenerator not found for hilo.multi @Id. domain class:"
                            + domainClas.getName());

            if (sg instanceof TableGenerator) {
                pst = (TableGenerator) sg;
            } else {
                throw new IllegalParameterException("The Id Generator [" + generatorName
                        + "] should be of type @javax.persistence.TableGenerator. domain class:"
                        + domainClas.getName());
            }
        }

        idProperties.setProperty("catalog", pst.catalog());
        idProperties.setProperty("schema", pst.schema());
        idProperties.setProperty(TableMultiIdGenerator.TABLE, pst.table());
        idProperties.setProperty(TableMultiIdGenerator.PK_COLUMN_NAME, pst.pkColumnName());
        idProperties.setProperty(TableMultiIdGenerator.PK_COLUMN_VALUE, pst.pkColumnValue());
        idProperties.setProperty(TableMultiIdGenerator.COLUMN, pst.valueColumnName());
        idProperties.setProperty(TableMultiIdGenerator.MAX_LO, String.valueOf(pst.allocationSize()));
        //we need db_group param, but the JPA won't give us.

        idProperties.setProperty("initialValue", String.valueOf(pst.initialValue()));
    } else {
        throw new GuzzException("unknown @javax.persistence.GenerationType:" + gt);
    }

    if ("native".equals(igCls)) {
        igCls = dbGroup.getDialect().getNativeIDGenerator();
    }

    String realClassName = (String) IdentifierGeneratorFactory.getGeneratorClass(igCls);
    Assert.assertNotNull(realClassName, "unknown Id generator:" + igCls);

    IdentifierGenerator ig = (IdentifierGenerator) BeanCreator.newBeanInstance(realClassName);

    if (ig instanceof Configurable) {
        ((Configurable) ig).configure(dbGroup.getDialect(), map, idProperties);
    }

    //register callback for GuzzContext's full starting.
    if (ig instanceof GuzzContextAware) {
        gf.registerContextStartedAware((GuzzContextAware) ig);
    }

    st.setIdentifierGenerator(ig);
}

From source file:org.kalypso.model.wspm.pdb.db.mapping.DhmIndex.java

@Id
@Column(name = "id", unique = true, nullable = false, precision = 20, scale = 0)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "dhmindex_id_seq")
@SequenceGenerator(name = "dhmindex_id_seq", sequenceName = "pdb.seq_pdb")
public long getId() {
    return m_id;/* w  ww  .  j  a  v a  2 s  .co  m*/
}

From source file:org.normandra.cassandra.CassandraDatabase.java

@Override
public void refresh() throws NormandraException {
    if (null == meta) {
        throw new NullArgumentException("database metadata");
    }//w  w w.  ja v  a  2  s.co  m

    if (DatabaseConstruction.NONE.equals(this.constructionMode)) {
        return;
    }

    // create all entity tables
    for (final String table : meta.getTables()) {
        try {
            this.refreshEntityTable(table, meta);
        } catch (final Exception e) {
            throw new NormandraException("Unable to refresh entity table [" + table + "].", e);
        }
    }

    // setup any table sequence/id generators
    for (final EntityMeta entity : meta) {
        for (final Class<?> entityType : entity.getTypes()) {
            final AnnotationParser parser = new AnnotationParser(new BasicColumnAccessorFactory(), entityType);
            for (final Map.Entry<Field, GeneratedValue> entry : parser.getGenerators(entityType).entrySet()) {
                final Field field = entry.getKey();
                final GeneratedValue generator = entry.getValue();
                final String type = generator.generator();
                String tableName = "id_generator";
                String keyColumn = "id";
                String keyValue = CaseUtils.camelToSnakeCase(entity.getTable());
                String valueColumn = "value";

                if (GenerationType.TABLE.equals(generator.strategy())) {
                    for (final TableGenerator table : parser.findAnnotations(entityType,
                            TableGenerator.class)) {
                        if (type.equalsIgnoreCase(table.name())) {
                            if (!table.table().isEmpty()) {
                                tableName = table.table();
                            }
                            if (!table.pkColumnName().isEmpty()) {
                                keyColumn = table.pkColumnName();
                            }
                            if (!table.pkColumnValue().isEmpty()) {
                                keyValue = table.pkColumnValue();
                            }
                            if (!table.valueColumnName().isEmpty()) {
                                valueColumn = table.valueColumnName();
                            }
                        }
                    }
                } else if (GenerationType.SEQUENCE.equals(generator.strategy())) {
                    for (final SequenceGenerator sequence : parser.findAnnotations(entityType,
                            SequenceGenerator.class)) {
                        if (type.equalsIgnoreCase(sequence.name())) {
                            if (!sequence.sequenceName().isEmpty()) {
                                keyValue = sequence.sequenceName();
                            }
                        }
                    }
                } else if (GenerationType.IDENTITY.equals(generator.strategy())) {
                    throw new NormandraException(
                            "Cassandra CQL3 does not support identity primary key generation.");
                }

                try {
                    this.refreshTableGenerator(tableName, keyColumn, valueColumn);
                } catch (final Exception e) {
                    throw new NormandraException(
                            "Unable to refresh id generator [" + generator.generator() + "].", e);
                }

                final String fieldName = field.getName();
                final ColumnMeta column = entity.findColumn(fieldName);
                if (column != null) {
                    final CassandraCounterIdGenerator counter = new CassandraCounterIdGenerator(tableName,
                            keyColumn, valueColumn, keyValue, this);
                    entity.setGenerator(column, counter);
                    logger.info("Set counter id generator for [" + column + "] on entity [" + entity + "].");
                    break;
                }
            }
        }
    }
}

From source file:org.normandra.orientdb.data.OrientDatabase.java

private void refreshGenerators(final EntityMeta entity, final ODatabaseDocument database) {
    // setup any table sequence/id generators
    for (final Class<?> entityType : entity.getTypes()) {
        final AnnotationParser parser = new AnnotationParser(new OrientAccessorFactory(), entityType);
        for (final Map.Entry<Field, GeneratedValue> entry : parser.getGenerators(entityType).entrySet()) {
            final Field field = entry.getKey();
            final GeneratedValue generator = entry.getValue();
            final String type = generator.generator();
            String tableName = "id_generator";
            String keyColumn = "id";
            String keyValue = CaseUtils.camelToSnakeCase(entity.getName());
            String valueColumn = "value";

            if (GenerationType.TABLE.equals(generator.strategy())) {
                for (final TableGenerator table : parser.findAnnotations(entityType, TableGenerator.class)) {
                    if (type.equalsIgnoreCase(table.name())) {
                        if (!table.table().isEmpty()) {
                            tableName = table.table();
                        }/*from w w w  .j  a v a  2  s .  com*/
                        if (!table.pkColumnName().isEmpty()) {
                            keyColumn = table.pkColumnName();
                        }
                        if (!table.pkColumnValue().isEmpty()) {
                            keyValue = table.pkColumnValue();
                        }
                        if (!table.valueColumnName().isEmpty()) {
                            valueColumn = table.valueColumnName();
                        }
                    }
                }
            } else if (GenerationType.SEQUENCE.equals(generator.strategy())) {
                for (final SequenceGenerator sequence : parser.findAnnotations(entityType,
                        SequenceGenerator.class)) {
                    if (type.equalsIgnoreCase(sequence.name())) {
                        if (!sequence.sequenceName().isEmpty()) {
                            keyValue = sequence.sequenceName();
                        }
                    }
                }
            } else if (GenerationType.IDENTITY.equals(generator.strategy())) {
                throw new IllegalStateException(
                        "No support available for orient-db identity primary key generation.");
            }

            // get the column type
            final String fieldName = field.getName();
            final String indexName = tableName + "." + keyColumn;
            final ColumnMeta column = entity.findColumn(fieldName);
            if (null == column) {
                throw new IllegalStateException(
                        "Unable to locate primary key [" + fieldName + "] for entity [" + entity + "].");
            }

            // drop table as required
            if (DatabaseConstruction.RECREATE.equals(this.constructionMode)) {
                if (hasCluster(database, tableName)) {
                    database.command(new OCommandSQL("DELETE FROM " + tableName)).execute();
                    database.getMetadata().getSchema().dropClass(tableName);
                }
                if (hasIndex(database, indexName)) {
                    database.command(new OCommandSQL("DROP INDEX " + indexName)).execute();
                    database.getMetadata().getIndexManager().dropIndex(indexName);
                }
            }

            // create sequence schema
            final OClass schemaClass = database.getMetadata().getSchema().getOrCreateClass(tableName);
            if (!schemaClass.existsProperty(keyColumn)) {
                schemaClass.createProperty(keyColumn, OType.STRING);
            }
            if (!schemaClass.existsProperty(valueColumn)) {
                schemaClass.createProperty(valueColumn, OrientUtils.columnType(column));
            }
            if (!schemaClass.areIndexed(keyColumn)) {
                schemaClass.createIndex(indexName, OClass.INDEX_TYPE.UNIQUE, keyColumn);
            }

            // assign generator
            final IdGenerator counter = new OrientIdGenerator(tableName, indexName, keyColumn, valueColumn,
                    keyValue, this);
            entity.setGenerator(column, counter);
            logger.info("Set counter id generator for [" + column + "] on entity [" + entity + "].");
        }
    }
}

From source file:org.openhie.openempi.model.ColumnInformation.java

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "column_information_seq")
@Column(name = "column_information_id", unique = true, nullable = false)
public Integer getColumnInformationId() {
    return columnInformationId;
}

From source file:org.openhie.openempi.model.ColumnMatchInformation.java

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "column_match_information_seq")
@Column(name = "column_match_information_id", unique = true, nullable = false)
public Integer getColumnMatchInformationId() {
    return columnMatchInformationId;
}