use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OSerializableWrapper method fromStream.
@Override
public OSerializableStream fromStream(byte[] iStream) throws OSerializationException {
ByteArrayInputStream stream = new ByteArrayInputStream(iStream);
try {
ObjectInputStream reader = new ObjectInputStream(stream);
serializable = (Serializable) reader.readObject();
reader.close();
} catch (Exception e) {
throw OException.wrapException(new ODatabaseException("Error on deserialization of Serializable"), e);
}
return this;
}
use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class ORecordSerializerBinaryV0 method writeOptimizedLink.
private int writeOptimizedLink(final BytesContainer bytes, OIdentifiable link) {
if (!link.getIdentity().isPersistent()) {
try {
final ORecord real = link.getRecord();
if (real != null)
link = real;
} catch (ORecordNotFoundException ex) {
// IGNORE IT WILL FAIL THE ASSERT IN CASE
}
}
if (link.getIdentity().getClusterId() < 0 && ORecordSerializationContext.getContext() != null)
throw new ODatabaseException("Impossible to serialize invalid link " + link.getIdentity());
final int pos = OVarIntSerializer.write(bytes, link.getIdentity().getClusterId());
OVarIntSerializer.write(bytes, link.getIdentity().getClusterPosition());
return pos;
}
use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OSQLEngine method getRecordOperators.
public synchronized OQueryOperator[] getRecordOperators() {
if (SORTED_OPERATORS != null) {
return SORTED_OPERATORS;
}
// sort operators, will happen only very few times since we cache the
// result
final Iterator<OQueryOperatorFactory> ite = getOperatorFactories();
final List<OQueryOperator> operators = new ArrayList<OQueryOperator>();
while (ite.hasNext()) {
final OQueryOperatorFactory factory = ite.next();
operators.addAll(factory.getOperators());
}
final List<OQueryOperator> sorted = new ArrayList<OQueryOperator>();
final Set<Pair> pairs = new LinkedHashSet<Pair>();
for (final OQueryOperator ca : operators) {
for (final OQueryOperator cb : operators) {
if (ca != cb) {
switch(ca.compare(cb)) {
case BEFORE:
pairs.add(new Pair(ca, cb));
break;
case AFTER:
pairs.add(new Pair(cb, ca));
break;
}
switch(cb.compare(ca)) {
case BEFORE:
pairs.add(new Pair(cb, ca));
break;
case AFTER:
pairs.add(new Pair(ca, cb));
break;
}
}
}
}
boolean added;
do {
added = false;
scan: for (final Iterator<OQueryOperator> it = operators.iterator(); it.hasNext(); ) {
final OQueryOperator candidate = it.next();
for (final Pair pair : pairs) {
if (pair.after == candidate) {
continue scan;
}
}
sorted.add(candidate);
it.remove();
for (final Iterator<Pair> itp = pairs.iterator(); itp.hasNext(); ) {
if (itp.next().before == candidate) {
itp.remove();
}
}
added = true;
}
} while (added);
if (!operators.isEmpty()) {
throw new ODatabaseException("Invalid sorting. " + OCollections.toString(pairs));
}
SORTED_OPERATORS = sorted.toArray(new OQueryOperator[sorted.size()]);
return SORTED_OPERATORS;
}
use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OClusterEntryIterator method next.
public OPhysicalPosition next() {
try {
if (positionsIndex == -1) {
positionsToProcess = cluster.ceilingPositions(new OPhysicalPosition(min));
positionsIndex = 0;
}
if (positionsToProcess.length == 0)
throw new NoSuchElementException();
final OPhysicalPosition result = positionsToProcess[positionsIndex];
positionsIndex++;
if (positionsIndex >= positionsToProcess.length) {
positionsToProcess = cluster.higherPositions(positionsToProcess[positionsToProcess.length - 1]);
positionsIndex = 0;
}
return result;
} catch (IOException e) {
throw OException.wrapException(new ODatabaseException("Cannot read next record of cluster"), e);
}
}
use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OTransactionNoTx method saveRecord.
/**
* Update the record.
*
* @param iRecord
* @param iForceCreate
* @param iRecordCreatedCallback
* @param iRecordUpdatedCallback
*/
public ORecord saveRecord(final ORecord iRecord, final String iClusterName, final OPERATION_MODE iMode, boolean iForceCreate, final ORecordCallback<? extends Number> iRecordCreatedCallback, ORecordCallback<Integer> iRecordUpdatedCallback) {
try {
ORecord toRet = null;
ODirtyManager dirtyManager = ORecordInternal.getDirtyManager(iRecord);
Set<ORecord> newRecord = dirtyManager.getNewRecords();
Set<ORecord> updatedRecord = dirtyManager.getUpdateRecords();
dirtyManager.clearForSave();
if (newRecord != null) {
for (ORecord rec : newRecord) {
if (rec.getIdentity().isNew() && rec instanceof ODocument) {
ORecord ret = saveNew((ODocument) rec, dirtyManager, iClusterName, iRecord, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
if (ret != null)
toRet = ret;
}
}
}
if (updatedRecord != null) {
for (ORecord rec : updatedRecord) {
if (rec == iRecord) {
toRet = database.executeSaveRecord(rec, iClusterName, rec.getVersion(), iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
} else
database.executeSaveRecord(rec, getClusterName(rec), rec.getVersion(), OPERATION_MODE.SYNCHRONOUS, false, null, null);
}
}
if (toRet != null)
return toRet;
else
return database.executeSaveRecord(iRecord, iClusterName, iRecord.getVersion(), iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
} catch (Exception e) {
// REMOVE IT FROM THE CACHE TO AVOID DIRTY RECORDS
final ORecordId rid = (ORecordId) iRecord.getIdentity();
if (rid.isValid())
database.getLocalCache().freeRecord(rid);
throw OException.wrapException(new ODatabaseException("Error during saving of record" + (iRecord != null ? " with rid " + iRecord.getIdentity() : "")), e);
}
}
Aggregations