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/03/04 23:08:05 UTC
svn commit: r1452559 [1/2] - in /jena/Experimental/jena-jdbc: ./
jena-jdbc-core/ jena-jdbc-core/src/ jena-jdbc-core/src/main/
jena-jdbc-core/src/main/java/ jena-jdbc-core/src/main/java/org/
jena-jdbc-core/src/main/java/org/apache/ jena-jdbc-core/src/ma...
Author: rvesse
Date: Mon Mar 4 22:08:04 2013
New Revision: 1452559
URL: http://svn.apache.org/r1452559
Log:
Initial stubs for an experimental SPARQL JDBC layer for Jena
Added:
jena/Experimental/jena-jdbc/ (with props)
jena/Experimental/jena-jdbc/jena-jdbc-core/ (with props)
jena/Experimental/jena-jdbc/jena-jdbc-core/pom.xml
jena/Experimental/jena-jdbc/jena-jdbc-core/src/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcConnection.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcStatement.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaTransactionalJdbcConnection.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaJdbcResultSet.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/SelectResults.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/JenaJdbcNodeUtils.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/resources/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/resources/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/ (with props)
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/pom.xml
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/JenaJdbcDatasetConnection.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/JenaJdbcDatasetStatement.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/resources/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcDatasetConnection.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/resources/
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/ (with props)
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/pom.xml
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/resources/
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/resources/
jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/ (with props)
jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/pom.xml
jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/
jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/main/
jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/main/java/
jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/main/resources/
jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/
jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/
jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/resources/
jena/Experimental/jena-jdbc/pom.xml
Propchange: jena/Experimental/jena-jdbc/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Mar 4 22:08:04 2013
@@ -0,0 +1,3 @@
+.settings
+.project
+src
Propchange: jena/Experimental/jena-jdbc/jena-jdbc-core/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Mar 4 22:08:04 2013
@@ -0,0 +1,4 @@
+.classpath
+.settings
+.project
+target
Added: jena/Experimental/jena-jdbc/jena-jdbc-core/pom.xml
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/pom.xml?rev=1452559&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/pom.xml (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/pom.xml Mon Mar 4 22:08:04 2013
@@ -0,0 +1,24 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>jena-jdbc</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>jena-jdbc-core</artifactId>
+ <name>Jena JDBC - Core</name>
+ <description>This library provides core functionality for Jena JDBC</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>jena-arq</artifactId>
+ <version>2.10.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>tests</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcConnection.java?rev=1452559&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcConnection.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcConnection.java Mon Mar 4 22:08:04 2013
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.jdbc;
+
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLClientInfoException;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLRecoverableException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.Struct;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Abstract base implementation of a Jena JDBC connection
+ *
+ */
+public abstract class JenaJdbcConnection implements Connection {
+
+ /**
+ * Constant for default cursor holdability for Jena JDBC connections
+ */
+ public static final int DEFAULT_HOLDABILITY = ResultSet.CLOSE_CURSORS_AT_COMMIT;
+
+ private Properties clientInfo = new Properties();
+ private int holdability = DEFAULT_HOLDABILITY;
+ private SQLWarning warnings = null;
+
+ /**
+ * Creates a new connection
+ * @throws SQLException Thrown if the arguments are invalid
+ */
+ public JenaJdbcConnection() throws SQLException {
+ this(DEFAULT_HOLDABILITY);
+ }
+
+ /**
+ * Creates a new connection
+ * @param holdability Cursor holdability
+ * @throws SQLException Thrown if the arguments are invalid
+ */
+ public JenaJdbcConnection(int holdability) throws SQLException {
+ this.checkHoldability(holdability);
+ this.holdability = holdability;
+ }
+
+ public boolean isWrapperFor(Class<?> arg0) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public <T> T unwrap(Class<T> arg0) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void clearWarnings() throws SQLException {
+ this.warnings = null;
+ }
+
+ public abstract void close() throws SQLException;
+
+ public void commit() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Blob createBlob() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Clob createClob() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public NClob createNClob() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public SQLXML createSQLXML() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public abstract Statement createStatement() throws SQLException;
+
+ public abstract Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException;
+
+ public abstract Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException;
+
+ public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public boolean getAutoCommit() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public String getCatalog() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Properties getClientInfo() throws SQLException {
+ return this.clientInfo;
+ }
+
+ public String getClientInfo(String name) throws SQLException {
+ return this.clientInfo.getProperty(name);
+ }
+
+ public int getHoldability() throws SQLException {
+ return this.holdability;
+ }
+
+ public DatabaseMetaData getMetaData() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public int getTransactionIsolation() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Map<String, Class<?>> getTypeMap() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return this.warnings;
+ }
+
+ public abstract boolean isClosed() throws SQLException;
+
+ public abstract boolean isReadOnly() throws SQLException;
+
+ public abstract boolean isValid(int timeout) throws SQLException;
+
+ public String nativeSQL(String sql) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public CallableStatement prepareCall(String sql) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public abstract PreparedStatement prepareStatement(String sql) throws SQLException;
+
+ public abstract PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException;
+
+ public abstract PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException;
+
+ public abstract PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException;
+
+ public abstract PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException;
+
+ public abstract PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException;
+
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void rollback() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void rollback(Savepoint savepoint) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void setCatalog(String catalog) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void setClientInfo(Properties properties) throws SQLClientInfoException {
+ this.clientInfo = properties;
+ }
+
+ public void setClientInfo(String name, String value) throws SQLClientInfoException {
+ this.clientInfo.put(name, value);
+ }
+
+ public void setHoldability(int holdability) throws SQLException {
+ this.checkHoldability(holdability);
+ this.holdability = holdability;
+ }
+
+ /**
+ * Helper method that checks whether the given holdability setting is valid, throws an error if it is not
+ * @param h Holdability Setting
+ * @throws SQLException Thrown if the setting is not valid
+ */
+ protected void checkHoldability(int h) throws SQLException {
+ switch (h) {
+ case ResultSet.CLOSE_CURSORS_AT_COMMIT:
+ case ResultSet.HOLD_CURSORS_OVER_COMMIT:
+ return;
+ default:
+ throw new SQLRecoverableException(String.format("%d is not a valid holdability setting", h));
+ }
+ }
+
+ public abstract void setReadOnly(boolean readOnly) throws SQLException;
+
+ public Savepoint setSavepoint() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Savepoint setSavepoint(String name) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void setTransactionIsolation(int level) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ /**
+ * Helper method that derived classes may use to set warnings
+ * @param warning Warning
+ */
+ protected void setWarning(SQLWarning warning) {
+ if (this.warnings == null) {
+ this.warnings = warning;
+ } else {
+ // Chain with existing warnings
+ warning.setNextWarning(this.warnings);
+ this.warnings = warning;
+ }
+ }
+
+ /**
+ * Helper method that derived classes may use to set warnings
+ * @param warning Warning
+ */
+ protected void setWarning(String warning) {
+ this.setWarning(new SQLWarning(warning));
+ }
+
+ /**
+ * Helper method that derived classes may use to set warnings
+ * @param warning Warning
+ * @param cause Cause
+ */
+ protected void setWarning(String warning, Throwable cause) {
+ this.setWarning(new SQLWarning(warning, cause));
+ }
+
+}
Added: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcStatement.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcStatement.java?rev=1452559&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcStatement.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcStatement.java Mon Mar 4 22:08:04 2013
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.jdbc;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+import org.apache.jena.jdbc.results.SelectResults;
+
+import com.hp.hpl.jena.query.Query;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.update.UpdateFactory;
+import com.hp.hpl.jena.update.UpdateProcessor;
+import com.hp.hpl.jena.update.UpdateRequest;
+
+/**
+ * Abstract Jena JDBC implementation of a statement that only permits read
+ * operations
+ *
+ */
+public abstract class JenaJdbcStatement implements Statement {
+
+ protected static final int DEFAULT_HOLDABILITY = ResultSet.CLOSE_CURSORS_AT_COMMIT;
+ protected static final int DEFAULT_FETCH_DIRECTION = ResultSet.FETCH_FORWARD;
+ protected static final int DEFAULT_FETCH_SIZE = 0;
+ protected static final int NO_LIMIT = 0;
+
+ private List<String> commands = new ArrayList<String>();
+ private SQLWarning warnings = null;
+ private Connection connection;
+ private ResultSet currResults = null;
+ private Queue<ResultSet> results = new LinkedList<ResultSet>();
+ private List<ResultSet> openResults = new ArrayList<ResultSet>();
+ private boolean closed = false;
+ private int fetchDirection = DEFAULT_FETCH_DIRECTION;
+ private int fetchSize = DEFAULT_FETCH_SIZE;
+ private int holdability = DEFAULT_HOLDABILITY;
+ private int updateCount = 0;
+ @SuppressWarnings("unused")
+ private boolean escapeProcessing = false;
+ private int timeout = NO_LIMIT;
+
+ /**
+ * Creates a new statement
+ *
+ * @param connection
+ * Connection
+ * @throws SQLException
+ * Thrown if the arguments are invalid
+ */
+ public JenaJdbcStatement(Connection connection) throws SQLException {
+ this(connection, DEFAULT_FETCH_DIRECTION, DEFAULT_FETCH_SIZE, DEFAULT_HOLDABILITY);
+ }
+
+ /**
+ * Creates a new statement
+ *
+ * @param connection
+ * Connection
+ * @param fetchDir
+ * Fetch Direction
+ * @param fetchSize
+ * Fetch Size
+ * @param holdability
+ * Result Set holdability
+ * @throws SQLException
+ * Thrown if there is an error with the statement parameters
+ *
+ */
+ public JenaJdbcStatement(Connection connection, int fetchDir, int fetchSize, int holdability) throws SQLException {
+ if (connection == null)
+ throw new SQLException("Cannot create a Statement with a null connection");
+ this.connection = connection;
+ this.checkFetchDirection(fetchDir);
+ this.fetchDirection = fetchDir;
+ this.fetchSize = fetchSize;
+ this.checkHoldability(holdability);
+ this.holdability = holdability;
+ }
+
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void addBatch(String sql) throws SQLException {
+ this.commands.add(sql);
+ }
+
+ public void cancel() throws SQLException {
+
+ }
+
+ public void clearBatch() throws SQLException {
+ this.commands.clear();
+ }
+
+ public void clearWarnings() throws SQLException {
+ this.warnings = null;
+ }
+
+ public void close() throws SQLException {
+ if (this.closed)
+ return;
+ this.closed = true;
+ if (this.currResults != null) {
+ this.currResults.close();
+ this.currResults = null;
+ }
+ while (!this.results.isEmpty()) {
+ ResultSet rset = this.results.poll();
+ if (rset != null)
+ rset.close();
+ }
+ for (ResultSet rset : this.openResults) {
+ rset.close();
+ }
+ this.openResults.clear();
+ }
+
+ public boolean execute(String sql) throws SQLException {
+ Query q = null;
+ UpdateRequest u = null;
+ try {
+ // Start by assuming a query
+ q = QueryFactory.create(sql);
+ } catch (Exception e) {
+ try {
+ // If that fails try as an update instead
+ u = UpdateFactory.create(sql);
+ } catch (Exception e2) {
+ throw new SQLException("Not a valid SPARQL query/update", e);
+ }
+ }
+
+ if (q != null) {
+ // Execute as a query
+ return this.executeQuery(q);
+ } else if (u != null) {
+ // Execute as an update
+ this.executeUpdate(u);
+ return false;
+ } else {
+ throw new SQLException("Unable to create a SPARQL query/update");
+ }
+ }
+
+ private boolean executeQuery(Query q) throws SQLException {
+ try {
+ QueryExecution qe = this.createQueryExecution(q);
+ if (q.isSelectType()) {
+ this.currResults = new SelectResults(this, qe, qe.execSelect());
+ return true;
+ } else if (q.isAskType()) {
+
+ } else if (q.isDescribeType()) {
+
+ } else if (q.isConstructType()) {
+
+ } else {
+ throw new SQLException("Unknown SPARQL Query type");
+ }
+ // TODO: Implement result set return for other query types
+ qe.close();
+ throw new SQLException("Not yet implemented");
+ } catch (Exception e) {
+ throw new SQLException("Error occurred during SPARQL query evaluation", e);
+ }
+ }
+
+ /**
+ * Helper method which derived classes must implement to provide a query execution
+ * @param q Query
+ * @return Query Execution
+ */
+ protected abstract QueryExecution createQueryExecution(Query q);
+
+ private int executeUpdate(UpdateRequest u) throws SQLException {
+ if (this.connection.isReadOnly()) throw new SQLException("The JDBC connection is currently in read-only mode, updates are not permitted");
+ try {
+ UpdateProcessor processor = this.createUpdateProcessor(u);
+ processor.execute();
+ return 0;
+ } catch (Exception e) {
+ throw new SQLException("Error occurred during SPARQL update evaluation", e);
+ }
+ }
+
+ /**
+ * Helper method which derived classes must implement to provide an update processor
+ * @param u Update
+ * @return Update Processor
+ */
+ protected abstract UpdateProcessor createUpdateProcessor(UpdateRequest u);
+
+ public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Use the single argument form of execute()");
+ }
+
+ public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Use the single argument form of execute()");
+ }
+
+ public boolean execute(String sql, String[] columnNames) throws SQLException {
+ // TODO: Assuming a SELECT * or DESCRIBE * could replace the * with the
+ // specific column names
+ throw new SQLFeatureNotSupportedException("Use the single argument form of execute()");
+ }
+
+ public int[] executeBatch() throws SQLException {
+ int[] rets = new int[this.commands.size()];
+ ResultSet curr = this.currResults;
+ for (int i = 0; i < this.commands.size(); i++) {
+ if (this.execute(this.commands.get(i))) {
+ // True means it returned a ResultSet
+ this.results.add(this.getResultSet());
+ this.currResults = null;
+ rets[i] = 0;
+ } else {
+ rets[i] = this.getUpdateCount();
+ }
+ }
+ this.currResults = curr;
+ // Make the next available results the current results if there
+ // are no current results
+ if (this.currResults == null && !this.results.isEmpty()) {
+ this.currResults = this.results.poll();
+ }
+ return rets;
+ }
+
+ public final ResultSet executeQuery(String sql) throws SQLException {
+ Query q = null;
+ try {
+ q = QueryFactory.create(sql);
+ } catch (Exception e) {
+ throw new SQLException("Not a valid SPARQL query", e);
+ }
+
+ if (q == null) throw new SQLException("Unable to create a SPARQL Query");
+ if (this.executeQuery(q)) {
+ return this.currResults;
+ } else {
+ throw new SQLException("Query did not produce a result set");
+ }
+ }
+
+ public final int executeUpdate(String sql) throws SQLException {
+ if (this.connection.isReadOnly()) throw new SQLException("The JDBC connection is currently in read-only mode, updates are not permitted");
+ UpdateRequest u = null;
+ try {
+ u = UpdateFactory.create(sql);
+ } catch (Exception e) {
+ throw new SQLException("Not a valid SPARQL Update", e);
+ }
+
+ if (u == null) throw new SQLException("Unable to create a SPARQL Update Request");
+ return this.executeUpdate(u);
+ }
+
+ public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Use the single argument form of executeUpdate()");
+ }
+
+ public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Use the single argument form of executeUpdate()");
+ }
+
+ public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Use the single argument form of executeUpdate()");
+ }
+
+ public final Connection getConnection() throws SQLException {
+ return this.connection;
+ }
+
+ public int getFetchDirection() throws SQLException {
+ return this.fetchDirection;
+ }
+
+ public int getFetchSize() throws SQLException {
+ return this.fetchSize;
+ }
+
+ public ResultSet getGeneratedKeys() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public int getMaxFieldSize() throws SQLException {
+ return NO_LIMIT;
+ }
+
+ public int getMaxRows() throws SQLException {
+ return NO_LIMIT;
+ }
+
+ public boolean getMoreResults() throws SQLException {
+ if (this.currResults != null) {
+ this.currResults.close();
+ this.currResults = null;
+ }
+ if (!this.results.isEmpty()) {
+ this.currResults = this.results.poll();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean getMoreResults(int current) throws SQLException {
+ switch (current) {
+ case Statement.CLOSE_CURRENT_RESULT:
+ return this.getMoreResults();
+ case Statement.CLOSE_ALL_RESULTS:
+ for (ResultSet rset : this.openResults) {
+ rset.close();
+ }
+ return this.getMoreResults();
+ case Statement.KEEP_CURRENT_RESULT:
+ if (this.currResults != null) {
+ this.openResults.add(this.currResults);
+ this.currResults = null;
+ }
+ return this.getMoreResults();
+ default:
+ throw new SQLFeatureNotSupportedException(
+ "Unsupported mode for dealing with current results, only Statement.CLOSE_CURRENT_RESULT, Statement.CLOSE_ALL_RESULTS and Statement.KEEP_CURRENT_RESULT are supported");
+ }
+ }
+
+ public int getQueryTimeout() throws SQLException {
+ return this.timeout;
+ }
+
+ public final ResultSet getResultSet() throws SQLException {
+ return this.currResults;
+ }
+
+ /**
+ * Helper method for use in execute() method implementations to set the
+ * current results
+ *
+ * @param results
+ * Results
+ * @throws SQLException
+ * Thrown if there is an error closing the previous results
+ */
+ protected void setCurrentResults(ResultSet results) throws SQLException {
+ if (this.currResults != null) {
+ this.currResults.close();
+ }
+ this.currResults = results;
+ }
+
+ /**
+ * Gets that result sets are read-only
+ */
+ public final int getResultSetConcurrency() throws SQLException {
+ return ResultSet.CONCUR_READ_ONLY;
+ }
+
+ public int getResultSetHoldability() throws SQLException {
+ return this.holdability;
+ }
+
+ protected void checkHoldability(int h) throws SQLException {
+ switch (h) {
+ case ResultSet.CLOSE_CURSORS_AT_COMMIT:
+ return;
+ default:
+ throw new SQLException("Invalid holdability, only ResultSet.CLOSE_CURSORS_AT_COMMIT is supported for Jena JDBC statements");
+ }
+ }
+
+ public final int getResultSetType() throws SQLException {
+ return ResultSet.TYPE_FORWARD_ONLY;
+ }
+
+ public int getUpdateCount() throws SQLException {
+ return this.updateCount;
+ }
+
+ /**
+ * Helper method which derived classes may use to set the update count
+ *
+ * @param count
+ * Update Count
+ */
+ protected void setUpdateCount(int count) {
+ this.updateCount = count;
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return this.warnings;
+ }
+
+ /**
+ * Helper method that derived classes may use to set warnings
+ *
+ * @param warning
+ * Warning
+ */
+ protected void setWarning(SQLWarning warning) {
+ if (this.warnings == null) {
+ this.warnings = warning;
+ } else {
+ // Chain with existing warnings
+ warning.setNextWarning(this.warnings);
+ this.warnings = warning;
+ }
+ }
+
+ /**
+ * Helper method that derived classes may use to set warnings
+ *
+ * @param warning
+ * Warning
+ */
+ protected void setWarning(String warning) {
+ this.setWarning(new SQLWarning(warning));
+ }
+
+ /**
+ * Helper method that derived classes may use to set warnings
+ *
+ * @param warning
+ * Warning
+ * @param cause
+ * Cause
+ */
+ protected void setWarning(String warning, Throwable cause) {
+ this.setWarning(new SQLWarning(warning, cause));
+ }
+
+ public final boolean isClosed() throws SQLException {
+ return this.closed;
+ }
+
+ public final boolean isPoolable() throws SQLException {
+ return true;
+ }
+
+ public void setCursorName(String name) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void setEscapeProcessing(boolean enable) throws SQLException {
+ this.escapeProcessing = enable;
+ }
+
+ public void setFetchDirection(int direction) throws SQLException {
+ this.checkFetchDirection(direction);
+ this.fetchDirection = direction;
+ }
+
+ /**
+ * Helper method which checks whether a given fetch direction is valid
+ * throwing an error if it is not
+ *
+ * @param dir
+ * Fetch Direction
+ * @throws SQLException
+ * Thrown if the direction is not valid
+ */
+ protected void checkFetchDirection(int dir) throws SQLException {
+ switch (dir) {
+ case ResultSet.FETCH_FORWARD:
+ return;
+ default:
+ throw new SQLFeatureNotSupportedException("Only ResultSet.FETCH_FORWARD is supported as a fetch direction");
+ }
+ }
+
+ public void setFetchSize(int rows) throws SQLException {
+ this.fetchSize = rows;
+ }
+
+ public void setMaxFieldSize(int max) throws SQLException {
+ // Ignored
+ this.setWarning("setMaxFieldSize() was called but there is no field size limit for Jena JDBC connections");
+ }
+
+ public void setMaxRows(int max) throws SQLException {
+ // Ignored
+ this.setWarning("setMaxRows() was called but there is no row limit for Jena JDBC connections");
+ }
+
+ public void setPoolable(boolean poolable) throws SQLException {
+ // Ignored
+ this.setWarning("setPoolable() was called but Jena JDBC statements are always considered poolable");
+ }
+
+ public void setQueryTimeout(int seconds) throws SQLException {
+ this.timeout = seconds;
+ }
+}
Added: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaTransactionalJdbcConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaTransactionalJdbcConnection.java?rev=1452559&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaTransactionalJdbcConnection.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaTransactionalJdbcConnection.java Mon Mar 4 22:08:04 2013
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.jdbc;
+
+import java.sql.SQLException;
+
+/**
+ * Abstract base implementation of a transactional Jena JDBC connection
+ *
+ * @author rvesse
+ *
+ */
+public abstract class JenaTransactionalJdbcConnection extends JenaJdbcConnection {
+
+ protected final static boolean DEFAULT_AUTO_COMMIT = true;
+ protected final static int DEFAULT_ISOLATION_LEVEL = TRANSACTION_NONE;
+
+ private boolean autoCommit = DEFAULT_AUTO_COMMIT;
+ private int isolationLevel = DEFAULT_ISOLATION_LEVEL;
+
+ /**
+ * Creates a new transactional connection
+ *
+ * @param autoCommit
+ * Auto-commit
+ * @param isolationLevel
+ * Isolation Level
+ * @throws SQLException
+ * Thrown if the arguments are invalid
+ */
+ public JenaTransactionalJdbcConnection(boolean autoCommit, int isolationLevel) throws SQLException {
+ this(DEFAULT_HOLDABILITY, autoCommit, isolationLevel);
+ }
+
+ /**
+ * Creates a new transactional connection
+ *
+ * @param holdability
+ * Cursor holdability
+ * @param autoCommit
+ * Auto-commit
+ * @param isolationLevel
+ * Isolation Level
+ * @throws SQLException
+ * Thrown if the arguments are invalid
+ */
+ public JenaTransactionalJdbcConnection(int holdability, boolean autoCommit, int isolationLevel) throws SQLException {
+ super(holdability);
+ this.checkTransactionIsolation(isolationLevel);
+
+ this.autoCommit = autoCommit;
+ this.isolationLevel = isolationLevel;
+ }
+
+ @Override
+ public abstract void commit() throws SQLException;
+
+ @Override
+ public boolean getAutoCommit() throws SQLException {
+ return this.autoCommit;
+ }
+
+ @Override
+ public int getTransactionIsolation() throws SQLException {
+ return this.isolationLevel;
+ }
+
+ @Override
+ public abstract void rollback() throws SQLException;
+
+ @Override
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ this.autoCommit = autoCommit;
+ }
+
+ @Override
+ public void setTransactionIsolation(int level) throws SQLException {
+ this.checkTransactionIsolation(level);
+ this.isolationLevel = level;
+ }
+
+ /**
+ * Helper method which checks that a transaction isolation level is valid,
+ * should throw an exception if the given level is not valid for the
+ * connection
+ *
+ * @param level
+ * Isolation Level
+ * @throws SQLException
+ * Thrown if the isolation level is not valid
+ */
+ protected abstract void checkTransactionIsolation(int level) throws SQLException;
+}
Added: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaJdbcResultSet.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaJdbcResultSet.java?rev=1452559&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaJdbcResultSet.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaJdbcResultSet.java Mon Mar 4 22:08:04 2013
@@ -0,0 +1,899 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.jdbc.results;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Map;
+
+import org.apache.jena.jdbc.utils.JenaJdbcNodeUtils;
+
+import com.hp.hpl.jena.graph.Node;
+
+/**
+ * Abstract implementation of a JDBC Result Set which makes all update methods
+ * throw {@link SQLFeatureNotSupportedException}
+ *
+ */
+public abstract class JenaJdbcResultSet implements ResultSet {
+
+ private SQLWarning warnings;
+ private Statement statement;
+ private boolean wasNull = false;
+
+ /**
+ * Creates a new result set
+ *
+ * @param statement
+ * Statement that originated the result set
+ * @throws SQLException
+ * Thrown if the arguments are invalid
+ */
+ public JenaJdbcResultSet(Statement statement) throws SQLException {
+ if (statement == null)
+ throw new SQLException("Statement for a Result Set cannot be null");
+ this.statement = statement;
+ }
+
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void cancelRowUpdates() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void clearWarnings() throws SQLException {
+ this.warnings = null;
+ }
+
+ public void deleteRow() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ // Get Methods for things we do support
+
+ /**
+ * Helper method which retrieves the Node for the given index of the current
+ * row
+ *
+ * @param columnIndex
+ * Column Index
+ * @return Node if there is a value, null if no value for the column
+ * @throws SQLException
+ * Should be thrown if there is no current row, the column index
+ * is invalid or the result set is closed
+ */
+ protected Node getNode(int columnIndex) throws SQLException {
+ return this.getNode(this.findColumnLabel(columnIndex));
+ }
+
+ /**
+ * Helper method which derived classes must implement to map a column index
+ * to a column label
+ *
+ * @param columnIndex
+ * Column Index
+ * @return Column Label
+ * @throws SQLException
+ * Should be thrown if the column index is invalid
+ */
+ protected abstract String findColumnLabel(int columnIndex) throws SQLException;
+
+ /**
+ * Helper method which derived classes must implement to retrieve the Node
+ * for the given column of the current row
+ *
+ * @param columnLabel
+ * Column Label
+ * @return Node if there is a value, null if no value for the column
+ * @throws SQLException
+ * Should be thrown if there is no current row, the column label
+ * is invalid or the result set is closed
+ */
+ protected abstract Node getNode(String columnLabel) throws SQLException;
+
+ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Deprecated
+ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Deprecated
+ public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean getBoolean(int columnIndex) throws SQLException {
+ return this.getBoolean(this.findColumnLabel(columnIndex));
+ }
+
+ public boolean getBoolean(String columnLabel) throws SQLException {
+ Node n = this.getNode(columnLabel);
+ if (n == null) {
+ this.setNull(true);
+ return false;
+ } else {
+ // Try to marshal into a boolean
+ this.setNull(false);
+ return JenaJdbcNodeUtils.toBoolean(n);
+ }
+ }
+
+ public byte getByte(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public byte getByte(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getConcurrency() throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Date getDate(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Date getDate(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Date getDate(int columnIndex, Calendar cal) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Date getDate(String columnLabel, Calendar cal) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public double getDouble(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public double getDouble(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public float getFloat(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public float getFloat(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getHoldability() throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getInt(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getInt(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long getLong(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long getLong(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public ResultSetMetaData getMetaData() throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getNString(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getNString(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getObject(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getObject(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public short getShort(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public short getShort(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String getString(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getString(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Time getTime(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Time getTime(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Time getTime(int columnIndex, Calendar cal) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Time getTime(String columnLabel, Calendar cal) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Timestamp getTimestamp(int columnIndex) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Timestamp getTimestamp(String columnLabel) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public URL getURL(int columnIndex) throws SQLException {
+ return this.getURL(this.findColumnLabel(columnIndex));
+ }
+
+ public URL getURL(String columnLabel) throws SQLException {
+ Node n = this.getNode(columnLabel);
+ if (n == null) {
+ this.setNull(true);
+ return null;
+ } else {
+ this.setNull(false);
+ return JenaJdbcNodeUtils.toURL(n);
+ }
+ }
+
+ // Get Methods for things we don't support
+
+ public Array getArray(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Array getArray(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public InputStream getAsciiStream(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public InputStream getAsciiStream(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public InputStream getBinaryStream(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public InputStream getBinaryStream(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Blob getBlob(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Blob getBlob(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public byte[] getBytes(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public byte[] getBytes(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Reader getCharacterStream(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Reader getCharacterStream(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Clob getClob(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Clob getClob(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public String getCursorName() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Reader getNCharacterStream(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Reader getNCharacterStream(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public NClob getNClob(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public NClob getNClob(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Ref getRef(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Ref getRef(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public RowId getRowId(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public RowId getRowId(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public SQLXML getSQLXML(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public SQLXML getSQLXML(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public Statement getStatement() throws SQLException {
+ return this.statement;
+ }
+
+ @Deprecated
+ public InputStream getUnicodeStream(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ @Deprecated
+ public InputStream getUnicodeStream(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return this.warnings;
+ }
+
+ /**
+ * Helper method that derived classes may use to set warnings
+ *
+ * @param warning
+ * Warning
+ */
+ protected void setWarning(SQLWarning warning) {
+ if (this.warnings == null) {
+ this.warnings = warning;
+ } else {
+ // Chain with existing warnings
+ warning.setNextWarning(this.warnings);
+ this.warnings = warning;
+ }
+ }
+
+ /**
+ * Helper method that derived classes may use to set warnings
+ *
+ * @param warning
+ * Warning
+ */
+ protected void setWarning(String warning) {
+ this.setWarning(new SQLWarning(warning));
+ }
+
+ /**
+ * Helper method that derived classes may use to set warnings
+ *
+ * @param warning
+ * Warning
+ * @param cause
+ * Cause
+ */
+ protected void setWarning(String warning, Throwable cause) {
+ this.setWarning(new SQLWarning(warning, cause));
+ }
+
+ public void insertRow() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void moveToCurrentRow() throws SQLException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
+ public void moveToInsertRow() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public boolean previous() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are forward-only");
+ }
+
+ public void refreshRow() throws SQLException {
+ // No-op
+ }
+
+ public boolean rowDeleted() throws SQLException {
+ return false;
+ }
+
+ public boolean rowInserted() throws SQLException {
+ return false;
+ }
+
+ public boolean rowUpdated() throws SQLException {
+ return false;
+ }
+
+ public void updateArray(int columnIndex, Array x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateArray(String columnLabel, Array x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBlob(int columnIndex, Blob x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBlob(String columnLabel, Blob x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBoolean(int columnIndex, boolean x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBoolean(String columnLabel, boolean x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateByte(int columnIndex, byte x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateByte(String columnLabel, byte x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBytes(int columnIndex, byte[] x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateBytes(String columnLabel, byte[] x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateClob(int columnIndex, Clob x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateClob(int columnIndex, Reader reader) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateClob(String columnLabel, Clob x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateClob(String columnLabel, Reader reader, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateClob(String columnLabel, Reader reader) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateDate(int columnIndex, Date x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateDate(String columnLabel, Date x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateDouble(int columnIndex, double x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateDouble(String columnLabel, double x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateFloat(int columnIndex, float x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateFloat(String columnLabel, float x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateInt(int columnIndex, int x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateInt(String columnLabel, int x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateLong(int columnIndex, long x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateLong(String columnLabel, long x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNClob(int columnIndex, Reader reader) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNClob(String columnLabel, NClob nClob) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNClob(String columnLabel, Reader reader) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNString(int columnIndex, String nString) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNString(String columnLabel, String nString) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNull(int columnIndex) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateNull(String columnLabel) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateObject(int columnIndex, Object x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateObject(String columnLabel, Object x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateRef(int columnIndex, Ref x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateRef(String columnLabel, Ref x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateRow() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateRowId(int columnIndex, RowId x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateRowId(String columnLabel, RowId x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateShort(int columnIndex, short x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateShort(String columnLabel, short x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateString(int columnIndex, String x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateString(String columnLabel, String x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateTime(int columnIndex, Time x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateTime(String columnLabel, Time x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets are read-only");
+ }
+
+ public boolean wasNull() throws SQLException {
+ return this.wasNull;
+ }
+
+ /**
+ * Helper method for setting the wasNull() status of the last column read
+ *
+ * @param wasNull
+ * Whether the last column was null
+ */
+ protected void setNull(boolean wasNull) {
+ this.wasNull = wasNull;
+ }
+
+}
Added: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/SelectResults.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/SelectResults.java?rev=1452559&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/SelectResults.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/SelectResults.java Mon Mar 4 22:08:04 2013
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.jdbc.results;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.sparql.core.Var;
+import com.hp.hpl.jena.sparql.engine.binding.Binding;
+
+/**
+ * Represents SPARQL SELECT results
+ *
+ */
+public class SelectResults extends JenaJdbcResultSet {
+
+ private QueryExecution qe;
+ private com.hp.hpl.jena.query.ResultSet innerResults;
+ private Binding binding;
+ private boolean started = false;
+ private boolean finished = false;
+ private int currRow = 0;
+ private List<String> columns;
+
+ /**
+ * Creates new select results
+ * @param statement Statement that created the result set
+ * @param qe Query Execution
+ * @param results SPARQL Results
+ * @throws SQLException Thrown if the arguments are invalid
+ */
+ public SelectResults(Statement statement, QueryExecution qe, com.hp.hpl.jena.query.ResultSet results) throws SQLException {
+ super(statement);
+ if (qe == null) throw new SQLException("Query Execution cannot be null");
+ this.qe = qe;
+ if (results == null) throw new SQLException("SPARQL Results cannot be null");
+ this.innerResults = results;
+ this.columns = new ArrayList<String>(this.innerResults.getResultVars());
+ }
+
+ public boolean absolute(int row) throws SQLException {
+ if (this.isClosed()) {
+ throw new SQLException("Cannot move to a row after the result set has been closed");
+ } else if (row == 1) {
+ // Try and move to the first row
+ return this.first();
+ } else if (row == -1) {
+ // Try and move to the last row
+ return this.last();
+ } else if (row <= 0) {
+ //Can't move to an arbitrary relative row from the end of the results
+ throw new SQLException("Jena JDBC result sets are forward only, cannot move to a row which is relative to the end of the result set");
+ } else if (row == this.currRow) {
+ // Already at the desired row
+ return true;
+ } else if (row < this.currRow) {
+ throw new SQLException("Jena JDBC result sets are forward only");
+ } else {
+ // Before the desired row
+ while (this.innerResults.hasNext() && this.currRow < row) {
+ this.binding = this.innerResults.nextBinding();
+ this.currRow++;
+ }
+ // If we didn't reach it we hit the end of the result set
+ if (this.currRow < row) {
+ this.finished = true;
+ this.binding = null;
+ }
+ return (row == this.currRow);
+ }
+ }
+
+ public void afterLast() throws SQLException {
+ if (finished) return;
+
+ // Move to end of results
+ while (this.innerResults.hasNext()) {
+ this.binding = this.innerResults.nextBinding();
+ this.currRow++;
+ }
+ this.binding = null;
+ this.finished = true;
+ }
+
+ public void beforeFirst() throws SQLException {
+ //If we've started throw an error as we can't move backwards
+ if (started) throw new SQLException("Jena JDBC result sets are forward only");
+ //Otherwise OK
+ this.binding = null;
+ }
+
+ public void close() throws SQLException {
+ if (this.innerResults != null) {
+ this.qe.close();
+ this.qe = null;
+ this.innerResults = null;
+ }
+ this.binding = null;
+ this.finished = true;
+ }
+
+ public int findColumn(String columnLabel) throws SQLException {
+ if (this.isClosed()) throw new SQLException("Result Set is closed");
+ for (int i = 0; i < this.columns.size(); i++) {
+ if (this.columns.get(i).equals(columnLabel)) return i;
+ }
+ throw new SQLException("The given column does not exist in this result set");
+ }
+
+ @Override
+ protected String findColumnLabel(int columnIndex) throws SQLException {
+ if (this.isClosed()) throw new SQLException("Result Set is closed");
+ if (columnIndex >= 0 && columnIndex < this.columns.size()) {
+ return this.columns.get(columnIndex);
+ } else {
+ throw new SQLException("Column Index is out of bounds");
+ }
+ }
+
+ public boolean first() throws SQLException {
+ if (this.started && this.currRow == 1) return true;
+ throw new SQLException("Jena JDBC result sets are forward only");
+ }
+
+ public int getFetchDirection() throws SQLException {
+ return ResultSet.FETCH_FORWARD;
+ }
+
+ public int getFetchSize() throws SQLException {
+ // TODO Need a buffering wrapper around ResultSet to make this configurable
+ return 0;
+ }
+
+ @Override
+ protected Node getNode(String columnLabel) throws SQLException {
+ if (this.isClosed()) throw new SQLException("Result Set is closed");
+ if (this.binding == null) throw new SQLException("Not currently at a row");
+ return this.binding.get(Var.alloc(columnLabel));
+ }
+
+ public int getRow() throws SQLException {
+ return this.currRow;
+ }
+
+ public final int getType() throws SQLException {
+ return ResultSet.TYPE_FORWARD_ONLY;
+ }
+
+ public boolean isAfterLast() throws SQLException {
+ return this.finished;
+ }
+
+ public boolean isBeforeFirst() throws SQLException {
+ return !this.started;
+ }
+
+ public boolean isClosed() throws SQLException {
+ return this.innerResults == null;
+ }
+
+ public boolean isFirst() throws SQLException {
+ return this.currRow == 1;
+ }
+
+ public boolean isLast() throws SQLException {
+ return !this.isClosed() && !this.innerResults.hasNext();
+ }
+
+ public boolean last() throws SQLException {
+ if (this.isClosed() || this.finished) {
+ throw new SQLException("Jena JDBC Result Sets are forward-only");
+ } else {
+ while (this.innerResults.hasNext()) {
+ this.binding = this.innerResults.nextBinding();
+ this.currRow++;
+ }
+ return true;
+ }
+ }
+
+ public boolean next() throws SQLException {
+ if (this.isClosed()) {
+ throw new SQLException("Cannot move to the next row in a closed result set");
+ } else {
+ if (this.innerResults.hasNext()) {
+ this.binding = this.innerResults.nextBinding();
+ this.currRow++;
+ return true;
+ } else {
+ if (!this.finished) this.currRow++;
+ this.finished = true;
+ return false;
+ }
+ }
+ }
+
+ public boolean relative(int rows) throws SQLException {
+ if (this.isClosed()) {
+ throw new SQLException("Cannot move to a row after the result set has been closed");
+ } else if (rows == 0) {
+ // Already at the desired row
+ return true;
+ } else if (rows < 0) {
+ throw new SQLException("Jena JDBC result sets are forward only");
+ } else {
+ // Before the desired row
+ int moved = 0;
+ while (this.innerResults.hasNext() && moved < rows) {
+ this.binding = this.innerResults.nextBinding();
+ this.currRow++;
+ moved++;
+ }
+ // If we didn't reach it we hit the end of the result set
+ if (moved < rows) {
+ this.finished = true;
+ this.binding = null;
+ }
+ return (rows == moved);
+ }
+ }
+
+ public void setFetchDirection(int direction) throws SQLException {
+ if (direction != ResultSet.FETCH_FORWARD) throw new SQLFeatureNotSupportedException("Jena JDBC Result Sets only support forward fetch");
+ }
+
+ public void setFetchSize(int rows) throws SQLException {
+ // TODO Need to provide some buffering wrapper over a ResultSet to make this possible
+ }
+}
Added: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/JenaJdbcNodeUtils.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/JenaJdbcNodeUtils.java?rev=1452559&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/JenaJdbcNodeUtils.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/JenaJdbcNodeUtils.java Mon Mar 4 22:08:04 2013
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.jdbc.utils;
+
+import java.net.URL;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.vocabulary.XSD;
+
+/**
+ * Class with helpful utility methods for Jena JDBC
+ *
+ */
+public class JenaJdbcNodeUtils {
+
+ private static Set<String> numericTypes = new HashSet<String>();
+
+ static {
+ numericTypes.add(XSD.decimal.getURI());
+ numericTypes.add(XSD.integer.getURI());
+ numericTypes.add(XSD.negativeInteger.getURI());
+ numericTypes.add(XSD.nonNegativeInteger.getURI());
+ numericTypes.add(XSD.nonPositiveInteger.getURI());
+ numericTypes.add(XSD.unsignedByte.getURI());
+ numericTypes.add(XSD.unsignedInt.getURI());
+ numericTypes.add(XSD.unsignedLong.getURI());
+ numericTypes.add(XSD.unsignedShort.getURI());
+ numericTypes.add(XSD.xbyte.getURI());
+ numericTypes.add(XSD.xdouble.getURI());
+ numericTypes.add(XSD.xfloat.getURI());
+ numericTypes.add(XSD.xint.getURI());
+ numericTypes.add(XSD.xlong.getURI());
+ numericTypes.add(XSD.xshort.getURI());
+ }
+
+ /**
+ * Private constructor prevents instantiation
+ */
+ private JenaJdbcNodeUtils() { }
+
+ /**
+ * Tries to convert a node to a boolean
+ * @param n Node
+ * @return Boolean
+ * @throws SQLException Thrown if the node cannot be converted
+ */
+ public static boolean toBoolean(Node n) throws SQLException {
+ try {
+ if (n == null) return false;
+ if (n.isLiteral()) {
+ if (n.getLiteralDatatypeURI().equals(XSD.xboolean.getURI())) {
+ return Boolean.parseBoolean(n.getLiteralLexicalForm());
+ } else if (hasNumericDatatype(n)) {
+ return parseAsInteger(n) == 0 ? false : true;
+ } else {
+ throw new SQLException("Unable to marshal the given literal to a boolean");
+ }
+ } else {
+ throw new SQLException("Unable to marshal a non-literal to a boolean");
+ }
+ } catch (SQLException e) {
+ // Throw as is
+ throw e;
+ } catch (Exception e) {
+ // Wrap other exceptions
+ throw new SQLException("Unable to marshal the value to a boolean", e);
+ }
+ }
+
+ /**
+ * Tries to convert a node to a URL
+ * @param n Node
+ * @return URL or null
+ * @throws SQLException Thrown if the node cannot be converted
+ */
+ public static URL toURL(Node n) throws SQLException {
+ try {
+ if (n == null) return null;
+ if (n.isURI()) {
+ return new URL(n.getURI());
+ } else {
+ throw new SQLException("Unable to marshal a non-uri to a URL");
+ }
+ } catch (SQLException e) {
+ // Throw as is
+ throw e;
+ } catch (Exception e) {
+ // Wrap other exceptions
+ throw new SQLException("Unable to marshal the value to a URL", e);
+ }
+ }
+
+ private static long parseAsInteger(Node n) throws SQLException {
+ if (n == null) throw new SQLException("Unable to marshal a null to an integer");
+ if (n.isLiteral()) {
+ try {
+ String lex = n.getLiteralLexicalForm();
+ if (lex.contains(".")) {
+ return Long.parseLong(lex.substring(0, lex.indexOf('.')));
+ } else {
+ return Long.parseLong(lex);
+ }
+ } catch (Exception e) {
+ throw new SQLException("Unable to marshal an invalid numeric representation to an integer", e);
+ }
+ } else {
+ throw new SQLException("Unable to marshal a non-literal to an integer");
+ }
+ }
+
+ /**
+ * Gets whether a node has a numeric datatype
+ * @param n Node
+ * @return True if a numeric datatype, false otherwise
+ */
+ private static boolean hasNumericDatatype(Node n) {
+ if (n == null) return false;
+ if (!n.isLiteral()) return false;
+ return numericTypes.contains(n.getLiteralDatatypeURI());
+ }
+}