use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.
the class OMetadataDefault method init.
private void init(final boolean iLoad) {
final ODatabaseDocumentInternal database = getDatabase();
schemaClusterId = database.getClusterIdByName(CLUSTER_INTERNAL_NAME);
final AtomicBoolean schemaLoaded = new AtomicBoolean(false);
schema = new OSchemaProxy(database.getStorage().getResource(OSchema.class.getSimpleName(), new Callable<OSchemaShared>() {
public OSchemaShared call() {
ODatabaseDocumentInternal database = getDatabase();
final OSchemaShared instance = new OSchemaShared(database.getStorageVersions().classesAreDetectedByClusterId());
if (iLoad)
instance.load();
schemaLoaded.set(true);
return instance;
}
}), database);
indexManager = new OIndexManagerProxy(database.getStorage().getResource(OIndexManager.class.getSimpleName(), new Callable<OIndexManager>() {
public OIndexManager call() {
OIndexManager instance;
if (database.getStorage() instanceof OStorageProxy)
instance = new OIndexManagerRemote(database);
else
instance = new OIndexManagerShared(database);
if (iLoad)
try {
instance.load();
} catch (Exception e) {
OLogManager.instance().error(this, "[OMetadata] Error on loading index manager, reset index configuration", e);
instance.create();
}
return instance;
}
}), database);
security = new OSecurityProxy(database.getStorage().getResource(OSecurity.class.getSimpleName(), new Callable<OSecurity>() {
public OSecurity call() {
final OSecurity instance = OSecurityManager.instance().newSecurity();
if (iLoad) {
security = instance;
instance.load();
}
return instance;
}
}), database);
commandCache = database.getStorage().getResource(OCommandCache.class.getSimpleName(), new Callable<OCommandCache>() {
public OCommandCache call() {
return new OCommandCacheSoftRefs(database.getName());
}
});
final Class<? extends OSecurity> securityClass = (Class<? extends OSecurity>) database.getProperty(ODatabase.OPTIONS.SECURITY.toString());
if (securityClass != null)
// INSTALL CUSTOM WRAPPED SECURITY
try {
final OSecurity wrapped = security;
security = securityClass.getDeclaredConstructor(OSecurity.class, ODatabaseDocumentInternal.class).newInstance(wrapped, database);
} catch (Exception e) {
throw OException.wrapException(new OSecurityException("Cannot install custom security implementation (" + securityClass + ")"), e);
}
functionLibrary = new OFunctionLibraryProxy(database.getStorage().getResource(OFunctionLibrary.class.getSimpleName(), new Callable<OFunctionLibrary>() {
public OFunctionLibrary call() {
final OFunctionLibraryImpl instance = new OFunctionLibraryImpl();
if (iLoad && !(database.getStorage() instanceof OStorageProxy))
instance.load();
return instance;
}
}), database);
sequenceLibrary = new OSequenceLibraryProxy(database.getStorage().getResource(OSequenceLibrary.class.getSimpleName(), new Callable<OSequenceLibrary>() {
@Override
public OSequenceLibrary call() throws Exception {
final OSequenceLibraryImpl instance = new OSequenceLibraryImpl();
if (iLoad) {
instance.load();
}
return instance;
}
}), database);
scheduler = new OSchedulerProxy(database.getStorage().getResource(OScheduler.class.getSimpleName(), new Callable<OScheduler>() {
public OScheduler call() {
final OSchedulerImpl instance = new OSchedulerImpl();
if (iLoad && !(database.getStorage() instanceof OStorageProxy))
instance.load();
return instance;
}
}), database);
if (schemaLoaded.get())
schema.onPostIndexManagement();
}
use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.
the class ODatabaseDocumentTxTest method testDocFromJsonEmbedded.
@Test
public void testDocFromJsonEmbedded() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory: testDocFromJsonEmbedded_" + ODatabaseDocumentTxTest.class.getSimpleName());
db.create();
try {
OSchemaProxy schema = db.getMetadata().getSchema();
OClass c0 = schema.createClass("Class0");
OClass c1 = schema.createClass("Class1");
c1.createProperty("account", OType.STRING);
c1.createProperty("meta", OType.EMBEDDED, c0);
ODocument doc = new ODocument("Class1");
doc.fromJSON("{\n" + " \"account\": \"#25:0\",\n" + " " + "\"meta\": {" + " \"created\": \"2016-10-03T21:10:21.77-07:00\",\n" + " \"ip\": \"0:0:0:0:0:0:0:1\",\n" + " \"contentType\": \"application/x-www-form-urlencoded\"," + " \"userAgent\": \"PostmanRuntime/2.5.2\"" + "}," + "\"data\": \"firstName=Jessica&lastName=Smith\"\n" + "}");
db.save(doc);
List<ODocument> result = db.query(new OSQLSynchQuery<Object>("select from Class0"));
Assert.assertEquals(result.size(), 0);
result = db.query(new OSQLSynchQuery<Object>("select from Class1"));
Assert.assertEquals(result.size(), 1);
ODocument item = result.get(0);
ODocument meta = item.field("meta");
Assert.assertEquals(meta.getClassName(), "Class0");
Assert.assertEquals(meta.field("ip"), "0:0:0:0:0:0:0:1");
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropPropertyTest method test.
@Test
public void test() {
OSchemaProxy schema = db.getMetadata().getSchema();
OClass foo = schema.createClass("Foo");
foo.createProperty("name", OType.STRING);
Assert.assertTrue(schema.getClass("Foo").existsProperty("name"));
db.command(new OCommandSQL("DROP PROPERTY Foo.name")).execute();
schema.reload();
Assert.assertFalse(schema.getClass("Foo").existsProperty("name"));
foo.createProperty("name", OType.STRING);
Assert.assertTrue(schema.getClass("Foo").existsProperty("name"));
db.command(new OCommandSQL("DROP PROPERTY `Foo`.name")).execute();
schema.reload();
Assert.assertFalse(schema.getClass("Foo").existsProperty("name"));
foo.createProperty("name", OType.STRING);
Assert.assertTrue(schema.getClass("Foo").existsProperty("name"));
db.command(new OCommandSQL("DROP PROPERTY Foo.`name`")).execute();
schema.reload();
Assert.assertFalse(schema.getClass("Foo").existsProperty("name"));
foo.createProperty("name", OType.STRING);
Assert.assertTrue(schema.getClass("Foo").existsProperty("name"));
db.command(new OCommandSQL("DROP PROPERTY `Foo`.`name`")).execute();
schema.reload();
Assert.assertFalse(schema.getClass("Foo").existsProperty("name"));
}
use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropPropertyTest method testIfExists.
@Test
public void testIfExists() {
OSchemaProxy schema = db.getMetadata().getSchema();
OClass testIfExistsClass = schema.createClass("testIfExists");
testIfExistsClass.createProperty("name", OType.STRING);
Assert.assertTrue(schema.getClass("testIfExists").existsProperty("name"));
db.command(new OCommandSQL("DROP PROPERTY testIfExists.name if exists")).execute();
schema.reload();
Assert.assertFalse(schema.getClass("testIfExists").existsProperty("name"));
db.command(new OCommandSQL("DROP PROPERTY testIfExists.name if exists")).execute();
schema.reload();
Assert.assertFalse(schema.getClass("testIfExists").existsProperty("name"));
}
use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testBigEntryPoint.
@Test
public void testBigEntryPoint() {
//issue #6890
OSchemaProxy schema = db.getMetadata().getSchema();
schema.createClass("testBigEntryPoint1");
schema.createClass("testBigEntryPoint2");
for (int i = 0; i < 1000; i++) {
ODocument doc = db.newInstance("testBigEntryPoint1");
doc.field("a", i);
doc.save();
}
ODocument doc = db.newInstance("testBigEntryPoint2");
doc.field("b", "b");
doc.save();
List<ODocument> qResult = db.command(new OCommandSQL("MATCH {class: testBigEntryPoint1, as: a}, {class: testBigEntryPoint2, as: b} return $elements limit 1")).execute();
assertEquals(1, qResult.size());
}
Aggregations