Ejemplo n.º 1
0
 protected void tearDown() throws Exception {
   if (runTestsForDatastore()) {
     clean(SamplePoint.class);
     clean(SampleLineString.class);
     clean(SamplePolygon.class);
     clean(SampleGeometryCollection.class);
   }
   super.tearDown();
 }
Ejemplo n.º 2
0
 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();
     }
   }
 }