@Override public void cleanup() throws DBException { INIT_LOCK.lock(); try { clientCounter--; if (clientCounter == 0) { databasePool.close(); databasePool = null; initialized = false; } } finally { INIT_LOCK.unlock(); } }
@Override public Status delete(String table, String key) { while (true) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); dictionary.remove(key); return Status.OK; } catch (OConcurrentModificationException cme) { continue; } catch (Exception e) { e.printStackTrace(); return Status.ERROR; } } }
ODatabaseDocumentTx db = new ODatabaseDocumentTx(url); if (db.getStorage().isRemote()) { isRemote = true; if (!isRemote) { if (newdb) { if (db.exists()) { db.open(user, password); LOG.info("OrientDB drop and recreate fresh db"); db.drop(); db.create(); } else { if (!db.exists()) { LOG.info("OrientDB database not found, creating fresh db"); db.create(); server.createDatabase(db.getName(), ORIENTDB_DOCUMENT_TYPE, remoteStorageType); } else { if (!server.existsDatabase()) { if (db.isClosed()) { db.open(user, password); if (!db.getMetadata().getSchema().existsClass(CLASS)) { db.getMetadata().getSchema().createClass(CLASS);
public void startup() { startupIfEnginesAreMissing(); OPartitionedDatabasePool pool = new OPartitionedDatabasePoolFactory().get(type + ":" + name, "admin", "admin"); pool.setAutoCreate(true); db = pool.acquire(); ODatabaseRecordThreadLocal.instance().set(db); updateSchema(); }
try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final OIndexCursor entries = dictionary.getIndex().iterateEntriesMajor(startkey, true, true); final ODocument document = entries.next().getRecord();
private OStorage getStorage() { return ODatabaseRecordThreadLocal.instance().get().getDatabaseOwner().getStorage(); } }
public ORidBagDeleteSerializationOperation(OBonsaiCollectionPointer collectionPointer, OSBTreeRidBag ridBag) { this.collectionPointer = collectionPointer; this.ridBag = ridBag; collectionManager = ODatabaseRecordThreadLocal.instance().get().getSbTreeCollectionManager(); }
/** * Create a new database if not exists * * @param database database name * @param type can be plocal or memory * * @return true if the database has been created, false if already exists */ public boolean createIfNotExists(String database, ODatabaseType type) { return createIfNotExists(database, type, OrientDBConfig.defaultConfig()); }
private void onFunctionsChanged(ODatabaseDocumentInternal database) { for (OMetadataUpdateListener listener : database.getSharedContext().browseListeners()) { listener.onFunctionLibraryUpdate(database.getName()); } }
private void onSequenceLibraryUpdate(ODatabaseDocumentInternal database) { for (OMetadataUpdateListener one : database.getSharedContext().browseListeners()) { one.onSequenceLibraryUpdate(database.getName()); } }
/** * Returns the maximum size of the pool * */ public int getMaxSize() { setup(); return dbPool.getMaxSize(); }
@Override public long countClusterElements(int[] iClusterIds, boolean countTombstones) { checkOpenness(); return underlying.countClusterElements(iClusterIds, countTombstones); }
/** * {@inheritDoc} */ @Override public void truncateCluster(String clusterName) { checkOpenness(); underlying.truncateCluster(clusterName); }
public String getClusterNameById(final int iClusterId) { checkOpenness(); return underlying.getClusterNameById(iClusterId); }
public int addCluster(String iClusterName, int iRequestedId, Object... iParameters) { checkOpenness(); return underlying.addCluster(iClusterName, iRequestedId, iParameters); }
@Override public Status insert(String table, String key, Map<String, ByteIterator> values) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODocument document = new ODocument(CLASS); for (Map.Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { document.field(entry.getKey(), entry.getValue()); } document.save(); final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); dictionary.put(key, document); return Status.OK; } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; }
@Override public Status update(String table, String key, Map<String, ByteIterator> values) { while (true) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final ODocument document = dictionary.get(key); if (document != null) { for (Map.Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { document.field(entry.getKey(), entry.getValue()); } document.save(); return Status.OK; } } catch (OConcurrentModificationException cme) { continue; } catch (Exception e) { e.printStackTrace(); return Status.ERROR; } } }
@Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final ODocument document = dictionary.get(key); if (document != null) { if (fields != null) { for (String field : fields) { result.put(field, new StringByteIterator((String) document.field(field))); } } else { for (String field : document.fieldNames()) { result.put(field, new StringByteIterator((String) document.field(field))); } } return Status.OK; } } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; }