use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class ODocumentValidationTest method testValidLinkCollectionsUpdate.
@Test
public void testValidLinkCollectionsUpdate() {
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("linkList", OType.LINKLIST).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);
d.field("linkBag", new ORidBag());
Map<String, ODocument> map = new HashMap<String, ODocument>();
map.put("a", new ODocument(clazz1));
d.field("linkMap", map);
db.save(d);
try {
ODocument newD = d.copy();
((Collection) newD.field("linkList")).add(new ODocument(clazz));
newD.validate();
AssertJUnit.fail();
} catch (OValidationException v) {
}
try {
ODocument newD = d.copy();
((Collection) newD.field("linkSet")).add(new ODocument(clazz));
newD.validate();
AssertJUnit.fail();
} catch (OValidationException v) {
}
try {
ODocument newD = d.copy();
((ORidBag) newD.field("linkBag")).add(new ODocument(clazz));
newD.validate();
AssertJUnit.fail();
} catch (OValidationException v) {
}
try {
ODocument newD = d.copy();
((Map<String, ODocument>) newD.field("linkMap")).put("a", new ODocument(clazz));
newD.validate();
AssertJUnit.fail();
} catch (OValidationException v) {
}
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class ODocumentValidationTest method testRequiredValidation.
@Test
public void testRequiredValidation() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ODocumentValidationTest.class.getSimpleName());
db.create();
try {
ODocument doc = new ODocument();
OIdentifiable id = db.save(doc).getIdentity();
OClass embeddedClazz = db.getMetadata().getSchema().createClass("EmbeddedValidation");
embeddedClazz.createProperty("int", OType.INTEGER).setMandatory(true);
OClass clazz = db.getMetadata().getSchema().createClass("Validation");
clazz.createProperty("int", OType.INTEGER).setMandatory(true);
clazz.createProperty("long", OType.LONG).setMandatory(true);
clazz.createProperty("float", OType.FLOAT).setMandatory(true);
clazz.createProperty("boolean", OType.BOOLEAN).setMandatory(true);
clazz.createProperty("binary", OType.BINARY).setMandatory(true);
clazz.createProperty("byte", OType.BYTE).setMandatory(true);
clazz.createProperty("date", OType.DATE).setMandatory(true);
clazz.createProperty("datetime", OType.DATETIME).setMandatory(true);
clazz.createProperty("decimal", OType.DECIMAL).setMandatory(true);
clazz.createProperty("double", OType.DOUBLE).setMandatory(true);
clazz.createProperty("short", OType.SHORT).setMandatory(true);
clazz.createProperty("string", OType.STRING).setMandatory(true);
clazz.createProperty("link", OType.LINK).setMandatory(true);
clazz.createProperty("embedded", OType.EMBEDDED, embeddedClazz).setMandatory(true);
clazz.createProperty("embeddedListNoClass", OType.EMBEDDEDLIST).setMandatory(true);
clazz.createProperty("embeddedSetNoClass", OType.EMBEDDEDSET).setMandatory(true);
clazz.createProperty("embeddedMapNoClass", OType.EMBEDDEDMAP).setMandatory(true);
clazz.createProperty("embeddedList", OType.EMBEDDEDLIST, embeddedClazz).setMandatory(true);
clazz.createProperty("embeddedSet", OType.EMBEDDEDSET, embeddedClazz).setMandatory(true);
clazz.createProperty("embeddedMap", OType.EMBEDDEDMAP, embeddedClazz).setMandatory(true);
clazz.createProperty("linkList", OType.LINKLIST).setMandatory(true);
clazz.createProperty("linkSet", OType.LINKSET).setMandatory(true);
clazz.createProperty("linkMap", OType.LINKMAP).setMandatory(true);
ODocument d = new ODocument(clazz);
d.field("int", 10);
d.field("long", 10);
d.field("float", 10);
d.field("boolean", 10);
d.field("binary", new byte[] {});
d.field("byte", 10);
d.field("date", new Date());
d.field("datetime", new Date());
d.field("decimal", 10);
d.field("double", 10);
d.field("short", 10);
d.field("string", "yeah");
d.field("link", id);
d.field("linkList", new ArrayList<ORecordId>());
d.field("linkSet", new HashSet<ORecordId>());
d.field("linkMap", new HashMap<String, ORecordId>());
d.field("embeddedListNoClass", new ArrayList<ORecordId>());
d.field("embeddedSetNoClass", new HashSet<ORecordId>());
d.field("embeddedMapNoClass", new HashMap<String, ORecordId>());
ODocument embedded = new ODocument("EmbeddedValidation");
embedded.field("int", 20);
embedded.field("long", 20);
d.field("embedded", embedded);
ODocument embeddedInList = new ODocument("EmbeddedValidation");
embeddedInList.field("int", 30);
embeddedInList.field("long", 30);
final ArrayList<ODocument> embeddedList = new ArrayList<ODocument>();
embeddedList.add(embeddedInList);
d.field("embeddedList", embeddedList);
ODocument embeddedInSet = new ODocument("EmbeddedValidation");
embeddedInSet.field("int", 30);
embeddedInSet.field("long", 30);
final Set<ODocument> embeddedSet = new HashSet<ODocument>();
embeddedSet.add(embeddedInSet);
d.field("embeddedSet", embeddedSet);
ODocument embeddedInMap = new ODocument("EmbeddedValidation");
embeddedInMap.field("int", 30);
embeddedInMap.field("long", 30);
final Map<String, ODocument> embeddedMap = new HashMap<String, ODocument>();
embeddedMap.put("testEmbedded", embeddedInMap);
d.field("embeddedMap", embeddedMap);
d.validate();
checkRequireField(d, "int");
checkRequireField(d, "long");
checkRequireField(d, "float");
checkRequireField(d, "boolean");
checkRequireField(d, "binary");
checkRequireField(d, "byte");
checkRequireField(d, "date");
checkRequireField(d, "datetime");
checkRequireField(d, "decimal");
checkRequireField(d, "double");
checkRequireField(d, "short");
checkRequireField(d, "string");
checkRequireField(d, "link");
checkRequireField(d, "embedded");
checkRequireField(d, "embeddedList");
checkRequireField(d, "embeddedSet");
checkRequireField(d, "embeddedMap");
checkRequireField(d, "linkList");
checkRequireField(d, "linkSet");
checkRequireField(d, "linkMap");
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OEmbeddedRidBagBasicTest method embeddedRidBagSerializationTest.
@Test
public void embeddedRidBagSerializationTest() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + OEmbeddedRidBag.class.getSimpleName());
db.create();
try {
OEmbeddedRidBag bag = new OEmbeddedRidBag();
bag.add(new ORecordId(3, 1000));
bag.convertLinks2Records();
bag.convertRecords2Links();
byte[] bytes = new byte[1024];
UUID id = UUID.randomUUID();
bag.serialize(bytes, 0, id);
OEmbeddedRidBag bag1 = new OEmbeddedRidBag();
bag1.deserialize(bytes, 0);
assertEquals(bag.size(), 1);
assertEquals(null, bag1.iterator().next());
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OServerCommandGetGephi method execute.
@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
String[] urlParts = checkSyntax(iRequest.url, 4, "Syntax error: gephi/<database>/<language>/<query-text>[/<limit>][/<fetchPlan>].<br>Limit is optional and is setted to 20 by default. Set expressely to 0 to have no limits.");
final String language = urlParts[2];
final String text = urlParts[3];
final int limit = urlParts.length > 4 ? Integer.parseInt(urlParts[4]) : 20;
final String fetchPlan = urlParts.length > 5 ? urlParts[5] : null;
iRequest.data.commandInfo = "Gephi";
iRequest.data.commandDetail = text;
final ODatabaseDocument db = getProfiledDatabaseInstance(iRequest);
final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
final OrientBaseGraph graph = OGraphCommandExecutorSQLFactory.getAnyGraph(shutdownFlag);
try {
final Iterable<OrientElement> vertices;
if (language.equals("sql"))
vertices = graph.command(new OSQLSynchQuery<OrientVertex>(text, limit).setFetchPlan(fetchPlan)).execute();
else if (language.equals("gremlin")) {
List<Object> result = new ArrayList<Object>();
OGremlinHelper.execute(graph, text, null, null, result, null, null);
vertices = new ArrayList<OrientElement>(result.size());
for (Object o : result) {
((ArrayList<OrientElement>) vertices).add(graph.getVertex(o));
}
} else
throw new IllegalArgumentException("Language '" + language + "' is not supported. Use 'sql' or 'gremlin'");
sendRecordsContent(iRequest, iResponse, vertices, fetchPlan);
} finally {
if (graph != null && shutdownFlag.getValue())
graph.shutdown(false, false);
if (db != null)
db.close();
}
return false;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLMoveVertex method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLMoveVertex parse(final OCommandRequest iRequest) {
final ODatabaseDocument database = getDatabase();
init((OCommandRequestText) iRequest);
parserRequiredKeyword("MOVE");
parserRequiredKeyword("VERTEX");
source = parserRequiredWord(false, "Syntax error", " =><,\r\n");
if (source == null)
throw new OCommandSQLParsingException("Cannot find source");
parserRequiredKeyword("TO");
String temp = parseOptionalWord(true);
while (temp != null) {
if (temp.startsWith("CLUSTER:")) {
if (className != null)
throw new OCommandSQLParsingException("Cannot define multiple sources. Found both cluster and class.");
clusterName = temp.substring("CLUSTER:".length());
if (database.getClusterIdByName(clusterName) == -1)
throw new OCommandSQLParsingException("Cluster '" + clusterName + "' was not found");
} else if (temp.startsWith("CLASS:")) {
if (clusterName != null)
throw new OCommandSQLParsingException("Cannot define multiple sources. Found both cluster and class.");
className = temp.substring("CLASS:".length());
clazz = database.getMetadata().getSchema().getClass(className);
if (clazz == null)
throw new OCommandSQLParsingException("Class '" + className + "' was not found");
} else if (temp.equals(KEYWORD_SET)) {
fields = new ArrayList<OPair<String, Object>>();
parseSetFields(clazz, fields);
} else if (temp.equals(KEYWORD_MERGE)) {
merge = parseJSON();
} else if (temp.equals(KEYWORD_BATCH)) {
temp = parserNextWord(true);
if (temp != null)
batch = Integer.parseInt(temp);
}
temp = parserOptionalWord(true);
if (parserIsEnded())
break;
}
return this;
}
Aggregations