/** * Returns a copy of current database if it's open. The returned instance can be used by another thread without affecting current * instance. The database copy is not set in thread local. */ public ODatabaseDocumentInternal copy() { ODatabaseDocumentEmbedded database = new ODatabaseDocumentEmbedded(storage); database.init(config); String user; if (getUser() != null) { user = getUser().getName(); } else { user = null; } database.internalOpen(user, null, false); database.callOnOpenListeners(); this.activateOnCurrentThread(); return database; }
@Override protected void doRollback() throws TransactionException { tx().doRollback(); ODatabaseDocumentEmbedded db = (ODatabaseDocumentEmbedded) g.graph().getRawDatabase(); db.internalClose(true); db.activateOnCurrentThread(); db.setStatus(ODatabase.STATUS.OPEN); }
@Override public int addBlobCluster(final String iClusterName, final Object... iParameters) { int id; if (!existsCluster(iClusterName)) { id = addCluster(iClusterName, iParameters); } else { id = getClusterIdByName(iClusterName); } getMetadata().getSchema().addBlobCluster(id); return id; }
@Override public OLiveQueryMonitor live(String query, OLiveQueryResultListener listener, Map<String, ?> args) { checkOpenness(); checkIfActive(); OLiveQueryListenerV2 queryListener = new LiveQueryListenerImpl(listener, query, this, (Map) args); ODatabaseDocumentInternal dbCopy = this.copy(); this.activateOnCurrentThread(); OLiveQueryMonitor monitor = new OLiveQueryMonitorEmbedded(queryListener.getToken(), dbCopy); return monitor; }
public void init(OrientDBConfig config) { activateOnCurrentThread(); this.config = config; applyAttributes(config); applyListeners(config); try { String serializeName = getStorage().getConfiguration().getRecordSerializer(); if (serializeName == null) throw new ODatabaseException("Impossible to open database from version before 2.x use export import instead"); if (serializer == null) throw new ODatabaseException("RecordSerializer with name '" + serializeName + "' not found "); if (getStorage().getConfiguration().getRecordSerializerVersion() > serializer.getMinSupportedVersion()) throw new ODatabaseException("Persistent record serializer version is not support by the current implementation"); loadMetadata(); installHooksEmbedded(); if (this.getMetadata().getCommandCache().isEnabled()) registerHook(new OCommandCacheHook(this), ORecordHook.HOOK_POSITION.REGULAR); } catch (Exception e) { ODatabaseRecordThreadLocal.instance().remove(); throw OException.wrapException(new ODatabaseException("Cannot open database url=" + getURL()), e);
@Override public <DB extends ODatabase> DB set(final ATTRIBUTES iAttribute, final Object iValue) { checkIfActive(); final OStorage storage = getStorage(); switch (iAttribute) { case STATUS: if (stringValue == null) throw new IllegalArgumentException("DB status can't be null"); setStatus(STATUS.valueOf(stringValue.toUpperCase(Locale.ENGLISH))); break; if (indx < 0) { if ("clear".equalsIgnoreCase(stringValue)) { clearCustomInternal(); } else throw new IllegalArgumentException("Syntax error: expected <name> = <value> or clear, instead found: " + iValue); String customValue = stringValue.substring(indx + 1).trim(); if (customValue.isEmpty()) removeCustomInternal(customName); else setCustomInternal(customName, customValue);
/** * {@inheritDoc} */ public void internalCreate(OrientDBConfig config) { this.status = STATUS.OPEN; // THIS IF SHOULDN'T BE NEEDED, CREATE HAPPEN ONLY IN EMBEDDED applyAttributes(config); applyListeners(config); metadata = new OMetadataDefault(this); installHooksEmbedded(); createMetadata(); if (this.getMetadata().getCommandCache().isEnabled()) registerHook(new OCommandCacheHook(this), ORecordHook.HOOK_POSITION.REGULAR); }
public ODatabaseDocumentInternal poolOpen(String name, String user, String password, ODatabasePoolInternal pool) { final ODatabaseDocumentEmbedded embedded; synchronized (this) { checkOpen(); OAbstractPaginatedStorage storage = getOrInitStorage(name); storage.open(pool.getConfig().getConfigurations()); embedded = factory.newPoolInstance(pool, storage); embedded.init(pool.getConfig()); } embedded.rebuildIndexes(); embedded.internalOpen(user, password); embedded.callOnOpenListeners(); return embedded; }
@Override public void run() { try { final ODatabaseDocumentEmbedded newDb = new ODatabaseDocumentEmbedded(storage); newDb.activateOnCurrentThread(); newDb.init(null); newDb.internalOpen("admin", "nopass", false); abstractPaginatedStorage.synch(); newDb.close();
/** * This method is internal, it can be subject to signature change or be removed, do not use. * * @Internal */ public <RET extends ORecord> RET executeSaveRecord(final ORecord record, String clusterName, final int ver, final OPERATION_MODE mode, boolean forceCreate, final ORecordCallback<? extends Number> recordCreatedCallback, ORecordCallback<Integer> recordUpdatedCallback) { checkOpenness(); checkIfActive(); if (!record.isDirty()) return (RET) record; final ORecordId rid = (ORecordId) record.getIdentity(); if (rid == null) throw new ODatabaseException( "Cannot create record because it has no identity. Probably is not a regular record or contains projections of fields rather than a full record"); final OMicroTransaction microTx = beginMicroTransaction(); try { microTx.saveRecord(record, clusterName, mode, forceCreate, recordCreatedCallback, recordUpdatedCallback); } catch (Exception e) { endMicroTransaction(false); throw e; } endMicroTransaction(true); return (RET) record; }
public ODatabaseDocumentEmbedded openNoAuthorization(String name) { try { final ODatabaseDocumentEmbedded embedded; OrientDBConfig config = solveConfig(null); synchronized (this) { OAbstractPaginatedStorage storage = getOrInitStorage(name); // THIS OPEN THE STORAGE ONLY THE FIRST TIME storage.open(config.getConfigurations()); embedded = factory.newInstance(storage); embedded.init(config); } embedded.rebuildIndexes(); embedded.callOnOpenListeners(); return embedded; } catch (Exception e) { throw OException.wrapException(new ODatabaseException("Cannot open database '" + name + "'"), e); } }
public ODatabaseDocumentEmbedded(final OStorage storage) { activateOnCurrentThread(); try { status = STATUS.CLOSED; // OVERWRITE THE URL url = storage.getURL(); this.storage = storage; this.componentsFactory = storage.getComponentsFactory(); unmodifiableHooks = Collections.unmodifiableMap(hooks); localCache = new OLocalRecordCache(); init(); databaseOwner = this; } catch (Exception t) { ODatabaseRecordThreadLocal.instance().remove(); throw OException.wrapException(new ODatabaseException("Error on opening database "), t); } }
public void callOnCreateListeners() { // WAKE UP DB LIFECYCLE LISTENER for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners(); it.hasNext(); ) it.next().onCreate(getDatabaseOwner()); // WAKE UP LISTENERS for (ODatabaseListener listener : browseListeners()) try { listener.onCreate(this); } catch (Exception ignore) { } }
public synchronized void initCustomStorage(String name, String path, String userName, String userPassword) { ODatabaseDocumentEmbedded embedded = null; synchronized (this) { boolean exists = OLocalPaginatedStorage.exists(Paths.get(path)); OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) disk.createStorage(path, new HashMap<>(), maxWALSegmentSize); // TODO: Add Creation settings and parameters if (!exists) { embedded = internalCreate(getConfigurations(), storage); } storages.put(name, storage); } if (embedded != null) { embedded.callOnCreateListeners(); ODatabaseRecordThreadLocal.instance().remove(); } }
@Override public ODatabaseDocumentEmbedded newInstance(OStorage storage) { return new ODatabaseDocumentEmbedded(storage); }
@Override public OLiveQueryMonitor live(String query, OLiveQueryResultListener listener, Object... args) { checkOpenness(); checkIfActive(); OLiveQueryListenerV2 queryListener = new LiveQueryListenerImpl(listener, query, this, args); ODatabaseDocumentInternal dbCopy = this.copy(); this.activateOnCurrentThread(); OLiveQueryMonitor monitor = new OLiveQueryMonitorEmbedded(queryListener.getToken(), dbCopy); return monitor; }
public ODatabaseDocumentEmbedded openNoAuthenticate(String name, String user) { try { final ODatabaseDocumentEmbedded embedded; OrientDBConfig config = solveConfig(null); synchronized (this) { OAbstractPaginatedStorage storage = getOrInitStorage(name); // THIS OPEN THE STORAGE ONLY THE FIRST TIME storage.open(config.getConfigurations()); embedded = factory.newInstance(storage); embedded.init(config); } embedded.rebuildIndexes(); embedded.internalOpen(user, "nopwd", false); embedded.callOnOpenListeners(); return embedded; } catch (Exception e) { throw OException.wrapException(new ODatabaseException("Cannot open database '" + name + "'"), e); } }
/** * This method is internal, it can be subject to signature change or be removed, do not use. * * @Internal */ public void executeDeleteRecord(OIdentifiable record, final int iVersion, final boolean iRequired, final OPERATION_MODE iMode, boolean prohibitTombstones) { checkOpenness(); checkIfActive(); final ORecordId rid = (ORecordId) record.getIdentity(); if (rid == null) throw new ODatabaseException( "Cannot delete record because it has no identity. Probably was created from scratch or contains projections of fields rather than a full record"); if (!rid.isValid()) return; record = record.getRecord(); if (record == null) return; final OMicroTransaction microTx = beginMicroTransaction(); try { microTx.deleteRecord(record.getRecord(), iMode); } catch (Exception e) { endMicroTransaction(false); throw e; } endMicroTransaction(true); return; }
public void restore(String name, String user, String password, ODatabaseType type, String path, OrientDBConfig config) { final ODatabaseDocumentEmbedded embedded; OAbstractPaginatedStorage storage; synchronized (this) { if (!exists(name, null, null)) { try { storage = (OAbstractPaginatedStorage) disk.createStorage(buildName(name), new HashMap<>(), maxWALSegmentSize); embedded = internalCreate(config, storage); storages.put(name, storage); } catch (Exception e) { throw OException.wrapException(new ODatabaseException("Cannot restore database '" + name + "'"), e); } } else throw new ODatabaseException("Cannot create new storage '" + name + "' because it already exists"); } storage.restoreFromIncrementalBackup(path); embedded.callOnCreateListeners(); ODatabaseRecordThreadLocal.instance().remove(); }
@Override protected void doCommit() throws TransactionException { tx().doCommit(); ODatabaseDocumentEmbedded db = (ODatabaseDocumentEmbedded) g.graph().getRawDatabase(); db.internalClose(true); db.activateOnCurrentThread(); db.setStatus(ODatabase.STATUS.OPEN); }