Search in sources :

Example 1 with TextCache

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

the class TextTable method getHeader.

public String getHeader() {
    PersistentStore store = database.persistentStoreCollection.getStore(this);
    TextCache cache = (TextCache) store.getCache();
    String header = cache == null ? null : cache.getHeader();
    return header == null ? null : StringConverter.toQuotedString(header, '\"', true);
}
Also used : TextCache(org.hsqldb_voltpatches.persist.TextCache) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore)

Example 2 with TextCache

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

the class TextTable method connect.

/**
     * connects to the data source
     */
private void connect(Session session, boolean withReadOnlyData) {
    // Open new cache:
    if ((dataSource.length() == 0) || isConnected) {
        // nothing to do
        return;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(this);
    this.store = store;
    DataFileCache cache = null;
    try {
        cache = (TextCache) database.logger.openTextCache(this, dataSource, withReadOnlyData, isReversed);
        store.setCache(cache);
        // read and insert all the rows from the source file
        Row row = null;
        int nextpos = 0;
        if (((TextCache) cache).ignoreFirst) {
            nextpos += ((TextCache) cache).readHeaderLine();
        }
        while (true) {
            row = (Row) store.get(nextpos, false);
            if (row == null) {
                break;
            }
            Object[] data = row.getData();
            nextpos = row.getPos() + row.getStorageSize();
            ((RowAVLDiskData) row).setNewNodes();
            systemUpdateIdentityValue(data);
            enforceRowConstraints(session, data);
            for (int i = 0; i < indexList.length; i++) {
                indexList[i].insert(null, store, row);
            }
        }
    } catch (Exception e) {
        int linenumber = cache == null ? 0 : ((TextCache) cache).getLineNumber();
        clearAllData(session);
        if (cache != null) {
            database.logger.closeTextCache(this);
            store.release();
        }
        // source and cache or have an empty source and null cache.
        throw Error.error(ErrorCode.TEXT_FILE, 0, new Object[] { new Integer(linenumber), e.getMessage() });
    }
    isConnected = true;
    isReadOnly = withReadOnlyData;
}
Also used : DataFileCache(org.hsqldb_voltpatches.persist.DataFileCache) TextCache(org.hsqldb_voltpatches.persist.TextCache) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore)

Example 3 with TextCache

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

the class TextTable method setHeader.

public void setHeader(String header) {
    PersistentStore store = database.persistentStoreCollection.getStore(this);
    TextCache cache = (TextCache) store.getCache();
    if (cache != null && cache.ignoreFirst) {
        cache.setHeader(header);
        return;
    }
    throw Error.error(ErrorCode.TEXT_TABLE_HEADER);
}
Also used : TextCache(org.hsqldb_voltpatches.persist.TextCache) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore)

Example 4 with TextCache

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

the class DatabaseInformationFull method SYSTEM_TEXTTABLES.

/**
     * Retrieves a <code>Table</code> object describing the TEXT TABLE objects
     * defined within this database. The table contains one row for each row
     * in the SYSTEM_TABLES table with a HSQLDB_TYPE of  TEXT . <p>
     *
     * Each row is a description of the attributes that defines its TEXT TABLE,
     * with the following columns:
     *
     * <pre class="SqlCodeExample">
     * TABLE_CAT                 VARCHAR   table's catalog name
     * TABLE_SCHEM               VARCHAR   table's simple schema name
     * TABLE_NAME                VARCHAR   table's simple name
     * DATA_SOURCE_DEFINITION    VARCHAR   the "spec" proption of the table's
     *                                     SET TABLE ... SOURCE DDL declaration
     * FILE_PATH                 VARCHAR   absolute file path.
     * FILE_ENCODING             VARCHAR   endcoding of table's text file
     * FIELD_SEPARATOR           VARCHAR   default field separator
     * VARCHAR_SEPARATOR         VARCAHR   varchar field separator
     * LONGVARCHAR_SEPARATOR     VARCHAR   longvarchar field separator
     * IS_IGNORE_FIRST           BOOLEAN   ignores first line of file?
     * IS_QUOTED                 BOOLEAN   fields are quoted if necessary?
     * IS_ALL_QUOTED             BOOLEAN   all fields are quoted?
     * IS_DESC                   BOOLEAN   read rows starting at end of file?
     * </pre> <p>
     *
     * @return a <code>Table</code> object describing the text attributes
     * of the accessible text tables defined within this database
     *
     */
Table SYSTEM_TEXTTABLES() {
    Table t = sysTables[SYSTEM_TEXTTABLES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_TEXTTABLES]);
        addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        addColumn(t, "DATA_SOURCE_DEFINTION", CHARACTER_DATA);
        addColumn(t, "FILE_PATH", CHARACTER_DATA);
        addColumn(t, "FILE_ENCODING", CHARACTER_DATA);
        addColumn(t, "FIELD_SEPARATOR", CHARACTER_DATA);
        addColumn(t, "VARCHAR_SEPARATOR", CHARACTER_DATA);
        addColumn(t, "LONGVARCHAR_SEPARATOR", CHARACTER_DATA);
        addColumn(t, "IS_IGNORE_FIRST", Type.SQL_BOOLEAN);
        addColumn(t, "IS_ALL_QUOTED", Type.SQL_BOOLEAN);
        addColumn(t, "IS_QUOTED", Type.SQL_BOOLEAN);
        addColumn(t, "IS_DESC", Type.SQL_BOOLEAN);
        // ------------------------------------------------------------
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_TEXTTABLES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
        return t;
    }
    // column number mappings
    final int itable_cat = 0;
    final int itable_schem = 1;
    final int itable_name = 2;
    final int idsd = 3;
    final int ifile_path = 4;
    final int ifile_enc = 5;
    final int ifs = 6;
    final int ivfs = 7;
    final int ilvfs = 8;
    final int iif = 9;
    final int iiq = 10;
    final int iiaq = 11;
    final int iid = 12;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // intermediate holders
    Iterator tables;
    Table table;
    Object[] row;
    // Initialization
    tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
    // Do it.
    while (tables.hasNext()) {
        table = (Table) tables.next();
        PersistentStore currentStore = database.persistentStoreCollection.getStore(t);
        if (!table.isText() || !isAccessibleTable(table)) {
            continue;
        }
        row = t.getEmptyRowData();
        row[itable_cat] = database.getCatalogName().name;
        row[itable_schem] = table.getSchemaName().name;
        row[itable_name] = table.getName().name;
        row[idsd] = ((TextTable) table).getDataSource();
        TextCache cache = (TextCache) currentStore.getCache();
        if (cache != null) {
            row[ifile_path] = FileUtil.getDefaultInstance().canonicalOrAbsolutePath(cache.getFileName());
            row[ifile_enc] = cache.stringEncoding;
            row[ifs] = cache.fs;
            row[ivfs] = cache.vs;
            row[ilvfs] = cache.lvs;
            row[iif] = ValuePool.getBoolean(cache.ignoreFirst);
            row[iiq] = ValuePool.getBoolean(cache.isQuoted);
            row[iiaq] = ValuePool.getBoolean(cache.isAllQuoted);
            row[iid] = ((TextTable) table).isDescDataSource() ? Boolean.TRUE : Boolean.FALSE;
        }
        t.insertSys(store, row);
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) TextCache(org.hsqldb_voltpatches.persist.TextCache) TextTable(org.hsqldb_voltpatches.TextTable) 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)

Aggregations

PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)4 TextCache (org.hsqldb_voltpatches.persist.TextCache)4 Constraint (org.hsqldb_voltpatches.Constraint)1 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)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 DataFileCache (org.hsqldb_voltpatches.persist.DataFileCache)1