use of javax.persistence.TableGenerator in project hibernate-orm by hibernate.
the class AnnotationBinder method bindPackage.
public static void bindPackage(String packageName, MetadataBuildingContext context) {
XPackage pckg;
try {
pckg = context.getBuildingOptions().getReflectionManager().packageForName(packageName);
} catch (ClassLoadingException e) {
LOG.packageNotFound(packageName);
return;
} catch (ClassNotFoundException cnf) {
LOG.packageNotFound(packageName);
return;
}
if (pckg.isAnnotationPresent(SequenceGenerator.class)) {
SequenceGenerator ann = pckg.getAnnotation(SequenceGenerator.class);
IdentifierGeneratorDefinition idGen = buildIdGenerator(ann, context);
context.getMetadataCollector().addIdentifierGenerator(idGen);
if (LOG.isTraceEnabled()) {
LOG.tracev("Add sequence generator with name: {0}", idGen.getName());
}
}
if (pckg.isAnnotationPresent(TableGenerator.class)) {
TableGenerator ann = pckg.getAnnotation(TableGenerator.class);
IdentifierGeneratorDefinition idGen = buildIdGenerator(ann, context);
context.getMetadataCollector().addIdentifierGenerator(idGen);
}
bindGenericGenerators(pckg, context);
bindQueries(pckg, context);
bindFilterDefs(pckg, context);
bindTypeDefs(pckg, context);
bindFetchProfiles(pckg, context);
BinderHelper.bindAnyMetaDefs(pckg, context);
}
use of javax.persistence.TableGenerator in project cloudstack by apache.
the class SqlGenerator method buildAttributes.
protected void buildAttributes(Class<?> clazz, String tableName, AttributeOverride[] overrides, boolean embedded, boolean isId) {
if (!embedded && clazz.getAnnotation(Entity.class) == null) {
// except that the mappings will apply only to its subclasses since no table exists for the mapped superclass itself
if (clazz.getAnnotation(MappedSuperclass.class) != null) {
Field[] declaredFields = clazz.getDeclaredFields();
_mappedSuperclassFields = (Field[]) ArrayUtils.addAll(_mappedSuperclassFields, declaredFields);
}
return;
}
Class<?> parent = clazz.getSuperclass();
if (parent != null) {
buildAttributes(parent, DbUtil.getTableName(parent), DbUtil.getAttributeOverrides(parent), false, false);
}
if (!embedded) {
_tables.add(clazz);
_ids.put(tableName, new ArrayList<Attribute>());
}
Field[] fields = clazz.getDeclaredFields();
fields = (Field[]) ArrayUtils.addAll(fields, _mappedSuperclassFields);
_mappedSuperclassFields = null;
for (Field field : fields) {
field.setAccessible(true);
TableGenerator tg = field.getAnnotation(TableGenerator.class);
if (tg != null) {
_generators.put(field.getName(), tg);
}
if (!DbUtil.isPersistable(field)) {
continue;
}
if (field.getAnnotation(Embedded.class) != null) {
_embeddeds.add(field);
Class<?> embeddedClass = field.getType();
assert (embeddedClass.getAnnotation(Embeddable.class) != null) : "Class is not annotated with Embeddable: " + embeddedClass.getName();
buildAttributes(embeddedClass, tableName, DbUtil.getAttributeOverrides(field), true, false);
continue;
}
if (field.getAnnotation(EmbeddedId.class) != null) {
_embeddeds.add(field);
Class<?> embeddedClass = field.getType();
assert (embeddedClass.getAnnotation(Embeddable.class) != null) : "Class is not annotated with Embeddable: " + embeddedClass.getName();
buildAttributes(embeddedClass, tableName, DbUtil.getAttributeOverrides(field), true, true);
continue;
}
Attribute attr = new Attribute(clazz, overrides, field, tableName, embedded, isId);
if (attr.getColumnName().equals(GenericDao.REMOVED_COLUMN)) {
attr.setTrue(Attribute.Flag.DaoGenerated);
attr.setFalse(Attribute.Flag.Insertable);
attr.setFalse(Attribute.Flag.Updatable);
attr.setTrue(Attribute.Flag.TimeStamp);
attr.setFalse(Attribute.Flag.Time);
attr.setFalse(Attribute.Flag.Date);
attr.setTrue(Attribute.Flag.Nullable);
attr.setTrue(Attribute.Flag.Removed);
}
if (attr.isId()) {
List<Attribute> attrs = _ids.get(tableName);
attrs.add(attr);
}
_attributes.add(attr);
}
}
use of javax.persistence.TableGenerator in project hibernate-orm by hibernate.
the class JPAMetadataProvider method getDefaults.
@Override
public Map<Object, Object> getDefaults() {
if (defaults == null) {
defaults = new HashMap<Object, Object>();
XMLContext.Default xmlDefaults = xmlContext.getDefault(null);
defaults.put("schema", xmlDefaults.getSchema());
defaults.put("catalog", xmlDefaults.getCatalog());
defaults.put("delimited-identifier", xmlDefaults.getDelimitedIdentifier());
List<Class> entityListeners = new ArrayList<Class>();
for (String className : xmlContext.getDefaultEntityListeners()) {
try {
entityListeners.add(classLoaderAccess.classForName(className));
} catch (ClassLoadingException e) {
throw new IllegalStateException("Default entity listener class not found: " + className);
}
}
defaults.put(EntityListeners.class, entityListeners);
for (Element element : xmlContext.getAllDocuments()) {
@SuppressWarnings("unchecked") List<Element> elements = element.elements("sequence-generator");
List<SequenceGenerator> sequenceGenerators = (List<SequenceGenerator>) defaults.get(SequenceGenerator.class);
if (sequenceGenerators == null) {
sequenceGenerators = new ArrayList<SequenceGenerator>();
defaults.put(SequenceGenerator.class, sequenceGenerators);
}
for (Element subelement : elements) {
sequenceGenerators.add(JPAOverriddenAnnotationReader.buildSequenceGeneratorAnnotation(subelement));
}
elements = element.elements("table-generator");
List<TableGenerator> tableGenerators = (List<TableGenerator>) defaults.get(TableGenerator.class);
if (tableGenerators == null) {
tableGenerators = new ArrayList<TableGenerator>();
defaults.put(TableGenerator.class, tableGenerators);
}
for (Element subelement : elements) {
tableGenerators.add(JPAOverriddenAnnotationReader.buildTableGeneratorAnnotation(subelement, xmlDefaults));
}
List<NamedQuery> namedQueries = (List<NamedQuery>) defaults.get(NamedQuery.class);
if (namedQueries == null) {
namedQueries = new ArrayList<NamedQuery>();
defaults.put(NamedQuery.class, namedQueries);
}
List<NamedQuery> currentNamedQueries = JPAOverriddenAnnotationReader.buildNamedQueries(element, false, xmlDefaults, classLoaderAccess);
namedQueries.addAll(currentNamedQueries);
List<NamedNativeQuery> namedNativeQueries = (List<NamedNativeQuery>) defaults.get(NamedNativeQuery.class);
if (namedNativeQueries == null) {
namedNativeQueries = new ArrayList<NamedNativeQuery>();
defaults.put(NamedNativeQuery.class, namedNativeQueries);
}
List<NamedNativeQuery> currentNamedNativeQueries = JPAOverriddenAnnotationReader.buildNamedQueries(element, true, xmlDefaults, classLoaderAccess);
namedNativeQueries.addAll(currentNamedNativeQueries);
List<SqlResultSetMapping> sqlResultSetMappings = (List<SqlResultSetMapping>) defaults.get(SqlResultSetMapping.class);
if (sqlResultSetMappings == null) {
sqlResultSetMappings = new ArrayList<SqlResultSetMapping>();
defaults.put(SqlResultSetMapping.class, sqlResultSetMappings);
}
List<SqlResultSetMapping> currentSqlResultSetMappings = JPAOverriddenAnnotationReader.buildSqlResultsetMappings(element, xmlDefaults, classLoaderAccess);
sqlResultSetMappings.addAll(currentSqlResultSetMappings);
List<NamedStoredProcedureQuery> namedStoredProcedureQueries = (List<NamedStoredProcedureQuery>) defaults.get(NamedStoredProcedureQuery.class);
if (namedStoredProcedureQueries == null) {
namedStoredProcedureQueries = new ArrayList<NamedStoredProcedureQuery>();
defaults.put(NamedStoredProcedureQuery.class, namedStoredProcedureQueries);
}
List<NamedStoredProcedureQuery> currentNamedStoredProcedureQueries = JPAOverriddenAnnotationReader.buildNamedStoreProcedureQueries(element, xmlDefaults, classLoaderAccess);
namedStoredProcedureQueries.addAll(currentNamedStoredProcedureQueries);
}
}
return defaults;
}
use of javax.persistence.TableGenerator in project hibernate-orm by hibernate.
the class AnnotationBinder method buildIdGenerator.
private static IdentifierGeneratorDefinition buildIdGenerator(java.lang.annotation.Annotation ann, MetadataBuildingContext context) {
if (ann == null) {
return null;
}
IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder();
if (context.getMappingDefaults().getImplicitSchemaName() != null) {
definitionBuilder.addParam(PersistentIdentifierGenerator.SCHEMA, context.getMappingDefaults().getImplicitSchemaName());
}
if (context.getMappingDefaults().getImplicitCatalogName() != null) {
definitionBuilder.addParam(PersistentIdentifierGenerator.CATALOG, context.getMappingDefaults().getImplicitCatalogName());
}
if (ann instanceof TableGenerator) {
context.getBuildingOptions().getIdGenerationTypeInterpreter().interpretTableGenerator((TableGenerator) ann, definitionBuilder);
if (LOG.isTraceEnabled()) {
LOG.tracev("Add table generator with name: {0}", definitionBuilder.getName());
}
} else if (ann instanceof SequenceGenerator) {
context.getBuildingOptions().getIdGenerationTypeInterpreter().interpretSequenceGenerator((SequenceGenerator) ann, definitionBuilder);
if (LOG.isTraceEnabled()) {
LOG.tracev("Add sequence generator with name: {0}", definitionBuilder.getName());
}
} else if (ann instanceof GenericGenerator) {
GenericGenerator genGen = (GenericGenerator) ann;
definitionBuilder.setName(genGen.name());
definitionBuilder.setStrategy(genGen.strategy());
Parameter[] params = genGen.parameters();
for (Parameter parameter : params) {
definitionBuilder.addParam(parameter.name(), parameter.value());
}
if (LOG.isTraceEnabled()) {
LOG.tracev("Add generic generator with name: {0}", definitionBuilder.getName());
}
} else {
throw new AssertionFailure("Unknown Generator annotation: " + ann);
}
return definitionBuilder.build();
}
use of javax.persistence.TableGenerator in project hibernate-orm by hibernate.
the class AnnotationBinder method buildLocalGenerators.
private static HashMap<String, IdentifierGeneratorDefinition> buildLocalGenerators(XAnnotatedElement annElt, MetadataBuildingContext context) {
HashMap<String, IdentifierGeneratorDefinition> generators = new HashMap<String, IdentifierGeneratorDefinition>();
TableGenerator tabGen = annElt.getAnnotation(TableGenerator.class);
SequenceGenerator seqGen = annElt.getAnnotation(SequenceGenerator.class);
GenericGenerator genGen = annElt.getAnnotation(GenericGenerator.class);
if (tabGen != null) {
IdentifierGeneratorDefinition idGen = buildIdGenerator(tabGen, context);
generators.put(idGen.getName(), idGen);
}
if (seqGen != null) {
IdentifierGeneratorDefinition idGen = buildIdGenerator(seqGen, context);
generators.put(idGen.getName(), idGen);
}
if (genGen != null) {
IdentifierGeneratorDefinition idGen = buildIdGenerator(genGen, context);
generators.put(idGen.getName(), idGen);
}
return generators;
}
Aggregations