/** * @author Frantisek Hartman */ @NodeEntity(label = "EntityWithMultipleCompositeIndexes") @CompositeIndex({ "firstName", "age" }) @CompositeIndex({ "firstName", "email" }) public class MultipleCompositeIndexEntity { Long id; String firstName; int age; String email; }
private synchronized Collection<CompositeIndex> initCompositeIndexFields() { // init property fields to be able to check existence of properties propertyFields(); if (cls == null) { try { cls = Class.forName(className, false, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { throw new RuntimeException("Could not get annotation info for class " + className, e); } } CompositeIndex[] annotations = cls.getDeclaredAnnotationsByType(CompositeIndex.class); ArrayList<CompositeIndex> result = new ArrayList<>(annotations.length); for (CompositeIndex annotation : annotations) { String[] properties = annotation.value().length > 0 ? annotation.value() : annotation.properties(); if (properties.length < 1) { throw new MetadataException("Incorrect CompositeIndex definition on " + className + ". Provide at least 1 property"); } for (String property : properties) { FieldInfo fieldInfo = propertyFields.get(property); if (fieldInfo == null) { throw new MetadataException("Incorrect CompositeIndex definition on " + className + ". Property " + property + " does not exists."); } } result.add(annotation); } return result; }
IndexType type = index.unique() ? IndexType.NODE_KEY_CONSTRAINT : IndexType.COMPOSITE_INDEX; String[] properties = index.value().length > 0 ? index.value() : index.properties(); AutoIndex autoIndex = new AutoIndex(type, owningType, properties); LOGGER.debug("Adding composite index [description={}]", autoIndex);
/** * @author Frantisek Hartman */ @NodeEntity(label = "Entity") @CompositeIndex({ "name", "ag" }) public class WrongPropertyCompositeIndexEntity { Long id; String name; int age; }
/** * @author Frantisek Hartman */ @NodeEntity(label = "Entity") @CompositeIndex(properties = { "name", "age" }, unique = true) public class NodeKeyConstraintEntity { Long id; String name; int age; }
/** * @author Frantisek Hartman */ @NodeEntity(label = "EntityWithCompositeIndex") @CompositeIndex({ "name", "age" }) public class CompositeIndexEntity { Long id; String name; int age; }
/** * @author Frantisek Hartman */ @NodeEntity(label = "Entity") @CompositeIndex public class NoPropertyCompositeIndexEntity { Long id; String name; int age; }