use of javax.jdo.Transaction in project OpenRefine by OpenRefine.
the class AppEngineRefineBrokerImpl method expireLocks.
protected void expireLocks(HttpServletResponse response) throws Exception {
PersistenceManager pm = pmfInstance.getPersistenceManager();
try {
Extent<Lock> extent = pm.getExtent(Lock.class, false);
try {
for (Lock lock : extent) {
if (lock.timestamp + LOCK_DURATION < System.currentTimeMillis()) {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.deletePersistent(lock);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
}
}
} finally {
extent.closeAll();
}
respond(response, OK);
} finally {
pm.close();
}
}
use of javax.jdo.Transaction in project OpenRefine by OpenRefine.
the class AppEngineRefineBrokerImpl method obtainLock.
protected void obtainLock(HttpServletResponse response, String pid, String uid, int locktype, String lockvalue) throws Exception {
PersistenceManager pm = pmfInstance.getPersistenceManager();
try {
Lock lock = getLock(pm, pid);
if (lock == null) {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
lock = new Lock(Long.toHexString(tx.hashCode()), pid, uid);
pm.makePersistent(lock);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
}
respond(response, lockToJSON(lock));
} finally {
pm.close();
}
}
use of javax.jdo.Transaction in project OpenRefine by OpenRefine.
the class AppEngineRefineBrokerImpl method startProject.
// ----------------------------------------------------------------------------------------------------
protected void startProject(HttpServletResponse response, String pid, String uid, String lid, String data) throws Exception {
PersistenceManager pm = pmfInstance.getPersistenceManager();
try {
checkLock(pm, pid, uid, lid);
Project project = getProject(pm, pid);
if (project != null) {
throw new RuntimeException("Project '" + pid + "' already exists");
}
Transaction tx = pm.currentTransaction();
try {
tx.begin();
project = new Project(pid, data);
pm.makePersistent(project);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
respond(response, OK);
} finally {
pm.close();
}
}
use of javax.jdo.Transaction in project tutorials by eugenp.
the class GuideToJDO method QueryJPQL.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void QueryJPQL() {
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
// JPQL :
LOGGER.log(Level.INFO, "JPQL --------------------------------------------------------------");
Query q = pm.newQuery("JPQL", "SELECT p FROM " + Product.class.getName() + " p WHERE p.name = 'Laptop'");
List results = (List) q.execute();
Iterator<Product> iter = results.iterator();
while (iter.hasNext()) {
Product p = iter.next();
LOGGER.log(Level.WARNING, "Product name: {0} - Price: {1}", new Object[] { p.name, p.price });
}
LOGGER.log(Level.INFO, "--------------------------------------------------------------");
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of javax.jdo.Transaction in project tutorials by eugenp.
the class GuideToJDO method UpdateProducts.
@SuppressWarnings("rawtypes")
public void UpdateProducts() {
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query query = pm.newQuery(Product.class, "name == \"Phone\"");
Collection result = (Collection) query.execute();
Product product = (Product) result.iterator().next();
product.setName("Android Phone");
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations