Example usage for javax.persistence Persistence createEntityManagerFactory

List of usage examples for javax.persistence Persistence createEntityManagerFactory

Introduction

In this page you can find the example usage for javax.persistence Persistence createEntityManagerFactory.

Prototype

public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName) 

Source Link

Document

Create and return an EntityManagerFactory for the named persistence unit.

Usage

From source file:Logica.Usuario.java

/**
 *
 * @param idUsuario//from  w w  w . j a  v  a  2s .  c  om
 * @param idRecurso
 * @param tipoRecurso
 * @return
 * @throws RemoteException
 */
@Override
public boolean ocultar(String idUsuario, String idRecurso, String tipoRecurso) throws RemoteException {
    try {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
        EntityManager em = emf.createEntityManager();
        Query q = em.createNamedQuery("Tablamostrar.findByAllParameters");
        q.setParameter("idU", idUsuario);
        q.setParameter("idA", new Double(idRecurso));
        q.setParameter("tipoA", tipoRecurso);
        List<Tablamostrar> resultList = q.getResultList();
        Integer idMostrar = resultList.get(0).getIdMostrar();
        TablamostrarJpaController controller = new TablamostrarJpaController(emf);
        Tablamostrar found = controller.findTablamostrar(idMostrar);
        found.setMostrar("NO");
        controller.edit(found);
        return true;
    } catch (Exception ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
}

From source file:org.jbpm.bpmn2.IntermediateEventTest.java

@Test
@RequirePersistence//from  ww w . j a va2s .  co  m
public void testEventTypesLifeCycle() throws Exception {
    // JBPM-4246
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2");
    EntityManagerFactory separateEmf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
    Environment env = createEnvironment(separateEmf);
    ksession = createKnowledgeSession(kbase, null, env);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
    ksession.startProcess("BPMN2-IntermediateCatchSignalBetweenUserTasks");

    int signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
        public Integer execute(Context context) {
            SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession)
                    .getRunner();
            InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
            ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime
                    .getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
            ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();

            List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
            return processInstancesToSignalList.size();
        }
    });

    // Process instance is not waiting for signal
    assertThat(signalListSize).isEqualTo(0);

    ksession.getWorkItemManager().completeWorkItem(1, null);

    signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
        public Integer execute(Context context) {
            SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession)
                    .getRunner();
            InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
            ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime
                    .getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
            ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();

            List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
            return processInstancesToSignalList.size();
        }
    });

    // Process instance is waiting for signal now
    assertThat(signalListSize).isEqualTo(1);

    ksession.signalEvent("MySignal", null);

    signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
        public Integer execute(Context context) {
            SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession)
                    .getRunner();
            InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
            ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime
                    .getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
            ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();

            List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
            return processInstancesToSignalList.size();
        }
    });

    // Process instance is not waiting for signal
    assertThat(signalListSize).isEqualTo(0);

    ksession.getWorkItemManager().completeWorkItem(2, null);

    ksession.dispose();
    ksession = null;
    separateEmf.close();
}

From source file:Logica.Usuario.java

/**
 *
 * @param mes/*from w w w  . j a v  a  2 s . co m*/
 * @return
 * @throws RemoteException
 *
 * Genera el informe de descargos de acuerdo al mes ingresado
 */
@Override
public ArrayList<informeDescargos> generarInforme(String mes) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    String statement = "create view gInforme1 as(select i.CINTERNO, i.INVENTARIO, i.DESCRIPCION, i.CANTIDAD as enInventario, d.FECHA as fecha, (select nombre from usuario where id = d.id_usuario) as nombre ,d.id_usuario as id, d.AREA\n"
            + "from item  i right outer join DESCARGO d\n" + "on i.CINTERNO = d.CINTERNO);";
    String statement2 = "create view gInforme2 as( select cinterno, inventario, descripcion, eninventario, fecha, nombre, id, area from gInforme1 where gInforme1.fecha like ?);";
    String statement3 = "create view gInforme3 as(select d.CINTERNO, \"\",sum(d.cantidad) as suma from descargo d, descargo dd where dd.id= d.id group by d.CINTERNO);";
    String statement4 = "select distinct  p2.cinterno, p2.inventario, p2.descripcion, p2.eninventario, p3.suma, p2.nombre, p2.id, p2.area\n"
            + " from gInforme2 p2 , gInforme3 p3 where p2.cinterno = p3.CINTERNO; ";
    informeDescargos fila = null;
    ArrayList<informeDescargos> listado = new ArrayList<>();

    System.out.println(statement);
    System.out.println(statement2);
    System.out.println(statement3);
    System.out.println(statement4);
    try {
        con = Conexion.conexion.getConnection();
        mes = "%-" + mes + "-%";
        ps = con.prepareStatement(statement);
        ps.executeUpdate();
        ps = con.prepareStatement(statement2);
        ps.setString(1, mes);
        ps.executeUpdate();
        ps = con.prepareStatement(statement3);
        ps.executeUpdate();
        ps = con.prepareStatement(statement4);
        rs = ps.executeQuery();
        while (rs.next()) {
            fila = new informeDescargos(rs.getString(1), rs.getString(2), rs.getString(3), rs.getFloat(4),
                    rs.getFloat(5), rs.getString(6), rs.getBigDecimal(7), rs.getString(8));
            listado.add(fila);
        }
        ps.executeUpdate("drop view gInforme1;");
        ps.executeUpdate("drop view gInforme2;");
        ps.executeUpdate("drop view gInforme3;");

    } catch (SQLException ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

        try {
            if (ps != null) {
                ps.close();
            }
            if (rs != null) {
                rs.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException ex) {
            System.out.println("Error cerrando conexion");
        }
    }
    return listado;
}

From source file:Logica.Usuario.java

@Override
public ArrayList<informeDescargos> generarInformePorLab(String mes) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    Connection con = null;//from   www. ja va2s. com
    PreparedStatement ps = null;
    ResultSet rs = null;
    String statement = "select D.CINTERNO, \"-\", item.DESCRIPCION, item.CANTIDAD, sum(D.CANTIDAD) \n"
            + "from item right outer join DESCARGO d\n" + "on item.CINTERNO = D.CINTERNO and d.FECHA like ?\n"
            + "group by D.CINTERNO, item.DESCRIPCION, item.CANTIDAD\n" + "order by D.CINTERNO";
    informeDescargos fila = null;
    System.out.println(statement);
    ArrayList<informeDescargos> listado = new ArrayList<>();
    try {
        con = Conexion.conexion.getConnection();
        mes = "%-" + mes + "-%";
        ps = con.prepareStatement(statement);
        ps.setString(1, mes);
        rs = ps.executeQuery();
        while (rs.next()) {
            fila = new informeDescargos(rs.getString(1), rs.getString(2), rs.getString(3), rs.getFloat(4),
                    rs.getFloat(5));
            listado.add(fila);
            System.out.println(fila.getCinterno());
            System.out.println(fila.getEninventario());
            System.out.println(fila.getInventario());
            System.out.println(fila.getDescripcion());
            System.out.println(fila.getEmpleado());

        }
    } catch (SQLException ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

        try {
            if (ps != null) {
                ps.close();
            }
            if (rs != null) {
                rs.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException ex) {
            System.out.println("Error cerrando conexion");
        }
    }
    return listado;
}

From source file:Logica.Usuario.java

@Override
public ArrayList<informeDescargos> generarInformePorRA(String area, BigDecimal id) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    Connection con = null;//from w w w  .  j  a  v  a  2s . co m
    PreparedStatement ps = null;
    ResultSet rs = null;
    String statement = "select D.CINTERNO, \"-\", item.DESCRIPCION, item.CANTIDAD, sum(D.CANTIDAD), D.FECHA\n"
            + "from item, DESCARGO d\n" + "where item.CINTERNO = D.CINTERNO and D.ID_usuario = ?\n"
            + "group by D.CINTERNO, item.DESCRIPCION, item.CANTIDAD, D.FECHA";
    informeDescargos fila = null;
    System.out.println(statement);
    ArrayList<informeDescargos> listado = new ArrayList<>();
    try {
        con = Conexion.conexion.getConnection();
        ps = con.prepareStatement(statement);
        ps.setBigDecimal(1, id);
        rs = ps.executeQuery();
        while (rs.next()) {
            GregorianCalendar c = new GregorianCalendar();
            c.setTime(rs.getDate(6));
            fila = new informeDescargos(rs.getString(1), rs.getString(2), rs.getString(3), rs.getFloat(4),
                    rs.getFloat(5), c);
            listado.add(fila);

        }
    } catch (SQLException ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

        try {
            if (ps != null) {
                ps.close();
            }
            if (rs != null) {
                rs.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException ex) {
            System.out.println("Error cerrando conexion");
        }
    }
    return listado;
}

From source file:Logica.Usuario.java

/**
 *
 * @param cinterno/*from  w w w .j  ava  2  s .  co m*/
 * @param cantidad
 * @return
 * @throws RemoteException
 *
 * Actualiza la cantidad de un tem en particular.
 */
@Override
public boolean updateCantidad(String cinterno, float cantidad) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    String statement = "update item set cantidad = cantidad +? where CINTERNO =?";
    boolean updated = false;
    try {
        con = Conexion.conexion.getConnection();
        ps = con.prepareStatement(statement);
        ps.setFloat(1, cantidad);
        ps.setString(2, cinterno);
        ps.executeUpdate();
        updated = true;

    } catch (SQLException ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

        try {
            if (ps != null) {
                ps.close();
            }
            if (rs != null) {
                rs.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException ex) {
            System.out.println("Error cerrando conexion");
        }
    }
    return updated;
}

From source file:Logica.Usuario.java

@Override
public boolean editarFormato(int formato, datosFormatos datos) throws RemoteException {
    boolean hecho = false;
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    DatosformatosJpaController controller = new DatosformatosJpaController(emf);
    Datosformatos found = controller.findDatosformatos(formato);
    found.setRevision(datos.getRevision());
    found.setFechaactualizacion(datos.getFechaActualizacion());
    found.setTitulo(datos.getTitulo());/*from  w w  w.  ja v  a2s  . c om*/
    try {
        controller.edit(found);
        hecho = true;
    } catch (Exception ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    }
    return hecho;
}