Search in sources :

Example 1 with PersistenceManager

use of javax.jdo.PersistenceManager 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();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager)

Example 2 with PersistenceManager

use of javax.jdo.PersistenceManager in project OpenRefine by OpenRefine.

the class AppEngineRefineBrokerImpl method getHistory.

protected void getHistory(HttpServletResponse response, String pid, int tindex) throws Exception {
    PersistenceManager pm = pmfInstance.getPersistenceManager();
    try {
        Project project = getProject(pm, pid);
        Writer w = response.getWriter();
        JSONWriter writer = new JSONWriter(w);
        writer.object();
        writer.key("transformations");
        writer.array();
        int size = project.transformations.size();
        for (int i = tindex; i < size; i++) {
            writer.value(project.transformations.get(i).toString());
        }
        writer.endArray();
        writer.endObject();
        w.flush();
        w.close();
    } finally {
        pm.close();
    }
}
Also used : JSONWriter(org.json.JSONWriter) PersistenceManager(javax.jdo.PersistenceManager) JSONWriter(org.json.JSONWriter) Writer(java.io.Writer)

Example 3 with PersistenceManager

use of javax.jdo.PersistenceManager 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();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager)

Example 4 with PersistenceManager

use of javax.jdo.PersistenceManager 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();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager)

Example 5 with PersistenceManager

use of javax.jdo.PersistenceManager in project estatio by estatio.

the class IncomingInvoiceItemRepository method findDistinctReportDates.

@Programmatic
public List<LocalDate> findDistinctReportDates() {
    final PersistenceManager pm = isisJdoSupport.getJdoPersistenceManager();
    final Query query = pm.newQuery(IncomingInvoiceItem.class);
    query.setResultClass(LocalDate.class);
    query.setResult("distinct reportedDate");
    query.setOrdering("reportedDate descending");
    return executeListAndClose(query);
}
Also used : Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)1664 Transaction (javax.jdo.Transaction)1542 Query (javax.jdo.Query)671 List (java.util.List)397 JDOUserException (javax.jdo.JDOUserException)352 Collection (java.util.Collection)309 Iterator (java.util.Iterator)239 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)185 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)170 Person (org.jpox.samples.models.company.Person)146 Employee (org.jpox.samples.models.company.Employee)128 Manager (org.jpox.samples.models.company.Manager)107 HashSet (java.util.HashSet)101 ArrayList (java.util.ArrayList)85 SQLException (java.sql.SQLException)82 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)77 JDOException (javax.jdo.JDOException)74 Extent (javax.jdo.Extent)72 JDOFatalUserException (javax.jdo.JDOFatalUserException)68 JDODataStoreException (javax.jdo.JDODataStoreException)65