use of javax.persistence.Index in project cassandra-driver-mapping by valchkou.
the class EntityTypeParser method parseEntityLevelMetadata.
/**
* Parses class level annotations and initializes EntityMetadata object for
* given entity class
*
* @param clazz
* @return EntityMetadata
*/
private static <T> EntityTypeMetadata parseEntityLevelMetadata(Class<T> clazz) {
EntityTypeMetadata result = null;
Annotation annotation = clazz.getAnnotation(Table.class);
if (annotation instanceof Table) {
Table tableAntn = (Table) annotation;
String tableName = tableAntn.name();
if (tableName != null && tableName.length() > 0) {
result = new EntityTypeMetadata(clazz, tableName);
} else {
result = new EntityTypeMetadata(clazz);
}
Index[] indexes = tableAntn.indexes();
if (indexes != null && indexes.length > 0) {
for (Index index : indexes) {
result.addindex(index.name(), index.columnList());
}
}
} else {
result = new EntityTypeMetadata(clazz);
}
// parse properties
annotation = clazz.getAnnotation(TableProperties.class);
if (annotation instanceof TableProperties) {
TableProperty[] props = ((TableProperties) annotation).values();
for (TableProperty prop : props) {
result.addProperty(prop.value());
}
}
// parse ttl
annotation = clazz.getAnnotation(Ttl.class);
if (annotation instanceof Ttl) {
result.setTtl(((Ttl) annotation).value());
}
return result;
}
use of javax.persistence.Index in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildIndex.
private static void buildIndex(AnnotationDescriptor annotation, Element element) {
List indexElementList = element.elements("index");
Index[] indexes = new Index[indexElementList.size()];
for (int i = 0; i < indexElementList.size(); i++) {
Element subelement = (Element) indexElementList.get(i);
AnnotationDescriptor indexAnn = new AnnotationDescriptor(Index.class);
copyStringAttribute(indexAnn, subelement, "name", false);
copyStringAttribute(indexAnn, subelement, "column-list", true);
copyBooleanAttribute(indexAnn, subelement, "unique");
indexes[i] = AnnotationFactory.create(indexAnn);
}
annotation.setValue("indexes", indexes);
}
use of javax.persistence.Index in project hibernate-orm by hibernate.
the class BinderHelper method getIdentifierGenerator.
private static IdentifierGeneratorDefinition getIdentifierGenerator(String name, XProperty idXProperty, Map<String, IdentifierGeneratorDefinition> localGenerators, MetadataBuildingContext buildingContext) {
if (localGenerators != null) {
final IdentifierGeneratorDefinition result = localGenerators.get(name);
if (result != null) {
return result;
}
}
final IdentifierGeneratorDefinition globalDefinition = buildingContext.getMetadataCollector().getIdentifierGenerator(name);
if (globalDefinition != null) {
return globalDefinition;
}
log.debugf("Could not resolve explicit IdentifierGeneratorDefinition - using implicit interpretation (%s)", name);
// If we were unable to locate an actual matching named generator assume a sequence/table of the given name.
// this really needs access to the `javax.persistence.GenerationType` to work completely properly
//
// (the crux of HHH-12122)
// temporarily, in lieu of having access to GenerationType, assume the EnhancedSequenceGenerator
// for the purpose of testing the feasibility of the approach
final GeneratedValue generatedValueAnn = idXProperty.getAnnotation(GeneratedValue.class);
if (generatedValueAnn == null) {
// this should really never happen, but its easy to protect against it...
return new IdentifierGeneratorDefinition("assigned", "assigned");
}
final IdGeneratorStrategyInterpreter generationInterpreter = buildingContext.getBuildingOptions().getIdGenerationTypeInterpreter();
final GenerationType generationType = interpretGenerationType(generatedValueAnn);
if (generationType == null || generationType == GenerationType.SEQUENCE) {
// NOTE : `null` will ultimately be interpreted as "hibernate_sequence"
log.debugf("Building implicit sequence-based IdentifierGeneratorDefinition (%s)", name);
final IdentifierGeneratorDefinition.Builder builder = new IdentifierGeneratorDefinition.Builder();
generationInterpreter.interpretSequenceGenerator(new SequenceGenerator() {
@Override
public String name() {
return name;
}
@Override
public String sequenceName() {
return "";
}
@Override
public String catalog() {
return "";
}
@Override
public String schema() {
return "";
}
@Override
public int initialValue() {
return 1;
}
@Override
public int allocationSize() {
return 50;
}
@Override
public Class<? extends Annotation> annotationType() {
return SequenceGenerator.class;
}
}, builder);
return builder.build();
} else if (generationType == GenerationType.TABLE) {
// NOTE : `null` will ultimately be interpreted as "hibernate_sequence"
log.debugf("Building implicit table-based IdentifierGeneratorDefinition (%s)", name);
final IdentifierGeneratorDefinition.Builder builder = new IdentifierGeneratorDefinition.Builder();
generationInterpreter.interpretTableGenerator(new TableGenerator() {
@Override
public String name() {
return name;
}
@Override
public String table() {
return "";
}
@Override
public int initialValue() {
return 0;
}
@Override
public int allocationSize() {
return 50;
}
@Override
public String catalog() {
return "";
}
@Override
public String schema() {
return "";
}
@Override
public String pkColumnName() {
return "";
}
@Override
public String valueColumnName() {
return "";
}
@Override
public String pkColumnValue() {
return "";
}
@Override
public UniqueConstraint[] uniqueConstraints() {
return new UniqueConstraint[0];
}
@Override
public Index[] indexes() {
return new Index[0];
}
@Override
public Class<? extends Annotation> annotationType() {
return TableGenerator.class;
}
}, builder);
return builder.build();
}
// really AUTO and IDENTITY work the same in this respect, aside from the actual strategy name
final String strategyName;
if (generationType == GenerationType.IDENTITY) {
strategyName = "identity";
} else {
strategyName = generationInterpreter.determineGeneratorName(generationType, new IdGeneratorStrategyInterpreter.GeneratorNameDeterminationContext() {
@Override
public Class getIdType() {
return buildingContext.getBootstrapContext().getReflectionManager().toClass(idXProperty.getType());
}
@Override
public String getGeneratedValueGeneratorName() {
return generatedValueAnn.generator();
}
});
}
log.debugf("Building implicit generic IdentifierGeneratorDefinition (%s) : %s", name, strategyName);
return new IdentifierGeneratorDefinition(name, strategyName, Collections.singletonMap(IdentifierGenerator.GENERATOR_NAME, name));
}
Aggregations