List of usage examples for org.hibernate.spatial.dialect.h2geodb GeoDBDialect GeoDBDialect
public GeoDBDialect()
From source file:org.n52.sos.ds.datasource.AbstractH2Datasource.java
License:Open Source License
@Override protected Dialect createDialect() { return new GeoDBDialect(); }
From source file:org.n52.sos.ds.hibernate.H2Configuration.java
License:Open Source License
public static void truncate() { synchronized (LOCK) { if (instance == null) { throw new IllegalStateException("Database is not initialized"); }/*w ww.j a v a2 s . co m*/ final Iterator<Table> tableMappings = instance.getConfiguration().getTableMappings(); final List<String> tableNames = new LinkedList<String>(); GeoDBDialect dialect = new GeoDBDialect(); while (tableMappings.hasNext()) { tableNames.add(tableMappings.next().getQuotedName(dialect)); } Session session = null; Transaction transaction = null; try { session = getSession(); transaction = session.beginTransaction(); session.doWork(new Work() { @Override public void execute(final Connection connection) throws SQLException { Statement stmt = null; try { stmt = connection.createStatement(); stmt.addBatch("SET REFERENTIAL_INTEGRITY FALSE"); for (final String table : tableNames) { stmt.addBatch("DELETE FROM " + table); } stmt.addBatch("SET REFERENTIAL_INTEGRITY TRUE"); stmt.executeBatch(); } finally { if (stmt != null) { stmt.close(); } } } }); transaction.commit(); } catch (final HibernateException e) { if (transaction != null) { transaction.rollback(); } throw e; } finally { returnSession(session); } } }
From source file:org.n52.sos.ds.hibernate.H2Configuration.java
License:Open Source License
private void prepareDatabase() { Connection conn = null;/*from w w w .j av a2s . c o m*/ Statement stmt = null; try { Class.forName(H2_DRIVER); conn = DriverManager.getConnection(H2_CONNECTION_URL); GeoDB.InitGeoDB(conn); stmt = conn.createStatement(); configuration = new Configuration().configure("/sos-hibernate.cfg.xml"); @SuppressWarnings("unchecked") List<String> resources = (List<String>) properties.get(SessionFactoryProvider.HIBERNATE_RESOURCES); for (String resource : resources) { configuration.addResource(resource); } final GeoDBDialect dialect = new GeoDBDialect(); createScript = getCreateSrcipt(configuration.generateSchemaCreationScript(dialect)); dropScript = getDropScript(configuration.generateDropSchemaScript(dialect)); for (final String s : createScript) { LOG.debug("Executing {}", s); stmt.execute(s); } } catch (final ClassNotFoundException ex) { throw new RuntimeException(ex); } catch (final SQLException ex) { throw new RuntimeException(ex); } catch (MappingException ex) { throw new RuntimeException(ex); } finally { if (stmt != null) { try { stmt.close(); } catch (final SQLException ex) { } } if (conn != null) { try { conn.close(); } catch (final SQLException ex) { } } } }
From source file:org.n52.sos.SQLScriptGenerator.java
License:Open Source License
private Dialect getDialect(int selection) throws Exception { switch (selection) { case 1:/*from w w w . ja v a2 s . co m*/ return new PostgisDialect(); case 2: try { return new OracleSpatial10gDialect(); } catch (ExceptionInInitializerError eiie) { printToScreen("The Oracle JDBC driver is missing!"); printToScreen( "To execute the SQL script generator for Oracle you have to uncomment the dependency in the pom.xml."); printToScreen("If the Oracle JDBC driver is not installed in your local Maven repository, "); printToScreen("follow the first steps describes here: "); printToScreen( "https://wiki.52north.org/bin/view/SensorWeb/SensorObservationServiceIVDocumentation#Oracle_support."); throw new MissingDriverException(); } case 3: return new GeoDBDialect(); case 4: return new MySQLSpatial5InnoDBDialect(); case 5: return new SqlServer2008SpatialDialect(); default: throw new Exception("The entered value is invalid!"); } }