Search in sources :

Example 1 with HsqlDatabaseProperties

use of org.hsqldb_voltpatches.persist.HsqlDatabaseProperties in project voltdb by VoltDB.

the class ParserCommand method compileSetProperty.

private Statement compileSetProperty() {
    read();
    String property;
    Object value;
    HsqlDatabaseProperties props;
    checkIsSimpleName();
    checkIsDelimitedIdentifier();
    property = token.tokenString;
    props = database.getProperties();
    boolean isboolean = props.isBoolean(token.tokenString);
    boolean isintegral = props.isIntegral(token.tokenString);
    boolean isstring = props.isString(token.tokenString);
    if (!(isboolean || isintegral || isstring)) {
        throw Error.error(ErrorCode.X_42511);
    }
    int typeCode = isboolean ? Types.SQL_BOOLEAN : isintegral ? Types.SQL_INTEGER : Types.SQL_CHAR;
    read();
    if (token.tokenType == Tokens.TRUE) {
        value = Boolean.TRUE;
    } else if (token.tokenType == Tokens.FALSE) {
        value = Boolean.FALSE;
    } else {
        checkIsValue();
        value = token.tokenValue;
        if (token.dataType.typeCode != typeCode) {
            throw Error.error(ErrorCode.X_42565, token.tokenString);
        }
    }
    read();
    Object[] args = new Object[] { property, value };
    return new StatementCommand(StatementTypes.SET_DATABASE_PROPERTY, args, null, null);
}
Also used : HsqlDatabaseProperties(org.hsqldb_voltpatches.persist.HsqlDatabaseProperties)

Example 2 with HsqlDatabaseProperties

use of org.hsqldb_voltpatches.persist.HsqlDatabaseProperties in project voltdb by VoltDB.

the class Database method reopen.

/**
     * Opens this database.  The database should be opened after construction.
     * or reopened by the close(int closemode) method during a
     * "shutdown compact". Closes the log if there is an error.
     */
void reopen() {
    boolean isNew;
    setState(DATABASE_OPENING);
    try {
        databaseProperties = new HsqlDatabaseProperties(this);
        isNew = !DatabaseURL.isFileBasedDatabaseType(databaseType) || !databaseProperties.checkFileExists();
        if (isNew && urlProperties.isPropertyTrue(HsqlDatabaseProperties.url_ifexists)) {
            throw Error.error(ErrorCode.DATABASE_NOT_EXISTS, sName);
        }
        databaseProperties.load();
        databaseProperties.setURLProperties(urlProperties);
        compiledStatementManager.reset();
        nameManager = new HsqlNameManager(this);
        granteeManager = new GranteeManager(this);
        userManager = new UserManager(this);
        schemaManager = new SchemaManager(this);
        persistentStoreCollection = new PersistentStoreCollectionDatabase();
        bReferentialIntegrity = true;
        sessionManager = new SessionManager(this);
        txManager = new TransactionManager(this);
        collation = collation.getDefaultInstance();
        dbInfo = DatabaseInformation.newDatabaseInformation(this);
        databaseProperties.setDatabaseVariables();
        String version = databaseProperties.getProperty(HsqlDatabaseProperties.db_version);
        if (version.substring(0, 3).equals("1.7")) {
            schemaManager.createPublicSchema();
        }
        if (DatabaseURL.isFileBasedDatabaseType(databaseType)) {
            logger.openLog(this);
        }
        if (version.substring(0, 3).equals("1.7") || version.substring(0, 5).equals("1.8.0")) {
            HsqlName name = schemaManager.findSchemaHsqlName(SqlInvariants.PUBLIC_SCHEMA);
            if (name != null) {
                schemaManager.setDefaultSchemaHsqlName(name);
            }
        }
        if (isNew) {
            String tableType = urlProperties.getProperty(HsqlDatabaseProperties.hsqldb_default_table_type, "MEMORY");
            if ("CACHED".equalsIgnoreCase(tableType)) {
                schemaManager.setDefaultTableType(TableBase.CACHED_TABLE);
            }
            HsqlName name = nameManager.newHsqlName("SA", false, SchemaObject.GRANTEE);
            userManager.createUser(name, "");
            Session session = sessionManager.getSysSession();
            granteeManager.grant(name.name, SqlInvariants.DBA_ADMIN_ROLE_NAME, granteeManager.getDBARole());
            logger.writeToLog(session, "CREATE USER SA PASSWORD \'\' ADMIN");
            schemaManager.createPublicSchema();
            logger.writeToLog(session, "CREATE SCHEMA PUBLIC AUTHORIZATION DBA");
            logger.writeToLog(session, "SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC");
            if (schemaManager.getDefaultTableType() == Table.CACHED_TABLE) {
                logger.writeToLog(session, "SET DATABASE DEFAULT TABLE TYPE CACHED");
            }
            logger.synchLogForce();
        }
        dbInfo.setWithContent(true);
    } catch (Throwable e) {
        logger.closeLog(Database.CLOSEMODE_IMMEDIATELY);
        logger.releaseLock();
        setState(DATABASE_SHUTDOWN);
        clearStructures();
        DatabaseManager.removeDatabase(this);
        if (!(e instanceof HsqlException)) {
            e = Error.error(ErrorCode.GENERAL_ERROR, e.toString());
        }
        throw (HsqlException) e;
    }
    setState(DATABASE_ONLINE);
}
Also used : HsqlDatabaseProperties(org.hsqldb_voltpatches.persist.HsqlDatabaseProperties) UserManager(org.hsqldb_voltpatches.rights.UserManager) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) GranteeManager(org.hsqldb_voltpatches.rights.GranteeManager) PersistentStoreCollectionDatabase(org.hsqldb_voltpatches.persist.PersistentStoreCollectionDatabase)

Example 3 with HsqlDatabaseProperties

use of org.hsqldb_voltpatches.persist.HsqlDatabaseProperties in project voltdb by VoltDB.

the class DatabaseInformationFull method SYSTEM_PROPERTIES.

/**
     * Retrieves a <code>Table</code> object describing the capabilities
     * and operating parameter properties for the engine hosting this
     * database, as well as their applicability in terms of scope and
     * name space. <p>
     *
     * Reported properties include certain predefined <code>Database</code>
     * properties file values as well as certain database scope
     * attributes. <p>
     *
     * It is intended that all <code>Database</code> attributes and
     * properties that can be set via the database properties file,
     * JDBC connection properties or SQL SET/ALTER statements will
     * eventually be reported here or, where more applicable, in an
     * ANSI/ISO conforming feature info base table in the defintion
     * schema. <p>
     *
     * Currently, the database properties reported are: <p>
     *
     * <OL>
     *     <LI>hsqldb.cache_file_scale - the scaling factor used to translate data and index structure file pointers
     *     <LI>hsqldb.cache_scale - base-2 exponent scaling allowable cache row count
     *     <LI>hsqldb.cache_size_scale - base-2 exponent scaling allowable cache byte count
     *     <LI>hsqldb.cache_version -
     *     <LI>hsqldb.catalogs - whether to report the database catalog (database uri)
     *     <LI>hsqldb.compatible_version -
     *     <LI>hsqldb.files_readonly - whether the database is in files_readonly mode
     *     <LI>hsqldb.gc_interval - # new records forcing gc ({0|NULL}=>never)
     *     <LI>hsqldb.max_nio_scale - scale factor for cache nio mapped buffers
     *     <LI>hsqldb.nio_data_file - whether cache uses nio mapped buffers
     *     <LI>hsqldb.original_version -
     *     <LI>sql.enforce_strict_size - column length specifications enforced strictly (raise exception on overflow)?
     *     <LI>textdb.all_quoted - default policy regarding whether to quote all character field values
     *     <LI>textdb.cache_scale - base-2 exponent scaling allowable cache row count
     *     <LI>textdb.cache_size_scale - base-2 exponent scaling allowable cache byte count
     *     <LI>textdb.encoding - default TEXT table file encoding
     *     <LI>textdb.fs - default field separator
     *     <LI>textdb.vs - default varchar field separator
     *     <LI>textdb.lvs - default long varchar field separator
     *     <LI>textdb.ignore_first - default policy regarding whether to ignore the first line
     *     <LI>textdb.quoted - default policy regarding treatement character field values that _may_ require quoting
     *     <LI>IGNORECASE - create table VARCHAR_IGNORECASE?
     *     <LI>LOGSIZSE - # bytes to which REDO log grows before auto-checkpoint
     *     <LI>REFERENTIAL_INTEGITY - currently enforcing referential integrity?
     *     <LI>SCRIPTFORMAT - 0 : TEXT, 1 : BINARY, ...
     *     <LI>WRITEDELAY - does REDO log currently use buffered write strategy?
     * </OL> <p>
     *
     * @return table describing database and session operating parameters
     *      and capabilities
     */
Table SYSTEM_PROPERTIES() {
    Table t = sysTables[SYSTEM_PROPERTIES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_PROPERTIES]);
        addColumn(t, "PROPERTY_SCOPE", CHARACTER_DATA);
        addColumn(t, "PROPERTY_NAMESPACE", CHARACTER_DATA);
        addColumn(t, "PROPERTY_NAME", CHARACTER_DATA);
        addColumn(t, "PROPERTY_VALUE", CHARACTER_DATA);
        addColumn(t, "PROPERTY_CLASS", CHARACTER_DATA);
        // order PROPERTY_SCOPE, PROPERTY_NAMESPACE, PROPERTY_NAME
        // true PK
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_PROPERTIES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2 }, true);
        return t;
    }
    // column number mappings
    final int iscope = 0;
    final int ins = 1;
    final int iname = 2;
    final int ivalue = 3;
    final int iclass = 4;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // calculated column values
    String scope;
    String nameSpace;
    // intermediate holders
    Object[] row;
    HsqlDatabaseProperties props;
    // First, we want the names and values for
    // all JDBC capabilities constants
    scope = "SESSION";
    props = database.getProperties();
    nameSpace = "database.properties";
    // boolean properties
    Iterator it = props.getUserDefinedPropertyData().iterator();
    while (it.hasNext()) {
        Object[] metaData = (Object[]) it.next();
        row = t.getEmptyRowData();
        row[iscope] = scope;
        row[ins] = nameSpace;
        row[iname] = metaData[HsqlProperties.indexName];
        row[ivalue] = props.getProperty((String) row[iname]);
        row[iclass] = metaData[HsqlProperties.indexClass];
        t.insertSys(store, row);
    }
    row = t.getEmptyRowData();
    row[iscope] = scope;
    row[ins] = nameSpace;
    row[iname] = "SCRIPTFORMAT";
    try {
        row[ivalue] = ScriptWriterBase.LIST_SCRIPT_FORMATS[database.logger.getScriptType()];
    } catch (Exception e) {
    }
    row[iclass] = "java.lang.String";
    t.insertSys(store, row);
    // write delay
    row = t.getEmptyRowData();
    row[iscope] = scope;
    row[ins] = nameSpace;
    row[iname] = "WRITE_DELAY";
    row[ivalue] = "" + database.logger.getWriteDelay();
    row[iclass] = "int";
    t.insertSys(store, row);
    // ignore case
    row = t.getEmptyRowData();
    row[iscope] = scope;
    row[ins] = nameSpace;
    row[iname] = "IGNORECASE";
    row[ivalue] = database.isIgnoreCase() ? "true" : "false";
    row[iclass] = "boolean";
    t.insertSys(store, row);
    // referential integrity
    row = t.getEmptyRowData();
    row[iscope] = scope;
    row[ins] = nameSpace;
    row[iname] = "REFERENTIAL_INTEGRITY";
    row[ivalue] = database.isReferentialIntegrity() ? "true" : "false";
    row[iclass] = "boolean";
    t.insertSys(store, row);
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) HsqlDatabaseProperties(org.hsqldb_voltpatches.persist.HsqlDatabaseProperties) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint) HsqlException(org.hsqldb_voltpatches.HsqlException)

Aggregations

HsqlDatabaseProperties (org.hsqldb_voltpatches.persist.HsqlDatabaseProperties)3 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)2 Constraint (org.hsqldb_voltpatches.Constraint)1 HsqlException (org.hsqldb_voltpatches.HsqlException)1 SchemaObject (org.hsqldb_voltpatches.SchemaObject)1 Table (org.hsqldb_voltpatches.Table)1 TextTable (org.hsqldb_voltpatches.TextTable)1 Iterator (org.hsqldb_voltpatches.lib.Iterator)1 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)1 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)1 PersistentStoreCollectionDatabase (org.hsqldb_voltpatches.persist.PersistentStoreCollectionDatabase)1 GranteeManager (org.hsqldb_voltpatches.rights.GranteeManager)1 UserManager (org.hsqldb_voltpatches.rights.UserManager)1