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);
}
}
}
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;
}
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();
}
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;
}
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));
}
Aggregations