Search in sources :

Example 1 with OTransaction

use of com.orientechnologies.orient.core.tx.OTransaction in project wicket-orientdb by OrienteerBAP.

the class DisableIfDocumentNotSavedBehavior method onConfigure.

@Override
public void onConfigure(Component component) {
    super.onConfigure(component);
    Object object = component.getDefaultModelObject();
    if (object != null && object instanceof OIdentifiable) {
        ORID rid = ((OIdentifiable) object).getIdentity();
        if (rid.isPersistent()) {
            component.setEnabled(true);
        } else {
            // Is record scheduled for creation?
            OTransaction transaction = OrientDbWebSession.get().getDatabase().getTransaction();
            ORecordOperation operation = transaction.getRecordEntry(rid);
            component.setEnabled(operation != null && operation.type == ORecordOperation.CREATED);
        }
    }
}
Also used : OTransaction(com.orientechnologies.orient.core.tx.OTransaction) ORecordOperation(com.orientechnologies.orient.core.db.record.ORecordOperation) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 2 with OTransaction

use of com.orientechnologies.orient.core.tx.OTransaction in project divide by HiddenStage.

the class OrientDBDao method query.

@Override
public List<TransientObject> query(Query query) throws DAOException {
    checkDb();
    List<TransientObject> list = new ArrayList<TransientObject>();
    OTransaction transaction = db.getTransaction();
    transaction.begin();
    try {
        String q = query.getSQL();
        System.out.println("OrientDB_Query: " + q);
        if (query.getAction().equals(QueryBuilder.QueryAction.SELECT)) {
            List<ODocument> objects = db.query(new OSQLSynchQuery<ODocument>(q));
            for (ODocument w : objects) {
                list.add(new ODocumentWrapper(w).toObject(TransientObject.class));
            }
        }
        if (query.getAction().equals(QueryBuilder.QueryAction.DELETE)) {
            // List<ODocument> objects = db.command(new OCommandSQL("delete from io.divide.dao.TestObject1 RETURN BEFORE")).execute();
            Integer objects = db.command(new OCommandSQL(q)).execute();
            TransientObject o = new EmptyTO();
            o.put("count", objects);
            list.add(o);
            System.out.println("Delete: " + objects);
        }
        transaction.commit();
        transaction.close();
    } catch (Exception e) {
        transaction.rollback();
        transaction.close();
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OTransaction(com.orientechnologies.orient.core.tx.OTransaction) TransientObject(io.divide.shared.transitory.TransientObject) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OTransaction

use of com.orientechnologies.orient.core.tx.OTransaction in project divide by HiddenStage.

the class OrientDBDao method save.

@Override
public void save(TransientObject... objects) throws DAOException {
    System.out.println("save: " + Arrays.asList(objects));
    checkDb();
    OTransaction transaction = db.getTransaction();
    transaction.begin();
    for (TransientObject t : objects) {
        db.save(new ODocumentWrapper(t));
    }
    transaction.commit();
    transaction.close();
}
Also used : OTransaction(com.orientechnologies.orient.core.tx.OTransaction) TransientObject(io.divide.shared.transitory.TransientObject)

Example 4 with OTransaction

use of com.orientechnologies.orient.core.tx.OTransaction in project divide by HiddenStage.

the class OrientDBDao method get.

@Override
public Collection<TransientObject> get(String objectType, String... keys) throws DAOException {
    if (keys.length == 0)
        return Arrays.asList();
    // String objectType = Query.safeTable(type);
    checkDb();
    OTransaction transaction = db.getTransaction();
    transaction.begin();
    // System.err.println(db.browseCluster(objectType).next());
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT * FROM " + objectType + " WHERE ");
    for (int x = 0; x < keys.length; x++) {
        sb.append("meta_data.object_key = '" + keys[x] + "'");
        if (x + 1 < keys.length)
            sb.append(" OR ");
    }
    List<TransientObject> objects = new ArrayList<TransientObject>();
    System.err.println("Query: " + sb.toString());
    List<ODocument> list = db.query(new OSQLSynchQuery<ODocument>(sb.toString()));
    System.err.println("Found: " + list.size());
    for (ODocument w : list) {
        System.err.println("Get: " + w);
        TransientObject to = ODocumentWrapper.toObject(w, TransientObject.class);
        objects.add(to);
    }
    transaction.commit();
    transaction.close();
    return objects;
}
Also used : OTransaction(com.orientechnologies.orient.core.tx.OTransaction) ArrayList(java.util.ArrayList) TransientObject(io.divide.shared.transitory.TransientObject) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OTransaction

use of com.orientechnologies.orient.core.tx.OTransaction in project orientdb by orientechnologies.

the class OrientGraphQuery method vertices.

/**
 * Returns the result set of the query as iterable vertices.
 */
@Override
public Iterable<Vertex> vertices() {
    if (limit == 0)
        return Collections.emptyList();
    OTransaction transaction = ((OrientBaseGraph) graph).getRawGraph().getTransaction();
    if (transaction.isActive() && transaction.getEntryCount() > 0 || hasCustomPredicate()) {
        // INSIDE TRANSACTION QUERY DOESN'T SEE IN MEMORY CHANGES, UNTIL
        // SUPPORTED USED THE BASIC IMPL
        String[] classes = allSubClassesLabels();
        return new OrientGraphQueryIterable<Vertex>(true, classes);
    }
    final StringBuilder text = new StringBuilder(512);
    // GO DIRECTLY AGAINST E CLASS AND SUB-CLASSES
    text.append(QUERY_SELECT_FROM);
    if (((OrientBaseGraph) graph).isUseClassForVertexLabel() && labels != null && labels.length > 0) {
        // FILTER PER CLASS SAVING CHECKING OF LABEL PROPERTY
        if (labels.length == 1)
            // USE THE CLASS NAME
            text.append(OrientBaseGraph.encodeClassName(labels[0]));
        else {
            // MULTIPLE CLASSES NOT SUPPORTED DIRECTLY: CREATE A SUB-QUERY
            String[] classes = allSubClassesLabels();
            return new OrientGraphQueryIterable<Vertex>(true, classes);
        }
    } else
        text.append(OrientVertexType.CLASS_NAME);
    final boolean usedWhere = manageFilters(text);
    if (!((OrientBaseGraph) graph).isUseClassForVertexLabel())
        manageLabels(usedWhere, text);
    if (orderBy.length() > 1) {
        text.append(ORDERBY);
        text.append(orderBy);
        text.append(" ").append(orderByDir).append(" ");
    }
    if (skip > 0 && skip < Integer.MAX_VALUE) {
        text.append(SKIP);
        text.append(skip);
    }
    if (limit > 0 && limit < Integer.MAX_VALUE) {
        text.append(LIMIT);
        text.append(limit);
    }
    final OSQLSynchQuery<OIdentifiable> query = new OSQLSynchQuery<OIdentifiable>(text.toString());
    if (fetchPlan != null)
        query.setFetchPlan(fetchPlan);
    return new OrientElementIterable<Vertex>(((OrientBaseGraph) graph), ((OrientBaseGraph) graph).getRawGraph().query(query));
}
Also used : OTransaction(com.orientechnologies.orient.core.tx.OTransaction) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Aggregations

OTransaction (com.orientechnologies.orient.core.tx.OTransaction)9 OLuceneIndexEngine (com.orientechnologies.lucene.engine.OLuceneIndexEngine)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)3 OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)3 OIndexEngine (com.orientechnologies.orient.core.index.OIndexEngine)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 TransientObject (io.divide.shared.transitory.TransientObject)3 OLuceneTxChanges (com.orientechnologies.lucene.tx.OLuceneTxChanges)2 OIndexEngineCallback (com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 OException (com.orientechnologies.common.exception.OException)1 OLuceneTxOperations (com.orientechnologies.lucene.OLuceneTxOperations)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)1 ORID (com.orientechnologies.orient.core.id.ORID)1 OIndexException (com.orientechnologies.orient.core.index.OIndexException)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 OTransactionOptimistic (com.orientechnologies.orient.core.tx.OTransactionOptimistic)1