use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.
the class OServerCommandGetDatabase method exportClass.
public static void exportClass(final ODatabaseDocument db, final OJSONWriter json, final OClass cls) throws IOException {
json.beginObject();
json.writeAttribute("name", cls.getName());
json.writeAttribute("superClass", cls.getSuperClass() != null ? cls.getSuperClass().getName() : "");
json.beginCollection("superClasses");
int i = 0;
for (OClass oClass : cls.getSuperClasses()) {
json.write((i > 0 ? "," : "") + "\"" + oClass.getName() + "\"");
i++;
}
json.endCollection();
json.writeAttribute("alias", cls.getShortName());
json.writeAttribute("abstract", cls.isAbstract());
json.writeAttribute("strictmode", cls.isStrictMode());
json.writeAttribute("clusters", cls.getClusterIds());
json.writeAttribute("defaultCluster", cls.getDefaultClusterId());
json.writeAttribute("clusterSelection", cls.getClusterSelection().getName());
if (cls instanceof OClassImpl) {
final Map<String, String> custom = ((OClassImpl) cls).getCustomInternal();
if (custom != null && !custom.isEmpty()) {
json.writeAttribute("custom", custom);
}
}
try {
json.writeAttribute("records", db.countClass(cls.getName()));
} catch (OSecurityAccessException e) {
json.writeAttribute("records", "? (Unauthorized)");
} catch (Exception e) {
json.writeAttribute("records", "? (Error)");
}
if (cls.properties() != null && cls.properties().size() > 0) {
json.beginCollection("properties");
for (final OProperty prop : cls.properties()) {
json.beginObject();
json.writeAttribute("name", prop.getName());
if (prop.getLinkedClass() != null)
json.writeAttribute("linkedClass", prop.getLinkedClass().getName());
if (prop.getLinkedType() != null)
json.writeAttribute("linkedType", prop.getLinkedType().toString());
json.writeAttribute("type", prop.getType().toString());
json.writeAttribute("mandatory", prop.isMandatory());
json.writeAttribute("readonly", prop.isReadonly());
json.writeAttribute("notNull", prop.isNotNull());
json.writeAttribute("min", prop.getMin());
json.writeAttribute("max", prop.getMax());
json.writeAttribute("regexp", prop.getRegexp());
json.writeAttribute("collate", prop.getCollate() != null ? prop.getCollate().getName() : "default");
json.writeAttribute("defaultValue", prop.getDefaultValue());
if (prop instanceof OPropertyImpl) {
final Map<String, String> custom = ((OPropertyImpl) prop).getCustomInternal();
if (custom != null && !custom.isEmpty()) {
json.writeAttribute("custom", custom);
}
}
json.endObject();
}
json.endCollection();
}
final Set<OIndex<?>> indexes = cls.getIndexes();
if (!indexes.isEmpty()) {
json.beginCollection("indexes");
for (final OIndex<?> index : indexes) {
json.beginObject();
json.writeAttribute("name", index.getName());
json.writeAttribute("type", index.getType());
final OIndexDefinition indexDefinition = index.getDefinition();
if (indexDefinition != null && !indexDefinition.getFields().isEmpty())
json.writeAttribute("fields", indexDefinition.getFields());
json.endObject();
}
json.endCollection();
}
json.endObject();
}
use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.
the class CRUDObjectInheritanceTestSchemaFull method checkNoLinkedProperty.
protected void checkNoLinkedProperty(OClass iClass, String iPropertyName, OType iType) {
OProperty prop = iClass.getProperty(iPropertyName);
Assert.assertNotNull(prop);
Assert.assertNull(prop.getLinkedType());
Assert.assertNull(prop.getLinkedClass());
}
use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.
the class CollateTest method testCompositeIndexQueryCS.
public void testCompositeIndexQueryCS() {
final OSchema schema = database.getMetadata().getSchema();
OClass clazz = schema.createClass("CompositeIndexQueryCSTest");
OProperty csp = clazz.createProperty("csp", OType.STRING);
csp.setCollate(ODefaultCollate.NAME);
OProperty cip = clazz.createProperty("cip", OType.STRING);
cip.setCollate(OCaseInsensitiveCollate.NAME);
clazz.createIndex("collateCompositeIndexCS", OClass.INDEX_TYPE.NOTUNIQUE, "csp", "cip");
for (int i = 0; i < 10; i++) {
ODocument document = new ODocument("CompositeIndexQueryCSTest");
if (i % 2 == 0) {
document.field("csp", "VAL");
document.field("cip", "VAL");
} else {
document.field("csp", "val");
document.field("cip", "val");
}
document.save();
}
String query = "select from CompositeIndexQueryCSTest where csp = 'VAL'";
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 5);
for (ODocument document : result) Assert.assertEquals(document.field("csp"), "VAL");
ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCS"));
query = "select from CompositeIndexQueryCSTest where csp = 'VAL' and cip = 'VaL'";
result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 5);
for (ODocument document : result) {
Assert.assertEquals(document.field("csp"), "VAL");
Assert.assertEquals((document.<String>field("cip")).toUpperCase(), "VAL");
}
explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCS"));
result = database.query(new OSQLSynchQuery<ODocument>("select from index:collateCompositeIndexCS where key = ['VAL', 'VaL']"));
Assert.assertEquals(result.size(), 5);
for (ODocument document : result) {
final OCompositeKey key = document.field("key");
final List keys = key.getKeys();
Assert.assertEquals(keys.get(0), "VAL");
Assert.assertTrue("val".compareToIgnoreCase((String) keys.get(1)) == 0);
final ODocument record = document.<OIdentifiable>field("rid").getRecord();
Assert.assertEquals(record.field("csp"), "VAL");
Assert.assertEquals((record.<String>field("cip")).toUpperCase(), "VAL");
}
}
use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.
the class CollateTest method testQuery.
public void testQuery() {
final OSchema schema = database.getMetadata().getSchema();
OClass clazz = schema.createClass("collateTest");
OProperty csp = clazz.createProperty("csp", OType.STRING);
csp.setCollate(ODefaultCollate.NAME);
OProperty cip = clazz.createProperty("cip", OType.STRING);
cip.setCollate(OCaseInsensitiveCollate.NAME);
for (int i = 0; i < 10; i++) {
ODocument document = new ODocument("collateTest");
if (i % 2 == 0) {
document.field("csp", "VAL");
document.field("cip", "VAL");
} else {
document.field("csp", "val");
document.field("cip", "val");
}
document.save();
}
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from collateTest where csp = 'VAL'"));
Assert.assertEquals(result.size(), 5);
for (ODocument document : result) Assert.assertEquals(document.field("csp"), "VAL");
result = database.query(new OSQLSynchQuery<ODocument>("select from collateTest where cip = 'VaL'"));
Assert.assertEquals(result.size(), 10);
for (ODocument document : result) Assert.assertEquals((document.<String>field("cip")).toUpperCase(), "VAL");
}
use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.
the class CollateTest method testIndexQuery.
public void testIndexQuery() {
final OSchema schema = database.getMetadata().getSchema();
OClass clazz = schema.createClass("collateIndexTest");
OProperty csp = clazz.createProperty("csp", OType.STRING);
csp.setCollate(ODefaultCollate.NAME);
OProperty cip = clazz.createProperty("cip", OType.STRING);
cip.setCollate(OCaseInsensitiveCollate.NAME);
clazz.createIndex("collateIndexCSP", OClass.INDEX_TYPE.NOTUNIQUE, "csp");
clazz.createIndex("collateIndexCIP", OClass.INDEX_TYPE.NOTUNIQUE, "cip");
for (int i = 0; i < 10; i++) {
ODocument document = new ODocument("collateIndexTest");
if (i % 2 == 0) {
document.field("csp", "VAL");
document.field("cip", "VAL");
} else {
document.field("csp", "val");
document.field("cip", "val");
}
document.save();
}
String query = "select from collateIndexTest where csp = 'VAL'";
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 5);
for (ODocument document : result) Assert.assertEquals(document.field("csp"), "VAL");
ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateIndexCSP"));
query = "select from collateIndexTest where cip = 'VaL'";
result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 10);
for (ODocument document : result) Assert.assertEquals((document.<String>field("cip")).toUpperCase(), "VAL");
explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateIndexCIP"));
}
Aggregations