예제 #1
0
 private boolean auto(String operation) {
   long startTime = System.currentTimeMillis();
   System.out.println("Operation: " + operation + "...");
   HibernateEntityManagerFactory emf = null;
   EntityManager em = null;
   try {
     Map<String, String> map = getPeristencePropertiesFixedMap();
     if (operation != null) {
       map.put("hibernate.hbm2ddl.auto", operation);
     }
     if (operation.equals("update")) {
       if (getDriver().equals(TestStation.Driver.derby)) {
         String url = map.get("hibernate.connection.url");
         if (!url.contains("create=true")) {
           url += ";create=true";
         }
         //                    if (!url.contains("logDevice=")) {
         //                        url += ";logDevice=" + getUserHome() + File.separator +
         // ".jtstand";
         //                    }
         map.put("hibernate.connection.url", url);
       }
     }
     emf =
         (HibernateEntityManagerFactory)
             Persistence.createEntityManagerFactory(getTestProject().getPun(), map);
     //            emf.getSessionFactory().getAllClassMetadata();
     //            System.out.println(emf.getSessionFactory().getAllClassMetadata());
     em = emf.createEntityManager();
     em.getTransaction().begin();
     em.getTransaction().commit();
     //            System.out.println("Closing entity manager");
     em.close();
     //            System.out.println("Closing entity manager factory");
     emf.close();
     System.out.println(
         "Database "
             + operation
             + " operation succeeded in "
             + Long.toString(System.currentTimeMillis() - startTime)
             + "ms");
     return true;
   } catch (Exception ex) {
     ex.printStackTrace();
     System.out.println(ex.getMessage());
     if (em != null && em.isOpen()) {
       em.close();
     }
     if (emf != null && emf.isOpen()) {
       emf.close();
     }
   }
   System.out.println(
       "Database "
           + operation
           + " operation failed in "
           + Long.toString(System.currentTimeMillis() - startTime)
           + "ms");
   return false;
 }