org.hsqldb.persist.HsqlProperties Java Examples

The following examples show how to use org.hsqldb.persist.HsqlProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqoopToolDatabaseConfiguration.java    From spring-cloud-task-app-starters with Apache License 2.0 6 votes vote down vote up
@Bean(destroyMethod = "stop")
public Server databaseServer() throws SQLException, IOException {
	DriverManager.registerDriver(new org.hsqldb.jdbcDriver());
	int hsqldbPort = SocketUtils.findAvailableTcpPort(10000);
	System.setProperty("db.server.port", Integer.toString(hsqldbPort));
	logger.info("Database is using port: " + Integer.toString(hsqldbPort));
	HsqlProperties configProps = new HsqlProperties();
	configProps.setProperty("server.port", hsqldbPort);
	configProps.setProperty("server.database.0", "file:target/db/test");
	configProps.setProperty("server.dbname.0", "test");
	Server server = new org.hsqldb.Server();
	server.setLogWriter(null);
	server.setErrWriter(null);
	server.setRestartOnShutdown(false);
	server.setNoSystemExit(true);
	server.setProperties(configProps);
	server.start();
	return server;
}
 
Example #2
Source File: JdbcHdfsDatabaseConfiguration.java    From spring-cloud-task-app-starters with Apache License 2.0 6 votes vote down vote up
@Bean(destroyMethod = "stop")
public Server databaseServer() throws SQLException, IOException, ServerAcl.AclFormatException {
	DriverManager.registerDriver(new org.hsqldb.jdbcDriver());
	int hsqldbPort = SocketUtils.findAvailableTcpPort(10000);
	System.setProperty("db.server.port", Integer.toString(hsqldbPort));
	logger.info("Database is using port: " + Integer.toString(hsqldbPort));
	HsqlProperties configProps = new HsqlProperties();
	configProps.setProperty("server.port", hsqldbPort);
	configProps.setProperty("server.database.0", "file:target/db/test");
	configProps.setProperty("server.dbname.0", "test");
	Server server = new Server();
	server.setLogWriter(null);
	server.setErrWriter(null);
	server.setRestartOnShutdown(false);
	server.setNoSystemExit(true);
	server.setProperties(configProps);
	server.start();
	return server;
}
 
Example #3
Source File: Database.java    From evosql with Apache License 2.0 6 votes vote down vote up
/**
 *  Constructs a new Database object.
 *
 * @param type is the type of the database: "mem:", "file:", "res:"
 * @param path is the given path to the database files
 * @param canonicalPath is the canonical path
 * @param props property overrides placed on the connect URL
 * @exception  HsqlException if the specified name and path
 *      combination is illegal or unavailable, or the database files the
 *      name and path resolves to are in use by another process
 */
Database(DatabaseType type, String path, String canonicalPath,
         HsqlProperties props) {

    setState(Database.DATABASE_SHUTDOWN);

    this.databaseType  = type;
    this.path          = path;
    this.canonicalPath = canonicalPath;
    this.urlProperties = props;

    if (databaseType == DatabaseType.DB_RES) {
        filesInJar    = true;
        filesReadOnly = true;
    }

    logger = new Logger(this);
    shutdownOnNoConnection =
        urlProperties.isPropertyTrue(HsqlDatabaseProperties.url_shutdown);
    recoveryMode = urlProperties.getIntegerProperty(
        HsqlDatabaseProperties.url_recover, 0);
}
 
Example #4
Source File: Server.java    From evosql with Apache License 2.0 6 votes vote down vote up
/**
 * Puts properties from the supplied string argument.  The relevant
 * key value pairs are the same as those for the (web)server.properties
 * file format, except that the 'server.' prefix should not be specified.
 *
 * @param s semicolon-delimited key=value pair string,
 *      e.g. silent=false;port=8080;...
 * @throws HsqlException if this server is running
 *
 * @jmx.managed-operation
 *   impact="ACTION"
 *   description="'server.' key prefix automatically supplied"
 *
 * @jmx.managed-operation-parameter
 *   name="s"
 *   type="java.lang.String"
 *   position="0"
 *   description="semicolon-delimited key=value pairs"
 */
public void putPropertiesFromString(String s) {

    if (getState() != ServerConstants.SERVER_STATE_SHUTDOWN) {
        throw Error.error(ErrorCode.GENERAL_ERROR);
    }

    if (StringUtil.isEmpty(s)) {
        return;
    }

    printWithThread("putPropertiesFromString(): [" + s + "]");

    HsqlProperties p = HsqlProperties.delimitedArgPairsToProps(s, "=",
        ";", ServerProperties.sc_key_prefix);

    try {
        setProperties(p);
    } catch (Exception e) {
        throw Error.error(e, ErrorCode.GENERAL_ERROR,
                          ErrorCode.M_Message_Pair,
                          new String[]{ "Failed to set properties" });
    }
}
 
Example #5
Source File: ServerConfiguration.java    From evosql with Apache License 2.0 5 votes vote down vote up
/**
 * Translates the legacy default database form: database=...
 * to the 1.7.2 form: database.0=...
 *
 * @param p The properties object upon which to perform the translation
 */
public static void translateDefaultDatabaseProperty(HsqlProperties p) {

    if (p == null) {
        return;
    }

    if (!p.isPropertyTrue(ServerProperties.sc_key_remote_open_db)) {
        if (p.getProperty(ServerProperties.sc_key_database + "." + 0)
                == null) {
            String defaultdb =
                p.getProperty(ServerProperties.sc_key_database);

            if (defaultdb == null) {
                defaultdb = SC_DEFAULT_DATABASE;
            } else {
                p.removeProperty(ServerProperties.sc_key_database);
            }

            p.setProperty(ServerProperties.sc_key_database + ".0",
                          defaultdb);
            p.setProperty(ServerProperties.sc_key_dbname + ".0", "");
        }

        if (p.getProperty(ServerProperties.sc_key_dbname + "." + 0)
                == null) {
            p.setProperty(ServerProperties.sc_key_dbname + ".0", "");
        }
    }
}
 
Example #6
Source File: DatabaseManager.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new manager.
 * 
 * @param databaseDir
 *          directory to keep the files in.
 * @throws SQLException
 *           if the DAO table cannot be initialized.
 */
public DatabaseManager(File databaseDir) throws SQLException {
	pool = new Stack<Connection>();
	props = new HsqlProperties();
	props.setProperty("connection_type", "file:");
	props.setProperty("database",
			new File(databaseDir, DBNAME).getAbsolutePath());
	daos = new HashMap<Class<?>, Object>();
	daoversions = new HashMap<String, Integer>();

	Connection c = new JDBCConnection(props);
	Statement st = null;
	ResultSet res = null;
	try {
		// Load the DAO version table
		st = c.createStatement();
		st.execute("CREATE TABLE IF NOT EXISTS versions (dao VARCHAR(255), version INT)");
		st.close();

		st = c.createStatement();
		st.execute("SELECT dao, version FROM versions");
		res = st.getResultSet();
		while (res.next()) {
			daoversions.put(res.getString(1), res.getInt(2));
		}
	}
	finally {
		if (res != null) {
			res.close();
		}
		if (st != null) {
			st.close();
		}
		pool.push(c);
	}
}
 
Example #7
Source File: HsqlTestUtils.java    From CogStack-Pipeline with Apache License 2.0 5 votes vote down vote up
public static void initHSQLDBs() throws IOException, ServerAcl.AclFormatException {

       HsqlProperties p1 = new HsqlProperties();
       p1.setProperty("server.database.0", "mem:hsqldb");
       p1.setProperty("server.dbname.0", "minicogs");
       p1.setProperty("server.port", "9001");
       p1.setProperty("server.remote_open", "true");
       server1 = new Server();
       server1.setProperties(p1);
       server1.setLogWriter(null);
       server1.setErrWriter(null);
       server1.start();

       HsqlProperties p2 = new HsqlProperties();
       p2.setProperty("server.database.0", "mem:hsqldb");
       p2.setProperty("server.dbname.0", "minicogs");
       p2.setProperty("server.port", "9002");
       p2.setProperty("server.remote_open", "true");
       server2 = new Server();
       server2.setProperties(p2);
       server2.setLogWriter(null);
       server2.setErrWriter(null);
       server2.start();

       //yodieconfig
       //Properties prop = System.getProperties();
       //prop.setProperty("at.ofai.gate.modularpipelines.configFile", "/home/rich/gate-apps/yodie/yodie-pipeline/main-bio/main-bio.config.yaml");        
   }
 
Example #8
Source File: TestCacheSize.java    From evosql with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) {

        TestCacheSize  test  = new TestCacheSize();
        HsqlProperties props = HsqlProperties.argArrayToProps(argv, "test");

        test.bigops   = props.getIntegerProperty("test.bigops", test.bigops);
        test.bigrows  = test.bigops;
        test.smallops = test.bigops / 8;
        test.cacheScale = props.getIntegerProperty("test.scale",
                test.cacheScale);
        test.tableType = props.getProperty("test.tabletype", test.tableType);
        test.nioMode   = props.isPropertyTrue("test.nio", test.nioMode);

        if (props.getProperty("test.dbtype", "").equals("mem")) {
            test.filepath = "mem:test";
            test.filedb   = false;
            test.shutdown = false;
        }

        test.setUp();

        StopWatch sw = new StopWatch();

        test.testFillUp();
        test.checkResults();

        long time = sw.elapsedTime();

        test.storeResult("total test time", 0, (int) time, 0);
        System.out.println("total test time -- " + sw.elapsedTime() + " ms");
        test.tearDown();
    }
 
Example #9
Source File: ServerConfiguration.java    From evosql with Apache License 2.0 5 votes vote down vote up
/**
 * Translates unspecified no_system_exit property to false, the default
 * typically required when a Server is started from the command line.
 *
 * @param p The properties object upon which to perform the translation
 */
public static void translateDefaultNoSystemExitProperty(HsqlProperties p) {

    if (p == null) {
        return;
    }

    p.setPropertyIfNotExists(ServerProperties.sc_key_no_system_exit,
                             "false");
}
 
Example #10
Source File: HsqlDatabaseServer.java    From tessera with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {

    HsqlProperties properties = new HsqlProperties();
    for (int i = 0; i < 4; i++) {
        String db = nodeId + (i + 1);
        properties.setProperty("server.database." + i, "file:target/hsql/" + db);
        properties.setProperty("server.dbname." + i, db);
    }
    
    properties.setProperty("server.database.4", "file:target/hsql/rest-httpwhitelist5");
    properties.setProperty("server.dbname.4", "rest-httpwhitelist5");

    hsqlServer.setPort(9189);
    hsqlServer.setSilent(true);
    hsqlServer.setTrace(false);
    try{
        hsqlServer.setProperties(properties);
    } catch (IOException | ServerAcl.AclFormatException ex) {
        throw new RuntimeException(ex);
    }
    hsqlServer.start();
    if(hsqlServer.isNotRunning()) {
        throw new IllegalStateException("HSQL DB not started. ");
    }

}
 
Example #11
Source File: ServerConfiguration.java    From evosql with Apache License 2.0 5 votes vote down vote up
/**
 * Translates null or zero length value for address key to the
 * special value ServerConstants.SC_DEFAULT_ADDRESS which causes
 * ServerSockets to be constructed without specifying an InetAddress.
 *
 * @param p The properties object upon which to perform the translation
 */
public static void translateAddressProperty(HsqlProperties p) {

    if (p == null) {
        return;
    }

    String address = p.getProperty(ServerProperties.sc_key_address);

    if (StringUtil.isEmpty(address)) {
        p.setProperty(ServerProperties.sc_key_address, SC_DEFAULT_ADDRESS);
    }
}
 
Example #12
Source File: DatabaseManager.java    From evosql with Apache License 2.0 5 votes vote down vote up
/**
 * Used by in-process connections and by Servlet
 */
public static Session newSession(String type, String path, String user,
                                 String password, HsqlProperties props,
                                 String zoneString, int timeZoneSeconds) {

    Database db = getDatabase(type, path, props);

    return db.connect(user, password, zoneString, timeZoneSeconds);
}
 
Example #13
Source File: WebServer.java    From evosql with Apache License 2.0 4 votes vote down vote up
/**
 *  Starts a new WebServer.
 *
 * @param  args the "command line" parameters with which to start
 *      the WebServer.  "-?" will cause the command line arguments
 *      help to be printed to the standard output
 */
public static void main(String[] args) {

    HsqlProperties argProps = null;

    argProps = HsqlProperties.argArrayToProps(args,
            ServerProperties.sc_key_prefix);

    String[] errors = argProps.getErrorKeys();

    if (errors.length != 0) {
        System.out.println("no value for argument:" + errors[0]);
        printHelp("webserver.help");

        return;
    }

    String propsPath = argProps.getProperty(ServerProperties.sc_key_props);
    String propsExtension = "";

    if (propsPath == null) {
        propsPath      = "webserver";
        propsExtension = ".properties";
    }

    propsPath = FileUtil.getFileUtil().canonicalOrAbsolutePath(propsPath);

    ServerProperties fileProps = ServerConfiguration.getPropertiesFromFile(
        ServerConstants.SC_PROTOCOL_HTTP, propsPath, propsExtension);
    ServerProperties props =
        fileProps == null
        ? new ServerProperties(ServerConstants.SC_PROTOCOL_HTTP)
        : fileProps;

    props.addProperties(argProps);
    ServerConfiguration.translateDefaultDatabaseProperty(props);

    // Standard behaviour when started from the command line
    // is to halt the VM when the server shuts down.  This may, of
    // course, be overridden by whatever, if any, security policy
    // is in place.
    ServerConfiguration.translateDefaultNoSystemExitProperty(props);
    ServerConfiguration.translateAddressProperty(props);

    // finished setting up properties;
    Server server = new WebServer();

    try {
        server.setProperties(props);
    } catch (Exception e) {
        server.printError("Failed to set properties");
        server.printStackTrace(e);

        return;
    }

    // now messages go to the channel specified in properties
    server.print("Startup sequence initiated from main() method");

    if (fileProps != null) {
        server.print("Loaded properties from [" + propsPath
                     + ".properties]");
    } else {
        server.print("Could not load properties from file");
        server.print("Using cli/default properties only");
    }

    server.start();
}
 
Example #14
Source File: Server.java    From evosql with Apache License 2.0 4 votes vote down vote up
/**
 * Creates and starts a new Server.  <p>
 *
 * Allows starting a Server via the command line interface. <p>
 *
 * @param args the command line arguments for the Server instance
 */
public static void main(String[] args) {

    HsqlProperties argProps = null;

    argProps = HsqlProperties.argArrayToProps(args,
            ServerProperties.sc_key_prefix);

    String[] errors = argProps.getErrorKeys();

    if (errors.length != 0) {
        System.out.println("no value for argument:" + errors[0]);
        printHelp("server.help");

        return;
    }

    String propsPath = argProps.getProperty(ServerProperties.sc_key_props);
    String propsExtension = "";

    if (propsPath == null) {
        propsPath      = "server";
        propsExtension = ".properties";
    } else {
        argProps.removeProperty(ServerProperties.sc_key_props);
    }

    propsPath = FileUtil.getFileUtil().canonicalOrAbsolutePath(propsPath);

    ServerProperties fileProps = ServerConfiguration.getPropertiesFromFile(
        ServerConstants.SC_PROTOCOL_HSQL, propsPath, propsExtension);
    ServerProperties props =
        fileProps == null
        ? new ServerProperties(ServerConstants.SC_PROTOCOL_HSQL)
        : fileProps;

    props.addProperties(argProps);
    ServerConfiguration.translateDefaultDatabaseProperty(props);

    // Standard behaviour when started from the command line
    // is to halt the VM when the server shuts down.  This may, of
    // course, be overridden by whatever, if any, security policy
    // is in place.
    ServerConfiguration.translateDefaultNoSystemExitProperty(props);
    ServerConfiguration.translateAddressProperty(props);

    // finished setting up properties;
    Server server = new Server();

    try {
        server.setProperties(props);
    } catch (Exception e) {
        server.printError("Failed to set properties");
        server.printStackTrace(e);

        return;
    }

    // now messages go to the channel specified in properties
    server.print("Startup sequence initiated from main() method");

    if (fileProps != null) {
        server.print("Loaded properties from [" + propsPath
                     + propsExtension + "]");
    } else {
        server.print("Could not load properties from file");
        server.print("Using cli/default properties only");
    }

    server.start();
}
 
Example #15
Source File: Server.java    From evosql with Apache License 2.0 4 votes vote down vote up
/**
 * Initialises the database attributes lists from the server properties object.
 */
private void setDBInfoArrays() {

    IntKeyHashMap dbNumberMap  = getDBNameArray();
    int           maxDatabases = dbNumberMap.size();

    if (serverProperties.isPropertyTrue(
            ServerProperties.sc_key_remote_open_db)) {
        int max = serverProperties.getIntegerProperty(
            ServerProperties.sc_key_max_databases,
            ServerConstants.SC_DEFAULT_MAX_DATABASES);

        if (maxDatabases < max) {
            maxDatabases = max;
        }
    }

    dbAlias          = new String[maxDatabases];
    dbPath           = new String[dbAlias.length];
    dbType           = new String[dbAlias.length];
    dbID             = new int[dbAlias.length];
    dbActionSequence = new long[dbAlias.length];
    dbProps          = new HsqlProperties[dbAlias.length];

    Iterator it = dbNumberMap.keySet().iterator();

    for (int i = 0; it.hasNext(); ) {
        int    dbNumber = it.nextInt();
        String path     = getDatabasePath(dbNumber, true);

        if (path == null) {
            printWithThread("missing database path: "
                            + dbNumberMap.get(dbNumber));

            continue;
        }

        HsqlProperties dbURL = DatabaseURL.parseURL(path, false, false);

        if (dbURL == null) {
            printWithThread("malformed database path: " + path);

            continue;
        }

        dbAlias[i] = (String) dbNumberMap.get(dbNumber);
        dbPath[i]  = dbURL.getProperty("database");
        dbType[i]  = dbURL.getProperty("connection_type");
        dbProps[i] = dbURL;

        i++;
    }
}
 
Example #16
Source File: Server.java    From evosql with Apache License 2.0 4 votes vote down vote up
/**
 * Sets server properties using the specified properties object
 *
 * @param props The object containing properties to set
 * @throws ServerAcl.AclFormatException
 *          ACL list was requested but problem loading ACL.
 * @throws IOException
 *          ACL list was requested but I/O problem loading ACL.
 */
public void setProperties(HsqlProperties props)
throws IOException, ServerAcl.AclFormatException {

    checkRunning(false);

    if (props != null) {
        props.validate();

        String[] errors = props.getErrorKeys();

        if (errors.length > 0) {
            throw Error.error(ErrorCode.SERVER_NO_DATABASE, errors[0]);
        }

        serverProperties.addProperties(props);
    }

    maxConnections = serverProperties.getIntegerProperty(
        ServerProperties.sc_key_max_connections, 16);

    JavaSystem.setLogToSystem(isTrace());

    isSilent =
        serverProperties.isPropertyTrue(ServerProperties.sc_key_silent);
    isRemoteOpen = serverProperties.isPropertyTrue(
        ServerProperties.sc_key_remote_open_db);
    isDaemon =
        serverProperties.isPropertyTrue(ServerProperties.sc_key_daemon);

    String aclFilepath =
        serverProperties.getProperty(ServerProperties.sc_key_acl);

    if (aclFilepath != null) {
        acl = new ServerAcl(new File(aclFilepath));

        if (logWriter != null && !isSilent) {
            acl.setPrintWriter(logWriter);
        }
    }
}
 
Example #17
Source File: JDBCConnection.java    From evosql with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a new external <code>Connection</code> to an HSQLDB
 * <code>Database</code>. <p>
 *
 * This constructor is called on behalf of the
 * <code>java.sql.DriverManager</code> when getting a
 * <code>Connection</code> for use in normal (external)
 * client code. <p>
 *
 * Internal client code, that being code located in HSQLDB SQL
 * functions and stored procedures, receives an INTERNAL
 * connection constructed by the {@link
 * #JDBCConnection(org.hsqldb.SessionInterface)
 * JDBCConnection(SessionInterface)} constructor. <p>
 *
 * @param props A <code>Properties</code> object containing the connection
 *      properties
 * @exception SQLException when the user/password combination is
 *     invalid, the connection url is invalid, or the
 *     <code>Database</code> is unavailable. <p>
 *
 *     The <code>Database</code> may be unavailable for a number
 *     of reasons, including network problems or the fact that it
 *     may already be in use by another process.
 */
public JDBCConnection(HsqlProperties props) throws SQLException {

    String user     = props.getProperty("user");
    String password = props.getProperty("password");
    String connType = props.getProperty("connection_type");
    String host     = props.getProperty("host");
    int    port     = props.getIntegerProperty("port", 0);
    String path     = props.getProperty("path");
    String database = props.getProperty("database");
    boolean isTLS = (DatabaseURL.S_HSQLS.equals(connType)
                     || DatabaseURL.S_HTTPS.equals(connType));
    boolean isTLSWrapper = props.isPropertyTrue(HsqlDatabaseProperties.url_tls_wrapper, false);

    isTLSWrapper &= isTLS;

    if (user == null) {
        user = "SA";
    }

    if (password == null) {
        password = "";
    }

    Calendar cal         = Calendar.getInstance();
    int      zoneSeconds = HsqlDateTime.getZoneSeconds(cal);

    try {
        if (DatabaseURL.isInProcessDatabaseType(connType)) {

            /**
             * @todo - fredt - this should be the only static reference to
             * a core class (apart form references to the Type package)
             * from the jdbc package - we might make it dynamic
             */
            sessionProxy = DatabaseManager.newSession(connType, database,
                    user, password, props, null, zoneSeconds);
        } else if (DatabaseURL.S_HSQL.equals(connType)
                   || DatabaseURL.S_HSQLS.equals(connType)) {
            sessionProxy = new ClientConnection(host, port, path,
                    database, isTLS, isTLSWrapper, user, password, zoneSeconds);
            isNetConn = true;
        } else if (DatabaseURL.S_HTTP.equals(connType)
                   || DatabaseURL.S_HTTPS.equals(connType)) {
            sessionProxy = new ClientConnectionHTTP(host, port, path,
                    database, isTLS, isTLSWrapper, user, password, zoneSeconds);
            isNetConn = true;
        } else {    // alias: type not yet implemented
            throw JDBCUtil.invalidArgument(connType);
        }
        sessionProxy.setJDBCConnection(this);

        connProperties   = props;
        clientProperties = sessionProxy.getClientProperties();

        setLocalVariables();
    } catch (HsqlException e) {
        throw JDBCUtil.sqlException(e);
    }
}
 
Example #18
Source File: Database.java    From evosql with Apache License 2.0 4 votes vote down vote up
public HsqlProperties getURLProperties() {
    return urlProperties;
}
 
Example #19
Source File: DatabaseManager.java    From evosql with Apache License 2.0 4 votes vote down vote up
private static synchronized Database getDatabaseObject(DatabaseType type,
        String path, HsqlProperties props) {

    Database db;
    String   key = path;
    HashMap  databaseMap;

    switch (type) {

        case DB_FILE : {
            databaseMap = fileDatabaseMap;
            key         = filePathToKey(path);
            db          = (Database) databaseMap.get(key);

            if (db == null) {
                if (databaseMap.size() > 0) {
                    Iterator it = databaseMap.keySet().iterator();

                    while (it.hasNext()) {
                        String current = (String) it.next();

                        if (key.equalsIgnoreCase(current)) {
                            key = current;

                            break;
                        }
                    }
                }
            }

            break;
        }
        case DB_RES : {
            databaseMap = resDatabaseMap;

            break;
        }
        case DB_MEM : {
            databaseMap = memDatabaseMap;

            break;
        }
        default :
            throw Error.runtimeError(ErrorCode.U_S0500, "DatabaseManager");
    }

    db = (Database) databaseMap.get(key);

    if (db == null) {
        db            = new Database(type, path, key, props);
        db.databaseID = dbIDCounter;

        synchronized (databaseIDMap) {
            databaseIDMap.put(dbIDCounter, db);

            dbIDCounter++;
        }

        databaseMap.put(key, db);
    }

    return db;
}
 
Example #20
Source File: DatabaseManager.java    From evosql with Apache License 2.0 4 votes vote down vote up
/**
 * This has to be improved once a threading model is in place.
 * Current behaviour:
 *
 * Attempts to connect to different databases do not block. Two db's can
 * open simultaneously.
 *
 * Attempts to connect to a db while it is opening or closing will block
 * until the db is open or closed. At this point the db state is either
 * DATABASE_ONLINE (after db.open() has returned) which allows a new
 * connection to be made, or the state is DATABASE_SHUTDOWN which means
 * the db can be reopened for the new connection).
 *
 */
public static Database getDatabase(String dbtype, String path,
                                   HsqlProperties props) {

    // If the (type, path) pair does not correspond to a registered
    // instance, then getDatabaseObject() returns a newly constructed
    // and registered Database instance.
    // The database state will be DATABASE_SHUTDOWN,
    // which means that the switch below will attempt to
    // open the database instance.
    DatabaseType type = DatabaseType.get(dbtype);
    Database     db   = getDatabaseObject(type, path, props);

    synchronized (db) {
        switch (db.getState()) {

            case Database.DATABASE_ONLINE :
                break;

            case Database.DATABASE_SHUTDOWN :

                // if the database was shutdown while this attempt
                // was waiting, add the database back to the registry
                if (lookupDatabaseObject(type, path) == null) {
                    addDatabaseObject(type, path, db);
                }

                db.open();
                break;

            // This state will currently not be reached as Database.Close() is
            // called while a lock is held on the database.
            // If we remove the lock from this method and a database is
            // being shutdown by a thread and in the meantime another thread
            // attempts to connect to the db. The threads could belong to
            // different server instances or be in-process.
            case Database.DATABASE_CLOSING :

            // this case will not be reached as the state is set and
            // cleared within the db.open() call above, which is called
            // from this synchronized block
            // it is here simply as a placeholder for future development
            case Database.DATABASE_OPENING :
                throw Error.error(ErrorCode.LOCK_FILE_ACQUISITION_FAILURE,
                                  ErrorCode.M_DatabaseManager_getDatabase);
        }
    }

    return db;
}
 
Example #21
Source File: HsqldbServer.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new instance of HSQLDB server.
 */
HsqldbServer() {
    catalogOptionLine = "";
    hsqlProperties = new HsqlProperties();
}
 
Example #22
Source File: HsqldbServer.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
@VisibleForTesting
HsqlProperties getHsqlProperties() {
    return hsqlProperties;
}
 
Example #23
Source File: DatabaseInformationMain.java    From evosql with Apache License 2.0 4 votes vote down vote up
/**
 * getClientInfoProperties
 *
 * @return Result
 *
 * <li><b>NAME</b> String=> The name of the client info property<br>
 * <li><b>MAX_LEN</b> int=> The maximum length of the value for the property<br>
 * <li><b>DEFAULT_VALUE</b> String=> The default value of the property<br>
 * <li><b>DESCRIPTION</b> String=> A description of the property.  This will typically
 *                                                  contain information as to where this property is
 *                                                  stored in the database.
 */
final Table SYSTEM_CONNECTION_PROPERTIES(Session session,
        PersistentStore store) {

    Table t = sysTables[SYSTEM_CONNECTION_PROPERTIES];

    if (t == null) {
        t = createBlankTable(
            sysTableHsqlNames[SYSTEM_CONNECTION_PROPERTIES]);

        addColumn(t, "NAME", SQL_IDENTIFIER);
        addColumn(t, "MAX_LEN", Type.SQL_INTEGER);
        addColumn(t, "DEFAULT_VALUE", SQL_IDENTIFIER);    // not null
        addColumn(t, "DESCRIPTION", SQL_IDENTIFIER);      // not null

        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
            sysTableHsqlNames[SYSTEM_CONNECTION_PROPERTIES].name, false,
            SchemaObject.INDEX);

        t.createPrimaryKeyConstraint(name, new int[]{ 0 }, true);

        return t;
    }

    Object[] row;

    // column number mappings
    final int iname          = 0;
    final int imax_len       = 1;
    final int idefault_value = 2;
    final int idescription   = 3;
    Iterator  it = HsqlDatabaseProperties.getPropertiesMetaIterator();

    while (it.hasNext()) {
        Object[] meta = (Object[]) it.next();
        int propType =
            ((Integer) meta[HsqlProperties.indexType]).intValue();

        if (propType == HsqlDatabaseProperties.FILE_PROPERTY) {
            if (HsqlDatabaseProperties.hsqldb_readonly.equals(
                    meta[HsqlProperties.indexName]) || HsqlDatabaseProperties
                        .hsqldb_files_readonly.equals(
                            meta[HsqlProperties.indexName])) {}
            else {
                continue;
            }
        } else if (propType != HsqlDatabaseProperties.SQL_PROPERTY) {
            continue;
        }

        row = t.getEmptyRowData();

        Object def = meta[HsqlProperties.indexDefaultValue];

        row[iname]          = meta[HsqlProperties.indexName];
        row[imax_len]       = ValuePool.getInt(8);
        row[idefault_value] = def == null ? null
                                          : def.toString();
        row[idescription]   = "see HyperSQL guide";

        t.insertSys(session, store, row);
    }

    return t;
}
 
Example #24
Source File: DatabaseManager.java    From evosql with Apache License 2.0 3 votes vote down vote up
/**
 * Used by server to open or create a database
 */
public static int getDatabase(String type, String path, Notified server,
                              HsqlProperties props) {

    Database db = getDatabase(type, path, props);

    registerServer(server, db);

    return db.databaseID;
}
 
Example #25
Source File: HsqldbServer.java    From scheduling with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Creates a new instance of HSQLDB server.
 *
 * @param configuration the path to the HSQLDB server properties file.
 *
 * @throws IOException if an error occurs while reading the configuration file.
 */
public HsqldbServer(Path configuration) throws IOException {

    Properties hsqldbServerProperties = loadProperties(configuration);

    catalogOptionLine = hsqldbServerProperties.getProperty(PROP_HSQLDB_SERVER_CATALOGS_OPTION_LINE);
    hsqldbServerProperties.remove(PROP_HSQLDB_SERVER_CATALOGS_OPTION_LINE);

    hsqlProperties = new HsqlProperties(hsqldbServerProperties);
}
 
Example #26
Source File: SessionInterface.java    From evosql with Apache License 2.0 votes vote down vote up
HsqlProperties getClientProperties();