protected void checkRecordClass(final OClass recordClass, final String iClusterName, final ORecordId rid) { final OClass clusterIdClass = metadata.getImmutableSchemaSnapshot().getClassByClusterId(rid.getClusterId()); if (recordClass == null && clusterIdClass != null || clusterIdClass == null && recordClass != null || (recordClass != null && !recordClass.equals(clusterIdClass))) throw new IllegalArgumentException( "Record saved into cluster '" + iClusterName + "' should be saved with class '" + clusterIdClass + "' but has been created with class '" + recordClass + "'"); }
private void updateRangesOnLiveUpdate() { if (liveUpdated) { final long[] range = database.getStorage().getClusterDataRange(current.getClusterId()); firstClusterEntry = range[0]; lastClusterEntry = range[1]; } } }
@Override public String getClusterNameByRid(String rid) { return getClusterNameById(new ORecordId(rid).getClusterId()); }
@Override public String getClusterNameByRid(String rid) { return getClusterNameById(new ORecordId(rid).getClusterId()); }
/** * Creates a new instance in memory of the specified class, linked by the Record Id to the persistent one. New instances are not * persistent until {@link #save()} is called. * * @param iClassName Class name * @param iRID Record Id */ public ODocument(final String iClassName, final ORID iRID) { this(iClassName); _recordId = (ORecordId) iRID; final ODatabaseDocumentInternal database = getDatabaseInternal(); if (_recordId.getClusterId() > -1) { final OSchema schema = database.getMetadata().getImmutableSchemaSnapshot(); final OClass cls = schema.getClassByClusterId(_recordId.getClusterId()); if (cls != null && !cls.getName().equals(iClassName)) throw new IllegalArgumentException( "Cluster id does not correspond class name should be " + iClassName + " but found " + cls.getName()); } _dirty = false; _contentChanged = false; _status = STATUS.NOT_LOADED; }
@Override public Set<String> getInvolvedClusters() { final HashSet<String> result = new HashSet<String>(); if (rid != null) result.add(database.getClusterNameById(rid.getClusterId())); else if (query != null) { final OCommandExecutor executor = OCommandManager.instance().getExecutor((OCommandRequestInternal) query); // COPY THE CONTEXT FROM THE REQUEST executor.setContext(context); executor.parse(query); return executor.getInvolvedClusters(); } return result; }
@Override public Set<String> getInvolvedClusters() { final HashSet<String> result = new HashSet<String>(); if (rid != null) result.add(database.getClusterNameById(rid.getClusterId())); else if (query != null) { final OCommandExecutor executor = OCommandManager.instance().getExecutor((OCommandRequestInternal) query); // COPY THE CONTEXT FROM THE REQUEST executor.setContext(context); executor.parse(query); return executor.getInvolvedClusters(); } return result; }
public OInteger getCluster() { if (expression != null) { ORecordId rid = toRecordId((OResult) null, new OBasicCommandContext()); if (rid == null) { OInteger result = new OInteger(-1); result.setValue(rid.getClusterId()); return result; } } return cluster; }
protected boolean prevPosition() { if (positionsToProcess == null) { positionsToProcess = dbStorage.floorPhysicalPositions(current.getClusterId(), new OPhysicalPosition(lastClusterEntry)); if (positionsToProcess == null) return false; if (positionsToProcess.length == 0) return false; currentEntryPosition = positionsToProcess.length; } else { if (currentEntry < firstClusterEntry) return false; } decrementEntreePosition(); while (positionsToProcess.length > 0 && currentEntryPosition < 0) { positionsToProcess = dbStorage.lowerPhysicalPositions(current.getClusterId(), positionsToProcess[0]); currentEntryPosition = positionsToProcess.length; decrementEntreePosition(); } if (positionsToProcess.length == 0) return false; currentEntry = positionsToProcess[currentEntryPosition].clusterPosition; if (currentEntry < firstClusterEntry) return false; current.setClusterPosition(currentEntry); return true; }
protected boolean nextPosition() { if (positionsToProcess == null) { positionsToProcess = dbStorage.ceilingPhysicalPositions(current.getClusterId(), new OPhysicalPosition(firstClusterEntry)); if (positionsToProcess == null) return false; } else { if (currentEntry >= lastClusterEntry) return false; } incrementEntreePosition(); while (positionsToProcess.length > 0 && currentEntryPosition >= positionsToProcess.length) { positionsToProcess = dbStorage .higherPhysicalPositions(current.getClusterId(), positionsToProcess[positionsToProcess.length - 1]); currentEntryPosition = -1; incrementEntreePosition(); } if (positionsToProcess.length == 0) return false; currentEntry = positionsToProcess[currentEntryPosition].clusterPosition; if (currentEntry > lastClusterEntry || currentEntry == ORID.CLUSTER_POS_INVALID) return false; current.setClusterPosition(currentEntry); return true; }
protected void updateClusterRange() { if (clusterIds.length == 0) return; // ADJUST IDX CHECKING BOUNDARIES if (currentClusterIdx >= clusterIds.length) currentClusterIdx = clusterIds.length - 1; else if (currentClusterIdx < 0) currentClusterIdx = 0; current.setClusterId(clusterIds[currentClusterIdx]); final long[] range = database.getStorage().getClusterDataRange(current.getClusterId()); if (beginRange != null && beginRange.getClusterId() == current.getClusterId() && beginRange.getClusterPosition() > range[0]) firstClusterEntry = beginRange.getClusterPosition(); else firstClusterEntry = range[0]; if (endRange != null && endRange.getClusterId() == current.getClusterId() && endRange.getClusterPosition() < range[1]) lastClusterEntry = endRange.getClusterPosition(); else lastClusterEntry = range[1]; resetCurrentPosition(); }
@Override public Set<String> getInvolvedClusters() { final HashSet<String> result = new HashSet<String>(); if (rids != null) { final ODatabaseDocumentInternal database = getDatabase(); for (ORecordId rid : rids) { result.add(database.getClusterNameById(rid.getClusterId())); } } else if (query != null) { final OCommandExecutor executor = OCommandManager.instance().getExecutor((OCommandRequestInternal) query); // COPY THE CONTEXT FROM THE REQUEST executor.setContext(context); executor.parse(query); return executor.getInvolvedClusters(); } return result; }
@Override public Set<String> getInvolvedClusters() { final HashSet<String> result = new HashSet<String>(); if (rids != null) { final ODatabaseDocumentInternal database = getDatabase(); for (ORecordId rid : rids) { result.add(database.getClusterNameById(rid.getClusterId())); } } else if (query != null) { final OCommandExecutor executor = OCommandManager.instance().getExecutor((OCommandRequestInternal) query); // COPY THE CONTEXT FROM THE REQUEST executor.setContext(context); executor.parse(query); return executor.getInvolvedClusters(); } return result; }
private void fetchClassName() { final ODatabaseDocumentInternal database = getDatabaseIfDefinedInternal(); if (database != null && database.getStorageVersions() != null) { if (_recordId.getClusterId() < 0) { checkForLoading(); checkForFields(ODocumentHelper.ATTRIBUTE_CLASS); } else { final OSchema schema = database.getMetadata().getImmutableSchemaSnapshot(); if (schema != null) { OClass _clazz = schema.getClassByClusterId(_recordId.getClusterId()); if (_clazz != null) _className = _clazz.getName(); } } } else { // CLASS NOT FOUND: CHECK IF NEED LOADING AND UNMARSHALLING checkForLoading(); checkForFields(ODocumentHelper.ATTRIBUTE_CLASS); } }
@Override public void serialize(ORecordId value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); jgen.writeFieldName(OrientIoRegistry.CLUSTER_ID); jgen.writeNumber(value.getClusterId()); jgen.writeFieldName(OrientIoRegistry.CLUSTER_POSITION); jgen.writeNumber(value.getClusterPosition()); jgen.writeEndObject(); }
@Override public final OStorageOperationResult<ORawBuffer> readRecordIfVersionIsNotLatest(final ORecordId rid, final String fetchPlan, final boolean ignoreCache, final int recordVersion) throws ORecordNotFoundException { try { checkOpenness(); return new OStorageOperationResult<>(readRecordIfNotLatest(getClusterById(rid.getClusterId()), rid, recordVersion)); } catch (final RuntimeException ee) { throw logAndPrepareForRethrow(ee); } catch (final Error ee) { throw logAndPrepareForRethrow(ee); } catch (final Throwable t) { throw logAndPrepareForRethrow(t); } }
@Override public final OStorageOperationResult<Boolean> hideRecord(final ORecordId rid, final int mode, final ORecordCallback<Boolean> callback) { try { checkOpenness(); checkLowDiskSpaceRequestsAndReadOnlyConditions(); final OCluster cluster = getClusterById(rid.getClusterId()); if (transaction.get() != null) { return doHideMethod(rid, cluster); } stateLock.acquireReadLock(); try { final Lock lock = recordVersionManager.acquireExclusiveLock(rid); try { checkOpenness(); return doHideMethod(rid, cluster); } finally { lock.unlock(); } } finally { stateLock.releaseReadLock(); } } catch (final RuntimeException ee) { throw logAndPrepareForRethrow(ee); } catch (final Error ee) { throw logAndPrepareForRethrow(ee); } catch (final Throwable t) { throw logAndPrepareForRethrow(t); } }
@Override public final OStorageOperationResult<Boolean> deleteRecord(final ORecordId rid, final int version, final int mode, final ORecordCallback<Boolean> callback) { try { checkOpenness(); checkLowDiskSpaceRequestsAndReadOnlyConditions(); final OCluster cluster = getClusterById(rid.getClusterId()); if (transaction.get() != null) { return doDeleteRecord(rid, version, cluster); } stateLock.acquireReadLock(); try { checkOpenness(); return doDeleteRecord(rid, version, cluster); } finally { stateLock.releaseReadLock(); } } catch (final RuntimeException ee) { throw logAndPrepareForRethrow(ee); } catch (final Error ee) { throw logAndPrepareForRethrow(ee); } catch (final Throwable t) { throw logAndPrepareForRethrow(t); } }
@Override public final OStorageOperationResult<ORawBuffer> readRecord(final ORecordId iRid, final String iFetchPlan, final boolean iIgnoreCache, final boolean prefetchRecords, final ORecordCallback<ORawBuffer> iCallback) { try { checkOpenness(); final OCluster cluster; try { cluster = getClusterById(iRid.getClusterId()); } catch (final IllegalArgumentException e) { throw OException.wrapException(new ORecordNotFoundException(iRid), e); } return new OStorageOperationResult<>(readRecord(cluster, iRid, prefetchRecords)); } catch (final RuntimeException ee) { throw logAndPrepareForRethrow(ee); } catch (final Error ee) { throw logAndPrepareForRethrow(ee); } catch (final Throwable t) { throw logAndPrepareForRethrow(t); } }
@Override public ILocation convertToEntity(ODocument document) { Location location = new Location(); location.setLongitude(document.field("longitude", Double.class)); location.setLatitude(document.field("latitude", Double.class)); location.setComment(document.field("comment", String.class)); // populate with data populateEntityWithBaseData(document, location); populateEntityWithCreatedModified(document, location); // parent ORecordId parent = document.field("parent", ORecordId.class); if (parent != null) { initDb(); location.setParentId(parent.getIdentity().toString()); location.setParentModel(db.getMetadata().getSchema().getClassByClusterId(parent.getClusterId()).getName()); //TODO: lazy load parent } // add distance, if set in document (added by some query results) if (document.field("$distance") != null) location.setDistance(document.field("$distance", Double.class)); return location; }