use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class DAOTest method testDelete.
@Test
public void testDelete() throws Exception {
rawSave(object1, object2, object3, object4);
dao.delete(testObject1);
dao.delete(testObject4);
Collection<TransientObject> results = dao.get(testObject1Table, testObject1.getObjectKey(), testObject2.getObjectKey());
assertNotEquals(null, results);
assertEquals(1, results.size());
assertEquals(ObjectUtils.get1stOrNull(results).getObjectKey(), testObject2.getObjectKey());
Query q = new QueryBuilder().select().from(TestObject1.class).build();
results = dao.query(q);
assertNotEquals("Select All", null, results);
assertEquals("Select All", 2, results.size());
q = new QueryBuilder().select().from(TestObject2.class).build();
results = dao.query(q);
assertNotEquals("Select All", null, results);
assertEquals("Select All", 0, results.size());
}
use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class ObjectifyDAO method query.
@Override
public List<TransientObject> query(Query query) throws DAOException {
logger.info("query: " + query);
LoadType<?> filter = ofy().load().type(OfyObject.class);
com.googlecode.objectify.cmd.Query<?> oFilter = filter.filter(TransientObject.META_DATA + "." + TransientObject.OBJECT_TYPE_KEY.KEY + " =", query.getFrom());
for (Clause c : query.getWhere().values()) {
oFilter = oFilter.filter(c.getBefore() + " " + // replace CONTAINS with ==
(c.getOperand().equals(OPERAND.CONTAINS.toString()) ? OPERAND.EQ.toString() : c.getOperand()), c.getAfter());
}
if (query.getOffset() != null) {
oFilter = oFilter.offset(query.getOffset());
}
if (query.getLimit() != null) {
oFilter = oFilter.limit(query.getLimit());
}
if (query.getRandom() != null) {
int count = count(query.getFrom());
if (count < 1)
return new ArrayList<TransientObject>();
int random = RANDOM.nextInt(count);
oFilter = oFilter.offset(random);
oFilter = oFilter.limit(query.getLimit());
}
List list = null;
switch(query.getAction()) {
case SELECT:
{
if (query.getSelect() == null) {
list = oFilter.list();
List<TransientObject> toReturn = new ArrayList<TransientObject>(list.size());
try {
for (OfyObject oo : (List<OfyObject>) list) {
logger.info("Got: " + oo);
toReturn.add(BackendToOfy.getBack(oo));
}
} catch (Exception e) {
throw new DAOException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
}
list.clear();
list = toReturn;
} else if (query.getSelect().equals(SelectOperation.COUNT)) {
int count = count(query.getFrom());
return Arrays.asList((TransientObject) new Count(count, query.getFrom()));
}
}
break;
case DELETE:
{
list = oFilter.keys().list();
ofy().delete().keys(list);
int count = list.size();
list.clear();
EmptyTO o = new EmptyTO();
o.put("count", count);
list.add(o);
}
break;
case UPDATE:
{
throw new NotImplementedException();
}
}
logger.info("Query Complete: " + list);
return (List<TransientObject>) list;
}
use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class ObjectifyDAO method delete.
@Override
public void delete(TransientObject... objects) throws DAOException {
logger.info("delete: " + ObjectUtils.v2c(objects));
try {
for (TransientObject bo : objects) {
ofy().delete().key(Key.create(OfyObject.class, bo.getObjectKey())).now();
}
} catch (Exception e) {
throw new DAOException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
}
logger.info("Delete Complete.");
}
use of io.divide.shared.transitory.TransientObject 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 io.divide.shared.transitory.TransientObject 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;
}
Aggregations