Package org.spw.controller

Source Code of org.spw.controller.SequenceController

/*
* SequenceController.java
*
* Created on 30 June 2007, 13:22
*
*/

package org.spw.controller;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.FlushModeType;
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 = Persistence.createEntityManagerFactory("VolunteerPU");
   
    /** Creates a new instance of SequenceController */
    public SequenceController() {
    }
   
    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;
    }

}
TOP

Related Classes of org.spw.controller.SequenceController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.