public static String getDateTimeFormat() { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null && !db.isClosed()) return db.getStorage().getConfiguration().getDateTimeFormat(); else return DEF_DATETIME_FORMAT; }
public static ODatabaseDocumentInternal getGraphDatabase(final ODatabaseDocumentInternal iCurrentDatabase) { ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.instance().get(); if (currentDb == null && iCurrentDatabase != null) // GET FROM THE RECORD currentDb = iCurrentDatabase; if (currentDb != null) currentDb = (ODatabaseDocumentInternal) currentDb.getDatabaseOwner(); return currentDb; }
@Override protected Boolean execute(ODatabaseDocument db) { document.save(); if (document.getDatabase().getTransaction().isActive()){ document.getDatabase().commit(); } return true; } }.execute();
static void runWithDatabase(final ODatabaseDocumentInternal database, final Runnable runnable) { if (!database.isActiveOnCurrentThread()) database.activateOnCurrentThread(); try { runnable.run(); } finally { ODatabaseRecordThreadLocal.INSTANCE.remove(); } }
public void clearCustom() { final ODatabaseDocumentInternal database = getDatabase(); database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE); acquireSchemaWriteLock(); try { final OStorage storage = database.getStorage(); if (isDistributedCommand(database)) { final String cmd = String.format("alter class `%s` custom clear", getName()); final OCommandSQL commandSQL = new OCommandSQL(cmd); commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId()); database.command(commandSQL).execute(); clearCustomInternal(); } else clearCustomInternal(); } finally { releaseSchemaWriteLock(); } }
private void distributedDropIndex(final String iName) { String dropIndexDDL = "DROP INDEX `" + iName + "`"; //noinspection deprecation getDatabase().command(new OCommandSQL(dropIndexDDL)).execute(); ORecordInternal .setIdentity(delegate.getDocument(), new ORecordId(getDatabase().getStorage().getConfiguration().getIndexMgrRecordId())); reload(); }
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db == null) { return null; OSchema schema = db.getMetadata().getSchema(); OClass clazz = schema.getClass(className); if (clazz != null) { Collection<OClass> subClasses = clazz.getAllSubclasses(); for (OClass subClass : subClasses) { allClassNames.add(subClass.getName());
private boolean isVertex(final OIdentifiable iObject) { final ORecord rec = iObject.getRecord(); if (rec == null || !(rec instanceof ODocument)) return false; final ODocument value = (ODocument) rec; final OIdentifiable v; OClass klass = ODocumentInternal.getImmutableSchemaClass(value); if (klass == null && ODatabaseRecordThreadLocal.instance().getIfDefined() != null) { ODatabaseRecordThreadLocal.instance().getIfDefined().getMetadata().reload(); klass = value.getSchemaClass(); } if (klass.isVertexType()) { // DIRECT VERTEX return true; } else if (klass.isEdgeType()) { return false; } throw new IllegalStateException("Invalid content found between connections: " + value); } }
public void create(ODatabaseDocumentInternal database) { if (database.getMetadata().getSchema().existsClass(OScheduledEvent.CLASS_NAME)) return; final OClass f = database.getMetadata().getSchema().createClass(OScheduledEvent.CLASS_NAME); f.createProperty(OScheduledEvent.PROP_NAME, OType.STRING, (OType) null, true).setMandatory(true).setNotNull(true); f.createProperty(OScheduledEvent.PROP_RULE, OType.STRING, (OType) null, true).setMandatory(true).setNotNull(true); f.createProperty(OScheduledEvent.PROP_ARGUMENTS, OType.EMBEDDEDMAP, (OType) null, true); f.createProperty(OScheduledEvent.PROP_STATUS, OType.STRING, (OType) null, true); f.createProperty(OScheduledEvent.PROP_FUNC, OType.LINK, database.getMetadata().getSchema().getClass(OFunction.CLASS_NAME), true) .setMandatory(true).setNotNull(true); f.createProperty(OScheduledEvent.PROP_STARTTIME, OType.DATETIME, (OType) null, true); }
public Directory createDirectory(ODatabaseDocumentInternal database, String indexName, ODocument metadata) { String luceneType = metadata.containsField(DIRECTORY_TYPE) ? metadata.<String>field(DIRECTORY_TYPE) : DIRECTORY_MMAP; if (database.getStorage().getType().equals("memory") || DIRECTORY_RAM.equals(luceneType)) { return new RAMDirectory(); } return createDirectory(database, indexName, metadata, luceneType); }
public OSchemaShared load(ODatabaseDocumentInternal database) { rwSpinLock.acquireWriteLock(); try { if (!new ORecordId(database.getStorage().getConfiguration().getSchemaRecordId()).isValid()) throw new OSchemaNotCreatedException("Schema is not created and cannot be loaded"); ((ORecordId) document.getIdentity()).fromString(database.getStorage().getConfiguration().getSchemaRecordId()); reload("*:-1 index:0"); return this; } finally { rwSpinLock.releaseWriteLock(); } }
public String getClusterName(final ORecord record) { if (ODatabaseRecordThreadLocal.instance().get().getStorage().isRemote()) // DON'T ASSIGN CLUSTER WITH REMOTE: SERVER KNOWS THE RIGHT CLUSTER BASED ON LOCALITY return null; int clusterId = record.getIdentity().getClusterId(); if (clusterId == ORID.CLUSTER_ID_INVALID) { // COMPUTE THE CLUSTER ID OClass schemaClass = null; if (record instanceof ODocument) schemaClass = ODocumentInternal.getImmutableSchemaClass(getDatabase(), (ODocument) record); if (schemaClass != null) { // FIND THE RIGHT CLUSTER AS CONFIGURED IN CLASS if (schemaClass.isAbstract()) throw new OSchemaException("Document belongs to abstract class '" + schemaClass.getName() + "' and cannot be saved"); clusterId = schemaClass.getClusterForNewInstance((ODocument) record); return database.getClusterNameById(clusterId); } else { return database.getClusterNameById(database.getStorage().getDefaultClusterId()); } } else { return database.getClusterNameById(clusterId); } }
@Override public <RET> RET execute(Object... iArgs) { ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.instance().get(); if (database.getStorage().isRemote()) { BackwardOLiveQueryResultListener listener = new BackwardOLiveQueryResultListener(); OLiveQueryMonitor monitor = database.live(getText(), listener, iArgs); listener.token = (int) monitor.getMonitorId(); ODocument doc = new ODocument(); doc.setProperty("token", listener.token); OLegacyResultSet<ODocument> result = new OBasicLegacyResultSet<>(); result.add(doc); return (RET) result; } return super.execute(iArgs); }
@Override protected OIndex<?> createInstance(OIndex proxy) { OSchema schema = OrientDbWebSession.get().getDatabase().getMetadata().getSchema(); OClass oClass = schema.getClass(proxy.getDefinition().getClassName()); String name = proxy.getName(); List<String> fields = proxy.getDefinition().getFields(); String type = proxy.getType(); if(name==null) name=oClass.getName()+"."+fields.get(0); ODocument metadata = proxy.getMetadata(); String algorithm = proxy.getAlgorithm(); values.keySet().retainAll(RW_ATTRS); return oClass.createIndex(name, type, null, metadata, algorithm, fields.toArray(new String[0])); }
@Override protected OProperty createInstance(OProperty proxy) { OSchema schema = OrientDbWebSession.get().getDatabase().getMetadata().getSchema(); OClass oClass = schema.getClass(className); return oClass.createProperty(proxy.getName(), proxy.getType()); }
@Override protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) { final OSchema schema = ((OMetadataInternal)ODatabaseRecordThreadLocal.instance().get().getMetadata()).getImmutableSchemaSnapshot(); final String baseClassName = iRight.toString(); final OClass baseClass = schema.getClass(baseClassName); if (baseClass == null) throw new OCommandExecutionException("Class '" + baseClassName + "' is not defined in database schema"); OClass cls = null; if (iLeft instanceof OIdentifiable) { // GET THE RECORD'S CLASS final ORecord record = ((OIdentifiable) iLeft).getRecord(); if (record instanceof ODocument) { cls = ODocumentInternal.getImmutableSchemaClass(((ODocument) record)); } } else if (iLeft instanceof String) // GET THE CLASS BY NAME cls = schema.getClass((String) iLeft); return cls != null ? cls.isSubClassOf(baseClass) : false; }
private void checkCollectionIndex(OIndexDefinition indexDefinition) { List<String> fields = indexDefinition.getFields(); OClass aClass = getDatabase().getMetadata().getSchema().getClass(indexDefinition.getClassName()); for (String field : fields) { OProperty property = aClass.getProperty(field); if (property.getType().isEmbedded() && property.getLinkedType() != null) { collectionFields.put(field, true); } else { collectionFields.put(field, false); } } }
private void convertToSbTree() { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().get(); final OIndexRIDContainerSBTree tree = new OIndexRIDContainerSBTree(fileId, (OAbstractPaginatedStorage) db.getStorage().getUnderlying()); tree.addAll(underlying); underlying = tree; isEmbedded = false; } }