private OClass getLinkInfo(final ODatabaseInternal<?> iDatabase, final String iFieldClassName) { if (iDatabase == null || iDatabase.isClosed() || iFieldClassName == null) return null; OClass linkedClass = ((OMetadataInternal) iDatabase.getMetadata()).getImmutableSchemaSnapshot().getClass(iFieldClassName); return linkedClass; }
public OStorage getStorage() { return underlying.getStorage(); }
/** * Utility method to obtain {@link ODatabaseDocument} from {@link ODatabase} * @param db {@link ODatabase} to cast from * @return {@link ODatabaseDocument} for a specified {@link ODatabase} */ public static ODatabaseDocument castToODatabaseDocument(ODatabase<?> db) { while(db!=null && !(db instanceof ODatabaseDocument)) { if(db instanceof ODatabaseInternal<?>) { db = ((ODatabaseInternal<?>)db).getUnderlying(); } } return (ODatabaseDocument)db; } }
/** * returns the cluster map for current deploy. The keys of the map are node names, the values contain names of clusters (data * files) available on the single node. * * @return the cluster map for current deploy */ default Map<String, Set<String>> getActiveClusterMap() { Map<String, Set<String>> result = new HashMap<>(); result.put(getLocalNodeName(), getStorage().getClusterNames()); return result; }
protected OClass superClass(ODatabaseInternal db) { return db.getMetadata().getSchema().getClass(BASE_CLASS); }
clusterId = id.getValue().intValue(); } else { clusterId = database.getStorage().getClusterIdByName(name.getStringValue()); if (clusterId < 0) { if (ifExists) { for (OClass iClass : database.getMetadata().getSchema().getClasses()) { for (int i : iClass.getClusterIds()) { if (i == clusterId) { String clusterName = database.getClusterNameById(clusterId); if (clusterName == null) { if (ifExists) { ((OMetadataInternal) database.getMetadata()).getCommandCache().invalidateResultsOfCluster(clusterName); database.dropCluster(clusterId, true);
@Override public void onOpen(final ODatabaseInternal db) { unregisterLiveQueryHook(db); if (OSecurityNull.class.equals(db.getProperty(ODatabase.OPTIONS.SECURITY.toString()))) { return; // ignore maintenance operations which run without security, such as index repair } if (!startRecording(db)) { pendingDbs.add(db); } // reload metadata when (re-)opening a DB connection if old schema is gone // (can be removed after upgrading to OrientDB 2.2.33 as it does it for us) if (db.getMetadata().getSchema().countClasses() == 0) { log.debug("Reloading metadata for {} as storage has changed", db.getName()); db.getMetadata().reload(); } }
public void begin(final ODatabaseDocumentInternal iDatabase) { if (disableSecurity) { currentUser = iDatabase.getDatabaseOwner().getUser(); iDatabase.getDatabaseOwner().setUser(null); ownerDb.getLocalCache().setEnable(enableCache); while (ownerDb.getDatabaseOwner() != ownerDb) ownerDb = ownerDb.getDatabaseOwner(); ownerDb.getHooks()); for (Map.Entry<ORecordHook, ORecordHook.HOOK_POSITION> hook : hooks.entrySet()) { if (!(hook.getKey() instanceof OClassIndexManager)) { removedHooks.put(hook.getKey(), hook.getValue()); ownerDb.unregisterHook(hook.getKey());
public boolean reuseResource(final String iKey, final Object[] iAdditionalArgs, final DB iValue) { if (((ODatabasePooled) iValue).isUnderlyingOpen()) { ((ODatabasePooled) iValue).reuse(owner, iAdditionalArgs); if (iValue.getStorage().isClosed()) // STORAGE HAS BEEN CLOSED: REOPEN IT iValue.getStorage().open((String) iAdditionalArgs[0], (String) iAdditionalArgs[1], null); else if (!iValue.getUser().checkPassword((String) iAdditionalArgs[1])) throw new OSecurityAccessException(iValue.getName(), "User or password not valid for database: '" + iValue.getName() + "'"); return true; } return false; } };
public void remove(final String iPoolName) { lock(); try { final OReentrantResourcePool<String, DB> pool = pools.remove(iPoolName); if (pool != null) { for (DB db : pool.getResources()) { final OStorage stg = db.getStorage(); if (stg != null && stg.getStatus() == OStorage.STATUS.OPEN) try { OLogManager.instance().debug(this, "Closing pooled database '%s'...", db.getName()); db.activateOnCurrentThread(); ((ODatabasePooled) db).forceClose(); OLogManager.instance().debug(this, "OK", db.getName()); } catch (Exception e) { OLogManager.instance().debug(this, "Error: %d", e.toString()); } } pool.close(); } } finally { unlock(); } }
public void end(final ODatabaseDocumentInternal iDatabase) { ODatabaseInternal<?> ownerDb = iDatabase.getDatabaseOwner(); if (disableSecurity) if (currentUser != null) // RE-ENABLE CHECK OF SECURITY ownerDb.setUser(currentUser); if (!enableCache) { ownerDb.getLocalCache().setEnable(!enableCache); } if (ownerDb instanceof ODatabaseDocument) { ((ODatabaseDocument) ownerDb).setRetainRecords(previousRetainRecords); if (disableValidation && !iDatabase.getStorage().isRemote()) ((ODatabaseDocument) ownerDb).setValidationEnabled(previousValidation); } while (ownerDb.getDatabaseOwner() != ownerDb) ownerDb = ownerDb.getDatabaseOwner(); if (disableHooks) if (removedHooks != null) { // RESTORE ALL REMOVED HOOKS for (Map.Entry<ORecordHook, ORecordHook.HOOK_POSITION> hook : removedHooks.entrySet()) { ownerDb.registerHook(hook.getKey(), hook.getValue()); } } }
public void release(final DB iDatabase) { // REMOVE ANY INTENT BEFORE. THIS RESTORE ANYTHING BEFORE THE CLOSE, LIKE THE USER NAME IN CASE OF MASSIVE INSERT iDatabase.declareIntent(null); final String dbPooledName = iDatabase.getUser().getName() + "@" + iDatabase.getURL(); final OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); } finally { unlock(); } if (pool == null) throw new OLockException("Cannot release a database URL not acquired before. URL: " + iDatabase.getName()); if (pool.returnResource(iDatabase)) this.notifyEvictor(dbPooledName, iDatabase); }
public void registerHooks(ODatabaseInternal iDatabase) { Set<ORecordHook> hooks = iDatabase.getHooks().keySet(); List<Class<? extends ORecordHook>> hooksToRegister = new ArrayList<Class<? extends ORecordHook>>(getOrientDbSettings().getORecordHooks()); for(ORecordHook hook : hooks) { if(hooksToRegister.contains(hook.getClass())) hooksToRegister.remove(hook.getClass()); } for (Class<? extends ORecordHook> oRecordHookClass : hooksToRegister) { ORecordHook hook = createHook(oRecordHookClass, iDatabase); if(hook!=null){ if (hook instanceof IHookPosition){ iDatabase.registerHook(hook,((IHookPosition) hook).getPosition()); }else{ iDatabase.registerHook(hook); } } } }
targetClusterNames.add(c.getClusterName()); } else { String clusterName = db.getClusterNameById(c.getClusterNumber()); if (clusterName == null) { throw new OCommandExecutionException("Cluster not found: " + c.getClusterNumber()); OSchema schema = db.getMetadata().getSchema(); for (OIdentifier className : this.classes) { OClass clazz = schema.getClass(className.getStringValue()); targetClusterNames.add(db.getClusterNameById(clusterId)); clusterName -> new ORecordIteratorCluster((ODatabaseDocumentInternal) db, db.getClusterIdByName(clusterName))).collect(Collectors.toList()); this.clusterIterators = iterators.iterator();
public void checkPersistentPropertyType(final ODatabaseInternal<ORecord> database, final String propertyName, final OType type) { if (OType.ANY.equals(type)) { return; } final boolean strictSQL = database.getStorage().getConfiguration().isStrictSql(); final StringBuilder builder = new StringBuilder(256); builder.append("select count(*) as count from "); builder.append(getEscapedName(name, strictSQL)); builder.append(" where "); builder.append(getEscapedName(propertyName, strictSQL)); builder.append(".type() not in ["); final Iterator<OType> cur = type.getCastable().iterator(); while (cur.hasNext()) { builder.append('"').append(cur.next().name()).append('"'); if (cur.hasNext()) builder.append(","); } builder.append("] and ").append(getEscapedName(propertyName, strictSQL)).append(" is not null "); if (type.isMultiValue()) builder.append(" and ").append(getEscapedName(propertyName, strictSQL)).append(".size() <> 0 limit 1"); try (final OResultSet res = database.command(builder.toString())) { if (((Long) res.next().getProperty("count")) > 0) throw new OSchemaException("The database contains some schema-less data in the property '" + name + "." + propertyName + "' that is not compatible with the type " + type + ". Fix those records and change the schema again"); } }
public <THISDB extends ODatabase> THISDB open(final String iUserName, final String iUserPassword) { underlying.open(iUserName, iUserPassword); return (THISDB) this; }
public String getName() { return underlying.getName(); }
public void drop() { underlying.drop(); }
public boolean isClosed() { return underlying.isClosed(); }