/** @todo error message */
  static Connection getConnection(String url, Properties info) throws SQLException {

    HsqlProperties props = DatabaseManager.parseURL(url, true);

    if (props == null) {
      throw new SQLException(Trace.getMessage(Trace.INVALID_JDBC_ARGUMENT));
    }

    props.addProperties(info);

    return new jdbcConnection(props);
  }
예제 #2
0
  /**
   * 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() throws HsqlException {

    setState(DATABASE_OPENING);

    try {
      User sysUser;

      isNew =
          (sType == DatabaseManager.S_MEM
              || !HsqlProperties.checkFileExists(sPath, isFilesInJar(), getClass()));
      databaseProperties = new HsqlDatabaseProperties(this);

      databaseProperties.load();
      databaseProperties.setURLProperties(urlProperties);
      compiledStatementManager.reset();

      tTable = new HsqlArrayList();
      userManager = new UserManager();
      hAlias = Library.getAliasMap();
      nameManager = new HsqlNameManager();
      triggerNameList = new DatabaseObjectNames();
      indexNameList = new DatabaseObjectNames();
      constraintNameList = new DatabaseObjectNames();
      sequenceManager = new SequenceManager();
      bReferentialIntegrity = true;
      sysUser = userManager.createSysUser(this);
      sessionManager = new SessionManager(this, sysUser);
      dInfo = DatabaseInformation.newDatabaseInformation(this);

      if (sType != DatabaseManager.S_MEM) {
        logger.openLog(this);
      }

      if (isNew) {
        sessionManager
            .getSysSession()
            .sqlExecuteDirectNoPreChecks("CREATE USER SA PASSWORD \"\" ADMIN");
      }

      dInfo.setWithContent(true);
    } catch (Throwable e) {
      logger.closeLog(Database.CLOSEMODE_IMMEDIATELY);
      logger.releaseLock();
      setState(DATABASE_SHUTDOWN);
      clearStructures();

      if (!(e instanceof HsqlException)) {
        e = Trace.error(Trace.GENERAL_ERROR, e.toString());
      }

      throw (HsqlException) e;
    }

    setState(DATABASE_ONLINE);
  }
예제 #3
0
  /**
   * Constructs a new Database object.
   *
   * @param type is the type of the database: "mem", "file", "res"
   * @param path is the canonical path to the database files
   * @param ifexists if true, prevents creation of a new database if it does not exist. Only valid
   *     for file-system databases.
   * @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(String type, String path, String name, boolean ifexists, HsqlProperties props)
      throws HsqlException {

    urlProperties = props;

    setState(Database.DATABASE_SHUTDOWN);

    sName = name;
    sType = type;
    sPath = path;

    if (sType == DatabaseManager.S_RES) {
      filesInJar = true;
      filesReadOnly = true;
      ifexists = true;
    }

    // does not need to be done more than once
    try {
      classLoader = getClass().getClassLoader();
    } catch (Exception e) {

      // strict security policy:  just use the system/boot loader
      classLoader = null;
    }

    try {
      isNew =
          (sType == DatabaseManager.S_MEM
              || !HsqlProperties.checkFileExists(path, isFilesInJar(), getClass()));
    } catch (IOException e) {
    }

    if (isNew && ifexists) {
      throw Trace.error(Trace.DATABASE_NOT_EXISTS, type + path);
    }

    logger = new Logger();
    compiledStatementManager = new CompiledStatementManager(this);
  }
  protected void initParams() throws HsqlException {

    // fredt - write rows as soon as they are inserted
    storeOnInsert = true;

    HsqlProperties tableprops = HsqlProperties.delimitedArgPairsToProps(sName, "=", ";", null);

    // -- Get file name
    switch (tableprops.errorCodes.length) {
      case 0:
        throw Trace.error(Trace.TEXT_TABLE_SOURCE, Trace.TEXT_TABLE_SOURCE_FILENAME);
      case 1:

        // source file name is the only key without a value
        sName = tableprops.errorKeys[0].trim();
        break;

      default:
        throw Trace.error(
            Trace.TEXT_TABLE_SOURCE,
            Trace.TEXT_TABLE_SOURCE_VALUE_MISSING,
            tableprops.errorKeys[1]);
    }

    // -- Get separators:
    fs = translateSep(tableprops.getProperty("fs", dbProps.getProperty("textdb.fs", ",")));
    vs = translateSep(tableprops.getProperty("vs", dbProps.getProperty("textdb.vs", fs)));
    lvs = translateSep(tableprops.getProperty("lvs", dbProps.getProperty("textdb.lvs", fs)));

    if (fs.length() == 0 || vs.length() == 0 || lvs.length() == 0) {
      throw Trace.error(Trace.TEXT_TABLE_SOURCE, Trace.TEXT_TABLE_SOURCE_SEPARATOR);
    }

    // -- Get booleans
    ignoreFirst =
        tableprops.isPropertyTrue(
            "ignore_first", dbProps.isPropertyTrue("textdb.ignore_first", false));
    isQuoted = tableprops.isPropertyTrue("quoted", dbProps.isPropertyTrue("textdb.quoted", true));
    isAllQuoted =
        tableprops.isPropertyTrue("all_quoted", dbProps.isPropertyTrue("textdb.all_quoted", false));

    // -- Get encoding
    stringEncoding =
        translateSep(
            tableprops.getProperty("encoding", dbProps.getProperty("textdb.encoding", "ASCII")));

    // -- Get size and scale
    cacheScale =
        tableprops.getIntegerProperty(
            "cache_scale", dbProps.getIntegerProperty("textdb.cache_scale", 10, 8, 16));
    cacheSizeScale =
        tableprops.getIntegerProperty(
            "cache_size_scale", dbProps.getIntegerProperty("textdb.cache_size_scale", 12, 8, 20));

    try {
      if (isQuoted || isAllQuoted) {
        rowIn = new RowInputTextQuoted(fs, vs, lvs, isAllQuoted);
        rowOut = new RowOutputTextQuoted(fs, vs, lvs, isAllQuoted, stringEncoding);
      } else {
        rowIn = new RowInputText(fs, vs, lvs, false);
        rowOut = new RowOutputText(fs, vs, lvs, false, stringEncoding);
      }
    } catch (IOException e) {

      // no exception expected here the IOException is vestigial
      throw (Trace.error(Trace.TEXT_TABLE_SOURCE, "invalid file: " + e));
    }
  }