Author: rvesse
Date: Tue Apr 23 00:04:02 2013
New Revision: 1470757
URL: http://svn.apache.org/r1470757
Log:
Some metadata schema refactoring
Modified:
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java
Modified:
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java
URL:
http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java?rev=1470757&r1=1470756&r2=1470757&view=diff
==============================================================================
---
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java
(original)
+++
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java
Tue Apr 23 00:04:02 2013
@@ -140,8 +140,8 @@ public abstract class JenaMetadata imple
@Override
public String getCatalogSeparator() throws SQLException {
- // Use a . since that's what SQL would use AFAIK
- return ".";
+ // Use an empty string to indicate not applicable
+ return "";
}
@Override
@@ -166,8 +166,7 @@ public abstract class JenaMetadata imple
@Override
public ResultSet getColumns(String arg0, String arg1, String arg2, String
arg3) throws SQLException {
- // TODO Auto-generated method stub
- return null;
+ return new MetaResultSet(MetadataSchema.getColumnColumns());
}
@Override
Modified:
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java
URL:
http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java?rev=1470757&r1=1470756&r2=1470757&view=diff
==============================================================================
---
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java
(original)
+++
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java
Tue Apr 23 00:04:02 2013
@@ -28,6 +28,8 @@ import org.apache.jena.jdbc.results.meta
import org.apache.jena.jdbc.results.metadata.columns.ShortIntegerColumn;
import org.apache.jena.jdbc.results.metadata.columns.StringColumn;
+import com.hp.hpl.jena.sparql.algebra.table.TableN;
+
/**
* Helper class containing constants pertaining to the columns returned by
* various methods of a {@link DatabaseMetaData} implementation
@@ -43,17 +45,8 @@ public class MetadataSchema {
private static boolean init = false;
- private static ColumnInfo[] ATTRIBUTE_COLUMNS;
-
- private static ColumnInfo[] BEST_ROW_IDENTIFIER_COLUMNS;
-
- private static ColumnInfo[] CATALOG_COLUMNS;
-
- private static ColumnInfo[] CLIENT_INFO_PROPERTY_COLUMNS;
-
- private static ColumnInfo[] COLUMN_PRIVILEGE_COLUMNS;
-
- private static ColumnInfo[] UDT_COLUMNS;
+ private static ColumnInfo[] ATTRIBUTE_COLUMNS,
BEST_ROW_IDENTIFIER_COLUMNS, CATALOG_COLUMNS, CLIENT_INFO_PROPERTY_COLUMNS,
+ COLUMN_COLUMNS, COLUMN_PRIVILEGE_COLUMNS, UDT_COLUMNS;
/**
* Gets the columns for the
@@ -96,6 +89,10 @@ public class MetadataSchema {
public static ColumnInfo[] getClientInfoPropertyColumns() {
return CLIENT_INFO_PROPERTY_COLUMNS;
}
+
+ public static ColumnInfo[] getColumnColumns() {
+ return COLUMN_COLUMNS;
+ }
public static ColumnInfo[] getColumnPrivilegeColumns() {
return COLUMN_PRIVILEGE_COLUMNS;
@@ -122,73 +119,117 @@ public class MetadataSchema {
if (init)
return;
try {
+ // Define all the columns we are going to use since some of these
+ // appear in multiple schema
+ 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 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 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);
+
ATTRIBUTE_COLUMNS = new ColumnInfo[] {
// TYPE_CAT String => type catalog (may be null)
- new StringColumn("TYPE_CAT", columnNullable),
+ typeCat,
// TYPE_SCHEM String => type schema (may be null)
- new StringColumn("TYPE_SCHEM", columnNullable),
+ typeSchema,
// TYPE_NAME String => type name
- new StringColumn("TYPE_NAME", columnNoNulls),
+ typeName,
// ATTR_NAME String => attribute name
- new StringColumn("ATTR_NAME", columnNoNulls),
+ attrName,
// DATA_TYPE int => attribute type SQL type from
// java.sql.Types
- new IntegerColumn("DATA_TYPE", columnNoNulls, true),
+ dataType,
// ATTR_TYPE_NAME String => Data source dependent type
name.
// For a UDT, the type name is fully qualified. For a REF,
// the type name is fully qualified and represents the
// target type of the reference type.
- new StringColumn("ATTR_TYPE_NAME", columnNoNulls),
+ attrTypeName,
// ATTR_SIZE int => column size. For char or date types
this
// is the maximum number of characters; for numeric or
// decimal types this is precision.
- new IntegerColumn("ATTR_SIZE", columnNoNulls, true),
+ attrSize,
// DECIMAL_DIGITS int => the number of fractional digits.
// Null is returned for data types where DECIMAL_DIGITS is
// not applicable.
- new IntegerColumn("DECIMAL_DIGITS", columnNoNulls, true),
+ decimalDigits,
// NUM_PREC_RADIX int => Radix (typically either 10 or 2)
- new IntegerColumn("NUM_PREC_RADIX", columnNoNulls, true),
+ numPrecRadix,
// NULLABLE int => whether NULL is allowed
// attributeNoNulls - might not allow NULL values
// attributeNullable - definitely allows NULL values
// attributeNullableUnknown - nullability unknown
- new IntegerColumn("NULLABLE", columnNoNulls, true),
+ nullable,
// REMARKS String => comment describing column (may be
null)
- new StringColumn("REMARKS", columnNullable),
+ remarks,
// ATTR_DEF String => default value (may be null)
- new StringColumn("ATTR_DEF", columnNullable),
+ attrDef,
// SQL_DATA_TYPE int => unused
- new IntegerColumn("SQL_DATA_TYPE", columnNoNulls, true),
+ sqlDataType,
// SQL_DATETIME_SUB int => unused
- new IntegerColumn("SQL_DATETIME_SUB", columnNoNulls, true),
+ sqlDateTimeSub,
// CHAR_OCTET_LENGTH int => for char types the maximum
// number of bytes in the column
- new IntegerColumn("CHAR_OCTET_LENGTH", columnNoNulls,
true),
+ charOctetLength,
// ORDINAL_POSITION int => index of the attribute in the
UDT
// (starting at 1)
- new IntegerColumn("ORDINAL_POSITION", columnNoNulls, true),
+ ordinalPosition,
// IS_NULLABLE String => ISO rules are used to determine
the
// nullability for a attribute.
// YES --- if the attribute can include NULLs
// NO --- if the attribute cannot include NULLs
// empty string --- if the nullability for the attribute is
// unknown
- new StringColumn("IS_NULLABLE", columnNoNulls),
+ isNullable,
// SCOPE_CATALOG String => catalog of table that is the
// scope of a
// reference attribute (null if DATA_TYPE isn't REF)
- new StringColumn("SCOPE_CATALOG", columnNullable),
+ scopeCatalog,
// SCOPE_SCHEMA String => schema of table that is the scope
// of a reference attribute (null if DATA_TYPE isn't REF)
- new StringColumn("SCOPE_SCHEMA", columnNullable),
+ scopeSchema,
// SCOPE_TABLE String => table name that is the scope of a
// referenceattribute (null if the DATA_TYPE isn't REF)
- new StringColumn("SCOPE_TABLE", columnNullable),
+ scopeTable,
// SOURCE_DATA_TYPE short => source type of a distinct type
// or user-generated Ref type,SQL type from java.sql.Types
// (null if DATA_TYPE isn't DISTINCT or user-generated REF)
- new ShortIntegerColumn("SOURCE_DATA_TYPE", columnNullable,
true) };
+ sourceDataType };
BEST_ROW_IDENTIFIER_COLUMNS = new ColumnInfo[] {
// SCOPE short => actual scope of result
@@ -196,88 +237,172 @@ public class MetadataSchema {
// bestRowTransaction - valid for remainder of current
// transaction
// bestRowSession - valid for remainder of current session
- new ShortIntegerColumn("SCOPE", columnNoNulls, true),
+ scope,
// COLUMN_NAME String => column name
- new StringColumn("COLUMN_NAME", columnNoNulls),
+ columnName,
// DATA_TYPE int => SQL data type from java.sql.Types
- new IntegerColumn("DATA_TYPE", columnNoNulls, true),
+ dataType,
// TYPE_NAME String => Data source dependent type name, for
- // a UDT
- // the type name is fully qualified
- new StringColumn("TYPE_NAME", columnNoNulls),
+ // a UDT the type name is fully qualified
+ typeName,
// COLUMN_SIZE int => precision
- new IntegerColumn("COLUMN_SIZE", columnNoNulls, true),
+ columnSize,
// BUFFER_LENGTH int => not used
- new IntegerColumn("BUFFER_LENGTH", columnNoNulls, true),
+ bufferLength,
// DECIMAL_DIGITS short => scale - Null is returned for
data
- // types
- // where DECIMAL_DIGITS is not applicable.
- new ShortIntegerColumn("DECIMAL_DIGITS", columnNullable,
true),
+ // types where DECIMAL_DIGITS is not applicable.
+ decimalDigits,
// PSEUDO_COLUMN short => is this a pseudo column like an
// Oracle ROWID
// bestRowUnknown - may or may not be pseudo column
// bestRowNotPseudo - is NOT a pseudo column
// bestRowPseudo - is a pseudo column
- new ShortIntegerColumn("PSUEDO_COLUMN", columnNoNulls,
true) };
+ psuedoColumn };
CATALOG_COLUMNS = new ColumnInfo[] {
// TABLE_CAT String => catalog name
- new StringColumn("TABLE_CAT", columnNoNulls) };
+ tableCat };
CLIENT_INFO_PROPERTY_COLUMNS = new ColumnInfo[] {
// NAME String=> The name of the client info property
- new StringColumn("NAME", columnNoNulls),
+ name,
// MAX_LEN int=> The maximum length of the value for the
// property
- new IntegerColumn("MAX_LEN", columnNoNulls, true),
+ maxLen,
// DEFAULT_VALUE String=> The default value of the property
- new StringColumn("DEFAULT_VALUE", columnNullable),
+ defaultValue,
// DESCRIPTION String=> A description of the property. This
// will typically contain information as to where this
// property is stored in the database.
- new StringColumn("DESCRIPTION", columnNullable) };
+ 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,
+ // TYPE_NAME String => Data source dependent type name, for
+ // a UDT
+ // the type name is fully qualified
+ typeName,
+ // COLUMN_SIZE int => column size.
+ columnSize,
+ // BUFFER_LENGTH is not used.
+ bufferLength,
+ // 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,
+ // NULLABLE int => is NULL allowed.
+ // columnNoNulls - might not allow NULL values
+ // columnNullable - definitely allows NULL values
+ // columnNullableUnknown - nullability unknown
+ nullable,
+ // REMARKS String => comment describing column (may be
+ // null),
+ remarks,
+ // COLUMN_DEF String => default value for the column, which
+ // should
+ // be interpreted as a string when the value is enclosed in
+ // single
+ // quotes (may be null)
+ columnDef,
+ // SQL_DATA_TYPE int => unused
+ sqlDataType,
+ // SQL_DATETIME_SUB int => unused
+ sqlDateTimeSub,
+ // CHAR_OCTET_LENGTH int => for char types the maximum
+ // number of
+ // bytes in the column
+ charOctetLength,
+ // ORDINAL_POSITION int => index of column in table
+ // (starting at 1)
+ ordinalPosition,
+ // IS_NULLABLE String => ISO rules are used to determine
the
+ // nullability for a column.
+ // YES --- if the parameter can include NULLs
+ // NO --- if the parameter cannot include NULLs
+ // empty string --- if the nullability for the parameter is
+ // unknown
+ isNullable,
+ // SCOPE_CATLOG String => catalog of table that is the
scope
+ // of a
+ // reference attribute (null if DATA_TYPE isn't REF)
+ scopeCatalog,
+ // SCOPE_SCHEMA String => schema of table that is the scope
+ // of a
+ // reference attribute (null if the DATA_TYPE isn't REF)
+ scopeSchema,
+ // SCOPE_TABLE String => table name that this the scope of
a
+ // reference attribure (null if the DATA_TYPE isn't REF)
+ scopeTable,
+ // SOURCE_DATA_TYPE short => source type of a distinct type
+ // or
+ // user-generated Ref type, SQL type from java.sql.Types
+ // (null if
+ // DATA_TYPE isn't DISTINCT or user-generated REF)
+ sourceDataType,
+ // IS_AUTOINCREMENT String => Indicates whether this column
+ // is auto
+ // incremented
+ // YES --- if the column is auto incremented
+ // NO --- if the column is not auto incremented
+ // empty string --- if it cannot be determined whether the
+ // column is
+ // auto incremented parameter is unknown
+ isAutoIncrement };
COLUMN_PRIVILEGE_COLUMNS = new ColumnInfo[] {
// TABLE_CAT String => table catalog (may be null)
- new StringColumn("TABLE_CAT", columnNullable),
+ tableCat,
// TABLE_SCHEM String => table schema (may be null)
- new StringColumn("TABLE_SCHEM", columnNullable),
+ tableSchema,
// TABLE_NAME String => table name
- new StringColumn("TABLE_NAME", columnNoNulls),
+ tableName,
// COLUMN_NAME String => column name
- new StringColumn("COLUMN_NAME", columnNoNulls),
+ columnName,
// GRANTOR String => grantor of access (may be null)
- new StringColumn("GRANTOR", columnNullable),
+ grantor,
// GRANTEE String => grantee of access
- new StringColumn("GRANTEE", columnNullable),
+ grantee,
// PRIVILEGE String => name of access (SELECT, INSERT,
// UPDATE, REFRENCES, ...)
- new StringColumn("PRIVILEGE", columnNoNulls),
+ privilege,
// IS_GRANTABLE String => "YES" if grantee is permitted to
// grant to others; "NO" if not; null if unknown
- new StringColumn("IS_GRANTABLE", columnNoNulls) };
+ isGrantable };
UDT_COLUMNS = new ColumnInfo[] {
// TYPE_CAT String => the type's catalog (may be null)
- new StringColumn("TYPE_CAT", columnNullable),
+ typeCat,
// TYPE_SCHEM String => type's schema (may be null)
- new StringColumn("TYPE_SCHEM", columnNullable),
+ typeSchema,
// TYPE_NAME String => type name
- new StringColumn("TYPE_NAME", columnNoNulls),
+ typeName,
// CLASS_NAME String => Java class name
- new StringColumn("CLASS_NAME", columnNoNulls),
+ className,
// DATA_TYPE int => type value defined in java.sql.Types.
// One of JAVA_OBJECT, STRUCT, or DISTINCT
- new IntegerColumn("DATA_TYPE", columnNoNulls, true),
+ dataType,
// REMARKS String => explanatory comment on the type
- new StringColumn("REMARKS", columnNullable),
+ remarks,
// BASE_TYPE short => type code of the source type of a
// DISTINCT type or the type that implements the
// user-generated reference type of the
// SELF_REFERENCING_COLUMN of a structured type as defined
// in java.sql.Types (null if DATA_TYPE is not DISTINCT or
// not STRUCT with REFERENCE_GENERATION = USER_DEFINED)
- new ShortIntegerColumn("BASE_TYPE", columnNullable, true)
};
+ baseType };
+
} catch (SQLException e) {
throw new Error("Fatal error initializing JDBC metadata schema
information");
}