Java Code Examples for org.hsqldb.persist.HsqlProperties#getProperty()

The following examples show how to use org.hsqldb.persist.HsqlProperties#getProperty() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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();
}