use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class SQLInsertTest method insertAvoidingSubQuery.
@Test
public void insertAvoidingSubQuery() {
final OSchema schema = database.getMetadata().getSchema();
if (schema.getClass("test") == null)
schema.createClass("test");
ODocument doc = (ODocument) database.command(new OCommandSQL("INSERT INTO test(text) VALUES ('(Hello World)')")).execute();
Assert.assertTrue(doc != null);
Assert.assertEquals(doc.field("text"), "(Hello World)");
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class SQLSelectHashIndexReuseTest method testReuseOfIndexOnSeveralClassesFields.
@Test
public void testReuseOfIndexOnSeveralClassesFields() {
final OSchema schema = database.getMetadata().getSchema();
final OClass superClass = schema.createClass("sqlSelectHashIndexReuseTestSuperClass");
superClass.createProperty("prop0", OType.INTEGER);
final OClass oClass = schema.createClass("sqlSelectHashIndexReuseTestChildClass", superClass);
oClass.createProperty("prop1", OType.INTEGER);
oClass.createIndex("sqlSelectHashIndexReuseTestOnPropertiesFromClassAndSuperclass", OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, "prop0", "prop1");
schema.save();
long oldIndexUsage = profiler.getCounter("db.demo.query.indexUsed");
long oldcompositeIndexUsed = profiler.getCounter("db.demo.query.compositeIndexUsed");
long oldcompositeIndexUsed2 = profiler.getCounter("db.demo.query.compositeIndexUsed.2");
final ODocument docOne = new ODocument("sqlSelectHashIndexReuseTestChildClass");
docOne.field("prop0", 0);
docOne.field("prop1", 1);
docOne.save();
final ODocument docTwo = new ODocument("sqlSelectHashIndexReuseTestChildClass");
docTwo.field("prop0", 2);
docTwo.field("prop1", 3);
docTwo.save();
final List<ODocument> result = database.command(new OSQLSynchQuery<ODocument>("select * from sqlSelectHashIndexReuseTestChildClass where prop0 = 0 and prop1 = 1")).execute();
Assert.assertEquals(result.size(), 1);
assertProfileCount(profiler.getCounter("db.demo.query.indexUsed"), oldIndexUsage, 1);
assertProfileCount(profiler.getCounter("db.demo.query.compositeIndexUsed"), oldcompositeIndexUsed, 1);
assertProfileCount(profiler.getCounter("db.demo.query.compositeIndexUsed.2"), oldcompositeIndexUsed2, 1);
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class MathTest method main.
public static final void main(String[] args) {
final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:test").create();
final OSchema schema = db.getMetadata().getSchema();
final OClass clazz = schema.createClass("test");
clazz.createProperty("numericAtt", OType.DOUBLE);
db.command(new OCommandSQL("INSERT INTO test(numericAtt) VALUES (28.23)")).execute();
final List<ODocument> docs = db.query(new OSQLSynchQuery("SELECT FROM test"));
Double value = (Double) docs.get(0).field("numericAtt");
System.out.println(value);
Assert.assertEquals(new Double(28.23), new Float(28.23).doubleValue());
Assert.assertEquals(new Float(28.23), new Double(28.23).floatValue());
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class IndexUniqueTest method indexUniqueTest.
public void indexUniqueTest() throws Exception {
String[] indexNames = new String[10];
Random random = new Random();
char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
for (int i = 0; i < indexNames.length; i++) {
String nm = "";
for (int k = 0; k < 10; k++) nm += chars[random.nextInt(chars.length)];
indexNames[i] = nm;
}
ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:./uniqueIndexTest");
final int cores = Runtime.getRuntime().availableProcessors();
if (db.exists()) {
db.open("admin", "admin");
db.drop();
}
for (int i = 0; i < propValues.length; i++) propValues[i] = new AtomicInteger();
db.create();
db.set(ODatabase.ATTRIBUTES.MINIMUMCLUSTERS, cores);
OSchema schema = db.getMetadata().getSchema();
OClass oClass = schema.createClass("indexTest");
for (int i = 0; i < 10; i++) {
oClass.createProperty("prop" + i, OType.INTEGER);
oClass.createIndex(indexNames[i], OClass.INDEX_TYPE.UNIQUE, "prop" + i);
}
ExecutorService executor = Executors.newCachedThreadPool();
List<Future<Integer>> futures = new ArrayList<Future<Integer>>();
for (int i = 0; i < cores; i++) {
phaser.register();
futures.add(executor.submit(new Populator("plocal:./uniqueIndexTest", random.nextBoolean())));
}
int sum = 0;
for (Future<Integer> future : futures) sum += future.get();
System.out.println("Total documents " + sum);
Assert.assertEquals(db.countClass("indexTest"), sum);
Set<Integer>[] props = new Set[10];
for (int i = 0; i < props.length; i++) {
props[i] = new HashSet<Integer>();
}
for (ODocument document : db.browseClass("indexTest")) {
for (int i = 0; i < 10; i++) {
Set<Integer> propValues = props[i];
Assert.assertTrue(propValues.add(document.<Integer>field("prop" + i)));
}
}
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class MultipleDBAlignmentOnNodesJoining method onAfterDatabaseCreation.
/**
* Event called right after the database has been created. It builds the schema and populates the db.
*
* @param db Current database
*/
protected void onAfterDatabaseCreation(final OrientBaseGraph db, String databaseURL) {
String databaseName = db.getRawGraph().getName();
System.out.println("Creating database schema for " + databaseName + "...");
ODatabaseRecordThreadLocal.INSTANCE.set(db.getRawGraph());
// building basic schema
OClass personClass = db.getRawGraph().getMetadata().getSchema().createClass("Person");
personClass.createProperty("id", OType.STRING);
personClass.createProperty("name", OType.STRING);
personClass.createProperty("birthday", OType.DATE);
personClass.createProperty("children", OType.STRING);
final OSchema schema = db.getRawGraph().getMetadata().getSchema();
OClass person = schema.getClass("Person");
idx = person.createIndex("Person.name", OClass.INDEX_TYPE.UNIQUE, "name");
// populating db
try {
ExecutorService executor = Executors.newSingleThreadExecutor();
Callable writer = createWriter(databaseName, databaseURL);
Future f = executor.submit(writer);
f.get();
assertTrue(f.isDone());
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations