Java Examples for javax.persistence.SequenceGenerator
The following java examples will help you to understand the usage of javax.persistence.SequenceGenerator. These source code samples are taken from different open source projects.
Example 1
| Project: castor-master File: JPASequenceGeneratorFieldProcessorTest.java View source code |
@Before
public void setUp() throws Exception {
processor = new JPASequenceGeneratorFieldProcessor();
MockitoAnnotations.initMocks(this);
initNature();
annotation = new SequenceGenerator() {
public Class<? extends Annotation> annotationType() {
return SequenceGenerator.class;
}
public String sequenceName() {
return sequenceName;
}
public String name() {
return generatorName;
}
public int initialValue() {
return initialValue;
}
public int allocationSize() {
return allocationSize;
}
};
}Example 2
| Project: modello-master File: AnnotationsVerifier.java View source code |
public void verify() throws Exception {
assertAnnotations("class annotation test", model.Group.class.getAnnotations(), javax.xml.bind.annotation.XmlRootElement.class);
assertAnnotations("field annotation test", model.Group.class.getDeclaredField("id").getAnnotations(), javax.persistence.Id.class, javax.persistence.SequenceGenerator.class, javax.persistence.GeneratedValue.class, javax.persistence.Column.class);
assertAnnotations("interface annotation test", model.SimpleInterface.class.getAnnotations(), javax.xml.bind.annotation.XmlRootElement.class);
}Example 3
| Project: kie-wb-common-master File: JavaRoasterModelDriverTest.java View source code |
private DataObject createPojo1() {
DataObject pojo1 = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package1", "Pojo1", "org.kie.workbench.common.services.datamodeller.driver.package2.Pojo2");
Annotation annotation;
annotation = createAnnotation(Entity.class, "name", "Pojo1Entity");
pojo1.addAnnotation(annotation);
annotation = createAnnotation(Table.class, "name", "POJO1");
annotation.setValue("catalog", "CATALOG_NAME");
annotation.setValue("schema", "SCHEMA_NAME");
Annotation constraint1 = createAnnotation(UniqueConstraint.class);
constraint1.setValue("name", "constraint1");
constraint1.setValue("columnNames", createArrayParam("column1", "column2"));
Annotation constraint2 = createAnnotation(UniqueConstraint.class);
constraint2.setValue("name", "constraint2");
constraint2.setValue("columnNames", createArrayParam("column3", "column4"));
List<Annotation> uniqueConstraints = new ArrayList<Annotation>();
uniqueConstraints.add(constraint1);
uniqueConstraints.add(constraint2);
annotation.setValue("uniqueConstraints", uniqueConstraints);
pojo1.addAnnotation(annotation);
annotation = createAnnotation(SequenceGenerator.class, "name", "pojo1IdSeq");
annotation.setValue("sequenceName", "POJO_ID_SEQ");
annotation.setValue("allocationSize", new Integer("1"));
pojo1.addAnnotation(annotation);
annotation = createAnnotation(TypeSafe.class, "value", true);
pojo1.addAnnotation(annotation);
annotation = createAnnotation(Role.class, "value", Role.Type.EVENT.toString());
pojo1.addAnnotation(annotation);
annotation = createAnnotation(Label.class, "value", "Pojo1Label");
pojo1.addAnnotation(annotation);
annotation = createAnnotation(Description.class, "value", "Pojo1Description");
pojo1.addAnnotation(annotation);
annotation = createAnnotation(Duration.class, "value", "duration");
pojo1.addAnnotation(annotation);
annotation = createAnnotation(Timestamp.class, "value", "timestamp");
pojo1.addAnnotation(annotation);
annotation = createAnnotation(ClassReactive.class);
pojo1.addAnnotation(annotation);
annotation = createAnnotation(Expires.class, "value", "1h25m");
pojo1.addAnnotation(annotation);
ObjectProperty property = pojo1.addProperty("serialVersionUID", "long");
property = pojo1.addProperty("field1", "java.lang.Character");
annotation = createAnnotation(Position.class, "value", new Integer("0"));
property.addAnnotation(annotation);
annotation = createAnnotation(Key.class);
property.addAnnotation(annotation);
annotation = createAnnotation(Label.class, "value", "field1Label");
property.addAnnotation(annotation);
annotation = createAnnotation(Description.class, "value", "field1Description");
property.addAnnotation(annotation);
property = pojo1.addProperty("duration", "java.lang.Integer");
annotation = createAnnotation(Position.class, "value", new Integer("1"));
property.addAnnotation(annotation);
property = pojo1.addProperty("timestamp", "java.util.Date");
annotation = createAnnotation(Position.class, "value", new Integer("2"));
property.addAnnotation(annotation);
property = pojo1.addProperty("field2", "char");
annotation = createAnnotation(Position.class, "value", new Integer("3"));
property.addAnnotation(annotation);
annotation = createAnnotation(Key.class);
property.addAnnotation(annotation);
annotation = createAnnotation(Label.class, "value", "field2Label");
property.addAnnotation(annotation);
annotation = createAnnotation(Description.class, "value", "field2Description");
property.addAnnotation(annotation);
return pojo1;
}Example 4
| Project: clinic-softacad-master File: JPAOverriddenAnnotationReader.java View source code |
private Annotation getSequenceGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
Element subelement = element != null ? element.element(annotationToXml.get(SequenceGenerator.class)) : null;
if (subelement != null) {
return buildSequenceGeneratorAnnotation(subelement);
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
return getJavaAnnotation(SequenceGenerator.class);
} else {
return null;
}
}Example 5
| Project: hibernate-core-3.6.x-mod-master File: JPAOverridenAnnotationReader.java View source code |
private Annotation getSequenceGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
Element subelement = element != null ? element.element(annotationToXml.get(SequenceGenerator.class)) : null;
if (subelement != null) {
return buildSequenceGeneratorAnnotation(subelement);
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
return getJavaAnnotation(SequenceGenerator.class);
} else {
return null;
}
}Example 6
| Project: hibernate-core-ogm-master File: JPAOverridenAnnotationReader.java View source code |
private Annotation getSequenceGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
Element subelement = element != null ? element.element(annotationToXml.get(SequenceGenerator.class)) : null;
if (subelement != null) {
return buildSequenceGeneratorAnnotation(subelement);
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
return getJavaAnnotation(SequenceGenerator.class);
} else {
return null;
}
}Example 7
| Project: hibernate-orm-master File: JPAOverriddenAnnotationReader.java View source code |
private Annotation getSequenceGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
Element subelement = element != null ? element.element(annotationToXml.get(SequenceGenerator.class)) : null;
if (subelement != null) {
return buildSequenceGeneratorAnnotation(subelement);
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
return getPhysicalAnnotation(SequenceGenerator.class);
} else {
return null;
}
}Example 8
| Project: kfs-master File: AbstractExpense.java View source code |
@SuppressWarnings("rawtypes")
@Override
public String getSequenceName() {
Class boClass = getClass();
String retval = "";
try {
boolean rethrow = true;
Exception e = null;
while (rethrow) {
LOG.debug("Looking for id in " + boClass.getName());
try {
final Field idField = boClass.getDeclaredField("id");
final SequenceGenerator sequenceInfo = idField.getAnnotation(SequenceGenerator.class);
return sequenceInfo.sequenceName();
} catch (Exception ee) {
LOG.debug("Could not find id in " + boClass.getName());
if (Object.class.equals(boClass)) {
rethrow = false;
}
boClass = boClass.getSuperclass();
e = ee;
}
}
if (e != null) {
throw e;
}
} catch (Exception e) {
LOG.error("Could not get the sequence name for business object " + getClass().getSimpleName());
LOG.error(e.getMessage());
if (LOG.isDebugEnabled()) {
e.printStackTrace();
}
}
return retval;
}Example 9
| Project: MyFramework-master File: MyBatisBaseModel.java View source code |
/** * 获å?–POJOä¸ä¸»é”®çš„åº?列å??ç§°,需è¦?定义@SequenceGenerator(name="åº?列å??ç§°") * @return */ public String getSequenceName() { Field[] fields = this.getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { if (fields[i].isAnnotationPresent(SequenceGenerator.class)) { SequenceGenerator seq = fields[i].getAnnotation(SequenceGenerator.class); return seq.name(); } } throw new MyBatisPojoStructureException("undefine POJO @SequenceGenerator(name=\"seqName\")"); }
Example 10
| Project: seasar2-master File: PropertyMetaFactoryImpl.java View source code |
/**
* {@link GenerationType#SEQUENCE}æ–¹å¼?ã?§è˜åˆ¥å?ã?®å€¤ã‚’自動生æˆ?ã?™ã‚‹IDジェãƒ?レータを処ç?†ã?—ã?¾ã?™ã€‚
*
* @param propertyMeta
* プãƒãƒ‘ティメタデータ
* @param generatedValue
* è˜åˆ¥å?ã?«ä»˜ã?‘られã?Ÿ{@link GeneratedValue}アノテーション
* @param entityMeta
* エンティティ�メタデータ
* @return {@link GenerationType#SEQUENCE}æ–¹å¼?ã?§è˜åˆ¥å?ã?®å€¤ã‚’自動生æˆ?ã?™ã‚‹IDジェãƒ?レータã?Œå˜åœ¨ã?—ã?Ÿå ´å?ˆã?«
* <code>true</code>
*/
protected boolean doSequenceIdGenerator(PropertyMeta propertyMeta, GeneratedValue generatedValue, EntityMeta entityMeta) {
String name = generatedValue.generator();
SequenceGenerator sequenceGenerator;
if (StringUtil.isEmpty(name)) {
sequenceGenerator = DEFAULT_SEQUENCE_GENERATOR;
} else {
sequenceGenerator = propertyMeta.getField().getAnnotation(SequenceGenerator.class);
if (sequenceGenerator == null || !name.equals(sequenceGenerator.name())) {
sequenceGenerator = entityMeta.getEntityClass().getAnnotation(SequenceGenerator.class);
if (sequenceGenerator == null || !name.equals(sequenceGenerator.name())) {
return false;
}
}
}
propertyMeta.setSequenceIdGenerator(new SequenceIdGenerator(entityMeta, propertyMeta, sequenceGenerator));
return true;
}Example 11
| Project: ef-orm-master File: ColumnType.java View source code |
private void init(GenerationType type, TableGenerator tg, SequenceGenerator sg, HiloGeneration hilo) {
this.nullable = false;
if (ORMConfig.getInstance().isGenerateBySequenceAndIdentityToAUTO()) {
if (type == GenerationType.IDENTITY || type == GenerationType.SEQUENCE) {
type = GenerationType.AUTO;
}
}
this.type = type;
this.tableGenerator = tg;
this.seqGenerator = sg;
}Example 12
| Project: ebean-master File: AnnotationFields.java View source code |
private void readGenValue(GeneratedValue gen, DeployBeanProperty prop) {
String genName = gen.generator();
SequenceGenerator sequenceGenerator = find(prop, SequenceGenerator.class);
if (sequenceGenerator != null) {
if (sequenceGenerator.name().equals(genName)) {
genName = sequenceGenerator.sequenceName();
}
descriptor.setSequenceInitialValue(sequenceGenerator.initialValue());
descriptor.setSequenceAllocationSize(sequenceGenerator.allocationSize());
}
GenerationType strategy = gen.strategy();
if (strategy == GenerationType.IDENTITY) {
descriptor.setIdType(IdType.IDENTITY);
} else if (strategy == GenerationType.SEQUENCE) {
descriptor.setIdType(IdType.SEQUENCE);
if (!genName.isEmpty()) {
descriptor.setIdGeneratorName(genName);
}
} else if (strategy == GenerationType.AUTO) {
if (!genName.isEmpty()) {
// use a custom IdGenerator
PlatformIdGenerator idGenerator = generatedPropFactory.getIdGenerator(genName);
if (idGenerator == null) {
throw new IllegalStateException("No custom IdGenerator registered with name " + genName);
}
descriptor.setCustomIdGenerator(idGenerator);
} else if (prop.getPropertyType().equals(UUID.class)) {
descriptor.setUuidGenerator();
}
}
}Example 13
| Project: BatooJPA-master File: EntityMetadataImpl.java View source code |
/**
* Handles the sequence generator definition of the entity.
* <p>
* If metadata provides a sequence generator then the definition is returned.
* <p>
* Then if the {@link SequenceGenerator} annotation present, then definition based on the annotation is returned.
* <p>
* Finally null value is returned
*
* @param metadata
* the metadata
* @param parsed
* the set of annotation parsed
* @return the sequence generator metadata or null
*
* @since 2.0.0
*/
private SequenceGeneratorMetadata handleSequenceGenerator(EntityMetadata metadata, Set<Class<? extends Annotation>> parsed) {
if ((metadata != null) && (metadata.getSequenceGenerator() != null)) {
return metadata.getSequenceGenerator();
}
final SequenceGenerator annotation = this.getClazz().getAnnotation(SequenceGenerator.class);
if (annotation != null) {
parsed.add(SequenceGenerator.class);
return new SequenceGeneratorMetadataImpl(this.getLocator(), annotation);
}
return null;
}Example 14
| Project: hibernate-tools-master File: EntityPOJOClass.java View source code |
public String generateAnnIdGenerator() {
KeyValue identifier = clazz.getIdentifier();
String strategy = null;
Properties properties = null;
StringBuffer wholeString = new StringBuffer(" ");
if (identifier instanceof Component) {
wholeString.append(AnnotationBuilder.createAnnotation(importType("javax.persistence.EmbeddedId")).getResult());
} else if (identifier instanceof SimpleValue) {
SimpleValue simpleValue = (SimpleValue) identifier;
strategy = simpleValue.getIdentifierGeneratorStrategy();
properties = c2j.getFilteredIdentifierGeneratorProperties(simpleValue);
StringBuffer idResult = new StringBuffer();
AnnotationBuilder builder = AnnotationBuilder.createAnnotation(importType("javax.persistence.Id"));
idResult.append(builder.getResult());
idResult.append(" ");
//TODO: how to handle generic now??
boolean isGenericGenerator = false;
if (!"assigned".equals(strategy)) {
if (!"native".equals(strategy)) {
if ("identity".equals(strategy)) {
builder.resetAnnotation(importType("javax.persistence.GeneratedValue"));
builder.addAttribute("strategy", staticImport("javax.persistence.GenerationType", "IDENTITY"));
idResult.append(builder.getResult());
} else if ("sequence".equals(strategy)) {
builder.resetAnnotation(importType("javax.persistence.GeneratedValue")).addAttribute("strategy", staticImport("javax.persistence.GenerationType", "SEQUENCE")).addQuotedAttribute("generator", clazz.getClassName() + "IdGenerator");
idResult.append(builder.getResult());
builder.resetAnnotation(importType("javax.persistence.SequenceGenerator")).addQuotedAttribute("name", clazz.getClassName() + "IdGenerator").addQuotedAttribute("sequenceName", properties.getProperty(org.hibernate.id.enhanced.SequenceStyleGenerator.SEQUENCE_PARAM, null));
// TODO HA does not support initialValue and allocationSize
wholeString.append(builder.getResult());
} else if (TableGenerator.class.getName().equals(strategy)) {
builder.resetAnnotation(importType("javax.persistence.GeneratedValue")).addAttribute("strategy", staticImport("javax.persistence.GenerationType", "TABLE")).addQuotedAttribute("generator", "generator");
idResult.append(builder.getResult());
buildAnnTableGenerator(wholeString, properties);
} else {
isGenericGenerator = true;
builder.resetAnnotation(importType("javax.persistence.GeneratedValue"));
builder.addQuotedAttribute("generator", "generator");
idResult.append(builder.getResult());
}
} else {
builder.resetAnnotation(importType("javax.persistence.GeneratedValue"));
idResult.append(builder.getResult());
}
}
if (isGenericGenerator) {
builder.resetAnnotation(importType("org.hibernate.annotations.GenericGenerator")).addQuotedAttribute("name", "generator").addQuotedAttribute("strategy", strategy);
List<AnnotationBuilder> params = new ArrayList<AnnotationBuilder>();
//wholeString.append( "parameters = { " );
if (properties != null) {
Enumeration<?> propNames = properties.propertyNames();
while (propNames.hasMoreElements()) {
String propertyName = (String) propNames.nextElement();
AnnotationBuilder parameter = AnnotationBuilder.createAnnotation(importType("org.hibernate.annotations.Parameter")).addQuotedAttribute("name", propertyName).addQuotedAttribute("value", properties.getProperty(propertyName));
params.add(parameter);
}
}
builder.addAttributes("parameters", params.iterator());
wholeString.append(builder.getResult());
}
wholeString.append(idResult);
}
return wholeString.toString();
}Example 15
| Project: openjpa-master File: AnnotationPersistenceMetaDataParser.java View source code |
/**
* Parse information in package-level class annotations.
*/
private void parsePackageAnnotations() {
Package pkg = _cls.getPackage();
if (pkg == null)
return;
int pkgMode = getSourceMode(pkg);
if (pkgMode == 0 && _log.isTraceEnabled())
_log.trace(_loc.get("parse-package", _cls.getName()));
if (// already visited
(pkgMode & _mode) == _mode)
return;
MetaDataTag tag;
for (Annotation anno : pkg.getDeclaredAnnotations()) {
tag = _tags.get(anno.annotationType());
if (tag == null) {
handleUnknownPackageAnnotation(pkg, anno);
continue;
}
switch(tag) {
case NATIVE_QUERIES:
if (isQueryMode() && (pkgMode & MODE_QUERY) == 0)
parseNamedNativeQueries(pkg, ((NamedNativeQueries) anno).value());
break;
case NATIVE_QUERY:
if (isQueryMode() && (pkgMode & MODE_QUERY) == 0)
parseNamedNativeQueries(pkg, (NamedNativeQuery) anno);
break;
case QUERIES:
if (isQueryMode() && (pkgMode & MODE_QUERY) == 0)
parseNamedQueries(pkg, ((NamedQueries) anno).value());
break;
case QUERY:
if (isQueryMode() && (pkgMode & MODE_QUERY) == 0)
parseNamedQueries(pkg, (NamedQuery) anno);
break;
case STOREDPROCEDURE_QUERIES:
if (isQueryMode())
parseNamedStoredProcedureQueries(pkg, ((NamedStoredProcedureQueries) anno).value());
break;
case STOREDPROCEDURE_QUERY:
if (isQueryMode())
parseNamedStoredProcedureQueries(pkg, ((NamedStoredProcedureQuery) anno));
break;
case SEQ_GENERATOR:
if (isMappingOverrideMode() && (pkgMode & MODE_MAPPING) == 0)
parseSequenceGenerator(pkg, (SequenceGenerator) anno);
break;
default:
throw new UnsupportedException(_loc.get("unsupported", pkg, anno.toString()));
}
}
// dependencies on metadata
if (isMappingOverrideMode() && (pkgMode & MODE_MAPPING) == 0)
parsePackageMappingAnnotations(pkg);
}Example 16
| Project: hbnpojogen-master File: Core.java View source code |
/**
* Another core method. Builds the object model from the parsed tables. At the end of this
* method we have our class model in place, ready to be written.
*
* @param classes List of classes
* @param commitOrder Mostly to obtain the classes in the order of dependencies
* @throws Exception
*/
public static void buildObjectModel(TreeMap<String, Clazz> classes, LinkedList<String> commitOrder) throws Exception {
// Start working through the tables
boolean inEmbedMode = false;
// Create all classes first
for (String tableName : commitOrder) {
if (checkInIgnoreList(tableName)) {
continue;
}
Clazz co = new Clazz();
classes.put(tableName, co);
TableObj tobj = State.getInstance().tables.get(tableName);
// convenience linking
co.setTableObj(tobj);
// convenience linking
tobj.setClazz(co);
co.setTableIsAView(tobj.isViewTable());
}
// Fill in the classes
for (String tableName : commitOrder) {
if (checkInIgnoreList(tableName)) {
continue;
}
String tableNameNoCat = SyncUtils.getTableName(tableName.toLowerCase());
String tableCat = SyncUtils.getTableCatalog(tableName.toLowerCase());
String tableSchema = SyncUtils.getTableSchema(tableName.toLowerCase());
Clazz co = classes.get(tableName);
co.setClassPackage(tableSchema);
co.setClassName(SyncUtils.upfirstChar(tableNameNoCat));
if (State.getInstance().abstractTables.contains(tableName)) {
co.setClassType("abstract");
}
// check if table is part of cyclicTableExclusionList - chrisp
co.setCyclicExclusionTable(State.getInstance().cyclicTableExclusionListTables.containsKey(tableName));
TableObj tobj = State.getInstance().tables.get(tableName);
// convenience linking
co.setTableObj(tobj);
// convenience linking
tobj.setClazz(co);
co.getImports().add("javax.persistence.Entity");
if ((State.getInstance().schemaRestrict != 0) || (co.getTableObj().getDbName().indexOf('_') >= 0) || !co.getClassName().equals(co.getTableObj().getDbName())) {
co.getImports().add("javax.persistence.Table");
}
Iterator<Entry<String, FieldObj>> fields = tobj.getFields().entrySet().iterator();
while (fields.hasNext()) {
inEmbedMode = false;
Entry<String, FieldObj> field = fields.next();
String fieldName = field.getKey();
FieldObj fieldObj = field.getValue();
if (fieldObj.isAliased()) {
fieldName = fieldObj.getAlias();
}
// fetch again (may have changed
co = classes.get(tableName);
// for case of
// composite keys)
PropertyObj property = co.getProperties().get(fieldName);
if (property == null) {
property = new PropertyObj();
}
property.setFieldObj(fieldObj);
// link for future reference
fieldObj.setProperty(property);
property.setJavaName(SyncUtils.upfirstChar(fieldName));
if (co.hasCompositeKey() && (tobj.getPrimaryKeys().contains(field.getKey()))) {
Clazz embed;
// this is a composite primary key
embed = co.getEmbeddableClass();
if (embed == null) {
co.getProperties().put("id", property);
co.setCompositePrimaryKey(true);
property.setJavaType(co.getClassName() + "PK");
property.setIdField(true);
property.setJavaName("Id");
property.setPropertyName("id");
property.setClazz(co);
property.setComposite(true);
co.getImports().add("javax.persistence.Id");
// link to a new class, containing our embedded object
embed = new Clazz();
// back link
embed.setEmbeddedFrom(co);
embed.getImports().add("java.io.Serializable");
embed.getImports().add("javax.persistence.Embeddable");
co.setEmbeddableClass(embed);
embed.setEmbeddable(true);
embed.setTableObj(co.getTableObj());
embed.setClassName(co.getClassName() + "PK");
classes.put(tableName + "PK", embed);
property.setCompositeLink(embed);
embed.setClassName(SyncUtils.upfirstChar(SyncUtils.getTableName(tableName.toLowerCase()) + "PK"));
embed.setClassPackage(tableCat);
// create a new property for the embedded class
property = new PropertyObj();
property.setFieldObj(fieldObj);
// link for future
fieldObj.setProperty(property);
// reference
property.setJavaName(SyncUtils.upfirstChar(fieldName));
}
inEmbedMode = true;
// switch class we're working on in this cycle
co = embed;
}
property.setClazz(co);
switch(property.getPropertyMeta(inEmbedMode)) {
case PRIMARY_FOREIGN_KEY:
co.getImports().add("javax.persistence.PrimaryKeyJoinColumn");
// co.setSubclass(true);
co.setExtendingProperty(property);
// WW 29/5/08
property.setIdField(true);
// we'll fill in the exact extendsFrom link later
property.setJavaType(SyncUtils.mapSQLType(fieldObj));
// chrisp patch START
// Populate external properties for PRIMARY_FOREIGN_KEYs
// also
// Also, match all objects not just the ones that match the
// field name.
// if (tobj.getExportedKeys().containsKey(fieldName)) {
Iterator<String> targetTableKeys = tobj.getExportedKeys().navigableKeySet().iterator();
while (targetTableKeys.hasNext()) {
String myFieldName = targetTableKeys.next();
for (KeyObj targetTable : tobj.getExportedKeys().get(myFieldName)) {
doExternalProperty(tableName, co, field, targetTable.getField(), /*
* tobj.
* getFullTableName
* (
* )
*/
targetTable.getPkTableName());
}
}
break;
case PRIMARY_FIELD:
if (property.isAutoInc()) {
co.getImports().add("javax.persistence.GeneratedValue");
Entry<String, GeneratorEnum> defaultGenerator = State.getInstance().generators.get("DEFAULT").getTables().get("*").getFields().firstEntry();
String defaultPattern = defaultGenerator.getKey().replace("${DB}", property.getClazz().getTableObj().getDbName());
GeneratorEnum defaultGeneratorType = defaultGenerator.getValue();
if (property.getFieldObj().getName().equalsIgnoreCase(defaultPattern)) {
property.setGeneratorType(defaultGeneratorType);
}
String seq = property.getClazz().getTableObj().getPrimaryKeySequences().get(property.getFieldObj().getName());
if (State.getInstance().dbMode == 2 && seq != null) {
property.setGeneratorType(GeneratorEnum.SEQUENCE);
property.setSequenceName(seq);
property.setSequenceHibernateRef(property.getClazz().getClassPropertyName() + SyncUtils.upfirstChar(property.getFieldObj().getName()) + "Generator");
co.getImports().add("javax.persistence.SequenceGenerator");
co.getImports().add("javax.persistence.GenerationType");
} else {
property.setGeneratorType(GeneratorEnum.AUTO);
}
property.setGeneratedValue(true);
}
if (tobj.getExportedKeys().containsKey(fieldName)) {
for (KeyObj targetTable : tobj.getExportedKeys().get(fieldName)) {
doExternalProperty(tableName, co, field, targetTable.getField(), targetTable.getPkTableName());
}
}
// Hibernate style is to rename the primary field to "id"
if (!inEmbedMode) {
fieldName = "id";
property.setIdField(true);
co.getImports().add("javax.persistence.Id");
}
property.setJavaType(SyncUtils.mapSQLType(fieldObj));
if (property.getJavaType().equals("String")) {
property.setLength(fieldObj.getLength());
if (property.isGeneratedValue()) {
HbnPojoGen.logE("PK with generated value with java type String detected. This is not supported by Hibernate unless you assign the ID manually. Expect unit tests to fail " + property);
}
}
// co.setPrimaryKeyType(property.getJavaType());
property.setJavaName(SyncUtils.upfirstChar(fieldName));
break;
case ENUM_FIELD:
// topLevel + "." + projectName + ".enums.db." +
// co.getClassPackage()+"."+field.getValue().getEnumName()
property.setJavaType(fieldObj.getEnumName());
if (field.getValue().isFakeEnum()) {
String tmp = Core.fixIdName(fieldName);
property.setJavaName(SyncUtils.upfirstChar(tmp));
} else {
property.setJavaName(SyncUtils.upfirstChar(fieldName));
}
property.setEnumType(true);
break;
case COMPOSITE_MANY_TO_ONE:
property.setManyToOne(true);
property.setCompositeManyToOne(true);
co.getImports().add("javax.persistence.FetchType");
co.getImports().add("javax.persistence.ManyToOne");
for (KeyObj keyObj : tobj.getImportedKeys().values()) {
if (keyObj.getKeyLinks().containsKey(field.getKey())) {
property.setJavaType(SyncUtils.upfirstChar(keyObj.getPkTableName()));
property.setJavaName(property.getJavaType());
// fix
fieldName = property.getLowerCaseFriendlyName();
// for
// inserting in
// set
property.setPropertyName(fieldName);
String targetTable = property.getClazz().getTableObj().getFullTableName();
Clazz parentClass = classes.get(keyObj.getPKFullTableName());
PropertyObj externalProperty = new PropertyObj();
externalProperty.setFieldObj(property.getFieldObj());
externalProperty.setJavaType(property.getClazz().getClassName());
externalProperty.setJavaName(property.getClazz().getClassName());
externalProperty.setPropertyName(property.getClazz().getClassPropertyName());
externalProperty.setClazz(parentClass);
// do back link
externalProperty.setOneToMany(true);
externalProperty.setOneToManyLink(property);
if (property == null) {
System.err.println("Property is null!!");
}
assert (property != null);
State.getInstance().tables.get(keyObj.getPKFullTableName()).getClazz().getImports().add(State.getInstance().doObjectImport(targetTable));
parentClass.getProperties().put(targetTable, externalProperty);
// topLevel + "." + projectName + ".model.obj." +
// SyncUtils.removeUnderscores(getTableCatalog(targetTable))+"."+SyncUtils.upfirstChar(SyncUtils.removeUnderscores(getTableName(targetTable)))
parentClass.getImports().add(State.getInstance().doObjectImport(targetTable));
parentClass.getImports().add("javax.persistence.OneToMany");
parentClass.getImports().add("javax.persistence.FetchType");
if (externalProperty.isOneToManyCascadeEnabledByConfig()) {
parentClass.getImports().add("javax.persistence.CascadeType");
}
parentClass.getImports().add("java.util.HashSet");
parentClass.getImports().add("java.util.Set");
// we should only process one
break;
}
}
if (property.isManyToOneCascadeEnabledByConfig()) {
co.getImports().add("javax.persistence.CascadeType");
}
break;
case ONE_TO_ONE_FIELD:
property.setOneToOne(true);
// we'll switch this off later
property.setManyToOne(true);
co.getImports().add("javax.persistence.FetchType");
co.getImports().add("javax.persistence.OneToOne");
String oname = field.getKey();
if (oname.toUpperCase().endsWith(Constants.IDCONST)) {
oname = oname.substring(0, oname.toUpperCase(Locale.getDefault()).lastIndexOf((Constants.IDCONST)));
} else if (oname.toUpperCase().endsWith(Constants.ID)) {
oname = oname.substring(0, oname.toUpperCase(Locale.getDefault()).lastIndexOf((Constants.ID)));
}
fieldName = Core.fixConflictingInheritedNames(oname, co);
property.setJavaName(SyncUtils.upfirstChar(oname));
for (KeyObj keyObj : tobj.getImportedKeys().values()) {
if (keyObj.getKeyLinks().containsKey(field.getKey())) {
property.setJavaType(SyncUtils.upfirstChar(keyObj.getPkTableName()));
// we should only find one
break;
}
}
break;
case MANY_TO_ONE_FIELD:
property.setManyToOne(true);
co.getImports().add("javax.persistence.FetchType");
co.getImports().add("javax.persistence.ManyToOne");
for (KeyObj keyObj : tobj.getImportedKeys().values()) {
if (keyObj.getKeyLinks().containsKey(field.getKey())) {
property.setJavaType(SyncUtils.upfirstChar(keyObj.getPkTableName().toLowerCase()));
// we should only find one
break;
}
}
if (co.getProperties().get(property.getJavaType()) != null) {
// this is the case for when we have one table with two
// fields both
// pointing to the same
// target table. This is problematic since using our
// usual field name
// mapping we will get
// duplicate entries (foo.setXXX will be duplicate).
// Therefore we try to
// fudge around it here
String name = field.getKey();
if (name.toUpperCase().endsWith(Constants.IDCONST)) {
name = name.substring(0, name.toUpperCase(Locale.getDefault()).lastIndexOf((Constants.IDCONST)));
} else if (name.toUpperCase().endsWith(Constants.ID)) {
name = name.substring(0, name.toUpperCase(Locale.getDefault()).lastIndexOf((Constants.ID)));
}
fieldName = Core.fixConflictingInheritedNames(name, co);
property.setJavaName(SyncUtils.upfirstChar(name));
} else {
String name = Core.fixIdName(fieldName);
fieldName = Core.fixConflictingInheritedNames(name, co);
property.setJavaName(SyncUtils.upfirstChar(name));
}
break;
case NORMAL_FIELD:
property.setJavaType(SyncUtils.mapSQLType(fieldObj));
if (fieldObj.getName().endsWith("_currency")) {
FieldObj f = tobj.getFields().get(fieldObj.getName().substring(0, fieldObj.getName().lastIndexOf("_currency")));
if (f != null && f.isMoneyType()) {
property.setHiddenCurrencyField(true);
}
}
if (fieldObj.getName().endsWith("_currency_code")) {
FieldObj f = tobj.getFields().get(fieldObj.getName().substring(0, fieldObj.getName().lastIndexOf("_currency_code")));
if (f != null && f.isMoneyType()) {
property.setHiddenCurrencyField(true);
}
}
if (fieldObj.isEncryptedType() || fieldObj.isMoneyType() || fieldObj.isCurrencyType()) {
co.getImports().add("org.hibernate.annotations.TypeDef");
co.getImports().add("org.hibernate.annotations.TypeDefs");
co.getImports().add("org.hibernate.annotations.Type");
co.getImports().add("org.hibernate.annotations.Columns");
co.getImports().add("javax.persistence.Column");
}
if (fieldObj.isEncryptedType()) {
co.getImports().add("org.jasypt.hibernate4.type.EncryptedStringType");
property.setEncrypted(true);
}
if (fieldObj.isMoneyType()) {
co.getImports().add(State.getInstance().getCustomMoneyType());
co.getImports().add("org.javamoney.moneta.Money");
property.setMoneyType(true);
property.setJavaType("Money");
}
if (fieldObj.isCurrencyType()) {
co.getImports().add(State.getInstance().getCustomCurrencyUnitType());
co.getImports().add("javax.money.CurrencyUnit");
property.setCurrencyType(true);
property.setJavaType("CurrencyUnit");
}
if (property.getJavaType().equals("String")) {
property.setLength(fieldObj.getLength());
}
if (property.isAutoInc()) {
property.setGeneratedValue(true);
Entry<String, GeneratorEnum> defaultGenerator = State.getInstance().generators.get("DEFAULT").getTables().get("*").getFields().firstEntry();
String defaultPattern = defaultGenerator.getKey().replace("${DB}", property.getClazz().getTableObj().getDbName());
GeneratorEnum defaultGeneratorType = defaultGenerator.getValue();
if (property.getFieldObj().getName().equalsIgnoreCase(defaultPattern)) {
property.setGeneratorType(defaultGeneratorType);
} else {
property.setGeneratorType(GeneratorEnum.AUTO);
}
co.getImports().add("javax.persistence.GeneratedValue");
// co.getImports().add("javax.persistence.GenerationType");
}
String name = Core.fixConflictingInheritedNames(property.getJavaName(), co);
property.setJavaName(SyncUtils.upfirstChar(name));
break;
default:
HbnPojoGen.logE("???? huh ??? ");
assert false;
}
if (property.getFieldObj().isFakeEnum()) {
property.setPropertyName(Core.fixIdName(fieldName));
} else {
property.setPropertyName(fieldName);
}
if (!property.isHiddenCurrencyField()) {
co.getProperties().put(fieldName, property);
} else {
co.getHiddenCurrencyProperties().put(fieldName, property);
}
}
}
// end main loop
// keep track of all conflicting keys (with superclasses) that need to
// change
LinkedList<Entry<String, PropertyObj>> changedKeys = new LinkedList<Entry<String, PropertyObj>>();
// make backlinks of many-to-one + subclass stuff
fixBackLinks(classes, changedKeys);
fixOneToMany(classes);
TreeMap<String, Clazz> clashMap = new TreeMap<String, Clazz>(new CaseInsensitiveComparator());
// schemas
for (Clazz clazz : classes.values()) {
// Check name clash
Clazz clash = clashMap.get(clazz.getClassName());
if (clash != null) {
clash.setNameAmbiguityPossible(true);
clazz.setNameAmbiguityPossible(true);
for (Clazz fixClass : classes.values()) {
Core.fixNameClash(clazz, fixClass);
Core.fixNameClash(clash, fixClass);
}
} else {
clashMap.put(clazz.getClassName(), clazz);
}
if (clazz.getExtendsFrom() != null) {
TreeMap<String, PropertyObj> extendsProperties = clazz.getExtendsFrom().getClazz().getAllProperties();
for (Entry<String, PropertyObj> property : clazz.getProperties().entrySet()) {
if (extendsProperties.get(property.getKey()) != null) {
property.getValue().getMethodLevelAnnotationsOnGetters().add("@Override");
property.getValue().getMethodLevelAnnotationsOnSetters().add("@Override");
}
}
}
}
// duplicate names along the way
for (Clazz clazz : classes.values()) {
TreeMap<String, PropertyObj> seen = new TreeMap<String, PropertyObj>(new CaseInsensitiveComparator());
for (PropertyObj property : clazz.getProperties().values()) {
if (property.isOneToMany() || property.isOneToOne()) {
PropertyObj tmp = seen.get(property.getPropertyName());
if (tmp == null) {
seen.put(property.getPropertyName(), property);
} else {
property.setClashResolved(true);
tmp.setClashResolved(true);
}
}
}
// fix all broken properties
for (PropertyObj prop : clazz.getProperties().values()) {
if (prop.isClashResolved()) {
String resolved = SyncUtils.upfirstChar(prop.getOneToManyLink().getClazz().getClassPackage()) + prop.getJavaName();
prop.setJavaName(resolved);
prop.setPropertyName(resolved.substring(0, 1).toLowerCase() + resolved.substring(1));
}
}
}
// check if property is part of cyclicTableExclusionList - chrisp
for (String tableName : commitOrder) {
if (Core.checkInIgnoreList(tableName)) {
continue;
}
TreeMap<String, String> propertyMap = State.getInstance().cyclicTableExclusionListTables.get(tableName);
if (propertyMap != null) {
for (PropertyObj property : State.getInstance().getTables().get(tableName).getClazz().getAllProperties().values()) {
if (propertyMap.containsKey(property.getFieldObj().getName())) {
property.setCyclicDependencyProperty(true);
}
}
}
}
// table - chrisp
for (Clazz clazz : classes.values()) {
if (clazz.isCyclicExclusionTable()) {
// find cyclic field
for (PropertyObj property : clazz.getProperties().values()) {
if (property.isCyclicDependencyProperty()) {
String fullTableName = clazz.getTableObj().getFullTableName();
String replacmentTableName = State.getInstance().cyclicTableExclusionListTables.get(fullTableName).get(property.getFieldObj().getName());
TableObj tObj = State.getInstance().tables.get(replacmentTableName);
if (tObj != null) {
Clazz co = tObj.getClazz();
property.setCyclicDependencyReplacementClazz(co);
co.setCyclicExclusionReplacementTable(true);
} else {
// for the case of "partial", we might not have
// used the cyclic dependency at all in the code
// generation phase.
property.setCyclicDependencyProperty(false);
}
}
}
}
}
// Change to our custom suffixes if required. Do it here since
// at other points we might not have all the information in our hands
addSuffixes(classes);
addCache(classes);
processLinkTables();
disableBacklinks(classes);
disableForwardlinks(classes);
if (!State.getInstance().disableSubtypeEnumGeneration) {
addSubclassEnums(classes);
}
// Add our custom annotations, add additional imports if necessary
addImports(classes);
// now cleanup all broken keys
for (Entry<String, PropertyObj> broken : changedKeys) {
PropertyObj prop = broken.getValue().getClazz().getProperties().get(broken.getKey());
broken.getValue().getClazz().getProperties().remove(broken.getKey());
prop.getClazz().getProperties().put(prop.getJavaName(), prop);
}
}Example 17
| Project: tianti-master File: OracleLongEntity.java View source code |
@Id
@SequenceGenerator(name = "ID_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_SEQ")
@Column(name = "ID", nullable = false)
public Long getId() {
return id;
}Example 18
| Project: hibernate-ogm-master File: Actor.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "actorSequenceGenerator")
@SequenceGenerator(name = "actorSequenceGenerator", sequenceName = "actor_sequence_name", initialValue = INITIAL_VALUE, allocationSize = 10)
public Long getId() {
return id;
}Example 19
| Project: Cerberus-master File: User.java View source code |
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "users_seq")
@SequenceGenerator(name = "users_seq", sequenceName = "users_seq", allocationSize = 1)
public Long getId() {
return this.id;
}Example 20
| Project: eclipselink.runtime-master File: Animal.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SequenceGenerator")
@Column(name = "ID")
public Integer getId() {
return id;
}Example 21
| Project: ORCID-Source-master File: BiographyEntity.java View source code |
/**
* @return the id of the name
*/
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "biography_seq")
@SequenceGenerator(name = "biography_seq", sequenceName = "biography_seq")
public Long getId() {
return id;
}Example 22
| Project: PhotoAlbum-api-master File: Album.java View source code |
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "albums_seq")
@SequenceGenerator(name = "albums_seq", sequenceName = "albums_seq", allocationSize = 1)
public Long getId() {
return this.id;
}Example 23
| Project: WebAPI-master File: RolePermissionEntity.java View source code |
@Id
@Column(name = "ID")
@SequenceGenerator(name = "SEC_ROLE_PERMISSION_SEQUENCE_GENERATOR", sequenceName = "SEC_ROLE_PERMISSION_SEQUENCE", allocationSize = 1, initialValue = 1000)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEC_ROLE_PERMISSION_SEQUENCE_GENERATOR")
public Long getId() {
return id;
}Example 24
| Project: cloudtm-data-platform-master File: Actor.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "actorSequenceGenerator")
@SequenceGenerator(name = "actorSequenceGenerator", sequenceName = "actor_sequence_name", initialValue = INITIAL_VALUE, allocationSize = 10)
public Long getId() {
return id;
}Example 25
| Project: sample-java-spring-genericdao-master File: Classes.java View source code |
@Id
@Column(name = "CLASSES_ID", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_CLASSES_ID")
@SequenceGenerator(name = "SEQ_CLASSES_ID", sequenceName = "SEQ_CLASSES_ID", allocationSize = 1, initialValue = 1)
public Integer getId() {
return this.id;
}Example 26
| Project: testcube-server-master File: Product.java View source code |
@Id
@SequenceGenerator(name = "CUB_PRODUCTS_SEQ", sequenceName = "CUB_PRODUCTS_SEQ", initialValue = 0)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "CUB_PRODUCTS_SEQ")
public Long getId() {
return super.getId();
}Example 27
| Project: fb-contrib-master File: JPAI_Sample.java View source code |
@Id
@SequenceGenerator(name = "MY_ENTITY_SEQ", sequenceName = "MY_ENTITY_SEQ", allocationSize = 100)
@GeneratedValue(generator = "MY_ENTITY_SEQ")
@Column(name = "ID", nullable = false, unique = true)
public Integer getId() {
return id;
}Example 28
| Project: opennms_dashboard-master File: OnmsServerMap.java View source code |
/**
* <p>getId</p>
*
* @return a {@link java.lang.Integer} object.
*/
@Id
@Column(name = "id")
@SequenceGenerator(name = "serverMapSequence", sequenceName = "svrMapNxtId")
@GeneratedValue(generator = "serverMapSequence")
public Integer getId() {
return m_id;
}Example 29
| Project: workdo-service-master File: Process.java View source code |
@XmlTransient
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "WORKFLOW_SEQ")
@SequenceGenerator(name = "WORKFLOW_SEQ", sequenceName = "workflow_seq")
public long getId() {
return this.id;
}Example 30
| Project: appverse-web-master File: BatchNodeDTO.java View source code |
@Id
@SequenceGenerator(name = "BATCH_NODE_ID_GENERATOR", sequenceName = "SEQ_BATCH_NODE", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BATCH_NODE_ID_GENERATOR")
@Column(unique = true, nullable = false, precision = 20)
public long getId() {
return id;
}Example 31
| Project: ranger-master File: AuthzAuditEventDbObj.java View source code |
@Id
@SequenceGenerator(name = "XA_ACCESS_AUDIT_SEQ", sequenceName = "XA_ACCESS_AUDIT_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "XA_ACCESS_AUDIT_SEQ")
@Column(name = "id", unique = true, nullable = false)
public long getAuditId() {
return this.auditId;
}Example 32
| Project: resource-manager-master File: JobData.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "JOBID_SEQUENCE")
@SequenceGenerator(name = "JOBID_SEQUENCE", sequenceName = "JOBID_SEQUENCE")
@Column(name = "ID")
public Long getId() {
return id;
}Example 33
| Project: scheduling-master File: JobData.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "JOBID_SEQUENCE")
@SequenceGenerator(name = "JOBID_SEQUENCE", sequenceName = "JOBID_SEQUENCE")
@Column(name = "ID")
public Long getId() {
return id;
}