Exemplo n.º 1
0
  /** @param args */
  public static void main(String[] args) {
    EntityManagerFactory emf = null;
    EntityManager em = null;

    Map<String, String> properties = new HashMap<String, String>();

    properties.put(DDL_GENERATION, DROP_AND_CREATE);
    properties.put(DDL_GENERATION_MODE, DDL_BOTH_GENERATION);
    properties.put(TARGET_DATABASE, TargetDatabase.Oracle);

    emf = PersistenceService.createEMF(properties, true, new EclipseLinkServiceFactory(), true);
    em = emf.createEntityManager();
    em.close();
    emf.close();
  }
  public static void main(String[] args) throws Exception {
    HashMap map = new HashMap();
    // map.put("hibernate.show_sql", "true");
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("titan", map);
    EntityManager entityManager = factory.createEntityManager();
    entityManager.getTransaction().begin();
    try {
      System.out.println("Initialize DB");
      InitializeDB.initialize(entityManager);
      System.out.println();
      System.out.println();

      System.out.println("Find Bill Burke by named parameter");
      Customer cust = findCustomerByNamedParameter(entityManager, "Bill", "Burke");
      System.out.println("Bill Burke's cust id: " + cust.getId());
      System.out.println();
      System.out.println();

      System.out.println("Find Gavin King by indexed parameter");
      cust = findCustomerByIndexedParameter(entityManager, "Gavin", "King");
      System.out.println("Gavin King's cust id: " + cust.getId());
      System.out.println();
      System.out.println();

      System.out.println("Output all customers via paging");
      List results;
      int first = 0;
      int max = 2;
      do {
        results = getCustomers(entityManager, max, first);
        Iterator it = results.iterator();
        while (it.hasNext()) {
          Customer c = (Customer) it.next();
          System.out.println(c.getFirstName() + " " + c.getLastName());
        }
        entityManager.clear();
        first = first + results.size();
      } while (results.size() > 0);
    } finally {
      entityManager.getTransaction().commit();
      entityManager.close();
      factory.close();
    }
  }
Exemplo n.º 3
0
 /** Close all entity manager factories. */
 public void shutdown() {
   for (EntityManagerFactory emf : emfs.values()) {
     emf.close();
   }
 }
Exemplo n.º 4
0
 public void close() {
   emConfig.close();
   emfConfig.close();
 }