Пример #1
8
 @Override
 public List<Group> findAll() {
   TypedQuery<Group> allGroupsQuery =
       em.createNamedQuery("info.galleria.domain.Group.findAllGroups", Group.class);
   List<Group> result = allGroupsQuery.getResultList();
   return result;
 }
  /**
   * Método que sirve para remover registros a la base de datos
   *
   * @param id, parametro enviado al metodo con tipo de dato: Object
   */
  public void remover(Object id) {
    try {
      EspacioFísico espacioFísico = entityManager.find(EspacioFísico.class, id);
      entityManager.remove(espacioFísico);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {

    }
  }
Пример #3
0
  public Long save(BaseEntity instance) {
    if (instance.getId() == null) {
      em.persist(instance);
    } else {
      instance = em.merge(instance);
      em.flush();
    }

    return instance.getId();
  }
Пример #4
0
  public void remove(BaseEntity instance) {
    if (em.contains(instance)) {
      em.remove(instance);
    } else {
      BaseEntity persistentInstance = em.find(instance.getClass(), instance.getId());

      if (persistentInstance != null) {
        em.remove(persistentInstance);
      }
    }
  }
  @Path("/link")
  @GET
  public String linkEmployees() {
    Department department =
        entityManager
            .createQuery("Select a From Department a where a.name = 'scala'", Department.class)
            .getSingleResult();
    Employee employee =
        entityManager
            .createQuery("Select a From Employee a where a.name = 'Captain Nemo'", Employee.class)
            .getSingleResult();

    containerTransactionBean.linkEmployeeToDepartment(employee.getId(), department.getId());

    return listEmployees();
  }
 private void initDepartmentManager() {
   Department department =
       entityManager
           .createQuery("Select a From Department a where a.name = 'scala'", Department.class)
           .getSingleResult();
   departmentManagerBean.init(department.getId());
 }
Пример #7
0
  private Query createQuery(String ql, Object... args) {
    Query query = em.createQuery(ql);

    for (int i = 0; i < args.length; i++) {
      Object arg = args[i];
      query.setParameter(1 + i, arg);
    }

    return query;
  }
  /**
   * Método que sirve para encontrarPorId registros a la base de datos
   *
   * @param id, parametro enviado al metodo con tipo de dato: Object
   * @return Tipo de retorno EspacioFísico
   */
  public EspacioFísico encontrarPorId(Object id) {
    EspacioFísico espacioFísico = null;
    try {
      espacioFísico = entityManager.find(EspacioFísico.class, id);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {

    }
    return espacioFísico;
  }
  @Path("/employee")
  @GET
  public String listEmployee() {
    Employee employee =
        entityManager
            .createQuery("Select a From Employee a where a.name = 'Captain Nemo'", Employee.class)
            .getSingleResult();

    containerTransactionBean.updateEmployee(employee);

    return listEmployees();
  }
Пример #10
0
  /**
   * Método que sirve para encontrarTodos registros a la base de datos
   *
   * @return Tipo de retorno List<EspacioFísico>
   */
  public List<EspacioFísico> encontrarTodos() {
    List<EspacioFísico> lista = null;
    try {
      TypedQuery<EspacioFísico> typedQuery =
          entityManager.createQuery("SELECT t FROM espaciofísico t ", EspacioFísico.class);
      lista = typedQuery.getResultList();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {

    }
    return lista;
  }
Пример #11
0
  /**
   * Método que sirve para totalRegistros registros a la base de datos
   *
   * @return Tipo de retorno Integer
   */
  public Integer totalRegistros() {
    Number cantidadRegistros = new Integer(0);
    try {
      cantidadRegistros =
          (Number)
              entityManager.createQuery("SELECT COUNT(t) FROM espaciofísico t ").getSingleResult();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {

    }
    return cantidadRegistros.intValue();
  }
  @Path("/list")
  @GET
  public String listEmployees() {
    String employees = "Employees are: ";
    List<Employee> resultList =
        entityManager.createQuery("Select a From Employee a", Employee.class).getResultList();

    if (resultList == null) {
      return "No employees found";
    }

    for (Employee next : resultList) {
      employees = employees + "; " + next;
    }

    return employees;
  }
Пример #13
0
 @PreDestroy
 public void destroy() {
   System.out.println("In SingletonBean::destroy()");
   try {
     javax.transaction.TransactionSynchronizationRegistry r =
         (javax.transaction.TransactionSynchronizationRegistry)
             new InitialContext().lookup("java:comp/TransactionSynchronizationRegistry");
     if (r.getTransactionStatus() != javax.transaction.Status.STATUS_ACTIVE) {
       throw new IllegalStateException(
           "Transaction status is not STATUS_ACTIVE: " + r.getTransactionStatus());
     }
     FooEntity fe = new FooEntity("FOO");
     em.persist(fe);
   } catch (Exception e) {
     throw new EJBException(e);
   }
 }
 public Collection getCategories() {
   return em.createQuery("SELECT OBJECT(c) FROM Category_1 c").getResultList();
 }
Пример #15
0
 public <T> List<T> list(Class<T> target) {
   return (List<T>)
       entityManager.createQuery("SELECT t FROM " + target.getSimpleName() + " t").getResultList();
 }
Пример #16
0
 @Asynchronous
 public void async() {
   FooEntity fe = new FooEntity("ASYNC");
   em.persist(fe);
 }
 public Collection getItems(String prodID) {
   return em.createQuery("SELECT i FROM Item i WHERE i.productID LIKE :productID")
       .setParameter("productID", prodID)
       .getResultList();
 }
Пример #18
0
 public <T> void persist(T t) {
   entityManager.persist(t);
 }
Пример #19
0
 @Override
 public Group modify(Group group) {
   em.find(Group.class, group.getGroupId());
   Group mergedGroup = em.merge(group);
   return mergedGroup;
 }
Пример #20
0
 @Override
 public Group create(Group group) {
   em.persist(group);
   return group;
 }
Пример #21
0
 /**
  * Método que sirve para actualizar registros a la base de datos
  *
  * @param espaciofísico, parametro enviado al metodo con tipo de dato: EspacioFísico
  * @return Tipo de retorno EspacioFísico
  */
 public EspacioFísico actualizar(EspacioFísico espaciofísico) {
   return entityManager.merge(espaciofísico);
 }
Пример #22
0
 @Override
 public void delete(Group group) {
   Group mergedGroup = em.merge(group);
   em.remove(mergedGroup);
 }
Пример #23
0
 /**
  * Método que sirve para insertar registros a la base de datos
  *
  * @param espaciofísico, parametro enviado al metodo con tipo de dato: EspacioFísico
  */
 public void insertar(EspacioFísico espaciofísico) {
   entityManager.persist(espaciofísico);
 }
Пример #24
0
 @Override
 public Group findById(String groupId) {
   Group group = em.find(Group.class, groupId);
   return group;
 }
Пример #25
0
 public <E extends BaseEntity> E find(Class<E> entityClass, long id) {
   return em.find(entityClass, id);
 }
Пример #26
0
 public void sayHello(Person p) {
   em.persist(p);
   fans = em.createQuery("select p from Person p").getResultList();
 }
 public Collection getProducts(String catID) {
   return em.createQuery("SELECT p FROM Product p WHERE p.categoryID LIKE :categoryID")
       .setParameter("categoryID", catID)
       .getResultList();
 }