Package org.apache.jena.jdbc.results.metadata.columns

Examples of org.apache.jena.jdbc.results.metadata.columns.StringColumn


                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);
View Full Code Here


        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)
View Full Code Here

                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);
View Full Code Here

     *
     * @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());

View Full Code Here

     * @throws SQLException
     */
    @Test(expected = SQLException.class)
    public void meta_result_set_bad_01() throws SQLException {
        // Every row must have the correct number of columns
        new MetaResultSet(new ColumnInfo[] { new StringColumn("Test", ResultSetMetaData.columnNullable) }, new Object[][] { {} });
    }
View Full Code Here

     * @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());
View Full Code Here

     * @throws SQLException
     */
    @Test
    public void meta_result_set_string_02() throws SQLException {
        MetaResultSet results = new MetaResultSet(
                new ColumnInfo[] { new StringColumn("Test", ResultSetMetaData.columnNullable) }, new Object[][] { { null } });

        Assert.assertTrue(results.next());
        String value = results.getString(1);
        Assert.assertEquals(null, value);
        Assert.assertTrue(results.wasNull());
View Full Code Here

     */
    public static ColumnInfo detectColumnType(String var, Node value, boolean allowsNulls) throws SQLException {
        if (allowsNulls && value == null) {
            // If we are allowing nulls and the value is null just type the
            // column as string
            return new StringColumn(var, ResultSetMetaData.columnNullable);
        } else if (!allowsNulls && value == null) {
            throw new SQLException("Unable to determine column type, column is non-nullable but example value is null");
        } else {
            // We know we have a non-null value so now we need to determine the
            // column type appropriately
            int nullable = allowsNulls ? ResultSetMetaData.columnNullable : ResultSetMetaData.columnNoNulls;
            if (value.isBlank()) {
                // Type blank nodes as strings
                return new StringColumn(var, nullable);
            } else if (value.isURI()) {
                // Type URIs as strings
                // TODO: Does JDBC have a URL type?
                return new StringColumn(var, nullable);
            } else if (value.isLiteral()) {
                // Literals will be typed based on the declared data type where
                // applicable
                String dtUri = value.getLiteralDatatypeURI();
                if (dtUri != null) {
                    // Is a typed literal
                    return selectColumnType(var, dtUri, nullable);
                } else {
                    // Untyped literals are typed as strings
                    return new StringColumn(var, nullable);
                }
            } else {
                // Anything else we treat as a string
                return new StringColumn(var, nullable);
            }
        }
    }
View Full Code Here

        } else if (dtUri.equals(XSD.decimal.toString())) {
            // Decimal column
            return new DecimalColumn(var, nullable);
        } else if (dtUri.equals(XSD.duration.toString())) {
            // JDBC has no notion of durations so return as a string
            return new StringColumn(var, nullable);
        } else if (dtUri.equals(XSD.integer.toString()) || dtUri.equals(XSD.xint.toString())
                || dtUri.equals(XSD.xlong.toString())) {
            // Integer column
            return new LongIntegerColumn(var, nullable, true);
        } else if (dtUri.equals(XSD.unsignedInt.toString()) || dtUri.equals(XSD.unsignedLong.toString())) {
            // Unsigned Integer column
            return new LongIntegerColumn(var, nullable, false);
        } else if (dtUri.equals(XSD.positiveInteger.toString()) || dtUri.equals(XSD.nonNegativeInteger.toString())) {
            // Unsigned Integer column
            return new LongIntegerColumn(var, nullable, false);
        } else if (dtUri.equals(XSD.nonPositiveInteger.toString()) || dtUri.equals(XSD.negativeInteger.toString())) {
            // Signed Integer column
            return new LongIntegerColumn(var, nullable, true);
        } else if (dtUri.equals(XSD.xshort.toString())) {
            // Short Integer column
            return new IntegerColumn(var, nullable, true);
        } else if (dtUri.equals(XSD.unsignedShort.toString())) {
            // Unsigned Short Integer column
            return new IntegerColumn(var, nullable, false);
        } else if (dtUri.equals(XSD.xbyte.toString())) {
            // Signed Byte
            return new ByteColumn(var, nullable, true);
        } else if (dtUri.equals(XSD.unsignedByte.toString())) {
            // Unsigned Byte
            return new ByteColumn(var, nullable, false);
        } else if (dtUri.equals(XSD.time.toString())) {
            // Time column
            return new TimeColumn(var, nullable);
        } else if (dtUri.equals(XSD.xboolean.toString())) {
            // Boolean column
            return new BooleanColumn(var, nullable);
        } else if (dtUri.equals(XSD.xdouble.toString())) {
            // Double column
            return new DoubleColumn(var, nullable);
        } else if (dtUri.equals(XSD.xfloat.toString())) {
            // Float column
            return new FloatColumn(var, nullable);
        } else if (dtUri.equals(XSD.xstring.toString())) {
            // String column
            return new StringColumn(var, nullable);
        } else {
            // Anything else we'll treat as a String
            return new StringColumn(var, nullable);
        }
    }
View Full Code Here

     */
    public static ColumnInfo detectColumnType(String var, Node value, boolean allowsNulls) throws SQLException {
        if (allowsNulls && value == null) {
            // If we are allowing nulls and the value is null just type the
            // column as string
            return new StringColumn(var, ResultSetMetaData.columnNullable);
        } else if (!allowsNulls && value == null) {
            throw new SQLException("Unable to determine column type, column is non-nullable but example value is null");
        } else {
            // We know we have a non-null value so now we need to determine the
            // column type appropriately
            int nullable = allowsNulls ? ResultSetMetaData.columnNullable : ResultSetMetaData.columnNoNulls;
            if (value.isBlank()) {
                // Type blank nodes as strings
                return new StringColumn(var, nullable);
            } else if (value.isURI()) {
                // Type URIs as strings
                // TODO: Does JDBC have a URL type?
                return new StringColumn(var, nullable);
            } else if (value.isLiteral()) {
                // Literals will be typed based on the declared data type where
                // applicable
                String dtUri = value.getLiteralDatatypeURI();
                if (dtUri != null) {
                    // Is a typed literal
                    return selectColumnType(var, dtUri, nullable);
                } else {
                    // Untyped literals are typed as strings
                    return new StringColumn(var, nullable);
                }
            } else {
                // Anything else we treat as a string
                return new StringColumn(var, nullable);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jena.jdbc.results.metadata.columns.StringColumn

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.