Search in sources :

Example 1 with Server

use of org.hsqldb.Server in project hadoop-book by elephantscale.

the class DBCountPageView method startHsqldbServer.

private void startHsqldbServer() {
    server = new Server();
    server.setDatabasePath(0, System.getProperty("test.build.data", ".") + "/URLAccess");
    server.setDatabaseName(0, "URLAccess");
    server.start();
}
Also used : Server(org.hsqldb.Server)

Example 2 with Server

use of org.hsqldb.Server in project gora by apache.

the class GoraSqlTestDriver method startHsqldbServer.

private void startHsqldbServer() {
    log.info("Starting HSQLDB server");
    server = new Server();
    server.setDatabasePath(0, System.getProperty("test.build.data", "/tmp") + "/goratest");
    server.setDatabaseName(0, "goratest");
    server.setDaemon(true);
    server.setPort(Integer.parseInt(HSQLDB_PORT));
    server.start();
}
Also used : Server(org.hsqldb.Server)

Example 3 with Server

use of org.hsqldb.Server in project yyl_example by Relucent.

the class HsqldbServer method start.

// ==============================Methods==========================================
public void start() {
    try {
        Server server = new Server();
        server.setDatabasePath(0, path + "/" + databaseName);
        server.setDatabaseName(0, databaseName);
        server.setPort(port);
        server.setSilent(true);
        server.start();
        Thread.sleep(WAIT_TIME);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Server(org.hsqldb.Server)

Example 4 with Server

use of org.hsqldb.Server in project tomee by apache.

the class HsqlService method init.

@Override
public void init(final Properties p) throws Exception {
    final Properties properties = new Properties();
    for (final Map.Entry<Object, Object> entry : p.entrySet()) {
        // Sometimes the properties object has non string values
        if (!(entry.getKey() instanceof String))
            continue;
        if (!(entry.getValue() instanceof String))
            continue;
        final String property = (String) entry.getKey();
        final String value = (String) entry.getValue();
        if (property.startsWith(sc_key_dbname + ".") || property.startsWith(sc_key_database + ".")) {
            throw new ServiceException("Databases cannot be declared in the hsql.properties.  " + "Instead declare a database connection in the openejb.conf file");
        }
        if ("port".equals(property)) {
            properties.setProperty(sc_key_port, value);
        } else if ("bind".equals(property)) {
            properties.setProperty(sc_key_address, value);
        } else {
            properties.setProperty(property, value);
        }
    }
    properties.setProperty(sc_key_no_system_exit, "true");
    final boolean disabled = Boolean.parseBoolean(properties.getProperty("disabled"));
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    if (!disabled && containerSystem != null) {
        final NamingEnumeration<Binding> bindings;
        try {
            bindings = containerSystem.getJNDIContext().listBindings("openejb/Resource/");
            final Set<String> dbnames = new TreeSet<String>();
            for (final Binding binding : Collections.list(bindings)) {
                final Object value = binding.getObject();
                if (value instanceof DataSource) {
                    final DataSource jdbc = (DataSource) value;
                    Connection connection = null;
                    String path = null;
                    try {
                        connection = jdbc.getConnection();
                        final DatabaseMetaData meta = connection.getMetaData();
                        path = getPath(meta.getDriverName(), meta.getURL());
                    } catch (Throwable t) {
                        continue;
                    } finally {
                        if (connection != null) {
                            try {
                                connection.close();
                            } catch (SQLException sqlEx) {
                            // no-op
                            }
                        }
                    }
                    if (path != null) {
                        if (dbnames.size() > 9) {
                            throw new ServiceException("Hsql Server can only host 10 database instances");
                        }
                        String dbname = path.substring(path.lastIndexOf(':') + 1);
                        dbname = dbname.substring(dbname.lastIndexOf('/') + 1);
                        if (!dbnames.contains(dbname)) {
                            properties.put(sc_key_dbname + "." + dbnames.size(), dbname);
                            properties.put(sc_key_database + "." + dbnames.size(), path);
                            dbnames.add(dbname);
                        }
                    }
                }
            }
        } catch (NameNotFoundException e) {
        //Ignore
        }
        // create the server
        server = new Server();
        // add the silent property
        properties.setProperty(sc_key_silent, "true");
        // set the log and error writers
        server.setLogWriter(new HsqlPrintWriter(false));
        server.setErrWriter(new HsqlPrintWriter(true));
        server.setProperties(new HsqlProperties(properties));
        // get the port
        port = server.getPort();
        // get the Address
        final String ipString = server.getAddress();
        if (ipString != null && ipString.length() > 0) {
            this.ip = ipString;
        }
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Binding(javax.naming.Binding) Server(org.hsqldb.Server) SQLException(java.sql.SQLException) NameNotFoundException(javax.naming.NameNotFoundException) Connection(java.sql.Connection) Properties(java.util.Properties) HsqlProperties(org.hsqldb.persist.HsqlProperties) HsqlDatabaseProperties(org.hsqldb.persist.HsqlDatabaseProperties) DatabaseMetaData(java.sql.DatabaseMetaData) DataSource(javax.sql.DataSource) ServiceException(org.apache.openejb.server.ServiceException) TreeSet(java.util.TreeSet) HsqlProperties(org.hsqldb.persist.HsqlProperties) Map(java.util.Map)

Aggregations

Server (org.hsqldb.Server)4 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 Map (java.util.Map)1 Properties (java.util.Properties)1 TreeSet (java.util.TreeSet)1 Binding (javax.naming.Binding)1 NameNotFoundException (javax.naming.NameNotFoundException)1 DataSource (javax.sql.DataSource)1 ServiceException (org.apache.openejb.server.ServiceException)1 ContainerSystem (org.apache.openejb.spi.ContainerSystem)1 HsqlDatabaseProperties (org.hsqldb.persist.HsqlDatabaseProperties)1 HsqlProperties (org.hsqldb.persist.HsqlProperties)1