use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ODocumentSchemalessBinarySerializationTest method testSimpleSerialization.
@Test
public void testSimpleSerialization() {
ODatabaseRecordThreadLocal.INSTANCE.remove();
ODocument document = new ODocument();
document.field("name", "name");
document.field("age", 20);
document.field("youngAge", (short) 20);
document.field("oldAge", (long) 20);
document.field("heigth", 12.5f);
document.field("bitHeigth", 12.5d);
document.field("class", (byte) 'C');
document.field("nullField", (Object) null);
document.field("character", 'C');
document.field("alive", true);
document.field("dateTime", new Date());
document.field("bigNumber", new BigDecimal("43989872423376487952454365232141525434.32146432321442534"));
ORidBag bag = new ORidBag();
bag.add(new ORecordId(1, 1));
bag.add(new ORecordId(2, 2));
// document.field("ridBag", bag);
Calendar c = Calendar.getInstance();
document.field("date", c.getTime(), OType.DATE);
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.MILLISECOND, 0);
c1.set(Calendar.SECOND, 0);
c1.set(Calendar.MINUTE, 0);
c1.set(Calendar.HOUR_OF_DAY, 0);
document.field("date1", c1.getTime(), OType.DATE);
byte[] byteValue = new byte[10];
Arrays.fill(byteValue, (byte) 10);
document.field("bytes", byteValue);
document.field("utf8String", new String("A" + "ê" + "ñ" + "ü" + "C"));
document.field("recordId", new ORecordId(10, 10));
byte[] res = serializer.toStream(document, false);
ODocument extr = (ODocument) serializer.fromStream(res, new ODocument(), new String[] {});
c.set(Calendar.MILLISECOND, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.HOUR_OF_DAY, 0);
assertEquals(extr.fields(), document.fields());
assertEquals(extr.field("name"), document.field("name"));
assertEquals(extr.field("age"), document.field("age"));
assertEquals(extr.field("youngAge"), document.field("youngAge"));
assertEquals(extr.field("oldAge"), document.field("oldAge"));
assertEquals(extr.field("heigth"), document.field("heigth"));
assertEquals(extr.field("bitHeigth"), document.field("bitHeigth"));
assertEquals(extr.field("class"), document.field("class"));
// TODO fix char management issue:#2427
// assertEquals(document.field("character"), extr.field("character"));
assertEquals(extr.field("alive"), document.field("alive"));
assertEquals(extr.field("dateTime"), document.field("dateTime"));
assertEquals(extr.field("date"), c.getTime());
assertEquals(extr.field("date1"), c1.getTime());
assertEquals(extr.field("bytes"), document.field("bytes"));
assertEquals(extr.field("utf8String"), document.field("utf8String"));
assertEquals(extr.field("recordId"), document.field("recordId"));
assertEquals(extr.field("bigNumber"), document.field("bigNumber"));
assertNull(extr.field("nullField"));
// assertEquals(extr.field("ridBag"), document.field("ridBag"));
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ODocumentSerializationPersistentTest method testRidBagInEmbeddedDocument.
@Test
public void testRidBagInEmbeddedDocument() {
ODatabaseRecordThreadLocal.INSTANCE.set(db);
ODocument doc = new ODocument();
ORidBag rids = new ORidBag();
rids.add(new ORecordId(2, 3));
rids.add(new ORecordId(2, 4));
rids.add(new ORecordId(2, 5));
rids.add(new ORecordId(2, 6));
List<ODocument> docs = new ArrayList<ODocument>();
ODocument doc1 = new ODocument();
doc1.field("rids", rids);
docs.add(doc1);
ODocument doc2 = new ODocument();
doc2.field("text", "text");
docs.add(doc2);
doc.field("emb", docs, OType.EMBEDDEDLIST);
doc.field("some", "test");
byte[] res = db.getSerializer().toStream(doc, false);
ODocument extr = (ODocument) db.getSerializer().fromStream(res, new ODocument(), new String[] {});
List<ODocument> emb = extr.field("emb");
assertNotNull(emb);
assertEquals(((ORidBag) emb.get(0).field("rids")).size(), rids.size());
assertEquals(emb.get(1).field("text"), doc2.field("text"));
assertEquals(extr.field("name"), doc.field("name"));
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ODocumentValidationTest method testLinkedClassValidation.
@Test
public void testLinkedClassValidation() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ODocumentValidationTest.class.getSimpleName());
db.create();
try {
OClass clazz = db.getMetadata().getSchema().createClass("Validation");
OClass clazz1 = db.getMetadata().getSchema().createClass("Validation1");
clazz.createProperty("link", OType.LINK).setLinkedClass(clazz1);
clazz.createProperty("embedded", OType.EMBEDDED).setLinkedClass(clazz1);
clazz.createProperty("linkList", OType.LINKLIST).setLinkedClass(clazz1);
clazz.createProperty("embeddedList", OType.EMBEDDEDLIST).setLinkedClass(clazz1);
clazz.createProperty("embeddedSet", OType.EMBEDDEDSET).setLinkedClass(clazz1);
clazz.createProperty("linkSet", OType.LINKSET).setLinkedClass(clazz1);
clazz.createProperty("linkMap", OType.LINKMAP).setLinkedClass(clazz1);
clazz.createProperty("linkBag", OType.LINKBAG).setLinkedClass(clazz1);
ODocument d = new ODocument(clazz);
d.field("link", new ODocument(clazz1));
d.field("embedded", new ODocument(clazz1));
List<ODocument> list = Arrays.asList(new ODocument(clazz1));
d.field("linkList", list);
Set<ODocument> set = new HashSet<ODocument>(list);
d.field("linkSet", set);
List<ODocument> embeddedList = Arrays.asList(new ODocument(clazz1), null);
d.field("embeddedList", embeddedList);
Set<ODocument> embeddedSet = new HashSet<ODocument>(embeddedList);
d.field("embeddedSet", embeddedSet);
Map<String, ODocument> map = new HashMap<String, ODocument>();
map.put("a", new ODocument(clazz1));
d.field("linkMap", map);
d.validate();
checkField(d, "link", new ODocument(clazz));
checkField(d, "embedded", new ODocument(clazz));
checkField(d, "linkList", Arrays.asList("a", "b"));
checkField(d, "linkSet", new HashSet<String>(Arrays.asList("a", "b")));
Map<String, String> map1 = new HashMap<String, String>();
map1.put("a", "a1");
map1.put("b", "a2");
checkField(d, "linkMap", map1);
checkField(d, "linkList", Arrays.asList(new ODocument(clazz)));
checkField(d, "linkSet", new HashSet<ODocument>(Arrays.asList(new ODocument(clazz))));
checkField(d, "embeddedList", Arrays.asList(new ODocument(clazz)));
checkField(d, "embeddedSet", Arrays.asList(new ODocument(clazz)));
ORidBag bag = new ORidBag();
bag.add(new ODocument(clazz));
checkField(d, "linkBag", bag);
Map<String, ODocument> map2 = new HashMap<String, ODocument>();
map2.put("a", new ODocument(clazz));
checkField(d, "linkMap", map2);
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class SBTreeBagDeleteTest method testDeleteRidbagNoTx.
@Test
public void testDeleteRidbagNoTx() {
ODocument doc = new ODocument();
ORidBag bag = new ORidBag();
int size = OGlobalConfiguration.INDEX_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger() * 2;
for (int i = 0; i < size; i++) bag.add(new ORecordId(10, i));
doc.field("bag", bag);
ORID id = db.save(doc).getIdentity();
bag = doc.field("bag");
OBonsaiCollectionPointer pointer = bag.getPointer();
db.delete(doc);
doc = db.load(id);
assertNull(doc);
((OSBTreeCollectionManagerShared) db.getSbTreeCollectionManager()).clear();
OSBTreeBonsai<OIdentifiable, Integer> tree = db.getSbTreeCollectionManager().loadSBTree(pointer);
assertNull(tree);
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class OrientVertex method getVertices.
/**
* Returns a lazy iterable instance against vertices.
*
* @param iDirection The direction between OUT, IN or BOTH
* @param iLabels Optional varargs of Strings representing edge label to consider
*/
@Override
public Iterable<Vertex> getVertices(final Direction iDirection, final String... iLabels) {
setCurrentGraphInThreadLocal();
OrientBaseGraph.getEdgeClassNames(getGraph(), iLabels);
OrientBaseGraph.encodeClassNames(iLabels);
final ODocument doc = getRecord();
final OMultiCollectionIterator<Vertex> iterable = new OMultiCollectionIterator<Vertex>();
String[] fieldNames = null;
if (iLabels != null && iLabels.length > 0) {
// EDGE LABELS: CREATE FIELD NAME TABLE (FASTER THAN EXTRACT FIELD NAMES FROM THE DOCUMENT)
fieldNames = getFieldNames(iDirection, iLabels);
if (fieldNames != null)
// EARLY FETCH ALL THE FIELDS THAT MATTERS
doc.deserializeFields(fieldNames);
}
if (fieldNames == null)
fieldNames = doc.fieldNames();
for (String fieldName : fieldNames) {
final OPair<Direction, String> connection = getConnection(iDirection, fieldName, iLabels);
if (connection == null)
// SKIP THIS FIELD
continue;
final Object fieldValue = doc.rawField(fieldName);
if (fieldValue != null)
if (fieldValue instanceof OIdentifiable) {
addSingleVertex(doc, iterable, fieldName, connection, fieldValue, iLabels);
} else if (fieldValue instanceof Collection<?>) {
Collection<?> coll = (Collection<?>) fieldValue;
if (coll.size() == 1) {
// SINGLE ITEM: AVOID CALLING ITERATOR
if (coll instanceof ORecordLazyMultiValue)
addSingleVertex(doc, iterable, fieldName, connection, ((ORecordLazyMultiValue) coll).rawIterator().next(), iLabels);
else if (coll instanceof List<?>)
addSingleVertex(doc, iterable, fieldName, connection, ((List<?>) coll).get(0), iLabels);
else
addSingleVertex(doc, iterable, fieldName, connection, coll.iterator().next(), iLabels);
} else {
// CREATE LAZY Iterable AGAINST COLLECTION FIELD
if (coll instanceof ORecordLazyMultiValue)
iterable.add(new OrientVertexIterator(this, coll, ((ORecordLazyMultiValue) coll).rawIterator(), connection, iLabels, coll.size()));
else
iterable.add(new OrientVertexIterator(this, coll, coll.iterator(), connection, iLabels, -1));
}
} else if (fieldValue instanceof ORidBag) {
iterable.add(new OrientVertexIterator(this, fieldValue, ((ORidBag) fieldValue).rawIterator(), connection, iLabels, -1));
}
}
return iterable;
}
Aggregations