use of com.orientechnologies.common.util.OPair in project orientdb by orientechnologies.
the class OCommandExecutorSQLSetAware method parseSetFields.
protected void parseSetFields(final OClass iClass, final List<OPair<String, Object>> fields) {
String fieldName;
String fieldValue;
while (!parserIsEnded() && (fields.size() == 0 || parserGetLastSeparator() == ',' || parserGetCurrentChar() == ',')) {
fieldName = parserRequiredWord(false, "Field name expected");
if (fieldName.equalsIgnoreCase(KEYWORD_WHERE)) {
parserGoBack();
break;
}
parserNextChars(false, true, "=");
fieldValue = parserRequiredWord(false, "Value expected", " =><,\r\n", true);
// INSERT TRANSFORMED FIELD VALUE
final Object v = convertValue(iClass, fieldName, getFieldValueCountingParameters(fieldValue));
fields.add(new OPair(fieldName, v));
parserSkipWhiteSpaces();
}
if (fields.size() == 0)
throwParsingException("Entries to set <field> = <value> are missed. Example: name = 'Bill', salary = 300.2");
}
use of com.orientechnologies.common.util.OPair in project orientdb by orientechnologies.
the class OCommandExecutorSQLMoveVertex method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLMoveVertex parse(final OCommandRequest iRequest) {
final ODatabaseDocument database = getDatabase();
init((OCommandRequestText) iRequest);
parserRequiredKeyword("MOVE");
parserRequiredKeyword("VERTEX");
source = parserRequiredWord(false, "Syntax error", " =><,\r\n");
if (source == null)
throw new OCommandSQLParsingException("Cannot find source");
parserRequiredKeyword("TO");
String temp = parseOptionalWord(true);
while (temp != null) {
if (temp.startsWith("CLUSTER:")) {
if (className != null)
throw new OCommandSQLParsingException("Cannot define multiple sources. Found both cluster and class.");
clusterName = temp.substring("CLUSTER:".length());
if (database.getClusterIdByName(clusterName) == -1)
throw new OCommandSQLParsingException("Cluster '" + clusterName + "' was not found");
} else if (temp.startsWith("CLASS:")) {
if (clusterName != null)
throw new OCommandSQLParsingException("Cannot define multiple sources. Found both cluster and class.");
className = temp.substring("CLASS:".length());
clazz = database.getMetadata().getSchema().getClass(className);
if (clazz == null)
throw new OCommandSQLParsingException("Class '" + className + "' was not found");
} else if (temp.equals(KEYWORD_SET)) {
fields = new ArrayList<OPair<String, Object>>();
parseSetFields(clazz, fields);
} else if (temp.equals(KEYWORD_MERGE)) {
merge = parseJSON();
} else if (temp.equals(KEYWORD_BATCH)) {
temp = parserNextWord(true);
if (temp != null)
batch = Integer.parseInt(temp);
}
temp = parserOptionalWord(true);
if (parserIsEnded())
break;
}
return this;
}
use of com.orientechnologies.common.util.OPair in project orientdb by orientechnologies.
the class OAbstractPaginatedStorage method readRecords.
/**
* Returns the requested records. The returned order could be different than the requested.
*
* @param iRids Set of rids to load in one shot
*/
public Collection<OPair<ORecordId, ORawBuffer>> readRecords(final Collection<ORecordId> iRids) {
checkOpeness();
final List<OPair<ORecordId, ORawBuffer>> records = new ArrayList<OPair<ORecordId, ORawBuffer>>();
if (iRids == null || iRids.isEmpty())
return records;
if (transaction.get() != null) {
for (ORecordId rid : iRids) {
if (!rid.isPersistent())
throw new ORecordNotFoundException(rid, "Cannot read record " + rid + " since the position is invalid in database '" + name + '\'');
records.add(new OPair<ORecordId, ORawBuffer>(rid, doReadRecord(getClusterById(rid.getClusterId()), rid, false)));
}
return records;
}
// CREATE GROUP OF RIDS PER CLUSTER TO REDUCE LOCKS
final Map<Integer, List<ORecordId>> ridsPerCluster = getRidsGroupedByCluster(iRids);
stateLock.acquireReadLock();
try {
for (Map.Entry<Integer, List<ORecordId>> entry : ridsPerCluster.entrySet()) {
final int clusterId = entry.getKey();
final OCluster clusterSegment = getClusterById(clusterId);
for (ORecordId rid : entry.getValue()) {
records.add(new OPair<ORecordId, ORawBuffer>(rid, doReadRecord(clusterSegment, rid, false)));
}
}
} finally {
stateLock.releaseReadLock();
}
return records;
}
use of com.orientechnologies.common.util.OPair in project orientdb by orientechnologies.
the class OStorageRemote method updateCollection.
private void updateCollection(final Map<OBonsaiCollectionPointer, OPair<Long, Long>> changes, final OSBTreeCollectionManager collectionManager) throws IOException {
if (collectionManager == null)
return;
for (Map.Entry<OBonsaiCollectionPointer, OPair<Long, Long>> entry : changes.entrySet()) {
final OBonsaiCollectionPointer pointer = entry.getKey();
final long mBitsOfId = entry.getValue().getKey();
final long lBitsOfId = entry.getValue().getValue();
collectionManager.updateCollectionPointer(new UUID(mBitsOfId, lBitsOfId), pointer);
}
if (ORecordSerializationContext.getDepth() <= 1)
collectionManager.clearPendingCollections();
}
use of com.orientechnologies.common.util.OPair in project orientdb by orientechnologies.
the class ODatabaseDocumentTx method executeReadRecords.
/**
* This method is internal, it can be subject to signature change or be removed, do not use.
*
* @Internal
*/
public Set<ORecord> executeReadRecords(final Set<ORecordId> iRids, final boolean ignoreCache) {
checkOpeness();
checkIfActive();
getMetadata().makeThreadLocalSchemaSnapshot();
ORecordSerializationContext.pushContext();
try {
final Set<ORecord> records = new HashSet<ORecord>(iRids.size() > 0 ? iRids.size() : 1);
if (iRids.isEmpty())
return records;
final Collection<ORecordId> rids = new ArrayList<ORecordId>(iRids);
for (Iterator<ORecordId> it = rids.iterator(); it.hasNext(); ) {
final ORecordId rid = it.next();
// SEARCH IN LOCAL TX
ORecord record = getTransaction().getRecord(rid);
if (record == OTransactionRealAbstract.DELETED_RECORD) {
// DELETED IN TX
it.remove();
continue;
}
if (record == null && !ignoreCache)
// SEARCH INTO THE CACHE
record = getLocalCache().findRecord(rid);
if (record != null) {
// FOUND FROM CACHE
records.add(record);
it.remove();
}
}
final Collection<OPair<ORecordId, ORawBuffer>> rawRecords = ((OAbstractPaginatedStorage) storage.getUnderlying()).readRecords(rids);
for (OPair<ORecordId, ORawBuffer> entry : rawRecords) {
// NO SAME RECORD TYPE: CAN'T REUSE OLD ONE BUT CREATE A NEW ONE FOR IT
final ORecord record = Orient.instance().getRecordFactoryManager().newInstance(entry.value.recordType);
ORecordInternal.fill(record, entry.key, entry.value.version, entry.value.buffer, false);
records.add(record);
}
return records;
} finally {
ORecordSerializationContext.pullContext();
getMetadata().clearThreadLocalSchemaSnapshot();
}
}
Aggregations