use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class DefaultValueTest method testDefaultValueDate.
@Test
public void testDefaultValueDate() {
OSchema schema = database.getMetadata().getSchema();
OClass classA = schema.createClass("ClassA");
OProperty prop = classA.createProperty("date", OType.DATE);
prop.setDefaultValue(ODateHelper.getDateTimeFormatInstance().format(new Date()));
OProperty some = classA.createProperty("id", OType.STRING);
some.setDefaultValue("uuid()");
System.out.println(prop.getDefaultValue());
ODocument doc = new ODocument(classA);
ODocument saved = database.save(doc);
assertNotNull(saved.field("date"));
assertTrue(saved.field("date") instanceof Date);
assertNotNull(saved.field("id"));
OIdentifiable id = database.command(new OCommandSQL("insert into ClassA content {}")).execute();
ODocument seved1 = database.load(id.getIdentity());
assertNotNull(seved1.field("date"));
assertNotNull(seved1.field("id"));
assertTrue(seved1.field("date") instanceof Date);
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class DefaultValueTest method testKeepValueSerialization.
@Test
public void testKeepValueSerialization() {
// create example schema
OSchema schema = database.getMetadata().getSchema();
OClass classA = schema.createClass("ClassC");
OProperty prop = classA.createProperty("name", OType.STRING);
prop.setDefaultValue("uuid()");
ODocument doc = new ODocument("ClassC");
byte[] val = doc.toStream();
ODocument doc1 = new ODocument();
doc1.fromStream(val);
doc1.deserializeFields();
assertEquals(doc.field("name"), doc1.field("name"));
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class OrientJdbcDatabaseMetaData method getColumns.
@Override
public ResultSet getColumns(final String catalog, final String schemaPattern, final String tableNamePattern, final String columnNamePattern) throws SQLException {
database.activateOnCurrentThread();
final List<ODocument> records = new ArrayList<ODocument>();
OSchema schema = database.getMetadata().getSchema();
for (OClass clazz : schema.getClasses()) {
if (OrientJdbcUtils.like(clazz.getName(), tableNamePattern)) {
for (OProperty prop : clazz.properties()) {
if (columnNamePattern == null) {
records.add(getPropertyAsDocument(clazz, prop));
} else {
if (OrientJdbcUtils.like(prop.getName(), columnNamePattern)) {
records.add(getPropertyAsDocument(clazz, prop));
}
}
}
}
}
return new OrientJdbcResultSet(new OrientJdbcStatement(connection), records, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class CompositeIndexWithNullTest method testPointQueryInTx.
public void testPointQueryInTx() {
final OSchema schema = database.getMetadata().getSchema();
OClass clazz = schema.createClass("compositeIndexNullPointQueryInTxClass");
clazz.createProperty("prop1", OType.INTEGER);
clazz.createProperty("prop2", OType.INTEGER);
clazz.createProperty("prop3", OType.INTEGER);
final ODocument metadata = new ODocument();
metadata.field("ignoreNullValues", false);
clazz.createIndex("compositeIndexNullPointQueryInTxIndex", OClass.INDEX_TYPE.NOTUNIQUE.toString(), null, metadata, new String[] { "prop1", "prop2", "prop3" });
database.begin();
for (int i = 0; i < 20; i++) {
ODocument document = new ODocument("compositeIndexNullPointQueryInTxClass");
document.field("prop1", i / 10);
document.field("prop2", i / 5);
if (i % 2 == 0)
document.field("prop3", i);
document.save();
}
database.commit();
String query = "select from compositeIndexNullPointQueryInTxClass where prop1 = 1 and prop2 = 2";
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 5);
for (int k = 0; k < 5; k++) {
ODocument document = result.get(k);
Assert.assertEquals(document.field("prop1"), 1);
Assert.assertEquals(document.field("prop2"), 2);
}
ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("compositeIndexNullPointQueryInTxIndex"));
query = "select from compositeIndexNullPointQueryInTxClass where prop1 = 1 and prop2 = 2 and prop3 is null";
result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 2);
for (ODocument document : result) Assert.assertNull(document.field("prop3"));
explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("compositeIndexNullPointQueryInTxIndex"));
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class CompositeIndexWithNullTest method testRangeQueryInMiddleTx.
public void testRangeQueryInMiddleTx() {
if (database.getURL().startsWith("remote:"))
return;
final OSchema schema = database.getMetadata().getSchema();
OClass clazz = schema.createClass("compositeIndexNullRangeQueryInMiddleTxClass");
clazz.createProperty("prop1", OType.INTEGER);
clazz.createProperty("prop2", OType.INTEGER);
clazz.createProperty("prop3", OType.INTEGER);
final ODocument metadata = new ODocument();
metadata.field("ignoreNullValues", false);
clazz.createIndex("compositeIndexNullRangeQueryInMiddleTxIndex", OClass.INDEX_TYPE.NOTUNIQUE.toString(), null, metadata, null, new String[] { "prop1", "prop2", "prop3" });
database.begin();
for (int i = 0; i < 20; i++) {
ODocument document = new ODocument("compositeIndexNullRangeQueryInMiddleTxClass");
document.field("prop1", i / 10);
document.field("prop2", i / 5);
if (i % 2 == 0)
document.field("prop3", i);
document.save();
}
String query = "select from compositeIndexNullRangeQueryInMiddleTxClass where prop1 = 1 and prop2 > 2";
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 5);
for (int k = 0; k < 5; k++) {
ODocument document = result.get(k);
Assert.assertEquals(document.field("prop1"), 1);
Assert.assertTrue(document.<Integer>field("prop2") > 2);
}
ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("compositeIndexNullRangeQueryInMiddleTxIndex"));
query = "select from compositeIndexNullRangeQueryInMiddleTxClass where prop1 > 0";
result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 10);
for (int k = 0; k < 10; k++) {
ODocument document = result.get(k);
Assert.assertTrue(document.<Integer>field("prop1") > 0);
}
database.commit();
}
Aggregations