Search in sources :

Example 1 with StringColumn

use of org.apache.jena.jdbc.results.metadata.columns.StringColumn in project jena by apache.

the class TestMetaResultSet method meta_result_set_string_01.

/**
     * Test retrieving meta column values
     * 
     * @throws SQLException
     */
@Test
public void meta_result_set_string_01() throws SQLException {
    MetaResultSet results = new MetaResultSet(new ColumnInfo[] { new StringColumn("Test", ResultSetMetaData.columnNullable) }, new Object[][] { { "value" } });
    Assert.assertTrue(results.next());
    String value = results.getString(1);
    Assert.assertEquals("value", value);
    Assert.assertFalse(results.wasNull());
    Assert.assertFalse(results.next());
    results.close();
    Assert.assertTrue(results.isClosed());
}
Also used : MetaResultSet(org.apache.jena.jdbc.metadata.results.MetaResultSet) StringColumn(org.apache.jena.jdbc.results.metadata.columns.StringColumn) Test(org.junit.Test)

Example 2 with StringColumn

use of org.apache.jena.jdbc.results.metadata.columns.StringColumn in project jena by apache.

the class TestMetaResultSet method empty_meta_result_set_02.

/**
     * Check empty meta result set with a single column
     * 
     * @throws SQLException
     */
@Test
public void empty_meta_result_set_02() throws SQLException {
    MetaResultSet results = new MetaResultSet(new ColumnInfo[] { new StringColumn("Test", ResultSetMetaData.columnNullable) });
    // Check results metadata
    ResultSetMetaData metadata = results.getMetaData();
    Assert.assertEquals(1, metadata.getColumnCount());
    // Check results
    Assert.assertTrue(results.isBeforeFirst());
    Assert.assertFalse(results.next());
    Assert.assertTrue(results.isAfterLast());
    results.close();
    Assert.assertTrue(results.isClosed());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) MetaResultSet(org.apache.jena.jdbc.metadata.results.MetaResultSet) StringColumn(org.apache.jena.jdbc.results.metadata.columns.StringColumn) Test(org.junit.Test)

Example 3 with StringColumn

use of org.apache.jena.jdbc.results.metadata.columns.StringColumn in project jena by apache.

the class MetadataSchema method init.

/**
     * Synchronized static initializer is called by the class static
     * initializer, this is done to avoid multi-threaded race conditions and
     * ensure once only initialization
     */
private static synchronized void init() {
    if (init)
        return;
    try {
        // Define all the columns we are going to use since some of these
        // appear in multiple schema
        ColumnInfo empty = new StringColumn("", columnNullable);
        ColumnInfo typeCat = new StringColumn("TYPE_CATA", columnNullable);
        ColumnInfo typeSchema = new StringColumn("TYPE_SCHEM", columnNullable);
        ColumnInfo typeName = new StringColumn("TYPE_NAME", columnNoNulls);
        ColumnInfo attrName = new StringColumn("ATTR_NAME", columnNoNulls);
        ColumnInfo dataType = new IntegerColumn("DATA_TYPE", columnNoNulls, true);
        ColumnInfo attrTypeName = new StringColumn("ATTR_TYPE_NAME", columnNoNulls);
        ColumnInfo attrSize = new IntegerColumn("ATTR_SIZE", columnNoNulls, true);
        ColumnInfo decimalDigits = new IntegerColumn("DECIMAL_DIGITS", columnNoNulls, true);
        ColumnInfo numPrecRadix = new IntegerColumn("NUM_PREC_RADIX", columnNoNulls, true);
        ColumnInfo nullable = new IntegerColumn("NULLABLE", columnNoNulls, true);
        ColumnInfo shortNullable = new ShortIntegerColumn("NULLABLE", columnNoNulls, true);
        ColumnInfo remarks = new StringColumn("REMARKS", columnNullable);
        ColumnInfo attrDef = new StringColumn("ATTR_DEF", columnNullable);
        ColumnInfo sqlDataType = new IntegerColumn("SQL_DATA_TYPE", columnNoNulls, true);
        ColumnInfo sqlDateTimeSub = new IntegerColumn("SQL_DATETIME_SUB", columnNoNulls, true);
        ColumnInfo charOctetLength = new IntegerColumn("CHAR_OCTET_LENGTH", columnNoNulls, true);
        ColumnInfo ordinalPosition = new IntegerColumn("ORDINAL_POSITION", columnNoNulls, true);
        ColumnInfo isNullable = new StringColumn("IS_NULLABLE", columnNoNulls);
        ColumnInfo scope = new ShortIntegerColumn("SCOPE", columnNoNulls, true);
        ColumnInfo scopeCatalog = new StringColumn("SCOPE_CATALOG", columnNullable);
        ColumnInfo scopeSchema = new StringColumn("SCOPE_SCHEMA", columnNullable);
        ColumnInfo scopeTable = new StringColumn("SCOPE_TABLE", columnNullable);
        ColumnInfo sourceDataType = new ShortIntegerColumn("SOURCE_DATA_TYPE", columnNullable, true);
        ColumnInfo columnName = new StringColumn("COLUMN_NAME", columnNoNulls);
        ColumnInfo columnSize = new IntegerColumn("COLUMN_SIZE", columnNoNulls, true);
        ColumnInfo columnDef = new StringColumn("COLUMN_DEF", columnNullable);
        ColumnInfo bufferLength = new IntegerColumn("BUFFER_LENGTH", columnNoNulls, true);
        ColumnInfo psuedoColumn = new ShortIntegerColumn("PSUEDO_COLUMN", columnNoNulls, true);
        ColumnInfo tableCat = new StringColumn("TABLE_CAT", columnNullable);
        ColumnInfo tableCatalog = new StringColumn("TABLE_CATALOG", columnNullable);
        ColumnInfo tableSchema = new StringColumn("TABLE_SCHEM", columnNullable);
        ColumnInfo tableName = new StringColumn("TABLE_NAME", columnNoNulls);
        ColumnInfo name = new StringColumn("NAME", columnNoNulls);
        ColumnInfo maxLen = new IntegerColumn("MAX_LEN", columnNoNulls, true);
        ColumnInfo defaultValue = new StringColumn("DEFAULT_VALUE", columnNullable);
        ColumnInfo description = new StringColumn("DESCRIPTION", columnNullable);
        ColumnInfo isAutoIncrement = new StringColumn("IS_AUTOINCREMENT", columnNoNulls);
        ColumnInfo className = new StringColumn("CLASS_NAME", columnNoNulls);
        ColumnInfo baseType = new ShortIntegerColumn("BASE_TYPE", columnNullable, true);
        ColumnInfo grantor = new StringColumn("GRANTOR", columnNullable);
        ColumnInfo grantee = new StringColumn("GRANTEE", columnNullable);
        ColumnInfo privilege = new StringColumn("PRIVILEGE", columnNoNulls);
        ColumnInfo isGrantable = new StringColumn("IS_GRANTABLE", columnNoNulls);
        ColumnInfo pkTableCat = new StringColumn("PKTABLE_CAT", columnNullable);
        ColumnInfo pkTableSchema = new StringColumn("PKTABLE_SCHEM", columnNullable);
        ColumnInfo pkTableName = new StringColumn("PKTABLE_NAME", columnNoNulls);
        ColumnInfo pkColumnName = new StringColumn("PKCOLUMN_NAME", columnNoNulls);
        ColumnInfo fkTableCat = new StringColumn("FKTABLE_CAT", columnNullable);
        ColumnInfo fkTableSchema = new StringColumn("FKTABLE_SCHEM", columnNullable);
        ColumnInfo fkTableName = new StringColumn("FKTABLE_NAME", columnNoNulls);
        ColumnInfo fkColumnName = new StringColumn("FKCOLUMN_NAME", columnNoNulls);
        ColumnInfo keySeq = new ShortIntegerColumn("KEY_SEQ", columnNoNulls, true);
        ColumnInfo updateRule = new ShortIntegerColumn("UPDATE_RULE", columnNoNulls, true);
        ColumnInfo deleteRule = new ShortIntegerColumn("DELETE_RULE", columnNoNulls, true);
        ColumnInfo fkName = new StringColumn("FK_NAME", columnNullable);
        ColumnInfo pkName = new StringColumn("PK_NAME", columnNullable);
        ColumnInfo deferrability = new ShortIntegerColumn("DEFERRABILITY", columnNoNulls, true);
        ColumnInfo functionCat = new StringColumn("FUNCTION_CAT", columnNullable);
        ColumnInfo functionSchema = new StringColumn("FUNCTION_SCHEM", columnNullable);
        ColumnInfo functionName = new StringColumn("FUNCTION_NAME", columnNoNulls);
        ColumnInfo columnType = new ShortIntegerColumn("COLUMN_TYPE", columnNoNulls, true);
        ColumnInfo precision = new IntegerColumn("PRECISION", columnNoNulls, true);
        ColumnInfo length = new IntegerColumn("LENGTH", columnNoNulls, true);
        ColumnInfo scale = new ShortIntegerColumn("SCALE", columnNoNulls, true);
        ColumnInfo radix = new ShortIntegerColumn("RADIX", columnNoNulls, true);
        ColumnInfo specificName = new StringColumn("SPECIFIC_NAME", columnNoNulls);
        ColumnInfo functionType = new ShortIntegerColumn("FUNCTION_TYPE", columnNoNulls, true);
        ColumnInfo nonUnique = new BooleanColumn("NON_UNIQUE", columnNoNulls);
        ColumnInfo indexQualifier = new StringColumn("INDEX_QUALIFIER", columnNullable);
        ColumnInfo indexName = new StringColumn("INDEX_NAME", columnNullable);
        ColumnInfo type = new ShortIntegerColumn("TYPE", columnNoNulls, true);
        ColumnInfo ascOrDesc = new StringColumn("ASC_OR_DESC", columnNullable);
        ColumnInfo cardinality = new IntegerColumn("CARDINALITY", columnNoNulls, true);
        ColumnInfo pages = new IntegerColumn("PAGES", columnNoNulls, true);
        ColumnInfo filterCondition = new StringColumn("FILTER_CONDITION", columnNullable);
        ColumnInfo procedureCat = new StringColumn("PROCEDURE_CAT", columnNullable);
        ColumnInfo procedureSchema = new StringColumn("PROCEDURE_SCHEM", columnNullable);
        ColumnInfo procedureName = new StringColumn("PROCEDURE_NAME", columnNoNulls);
        ColumnInfo procedureType = new ShortIntegerColumn("PROCEDURE_TYPE", columnNoNulls, true);
        ColumnInfo superTableName = new StringColumn("SUPERTABLE_NAME", columnNoNulls);
        ColumnInfo superTypeCat = new StringColumn("SUPERTYPE_CAT", columnNullable);
        ColumnInfo superTypeSchema = new StringColumn("SUPERTYPE_SCHEM", columnNullable);
        ColumnInfo superTypeName = new StringColumn("SUPERTYPE_NAME", columnNoNulls);
        ColumnInfo litPrefix = new StringColumn("LITERAL_PREFIX", columnNullable);
        ColumnInfo litSuffix = new StringColumn("LITERAL_SUFFIX", columnNullable);
        ColumnInfo createParams = new StringColumn("CREATE_PARAMS", columnNullable);
        ColumnInfo caseSensitive = new BooleanColumn("CASE_SENSITIVE", columnNoNulls);
        ColumnInfo searchable = new ShortIntegerColumn("SEARCHABLE", columnNoNulls, true);
        ColumnInfo unsignedAttr = new BooleanColumn("UNSIGNED_ATTRIBUTE", columnNoNulls);
        ColumnInfo fixedPrecScale = new BooleanColumn("FIXED_PREC_SCALE", columnNoNulls);
        ColumnInfo autoIncrement = new BooleanColumn("AUTO_INCREMENT", columnNoNulls);
        ColumnInfo localTypeName = new StringColumn("LOCAL_TYPE_NAME", columnNullable);
        ColumnInfo minScale = new ShortIntegerColumn("MINIMUM_SCALE", columnNoNulls, true);
        ColumnInfo maxScale = new ShortIntegerColumn("MAXIMUM_SCALE", columnNullable, true);
        ColumnInfo tableType = new StringColumn("TABLE_TYPE", columnNoNulls);
        ColumnInfo selfRefColName = new StringColumn("SELF_REFERENCING_COL_NAME", columnNullable);
        ColumnInfo refGeneration = new StringColumn("REF_GENERATION", columnNullable);
        ColumnInfo columnUsage = new StringColumn("COLUMN_USAGE", columnNoNulls);
        ATTRIBUTE_COLUMNS = new ColumnInfo[] { // TYPE_CAT String => type catalog (may be null)
        typeCat, // TYPE_SCHEM String => type schema (may be null)
        typeSchema, // TYPE_NAME String => type name
        typeName, // ATTR_NAME String => attribute name
        attrName, // java.sql.Types
        dataType, // target type of the reference type.
        attrTypeName, // decimal types this is precision.
        attrSize, // not applicable.
        decimalDigits, // NUM_PREC_RADIX int => Radix (typically either 10 or 2)
        numPrecRadix, // attributeNullableUnknown - nullability unknown
        nullable, // REMARKS String => comment describing column (may be null)
        remarks, // ATTR_DEF String => default value (may be null)
        attrDef, // SQL_DATA_TYPE int => unused
        sqlDataType, // SQL_DATETIME_SUB int => unused
        sqlDateTimeSub, // number of bytes in the column
        charOctetLength, // (starting at 1)
        ordinalPosition, // unknown
        isNullable, // reference attribute (null if DATA_TYPE isn't REF)
        scopeCatalog, // of a reference attribute (null if DATA_TYPE isn't REF)
        scopeSchema, // referenceattribute (null if the DATA_TYPE isn't REF)
        scopeTable, // (null if DATA_TYPE isn't DISTINCT or user-generated REF)
        sourceDataType };
        BEST_ROW_IDENTIFIER_COLUMNS = new ColumnInfo[] { // bestRowSession - valid for remainder of current session
        scope, // COLUMN_NAME String => column name
        columnName, // DATA_TYPE int => SQL data type from java.sql.Types
        dataType, // a UDT the type name is fully qualified
        typeName, // COLUMN_SIZE int => precision
        columnSize, // BUFFER_LENGTH int => not used
        bufferLength, // types where DECIMAL_DIGITS is not applicable.
        decimalDigits, // bestRowPseudo - is a pseudo column
        psuedoColumn };
        CATALOG_COLUMNS = new ColumnInfo[] { // TABLE_CAT String => catalog name
        tableCat };
        CLIENT_INFO_PROPERTY_COLUMNS = new ColumnInfo[] { // NAME String=> The name of the client info property
        name, // property
        maxLen, // DEFAULT_VALUE String=> The default value of the property
        defaultValue, // property is stored in the database.
        description };
        COLUMN_COLUMNS = new ColumnInfo[] { // TABLE_CAT String => table catalog (may be null)
        tableCat, // TABLE_SCHEM String => table schema (may be null)
        tableSchema, // TABLE_NAME String => table name
        tableName, // COLUMN_NAME String => column name
        columnName, // DATA_TYPE int => SQL type from java.sql.Types
        dataType, // the type name is fully qualified
        typeName, // COLUMN_SIZE int => column size.
        columnSize, // BUFFER_LENGTH is not used.
        bufferLength, // applicable.
        decimalDigits, // NUM_PREC_RADIX int => Radix (typically either 10 or 2)
        numPrecRadix, // columnNullableUnknown - nullability unknown
        nullable, // null),
        remarks, // quotes (may be null)
        columnDef, // SQL_DATA_TYPE int => unused
        sqlDataType, // SQL_DATETIME_SUB int => unused
        sqlDateTimeSub, // bytes in the column
        charOctetLength, // (starting at 1)
        ordinalPosition, // unknown
        isNullable, // reference attribute (null if DATA_TYPE isn't REF)
        scopeCatalog, // reference attribute (null if the DATA_TYPE isn't REF)
        scopeSchema, // reference attribure (null if the DATA_TYPE isn't REF)
        scopeTable, // DATA_TYPE isn't DISTINCT or user-generated REF)
        sourceDataType, // auto incremented parameter is unknown
        isAutoIncrement };
        COLUMN_PRIVILEGE_COLUMNS = new ColumnInfo[] { // TABLE_CAT String => table catalog (may be null)
        tableCat, // TABLE_SCHEM String => table schema (may be null)
        tableSchema, // TABLE_NAME String => table name
        tableName, // COLUMN_NAME String => column name
        columnName, // GRANTOR String => grantor of access (may be null)
        grantor, // GRANTEE String => grantee of access
        grantee, // UPDATE, REFRENCES, ...)
        privilege, // grant to others; "NO" if not; null if unknown
        isGrantable };
        CROSS_REFERENCE_COLUMNS = new ColumnInfo[] { // null)
        pkTableCat, // null)
        pkTableSchema, // PKTABLE_NAME String => parent key table name
        pkTableName, // PKCOLUMN_NAME String => parent key column name
        pkColumnName, // being exported (may be null)
        fkTableCat, // null) being exported (may be null)
        fkTableSchema, // exported
        fkTableName, // exported
        fkColumnName, // within the foreign key).
        keySeq, // ODBC 2.x compatibility)
        updateRule, // its parent key has been deleted
        deleteRule, // FK_NAME String => foreign key name (may be null)
        fkName, // PK_NAME String => parent key name (may be null)
        pkName, // importedKeyNotDeferrable - see SQL92 for definition
        deferrability };
        EXPORTED_KEY_COLUMNS = new ColumnInfo[] { // null)
        pkTableCat, // null)
        pkTableSchema, // PKTABLE_NAME String => primary key table name
        pkTableName, // PKCOLUMN_NAME String => primary key column name
        pkColumnName, // null) being exported (may be null)
        fkTableCat, // null) being exported (may be null)
        fkTableSchema, // exported
        fkTableName, // exported
        fkColumnName, // within the foreign key).
        keySeq, // ODBC 2.x compatibility)
        updateRule, // its primary key has been deleted
        deleteRule, // FK_NAME String => foreign key name (may be null)
        fkName, // PK_NAME String => primary key name (may be null)
        pkName, // importedKeyNotDeferrable - see SQL92 for definition
        deferrability };
        FUNCTION_COLUMN_COLUMNS = new ColumnInfo[] { // FUNCTION_CAT String => function catalog (may be null)
        functionCat, // FUNCTION_SCHEM String => function schema (may be null)
        functionSchema, // used to invoke the function
        functionName, // COLUMN_NAME String => column/parameter name
        columnName, // column is a column in the ResultSet
        columnType, // DATA_TYPE int => SQL type from java.sql.Types
        dataType, // type name is fully qualified
        typeName, // PRECISION int => precision
        precision, // LENGTH int => length in bytes of data
        length, // where SCALE is not applicable.
        scale, // RADIX short => radix
        radix, // functionNullableUnknown - nullability unknown
        shortNullable, // REMARKS String => comment describing column/parameter
        remarks, // datatype the returned value is a NULL
        charOctetLength, // of the column in the result set starting from 1.
        ordinalPosition, // column is unknown
        isNullable, // overload functions
        specificName };
        FUNCTION_COLUMNS = new ColumnInfo[] { // FUNCTION_CAT String => function catalog (may be null)
        functionCat, // FUNCTION_SCHEM String => function schema (may be null)
        functionSchema, // used to invoke the function
        functionName, // REMARKS String => explanatory comment on the function
        remarks, // functionReturnsTable - Returns a table
        functionType, // overload functions
        specificName };
        IMPORTED_KEY_COLUMNS = new ColumnInfo[] { // imported (may be null)
        pkTableCat, // imported (may be null)
        pkTableSchema, // imported
        pkTableName, // imported
        pkColumnName, // null)
        fkTableCat, // null)
        fkTableSchema, // FKTABLE_NAME String => foreign key table name
        fkTableName, // FKCOLUMN_NAME String => foreign key column name
        fkColumnName, // within the foreign key).
        keySeq, // ODBC 2.x compatibility)
        updateRule, // its primary key has been deleted
        deleteRule, // FK_NAME String => foreign key name (may be null)
        fkName, // PK_NAME String => primary key name (may be null)
        pkName, // importedKeyNotDeferrable - see SQL92 for definition
        deferrability };
        INDEX_INFO_COLUMNS = new ColumnInfo[] { // TABLE_CAT String => table catalog (may be null)
        tableCat, // TABLE_SCHEM String => table schema (may be null)
        tableSchema, // TABLE_NAME String => table name
        tableName, // false when TYPE is tableIndexStatistic
        nonUnique, // null when TYPE is tableIndexStatistic
        indexQualifier, // tableIndexStatistic
        indexName, // tableIndexOther - this is some other style of index
        type, // index; zero when TYPE is tableIndexStatistic
        ordinalPosition, // tableIndexStatistic
        columnName, // tableIndexStatistic
        ascOrDesc, // the number of unique values in the index.
        cardinality, // the number of pages used for the current index.
        pages, // be null)
        filterCondition };
        PRIMARY_KEY_COLUMNS = new ColumnInfo[] { // TABLE_CAT String => table catalog (may be null)
        tableCat, // TABLE_SCHEM String => table schema (may be null)
        tableSchema, // TABLE_NAME String => table name
        tableName, // COLUMN_NAME String => column name
        columnName, // within the primary key).
        keySeq, // PK_NAME String => primary key name (may be null)
        pkName };
        PROCEDURE_COLUMN_COLUMNS = new ColumnInfo[] { // PROCEDURE_CAT String => procedure catalog (may be null)
        procedureCat, // PROCEDURE_SCHEM String => procedure schema (may be null)
        procedureSchema, // PROCEDURE_NAME String => procedure name
        procedureName, // COLUMN_NAME String => column/parameter name
        columnName, // procedureColumnResult - result column in ResultSet
        columnType, // DATA_TYPE int => SQL type from java.sql.Types
        dataType, // type name is fully qualified
        typeName, // PRECISION int => precision
        precision, // LENGTH int => length in bytes of data
        length, // where SCALE is not applicable.
        scale, // RADIX short => radix
        radix, // procedureNullableUnknown - nullability unknown
        shortNullable, // REMARKS String => comment describing parameter/column
        remarks, // NULL - if a default value was not specified
        columnDef, // SQL_DATA_TYPE int => reserved for future use
        sqlDataType, // SQL_DATETIME_SUB int => reserved for future use
        sqlDateTimeSub, // returned value is a NULL
        charOctetLength, // column ordinal positions are implementation defined.
        ordinalPosition, // unknown
        isNullable, // identifies this procedure within its schema.
        specificName };
        PROCEDURE_COLUMNS = new ColumnInfo[] { // PROCEDURE_CAT String => procedure catalog (may be null)
        procedureCat, // PROCEDURE_SCHEM String => procedure schema (may be null)
        procedureSchema, // PROCEDURE_NAME String => procedure name
        procedureName, // reserved for future use
        empty, // reserved for future use
        empty, // reserved for future use
        empty, // REMARKS String => explanatory comment on the procedure
        remarks, // procedureReturnsResult - Returns a return value
        procedureType, // identifies this procedure within its schema.
        specificName };
        PSUEDO_COLUMN_COLUMNS = new ColumnInfo[] { // TABLE_CAT String => table catalog (may be null)
        tableCat, // TABLE_SCHEM String => table schema (may be null)
        tableSchema, // TABLE_NAME String => table name
        tableName, // COLUMN_NAME String => column name
        columnName, // DATA_TYPE int => SQL type from java.sql.Types
        dataType, // COLUMN_SIZE int => column size.
        columnSize, // not applicable.
        decimalDigits, // NUM_PREC_RADIX int => Radix (typically either 10 or 2)
        numPrecRadix, // returned by PseudoColumnUsage.name()
        columnUsage, // REMARKS String => comment describing column (may be null)
        remarks, // number of bytes in the column
        charOctetLength, // unknown
        isNullable };
        // NB - For some reason JDBC suddenly uses TABLE_CATALOG instead of
        // TABLE_CAT here?
        SCHEMA_COLUMNS = new ColumnInfo[] { // TABLE_SCHEM String => schema name
        tableSchema, // TABLE_CATALOG String => catalog name (may be null)
        tableCatalog };
        SUPER_TABLE_COLUMNS = new ColumnInfo[] { // TABLE_CAT String => the type's catalog (may be null)
        tableCat, // TABLE_SCHEM String => type's schema (may be null)
        tableSchema, // TABLE_NAME String => type name
        tableName, // SUPERTABLE_NAME String => the direct super type's name
        superTableName };
        SUPER_TYPE_COLUMNS = new ColumnInfo[] { // TYPE_CAT String => the UDT's catalog (may be null)
        typeCat, // TYPE_SCHEM String => UDT's schema (may be null)
        typeSchema, // TYPE_NAME String => type name of the UDT
        typeName, // (may be null)
        superTypeCat, // (may be null)
        superTypeSchema, // SUPERTYPE_NAME String => the direct super type's name
        superTypeName };
        TABLE_PRIVILEGE_COLUMNS = new ColumnInfo[] { // TABLE_CAT String => table catalog (may be null)
        tableCat, // TABLE_SCHEM String => table schema (may be null)
        tableSchema, // TABLE_NAME String => table name
        tableName, // GRANTOR String => grantor of access (may be null)
        grantor, // GRANTEE String => grantee of access
        grantee, // UPDATE, REFRENCES, ...)
        privilege, // grant to others; "NO" if not; null if unknown
        isGrantable };
        TABLE_TYPE_COLUMNS = new ColumnInfo[] { // "ALIAS", "SYNONYM".
        tableType };
        TABLE_COLUMNS = new ColumnInfo[] { // TABLE_CAT String => table catalog (may be null)
        tableCat, // TABLE_SCHEM String => table schema (may be null)
        tableSchema, // TABLE_NAME String => table name
        tableName, // "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
        tableType, // REMARKS String => explanatory comment on the table
        remarks, // TYPE_CAT String => the types catalog (may be null)
        typeCat, // TYPE_SCHEM String => the types schema (may be null)
        typeSchema, // TYPE_NAME String => type name (may be null)
        typeName, // null)
        selfRefColName, // "SYSTEM", "USER", "DERIVED". (may be null)
        refGeneration };
        TYPE_INFO_COLUMNS = new ColumnInfo[] { // TYPE_NAME String => Type name
        typeName, // DATA_TYPE int => SQL data type from java.sql.Types
        dataType, // PRECISION int => maximum precision
        precision, // (may be null)
        litPrefix, // (may be null)
        litSuffix, // type (may be null)
        createParams, // typeNullableUnknown - nullability unknown
        shortNullable, // CASE_SENSITIVE boolean=> is it case sensitive.
        caseSensitive, // typeSearchable - Supported for all WHERE ..
        searchable, // UNSIGNED_ATTRIBUTE boolean => is it unsigned.
        unsignedAttr, // FIXED_PREC_SCALE boolean => can it be a money value.
        fixedPrecScale, // auto-increment value.
        autoIncrement, // (may be null)
        localTypeName, // MINIMUM_SCALE short => minimum scale supported
        minScale, // MAXIMUM_SCALE short => maximum scale supported
        maxScale, // SQL_DATA_TYPE int => unused
        sqlDataType, // SQL_DATETIME_SUB int => unused
        sqlDateTimeSub, // NUM_PREC_RADIX int => usually 2 or 10
        numPrecRadix };
        UDT_COLUMNS = new ColumnInfo[] { // TYPE_CAT String => the type's catalog (may be null)
        typeCat, // TYPE_SCHEM String => type's schema (may be null)
        typeSchema, // TYPE_NAME String => type name
        typeName, // CLASS_NAME String => Java class name
        className, // One of JAVA_OBJECT, STRUCT, or DISTINCT
        dataType, // REMARKS String => explanatory comment on the type
        remarks, // not STRUCT with REFERENCE_GENERATION = USER_DEFINED)
        baseType };
        VERSION_COLUMNS = new ColumnInfo[] { // SCOPE short => is not used
        scope, // COLUMN_NAME String => column name
        columnName, // DATA_TYPE int => SQL data type from java.sql.Types
        dataType, // TYPE_NAME String => Data source-dependent type name
        typeName, // COLUMN_SIZE int => precision
        columnSize, // BUFFER_LENGTH int => length of column value in bytes
        bufferLength, // types where DECIMAL_DIGITS is not applicable.
        decimalDigits, // versionColumnPseudo - is a pseudo column
        psuedoColumn };
    } catch (SQLException e) {
        throw new Error("Fatal error initializing JDBC metadata schema information");
    }
    init = true;
}
Also used : ShortIntegerColumn(org.apache.jena.jdbc.results.metadata.columns.ShortIntegerColumn) StringColumn(org.apache.jena.jdbc.results.metadata.columns.StringColumn) ShortIntegerColumn(org.apache.jena.jdbc.results.metadata.columns.ShortIntegerColumn) IntegerColumn(org.apache.jena.jdbc.results.metadata.columns.IntegerColumn) SQLException(java.sql.SQLException) BooleanColumn(org.apache.jena.jdbc.results.metadata.columns.BooleanColumn) ColumnInfo(org.apache.jena.jdbc.results.metadata.columns.ColumnInfo)

Example 4 with StringColumn

use of org.apache.jena.jdbc.results.metadata.columns.StringColumn in project jena by apache.

the class SelectResultsMetadata method makeColumns.

/**
     * Makes column information for SELECT results
     * 
     * @param results
     *            Result Set
     * @param rset
     *            Underlying SPARQL results
     * @return Column information
     * @throws SQLException
     *             Thrown if the column information cannot be created
     */
private static ColumnInfo[] makeColumns(JenaResultSet results, ResultSetPeekable rset) throws SQLException {
    List<String> vars = rset.getResultVars();
    ColumnInfo[] columns = new ColumnInfo[vars.size()];
    int level = JdbcCompatibility.normalizeLevel(results.getJdbcCompatibilityLevel());
    boolean columnsAsStrings = JdbcCompatibility.shouldTypeColumnsAsString(level);
    boolean columnsDetected = JdbcCompatibility.shouldDetectColumnTypes(level);
    Binding b = null;
    if (columnsDetected) {
        if (rset.hasNext()) {
            b = rset.peekBinding();
        } else {
            // If we were supposed to detect columns but there is no data
            // available then we will just fallback to typing everything as
            // strings
            columnsAsStrings = true;
            columnsDetected = false;
        }
    }
    for (int i = 0; i < columns.length; i++) {
        if (!columnsAsStrings && !columnsDetected) {
            // Low compatibility, report columns as being typed as
            // JAVA_OBJECT with ARQ Node as the column class
            columns[i] = new SparqlColumnInfo(vars.get(i), Types.JAVA_OBJECT, columnNullable);
            LOGGER.info("Low JDBC compatibility, column " + vars.get(i) + " is being typed as Node");
        } else if (columnsAsStrings) {
            // Medium compatibility, report columns as being typed as
            // NVARCHAR with String as the column class
            columns[i] = new StringColumn(vars.get(i), columnNullable);
            LOGGER.info("Medium JDBC compatibility, column " + vars.get(i) + " is being typed as String");
        } else if (columnsDetected) {
            // High compatibility, detect columns types based on first row
            // of results
            columns[i] = JdbcCompatibility.detectColumnType(vars.get(i), b.get(Var.alloc(vars.get(i))), true);
            LOGGER.info("High compatibility, column " + vars.get(i) + " was detected as being of type " + columns[i].getClassName());
        } else {
            throw new SQLFeatureNotSupportedException("Unknown JDBC compatibility level was set");
        }
    }
    return columns;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) StringColumn(org.apache.jena.jdbc.results.metadata.columns.StringColumn) SparqlColumnInfo(org.apache.jena.jdbc.results.metadata.columns.SparqlColumnInfo) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) ColumnInfo(org.apache.jena.jdbc.results.metadata.columns.ColumnInfo) SparqlColumnInfo(org.apache.jena.jdbc.results.metadata.columns.SparqlColumnInfo)

Example 5 with StringColumn

use of org.apache.jena.jdbc.results.metadata.columns.StringColumn in project jena by apache.

the class TripleResultsMetadata method makeColumns.

/**
     * Gets the columns for CONSTRUCT/DESCRIBE results
     * 
     * @param results
     *            Results
     * @param ts
     *            Underlying triples
     * @param subjLabel
     *            Label for subject column, use {@code null} to omit the subject
     *            column
     * @param predLabel
     *            Label for predicate column, use {@code null} to omit the
     *            predicate column
     * @param objLabel
     *            Label for object column, use {@code null} to omit the object
     *            column
     * 
     * @return Column Information
     * @throws SQLException
     */
private static ColumnInfo[] makeColumns(JenaResultSet results, PeekIterator<Triple> ts, String subjLabel, String predLabel, String objLabel) throws SQLException {
    int numColumns = 0;
    if (subjLabel != null)
        numColumns++;
    if (predLabel != null)
        numColumns++;
    if (objLabel != null)
        numColumns++;
    ColumnInfo[] columns = new ColumnInfo[numColumns];
    // Figure out column names
    String[] names = new String[numColumns];
    names[0] = subjLabel != null ? subjLabel : (predLabel != null ? predLabel : objLabel);
    if (numColumns > 1) {
        names[1] = subjLabel != null && predLabel != null ? predLabel : objLabel;
    }
    if (numColumns == 3) {
        names[2] = objLabel;
    }
    int level = JdbcCompatibility.normalizeLevel(results.getJdbcCompatibilityLevel());
    boolean columnsAsStrings = JdbcCompatibility.shouldTypeColumnsAsString(level);
    boolean columnsDetected = JdbcCompatibility.shouldDetectColumnTypes(level);
    Triple t = null;
    Node[] values = new Node[numColumns];
    if (columnsDetected) {
        if (ts.hasNext()) {
            // Need to peek the first Triple and grab appropriate nodes
            t = ts.peek();
            if (numColumns == NUM_COLUMNS) {
                values[0] = t.getSubject();
                values[1] = t.getPredicate();
                values[2] = t.getObject();
            } else {
                values[0] = subjLabel != null ? t.getSubject() : (predLabel != null ? t.getPredicate() : t.getObject());
                if (numColumns > 1) {
                    values[1] = subjLabel != null && predLabel != null ? t.getPredicate() : t.getObject();
                }
            }
        } else {
            // If we were supposed to detect columns but there is no data
            // available then we will just fallback to typing everything as
            // strings
            columnsAsStrings = true;
            columnsDetected = false;
        }
    }
    for (int i = 0; i < columns.length; i++) {
        if (!columnsAsStrings && !columnsDetected) {
            // Low compatibility, report columns as being typed as
            // JAVA_OBJECT with ARQ Node as the column class
            columns[i] = new SparqlColumnInfo(names[i], Types.JAVA_OBJECT, columnNoNulls);
            LOGGER.info("Low JDBC compatibility, column " + names[i] + " is being typed as Node");
        } else if (columnsAsStrings) {
            // Medium compatibility, report columns as being typed as
            // NVARChar with String as the column class
            columns[i] = new StringColumn(names[i], columnNoNulls);
            LOGGER.info("Medium JDBC compatibility, column " + names[i] + " is being typed as String");
        } else if (columnsDetected) {
            // High compatibility, detect columns types based on first row
            // of results
            columns[i] = JdbcCompatibility.detectColumnType(names[i], values[i], false);
            LOGGER.info("High compatibility, column " + names[i] + " was detected as being of type " + columns[i].getClassName());
        } else {
            throw new SQLFeatureNotSupportedException("Unknown JDBC compatibility level was set");
        }
    }
    return columns;
}
Also used : Triple(org.apache.jena.graph.Triple) StringColumn(org.apache.jena.jdbc.results.metadata.columns.StringColumn) SparqlColumnInfo(org.apache.jena.jdbc.results.metadata.columns.SparqlColumnInfo) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) Node(org.apache.jena.graph.Node) ColumnInfo(org.apache.jena.jdbc.results.metadata.columns.ColumnInfo) SparqlColumnInfo(org.apache.jena.jdbc.results.metadata.columns.SparqlColumnInfo)

Aggregations

StringColumn (org.apache.jena.jdbc.results.metadata.columns.StringColumn)6 MetaResultSet (org.apache.jena.jdbc.metadata.results.MetaResultSet)3 ColumnInfo (org.apache.jena.jdbc.results.metadata.columns.ColumnInfo)3 Test (org.junit.Test)3 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 SparqlColumnInfo (org.apache.jena.jdbc.results.metadata.columns.SparqlColumnInfo)2 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 BooleanColumn (org.apache.jena.jdbc.results.metadata.columns.BooleanColumn)1 IntegerColumn (org.apache.jena.jdbc.results.metadata.columns.IntegerColumn)1 ShortIntegerColumn (org.apache.jena.jdbc.results.metadata.columns.ShortIntegerColumn)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1