@Override public ORawBuffer readRecord(OStorage storage, ORecordId rid, String fetchPlan, boolean ignoreCache, final int recordVersion) throws ORecordNotFoundException { return storage.readRecordIfVersionIsNotLatest(rid, fetchPlan, ignoreCache, recordVersion).getResult(); } }
@Override public ORawBuffer readRecord(OStorage storage, ORecordId rid, String fetchPlan, boolean ignoreCache, final int recordVersion) throws ORecordNotFoundException { return storage.readRecord(rid, fetchPlan, ignoreCache, prefetchRecords, null).getResult(); } }
@Override public final boolean cleanOutRecord(final ORecordId recordId, final int recordVersion, final int iMode, final ORecordCallback<Boolean> callback) { return deleteRecord(recordId, recordVersion, iMode, callback).getResult(); }
@Override public ORawBuffer call(ODatabaseDocumentInternal database) { return database.getStorage().readRecord(rid, null, true, false, null).getResult(); } });
@Override public ORawBuffer call(ODatabaseDocumentInternal database) { return database.getStorage().readRecord(rid2, null, true, false, null).getResult(); } });
byte[] storedContent = storage.readRecord(rid, null, false, false, null).getResult().getBuffer();
@Override public byte[] onUpdate(OStorage storage, byte iRecordType, final ORecordId rid, final int iRecordVersion, final byte[] iRecordContent, final AtomicInteger iDatabaseVersion) { if (iRecordType == ODocument.RECORD_TYPE) { // No need lock, is already inside a lock. Use database to read temporary objects too OStorageOperationResult<ORawBuffer> res = storage.readRecord(rid, null, false, false, null); final ODocument storedRecord = new ODocument(rid).fromStream(res.getResult().getBuffer()); ODocument newRecord = (ODocument) ORecordSaveThreadLocal.getLast(); if (newRecord == null || !newRecord.getIdentity().equals(rid)) newRecord = new ODocument(rid).fromStream(iRecordContent); storedRecord.merge(newRecord, true, true); iDatabaseVersion.set(Math.max(iDatabaseVersion.get(), iRecordVersion) + 1); return storedRecord.toStream(); } else // NO DOCUMENT, CANNOT MERGE SO RELY TO THE VERSION CHECK checkVersions(rid, iRecordVersion, iDatabaseVersion.get()); return null; }
@Override public byte[] onUpdate(OStorage storage, final byte iRecordType, final ORecordId rid, final int iRecordVersion, final byte[] iRecordContent, final AtomicInteger iDatabaseVersion) { final boolean hasSameContent; if (iRecordType == ODocument.RECORD_TYPE) { // No need lock, is already inside a lock. OStorageOperationResult<ORawBuffer> res = storage.readRecord(rid, null, false, false, null); final ODocument storedRecord = new ODocument(rid).fromStream(res.getResult().getBuffer()); final ODocument newRecord = new ODocument().fromStream(iRecordContent); final ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.instance().get(); hasSameContent = ODocumentHelper.hasSameContentOf(storedRecord, currentDb, newRecord, currentDb, null, false); } else { // CHECK BYTE PER BYTE final ORecordAbstract storedRecord = rid.getRecord(); hasSameContent = Arrays.equals(storedRecord.toStream(), iRecordContent); } if (hasSameContent) // OK iDatabaseVersion.set(Math.max(iDatabaseVersion.get(), iRecordVersion)); else // NO DOCUMENT, CANNOT MERGE SO RELY TO THE VERSION CHECK checkVersions(rid, iRecordVersion, iDatabaseVersion.get()); return null; }
/** * This method load the record information by the internal cluster segment. It's for compatibility with older database than * 0.9.25. */ public OStorageConfigurationImpl load(final OContextConfiguration configuration) throws OSerializationException { lock.acquireWriteLock(); try { initConfiguration(configuration); final byte[] record = storage.readRecord(CONFIG_RID, null, false, false, null).getResult().buffer; if (record == null) throw new OStorageException("Cannot load database configuration. The database seems corrupted"); fromStream(record, 0, record.length, streamCharset); } finally { lock.releaseWriteLock(); } return this; }
/** * Execute the command. */ public Object execute(final Map<Object, Object> iArgs) { if (records.isEmpty()) throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet"); int deleted = 0; final ODatabaseDocumentInternal database = getDatabase(); for (String rec : records) { try { final ORecordId rid = new ORecordId(rec); final OStorageOperationResult<Boolean> result = database.getStorage().deleteRecord(rid, -1, 0, null); database.getLocalCache().deleteRecord(rid); if (result.getResult()) deleted++; } catch (Exception e) { throw OException.wrapException(new OCommandExecutionException("Error on executing command"), e); } } return deleted; }
@Override public OResultSet executeSimple(OCommandContext ctx) { List<ORid> recs = new ArrayList<>(); if (record != null) { recs.add(record); } else { recs.addAll(records); } OInternalResultSet rs = new OInternalResultSet(); final ODatabaseDocumentInternal database = (ODatabaseDocumentInternal) ctx.getDatabase(); for (ORid rec : recs) { try { final ORecordId rid = rec.toRecordId((OResult) null, ctx); final OStorageOperationResult<Boolean> result = database.getStorage().deleteRecord(rid, -1, 0, null); database.getLocalCache().deleteRecord(rid); if (result.getResult()) { OResultInternal recordRes = new OResultInternal(); recordRes.setProperty("operation", "truncate record"); recordRes.setProperty("record", rec.toString()); rs.add(recordRes); } } catch (Exception e) { throw OException.wrapException(new OCommandExecutionException("Error on executing command"), e); } } return rs; }
ORecordId id = new ORecordId(rid); if (!(currentDatabase.getStorage() instanceof OLocalPaginatedStorage)) { record = currentDatabase.getStorage().readRecord(rid, null, false, false, null).getResult(); if (record != null) { String content;
final OPhysicalPosition ppos; final byte recordType = ORecordInternal.getRecordType(rec); ppos = doCreateRecord(rid, stream, rec.getVersion(), recordType, null, cluster, allocated).getResult(); ORecordInternal.setVersion(rec, updateRes.getResult()); if (updateRes.getModifiedRecordContent() != null) { ORecordInternal.fill(rec, rid, updateRes.getResult(), updateRes.getModifiedRecordContent(), false); ORecordInternal.setVersion(rec, updateRes.getResult()); if (updateRes.getModifiedRecordContent() != null) { ORecordInternal.fill(rec, rid, updateRes.getResult(), updateRes.getModifiedRecordContent(), false);
public <RET extends ORecord> RET executeSaveEmptyRecord(ORecord record, String clusterName) { ORecordId rid = (ORecordId) record.getIdentity(); assert rid.isNew(); ORecordInternal.onBeforeIdentityChanged(record); int id = assignAndCheckCluster(record, clusterName); clusterName = getClusterNameById(id); checkSecurity(ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_CREATE, clusterName); byte[] content = getSerializer().writeClassOnly(record); final OStorageOperationResult<OPhysicalPosition> ppos = getStorage() .createRecord(rid, content, record.getVersion(), recordType, OPERATION_MODE.SYNCHRONOUS.ordinal(), null); ORecordInternal.setVersion(record, ppos.getResult().recordVersion); ((ORecordId) record.getIdentity()).copyFrom(rid); ORecordInternal.onAfterIdentityChanged(record); return (RET) record; }
getLocalCache().deleteRecord(rid); return operationResult.getResult(); } finally { ORecordSerializationContext.pullContext();