use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testNoClassIndexesUpdate.
public void testNoClassIndexesUpdate() {
final ODocument doc = new ODocument("classIndexManagerTestClassTwo");
doc.field("prop1", "a");
doc.save();
doc.field("prop1", "b");
doc.save();
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("classIndexManagerTestClass");
final Collection<OIndex<?>> indexes = oClass.getIndexes();
for (final OIndex<?> index : indexes) {
Assert.assertEquals(index.getSize(), 0);
}
}
use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.
the class OChainedIndexProxyFindBestIndexTest method testTheOnlyChoice.
@Test
public void testTheOnlyChoice() throws Exception {
final OIndexUnique expectedResult = mockUniqueIndex();
final List<OIndex<?>> indexes = Arrays.<OIndex<?>>asList(expectedResult);
final OIndex<?> result = OChainedIndexProxy.findBestIndex(indexes);
Assert.assertSame(result, expectedResult);
}
use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.
the class OChainedIndexProxyFindBestIndexTest method testDoNotUseIndexesWithNoNullValueSupport.
@Test
public void testDoNotUseIndexesWithNoNullValueSupport() throws Exception {
final OIndexUnique expectedResult = mockUniqueIndex();
final List<OIndex<?>> indexes = Arrays.<OIndex<?>>asList(mockUniqueCompositeHashIndex(), mockUniqueCompositeIndex(), expectedResult);
final OIndex<?> result = OChainedIndexProxy.findBestIndex(indexes);
Assert.assertSame(result, expectedResult);
}
use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.
the class OOrientDBLoader method createSchema.
private void createSchema(OETLPipeline pipeline, ODatabaseDocument documentDatabase) {
if (classes != null) {
for (ODocument cls : classes) {
schemaClass = getOrCreateClass(pipeline, (String) cls.field("name"), (String) cls.field("extends"));
Integer clusters = cls.field("clusters");
if (clusters != null)
OClassImpl.addClusters(schemaClass, clusters);
log(DEBUG, "%s: found %d %s in class '%s'", getName(), schemaClass.count(), getUnit(), className);
}
}
if (className != null) {
schemaClass = getOrCreateClass(pipeline, className, null);
log(DEBUG, "%s: found %d %s in class '%s'", getName(), schemaClass.count(), getUnit(), className);
}
if (indexes != null) {
for (ODocument idx : indexes) {
OIndex index;
final ODocument metadata = (ODocument) resolve(idx.field("metadata"));
log(DEBUG, "%s: found metadata field '%s'", getName(), metadata);
String idxName = (String) resolve(idx.field("name"));
if (idxName != null) {
index = documentDatabase.getMetadata().getIndexManager().getIndex(idxName);
if (index != null)
// ALREADY EXISTS
continue;
}
final String idxClass = (String) resolve(idx.field("class"));
if (idxClass == null)
throw new OConfigurationException("Index 'class' missed in OrientDB Loader");
final OClass cls = getOrCreateClass(pipeline, idxClass, null);
final String idxType = idx.field("type");
if (idxType == null)
throw new OConfigurationException("Index 'type' missed in OrientDB Loader for index '" + idxName + "'");
final List<String> idxFields = idx.field("fields");
if (idxFields == null)
throw new OConfigurationException("Index 'fields' missed in OrientDB Loader");
String[] fields = new String[idxFields.size()];
for (int f = 0; f < fields.length; ++f) {
final String fieldName = idxFields.get(f);
final String[] fieldNameParts = fieldName.split(":");
if (!cls.existsProperty(fieldNameParts[0])) {
if (fieldNameParts.length < 2)
throw new OConfigurationException("Index field type missed in OrientDB Loader for field '" + fieldName + "'");
final String fieldType = fieldNameParts[1].toUpperCase(Locale.ENGLISH);
final OType type = OType.valueOf(fieldType);
cls.createProperty(fieldNameParts[0], type);
log(DEBUG, "- OrientDBLoader: created property '%s.%s' of type: %s", idxClass, fieldNameParts[0], fieldNameParts[1]);
}
fields[f] = fieldNameParts[0];
}
if (idxName == null) {
// CREATE INDEX NAME
idxName = idxClass + ".";
for (int i = 0; i < fields.length; ++i) {
if (i > 0)
idxName += '_';
idxName += fields[i];
}
}
index = documentDatabase.getMetadata().getIndexManager().getIndex(idxName);
if (index != null)
// ALREADY EXISTS
continue;
index = cls.createIndex(idxName, idxType, null, metadata, fields);
log(DEBUG, "- OrientDocumentLoader: created index '%s' type '%s' against Class '%s', fields %s", idxName, idxType, idxClass, idxFields);
}
}
}
use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.
the class OSQLFunctionOut method fetchFromIndex.
private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
String edgeClassName = null;
if (iEdgeTypes == null) {
edgeClassName = "E";
} else if (iEdgeTypes.length == 1) {
edgeClassName = iEdgeTypes[0];
} else {
return null;
}
OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
if (edgeClass == null) {
return null;
}
Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("out", "in");
if (indexes == null || indexes.size() == 0) {
return null;
}
OIndex index = indexes.iterator().next();
OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
for (OIdentifiable to : iTo) {
OCompositeKey key = new OCompositeKey(iFrom, to);
Object indexResult = index.get(key);
if (indexResult instanceof OIdentifiable) {
indexResult = Collections.singleton(indexResult);
}
Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
}
result.add(identities);
}
return result;
}
Aggregations