use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OrientIndex method removeElement.
protected void removeElement(final T element) {
graph.setCurrentGraphInThreadLocal();
graph.autoStartTransaction();
final OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>("select from index:" + recordKeyValueIndex.getName() + " where key between [" + element.getIdentity() + "] and [" + element.getIdentity() + "]");
final Collection<ODocument> entries = (Collection<ODocument>) graph.getRawGraph().query(query);
for (ODocument entry : entries) {
final OCompositeKey key = entry.field("key");
final List<Object> keys = key.getKeys();
underlying.remove(keys.get(1).toString(), element.getIdentity());
recordKeyValueIndex.remove(key, element.getIdentity());
}
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OrientIndex method put.
public void put(final String key, final Object value, final T element) {
final String keyTemp = key + SEPARATOR + value;
final ODocument doc = element.getRecord();
if (!doc.getIdentity().isValid())
doc.save();
graph.setCurrentGraphInThreadLocal();
graph.autoStartTransaction();
underlying.put(keyTemp, doc);
recordKeyValueIndex.put(new OCompositeKey(doc.getIdentity(), keyTemp), doc.getIdentity());
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OSQLFunctionIn 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("in", "out");
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;
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class OLuceneFullTextIndexEngine method putInManualindex.
private Document putInManualindex(Object key, OIdentifiable oIdentifiable) {
Document doc = new Document();
doc.add(OLuceneIndexType.createField(RID, oIdentifiable.getIdentity().toString(), Field.Store.YES));
if (key instanceof OCompositeKey) {
List<Object> keys = ((OCompositeKey) key).getKeys();
int k = 0;
for (Object o : keys) {
doc.add(OLuceneIndexType.createField("k" + k, o, Field.Store.NO));
k++;
}
} else if (key instanceof Collection) {
Collection<Object> keys = (Collection<Object>) key;
int k = 0;
for (Object o : keys) {
doc.add(OLuceneIndexType.createField("k" + k, o, Field.Store.NO));
k++;
}
} else {
doc.add(OLuceneIndexType.createField("k0", key, Field.Store.NO));
}
return doc;
}
use of com.orientechnologies.orient.core.index.OCompositeKey in project orientdb by orientechnologies.
the class EmbeddedObjectSerializationTest method testEmbeddedObjectSerialization.
public void testEmbeddedObjectSerialization() {
final ODocument originalDoc = new ODocument();
final OCompositeKey compositeKey = new OCompositeKey(123, "56", new Date(), new ORecordId("#0:12"));
originalDoc.field("compositeKey", compositeKey);
originalDoc.field("int", 12);
originalDoc.field("val", "test");
originalDoc.save();
final ODocument loadedDoc = database.load(originalDoc.getIdentity(), "*:-1", true);
Assert.assertNotSame(loadedDoc, originalDoc);
final OCompositeKey loadedCompositeKey = loadedDoc.field("compositeKey");
Assert.assertEquals(loadedCompositeKey, compositeKey);
originalDoc.delete();
}
Aggregations