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/04/30 20:33:45 UTC
svn commit: r1477759 - in /jena/Experimental/jena-jdbc:
jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/
jena-jdbc-core/src/test/java/org/apache/jena/jdbc/
jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/
jena-jdbc-core/src/t...
Author: rvesse
Date: Tue Apr 30 18:33:44 2013
New Revision: 1477759
URL: http://svn.apache.org/r1477759
Log:
More work on prepared statement support, reduce logging under unit tests
Added:
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointPreparedStatement.java
Modified:
jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaPreparedStatement.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaDriverTests.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/TestCompatibility.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/metadata/results/AbstractDatabaseMetadataTests.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java
Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaPreparedStatement.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaPreparedStatement.java?rev=1477759&r1=1477758&r2=1477759&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaPreparedStatement.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaPreparedStatement.java Tue Apr 30 18:33:44 2013
@@ -39,14 +39,18 @@ import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
+import java.util.TimeZone;
import org.apache.jena.jdbc.connections.JenaConnection;
import org.apache.jena.jdbc.statements.metadata.JenaParameterMetadata;
import com.hp.hpl.jena.datatypes.TypeMapper;
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.NodeFactory;
import com.hp.hpl.jena.query.ParameterizedSparqlString;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.sparql.util.NodeFactoryExtra;
import com.hp.hpl.jena.vocabulary.XSD;
@@ -56,6 +60,7 @@ import com.hp.hpl.jena.vocabulary.XSD;
*/
public abstract class JenaPreparedStatement extends JenaStatement implements PreparedStatement {
+ private Model resourceModel = ModelFactory.createDefaultModel();
private ParameterizedSparqlString sparqlStr = new ParameterizedSparqlString();
private ParameterMetaData paramMetadata;
@@ -152,7 +157,7 @@ public abstract class JenaPreparedStatem
@Override
public void setBigDecimal(int parameterIndex, BigDecimal value) throws SQLException {
- // TODO Auto generated method stub
+ this.setParameter(parameterIndex, NodeFactory.createLiteral(value.toPlainString(), XSDDatatype.XSDdecimal));
}
@Override
@@ -187,12 +192,12 @@ public abstract class JenaPreparedStatem
@Override
public void setBoolean(int parameterIndex, boolean value) throws SQLException {
- this.setParameter(parameterIndex, NodeFactory.createLiteral(Boolean.toString(value), TypeMapper.getInstance().getSafeTypeByName(XSD.xboolean.getURI())));
+ this.setParameter(parameterIndex, NodeFactory.createLiteral(Boolean.toString(value), XSDDatatype.XSDboolean));
}
@Override
public void setByte(int parameterIndex, byte value) throws SQLException {
- this.setParameter(parameterIndex, NodeFactory.createLiteral(Byte.toString(value), TypeMapper.getInstance().getSafeTypeByName(XSD.xbyte.getURI())));
+ this.setParameter(parameterIndex, NodeFactory.createLiteral(Byte.toString(value), XSDDatatype.XSDbyte));
}
@Override
@@ -232,14 +237,14 @@ public abstract class JenaPreparedStatem
@Override
public void setDate(int parameterIndex, Date value) throws SQLException {
- // TODO Auto-generated method stub
-
+ Calendar c = Calendar.getInstance();
+ c.setTimeInMillis(value.getTime());
+ this.setParameter(parameterIndex, NodeFactoryExtra.dateTimeToNode(c));
}
@Override
public void setDate(int parameterIndex, Date value, Calendar arg2) throws SQLException {
- // TODO Auto-generated method stub
-
+ throw new SQLFeatureNotSupportedException();
}
@Override
@@ -339,7 +344,7 @@ public abstract class JenaPreparedStatem
@Override
public void setShort(int parameterIndex, short value) throws SQLException {
this.setParameter(parameterIndex,
- NodeFactory.createLiteral(Short.toString(value), TypeMapper.getInstance().getSafeTypeByName(XSD.xshort.getURI())));
+ NodeFactory.createLiteral(Short.toString(value), XSDDatatype.XSDshort));
}
@Override
@@ -349,8 +354,9 @@ public abstract class JenaPreparedStatem
@Override
public void setTime(int parameterIndex, Time value) throws SQLException {
- // TODO Auto-generated method stub
-
+ Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ c.setTimeInMillis(value.getTime());
+ this.setParameter(parameterIndex, NodeFactoryExtra.timeToNode(c));
}
@Override
Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaDriverTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaDriverTests.java?rev=1477759&r1=1477758&r2=1477759&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaDriverTests.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaDriverTests.java Tue Apr 30 18:33:44 2013
@@ -45,7 +45,7 @@ public abstract class AbstractJenaDriver
// Init Log4j
BasicConfigurator.resetConfiguration();
BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.INFO);
+ Logger.getRootLogger().setLevel(Level.WARN);
// Init ARQ
ARQ.init();
Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/TestCompatibility.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/TestCompatibility.java?rev=1477759&r1=1477758&r2=1477759&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/TestCompatibility.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/TestCompatibility.java Tue Apr 30 18:33:44 2013
@@ -31,6 +31,7 @@ import org.junit.Assert;
import org.junit.Test;
import com.hp.hpl.jena.datatypes.TypeMapper;
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.NodeFactory;
import com.hp.hpl.jena.rdf.model.Model;
@@ -147,7 +148,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_integer_02() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", TypeMapper.getInstance().getSafeTypeByName(XSD.xint.toString())), true, Types.BIGINT, Long.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", XSDDatatype.XSDint), true, Types.BIGINT, Long.class.getCanonicalName());
Assert.assertEquals(0, info.getScale());
Assert.assertTrue(info.isSigned());
}
@@ -158,7 +159,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_integer_03() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", TypeMapper.getInstance().getSafeTypeByName(XSD.xlong.toString())), true, Types.BIGINT, Long.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", XSDDatatype.XSDlong), true, Types.BIGINT, Long.class.getCanonicalName());
Assert.assertEquals(0, info.getScale());
Assert.assertTrue(info.isSigned());
}
@@ -169,7 +170,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_integer_04() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", TypeMapper.getInstance().getSafeTypeByName(XSD.unsignedInt.toString())), true, Types.BIGINT, Long.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", XSDDatatype.XSDunsignedInt), true, Types.BIGINT, Long.class.getCanonicalName());
Assert.assertEquals(0, info.getScale());
Assert.assertFalse(info.isSigned());
}
@@ -180,7 +181,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_integer_05() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", TypeMapper.getInstance().getSafeTypeByName(XSD.unsignedLong.toString())), true, Types.BIGINT, Long.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", XSDDatatype.XSDunsignedLong), true, Types.BIGINT, Long.class.getCanonicalName());
Assert.assertEquals(0, info.getScale());
Assert.assertFalse(info.isSigned());
}
@@ -191,7 +192,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_integer_06() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", TypeMapper.getInstance().getSafeTypeByName(XSD.xshort.toString())), true, Types.INTEGER, Integer.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", XSDDatatype.XSDshort), true, Types.INTEGER, Integer.class.getCanonicalName());
Assert.assertEquals(0, info.getScale());
Assert.assertTrue(info.isSigned());
}
@@ -202,7 +203,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_integer_07() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", TypeMapper.getInstance().getSafeTypeByName(XSD.unsignedShort.toString())), true, Types.INTEGER, Integer.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("1234", XSDDatatype.XSDunsignedShort), true, Types.INTEGER, Integer.class.getCanonicalName());
Assert.assertEquals(0, info.getScale());
Assert.assertFalse(info.isSigned());
}
@@ -213,7 +214,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_byte_01() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("123", TypeMapper.getInstance().getSafeTypeByName(XSD.xbyte.toString())), true, Types.TINYINT, Byte.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("123", XSDDatatype.XSDbyte), true, Types.TINYINT, Byte.class.getCanonicalName());
Assert.assertEquals(0, info.getScale());
Assert.assertTrue(info.isSigned());
}
@@ -224,7 +225,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_byte_02() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("123", TypeMapper.getInstance().getSafeTypeByName(XSD.unsignedByte.toString())), true, Types.TINYINT, Byte.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("123", XSDDatatype.XSDunsignedByte), true, Types.TINYINT, Byte.class.getCanonicalName());
Assert.assertEquals(0, info.getScale());
Assert.assertFalse(info.isSigned());
}
@@ -235,7 +236,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_boolean() throws SQLException {
- testColumnTypeDetection("x", NodeFactory.createLiteral("true", TypeMapper.getInstance().getSafeTypeByName(XSD.xboolean.toString())), true, Types.BOOLEAN, Boolean.class.getCanonicalName());
+ testColumnTypeDetection("x", NodeFactory.createLiteral("true", XSDDatatype.XSDboolean), true, Types.BOOLEAN, Boolean.class.getCanonicalName());
}
@@ -245,7 +246,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_decimal() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("123.4", TypeMapper.getInstance().getSafeTypeByName(XSD.decimal.toString())), true, Types.DECIMAL, BigDecimal.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("123.4", XSDDatatype.XSDdecimal), true, Types.DECIMAL, BigDecimal.class.getCanonicalName());
Assert.assertEquals(16, info.getScale());
Assert.assertEquals(16, info.getPrecision());
Assert.assertTrue(info.isSigned());
@@ -257,7 +258,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_double() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("12.3e4", TypeMapper.getInstance().getSafeTypeByName(XSD.xdouble.toString())), true, Types.DOUBLE, Double.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("12.3e4", XSDDatatype.XSDdouble), true, Types.DOUBLE, Double.class.getCanonicalName());
Assert.assertEquals(16, info.getScale());
Assert.assertEquals(16, info.getPrecision());
Assert.assertTrue(info.isSigned());
@@ -269,7 +270,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_float() throws SQLException {
- ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("12.3e4", TypeMapper.getInstance().getSafeTypeByName(XSD.xfloat.toString())), true, Types.FLOAT, Float.class.getCanonicalName());
+ ColumnInfo info = testColumnTypeDetection("x", NodeFactory.createLiteral("12.3e4", XSDDatatype.XSDfloat), true, Types.FLOAT, Float.class.getCanonicalName());
Assert.assertEquals(7, info.getScale());
Assert.assertEquals(15, info.getPrecision());
Assert.assertTrue(info.isSigned());
@@ -291,7 +292,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_datetimes_02() throws SQLException {
- testColumnTypeDetection("x", NodeFactory.createLiteral("2013-04-08", TypeMapper.getInstance().getSafeTypeByName(XSD.date.toString())), true, Types.DATE, Date.class.getCanonicalName());
+ testColumnTypeDetection("x", NodeFactory.createLiteral("2013-04-08", XSDDatatype.XSDdate), true, Types.DATE, Date.class.getCanonicalName());
}
/**
@@ -300,7 +301,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_datetimes_03() throws SQLException {
- testColumnTypeDetection("x", NodeFactory.createLiteral("13:15:00", TypeMapper.getInstance().getSafeTypeByName(XSD.time.toString())), true, Types.TIME, Time.class.getCanonicalName());
+ testColumnTypeDetection("x", NodeFactory.createLiteral("13:15:00", XSDDatatype.XSDtime), true, Types.TIME, Time.class.getCanonicalName());
}
/**
@@ -309,7 +310,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_datetimes_04() throws SQLException {
- testColumnTypeDetection("x", NodeFactory.createLiteral("13:15:00.123", TypeMapper.getInstance().getSafeTypeByName(XSD.time.toString())), true, Types.TIME, Time.class.getCanonicalName());
+ testColumnTypeDetection("x", NodeFactory.createLiteral("13:15:00.123", XSDDatatype.XSDtime), true, Types.TIME, Time.class.getCanonicalName());
}
/**
@@ -336,7 +337,7 @@ public class TestCompatibility {
*/
@Test
public void test_column_type_detection_strings_03() throws SQLException {
- testColumnTypeDetection("x", NodeFactory.createLiteral("simple", TypeMapper.getInstance().getSafeTypeByName(XSD.xstring.toString())), true, Types.NVARCHAR, String.class.getCanonicalName());
+ testColumnTypeDetection("x", NodeFactory.createLiteral("simple", XSDDatatype.XSDstring), true, Types.NVARCHAR, String.class.getCanonicalName());
}
/**
Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java?rev=1477759&r1=1477758&r2=1477759&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java Tue Apr 30 18:33:44 2013
@@ -52,7 +52,7 @@ public abstract class AbstractJenaConnec
// Init Log4j
BasicConfigurator.resetConfiguration();
BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.INFO);
+ Logger.getRootLogger().setLevel(Level.WARN);
// Init ARQ
ARQ.init();
Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/metadata/results/AbstractDatabaseMetadataTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/metadata/results/AbstractDatabaseMetadataTests.java?rev=1477759&r1=1477758&r2=1477759&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/metadata/results/AbstractDatabaseMetadataTests.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/metadata/results/AbstractDatabaseMetadataTests.java Tue Apr 30 18:33:44 2013
@@ -55,7 +55,7 @@ public abstract class AbstractDatabaseMe
// Init Log4j
BasicConfigurator.resetConfiguration();
BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.INFO);
+ Logger.getRootLogger().setLevel(Level.WARN);
// Init ARQ
ARQ.init();
Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java?rev=1477759&r1=1477758&r2=1477759&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java Tue Apr 30 18:33:44 2013
@@ -33,6 +33,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import com.hp.hpl.jena.datatypes.TypeMapper;
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.query.ARQ;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.DatasetFactory;
@@ -54,7 +55,7 @@ public abstract class AbstractResultSetT
// Init Log4j
BasicConfigurator.resetConfiguration();
BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.INFO);
+ Logger.getRootLogger().setLevel(Level.WARN);
// Init ARQ
ARQ.init();
@@ -87,8 +88,7 @@ public abstract class AbstractResultSetT
Literal objSimpleLiteral = m.createLiteral("simple");
Literal objLangLiteral = m.createLiteral("simple", "en");
Literal objBoolean = m.createTypedLiteral(true);
- Literal objByte = m.createTypedLiteral(Byte.toString((byte) 123),
- TypeMapper.getInstance().getSafeTypeByName(XSD.xbyte.toString()));
+ Literal objByte = m.createTypedLiteral(Byte.toString((byte) 123), XSDDatatype.XSDbyte);
Literal objDate = m.createTypedLiteral(Calendar.getInstance());
Literal objChar = m.createTypedLiteral('a');
Literal objDecimal = m.createTypedLiteral(new BigDecimal(123.4));
@@ -96,8 +96,7 @@ public abstract class AbstractResultSetT
Literal objFloat = m.createTypedLiteral(123.4f);
Literal objInteger = m.createTypedLiteral(1234);
Literal objLong = m.createTypedLiteral(1234l);
- Literal objShort = m.createTypedLiteral(Short.toString((short) 123),
- TypeMapper.getInstance().getSafeTypeByName(XSD.xshort.toString()));
+ Literal objShort = m.createTypedLiteral(Short.toString((short) 123), XSDDatatype.XSDshort);
Literal objString = m.createTypedLiteral("typed");
Literal objCustom = m.createTypedLiteral("custom",
TypeMapper.getInstance().getSafeTypeByName("http://example/customType"));
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java?rev=1477759&r1=1477758&r2=1477759&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java Tue Apr 30 18:33:44 2013
@@ -29,6 +29,7 @@ import java.util.List;
import org.apache.jena.jdbc.JdbcCompatibility;
import org.apache.jena.jdbc.connections.JenaConnection;
import org.apache.jena.jdbc.remote.metadata.RemoteEndpointMetadata;
+import org.apache.jena.jdbc.remote.statements.RemoteEndpointPreparedStatement;
import org.apache.jena.jdbc.remote.statements.RemoteEndpointStatement;
import org.apache.jena.jdbc.statements.JenaPreparedStatement;
import org.apache.jena.jdbc.statements.JenaStatement;
@@ -192,7 +193,7 @@ public class RemoteEndpointConnection ex
throw new SQLException("Remote endpoint backed connection currently only support forward-only result sets");
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
throw new SQLException("Remote endpoint backed connections only support read-only result sets");
- throw new SQLFeatureNotSupportedException("Remote endpoint backed connections do not yet support prepared statements");
+ return new RemoteEndpointPreparedStatement(sparql, this, this.username, this.password, ResultSet.FETCH_FORWARD, 0, resultSetHoldability);
}
@Override
Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointPreparedStatement.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointPreparedStatement.java?rev=1477759&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointPreparedStatement.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointPreparedStatement.java Tue Apr 30 18:33:44 2013
@@ -0,0 +1,157 @@
+/**
+ * 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.remote.statements;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+
+import org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection;
+import org.apache.jena.jdbc.statements.JenaPreparedStatement;
+import com.hp.hpl.jena.query.Query;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.ReadWrite;
+import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP;
+import com.hp.hpl.jena.sparql.modify.UpdateProcessRemoteBase;
+import com.hp.hpl.jena.update.UpdateExecutionFactory;
+import com.hp.hpl.jena.update.UpdateProcessor;
+import com.hp.hpl.jena.update.UpdateRequest;
+
+/**
+ * A Jena JDBC statement against a remote endpoint
+ *
+ */
+public class RemoteEndpointPreparedStatement extends JenaPreparedStatement {
+
+ private RemoteEndpointConnection remoteConn;
+ private String username;
+ private char[] password;
+
+ /**
+ * Creates a new statement
+ *
+ * @param sparql
+ * SPARQL command
+ * @param connection
+ * Connection
+ * @throws SQLException
+ * Thrown if there is an error with the statement parameters
+ */
+ public RemoteEndpointPreparedStatement(String sparql, RemoteEndpointConnection connection) throws SQLException {
+ this(sparql, connection, null, null, DEFAULT_FETCH_DIRECTION, DEFAULT_FETCH_SIZE, DEFAULT_HOLDABILITY);
+ }
+
+ /**
+ * Creates a new statement
+ *
+ * @param sparql
+ * SPARQL command
+ * @param connection
+ * Connection
+ * @param username
+ * Username for HTTP Basic Authentication
+ * @param password
+ * Username for HTTP Basic Authentication
+ * @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 RemoteEndpointPreparedStatement(String sparql, RemoteEndpointConnection connection, String username, char[] password, int fetchDir,
+ int fetchSize, int holdability) throws SQLException {
+ super(sparql, connection, fetchDir, fetchSize, holdability, false, Connection.TRANSACTION_NONE);
+ this.remoteConn = connection;
+ this.username = username;
+ this.password = password;
+ }
+
+ @Override
+ protected QueryExecution createQueryExecution(Query q) throws SQLException {
+ if (this.remoteConn.getQueryEndpoint() == null)
+ throw new SQLException("This statement is backed by a write-only connection, read operations are not supported");
+
+ // Create basic execution
+ QueryEngineHTTP exec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(this.remoteConn.getQueryEndpoint(), q);
+
+ // Apply authentication settings
+ if (this.username != null && this.password != null) {
+ exec.setBasicAuthentication(this.username, this.password);
+ }
+
+ // Apply default and named graphs if appropriate
+ if (this.remoteConn.getDefaultGraphURIs() != null) {
+ exec.setDefaultGraphURIs(this.remoteConn.getDefaultGraphURIs());
+ }
+ if (this.remoteConn.getNamedGraphURIs() != null) {
+ exec.setNamedGraphURIs(this.remoteConn.getNamedGraphURIs());
+ }
+
+ // Return execution
+ return exec;
+ }
+
+ @Override
+ protected UpdateProcessor createUpdateProcessor(UpdateRequest u) {
+ UpdateProcessRemoteBase proc = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(u,
+ this.remoteConn.getUpdateEndpoint());
+
+ // Apply authentication settings
+ if (this.username != null && this.password != null) {
+ proc.setAuthentication(this.username, this.password);
+ }
+
+ // Apply default and named graphs if appropriate
+ if (this.remoteConn.getUsingGraphURIs() != null) {
+ proc.setDefaultGraphs(this.remoteConn.getUsingGraphURIs());
+ }
+ if (this.remoteConn.getNamedGraphURIs() != null) {
+ proc.setNamedGraphs(this.remoteConn.getUsingNamedGraphURIs());
+ }
+
+ return proc;
+ }
+
+ @Override
+ protected void beginTransaction(ReadWrite type) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Transactions against remote endpoint backed connections are not supported");
+ }
+
+ @Override
+ protected void commitTransaction() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Transactions against remote endpoint backed connections are not supported");
+ }
+
+ @Override
+ protected void rollbackTransaction() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Transactions against remote endpoint backed connections are not supported");
+ }
+
+ @Override
+ protected boolean hasActiveTransaction() throws SQLException {
+ // Remote endpoints don't support transactions so can't ever have an
+ // active transaction
+ return false;
+ }
+}