Search in sources :

Example 16 with ODatabaseException

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) IOException(java.io.IOException) OException(com.orientechnologies.common.exception.OException) OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) ObjectInputStream(java.io.ObjectInputStream)

Example 17 with ODatabaseException

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;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException)

Example 18 with ODatabaseException

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OQueryOperatorFactory(com.orientechnologies.orient.core.sql.operator.OQueryOperatorFactory) ArrayList(java.util.ArrayList) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) Iterator(java.util.Iterator) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OQueryOperator(com.orientechnologies.orient.core.sql.operator.OQueryOperator)

Example 19 with ODatabaseException

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);
    }
}
Also used : IOException(java.io.IOException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) NoSuchElementException(java.util.NoSuchElementException)

Example 20 with ODatabaseException

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);
    }
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OException(com.orientechnologies.common.exception.OException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)28 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)7 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)7 OException (com.orientechnologies.common.exception.OException)5 ORecordId (com.orientechnologies.orient.core.id.ORecordId)5 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)4 IOException (java.io.IOException)4 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)3 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)3 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)3 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)3 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 OLocalClusterWrapperStrategy (com.orientechnologies.orient.server.distributed.impl.OLocalClusterWrapperStrategy)2 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 OMultiCollectionIterator (com.orientechnologies.common.collection.OMultiCollectionIterator)1