use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.
the class ORidBagTest method testFromEmbeddedToSBTreeAndBackTx.
public void testFromEmbeddedToSBTreeAndBackTx() throws IOException {
OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(7);
OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(-1);
if (database.getStorage() instanceof OStorageProxy) {
OServerAdmin server = new OServerAdmin(database.getURL()).connect("root", ODatabaseHelper.getServerRootPassword());
server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD, 7);
server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD, -1);
server.close();
}
ORidBag ridBag = new ORidBag();
ODocument document = new ODocument();
document.field("ridBag", ridBag);
Assert.assertTrue(ridBag.isEmbedded());
database.begin();
document.save();
database.commit();
document.reload();
ridBag = document.field("ridBag");
Assert.assertTrue(ridBag.isEmbedded());
List<OIdentifiable> addedItems = new ArrayList<OIdentifiable>();
database.begin();
for (int i = 0; i < 6; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
ridBag.add(docToAdd);
addedItems.add(docToAdd);
}
document.save();
database.commit();
document.reload();
ridBag = document.field("ridBag");
Assert.assertTrue(ridBag.isEmbedded());
ODocument docToAdd = new ODocument();
ridBag.add(docToAdd);
addedItems.add(docToAdd);
database.begin();
document.save();
database.commit();
Assert.assertTrue(!ridBag.isEmbedded());
List<OIdentifiable> addedItemsCopy = new ArrayList<OIdentifiable>(addedItems);
for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
Assert.assertTrue(addedItems.isEmpty());
document.reload();
ridBag = document.field("ridBag");
Assert.assertTrue(!ridBag.isEmbedded());
addedItems.addAll(addedItemsCopy);
for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
Assert.assertTrue(addedItems.isEmpty());
addedItems.addAll(addedItemsCopy);
for (int i = 0; i < 3; i++) ridBag.remove(addedItems.remove(i));
addedItemsCopy.clear();
addedItemsCopy.addAll(addedItems);
database.begin();
document.save();
database.commit();
Assert.assertTrue(!ridBag.isEmbedded());
for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
Assert.assertTrue(addedItems.isEmpty());
document.reload();
ridBag = document.field("ridBag");
Assert.assertTrue(!ridBag.isEmbedded());
addedItems.addAll(addedItemsCopy);
for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
Assert.assertTrue(addedItems.isEmpty());
}
use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.
the class OSBTreeRidBagTest method beforeMethod.
@BeforeMethod
public void beforeMethod() throws IOException {
topThreshold = OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger();
bottomThreshold = OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.getValueAsInteger();
if (database.getStorage() instanceof OStorageProxy) {
OServerAdmin server = new OServerAdmin(database.getURL()).connect("root", ODatabaseHelper.getServerRootPassword());
server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD, -1);
server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD, -1);
server.close();
}
OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1);
OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(-1);
}
use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.
the class RecordReloadTest method documentReloadLatestVersionLinkedValueTwo.
public void documentReloadLatestVersionLinkedValueTwo() throws Exception {
if (!(database.getStorage() instanceof OStorageProxy))
return;
ExecutorService executor = Executors.newSingleThreadExecutor();
final ODocument document = new ODocument();
document.field("value", "value one");
ODocument linkedValue = new ODocument();
linkedValue.field("val", "value 1");
document.field("link", linkedValue);
document.save();
final ORID rid = document.getIdentity();
final Future<?> future = executor.submit(new Runnable() {
@Override
public void run() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
db.open("admin", "admin");
ODocument doc = db.load(rid);
ODocument linkedValue = doc.field("link");
linkedValue.field("val", "value 2");
linkedValue.save();
db.close();
}
});
future.get();
document.reload("*:1", true, false);
linkedValue = document.field("link");
Assert.assertEquals(linkedValue.field("val"), "value 1");
}
use of com.orientechnologies.orient.core.storage.OStorageProxy 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.storage.OStorageProxy in project orientdb by orientechnologies.
the class OSchemaShared method doCreateClass.
private OClass doCreateClass(final String className, int[] clusterIds, int retry, OClass... superClasses) throws ClusterIdsAreEmptyException {
OClass result;
final ODatabaseDocumentInternal db = getDatabase();
final OStorage storage = db.getStorage();
StringBuilder cmd = null;
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_CREATE);
if (superClasses != null)
OClassImpl.checkParametersConflict(Arrays.asList(superClasses));
acquireSchemaWriteLock();
try {
final String key = className.toLowerCase();
if (classes.containsKey(key) && retry == 0)
throw new OSchemaException("Class '" + className + "' already exists in current database");
if (!executeThroughDistributedStorage())
checkClustersAreAbsent(clusterIds);
if (clusterIds == null || clusterIds.length == 0) {
clusterIds = createClusters(className, getDatabase().getStorage().getConfiguration().getMinimumClusters());
}
cmd = new StringBuilder("create class ");
if (getDatabase().getStorage().getConfiguration().isStrictSql())
cmd.append('`');
cmd.append(className);
if (getDatabase().getStorage().getConfiguration().isStrictSql())
cmd.append('`');
List<OClass> superClassesList = new ArrayList<OClass>();
if (superClasses != null && superClasses.length > 0) {
boolean first = true;
for (OClass superClass : superClasses) {
// Filtering for null
if (superClass != null) {
if (first)
cmd.append(" extends ");
else
cmd.append(", ");
cmd.append('`').append(superClass.getName()).append('`');
first = false;
superClassesList.add(superClass);
}
}
}
if (clusterIds != null) {
if (clusterIds.length == 1 && clusterIds[0] == -1)
cmd.append(" abstract");
else {
cmd.append(" cluster ");
for (int i = 0; i < clusterIds.length; ++i) {
if (i > 0)
cmd.append(',');
else
cmd.append(' ');
cmd.append(clusterIds[i]);
}
}
}
if (executeThroughDistributedStorage()) {
createClassInternal(className, clusterIds, superClassesList);
final OAutoshardedStorage autoshardedStorage = (OAutoshardedStorage) storage;
OCommandSQL commandSQL = new OCommandSQL(cmd.toString());
commandSQL.addExcludedNode(autoshardedStorage.getNodeId());
final Object res = db.command(commandSQL).execute();
} else if (storage instanceof OStorageProxy) {
db.command(new OCommandSQL(cmd.toString())).execute();
reload();
} else
createClassInternal(className, clusterIds, superClassesList);
result = classes.get(className.toLowerCase());
// WAKE UP DB LIFECYCLE LISTENER
for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners(); it.hasNext(); ) it.next().onCreateClass(getDatabase(), result);
} finally {
releaseSchemaWriteLock();
}
return result;
}
Aggregations