use of javax.persistence.GeneratedValue in project hibernate-orm by hibernate.
the class AnnotationBinder method processId.
private static void processId(PropertyHolder propertyHolder, PropertyData inferredData, SimpleValue idValue, HashMap<String, IdentifierGeneratorDefinition> classGenerators, boolean isIdentifierMapper, MetadataBuildingContext buildingContext) {
if (isIdentifierMapper) {
throw new AnnotationException("@IdClass class should not have @Id nor @EmbeddedId properties: " + BinderHelper.getPath(propertyHolder, inferredData));
}
XClass entityXClass = inferredData.getClassOrElement();
XProperty idXProperty = inferredData.getProperty();
// clone classGenerator and override with local values
// HashMap<String, IdentifierGeneratorDefinition> localGenerators = ( HashMap<String, IdentifierGeneratorDefinition> ) classGenerators.clone();
// localGenerators.putAll( buildGenerators( idXProperty, buildingContext ) );
buildGenerators(idXProperty, buildingContext);
// manage composite related metadata
// guess if its a component and find id data access (property, field etc)
final boolean isComponent = entityXClass.isAnnotationPresent(Embeddable.class) || idXProperty.isAnnotationPresent(EmbeddedId.class);
GeneratedValue generatedValue = idXProperty.getAnnotation(GeneratedValue.class);
String generatorType = generatedValue != null ? generatorType(generatedValue, buildingContext, entityXClass) : "assigned";
String generatorName = generatedValue != null ? generatedValue.generator() : BinderHelper.ANNOTATION_STRING_DEFAULT;
if (isComponent) {
// a component must not have any generator
generatorType = "assigned";
}
SecondPass secondPass = new IdGeneratorResolverSecondPass(idValue, idXProperty, generatorType, generatorName, buildingContext);
buildingContext.getMetadataCollector().addSecondPass(secondPass);
if (LOG.isTraceEnabled()) {
LOG.tracev("Bind {0} on {1}", (isComponent ? "@EmbeddedId" : "@Id"), inferredData.getPropertyName());
}
}
use of javax.persistence.GeneratedValue in project jirm by agentgt.
the class SqlParameterDefinition method parameterDef.
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;
}
use of javax.persistence.GeneratedValue in project cosmic by MissionCriticalCloud.
the class Attribute method setupColumnInfo.
protected void setupColumnInfo(final Class<?> clazz, final AttributeOverride[] overrides, final String tableName, final boolean isEmbedded, final boolean isId) {
flags = Flag.Selectable.setTrue(flags);
final 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 {
final 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);
}
final Encrypt encrypt = field.getAnnotation(Encrypt.class);
if (encrypt != null && encrypt.encrypt()) {
flags = Flag.Encrypted.setTrue(flags);
}
}
final ElementCollection ec = field.getAnnotation(ElementCollection.class);
if (ec != null) {
flags = Flag.Insertable.setFalse(flags);
flags = Flag.Selectable.setFalse(flags);
}
final 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);
}
use of javax.persistence.GeneratedValue in project dal by ctripcorp.
the class EntityManager method processAutoIncrementColumn.
private void processAutoIncrementColumn(Field field, String currentClassName, Set<String> classNameSet) {
GeneratedValue generatedValue = field.getAnnotation(GeneratedValue.class);
if (!autoIncremental && null != generatedValue && (generatedValue.strategy() == GenerationType.AUTO || generatedValue.strategy() == GenerationType.IDENTITY))
autoIncremental = true;
if (field.getAnnotation(Id.class) != null && generatedValue != null && generatedValue.strategy() == GenerationType.AUTO) {
// first add identity(auto increment)
if (classNameSet.isEmpty()) {
classNameSet.add(currentClassName);
identityList.add(field);
return;
}
if (classNameSet.contains(currentClassName)) {
identityList.add(field);
}
}
}
use of javax.persistence.GeneratedValue in project CloudStack-archive by CloudStack-extras.
the class Attribute method setupColumnInfo.
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);
}
Aggregations