Java Examples for javax.persistence.GeneratedValue
The following java examples will help you to understand the usage of javax.persistence.GeneratedValue. These source code samples are taken from different open source projects.
Example 1
| Project: ehour-master File: FieldMap.java View source code |
void afterFieldsSet() {
for (FieldDefinition fieldDefinition : fieldDefinitions()) {
Field field = fieldDefinition.getField();
if (field.isAnnotationPresent(Id.class)) {
id = fieldDefinition;
if (field.isAnnotationPresent(GeneratedValue.class)) {
generatedId = fieldDefinition;
} else {
compositeId = field.getType().isAnnotationPresent(Embeddable.class);
}
break;
}
}
}Example 2
| Project: jdbctemplatetool-master File: IdUtils.java View source code |
/**
* æ ¹æ?®æ³¨è§£èŽ·å?–è‡ªå¢žä¸»é”®å—æ®µå??
* 如果没找到就返回空å—符串
* @param po
* @return increamentIdFieldName
* @throws NoSuchMethodException
* @throws SecurityException
*/
public static String getAutoGeneratedId(Object po) throws SecurityException, NoSuchMethodException {
String autoGeneratedId = "";
//æ ¹æ?®æ³¨è§£èŽ·å?–è‡ªå¢žä¸»é”®å—æ®µå??
Field[] allFields = po.getClass().getDeclaredFields();
for (Field f : allFields) {
if ("serialVersionUID".equals(f.getName())) {
continue;
}
//获�getter方法
String getterName = "get" + CamelNameUtils.capitalize(f.getName());
Method getter = po.getClass().getDeclaredMethod(getterName);
Id idAnno = getter.getAnnotation(Id.class);
if (idAnno == null) {
continue;
}
GeneratedValue generatedValueAnno = getter.getAnnotation(GeneratedValue.class);
if (generatedValueAnno == null) {
continue;
}
if (GenerationType.IDENTITY == generatedValueAnno.strategy() || GenerationType.TABLE == generatedValueAnno.strategy()) {
autoGeneratedId = f.getName();
break;
}
}
return autoGeneratedId;
}Example 3
| 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 4
| Project: screensaver-master File: IdentifierMetadataTester.java View source code |
private void testGeneratedValueAppropriateness(String entityName, String identifierPropertyName) {
boolean isSemanticIDAbstractEntity = isSemanticIDAbstractEntity();
boolean hasGeneratedValue = hasGeneratedValueAnnotation(entityName, identifierPropertyName);
if (hasGeneratedValue && isSemanticIDAbstractEntity) {
fail("SemanticIDAbstractEntities should not have @GeneratedValue annotations on their identifier setters: " + entityName);
}
if (!hasGeneratedValue && !isSemanticIDAbstractEntity) {
fail("non-SemanticIDAbstractEntities should have @GeneratedValue annotations on their identifier setters: " + entityName);
}
}Example 5
| Project: castor-master File: JPAGeneratedValueProcessorTest.java View source code |
@Before
public void setUp() throws Exception {
processor = new JPAGeneratedValueProcessor();
MockitoAnnotations.initMocks(this);
initNature();
annotation = new GeneratedValue() {
public Class<? extends Annotation> annotationType() {
return this.getClass();
}
public GenerationType strategy() {
return GenerationType.AUTO;
}
public String generator() {
return "generator";
}
};
}Example 6
| Project: kie-wb-common-master File: JPADataObjectFieldEditorTest.java View source code |
@Test
public void valuesChangesTest() {
JPADataObjectFieldEditor fieldEditor = createFieldEditor();
DataObject dataObject = context.getDataObject();
ObjectProperty field = dataObject.getProperty("field1");
//emulates selection of field1 in current context.
context.setObjectProperty(field);
//The domain editors typically reacts upon DataModelerContext changes.
//when the context changes the editor will typically be reloaded.
fieldEditor.onContextChange(context);
//emulates user interactions
//changes related to the identifier category
fieldEditor.onIdentifierFieldChange(createFieldInfo(JPADataObjectFieldEditorView.IDENTIFIER_FIELD, null), "true");
fieldEditor.onGeneratedValueFieldChange(createFieldInfo(JPADataObjectFieldEditorView.GENERATED_VALUE_FIELD, new Pair<String, Object>("strategy", "SEQUENCE"), new Pair<String, Object>("generator", "TheGeneratorName")), "not_used");
fieldEditor.onSequenceGeneratorFieldChange(createFieldInfo(JPADataObjectFieldEditorView.SEQUENCE_GENERATOR_FIELD, new Pair<String, Object>(SequenceGeneratorValueHandler.NAME, "TheGeneratorName"), new Pair<String, Object>(SequenceGeneratorValueHandler.SEQUENCE_NAME, "TheSequenceName"), new Pair<String, Object>(SequenceGeneratorValueHandler.INITIAL_VALUE, 1), new Pair<String, Object>(SequenceGeneratorValueHandler.ALLOCATION_SIZE, 100)), "not_used");
//the field should have been updated according to the values entered on the ui
assertNotNull(field.getAnnotation(Id.class.getName()));
assertNotNull(field.getAnnotation(GeneratedValue.class.getName()));
assertEquals("SEQUENCE", AnnotationValueHandler.getStringValue(field, GeneratedValue.class.getName(), "strategy"));
assertEquals("TheGeneratorName", AnnotationValueHandler.getStringValue(field, GeneratedValue.class.getName(), "generator"));
assertNotNull(field.getAnnotation(SequenceGenerator.class.getName()));
assertEquals("TheGeneratorName", AnnotationValueHandler.getStringValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.NAME));
assertEquals("TheSequenceName", AnnotationValueHandler.getStringValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.SEQUENCE_NAME));
assertEquals(1, AnnotationValueHandler.getValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.INITIAL_VALUE));
assertEquals(100, AnnotationValueHandler.getValue(field, SequenceGenerator.class.getName(), SequenceGeneratorValueHandler.ALLOCATION_SIZE));
//changes related to the column category
fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_NAME_FIELD, new Pair<String, Object>("name", "NewColumnName")), "NewColumnName");
fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_UNIQUE_FIELD, new Pair<String, Object>("unique", true)), "true");
fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_NULLABLE_FIELD, new Pair<String, Object>("nullable", false)), "false");
fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_INSERTABLE_FIELD, new Pair<String, Object>("insertable", false)), "false");
fieldEditor.onColumnFieldChange(createFieldInfo(JPADataObjectFieldEditorView.COLUMN_UPDATABLE_FIELD, new Pair<String, Object>("updatable", false)), "false");
//the field should have been updated according to the values entered on the ui
assertNotNull(field.getAnnotation(Column.class.getName()));
assertEquals("NewColumnName", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "name"));
assertEquals("true", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "unique"));
assertEquals("false", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "nullable"));
assertEquals("false", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "insertable"));
assertEquals("false", AnnotationValueHandler.getStringValue(field, Column.class.getName(), "updatable"));
//changes related to the relationship
List<CascadeType> cascadeTypes = new ArrayList<CascadeType>();
cascadeTypes.add(CascadeType.ALL);
fieldEditor.onRelationTypeFieldChange(createFieldInfo(JPADataObjectFieldEditorView.RELATIONSHIP_TYPE_FIELD, new Pair<String, Object>(RelationshipAnnotationValueHandler.RELATION_TYPE, RelationType.ONE_TO_MANY), new Pair<String, Object>(RelationshipAnnotationValueHandler.CASCADE, cascadeTypes), new Pair<String, Object>(RelationshipAnnotationValueHandler.FETCH, FetchMode.EAGER)), "not_used");
//the field should have been updated according to the values entered on the ui
List<String> expectedCascadeTypes = new ArrayList<String>();
expectedCascadeTypes.add(CascadeType.ALL.name());
assertNotNull(field.getAnnotation(OneToMany.class.getName()));
assertEquals(expectedCascadeTypes, AnnotationValueHandler.getValue(field, OneToMany.class.getName(), RelationshipAnnotationValueHandler.CASCADE));
assertEquals(FetchMode.EAGER.name(), AnnotationValueHandler.getValue(field, OneToMany.class.getName(), RelationshipAnnotationValueHandler.FETCH));
}Example 7
| Project: hibernate-delta-master File: HibernateValidator.java View source code |
static void validateColumn(Class<?> entity, Field field) {
String name = entity.getName() + "." + field.getName();
GeneratedValue generatedValue = field.getAnnotation(GeneratedValue.class);
if (generatedValue != null) {
if (generatedValue.strategy() != GenerationType.AUTO) {
throw new IllegalStateException("strategy must be auto: " + name);
}
if (StringUtils.isNotBlank(generatedValue.generator())) {
throw new IllegalStateException("generator must be null: " + name);
}
}
Column column = field.getAnnotation(Column.class);
if (column != null) {
if (field.getType().equals(String.class) && column.length() > 4000) {
throw new IllegalStateException("varchar greater than 4000: " + name);
}
if (StringUtils.isNotBlank(column.name()) && !OracleKeywords.KEYWORDS.contains(field.getName()) && field.getName().length() <= 28) {
if (column.name().toLowerCase().endsWith("_id")) {
if (!StringUtils.substringBefore(column.name().toLowerCase(), "_id").equalsIgnoreCase(field.getName())) {
throw new IllegalStateException("column/field name mismatch: " + name);
}
} else {
if (!column.name().equalsIgnoreCase(field.getName())) {
throw new IllegalStateException("column/field name mismatch: " + name);
}
}
}
}
NotFound notFound = field.getAnnotation(NotFound.class);
if (notFound != null) {
throw new IllegalStateException("@NotFound annotation on " + name);
}
final JoinColumn joinColumn = field.getAnnotation(JoinColumn.class);
if (joinColumn != null && StringUtils.isNotBlank(joinColumn.name())) {
if (field.getName().length() <= 25 && !(field.getName() + "_id").equalsIgnoreCase(joinColumn.name())) {
throw new IllegalStateException("JoinColumn name mismatch: " + name);
}
}
}Example 8
| Project: mybatis-generator-gui-master File: DbRemarksCommentGenerator.java View source code |
public void addJavaFileComment(CompilationUnit compilationUnit) {
// add no file level comments by default
if (isAnnotations) {
compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.Table"));
compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.Id"));
compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.Column"));
compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.GeneratedValue"));
compilationUnit.addImportedType(new FullyQualifiedJavaType("org.hibernate.validator.constraints.NotEmpty"));
}
}Example 9
| Project: ormlite-core-master File: JavaxPersistenceImpl.java View source code |
@Override
public DatabaseFieldConfig createFieldConfig(DatabaseType databaseType, Field field) {
Column columnAnnotation = field.getAnnotation(Column.class);
Basic basicAnnotation = field.getAnnotation(Basic.class);
Id idAnnotation = field.getAnnotation(Id.class);
GeneratedValue generatedValueAnnotation = field.getAnnotation(GeneratedValue.class);
OneToOne oneToOneAnnotation = field.getAnnotation(OneToOne.class);
ManyToOne manyToOneAnnotation = field.getAnnotation(ManyToOne.class);
JoinColumn joinColumnAnnotation = field.getAnnotation(JoinColumn.class);
Enumerated enumeratedAnnotation = field.getAnnotation(Enumerated.class);
Version versionAnnotation = field.getAnnotation(Version.class);
if (columnAnnotation == null && basicAnnotation == null && idAnnotation == null && oneToOneAnnotation == null && manyToOneAnnotation == null && enumeratedAnnotation == null && versionAnnotation == null) {
return null;
}
DatabaseFieldConfig config = new DatabaseFieldConfig();
String fieldName = field.getName();
if (databaseType.isEntityNamesMustBeUpCase()) {
fieldName = databaseType.upCaseEntityName(fieldName);
}
config.setFieldName(fieldName);
if (columnAnnotation != null) {
if (stringNotEmpty(columnAnnotation.name())) {
config.setColumnName(columnAnnotation.name());
}
if (stringNotEmpty(columnAnnotation.columnDefinition())) {
config.setColumnDefinition(columnAnnotation.columnDefinition());
}
config.setWidth(columnAnnotation.length());
config.setCanBeNull(columnAnnotation.nullable());
config.setUnique(columnAnnotation.unique());
}
if (basicAnnotation != null) {
config.setCanBeNull(basicAnnotation.optional());
}
if (idAnnotation != null) {
if (generatedValueAnnotation == null) {
config.setId(true);
} else {
// generatedValue only works if it is also an id according to {@link GeneratedValue)
config.setGeneratedId(true);
}
}
if (oneToOneAnnotation != null || manyToOneAnnotation != null) {
// if we have a collection then make it a foreign collection
if (Collection.class.isAssignableFrom(field.getType()) || ForeignCollection.class.isAssignableFrom(field.getType())) {
config.setForeignCollection(true);
if (joinColumnAnnotation != null && stringNotEmpty(joinColumnAnnotation.name())) {
config.setForeignCollectionColumnName(joinColumnAnnotation.name());
}
if (manyToOneAnnotation != null) {
FetchType fetchType = manyToOneAnnotation.fetch();
if (fetchType != null && fetchType == FetchType.EAGER) {
config.setForeignCollectionEager(true);
}
}
} else {
// otherwise it is a foreign field
config.setForeign(true);
if (joinColumnAnnotation != null) {
if (stringNotEmpty(joinColumnAnnotation.name())) {
config.setColumnName(joinColumnAnnotation.name());
}
config.setCanBeNull(joinColumnAnnotation.nullable());
config.setUnique(joinColumnAnnotation.unique());
}
}
}
if (enumeratedAnnotation != null) {
EnumType enumType = enumeratedAnnotation.value();
if (enumType != null && enumType == EnumType.STRING) {
config.setDataType(DataType.ENUM_STRING);
} else {
config.setDataType(DataType.ENUM_INTEGER);
}
}
if (versionAnnotation != null) {
// just the presence of the version...
config.setVersion(true);
}
if (config.getDataPersister() == null) {
config.setDataPersister(DataPersisterManager.lookupForField(field));
}
config.setUseGetSet(DatabaseFieldConfig.findGetMethod(field, false) != null && DatabaseFieldConfig.findSetMethod(field, false) != null);
return config;
}Example 10
| Project: seam-forge-master File: NewEntityPlugin.java View source code |
@DefaultCommand(help = "Create a JPA @Entity")
public void newEntity(@Option(required = true, name = "named", description = "The @Entity name") final String entityName) throws FileNotFoundException {
// TODO this should accept a qualified name as a parameter instead of
// prompting for the package later
PersistenceFacet jpa = project.getFacet(PersistenceFacet.class);
JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
String entityPackage = shell.promptCommon("In which package you'd like to create this @Entity, or enter for default:", PromptType.JAVA_PACKAGE, jpa.getEntityPackage());
JavaClass javaClass = JavaParser.create(JavaClass.class).setPackage(entityPackage).setName(entityName).setPublic().addAnnotation(Entity.class).getOrigin().addInterface(Serializable.class);
Field<JavaClass> id = javaClass.addField("private long id = 0;");
id.addAnnotation(Id.class);
id.addAnnotation(GeneratedValue.class).setEnumValue("strategy", GenerationType.AUTO);
id.addAnnotation(Column.class).setStringValue("name", "id").setLiteralValue("updatable", "false").setLiteralValue("nullable", "false");
Field<JavaClass> version = javaClass.addField("private int version = 0;");
version.addAnnotation(Version.class);
version.addAnnotation(Column.class).setStringValue("name", "version");
Refactory.createGetterAndSetter(javaClass, id);
Refactory.createGetterAndSetter(javaClass, version);
JavaResource javaFileLocation = java.saveJavaSource(javaClass);
shell.println("Created @Entity [" + javaClass.getQualifiedName() + "]");
/**
* Pick up the generated resource.
*/
shell.execute("pick-up " + javaFileLocation.getFullyQualifiedName());
}Example 11
| Project: seasar2-master File: PropertyMetaFactoryImpl.java View source code |
/**
* è˜åˆ¥å?メタデータを処ç?†ã?—ã?¾ã?™ã€‚
*
* @param propertyMeta
* プãƒãƒ‘ティメタデータ
* @param field
* フィールド
* @param entityMeta
* エンティティメタデータ
*/
protected void doId(PropertyMeta propertyMeta, Field field, EntityMeta entityMeta) {
propertyMeta.setId(field.getAnnotation(Id.class) != null);
GeneratedValue generatedValue = field.getAnnotation(GeneratedValue.class);
if (generatedValue == null) {
return;
}
GenerationType generationType = generatedValue.strategy();
propertyMeta.setGenerationType(generationType);
switch(generationType) {
case AUTO:
doIdentityIdGenerator(propertyMeta, entityMeta);
doSequenceIdGenerator(propertyMeta, generatedValue, entityMeta);
doTableIdGenerator(propertyMeta, generatedValue, entityMeta);
break;
case IDENTITY:
doIdentityIdGenerator(propertyMeta, entityMeta);
break;
case SEQUENCE:
if (!doSequenceIdGenerator(propertyMeta, generatedValue, entityMeta)) {
throw new IdGeneratorNotFoundRuntimeException(entityMeta.getName(), propertyMeta.getName(), generatedValue.generator());
}
break;
case TABLE:
if (!doTableIdGenerator(propertyMeta, generatedValue, entityMeta)) {
throw new IdGeneratorNotFoundRuntimeException(entityMeta.getName(), propertyMeta.getName(), generatedValue.generator());
}
break;
}
}Example 12
| 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 13
| Project: deadcode4j-master File: HibernateAnnotationsAnalyzer.java View source code |
private void processGeneratedValueAnnotations(CtClass clazz) {
for (Annotation annotation : getAnnotations(clazz, "javax.persistence.GeneratedValue", METHOD, FIELD)) {
String generatorName = getStringFrom(annotation, "generator");
if (generatorName != null) {
getOrAddMappedSet(this.generatorUsages, generatorName).add(clazz.getName());
}
}
}Example 14
| Project: ef-orm-master File: ColumnTypeBuilder.java View source code |
private void init(Column col) {
generatedValue = GenerateTypeDef.create(fieldProvider.getAnnotation(javax.persistence.GeneratedValue.class));
version = fieldProvider.getAnnotation(javax.persistence.Version.class) != null;
lob = fieldProvider.getAnnotation(Lob.class) != null;
if (col != null) {
length = col.length();
precision = col.precision();
scale = col.scale();
nullable = col.nullable();
unique = col.unique();
if (col.columnDefinition().length() > 0) {
parseColumnDef(col.columnDefinition());
}
} else {
nullable = !javaType.isPrimitive();
}
}Example 15
| Project: clinic-softacad-master File: JPAOverriddenAnnotationReader.java View source code |
private void getEmbeddedId(List<Annotation> annotationList, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
if ("embedded-id".equals(element.getName())) {
if (isProcessingId(defaults)) {
Annotation annotation = getAttributeOverrides(element, defaults, false);
addIfNotNull(annotationList, annotation);
annotation = getAssociationOverrides(element, defaults, false);
addIfNotNull(annotationList, annotation);
AnnotationDescriptor ad = new AnnotationDescriptor(EmbeddedId.class);
annotationList.add(AnnotationFactory.create(ad));
getAccessType(annotationList, element);
}
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
Annotation annotation = getJavaAnnotation(EmbeddedId.class);
if (annotation != null) {
annotationList.add(annotation);
annotation = getJavaAnnotation(Column.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(Columns.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(GeneratedValue.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(Temporal.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(TableGenerator.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(SequenceGenerator.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AttributeOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AttributeOverrides.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AssociationOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AssociationOverrides.class);
addIfNotNull(annotationList, annotation);
}
}
}Example 16
| Project: CloudStack-archive-master File: Attribute.java View source code |
protected void setupColumnInfo(Class<?> clazz, AttributeOverride[] overrides, String tableName, boolean isEmbedded, boolean isId) {
flags = Flag.Selectable.setTrue(flags);
GeneratedValue gv = field.getAnnotation(GeneratedValue.class);
if (gv != null) {
if (gv.strategy() == GenerationType.IDENTITY) {
flags = Flag.DbGenerated.setTrue(flags);
} else if (gv.strategy() == GenerationType.SEQUENCE) {
assert (false) : "Sequence generation not supported.";
flags = Flag.DaoGenerated.setTrue(flags);
flags = Flag.Insertable.setTrue(flags);
flags = Flag.SequenceGV.setTrue(flags);
} else if (gv.strategy() == GenerationType.TABLE) {
flags = Flag.DaoGenerated.setTrue(flags);
flags = Flag.Insertable.setTrue(flags);
flags = Flag.TableGV.setTrue(flags);
} else if (gv.strategy() == GenerationType.AUTO) {
flags = Flag.DaoGenerated.setTrue(flags);
flags = Flag.Insertable.setTrue(flags);
flags = Flag.AutoGV.setTrue(flags);
}
}
if (isEmbedded) {
flags = Flag.Embedded.setTrue(flags);
}
if (isId) {
flags = Flag.Id.setTrue(flags);
} else {
Id id = field.getAnnotation(Id.class);
if (id != null) {
flags = Flag.Id.setTrue(flags);
}
}
column = field.getAnnotation(Column.class);
if (gv == null) {
if (column == null || (column.insertable() && column.table().length() == 0)) {
flags = Flag.Insertable.setTrue(flags);
}
if (column == null || (column.updatable() && column.table().length() == 0)) {
flags = Flag.Updatable.setTrue(flags);
}
if (column == null || column.nullable()) {
flags = Flag.Nullable.setTrue(flags);
}
if (column != null && column.encryptable()) {
flags = Flag.Encrypted.setTrue(flags);
}
}
ElementCollection ec = field.getAnnotation(ElementCollection.class);
if (ec != null) {
flags = Flag.Insertable.setFalse(flags);
flags = Flag.Selectable.setFalse(flags);
}
Temporal temporal = field.getAnnotation(Temporal.class);
if (temporal != null) {
if (temporal.value() == TemporalType.DATE) {
flags = Flag.Date.setTrue(flags);
} else if (temporal.value() == TemporalType.TIME) {
flags = Flag.Time.setTrue(flags);
} else if (temporal.value() == TemporalType.TIMESTAMP) {
flags = Flag.TimeStamp.setTrue(flags);
}
}
if (column != null && column.table().length() > 0) {
table = column.table();
}
columnName = DbUtil.getColumnName(field, overrides);
}Example 17
| Project: cloudstack-master File: Attribute.java View source code |
protected void setupColumnInfo(Class<?> clazz, AttributeOverride[] overrides, String tableName, boolean isEmbedded, boolean isId) {
flags = Flag.Selectable.setTrue(flags);
GeneratedValue gv = field.getAnnotation(GeneratedValue.class);
if (gv != null) {
if (gv.strategy() == GenerationType.IDENTITY) {
flags = Flag.DbGenerated.setTrue(flags);
} else if (gv.strategy() == GenerationType.SEQUENCE) {
assert (false) : "Sequence generation not supported.";
flags = Flag.DaoGenerated.setTrue(flags);
flags = Flag.Insertable.setTrue(flags);
flags = Flag.SequenceGV.setTrue(flags);
} else if (gv.strategy() == GenerationType.TABLE) {
flags = Flag.DaoGenerated.setTrue(flags);
flags = Flag.Insertable.setTrue(flags);
flags = Flag.TableGV.setTrue(flags);
} else if (gv.strategy() == GenerationType.AUTO) {
flags = Flag.DaoGenerated.setTrue(flags);
flags = Flag.Insertable.setTrue(flags);
flags = Flag.AutoGV.setTrue(flags);
}
}
if (isEmbedded) {
flags = Flag.Embedded.setTrue(flags);
}
if (isId) {
flags = Flag.Id.setTrue(flags);
} else {
Id id = field.getAnnotation(Id.class);
if (id != null) {
flags = Flag.Id.setTrue(flags);
}
}
column = field.getAnnotation(Column.class);
if (gv == null) {
if (column == null || (column.insertable() && column.table().length() == 0)) {
flags = Flag.Insertable.setTrue(flags);
}
if (column == null || (column.updatable() && column.table().length() == 0)) {
flags = Flag.Updatable.setTrue(flags);
}
if (column == null || column.nullable()) {
flags = Flag.Nullable.setTrue(flags);
}
Encrypt encrypt = field.getAnnotation(Encrypt.class);
if (encrypt != null && encrypt.encrypt()) {
flags = Flag.Encrypted.setTrue(flags);
}
}
ElementCollection ec = field.getAnnotation(ElementCollection.class);
if (ec != null) {
flags = Flag.Insertable.setFalse(flags);
flags = Flag.Selectable.setFalse(flags);
}
Temporal temporal = field.getAnnotation(Temporal.class);
if (temporal != null) {
if (temporal.value() == TemporalType.DATE) {
flags = Flag.Date.setTrue(flags);
} else if (temporal.value() == TemporalType.TIME) {
flags = Flag.Time.setTrue(flags);
} else if (temporal.value() == TemporalType.TIMESTAMP) {
flags = Flag.TimeStamp.setTrue(flags);
}
}
if (column != null && column.table().length() > 0) {
table = column.table();
}
columnName = DbUtil.getColumnName(field, overrides);
}Example 18
| Project: cloudstack-old-master File: Attribute.java View source code |
protected void setupColumnInfo(Class<?> clazz, AttributeOverride[] overrides, String tableName, boolean isEmbedded, boolean isId) {
flags = Flag.Selectable.setTrue(flags);
GeneratedValue gv = field.getAnnotation(GeneratedValue.class);
if (gv != null) {
if (gv.strategy() == GenerationType.IDENTITY) {
flags = Flag.DbGenerated.setTrue(flags);
} else if (gv.strategy() == GenerationType.SEQUENCE) {
assert (false) : "Sequence generation not supported.";
flags = Flag.DaoGenerated.setTrue(flags);
flags = Flag.Insertable.setTrue(flags);
flags = Flag.SequenceGV.setTrue(flags);
} else if (gv.strategy() == GenerationType.TABLE) {
flags = Flag.DaoGenerated.setTrue(flags);
flags = Flag.Insertable.setTrue(flags);
flags = Flag.TableGV.setTrue(flags);
} else if (gv.strategy() == GenerationType.AUTO) {
assert (false) : "Auto generation not supported.";
flags = Flag.DaoGenerated.setTrue(flags);
flags = Flag.Insertable.setTrue(flags);
flags = Flag.AutoGV.setTrue(flags);
}
}
if (isEmbedded) {
flags = Flag.Embedded.setTrue(flags);
}
if (isId) {
flags = Flag.Id.setTrue(flags);
} else {
Id id = field.getAnnotation(Id.class);
if (id != null) {
flags = Flag.Id.setTrue(flags);
}
}
column = field.getAnnotation(Column.class);
if (gv == null) {
if (column == null || (column.insertable() && column.table().length() == 0)) {
flags = Flag.Insertable.setTrue(flags);
}
if (column == null || (column.updatable() && column.table().length() == 0)) {
flags = Flag.Updatable.setTrue(flags);
}
if (column == null || column.nullable()) {
flags = Flag.Nullable.setTrue(flags);
}
}
Temporal temporal = field.getAnnotation(Temporal.class);
if (temporal != null) {
if (temporal.value() == TemporalType.DATE) {
flags = Flag.Date.setTrue(flags);
} else if (temporal.value() == TemporalType.TIME) {
flags = Flag.Time.setTrue(flags);
} else if (temporal.value() == TemporalType.TIMESTAMP) {
flags = Flag.TimeStamp.setTrue(flags);
}
}
if (column != null && column.table().length() > 0) {
table = column.table();
}
columnName = DbUtil.getColumnName(field, overrides);
}Example 19
| Project: cosmos-message-master File: BeanPersistenceBuilder.java View source code |
private void evalColumn(Field field, Annotation ann) {
if (field == null || ann == null) {
logger.debug("field or ann is null!");
return;
}
logger.debug("field '{}' annotation is '{}'", field.getName(), ann);
Class annType = ann.annotationType();
if (Id.class.equals(annType)) {
// 主键
String idFieldName = field.getName();
String idColumnName = DynamicBeanUtils.underscoreName(idFieldName);
this.beanPersistenceDef.setIdClass(field.getType());
this.beanPersistenceDef.setIdFieldName(idFieldName);
this.beanPersistenceDef.setIdColumnName(idColumnName);
} else if (GeneratedValue.class.equals(annType)) {
GeneratedValue gv = (GeneratedValue) ann;
this.beanPersistenceDef.setGenerator(gv.generator());
} else if (Column.class.equals(annType)) {
Column column = (Column) ann;
// æ™®é€šå—æ®µ
String fieldName = field.getName();
String columnName = column.name();
if (StringUtils.isEmpty(columnName)) {
columnName = DynamicBeanUtils.underscoreName(fieldName);
}
this.beanPersistenceDef.addFieldColumnMapping(fieldName, columnName);
}
}Example 20
| Project: EmiteCBB-master File: Generate.java View source code |
public void generateScaffolding() {
// Locate domain model classes that we can process.
// Currently, we only support classes that extend the
// play.db.jpa.Model or siena.Model classes.
List<Class> classes = Play.classloader.getAllClasses();
ScaffoldingGenerator generator = new ScaffoldingGenerator();
generator.setForceOverwrite(forceOverwrite);
generator.setIncludeLayout(includeLayout);
generator.setIncludeLogin(includeLogin);
for (Class clazz : classes) {
// If this model is of a supported type, queue it up
// so the ScaffoldGenerator will create its controller
// and views.
PersistenceStrategy persistenceStrategy = PersistenceStrategy.forModel(clazz);
if (persistenceStrategy != null) {
String simpleName = clazz.getSimpleName();
boolean includeEntity = false;
// specified
if (includeRegEx == null) {
includeEntity = true;
}
// that match
if (includeRegEx != null && match(simpleName, includeRegEx)) {
includeEntity = true;
}
// always exclude models that match the --exclude= parameter
if (excludeRegEx != null && match(simpleName, excludeRegEx)) {
includeEntity = false;
}
if (includeEntity) {
Entity entity = new Entity(clazz);
// validate known limitations
if (persistenceStrategy == PersistenceStrategy.PURE_JPA) {
String idField = entity.getIdField();
if (idField == null) {
Logger.warn("Can not process %s because it needs an @Id annotated column", simpleName);
continue;
}
if (!Fields.annotations(clazz, idField).contains(GeneratedValue.class)) {
Logger.warn("Can not process %s because key must be auto-generated (use @GeneratedValue)", simpleName);
continue;
}
}
// we appear to be good to go!
generator.addEntity(entity);
} else {
Logger.info("Skipping %s", simpleName);
}
}
}
generator.generate();
}Example 21
| Project: hexa.tools-master File: PersistenceConfigurationFactoryGenerator.java View source code |
private void writeBody(SourceWriter sourceWriter) {
sourceWriter.println("private PersistenceConfiguration config;");
sourceWriter.println("@Override");
sourceWriter.println("public PersistenceConfiguration getPersistenceConfiguration() {");
sourceWriter.println("if( config == null )");
sourceWriter.println("createConfig();");
sourceWriter.println("return config;");
sourceWriter.println("}");
sourceWriter.println("private void createConfig() {");
sourceWriter.println("ClassBundle clazzBundle = GWT.create( ClassBundle.class );");
sourceWriter.println("clazzBundle.register();");
sourceWriter.println("config = new PersistenceConfiguration();");
sourceWriter.println("EntityConfiguration ec = null;");
for (int i = 0; i < entityClasses.length; i++) {
Class<?> entityClass = entityClasses[i];
// ensure class has the @Entity annotation...
assert entityClass.getAnnotation(Entity.class) != null : "Class xxx should be annotated with @Entity !";
// search @Id field : class, name, generation policy
Field idField = getIdField(entityClass);
assert idField != null : "Entity class should have an @Id field";
String generationTypeString = "GenerationType.SEQUENCE";
GeneratedValue generatedValueAnnotation = idField.getAnnotation(GeneratedValue.class);
if (generatedValueAnnotation != null && generatedValueAnnotation.strategy() != null)
generationTypeString = "GenerationType." + generatedValueAnnotation.strategy().name();
sourceWriter.println("ec = config.addEntityConfiguration( " + entityClass.getName() + ".class, " + idField.getType().getName() + ".class, \"" + idField.getName() + "\", " + generationTypeString + " );");
Field[] fields = entityClass.getDeclaredFields();
for (int f = 0; f < fields.length; f++) {
Id idAnnotation = fields[f].getAnnotation(Id.class);
if (idAnnotation != null)
continue;
// TODO : check transcient, final, ...
OneToMany oneToMany = fields[f].getAnnotation(OneToMany.class);
if (oneToMany != null) {
//@OneToMany( mappedBy = "category" )
//private List<Article> articles;
String mappedBy = oneToMany.mappedBy();
//ec.addOneToManyFieldConfiguration( List.class, Article.class, "articles", "category", false );
JClassType entityType = typeOracle.findType(entityClass.getName());
JField jField = entityType.findField(fields[f].getName());
String containerClassName = jField.getType().getErasedType().getQualifiedSourceName();
String targetClassName = jField.getType().isParameterized().getTypeArgs()[0].getQualifiedSourceName();
sourceWriter.println("ec.addOneToManyFieldConfiguration( " + containerClassName + ".class, " + targetClassName + ".class, \"" + fields[f].getName() + "\", \"" + mappedBy + "\", false );");
continue;
}
ManyToOne manyToOne = fields[f].getAnnotation(ManyToOne.class);
if (manyToOne != null) {
//@ManyToOne( fetch = FetchType.LAZY, cascade = { CascadeType.MERGE } )
//@JoinColumn( name="category_id" )
//Category category;
String columnName = fields[f].getName() + "_id";
JoinColumn joinColumn = fields[f].getAnnotation(JoinColumn.class);
if (joinColumn != null)
columnName = joinColumn.name();
String fetchTypeString = "FetchType." + manyToOne.fetch();
// ec.addManyToOneFieldConfiguration( Category.class, "category", "category_id", FetchType.LAZY );
sourceWriter.println("ec.addManyToOneFieldConfiguration( " + fields[f].getType().getName() + ".class, \"" + fields[f].getName() + "\", \"" + columnName + "\", " + fetchTypeString + " );");
continue;
}
// normal field fields
sourceWriter.println("ec.addFieldConfiguration( " + fields[f].getType().getName() + ".class, \"" + fields[f].getName() + "\" );");
}
}
sourceWriter.println("}");
}Example 22
| Project: hibernate-core-ogm-master File: JPAOverridenAnnotationReader.java View source code |
private void getEmbeddedId(List<Annotation> annotationList, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
if ("embedded-id".equals(element.getName())) {
if (isProcessingId(defaults)) {
Annotation annotation = getAttributeOverrides(element, defaults, false);
addIfNotNull(annotationList, annotation);
annotation = getAssociationOverrides(element, defaults, false);
addIfNotNull(annotationList, annotation);
AnnotationDescriptor ad = new AnnotationDescriptor(EmbeddedId.class);
annotationList.add(AnnotationFactory.create(ad));
getAccessType(annotationList, element);
}
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
Annotation annotation = getJavaAnnotation(EmbeddedId.class);
if (annotation != null) {
annotationList.add(annotation);
annotation = getJavaAnnotation(Column.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(Columns.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(GeneratedValue.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(Temporal.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(TableGenerator.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(SequenceGenerator.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AttributeOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AttributeOverrides.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AssociationOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AssociationOverrides.class);
addIfNotNull(annotationList, annotation);
}
}
}Example 23
| Project: norm-master File: StandardPojoInfo.java View source code |
/**
* Apply the annotations on the field or getter method to the property.
* @throws IllegalAccessException
* @throws InstantiationException
*/
private void applyAnnotations(Property prop, AnnotatedElement ae) throws InstantiationException, IllegalAccessException {
Column col = ae.getAnnotation(Column.class);
if (col != null) {
String name = col.name().trim();
if (name.length() > 0) {
prop.name = name;
}
prop.columnAnnotation = col;
}
if (ae.getAnnotation(Id.class) != null) {
prop.isPrimaryKey = true;
primaryKeyName = prop.name;
}
if (ae.getAnnotation(GeneratedValue.class) != null) {
generatedColumnName = prop.name;
prop.isGenerated = true;
}
if (prop.dataType.isEnum()) {
prop.isEnumField = true;
prop.enumClass = (Class<Enum>) prop.dataType;
/* We default to STRING enum type. Can be overriden with @Enumerated annotation */
prop.enumType = EnumType.STRING;
if (ae.getAnnotation(Enumerated.class) != null) {
prop.enumType = ae.getAnnotation(Enumerated.class).value();
}
}
DbSerializer sc = ae.getAnnotation(DbSerializer.class);
if (sc != null) {
prop.serializer = sc.value().newInstance();
}
}Example 24
| Project: Play--Scaffold-master File: Generate.java View source code |
public void generateScaffolding() {
// Locate domain model classes that we can process.
// Currently, we only support classes that extend the
// play.db.jpa.Model or siena.Model classes.
List<Class> classes = Play.classloader.getAllClasses();
ScaffoldingGenerator generator = new ScaffoldingGenerator();
generator.setForceOverwrite(forceOverwrite);
generator.setIncludeLayout(includeLayout);
generator.setIncludeLogin(includeLogin);
generator.setFlattenPaths(flattenPaths);
for (Class clazz : classes) {
// If this model is of a supported type, queue it up
// so the ScaffoldGenerator will create its controller
// and views.
PersistenceStrategy persistenceStrategy = PersistenceStrategy.forModel(clazz);
if (persistenceStrategy != null) {
String simpleName = clazz.getSimpleName();
boolean includeEntity = false;
// specified
if (includeRegEx == null) {
includeEntity = true;
}
// that match
if (includeRegEx != null && match(simpleName, includeRegEx)) {
includeEntity = true;
}
// always exclude models that match the --exclude= parameter
if (excludeRegEx != null && match(simpleName, excludeRegEx)) {
includeEntity = false;
}
if (includeEntity) {
Entity entity = new Entity(clazz);
// validate known limitations
if (persistenceStrategy == PersistenceStrategy.PURE_JPA) {
String idField = entity.getIdField();
if (idField == null) {
Logger.warn("Can not process %s because it needs an @Id annotated column", simpleName);
continue;
}
if (!Fields.annotations(clazz, idField).contains(GeneratedValue.class)) {
Logger.warn("Can not process %s because key must be auto-generated (use @GeneratedValue)", simpleName);
continue;
}
}
// we appear to be good to go!
generator.addEntity(entity);
} else {
Logger.info("Skipping %s", simpleName);
}
}
}
generator.generate();
}Example 25
| Project: service-framework-master File: PropertyEnhancer.java View source code |
private void autoInjectProperty(CtClass ctClass) {
//连接数æ?®åº“,自动获å?–所有信æ?¯ï¼Œç„¶å?Žæ·»åŠ å±žæ€§
String entitySimpleName = ctClass.getSimpleName();
List<String> skipFields = list();
notMapping(ctClass, skipFields);
try {
DBType dbType = ServiceFramwork.injector.getInstance(DBType.class);
DBInfo dbInfo = ServiceFramwork.injector.getInstance(DBInfo.class);
Map<String, String> columns = dbInfo.tableColumns.get(entitySimpleName);
for (String columnName : columns.keySet()) {
String fieldName = columnName;
String fieldType = columns.get(columnName);
if (skipFields.contains(fieldName))
continue;
//对定义过的属性略过
boolean pass = true;
try {
ctClass.getField(fieldName);
} catch (Exception e) {
pass = false;
}
if (pass)
continue;
ConstPool constPool = ctClass.getClassFile().getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
CtField ctField = CtField.make(" private " + dbType.typeToJava(fieldType).v2() + " " + fieldName + " ;", ctClass);
Tuple<Class, Map> tuple = dbType.dateType(fieldType, constPool);
if (tuple != null) {
createAnnotation(attr, tuple.v1(), tuple.v2());
}
if (fieldName.equals("id")) {
createAnnotation(attr, javax.persistence.Id.class, map());
createAnnotation(attr, javax.persistence.GeneratedValue.class, map());
} else {
createAnnotation(attr, Column.class, map("nullable", new BooleanMemberValue(true, constPool)));
}
if (attr.getAnnotations().length > 0) {
ctField.getFieldInfo().addAttribute(attr);
}
ctClass.addField(ctField);
}
} catch (Exception e) {
e.printStackTrace();
}
ctClass.defrost();
}Example 26
| 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 27
| Project: jirm-master File: SqlParameterDefinition.java View source code |
static SqlParameterDefinition parameterDef(SqlObjectConfig config, Class<?> objectType, String parameterName, Class<?> parameterType, int order) {
final SqlParameterDefinition definition;
String sn = null;
ManyToOne manyToOne = getAnnotation(objectType, parameterName, ManyToOne.class);
if (manyToOne != null) {
Class<?> subK = checkNotNull(manyToOne.targetEntity(), "targetEntity not set");
JoinColumn joinColumn = getAnnotation(objectType, parameterName, JoinColumn.class);
SqlObjectDefinition<?> od = SqlObjectDefinition.fromClass(subK, config);
checkState(!od.getIdParameters().isEmpty(), "No id parameters");
if (joinColumn != null)
sn = joinColumn.name();
if (sn == null)
sn = config.getNamingStrategy().propertyToColumnName(parameterName);
FetchType fetch = manyToOne.fetch();
int depth;
if (FetchType.LAZY == fetch) {
depth = 1;
} else {
depth = config.getMaximumLoadDepth();
}
SqlParameterObjectDefinition sod = new SqlParameterObjectDefinition(od, depth);
definition = SqlParameterDefinition.newComplexInstance(config.getConverter(), parameterName, sod, order, sn);
} else {
Column col = getAnnotation(objectType, parameterName, Column.class);
if (col != null && !isNullOrEmpty(col.name()))
sn = col.name();
Id id = getAnnotation(objectType, parameterName, Id.class);
Version version = getAnnotation(objectType, parameterName, Version.class);
GeneratedValue generated = getAnnotation(objectType, parameterName, GeneratedValue.class);
Enumerated enumerated = getAnnotation(objectType, parameterName, Enumerated.class);
boolean idFlag = id != null;
boolean versionFlag = version != null;
boolean generatedFlag = generated != null;
if (sn == null)
sn = config.getNamingStrategy().propertyToColumnName(parameterName);
definition = SqlParameterDefinition.newSimpleInstance(config.getConverter(), parameterName, parameterType, order, sn, idFlag, versionFlag, generatedFlag, Optional.fromNullable(enumerated));
}
return definition;
}Example 28
| Project: ebean-master File: AnnotationFields.java View source code |
private void readField(DeployBeanProperty prop) {
// all Enums will have a ScalarType assigned...
boolean isEnum = prop.getPropertyType().isEnum();
Enumerated enumerated = get(prop, Enumerated.class);
if (isEnum || enumerated != null) {
util.setEnumScalarType(enumerated, prop);
}
// its persistent and assumed to be on the base table
// rather than on a secondary table
prop.setDbRead(true);
prop.setDbInsertable(true);
prop.setDbUpdateable(true);
Column column = get(prop, Column.class);
if (column != null) {
readColumn(column, prop);
}
readJsonAnnotations(prop);
if (prop.getDbColumn() == null) {
// No @Column annotation or @Column.name() not set
// Use the NamingConvention to set the DB column name
String dbColumn = namingConvention.getColumnFromProperty(beanType, prop.getName());
prop.setDbColumn(dbColumn);
}
GeneratedValue gen = get(prop, GeneratedValue.class);
if (gen != null) {
readGenValue(gen, prop);
}
Id id = get(prop, Id.class);
if (id != null) {
readId(prop);
}
// determine the JDBC type using Lob/Temporal
// otherwise based on the property Class
Temporal temporal = get(prop, Temporal.class);
if (temporal != null) {
readTemporal(temporal, prop);
} else if (get(prop, Lob.class) != null) {
util.setLobType(prop);
}
if (get(prop, TenantId.class) != null) {
prop.setTenantId();
}
if (get(prop, Draft.class) != null) {
prop.setDraft();
}
if (get(prop, DraftOnly.class) != null) {
prop.setDraftOnly();
}
if (get(prop, DraftDirty.class) != null) {
prop.setDraftDirty();
}
if (get(prop, DraftReset.class) != null) {
prop.setDraftReset();
}
SoftDelete softDelete = get(prop, SoftDelete.class);
if (softDelete != null) {
prop.setSoftDelete();
}
DbComment comment = get(prop, DbComment.class);
if (comment != null) {
prop.setDbComment(comment.value());
}
DbHstore dbHstore = get(prop, DbHstore.class);
if (dbHstore != null) {
util.setDbHstore(prop, dbHstore);
}
DbJson dbJson = get(prop, DbJson.class);
if (dbJson != null) {
util.setDbJsonType(prop, dbJson);
} else {
DbJsonB dbJsonB = get(prop, DbJsonB.class);
if (dbJsonB != null) {
util.setDbJsonBType(prop, dbJsonB);
}
}
DbArray dbArray = get(prop, DbArray.class);
if (dbArray != null) {
util.setDbArray(prop, dbArray);
}
DocCode docCode = get(prop, DocCode.class);
if (docCode != null) {
prop.setDocCode(docCode);
}
DocSortable docSortable = get(prop, DocSortable.class);
if (docSortable != null) {
prop.setDocSortable(docSortable);
}
DocProperty docProperty = get(prop, DocProperty.class);
if (docProperty != null) {
prop.setDocProperty(docProperty);
}
Formula formula = get(prop, Formula.class);
if (formula != null) {
prop.setSqlFormula(formula.select(), formula.join());
}
Aggregation aggregation = get(prop, Aggregation.class);
if (aggregation != null) {
prop.setAggregation(aggregation.value());
}
Version version = get(prop, Version.class);
if (version != null) {
// explicitly specify a version column
prop.setVersionColumn();
generatedPropFactory.setVersion(prop);
}
Basic basic = get(prop, Basic.class);
if (basic != null) {
prop.setFetchType(basic.fetch());
if (!basic.optional()) {
prop.setNullable(false);
}
} else if (prop.isLob()) {
// use the default Lob fetchType
prop.setFetchType(defaultLobFetchType);
}
if (get(prop, WhenCreated.class) != null || get(prop, CreatedTimestamp.class) != null) {
generatedPropFactory.setInsertTimestamp(prop);
}
if (get(prop, WhenModified.class) != null || get(prop, UpdatedTimestamp.class) != null) {
generatedPropFactory.setUpdateTimestamp(prop);
}
initWhoProperties(prop);
if (get(prop, HistoryExclude.class) != null) {
prop.setExcludedFromHistory();
}
Length length = get(prop, Length.class);
if (length != null) {
prop.setDbLength(length.value());
}
io.ebean.annotation.NotNull nonNull = get(prop, io.ebean.annotation.NotNull.class);
if (nonNull != null) {
prop.setNullable(false);
}
if (validationAnnotations) {
NotNull notNull = get(prop, NotNull.class);
if (notNull != null && isEbeanValidationGroups(notNull.groups())) {
// Not null on all validation groups so enable
// DDL generation of Not Null Constraint
prop.setNullable(false);
}
if (!prop.isLob()) {
// take the max size of all @Size annotations
int maxSize = -1;
for (Size size : getAll(prop, Size.class)) {
if (size.max() < Integer.MAX_VALUE) {
maxSize = Math.max(maxSize, size.max());
}
}
if (maxSize != -1) {
prop.setDbLength(maxSize);
}
}
}
// Want to process last so we can use with @Formula
Transient t = get(prop, Transient.class);
if (t != null) {
// it is not a persistent property.
prop.setDbRead(false);
prop.setDbInsertable(false);
prop.setDbUpdateable(false);
prop.setTransient();
}
if (!prop.isTransient()) {
EncryptDeploy encryptDeploy = util.getEncryptDeploy(info.getDescriptor().getBaseTableFull(), prop.getDbColumn());
if (encryptDeploy == null || encryptDeploy.getMode().equals(Mode.MODE_ANNOTATION)) {
Encrypted encrypted = get(prop, Encrypted.class);
if (encrypted != null) {
setEncryption(prop, encrypted.dbEncryption(), encrypted.dbLength());
}
} else if (Mode.MODE_ENCRYPT.equals(encryptDeploy.getMode())) {
setEncryption(prop, encryptDeploy.isDbEncrypt(), encryptDeploy.getDbLength());
}
}
Set<Index> indices = getAll(prop, Index.class);
for (Index index : indices) {
addIndex(prop, index);
}
}Example 29
| Project: mobicents-master File: ConcreteProfileEntityGenerator.java View source code |
/**
* Generates a class that extends {@link ProfileEntityArrayAttributeValue} for a specific entity attribute of array type value
* @param concreteProfileEntityClass
* @param profileAttributeName
* @return
*/
private Class<?> generateProfileAttributeArrayValueClass(CtClass concreteProfileEntityClass, String profileAttributeName, boolean unique) {
CtClass concreteArrayValueClass = null;
try {
// define the concrete profile attribute array value class name
String concreteArrayValueClassName = profileComponent.getProfileCmpInterfaceClass().getName() + "PEAAV_" + ClassGeneratorUtils.capitalize(profileAttributeName);
// create javassist class
concreteArrayValueClass = ClassGeneratorUtils.createClass(concreteArrayValueClassName, new String[] { Serializable.class.getName() });
// set inheritance
ClassGeneratorUtils.createInheritanceLink(concreteArrayValueClass, ProfileEntityArrayAttributeValue.class.getName());
// annotate class with @Entity
ClassGeneratorUtils.addAnnotation(Entity.class.getName(), new LinkedHashMap<String, Object>(), concreteArrayValueClass);
// generate a random table name
addTableAnnotationToPEAAV("SLEE_PEAAV_" + profileComponent.getProfileCmpInterfaceClass().getSimpleName() + "_" + Math.abs(profileComponent.getComponentID().hashCode()) + profileAttributeName, unique, concreteArrayValueClass);
// override @id
String getIdNameMethodSrc = "public long getId() { return super.getId(); }";
CtMethod getIdNameMethod = CtNewMethod.make(getIdNameMethodSrc, concreteArrayValueClass);
ClassGeneratorUtils.addAnnotation(Id.class.getName(), new LinkedHashMap<String, Object>(), getIdNameMethod);
ClassGeneratorUtils.addAnnotation(GeneratedValue.class.getName(), new LinkedHashMap<String, Object>(), getIdNameMethod);
concreteArrayValueClass.addMethod(getIdNameMethod);
// override getter methods
String getSerializableMethodSrc = "public " + Serializable.class.getName() + " getSerializable() { return super.getSerializable(); }";
CtMethod getSerializableMethod = CtNewMethod.make(getSerializableMethodSrc, concreteArrayValueClass);
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
map.put("name", "serializable");
//if (unique)map.put("unique", true);
ClassGeneratorUtils.addAnnotation(Column.class.getName(), map, getSerializableMethod);
concreteArrayValueClass.addMethod(getSerializableMethod);
String getStringMethodSrc = "public String getString() { return super.getString(); }";
CtMethod getStringMethod = CtNewMethod.make(getStringMethodSrc, concreteArrayValueClass);
map = new LinkedHashMap<String, Object>();
map.put("name", "string");
//if (unique)map.put("unique", true);
ClassGeneratorUtils.addAnnotation(Column.class.getName(), map, getStringMethod);
concreteArrayValueClass.addMethod(getStringMethod);
// FIXME add join columns here or in profile entity class to make
// the relation without a join table, atm if this is changed, the
// inserts on this table go with profile and table name as null %)
// THE PROFILENTITY FIELD IN AAV CLASS IS REQUIRED FOR THE RELATION WITH PROFILE ENTITY CLASS WITHOUT A JOIN TABLE
// add join column regarding the relation from array attr value to profile entity
CtField ctField = ClassGeneratorUtils.addField(concreteProfileEntityClass, "owner", concreteArrayValueClass);
ClassGeneratorUtils.generateSetter(ctField, null);
CtMethod getter = ClassGeneratorUtils.generateGetter(ctField, null);
//ClassGeneratorUtils.addAnnotation(ManyToOne.class.getName(), new LinkedHashMap<String, Object>(), getter);
// ----
ConstPool cp = getter.getMethodInfo().getConstPool();
AnnotationsAttribute attr = (AnnotationsAttribute) getter.getMethodInfo().getAttribute(AnnotationsAttribute.visibleTag);
if (attr == null) {
attr = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);
}
Annotation manyToOne = new Annotation(ManyToOne.class.getName(), cp);
manyToOne.addMemberValue("optional", new BooleanMemberValue(false, cp));
attr.addAnnotation(manyToOne);
Annotation joinColumns = new Annotation(JoinColumns.class.getName(), cp);
Annotation joinColumn1 = new Annotation(JoinColumn.class.getName(), cp);
joinColumn1.addMemberValue("name", new StringMemberValue("owner_tableName", cp));
joinColumn1.addMemberValue("referencedColumnName", new StringMemberValue("tableName", cp));
Annotation joinColumn2 = new Annotation(JoinColumn.class.getName(), cp);
joinColumn2.addMemberValue("name", new StringMemberValue("owner_profileName", cp));
joinColumn2.addMemberValue("referencedColumnName", new StringMemberValue("profileName", cp));
ArrayMemberValue joinColumnsMemberValue = new ArrayMemberValue(cp);
joinColumnsMemberValue.setValue(new MemberValue[] { new AnnotationMemberValue(joinColumn1, cp), new AnnotationMemberValue(joinColumn2, cp) });
joinColumns.addMemberValue("value", joinColumnsMemberValue);
attr.addAnnotation(joinColumns);
getter.getMethodInfo().addAttribute(attr);
// generate concrete setProfileEntity method
String setProfileEntityMethodSrc = "public void setProfileEntity(" + ProfileEntity.class.getName() + " profileEntity){ setOwner((" + concreteProfileEntityClass.getName() + ")profileEntity); }";
CtMethod setProfileEntityMethod = CtMethod.make(setProfileEntityMethodSrc, concreteArrayValueClass);
concreteArrayValueClass.addMethod(setProfileEntityMethod);
// write and load the attr array value class
String deployDir = profileComponent.getDeploymentDir().getAbsolutePath();
if (logger.isDebugEnabled()) {
logger.debug("Writing PROFILE ATTR ARRAY VALUE CONCRETE CLASS ( " + concreteArrayValueClass.getName() + " ) to: " + deployDir);
}
concreteArrayValueClass.writeFile(deployDir);
return Thread.currentThread().getContextClassLoader().loadClass(concreteArrayValueClass.getName());
} catch (Throwable e) {
throw new SLEEException(e.getMessage(), e);
} finally {
if (concreteArrayValueClass != null) {
concreteArrayValueClass.defrost();
}
}
}Example 30
| Project: picketlink-master File: SchemaOperations.java View source code |
private JavaClass createIdentityAttributeEntity(String packageName) {
String lineSeparator = System.getProperty("line.separator");
JavaClass javaClass = javaSourceFactory.create(JavaClass.class).setName("IdentityAttribute").setPublic().addInterface(Serializable.class);
javaClass.setPackage(packageName);
javaClass.addAnnotation(Entity.class);
javaClass.addAnnotation(IdentityManaged.class).setClassValue(IdentityType.class);
// Create the id property
Field<JavaClass> f = javaClass.addField("private Long id = null;");
f.addAnnotation(Id.class);
f.addAnnotation(GeneratedValue.class);
javaClass.addMethod("public Long getId() {" + lineSeparator + " return id;" + lineSeparator + "}");
javaClass.addMethod("public void setId(Long id) {" + lineSeparator + " this.id = id;" + lineSeparator + "}");
// Create the owner property
f = javaClass.addField("private IdentityEntity owner;");
f.addAnnotation(ManyToOne.class);
f.addAnnotation(OwnerReference.class);
javaClass.addMethod("public IdentityEntity getIdentity() {" + lineSeparator + " return identity;" + lineSeparator + "}");
javaClass.addMethod("public void setIdentity(IdentityEntity identity) {" + lineSeparator + " this.identity = identity;" + lineSeparator + "}");
// Create the attributeClass property
f = javaClass.addField("private String attributeClass;");
f.addAnnotation(AttributeClass.class);
javaClass.addMethod("public String getAttributeClass() {" + lineSeparator + " return attributeClass;" + lineSeparator + "}");
javaClass.addMethod("public void setAttributeClass(String attributeClass) {" + lineSeparator + " this.attributeClass = attributeClass;" + lineSeparator + "}");
// Create the name property
f = javaClass.addField("private String name;");
f.addAnnotation(AttributeName.class);
javaClass.addMethod("public String getName() {" + lineSeparator + " return name;" + lineSeparator + "}");
javaClass.addMethod("public void setName(String name) {" + lineSeparator + " this.name = name;" + lineSeparator + "}");
// Create the value property
f = javaClass.addField("private String value;");
f.addAnnotation(AttributeValue.class);
javaClass.addMethod("public String getValue() {" + lineSeparator + " return value;" + lineSeparator + "}");
javaClass.addMethod("public void setValue(String value) {" + lineSeparator + " this.value = value;" + lineSeparator + "}");
javaClass.addImport(Entity.class);
javaClass.addImport(IdentityManaged.class);
javaClass.addImport(ManyToOne.class);
javaClass.addImport(OwnerReference.class);
javaClass.addImport(AttributeClass.class);
javaClass.addImport(AttributeName.class);
javaClass.addImport(AttributeValue.class);
javaClass.addImport(Serializable.class);
return javaClass;
}Example 31
| Project: projectforge-webapp-master File: HibernateUtils.java View source code |
public static Serializable getIdentifier(final Object obj) {
if (obj instanceof BaseDO<?>) {
return getIdentifier((BaseDO<?>) obj);
}
for (final Field field : obj.getClass().getDeclaredFields()) {
if (field.isAnnotationPresent(Id.class) == true && field.isAnnotationPresent(GeneratedValue.class) == true) {
final boolean isAccessible = field.isAccessible();
try {
field.setAccessible(true);
final Object idObject = field.get(obj);
field.setAccessible(isAccessible);
if (idObject != null && Serializable.class.isAssignableFrom(idObject.getClass()) == true) {
return (Serializable) idObject;
}
} catch (final IllegalArgumentException e) {
e.printStackTrace();
} catch (final IllegalAccessException e) {
e.printStackTrace();
}
}
}
return null;
}Example 32
| Project: tapestry-model-master File: JpaDescriptorDecorator.java View source code |
/**
* @param type
* @param descriptor
* @param parentClassDescriptor
* @return
*/
private IdentifierDescriptor createIdentifierDescriptor(Class type, TynamoPropertyDescriptor descriptor, TynamoClassDescriptor parentClassDescriptor) {
IdentifierDescriptor identifierDescriptor;
ManagedType mapping = getMapping(type);
if (mapping.getAttribute(descriptor.getName()).getPersistentAttributeType().equals(Attribute.PersistentAttributeType.EMBEDDED)) {
EmbeddedDescriptor embeddedDescriptor = buildEmbeddedDescriptor(type, findMetadata(type), descriptor, parentClassDescriptor);
embeddedDescriptor.setIdentifier(true);
identifierDescriptor = embeddedDescriptor;
} else {
identifierDescriptor = new IdentifierDescriptorImpl(type, descriptor);
}
if (getAnnotation(mapping.getSingularAttribute(descriptor.getName()).getJavaMember(), GeneratedValue.class) == null) {
identifierDescriptor.setGenerated(false);
}
return identifierDescriptor;
}Example 33
| Project: hibernate-orm-master File: JPAOverriddenAnnotationReader.java View source code |
private void getEmbeddedId(List<Annotation> annotationList, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
if ("embedded-id".equals(element.getName())) {
if (isProcessingId(defaults)) {
Annotation annotation = getAttributeOverrides(element, defaults, false);
addIfNotNull(annotationList, annotation);
annotation = getAssociationOverrides(element, defaults, false);
addIfNotNull(annotationList, annotation);
AnnotationDescriptor ad = new AnnotationDescriptor(EmbeddedId.class);
annotationList.add(AnnotationFactory.create(ad));
getAccessType(annotationList, element);
}
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
Annotation annotation = getPhysicalAnnotation(EmbeddedId.class);
if (annotation != null) {
annotationList.add(annotation);
annotation = getPhysicalAnnotation(Column.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Columns.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(GeneratedValue.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Temporal.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(TableGenerator.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(SequenceGenerator.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AttributeOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AttributeOverrides.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AssociationOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AssociationOverrides.class);
addIfNotNull(annotationList, annotation);
}
}
}Example 34
| Project: jain-slee-master File: ConcreteProfileEntityGenerator.java View source code |
/**
* Generates a class that extends {@link ProfileEntityArrayAttributeValue} for a specific entity attribute of array type value
* @param concreteProfileEntityClass
* @param profileAttributeName
* @return
*/
private Class<?> generateProfileAttributeArrayValueClass(CtClass concreteProfileEntityClass, String profileAttributeName, boolean unique) {
CtClass concreteArrayValueClass = null;
try {
// define the concrete profile attribute array value class name
String concreteArrayValueClassName = profileComponent.getProfileCmpInterfaceClass().getName() + "PEAAV_" + ClassGeneratorUtils.capitalize(profileAttributeName);
// create javassist class
concreteArrayValueClass = ClassGeneratorUtils.createClass(concreteArrayValueClassName, new String[] { Serializable.class.getName() });
// set inheritance
ClassGeneratorUtils.createInheritanceLink(concreteArrayValueClass, ProfileEntityArrayAttributeValue.class.getName());
// annotate class with @Entity
ClassGeneratorUtils.addAnnotation(Entity.class.getName(), new LinkedHashMap<String, Object>(), concreteArrayValueClass);
// generate a random table name
addTableAnnotationToPEAAV("SLEE_PEAAV_" + profileComponent.getProfileCmpInterfaceClass().getSimpleName() + "_" + Math.abs((long) profileComponent.getComponentID().hashCode()) + profileAttributeName, unique, concreteArrayValueClass);
// override @id
String getIdNameMethodSrc = "public long getId() { return super.getId(); }";
CtMethod getIdNameMethod = CtNewMethod.make(getIdNameMethodSrc, concreteArrayValueClass);
ClassGeneratorUtils.addAnnotation(Id.class.getName(), new LinkedHashMap<String, Object>(), getIdNameMethod);
ClassGeneratorUtils.addAnnotation(GeneratedValue.class.getName(), new LinkedHashMap<String, Object>(), getIdNameMethod);
concreteArrayValueClass.addMethod(getIdNameMethod);
// override getter methods
String getSerializableMethodSrc = "public " + Serializable.class.getName() + " getSerializable() { return super.getSerializable(); }";
CtMethod getSerializableMethod = CtNewMethod.make(getSerializableMethodSrc, concreteArrayValueClass);
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
map.put("name", "serializable");
map.put("length", 512);
//if (unique)map.put("unique", true);
ClassGeneratorUtils.addAnnotation(Column.class.getName(), map, getSerializableMethod);
concreteArrayValueClass.addMethod(getSerializableMethod);
String getStringMethodSrc = "public String getString() { return super.getString(); }";
CtMethod getStringMethod = CtNewMethod.make(getStringMethodSrc, concreteArrayValueClass);
map = new LinkedHashMap<String, Object>();
map.put("name", "string");
//if (unique)map.put("unique", true);
ClassGeneratorUtils.addAnnotation(Column.class.getName(), map, getStringMethod);
concreteArrayValueClass.addMethod(getStringMethod);
// FIXME add join columns here or in profile entity class to make
// the relation without a join table, atm if this is changed, the
// inserts on this table go with profile and table name as null %)
// THE PROFILENTITY FIELD IN AAV CLASS IS REQUIRED FOR THE RELATION WITH PROFILE ENTITY CLASS WITHOUT A JOIN TABLE
// add join column regarding the relation from array attr value to profile entity
CtField ctField = ClassGeneratorUtils.addField(concreteProfileEntityClass, "owner", concreteArrayValueClass);
ClassGeneratorUtils.generateSetter(ctField, null);
CtMethod getter = ClassGeneratorUtils.generateGetter(ctField, null);
//ClassGeneratorUtils.addAnnotation(ManyToOne.class.getName(), new LinkedHashMap<String, Object>(), getter);
// ----
ConstPool cp = getter.getMethodInfo().getConstPool();
AnnotationsAttribute attr = (AnnotationsAttribute) getter.getMethodInfo().getAttribute(AnnotationsAttribute.visibleTag);
if (attr == null) {
attr = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);
}
Annotation manyToOne = new Annotation(ManyToOne.class.getName(), cp);
manyToOne.addMemberValue("optional", new BooleanMemberValue(false, cp));
attr.addAnnotation(manyToOne);
Annotation joinColumns = new Annotation(JoinColumns.class.getName(), cp);
Annotation joinColumn1 = new Annotation(JoinColumn.class.getName(), cp);
joinColumn1.addMemberValue("name", new StringMemberValue("owner_tableName", cp));
joinColumn1.addMemberValue("referencedColumnName", new StringMemberValue("tableName", cp));
Annotation joinColumn2 = new Annotation(JoinColumn.class.getName(), cp);
joinColumn2.addMemberValue("name", new StringMemberValue("owner_profileName", cp));
joinColumn2.addMemberValue("referencedColumnName", new StringMemberValue("profileName", cp));
ArrayMemberValue joinColumnsMemberValue = new ArrayMemberValue(cp);
joinColumnsMemberValue.setValue(new MemberValue[] { new AnnotationMemberValue(joinColumn1, cp), new AnnotationMemberValue(joinColumn2, cp) });
joinColumns.addMemberValue("value", joinColumnsMemberValue);
attr.addAnnotation(joinColumns);
getter.getMethodInfo().addAttribute(attr);
// generate concrete setProfileEntity method
String setProfileEntityMethodSrc = "public void setProfileEntity(" + ProfileEntity.class.getName() + " profileEntity){ setOwner((" + concreteProfileEntityClass.getName() + ")profileEntity); }";
CtMethod setProfileEntityMethod = CtMethod.make(setProfileEntityMethodSrc, concreteArrayValueClass);
concreteArrayValueClass.addMethod(setProfileEntityMethod);
// write and load the attr array value class
String deployDir = profileComponent.getDeploymentDir().getAbsolutePath();
if (logger.isDebugEnabled()) {
logger.debug("Writing PROFILE ATTR ARRAY VALUE CONCRETE CLASS ( " + concreteArrayValueClass.getName() + " ) to: " + deployDir);
}
concreteArrayValueClass.writeFile(deployDir);
return Thread.currentThread().getContextClassLoader().loadClass(concreteArrayValueClass.getName());
} catch (Throwable e) {
throw new SLEEException(e.getMessage(), e);
} finally {
if (concreteArrayValueClass != null) {
concreteArrayValueClass.defrost();
}
}
}Example 35
| Project: requery-master File: AttributeMember.java View source code |
private void processBasicColumnAnnotations(ElementValidator validator) {
if (annotationOf(Key.class).isPresent() || annotationOf(javax.persistence.Id.class).isPresent()) {
isKey = true;
if (isTransient) {
validator.error("Key field cannot be transient");
}
}
// generated keys can't be set through a setter
if (annotationOf(Generated.class).isPresent() || annotationOf(GeneratedValue.class).isPresent()) {
isGenerated = true;
isReadOnly = true;
// check generation strategy
annotationOf(GeneratedValue.class).ifPresent( generatedValue -> {
if (generatedValue.strategy() != GenerationType.IDENTITY && generatedValue.strategy() != GenerationType.AUTO) {
validator.warning("GeneratedValue.strategy() " + generatedValue.strategy() + " not supported", generatedValue.getClass());
}
});
}
if (annotationOf(Lazy.class).isPresent()) {
if (isKey) {
cannotCombine(validator, Key.class, Lazy.class);
}
isLazy = true;
}
if (annotationOf(Nullable.class).isPresent() || isOptional || Mirrors.findAnnotationMirror(element(), "javax.annotation.Nullable").isPresent()) {
isNullable = true;
} else {
// if not a primitive type the value assumed nullable
if (element().getKind().isField()) {
isNullable = !element().asType().getKind().isPrimitive();
} else if (element().getKind() == ElementKind.METHOD) {
ExecutableElement executableElement = (ExecutableElement) element();
isNullable = !executableElement.getReturnType().getKind().isPrimitive();
}
}
if (annotationOf(Version.class).isPresent() || annotationOf(javax.persistence.Version.class).isPresent()) {
isVersion = true;
if (isKey) {
cannotCombine(validator, Key.class, Version.class);
}
}
Column column = annotationOf(Column.class).orElse(null);
ForeignKey foreignKey = null;
boolean foreignKeySetFromColumn = false;
if (column != null) {
name = "".equals(column.name()) ? null : column.name();
isUnique = column.unique();
isNullable = column.nullable();
defaultValue = column.value();
collate = column.collate();
definition = column.definition();
if (column.length() > 0) {
length = column.length();
}
if (column.foreignKey().length > 0) {
foreignKey = column.foreignKey()[0];
foreignKeySetFromColumn = true;
}
}
if (!foreignKeySetFromColumn) {
foreignKey = annotationOf(ForeignKey.class).orElse(null);
}
if (foreignKey != null) {
this.isForeignKey = true;
deleteAction = foreignKey.delete();
updateAction = foreignKey.update();
referencedColumn = foreignKey.referencedColumn();
}
annotationOf(Index.class).ifPresent( index -> {
isIndexed = true;
Collections.addAll(indexNames, index.value());
});
// JPA specific
annotationOf(Basic.class).ifPresent( basic -> {
isNullable = basic.optional();
isLazy = basic.fetch() == FetchType.LAZY;
});
annotationOf(javax.persistence.Index.class).ifPresent( index -> {
isIndexed = true;
Collections.addAll(indexNames, index.name());
});
annotationOf(JoinColumn.class).ifPresent( joinColumn -> {
javax.persistence.ForeignKey joinForeignKey = joinColumn.foreignKey();
this.isForeignKey = true;
ConstraintMode constraintMode = joinForeignKey.value();
switch(constraintMode) {
default:
case PROVIDER_DEFAULT:
case CONSTRAINT:
deleteAction = ReferentialAction.CASCADE;
updateAction = ReferentialAction.CASCADE;
break;
case NO_CONSTRAINT:
deleteAction = ReferentialAction.NO_ACTION;
updateAction = ReferentialAction.NO_ACTION;
break;
}
this.referencedTable = joinColumn.table();
this.referencedColumn = joinColumn.referencedColumnName();
});
annotationOf(javax.persistence.Column.class).ifPresent( persistenceColumn -> {
name = "".equals(persistenceColumn.name()) ? null : persistenceColumn.name();
isUnique = persistenceColumn.unique();
isNullable = persistenceColumn.nullable();
length = persistenceColumn.length();
isReadOnly = !persistenceColumn.updatable();
definition = persistenceColumn.columnDefinition();
});
annotationOf(Enumerated.class).ifPresent( enumerated -> {
EnumType enumType = enumerated.value();
if (enumType == EnumType.ORDINAL) {
converterType = EnumOrdinalConverter.class.getCanonicalName();
}
});
}Example 36
| Project: breeze.server.java-master File: JPAMetadata.java View source code |
/**
* Add the metadata for an entity or mapped superclass.
* Embeddables are skipped, and only added when they are the property of an entity.
*
* @param meta
*/
void addClass(ManagedType<?> meta) {
// skip embeddable types until they are encountered via an entity
if (!(meta instanceof IdentifiableType))
return;
Class type = meta.getJavaType();
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());
IdentifiableType<?> idmeta = (IdentifiableType) meta;
IdentifiableType superMeta = idmeta.getSupertype();
if (superMeta != null) {
Class superClass = superMeta.getJavaType();
cmap.put("baseTypeName", getEntityTypeName(superClass));
}
String genType = "None";
if (idmeta.hasSingleIdAttribute()) {
SingularAttribute<?, ?> idAttr = getSingleIdAttribute(idmeta);
Member member = idAttr.getJavaMember();
GeneratedValue genValueAnn = ((AnnotatedElement) member).getAnnotation(GeneratedValue.class);
if (genValueAnn != null) {
// String generator = genValueAnn.generator();
GenerationType strategy = genValueAnn.strategy();
if (strategy == GenerationType.SEQUENCE || strategy == GenerationType.TABLE)
genType = "KeyGenerator";
else if (strategy == GenerationType.IDENTITY || strategy == GenerationType.AUTO)
// not sure what to do about AUTO
genType = "Identity";
cmap.put("autoGeneratedKeyType", genType);
}
}
// TODO find the real name
String resourceName = pluralize(type.getSimpleName());
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);
}Example 37
| Project: infinispan-master File: JpaStore.java View source code |
@Override
public void start() {
this.emf = emfRegistry.getEntityManagerFactory(configuration.persistenceUnitName());
ManagedType<?> mt;
try {
mt = emf.getMetamodel().entity(this.configuration.entityClass());
} catch (IllegalArgumentException e) {
throw new JpaStoreException("Entity class [" + this.configuration.entityClass().getName() + " specified in configuration is not recognized by the EntityManagerFactory with Persistence Unit [" + this.configuration.persistenceUnitName() + "]", e);
}
if (!(mt instanceof IdentifiableType)) {
throw new JpaStoreException("Entity class must have one and only one identifier (@Id or @EmbeddedId)");
}
IdentifiableType<?> it = (IdentifiableType<?>) mt;
if (!it.hasSingleIdAttribute()) {
throw new JpaStoreException("Entity class has more than one identifier. It must have only one identifier.");
}
Type<?> idType = it.getIdType();
Class<?> idJavaType = idType.getJavaType();
if (idJavaType.isAnnotationPresent(GeneratedValue.class)) {
throw new JpaStoreException("Entity class has one identifier, but it must not have @GeneratedValue annotation");
}
// Hack: MySQL needs to have fetchSize set to Integer.MIN_VALUE in order to do streaming
SessionFactory sessionFactory = emf.createEntityManager().unwrap(Session.class).getSessionFactory();
if (sessionFactory instanceof SessionFactoryImplementor) {
Dialect dialect = ((SessionFactoryImplementor) sessionFactory).getDialect();
if (dialect instanceof MySQLDialect) {
setFetchSizeMinInteger = true;
}
}
}Example 38
| Project: cloud-roo-gwaddon-master File: GWOperationsUtils.java View source code |
public void addImports(JavaSourceFileEditor entityClassFile, String namespace) {
ArrayList<String> connectivityImports = new ArrayList<String>();
connectivityImports.add(getTopLevelPackageName() + ".connectivity." + namespace);
connectivityImports.add(getTopLevelPackageName() + ".connectivity.ODataConnectivity");
connectivityImports.add("org.odata4j.core.OEntity");
connectivityImports.add("org.odata4j.core.OProperties");
connectivityImports.add("org.springframework.transaction.annotation.Transactional");
connectivityImports.add("java.util.List");
connectivityImports.add("java.util.ArrayList");
connectivityImports.add("java.util.Date");
connectivityImports.add("java.util.Calendar");
connectivityImports.add("org.odata4j.core.OQueryRequest");
connectivityImports.add("org.odata4j.core.OCreateRequest");
connectivityImports.add("org.odata4j.core.OModifyRequest");
connectivityImports.add("org.odata4j.core.OEntityKey");
connectivityImports.add("javax.persistence.Temporal");
connectivityImports.add("javax.persistence.TemporalType");
connectivityImports.add("org.springframework.format.annotation.DateTimeFormat");
connectivityImports.add("org.joda.time.DateTime");
connectivityImports.add("org.joda.time.format.DateTimeFormatter");
connectivityImports.add("org.joda.time.format.ISODateTimeFormat");
connectivityImports.add("org.odata4j.core.OEntityKey");
connectivityImports.add("javax.persistence.Column");
connectivityImports.add("javax.persistence.GenerationType");
connectivityImports.add("javax.persistence.GeneratedValue");
connectivityImports.add("java.net.URLDecoder");
connectivityImports.add("java.net.URLEncoder");
connectivityImports.add("java.io.UnsupportedEncodingException");
connectivityImports.add("javax.persistence.Id");
entityClassFile.addImports(connectivityImports);
}Example 39
| Project: OpenSpaces-master File: StoreManager.java View source code |
/**
* Validates the provided class' annotations.
* Currently the only validation performed is for @Id & @SpaceId annotations
* that must be declared on the same getter.
*/
private void validateClassAnnotations(Class<?> type) {
// Validation is only relevant for Entities
if (type.getAnnotation(Entity.class) == null)
return;
for (Method getter : type.getMethods()) {
if (!getter.getName().startsWith("get"))
continue;
SpaceId spaceId = getter.getAnnotation(SpaceId.class);
boolean hasJpaId = getter.getAnnotation(Id.class) != null || getter.getAnnotation(EmbeddedId.class) != null;
if (spaceId != null || hasJpaId) {
if (!hasJpaId || spaceId == null)
throw new IllegalArgumentException("SpaceId and Id annotations must both be declared on the same property in JPA entities in type: " + type.getName());
if (spaceId.autoGenerate()) {
GeneratedValue generatedValue = getter.getAnnotation(GeneratedValue.class);
if (generatedValue == null || generatedValue.strategy() != GenerationType.IDENTITY)
throw new IllegalArgumentException("SpaceId with autoGenerate=true annotated property should also have a JPA GeneratedValue annotation with strategy = GenerationType.IDENTITY.");
}
break;
}
}
}Example 40
| Project: oreilly-ejb-6thedition-book-examples-master File: EmployeeIntegrationTest.java View source code |
@Override
public Long call() throws Exception {
// Make a new Employee
final EmployeeWithMappedSuperClassId alrubinger = new EmployeeWithMappedSuperClassId("Andrew Lee Rubinger");
// Ensure we have no ID now
Assert.assertNull("Primary key should not be set yet", alrubinger.getId());
// Persist
emHook.getEntityManager().persist(alrubinger);
// Now show that JPA gave us a primary key as generated
final Long id = alrubinger.getId();
Assert.assertNotNull("Persisting an entity with PK " + GeneratedValue.class.getName() + " should be created", id);
log.info("Persisted: " + alrubinger);
// Return
return id;
}Example 41
| Project: ajah-master File: AbstractAjahDao.java View source code |
protected boolean isAutoIdAssign() {
if (this.autoIdAssign == null) {
try {
final Field field = getTargetClass().getDeclaredField("id");
if (field.isAnnotationPresent(GeneratedValue.class)) {
this.autoIdAssign = Boolean.TRUE;
} else {
this.autoIdAssign = Boolean.FALSE;
}
} catch (NoSuchFieldExceptionSecurityException | e) {
this.autoIdAssign = Boolean.FALSE;
}
}
return this.autoIdAssign.booleanValue();
}Example 42
| Project: hibernate-core-3.6.x-mod-master File: JPAOverridenAnnotationReader.java View source code |
private void getEmbeddedId(List<Annotation> annotationList, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
if ("embedded-id".equals(element.getName())) {
if (isProcessingId(defaults)) {
Annotation annotation = getAttributeOverrides(element, defaults, false);
addIfNotNull(annotationList, annotation);
annotation = getAssociationOverrides(element, defaults, false);
addIfNotNull(annotationList, annotation);
AnnotationDescriptor ad = new AnnotationDescriptor(EmbeddedId.class);
annotationList.add(AnnotationFactory.create(ad));
getAccessType(annotationList, element);
}
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
Annotation annotation = getJavaAnnotation(EmbeddedId.class);
if (annotation != null) {
annotationList.add(annotation);
annotation = getJavaAnnotation(Column.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(Columns.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(GeneratedValue.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(Temporal.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(TableGenerator.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(SequenceGenerator.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AttributeOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AttributeOverrides.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AssociationOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getJavaAnnotation(AssociationOverrides.class);
addIfNotNull(annotationList, annotation);
}
}
}Example 43
| Project: openjpa-master File: AnnotationPersistenceMetaDataParser.java View source code |
/**
* Read annotations for the given member.
*/
private void parseMemberAnnotations(FieldMetaData fmd) {
// look for persistence strategy in annotation table
Member member = getRepository().getMetaDataFactory().getDefaults().getBackingMember(fmd);
PersistenceStrategy pstrat = PersistenceMetaDataDefaults.getPersistenceStrategy(fmd, member);
if (pstrat == null)
return;
fmd.setExplicit(true);
AnnotatedElement el = (AnnotatedElement) member;
boolean lob = (AccessController.doPrivileged(J2DoPrivHelper.isAnnotationPresentAction(el, Lob.class))).booleanValue();
if (isMetaDataMode()) {
switch(pstrat) {
case BASIC:
parseBasic(fmd, (Basic) el.getAnnotation(Basic.class), lob);
break;
case MANY_ONE:
parseManyToOne(fmd, (ManyToOne) el.getAnnotation(ManyToOne.class));
break;
case ONE_ONE:
parseOneToOne(fmd, (OneToOne) el.getAnnotation(OneToOne.class));
break;
case EMBEDDED:
parseEmbedded(fmd, (Embedded) el.getAnnotation(Embedded.class));
break;
case ONE_MANY:
parseOneToMany(fmd, (OneToMany) el.getAnnotation(OneToMany.class));
break;
case MANY_MANY:
parseManyToMany(fmd, (ManyToMany) el.getAnnotation(ManyToMany.class));
break;
case PERS:
parsePersistent(fmd, (Persistent) el.getAnnotation(Persistent.class));
break;
case PERS_COLL:
parsePersistentCollection(fmd, (PersistentCollection) el.getAnnotation(PersistentCollection.class));
break;
case ELEM_COLL:
parseElementCollection(fmd, (ElementCollection) el.getAnnotation(ElementCollection.class));
break;
case PERS_MAP:
parsePersistentMap(fmd, (PersistentMap) el.getAnnotation(PersistentMap.class));
break;
case TRANSIENT:
break;
default:
throw new InternalException();
}
}
if (isMappingOverrideMode() && lob)
parseLobMapping(fmd);
// extensions
MetaDataTag tag;
for (Annotation anno : el.getDeclaredAnnotations()) {
tag = _tags.get(anno.annotationType());
if (tag == null) {
handleUnknownMemberAnnotation(fmd, anno);
continue;
}
switch(tag) {
case ACCESS:
parseAccess(fmd, (Access) anno);
break;
case FLUSH_MODE:
if (isMetaDataMode())
warnFlushMode(fmd);
break;
case GENERATED_VALUE:
if (isMappingOverrideMode())
parseGeneratedValue(fmd, (GeneratedValue) anno);
break;
case ID:
case EMBEDDED_ID:
fmd.setPrimaryKey(true);
break;
case MAPPED_BY_ID:
parseMapsId(fmd, (MapsId) anno);
break;
case MAP_KEY:
if (isMappingOverrideMode())
parseMapKey(fmd, (MapKey) anno);
break;
case MAP_KEY_CLASS:
if (isMappingOverrideMode())
parseMapKeyClass(fmd, (MapKeyClass) anno);
break;
case ORDER_BY:
parseOrderBy(fmd, (OrderBy) el.getAnnotation(OrderBy.class));
break;
case SEQ_GENERATOR:
if (isMappingOverrideMode())
parseSequenceGenerator(el, (SequenceGenerator) anno);
break;
case VERSION:
fmd.setVersion(true);
break;
case DEPENDENT:
if (isMetaDataMode() && ((Dependent) anno).value())
fmd.setCascadeDelete(ValueMetaData.CASCADE_AUTO);
break;
case ELEM_DEPENDENT:
if (isMetaDataMode() && ((ElementDependent) anno).value())
fmd.getElement().setCascadeDelete(ValueMetaData.CASCADE_AUTO);
break;
case ELEM_TYPE:
if (isMetaDataMode())
fmd.getElement().setTypeOverride(toOverrideType(((ElementType) anno).value()));
break;
case EXTERNAL_VALS:
if (isMetaDataMode())
fmd.setExternalValues(StringUtil.join(((ExternalValues) anno).value(), ","));
break;
case EXTERNALIZER:
if (isMetaDataMode())
fmd.setExternalizer(((Externalizer) anno).value());
break;
case FACTORY:
if (isMetaDataMode())
fmd.setFactory(((Factory) anno).value());
break;
case INVERSE_LOGICAL:
if (isMetaDataMode())
fmd.setInverse(((InverseLogical) anno).value());
break;
case KEY_DEPENDENT:
if (isMetaDataMode() && ((KeyDependent) anno).value())
fmd.getKey().setCascadeDelete(ValueMetaData.CASCADE_AUTO);
break;
case KEY_TYPE:
if (isMetaDataMode())
fmd.getKey().setTypeOverride(toOverrideType(((KeyType) anno).value()));
break;
case LOAD_FETCH_GROUP:
if (isMetaDataMode())
fmd.setLoadFetchGroup(((LoadFetchGroup) anno).value());
break;
case LRS:
if (isMetaDataMode())
fmd.setLRS(((LRS) anno).value());
break;
case READ_ONLY:
if (isMetaDataMode())
parseReadOnly(fmd, (ReadOnly) anno);
break;
case TYPE:
if (isMetaDataMode())
fmd.setTypeOverride(toOverrideType(((Type) anno).value()));
break;
default:
throw new UnsupportedException(_loc.get("unsupported", fmd, anno.toString()));
}
}
}Example 44
| Project: cdi-extension-showcase-master File: SampleEntity.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 45
| Project: cloudtm-data-platform-master File: Spouse.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 46
| Project: exit-web-framework-master File: UniversallyUniqueIdentifier.java View source code |
@Id
@Column(length = 32)
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
public String getId() {
return this.id;
}Example 47
| Project: fluent-hibernate-master File: SashaGrey.java View source code |
@Id
@GeneratedValue
@Column
public Long getPid() {
return pid;
}Example 48
| Project: j360-master File: IdEntity.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}Example 49
| Project: mycontainer-master File: CustomerTypeBean.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}Example 50
| Project: spring-mvc-qq-weibo-master File: IdEntity.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}Example 51
| Project: tx-club-master File: BaseBean.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getId() {
return id;
}Example 52
| Project: eclipselink.runtime-master File: ConcurrencyB.java View source code |
/**
* @return the id
*/
@Id
@GeneratedValue
public int getId() {
return id;
}Example 53
| Project: javers-master File: DummyEntity.java View source code |
@Id
@GeneratedValue
public int getId() {
return id;
}Example 54
| Project: jboss-seam-2.3.0.Final-Hibernate.3-master File: SimpleEntity.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 55
| Project: minnal-master File: BaseDomain.java View source code |
@Override
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}Example 56
| Project: OA-master File: PersonPosition.java View source code |
@Id
@GeneratedValue
public Integer getId() {
return id;
}Example 57
| Project: seam-2.2-master File: SimpleEntity.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 58
| Project: seam-revisited-master File: SimpleEntity.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 59
| Project: seam2jsf2-master File: SimpleEntity.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 60
| Project: taylor-seam-jsf2-master File: SimpleEntity.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 61
| Project: tianti-master File: MysqlLongIdEntity.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}Example 62
| Project: ticket-monster-master File: EventCategory.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 63
| Project: 5.2.0.RC-master File: IdEntity.java View source code |
@Id
@GenericGenerator(name = "paymentableGenerator", strategy = "native")
@GeneratedValue(generator = "paymentableGenerator")
public Long getId() {
return id;
}Example 64
| Project: acs-master File: SubEntity.java View source code |
@Id
@GeneratedValue
public Integer getSubId() {
return subId;
}Example 65
| Project: arquillian-showcase-master File: LineItem.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 66
| Project: bygle-ldp-master File: Slugs.java View source code |
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id_slug", unique = true, nullable = false)
public Integer getIdSlug() {
return this.idSlug;
}Example 67
| Project: civilizer-master File: Tag2Fragment.java View source code |
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "tag2fragment_id")
public Long getId() {
return id;
}Example 68
| Project: deliciousfruit-master File: IdEntity.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}Example 69
| Project: hibernate-ogm-master File: Address.java View source code |
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
public String getId() {
return id;
}Example 70
| Project: hibernate-search-master File: Grandpa.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 71
| Project: Hibernate-Search-on-action-master File: ElectricalProperties.java View source code |
@Id
@DocumentId
@GeneratedValue
public int getId() {
return id;
}Example 72
| Project: iMatrix6.0.0Dev-master File: IdEntity.java View source code |
@Id
@GenericGenerator(name = "paymentableGenerator", strategy = "native")
@GeneratedValue(generator = "paymentableGenerator")
public Long getId() {
return id;
}Example 73
| Project: Java-Spring-Examples-master File: Product.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 74
| Project: jbosstools-hibernate-master File: PhysicalGeneGenericIdType.java View source code |
@Id
@GeneratedValue
@Column(name = "ID", nullable = false, unique = true, precision = 11)
public long getId() {
return id;
}Example 75
| Project: jgt-master File: IdEntity.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}Example 76
| Project: ManalithBot-master File: Player.java View source code |
@Id
@GeneratedValue
public long getId() {
return id;
}Example 77
| Project: raidenjpa-master File: ItemA.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 78
| Project: resthub-spring-stack-master File: StandaloneEntity.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 79
| Project: saos-master File: EnrichmentTag.java View source code |
//------------------------ GETTERS --------------------------
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_enrichment_tag")
@Override
public long getId() {
return id;
}Example 80
| Project: springlab-master File: IdEntity.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}Example 81
| Project: springside-core-3.3.4.x-master File: IdEntity.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}Example 82
| Project: tourismwork-master File: TraitType.java View source code |
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "TRAIT_ID", unique = true, nullable = false)
public Integer getTraitId() {
return this.traitId;
}Example 83
| Project: tramory-server-master File: Genre.java View source code |
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "genre_id", unique = true, nullable = false)
public int getGenreId() {
return genreId;
}Example 84
| Project: arquillian-examples-master File: Widget.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 85
| Project: blaze-persistence-master File: TestEntity.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 86
| Project: brix-cms-plugins-master File: BaseEntity.java View source code |
@Id
@Override
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}Example 87
| Project: budgetapp-master File: AuthToken.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}Example 88
| Project: cims-master File: UserDeptRelation.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer getUdre_id() {
return udre_id;
}Example 89
| Project: cloudconductor-server-master File: EFileTag.java View source code |
@Override
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return this.id;
}Example 90
| Project: coner-master File: HandicapGroupSetHibernateEntity.java View source code |
@Id
@Column(name = "id")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
public String getId() {
return id;
}Example 91
| Project: corona_src-master File: CategoryBean.java View source code |
/**
* @return ID
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
public int getId() {
return id;
}Example 92
| Project: dbDiff-master File: LongTableName.java View source code |
@Id
@GeneratedValue
public Long getId() {
return m_id;
}Example 93
| Project: deltaspike-solder-master File: Person.java View source code |
@Id
@GeneratedValue
public Integer getPersonId() {
return personId;
}Example 94
| Project: ecommercePlaySample-master File: Category.java View source code |
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id")
public int getId() {
return this.id;
}Example 95
| Project: edu-master File: LineItem.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int getId() {
return id;
}Example 96
| Project: fastdfs-zyc-master File: DownloadFileRecord.java View source code |
@Id
@GeneratedValue(generator = "system_uuid")
@GenericGenerator(name = "system_uuid", strategy = "uuid")
public String getId() {
return id;
}Example 97
| Project: headmaster-master File: GPA.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@XmlAttribute
public Long getId() {
return id;
}Example 98
| Project: hibernateuniversity-devoxx-master File: Address.java View source code |
@Id
@GeneratedValue
public Long getId() {
return id;
}Example 99
| Project: hibhik-master File: TestTable.java View source code |
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
public Long getId() {
return id;
}Example 100
| Project: hrms-master File: Action.java View source code |
// Property accessors
@Id
@GeneratedValue
@Column(name = "actionId", unique = true, nullable = false)
public Integer getActionId() {
return this.actionId;
}Example 101
| Project: IntelliDict-master File: Student.java View source code |
@Id
@GeneratedValue
@Column(name = "STUDENT_ID")
public long getStudentId() {
return this.studentId;
}