You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2013/08/29 02:32:22 UTC
svn commit: r1518427 - in
/jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata:
JenaMetadata.java MetadataSchema.java
Author: rvesse
Date: Thu Aug 29 00:32:22 2013
New Revision: 1518427
URL: http://svn.apache.org/r1518427
Log:
Add implementation for JDBC 4.1 DatabaseMetadata methods
Modified:
jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java
jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java
Modified: jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java?rev=1518427&r1=1518426&r2=1518427&view=diff
==============================================================================
--- jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java (original)
+++ jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java Thu Aug 29 00:32:22 2013
@@ -107,6 +107,7 @@ public abstract class JenaMetadata imple
/**
* Gets the associated Jena connection instance
+ *
* @return Jena connection
*/
public JenaConnection getJenaConnection() {
@@ -567,32 +568,64 @@ public abstract class JenaMetadata imple
// SQL_DATA_TYPE int => unused
// SQL_DATETIME_SUB int => unused
// NUM_PREC_RADIX int => usually 2 or 10
-
- //Report types we can marshal appropriately
- return new MetaResultSet(MetadataSchema.getTypeInfoColumns(),
- new Object[][] {
- { XSD.xboolean.toString(), Types.BOOLEAN, 0, null, null, null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 0 },
- { XSD.xbyte.toString(), Types.TINYINT, Byte.toString(Byte.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 0 },
- { XSD.date.toString(), Types.DATE, 0, "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 0 },
- { XSD.dateTime.toString(), Types.DATE, 0, "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 0 },
- { XSD.decimal.toString(), Types.DECIMAL, 16, null, null, null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)16, 0, 0, 10 },
- { XSD.xdouble.toString(), Types.DOUBLE, 16, null, null, null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)16, 0, 0, 10 },
- { XSD.xfloat.toString(), Types.FLOAT, 15, "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)7, 0, 0, 10 },
- { XSD.xshort.toString(), Types.INTEGER, Integer.toString(Integer.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.integer.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), null, null, null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.xlong.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.xint.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.negativeInteger.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.nonNegativeInteger.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, true, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.nonPositiveInteger.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.positiveInteger.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, true, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.unsignedByte.toString(), Types.TINYINT, Byte.toString(Byte.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, true, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.unsignedInt.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, true, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.unsignedLong.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, true, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.unsignedShort.toString(), Types.INTEGER, Integer.toString(Integer.MAX_VALUE).length(), "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, true, false, false, null, (short)0, (short)0, 0, 0, 10 },
- { XSD.xstring.toString(), Types.NVARCHAR, 0, "\"", "\"", null, (short)typeNullable, true, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 0 },
- { XSD.time.toString(), Types.TIME, 0, "\"", "\"", null, (short)typeNullable, false, (short)typeSearchable, false, false, false, null, (short)0, (short)0, 0, 0, 0 },
- });
+
+ // Report types we can marshal appropriately
+ return new MetaResultSet(MetadataSchema.getTypeInfoColumns(), new Object[][] {
+ { XSD.xboolean.toString(), Types.BOOLEAN, 0, null, null, null, (short) typeNullable, false,
+ (short) typeSearchable, false, false, false, null, (short) 0, (short) 0, 0, 0, 0 },
+ { XSD.xbyte.toString(), Types.TINYINT, Byte.toString(Byte.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, false, false, false, null, (short) 0, (short) 0, 0,
+ 0, 0 },
+ { XSD.date.toString(), Types.DATE, 0, "\"", "\"", null, (short) typeNullable, false, (short) typeSearchable,
+ false, false, false, null, (short) 0, (short) 0, 0, 0, 0 },
+ { XSD.dateTime.toString(), Types.DATE, 0, "\"", "\"", null, (short) typeNullable, false, (short) typeSearchable,
+ false, false, false, null, (short) 0, (short) 0, 0, 0, 0 },
+ { XSD.decimal.toString(), Types.DECIMAL, 16, null, null, null, (short) typeNullable, false,
+ (short) typeSearchable, false, false, false, null, (short) 0, (short) 16, 0, 0, 10 },
+ { XSD.xdouble.toString(), Types.DOUBLE, 16, null, null, null, (short) typeNullable, false,
+ (short) typeSearchable, false, false, false, null, (short) 0, (short) 16, 0, 0, 10 },
+ { XSD.xfloat.toString(), Types.FLOAT, 15, "\"", "\"", null, (short) typeNullable, false, (short) typeSearchable,
+ false, false, false, null, (short) 0, (short) 7, 0, 0, 10 },
+ { XSD.xshort.toString(), Types.INTEGER, Integer.toString(Integer.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, false, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.integer.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), null, null, null,
+ (short) typeNullable, false, (short) typeSearchable, false, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.xlong.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, false, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.xint.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, false, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.negativeInteger.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, false, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.nonNegativeInteger.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, true, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.nonPositiveInteger.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, false, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.positiveInteger.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, true, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.unsignedByte.toString(), Types.TINYINT, Byte.toString(Byte.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, true, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.unsignedInt.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, true, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.unsignedLong.toString(), Types.BIGINT, Long.toString(Long.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, true, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.unsignedShort.toString(), Types.INTEGER, Integer.toString(Integer.MAX_VALUE).length(), "\"", "\"", null,
+ (short) typeNullable, false, (short) typeSearchable, true, false, false, null, (short) 0, (short) 0, 0,
+ 0, 10 },
+ { XSD.xstring.toString(), Types.NVARCHAR, 0, "\"", "\"", null, (short) typeNullable, true,
+ (short) typeSearchable, false, false, false, null, (short) 0, (short) 0, 0, 0, 0 },
+ { XSD.time.toString(), Types.TIME, 0, "\"", "\"", null, (short) typeNullable, false, (short) typeSearchable,
+ false, false, false, null, (short) 0, (short) 0, 0, 0, 0 }, });
}
@Override
@@ -1029,7 +1062,8 @@ public abstract class JenaMetadata imple
@Override
public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException {
// We only support read-only result sets
- if (concurrency != ResultSet.CONCUR_READ_ONLY) return false;
+ if (concurrency != ResultSet.CONCUR_READ_ONLY)
+ return false;
return supportsResultSetType(type);
}
@@ -1185,15 +1219,14 @@ public abstract class JenaMetadata imple
@Override
public abstract boolean usesLocalFiles() throws SQLException;
- public ResultSet getPseudoColumns(String catalog,
- String schemaPattern,
- String tableNamePattern,
- String columnNamePattern) throws SQLException {
- throw new SQLFeatureNotSupportedException();
- }
-
- // Java 6/7 compatibility
- public boolean generatedKeyAlwaysReturned() throws SQLException {
- throw new SQLFeatureNotSupportedException();
- }
+ public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)
+ throws SQLException {
+ return new MetaResultSet(MetadataSchema.getPsuedoColumnColumns());
+ }
+
+ // Java 6/7 compatibility
+ public boolean generatedKeyAlwaysReturned() throws SQLException {
+ // We don't support returning keys
+ return false;
+ }
}
Modified: jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java?rev=1518427&r1=1518426&r2=1518427&view=diff
==============================================================================
--- jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java (original)
+++ jena/trunk/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java Thu Aug 29 00:32:22 2013
@@ -47,8 +47,8 @@ public class MetadataSchema {
private static ColumnInfo[] ATTRIBUTE_COLUMNS, BEST_ROW_IDENTIFIER_COLUMNS, CATALOG_COLUMNS, CLIENT_INFO_PROPERTY_COLUMNS,
COLUMN_COLUMNS, COLUMN_PRIVILEGE_COLUMNS, CROSS_REFERENCE_COLUMNS, EXPORTED_KEY_COLUMNS, FUNCTION_COLUMN_COLUMNS,
FUNCTION_COLUMNS, IMPORTED_KEY_COLUMNS, INDEX_INFO_COLUMNS, PRIMARY_KEY_COLUMNS, PROCEDURE_COLUMN_COLUMNS,
- PROCEDURE_COLUMNS, SCHEMA_COLUMNS, SUPER_TABLE_COLUMNS, SUPER_TYPE_COLUMNS, TABLE_PRIVILEGE_COLUMNS,
- TABLE_TYPE_COLUMNS, TABLE_COLUMNS, TYPE_INFO_COLUMNS, UDT_COLUMNS, VERSION_COLUMNS;
+ PROCEDURE_COLUMNS, PSUEDO_COLUMN_COLUMNS, SCHEMA_COLUMNS, SUPER_TABLE_COLUMNS, SUPER_TYPE_COLUMNS,
+ TABLE_PRIVILEGE_COLUMNS, TABLE_TYPE_COLUMNS, TABLE_COLUMNS, TYPE_INFO_COLUMNS, UDT_COLUMNS, VERSION_COLUMNS;
/**
* Gets the columns for the
@@ -207,6 +207,10 @@ public class MetadataSchema {
public static ColumnInfo[] getProcedureColumns() {
return PROCEDURE_COLUMNS;
}
+
+ public static ColumnInfo[] getPsuedoColumnColumns() {
+ return PSUEDO_COLUMN_COLUMNS;
+ }
/**
* Gets the columns for the {@link DatabaseMetaData#getSchemas()} method
@@ -414,6 +418,7 @@ public class MetadataSchema {
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)
@@ -1078,6 +1083,36 @@ public class MetadataSchema {
// SPECIFIC_NAME String => The name which uniquely
// 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,
+ // DECIMAL_DIGITS int => the number of fractional digits. Null is returned for data types where DECIMAL_DIGITS is not applicable.
+ decimalDigits,
+ // NUM_PREC_RADIX int => Radix (typically either 10 or 2)
+ numPrecRadix,
+ // COLUMN_USAGE String => The allowed usage for the column. The value returned will correspond to the enum name returned by PseudoColumnUsage.name()
+ columnUsage,
+ // REMARKS String => comment describing column (may be null)
+ remarks,
+ // CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column
+ charOctetLength,
+ // IS_NULLABLE String => ISO rules are used to determine the nullability for a column.
+ // YES --- if the column can include NULLs
+ // NO --- if the column cannot include NULLs
+ // empty string --- if the nullability for the column is unknown
+ isNullable
+ };
// NB - For some reason JDBC suddenly uses TABLE_CATALOG instead of
// TABLE_CAT here?