Java Code Examples for com.orientechnologies.orient.core.metadata.schema.OClass#createIndex()

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OClass#createIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobDetailEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  super.defineType(type);

  type.createProperty(P_NAME, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_GROUP, OType.STRING)
      .setMandatory(true)
      .setNotNull(false); // nullable
  type.createProperty(P_JOB_TYPE, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);

  type.createIndex(I_NAME_GROUP, INDEX_TYPE.UNIQUE, P_NAME, P_GROUP);
}
 
Example 2
Source File: DatabaseExternalizerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void createSampleDb() {
  try (ODatabaseDocumentTx db = database.getInstance().connect()) {
    OSchema schema = db.getMetadata().getSchema();

    OClass cityType = schema.createClass("City");
    cityType.createProperty("name", OType.STRING);
    cityType.createProperty("country", OType.STRING);
    cityType.createIndex("name_country_idx", INDEX_TYPE.UNIQUE, "name", "country");

    OClass personType = schema.createClass("Person");
    personType.createProperty("name", OType.STRING);
    personType.createProperty("surname", OType.STRING);
    personType.createIndex("name_surname_idx", INDEX_TYPE.UNIQUE, "name", "surname");

    ODocument doc = db.newInstance("Person");
    doc.field("name", "Luke")
        .field("surname", "Skywalker")
        .field("city", new ODocument("City")
            .field("name", "Rome")
            .field("country", "Italy"));
    doc.save();
  }
}
 
Example 3
Source File: OrientApiKeyEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  type.createProperty(P_APIKEY, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_DOMAIN, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_PRIMARY_PRINCIPAL, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_PRINCIPALS, OType.BINARY)
      .setMandatory(true)
      .setNotNull(true);
  type.createIndex(I_APIKEY, INDEX_TYPE.UNIQUE, P_DOMAIN, P_APIKEY);
  type.createIndex(I_PRIMARY_PRINCIPAL, INDEX_TYPE.UNIQUE, P_DOMAIN, P_PRIMARY_PRINCIPAL);
}
 
Example 4
Source File: AssetEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void defineType(final ODatabaseDocumentTx db, final OClass type) {
  super.defineType(type);
  type.createProperty(P_COMPONENT, OType.LINK, componentEntityAdapter.getSchemaType());
  type.createProperty(P_NAME, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_SIZE, OType.LONG);
  type.createProperty(P_CONTENT_TYPE, OType.STRING);
  type.createProperty(P_BLOB_REF, OType.STRING);
  type.createProperty(P_LAST_DOWNLOADED, OType.DATETIME);
  type.createProperty(P_BLOB_CREATED, OType.DATETIME);
  type.createProperty(P_BLOB_UPDATED, OType.DATETIME);
  type.createProperty(P_CREATED_BY, OType.STRING);
  type.createProperty(P_CREATED_BY_IP, OType.STRING);

  ODocument metadata = db.newInstance()
      .field("ignoreNullValues", false)
      .field("mergeKeys", false);
  type.createIndex(I_BUCKET_COMPONENT_NAME, INDEX_TYPE.UNIQUE.name(), null, metadata,
      new String[]{P_BUCKET, P_COMPONENT, P_NAME}
  );
  type.createIndex(I_BUCKET_NAME, INDEX_TYPE.NOTUNIQUE, P_BUCKET, P_NAME);
  type.createIndex(I_COMPONENT, INDEX_TYPE.NOTUNIQUE, P_COMPONENT);

  new OIndexBuilder(type, I_NAME_CASEINSENSITIVE, INDEX_TYPE.NOTUNIQUE)
      .property(P_NAME, OType.STRING)
      .caseInsensitive()
      .build(db);
}
 
Example 5
Source File: CreateCityDb.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@Override
@Test(enabled = false)
public void init() throws Exception {
  String buildDirectory = System.getProperty("buildDirectory", ".");
  if (buildDirectory == null)
    buildDirectory = ".";

  String uri = "plocal:" + buildDirectory + "/databases/city";
  databaseDocumentTx = new ODatabaseDocumentTx(uri);
  if (databaseDocumentTx.exists()) {
    databaseDocumentTx.open("admin", "admin");
    databaseDocumentTx.drop();
  }
  databaseDocumentTx.create();
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();
  if (schema.getClass("City") == null) {
    OClass oClass = schema.createClass("City");
    oClass.createProperty("latitude", OType.DOUBLE);
    oClass.createProperty("longitude", OType.DOUBLE);
    oClass.createProperty("name", OType.STRING);
    oClass.createIndex("City.name", "FULLTEXT", null, null, "LUCENE", new String[] { "name" });
    oClass.createIndex("City.lat_lng", "SPATIAL", null, null, "LUCENE", new String[] { "latitude", "longitude" });
  }
  ZipFile zipFile = new ZipFile("files/allCountries.zip");
  Enumeration<? extends ZipEntry> entries = zipFile.entries();

  while (entries.hasMoreElements()) {

    ZipEntry entry = entries.nextElement();
    if (entry.getName().equals("allCountries.txt")) {

      InputStream stream = zipFile.getInputStream(entry);
      lineReader = new LineNumberReader(new InputStreamReader(stream));
    }
  }

  databaseDocumentTx.declareIntent(new OIntentMassiveInsert());
}
 
Example 6
Source File: OrientCUserEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  type.createProperty(P_ID, OType.STRING)
      .setNotNull(true);
  type.createProperty(P_FIRST_NAME, OType.STRING);
  type.createProperty(P_LAST_NAME, OType.STRING);
  type.createProperty(P_PASSWORD, OType.STRING)
      .setNotNull(true);
  type.createProperty(P_STATUS, OType.STRING)
      .setNotNull(true);
  type.createProperty(P_EMAIL, OType.STRING)
      .setNotNull(true);

  type.createIndex(I_ID, INDEX_TYPE.UNIQUE, P_ID);
}
 
Example 7
Source File: TriggerEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  super.defineType(type);

  type.createProperty(P_NAME, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_GROUP, OType.STRING)
      .setMandatory(true)
      .setNotNull(false); // nullable
  type.createProperty(P_JOB_NAME, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_JOB_GROUP, OType.STRING)
      .setMandatory(true)
      .setNotNull(false); // nullable
  type.createProperty(P_CALENDAR_NAME, OType.STRING)
      .setMandatory(true)
      .setNotNull(false); // nullable
  type.createProperty(P_STATE, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);

  type.createIndex(I_NAME_GROUP, INDEX_TYPE.UNIQUE, P_NAME, P_GROUP);
  type.createIndex(I_JOB_NAME_JOB_GROUP, INDEX_TYPE.NOTUNIQUE, P_JOB_NAME, P_JOB_GROUP);
  type.createIndex(I_CALENDAR_NAME, INDEX_TYPE.NOTUNIQUE, P_CALENDAR_NAME);
  type.createIndex(I_STATE, INDEX_TYPE.NOTUNIQUE, P_STATE);
}
 
Example 8
Source File: OrientQuartzSchema.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static OIndex<?> maybeCreateIndex(final OClass clazz, final String name, final String... props) {
  OIndex<?> index = clazz.getClassIndex(name);
  if (index == null) {
    index = clazz.createIndex(name, UNIQUE, props);
  }
  return index;
}
 
Example 9
Source File: OrientSelectorConfigurationEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  type.createProperty(P_NAME, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_TYPE, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_DESCRIPTION, OType.STRING);
  type.createProperty(P_ATTRIBUTES, OType.EMBEDDEDMAP)
      .setMandatory(true)
      .setNotNull(true);
  type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME);
}
 
Example 10
Source File: IndexTypeExtension.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
public void afterRegistration(final ODatabaseObject db, final SchemeDescriptor descriptor,
                              final CompositeIndex annotation) {
    // single field index definition intentionally allowed (no check)
    final String name = Strings.emptyToNull(annotation.name().trim());
    Preconditions.checkArgument(name != null, "Index name required");
    final String model = descriptor.schemeClass;
    final OClass clazz = db.getMetadata().getSchema().getClass(model);
    final OIndex<?> classIndex = clazz.getClassIndex(name);
    final OClass.INDEX_TYPE type = annotation.type();
    final String[] fields = annotation.fields();
    if (!descriptor.initialRegistration && classIndex != null) {
        final IndexValidationSupport support = new IndexValidationSupport(classIndex, logger);

        support.checkFieldsCompatible(fields);

        final boolean correct = support
                .isIndexSigns(classIndex.getDefinition().isNullValuesIgnored())
                .matchRequiredSigns(type, annotation.ignoreNullValues());
        if (!correct) {
            support.dropIndex(db);
        } else {
            // index ok
            return;
        }
    }
    final ODocument metadata = new ODocument()
            .field("ignoreNullValues", annotation.ignoreNullValues());
    clazz.createIndex(name, type.name(), null, metadata, fields);
    logger.info("Index '{}' ({} [{}]) {} created", name, model, Joiner.on(',').join(fields), type);
}
 
Example 11
Source File: BucketEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  type.createProperty(P_REPOSITORY_NAME, OType.STRING)
      .setMandatory(true)
      .setNotNull(true);
  type.createProperty(P_ATTRIBUTES, OType.EMBEDDEDMAP)
      .setNotNull(true);

  type.createIndex(I_REPOSITORY_NAME, INDEX_TYPE.UNIQUE, P_REPOSITORY_NAME);
}
 
Example 12
Source File: SecurityDatabaseUpgrade_1_2Test.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() {
  underTest = new SecurityDatabaseUpgrade_1_2(securityDatabase.getInstanceProvider());

  try (ODatabaseDocumentTx securityDb = securityDatabase.getInstance().connect()) {
    OSchema securitySchema = securityDb.getMetadata().getSchema();
    OClass type = securitySchema.createClass(DB_CLASS);
    type.createProperty(P_ID, OType.STRING).setNotNull(true);
    type.createProperty(P_PASSWORD, OType.STRING).setNotNull(true);
    type.createProperty(P_STATUS, OType.STRING).setNotNull(true);
    type.createIndex(I_ID, OClass.INDEX_TYPE.UNIQUE, P_ID);
  }
}
 
Example 13
Source File: ComponentDatabaseUpgrade_1_2.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void createBucketNameIndex() {
  try (ODatabaseDocumentTx db = componentDatabaseInstance.get().connect()) {
    if (db.getMetadata().getIndexManager().getIndex(I_BUCKET_NAME_VERSION) == null) {
      OSchema schema = db.getMetadata().getSchema();
      OClass type = schema.getClass(COMPONENT_CLASS);
      if (type != null) {
        type.createIndex(I_BUCKET_NAME_VERSION, INDEX_TYPE.NOTUNIQUE, new String[] { P_BUCKET, P_NAME, P_VERSION });
      }
    }
  }
}
 
Example 14
Source File: OrientCleanupPolicyEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  type.createProperty(P_NAME, OType.STRING).setMandatory(true).setMax(MAX_NAME_LENGTH).setNotNull(true);
  type.createProperty(P_NOTES, OType.STRING).setMandatory(false).setNotNull(false);
  type.createProperty(P_FORMAT, OType.STRING).setMandatory(true).setNotNull(true);
  type.createProperty(P_MODE, OType.STRING).setMandatory(true).setNotNull(true);
  type.createProperty(P_CRITERIA, OType.EMBEDDEDMAP).setMandatory(true).setNotNull(true);

  type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME);
  type.createIndex(I_FORMAT, INDEX_TYPE.NOTUNIQUE, P_FORMAT);
}
 
Example 15
Source File: OIndexPrototyper.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Override
protected OIndex<?> createInstance(OIndex proxy) {
	OSchema schema = OrientDbWebSession.get().getDatabase().getMetadata().getSchema();
	OClass oClass = schema.getClass(proxy.getDefinition().getClassName());
	String name = proxy.getName();
	List<String> fields = proxy.getDefinition().getFields();
	String type = proxy.getType();
	if(name==null) name=oClass.getName()+"."+fields.get(0);
	ODocument metadata = proxy.getMetadata();
	String algorithm = proxy.getAlgorithm();
	values.keySet().retainAll(RW_ATTRS);
	return oClass.createIndex(name, type, null, metadata, algorithm, fields.toArray(new String[0]));
}
 
Example 16
Source File: OrientCRoleEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void defineType(final OClass type) {
  type.createProperty(P_ID, OType.STRING)
      .setNotNull(true);
  type.createProperty(P_NAME, OType.STRING)
      .setNotNull(true);
  type.createProperty(P_DESCRIPTION, OType.STRING);
  type.createProperty(P_PRIVILEGES, OType.EMBEDDEDSET);
  type.createProperty(P_ROLES, OType.EMBEDDEDSET);

  type.createIndex(I_ID, INDEX_TYPE.UNIQUE, P_ID);
}
 
Example 17
Source File: ComponentDatabaseUpgrade_1_4.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private void createComponentIndex(final ODatabaseDocumentTx db, final OClass type) {
  if (db.getMetadata().getIndexManager().getIndex(I_COMPONENT) == null) {
    type.createIndex(I_COMPONENT, INDEX_TYPE.NOTUNIQUE, AssetEntityAdapter.P_COMPONENT);
  }
}
 
Example 18
Source File: ODocumentWrapper.java    From divide with Apache License 2.0 4 votes vote down vote up
public <B extends TransientObject> ODocumentWrapper(B b){
    super();

    String className = b.getObjectType();
    this.setAllowChainedAccess(true);
    this.setLazyLoad(false);


    // dirty unreliable hack to add HighLanderIndexFactory to the list.
    if(!OIndexes.getIndexTypes().contains(ID))
    try {
        HighLanderIndexFactory f = new HighLanderIndexFactory();
        Set<OIndexFactory> set = new HashSet<OIndexFactory>();
        Iterator<OIndexFactory> ite = OIndexes.getAllFactories();
        while (ite.hasNext()) {
            set.add(ite.next());
        }
        set.add(f);
        ReflectionUtils.setFinalStatic(ReflectionUtils.getClassField(OIndexes.class, "FACTORIES"), set);
    } catch (Exception e) {
        throw new RuntimeException("Unable to create OrientDBWrapper");
    }

    if(getDatabase().getClusterIdByName(className) == -1){
        OClass object = getDatabase().getMetadata().getSchema().getOrCreateClass(className);
        object.createProperty(indexAttribute, OType.STRING)
                .setMandatory(true)
                .setNotNull(true)
                .setReadonly(true);
        object.createIndex(className, ID, indexAttribute);
        getDatabase().getMetadata().getSchema().save();
    }

    Map user = b.getUserData();
    Map meta = b.getMetaData();

    field(indexAttribute, b.getObjectKey(), OType.STRING);
    field("user_data", user);
    field("meta_data", meta);
    super.setClassNameIfExists(className);

    System.out.println("DB: " + getDatabase().getName() + " : " + this.getClassName() + " : " + getDatabase().getClusterIdByName(className));
}
 
Example 19
Source File: LuceneCreateJavaApi.java    From orientdb-lucene with Apache License 2.0 3 votes vote down vote up
public void testCreateIndex() {
  OSchema schema = databaseDocumentTx.getMetadata().getSchema();

  OClass song = schema.getClass("Song");

  OIndex<?> lucene = song.createIndex("Song.title", OClass.INDEX_TYPE.FULLTEXT.toString(), null, null, "LUCENE",
      new String[] { "title" });

  Assert.assertNotNull(lucene);
}
 
Example 20
Source File: TestCreateNested1.java    From orientdb-lucene with Apache License 2.0 3 votes vote down vote up
@Test
public void testIndex() {

  ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:tmp");

  db.create();

  OClass test = db.getMetadata().getSchema().createClass("Test");

  test.createProperty("name", OType.STRING);
  test.createProperty("age", OType.INTEGER);

  test.createIndex("Test.name_age", OClass.INDEX_TYPE.NOTUNIQUE, "name", "age");

  ODocument doc = new ODocument("Test");

  doc.field("name", "Enrico");
  doc.field("age", 32);
  db.save(doc);

  OIndex<?> index = db.getMetadata().getIndexManager().getIndex("Test.name_age");

  Collection<OIdentifiable> results = (Collection<OIdentifiable>) index.get(new OCompositeKey(Arrays.asList("Enrico", 32)));

  Assert.assertEquals(results.size(), 1);

  results = (Collection<OIdentifiable>) index.get(new OCompositeKey(Arrays.asList("Enrico", 31)));
  Assert.assertEquals(results.size(), 0);
}