@Override public ODatabaseDocument getDatabase() { return element.getDatabase(); }
public ORecordAbstract save(final String iClusterName, final boolean forceCreate) { return getDatabase().save(this, iClusterName, ODatabase.OPERATION_MODE.SYNCHRONOUS, forceCreate, null, null); }
@Override public ODatabaseDocument getDatabase() { if (element != null) { return element.getDatabase(); } else { return ODatabaseRecordThreadLocal.instance().getIfDefined(); } }
@Override protected Boolean execute(ODatabaseDocument db) { document.save(); if (document.getDatabase().getTransaction().isActive()){ document.getDatabase().commit(); } return true; } }.execute();
private Iterable<ODocument> browseComponentAssets(final ODocument component) { checkNotNull(component); OIdentifiable bucket = component.field(ComponentEntityAdapter.P_BUCKET, OIdentifiable.class); ODatabaseDocumentInternal db = component.getDatabase(); Iterable<ODocument> results = db .command(new OCommandSQL("select from asset where bucket = :bucket and component = :component")).execute( new ImmutableMap.Builder<String, Object>() .put("bucket", bucket.getIdentity()) .put("component", component.getIdentity()) .build() ); return results; } }
public OUser addRole(final String iRole) { if (iRole != null) addRole(document.getDatabase().getMetadata().getSecurity().getRole(iRole)); return this; }
/** * TEMP: workaround OrientDB 2.1 issue where in-TX dictionary updates are not replicated. * * @since 3.1 */ public void replicate(final ODocument document, final EventKind eventKind) { ODictionary<ORecord> dictionary = document.getDatabase().getDictionary(); switch (eventKind) { case CREATE: case UPDATE: dictionary.put(key, document); break; case DELETE: dictionary.remove(key); break; default: break; } } }
@Deprecated public ODocument load(final String iFetchPlan, boolean iIgnoreCache, boolean loadTombstone) { Object result; try { result = getDatabase().load(this, iFetchPlan, iIgnoreCache, loadTombstone, OStorage.LOCKING_STRATEGY.DEFAULT); } catch (Exception e) { throw OException.wrapException(new ORecordNotFoundException(getIdentity()), e); } if (result == null) throw new ORecordNotFoundException(getIdentity()); return (ODocument) result; }
@Override public void onRecordAfterUpdate(ODocument iDocument) { OrienteerWebApplication app = OrienteerWebApplication.lookupApplication(); if(app!=null) { String moduleName = iDocument.field(IOrienteerModule.OMODULE_NAME); IOrienteerModule module = app.getModuleByName(moduleName); if(module!=null) { ODatabaseDocument db = iDocument.getDatabase(); Object previousActivate = iDocument.getOriginalValue(IOrienteerModule.OMODULE_ACTIVATE); Object activated = iDocument.field(IOrienteerModule.OMODULE_ACTIVATE); boolean active = activated==null || Boolean.TRUE.equals(activated); if(previousActivate!=null && !previousActivate.equals(activated)) { if(active) module.onInitialize(app, db, iDocument); else module.onDestroy(app, db, iDocument); } if(active) module.onConfigurationChange(app, db, iDocument); } } }
/** * Checks if the user has the permission to access to the requested resource for the requested operation. * * @param iOperation Requested operation * * @return The role that has granted the permission if any, otherwise a OSecurityAccessException exception is raised * * @throws OSecurityAccessException */ public ORole allow(final ORule.ResourceGeneric resourceGeneric, String resourceSpecific, final int iOperation) { if (roles == null || roles.isEmpty()) { if (document.field("roles") != null && !((Collection<OIdentifiable>) document.field("roles")).isEmpty()) { final ODocument doc = document; document = null; fromStream(doc); } else throw new OSecurityAccessException(document.getDatabase().getName(), "User '" + document.field("name") + "' has no role defined"); } final ORole role = checkIfAllowed(resourceGeneric, resourceSpecific, iOperation); if (role == null) throw new OSecurityAccessException(document.getDatabase().getName(), "User '" + document.field("name") + "' does not have permission to execute the operation '" + ORole .permissionToString(iOperation) + "' against the resource: " + resourceGeneric + "." + resourceSpecific); return role; }
@SuppressWarnings("deprecation") private List<String> getCalcProperties(ODocument iDocument) ODatabaseDocument db = iDocument.getDatabase(); OClass oClass = iDocument.getSchemaClass(); if(db==null || oClass==null) return null;
/** * Loads the record using a fetch plan. Example: <p> <code>doc.load( "*:3", true ); // LOAD THE DOCUMENT BY EARLY FETCHING UP TO * 3rd LEVEL OF CONNECTIONS IGNORING THE CACHE</code> </p> * * @param iIgnoreCache Ignore the cache or use it */ public ODocument load(final String iFetchPlan, boolean iIgnoreCache) { Object result; try { result = getDatabase().load(this, iFetchPlan, iIgnoreCache); } catch (Exception e) { throw OException.wrapException(new ORecordNotFoundException(getIdentity()), e); } if (result == null) throw new ORecordNotFoundException(getIdentity()); return (ODocument) result; }
protected OGlobalProperty getGlobalPropertyById(int id) { if (_schema == null) { OMetadataInternal metadata = getDatabase().getMetadata(); _schema = metadata.getImmutableSchemaSnapshot(); } OGlobalProperty prop = _schema.getGlobalPropertyById(id); if (prop == null) { ODatabaseDocument db = getDatabase(); if (db == null || db.isClosed()) throw new ODatabaseException( "Cannot unmarshall the document because no database is active, use detach for use the document outside the database session scope"); OMetadataInternal metadata = (OMetadataInternal) db.getMetadata(); if (metadata.getImmutableSchemaSnapshot() != null) metadata.clearThreadLocalSchemaSnapshot(); metadata.reload(); metadata.makeThreadLocalSchemaSnapshot(); _schema = metadata.getImmutableSchemaSnapshot(); prop = _schema.getGlobalPropertyById(id); } return prop; }
if(FULL_QUERY_PATTERN.matcher(script).find()) calculated = iDocument.getDatabase().query(new OSQLSynchQuery<Object>(script), iDocument); calculated = iDocument.getDatabase().query(new OSQLSynchQuery<Object>(script));
.isNew()) && ODatabaseRecordThreadLocal.instance().isDefined()) { RET newValue = getDatabase().load((ORID) value); if (newValue != null) { unTrack((ORID) value);
.isNew()) && ODatabaseRecordThreadLocal.instance().isDefined()) { RET newValue = getDatabase().load((ORID) value); if (newValue != null) { unTrack((ORID) value);
parentRole = role != null ? document.getDatabase().getMetadata().getSecurity().getRole(role) : null;
/** * Validates the record following the declared constraints defined in schema such as mandatory, notNull, min, max, regexp, etc. If * the schema is not defined for the current class or there are not constraints then the validation is ignored. * * @throws OValidationException if the document breaks some validation constraints defined in the schema * @see OProperty */ public void validate() throws OValidationException { checkForLoading(); checkForFields(); autoConvertValues(); if (ODatabaseRecordThreadLocal.instance().isDefined() && !getDatabase().isValidationEnabled()) return; final OImmutableClass immutableSchemaClass = getImmutableSchemaClass(); if (immutableSchemaClass != null) { if (immutableSchemaClass.isStrictMode()) { // CHECK IF ALL FIELDS ARE DEFINED for (String f : fieldNames()) { if (immutableSchemaClass.getProperty(f) == null) throw new OValidationException( "Found additional field '" + f + "'. It cannot be added because the schema class '" + immutableSchemaClass.getName() + "' is defined as STRICT"); } } for (OProperty p : immutableSchemaClass.properties()) { validateField(this, (OImmutableProperty) p); } } }