protected void setUp() throws Exception {
   super.setUp();
   if (runTestsForDatastore()) {
     PersistenceManager pm = pmf.getPersistenceManager();
     Transaction tx = pm.currentTransaction();
     try {
       tx.begin();
       pm.newQuery(SamplePoint.class).deletePersistentAll();
       pm.newQuery(SampleLineString.class).deletePersistentAll();
       pm.newQuery(SamplePolygon.class).deletePersistentAll();
       pm.newQuery(SampleGeometryCollection.class).deletePersistentAll();
     } finally {
       tx.commit();
     }
     Connection sqlConn = null;
     try {
       tx.begin();
       sqlConn = (Connection) pm.getDataStoreConnection();
       String connUrl = pmf.getConnectionURL().toLowerCase();
       String fileName = "sample_jts_postgis.sql";
       if (connUrl.contains("mysql") || connUrl.contains("mariadb")) {
         fileName = "sample_jts_mysql.sql";
       }
       File file =
           new File(
               PgGeometryMySQLTest.class
                   .getResource("/org/datanucleus/samples/data/" + fileName)
                   .toURI());
       String s = "";
       InputStream is = new FileInputStream(file);
       int c;
       while ((c = is.read()) != -1) {
         s += (char) c;
       }
       String ss[] = StringUtils.split(s, ";");
       for (int i = 0; i < ss.length; i++) {
         sqlConn.createStatement().execute(ss[i]);
       }
       is.close();
     } finally {
       sqlConn.close();
       tx.commit();
     }
   }
 }
 public static String insertarSucursal(String clavePublica, Sucursal bean)
     throws UnknownException {
   PersistenceManager pm = null;
   Connection cnx = null;
   try {
     String keypublic = StringHex.convertHexToString(clavePublica);
     pm = PMF.getClassPMF().getPMF(keypublic).getPersistenceManager();
     if (!pm.isClosed()) {
       LogicSucursal logic = new LogicSucursal(pm);
       JDOConnection cnxJDO = pm.getDataStoreConnection();
       cnx = (Connection) cnxJDO.getNativeConnection();
       cnx.setAutoCommit(false);
       List<String> array = (List) logic.insertarSucursal(cnx, bean);
       cnx.commit();
       cnx.close();
       return array.get(0);
     } else {
       throw new UnknownException("Conexión expiró/nvuelva a iniciar sesión");
     }
   } catch (UnknownException ex) {
     throw new UnknownException(ex.getMessage());
   } catch (SQLException ex) {
     throw new UnknownException(ex.getMessage());
   } finally {
     if (cnx != null) {
       try {
         if (!cnx.isClosed()) {
           cnx.rollback();
           cnx.close();
         }
       } catch (SQLException ex) {
         Logger.getLogger(MantenimientoPrecioItem.class.getName()).log(Level.SEVERE, null, ex);
         throw new UnknownException(ex.getMessage());
       }
     }
     if (!pm.isClosed()) {
       pm.close();
     }
   }
 }
 public static List<CondicionVenta> listarxVigenciaCredito(
     String clavePublica, Integer vigenciaCredito) throws UnknownException {
   PersistenceManager pm = null;
   Connection cnx = null;
   try {
     String keypublic = StringHex.convertHexToString(clavePublica);
     pm = PMF.getClassPMF().getPMF(keypublic).getPersistenceManager();
     if (!pm.isClosed()) {
       LogicCondicionVenta logic = new LogicCondicionVenta(pm);
       JDOConnection cnxJDO = pm.getDataStoreConnection();
       cnx = (Connection) cnxJDO.getNativeConnection();
       List<CondicionVenta> lista =
           (List) logic.getListarBeanXvigenciaCredito(cnx, vigenciaCredito);
       cnx.close();
       return lista;
     } else {
       throw new UnknownException("Conexión expiró/nvuelva a iniciar sesión");
     }
   } catch (UnknownException ex) {
     throw new UnknownException(ex.getMessage());
   } catch (Exception ex) {
     throw new UnknownException(ex.getMessage());
   } finally {
     if (cnx != null) {
       try {
         if (!cnx.isClosed()) {
           cnx.close();
         }
       } catch (SQLException ex) {
         Logger.getLogger(MantenimientoCondicionVenta.class.getName()).log(Level.SEVERE, null, ex);
         throw new UnknownException(ex.getMessage());
       }
     }
     if (!pm.isClosed()) {
       pm.close();
     }
   }
 }
 /** Non-API. */
 public Connection getJavaSqlConnection() {
   return (Connection) persistenceManager.getDataStoreConnection().getNativeConnection();
 }