/*
* SequenceController.java
*
* Created on 30 June 2007, 13:22
*
*/
package org.spw.controller;
import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
/**
* Do not use this class except to set sequence
* in case of historical data integration from legacy sysem
* @author PSe
*/
public class SequenceController {
private static EntityManagerFactory emf;
/** Creates a new instance of SequenceController */
public SequenceController() {
Properties props = PropertiesLoader.loadProperties("database.properties");
if (props != null)
{
emf = Persistence.createEntityManagerFactory("VolunteerPU", props);
}
else
{
emf = Persistence.createEntityManagerFactory("VolunteerPU");
}
}
public int setSequence(long sequence) {
int result = 0;
EntityManager em = emf.createEntityManager();
Query query = em.createNativeQuery("update SEQUENCE set SEQ_COUNT = ?1");
query.setParameter(1, sequence);
em.getTransaction().begin();
try {
result = query.executeUpdate();
em.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
if (em.getTransaction().isActive())
em.getTransaction().rollback();
} finally {
em.close();
}
return result;
}
}