Added:
trunk/connector-j/.fbprefs
trunk/connector-j/src/com/mysql/jdbc/JDBC4CallableStatement.java
trunk/connector-j/src/com/mysql/jdbc/JDBC4Connection.java
trunk/connector-j/src/com/mysql/jdbc/JDBC4DatabaseMetaData.java
trunk/connector-j/src/com/mysql/jdbc/JDBC4MysqlSQLXML.java
trunk/connector-j/src/com/mysql/jdbc/JDBC4NClob.java
trunk/connector-j/src/com/mysql/jdbc/JDBC4PreparedStatement.java
trunk/connector-j/src/com/mysql/jdbc/JDBC4PreparedStatementHelper.java
trunk/connector-j/src/com/mysql/jdbc/JDBC4ResultSet.java
trunk/connector-j/src/com/mysql/jdbc/JDBC4ServerPreparedStatement.java
trunk/connector-j/src/com/mysql/jdbc/JDBC4UpdatableResultSet.java
trunk/connector-j/src/com/mysql/jdbc/exceptions/NotYetImplementedException.java
trunk/connector-j/src/testsuite/simple/jdbc4/
trunk/connector-j/src/testsuite/simple/jdbc4/StatementsTest.java
Removed:
trunk/connector-j/src/com/mysql/jdbc/MysqlSQLXML.java
trunk/connector-j/src/com/mysql/jdbc/NClob.java
trunk/connector-j/src/com/mysql/jdbc/exceptions/JDBC40NotYetImplementedException.java
trunk/connector-j/src/com/mysql/jdbc/jdbc4/MysqlSQLXML.java
trunk/connector-j/src/com/mysql/jdbc/jdbc4/NClob.java
Modified:
trunk/connector-j/.classpath
trunk/connector-j/.settings/org.eclipse.jdt.core.prefs
trunk/connector-j/.settings/org.eclipse.jdt.ui.prefs
trunk/connector-j/CHANGES
trunk/connector-j/build.xml
trunk/connector-j/src/com/mysql/jdbc/BlobFromLocator.java
trunk/connector-j/src/com/mysql/jdbc/CallableStatement.java
trunk/connector-j/src/com/mysql/jdbc/Clob.java
trunk/connector-j/src/com/mysql/jdbc/Connection.java
trunk/connector-j/src/com/mysql/jdbc/MysqlParameterMetadata.java
trunk/connector-j/src/com/mysql/jdbc/PreparedStatement.java
trunk/connector-j/src/com/mysql/jdbc/ResultSet.java
trunk/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java
trunk/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
trunk/connector-j/src/com/mysql/jdbc/Statement.java
trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/CallableStatementWrapper.java
trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java
trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSource.java
trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlPooledConnection.java
trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/PreparedStatementWrapper.java
trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/StatementWrapper.java
Log:
Re-worked Ant buildfile to build JDBC-4.0 classes separately, as well
as support building under Eclipse (since Eclipse can't mix/match JDKs).
Refactoring to get JDBC-4-specific code into subclasses that get loaded by factory methods (so that we can have _one_ driver codebase and .jar and run in both Java6 and older VMs)
Modified: trunk/connector-j/.classpath
===================================================================
(Binary files differ)
Added: trunk/connector-j/.fbprefs
===================================================================
--- trunk/connector-j/.fbprefs 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/.fbprefs 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,98 @@
+#FindBugs User Preferences
+#Tue Dec 19 15:23:45 CST 2006
+detector73=InefficientToArray|true
+detector72=FindDeadLocalStores|true
+detector71=FindNonSerializableValuePassedToWriteObject|true
+detector70=UncallableMethodOfAnonymousClass|true
+detector9=FindOpenStream|true
+detector8=FindUnsyncGet|true
+detector7=InefficientMemberAccess|false
+detector6=FindDoubleCheck|true
+detector5=FindNonSerializableStoreIntoSession|true
+detector4=IteratorIdioms|true
+detector69=LoadOfKnownNullValue|true
+detector3=DontCatchIllegalMonitorStateException|true
+detector68=DumbMethodInvocations|true
+detector2=SuspiciousThreadInterrupted|true
+detector67=SuperfluousInstanceOf|true
+detector1=FindNakedNotify|true
+detector66=FindSleepWithLockHeld|true
+detector0=BadSyntaxForRegularExpression|true
+detector65=ConfusedInheritance|true
+detector64=SerializableIdiom|true
+detector63=FindUnreleasedLock|true
+detector62=PreferZeroLengthArrays|true
+detector61=UnnecessaryMath|true
+detector60=FindNonShortCircuit|true
+detector59=StartInConstructor|true
+detector58=WrongMapIterator|true
+detector57=FindTwoLockWait|true
+detector56=FindReturnRef|true
+detector55=DuplicateBranches|true
+detector54=FindCircularDependencies|false
+detector53=UnreadFields|true
+detector52=QuestionableBooleanAssignment|true
+detector51=UselessSubclassMethod|false
+detector50=FindUninitializedGet|true
+detector49=FindFloatEquality|true
+detector48=LazyInit|true
+detector47=FindSpinLoop|true
+detector46=FindBadCast2|true
+detector45=FindLocalSelfAssignment2|true
+detector44=BadAppletConstructor|false
+detector43=FindFieldSelfAssignment|true
+detector42=IDivResultCastToDouble|true
+filter_settings=Medium|CORRECTNESS,PERFORMANCE,I18N,MT_CORRECTNESS,STYLE,MALICIOUS_CODE|false
+detector41=FindUselessControlFlow|true
+detector40=FindNullDeref|true
+detector39=CloneIdiom|true
+detector38=FindEmptySynchronizedBlock|true
+detector37=XMLFactoryBypass|true
+detector36=FindRefComparison|true
+detector35=WaitInLoop|true
+detector34=InstantiateStaticClass|true
+detector33=ComparatorIdiom|true
+detector32=BadlyOverriddenAdapter|true
+detector31=VolatileUsage|true
+detector30=ReadReturnShouldBeChecked|true
+detector92=InfiniteRecursiveLoop|true
+detector91=RuntimeExceptionCapture|true
+detector90=ConfusionBetweenInheritedAndOuterMethod|true
+default_directory=C\:\\ides\\eclipse-SDK-3.2RC7-win32
+detector29=FindUnconditionalWait|true
+detector28=FindJSR166LockMonitorenter|true
+detector27=InvalidJUnitTest|true
+detector26=FindRunInvocations|true
+detector25=MultithreadedInstanceAccess|true
+detector89=BadResultSetAccess|true
+detector24=MutableLock|true
+detector88=MutableStaticFields|true
+detector23=UseObjectEquals|false
+detector87=CheckImmutableAnnotation|true
+detector22=DumbMethods|true
+detector86=DroppedException|true
+detector21=VarArgsProblems|true
+detector85=FindHEmismatch|true
+detector20=FindUncalledPrivateMethods|true
+detector84=MethodReturnCheck|true
+detector_threshold=2
+detector83=BadUseOfReturnValue|true
+detector82=FindSqlInjection|true
+detector81=Naming|true
+detector80=EmptyZipFileEntry|true
+detector19=FindMaskedFields|true
+detector18=InfiniteLoop|false
+detector17=DoInsideDoPriviledged|true
+detector16=FindPuzzlers|true
+detector15=RedundantInterfaces|true
+detector79=InitializationChain|true
+detector14=IncompatMask|true
+detector78=InfiniteRecursiveLoop2|false
+detector13=FindMismatchedWaitOrNotify|true
+detector77=PublicSemaphores|true
+detector12=FindFinalizeInvocations|true
+detector76=SwitchFallthrough|true
+detector11=StringConcatenation|true
+detector75=InheritanceUnsafeGetResource|true
+detector10=FindBadForLoop|true
+detector74=FindInconsistentSync2|true
Modified: trunk/connector-j/.settings/org.eclipse.jdt.core.prefs
===================================================================
(Binary files differ)
Modified: trunk/connector-j/.settings/org.eclipse.jdt.ui.prefs
===================================================================
--- trunk/connector-j/.settings/org.eclipse.jdt.ui.prefs 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/.settings/org.eclipse.jdt.ui.prefs 2007-03-09 21:45:01 UTC (rev 6342)
@@ -1,3 +1,3 @@
-#Tue Sep 26 22:06:10 CDT 2006
+#Tue Dec 19 15:23:45 CST 2006
eclipse.preferences.version=1
internal.default.compliance=default
Modified: trunk/connector-j/CHANGES
===================================================================
--- trunk/connector-j/CHANGES 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/CHANGES 2007-03-09 21:45:01 UTC (rev 6342)
@@ -5,6 +5,9 @@
- Bumped JDBC Specification version number in jar-file manifest.
+ - Re-worked Ant buildfile to build JDBC-4.0 classes separately, as well
+ as support building under Eclipse (since Eclipse can't mix/match JDKs).
+
03-nn-07 - Version 5.0.6
- Fixed BUG#25545 - Client options not sent correctly when using SSL,
@@ -24,7 +27,12 @@
statement that enables this functionality, which the driver ignored (using
the original metadata returned during prepare()), causing corrupt reading
of data due to type mismatch when the actual rows were returned.
-
+
+ - Fixed BUG#26959 - comments in DDL of stored procedures/functions confuse
+ procedure parser, and thus metadata about them can not be created, leading to
+ inability to retrieve said metadata, or execute procedures that have certain
+ comments in them.
+
03-01-07 - Version 5.0.5
- Fixed BUG#23645 - Some collations/character sets reported as "unknown"
Modified: trunk/connector-j/build.xml
===================================================================
--- trunk/connector-j/build.xml 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/build.xml 2007-03-09 21:45:01 UTC (rev 6342)
@@ -39,9 +39,14 @@
<property name="distDir" value="./dist"/>
<property name="junit.results" value="${buildDir}/junit"/>
<property name="debug.enable" value="on" />
+
+ <!-- Send class files to correct location if running in eclipse -->
+
+ <condition property="compiler.output" value="bin" else="${buildDir}/${fullProdName}">
+ <isset property="eclipse.pdebuild.home" />
+ </condition>
<!--
-
The following property is needed for building the docs. It's
set to the defaults for my development environment, but can be passed
on the command line to ant via -D switches.
@@ -49,6 +54,15 @@
<property name="com.mysql.jdbc.docs.sourceDir" value="/home/mmatthew/work/docs/prebuilt"/>
+ <!--
+ The following properties are needed for finding JDK6, set to the defaults
+ for my development environment, but can be passed on the command line
+ to ant via -D switches
+ -->
+
+ <property name="com.mysql.jdbc.java6.javac" value="C:\jvms\jdk1.6.0\bin\javac.exe" />
+ <property name="com.mysql.jdbc.java6.rtjar" value="C:\jvms\jdk1.6.0\jre\lib\rt.jar" />
+
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${sourceDir}/lib/ant-contrib.jar"/>
@@ -113,7 +127,7 @@
<fileset dir="${sourceDir}/" excludes="**/CVS">
<patternset id="classjar" >
<exclude name="**/*.class*"/>
- <exclude name="**/*.jar"/>
+ <exclude name="**/*.jar"/>
</patternset>
</fileset>
@@ -633,17 +647,41 @@
<!-- Compiles the driver itself -->
- <target name="compile-driver" depends="init, -clean-output">
- <javac srcdir="${buildDir}/${fullProdName}"
- destdir="${buildDir}/${fullProdName}"
+ <target name="compile-driver" depends="compile-driver-jdbc3, compile-driver-jdbc4" />
+
+ <target name="compile-driver-jdbc3" depends="init, -clean-output">
+ <javac sourcepath="" srcdir="${buildDir}/${fullProdName}"
+ destdir="${compiler.output}"
deprecation="off"
- debug="${debug.enable}"
- excludes="testsuite/**,
- com/mysql/jdbc/integration/**,
- com/mysql/jdbc/log/Log4JLogger.java">
+ debug="${debug.enable}">
+ <include name="**/*.java" />
+ <exclude name="testsuite/**" />
+ <exclude name="com/mysql/jdbc/integration/**" />
+ <exclude name="com/mysql/jdbc/log/Log4JLogger.java" />
+ <exclude name="com/mysql/jdbc/JDBC4*.java" />
+ <exclude name="com/mysql/jdbc/exceptions/jdbc4/*" />
+
<classpath refid="project.build.classpath" />
</javac>
</target>
+
+ <target name="compile-driver-jdbc4" depends="compile-driver-jdbc3">
+
+ <javac destdir="${compiler.output}"
+ deprecation="off"
+ debug="${debug.enable}"
+ fork="yes"
+ executable="${com.mysql.jdbc.java6.javac}"
+ compiler="modern"
+ sourcepath="" srcdir="${buildDir}/${fullProdName}"
+ bootclasspath="${com.mysql.jdbc.java6.rtjar}">
+ <include name="**/JDBC4*.java" />
+ <include name="com/mysql/jdbc/exceptions/jdbc4/*" />
+
+ <classpath refid="project.build.classpath" />
+ </javac>
+
+ </target>
<!-- Compiles a version of the driver with AspectJ tracing -->
@@ -656,7 +694,7 @@
</taskdef>
- <iajc destDir="${buildDir}/${fullProdName}">
+ <iajc destdir="${compiler.output}">
<sourceroots>
<pathelement location="${buildDir}/${fullProdName}/org"/>
<pathelement location="${buildDir}/${fullProdName}/com"/>
@@ -679,7 +717,7 @@
depends="compile-driver"
if="com.mysql.jdbc.c3p0Present">
<javac srcdir="${buildDir}/${fullProdName}"
- destdir="${buildDir}/${fullProdName}"
+ destdir="${compiler.output}"
deprecation="off"
debug="${debug.enable}"
includes="com/mysql/jdbc/integration/c3p0/**">
@@ -691,7 +729,7 @@
depends="compile-driver"
if="com.mysql.jdbc.jbossPresent">
<javac srcdir="${buildDir}/${fullProdName}"
- destdir="${buildDir}/${fullProdName}"
+ destdir="${compiler.output}"
deprecation="off"
debug="${debug.enable}"
includes="com/mysql/jdbc/integration/jboss/**">
@@ -703,7 +741,7 @@
depends="compile-driver"
if="com.mysql.jdbc.log4jPresent">
<javac srcdir="${buildDir}/${fullProdName}"
- destdir="${buildDir}/${fullProdName}"
+ destdir="${compiler.output}"
deprecation="off"
debug="${debug.enable}"
includes="com/mysql/jdbc/log/Log4JLogger.java">
@@ -716,13 +754,26 @@
<target name="compile-testsuite" depends="init, compile-driver">
<javac
srcdir="${buildDir}/${fullProdName}"
- destdir="${buildDir}/${fullProdName}"
+ destdir="${compiler.output}"
deprecation="off"
debug="${debug.enable}"
includes="testsuite/**"
- excludes="testsuite/requiresNonRedists/**">
+ excludes="testsuite/requiresNonRedists/**, testsuite/**/jdbc4/**">
<classpath refid="project.build.classpath"/>
</javac>
+
+ <javac destdir="${compiler.output}"
+ deprecation="off"
+ debug="${debug.enable}"
+ fork="yes"
+ executable="${com.mysql.jdbc.java6.javac}"
+ compiler="modern"
+ sourcepath="" srcdir="${buildDir}/${fullProdName}"
+ bootclasspath="${com.mysql.jdbc.java6.rtjar}">
+ <include name="testsuite/**/jdbc4/**" />
+
+ <classpath refid="project.build.classpath" />
+ </javac>
</target>
<target name="real-clean">
@@ -797,7 +848,7 @@
<emma enabled="${emma.enabled}" >
<instr instrpathref="built.driver.only.classpath"
- destdir="${buildDir}/${fullProdName}"
+ destdir="${compiler.output}"
metadatafile="${emma.coverage.dir}/metadata.emma"
merge="true"
mode="overwrite">
Modified: trunk/connector-j/src/com/mysql/jdbc/BlobFromLocator.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/BlobFromLocator.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/BlobFromLocator.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -32,7 +32,7 @@
import java.util.ArrayList;
import java.util.List;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
/**
* The representation (mapping) in the JavaTM programming language of an SQL
@@ -671,11 +671,11 @@
}
public void free() throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
public InputStream getBinaryStream(long pos, long length) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
}
Modified: trunk/connector-j/src/com/mysql/jdbc/CallableStatement.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/CallableStatement.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/CallableStatement.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -47,10 +47,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
-import com.mysql.jdbc.jdbc4.NClob;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
/**
* Representation of stored procedures for JDBC
@@ -61,7 +59,7 @@
*/
public class CallableStatement extends PreparedStatement implements
java.sql.CallableStatement {
- class CallableStatementParam {
+ protected class CallableStatementParam {
int desiredJdbcType;
int index;
@@ -110,7 +108,7 @@
}
}
- class CallableStatementParamInfo {
+ protected class CallableStatementParamInfo {
String catalogInUse;
boolean isFunctionCall;
@@ -338,7 +336,7 @@
* quite a bit out there in the wild (Websphere, FreeBSD, anyone?)
*/
- class CallableStatementParamInfoJDBC3 extends CallableStatementParamInfo
+ protected class CallableStatementParamInfoJDBC3 extends CallableStatementParamInfo
implements ParameterMetaData {
CallableStatementParamInfoJDBC3(java.sql.ResultSet paramTypesRs)
@@ -351,11 +349,11 @@
}
public boolean isWrapperFor(Class arg0) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
public Object unwrap(Class arg0) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
}
@@ -896,7 +894,7 @@
* @throws SQLException
* if the parameter name is null or empty.
*/
- private String fixParameterName(String paramNameIn) throws SQLException {
+ protected String fixParameterName(String paramNameIn) throws SQLException {
if ((paramNameIn == null) || (paramNameIn.length() == 0)) {
throw SQLError.createSQLException(
((Messages.getString("CallableStatement.0") + paramNameIn) == null) //$NON-NLS-1$
@@ -1322,7 +1320,7 @@
return retValue;
}
- private int getNamedParamIndex(String paramName, boolean forOut)
+ protected int getNamedParamIndex(String paramName, boolean forOut)
throws SQLException {
if (this.connection.getNoAccessToProcedureBodies()) {
throw SQLError.createSQLException("No access to parameters by name when connection has been configured not to access procedure bodies",
@@ -1439,7 +1437,7 @@
* if no output parameters were defined, or if no output
* parameters were returned.
*/
- private ResultSet getOutputParameters(int paramIndex) throws SQLException {
+ protected ResultSet getOutputParameters(int paramIndex) throws SQLException {
this.outputParamWasNull = false;
if (paramIndex == 1 && this.callingStoredFunction
@@ -1706,7 +1704,7 @@
return retValue;
}
- private int mapOutputParameterIndexToRsIndex(int paramIndex)
+ protected int mapOutputParameterIndexToRsIndex(int paramIndex)
throws SQLException {
if (this.returnValueParam != null && paramIndex == 1) {
@@ -2179,4 +2177,75 @@
return super.getParameterIndexOffset();
}
+
+ public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
+ setAsciiStream(getNamedParamIndex(parameterName, false), x);
+
+ }
+
+ public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
+ setAsciiStream(getNamedParamIndex(parameterName, false), x, length);
+
+ }
+
+ public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
+ setBinaryStream(getNamedParamIndex(parameterName, false), x);
+
+ }
+
+ public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException {
+ setBinaryStream(getNamedParamIndex(parameterName, false), x, length);
+
+ }
+
+ public void setBlob(String parameterName, Blob x) throws SQLException {
+ setBlob(getNamedParamIndex(parameterName, false), x);
+
+ }
+
+ public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
+ setBlob(getNamedParamIndex(parameterName, false), inputStream);
+
+ }
+
+ public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {
+ setBlob(getNamedParamIndex(parameterName, false), inputStream, length);
+
+ }
+
+ public void setCharacterStream(String parameterName, Reader reader) throws SQLException {
+ setCharacterStream(getNamedParamIndex(parameterName, false), reader);
+
+ }
+
+ public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
+ setCharacterStream(getNamedParamIndex(parameterName, false), reader, length);
+
+ }
+
+ public void setClob(String parameterName, Clob x) throws SQLException {
+ setClob(getNamedParamIndex(parameterName, false), x);
+
+ }
+
+ public void setClob(String parameterName, Reader reader) throws SQLException {
+ setClob(getNamedParamIndex(parameterName, false), reader);
+
+ }
+
+ public void setClob(String parameterName, Reader reader, long length) throws SQLException {
+ setClob(getNamedParamIndex(parameterName, false), reader, length);
+
+ }
+
+ public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
+ setNCharacterStream(getNamedParamIndex(parameterName, false), value);
+
+ }
+
+ public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {
+ setNCharacterStream(getNamedParamIndex(parameterName, false), value, length);
+
+ }
+
}
Modified: trunk/connector-j/src/com/mysql/jdbc/Clob.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/Clob.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/Clob.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -33,7 +33,7 @@
import java.sql.SQLException;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
/**
* Simplistic implementation of java.sql.Clob for MySQL Connector/J
@@ -295,10 +295,10 @@
}
public void free() throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
public Reader getCharacterStream(long pos, long length) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
}
Modified: trunk/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/Connection.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/Connection.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -594,7 +594,7 @@
* @exception SQLException
* if a database access error occurs
*/
- private Connection(String hostToConnectTo, int portToConnectTo, Properties info,
+ protected Connection(String hostToConnectTo, int portToConnectTo, Properties info,
String databaseToConnectTo, String url)
throws SQLException {
this.charsetToNumBytesMap = new HashMap();
Added: trunk/connector-j/src/com/mysql/jdbc/JDBC4CallableStatement.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/JDBC4CallableStatement.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/JDBC4CallableStatement.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,244 @@
+/*
+ Copyright (C) 2002-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.SQLException;
+import java.sql.RowId;
+import java.sql.SQLXML;
+import java.sql.NClob;
+
+import com.mysql.jdbc.CallableStatement;
+import com.mysql.jdbc.Connection;
+import com.mysql.jdbc.ResultSet;
+import com.mysql.jdbc.CallableStatement.CallableStatementParamInfo;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
+
+public class JDBC4CallableStatement extends CallableStatement {
+
+ public JDBC4CallableStatement(Connection conn, CallableStatementParamInfo paramInfo) throws SQLException {
+ super(conn, paramInfo);
+ // TODO Auto-generated constructor stub
+ }
+
+ public void setRowId(String parameterName, RowId x) throws SQLException {
+ JDBC4PreparedStatementHelper.setRowId(this, getNamedParamIndex(parameterName, false), x);
+ }
+
+ public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
+ JDBC4PreparedStatementHelper.setSQLXML(this, getNamedParamIndex(parameterName, false), xmlObject);
+
+ }
+
+ public SQLXML getSQLXML(int parameterIndex) throws SQLException {
+ ResultSet rs = getOutputParameters(parameterIndex);
+
+ SQLXML retValue = ((com.mysql.jdbc.JDBC4ResultSet)rs)
+ .getSQLXML(mapOutputParameterIndexToRsIndex(parameterIndex));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+
+ }
+
+ public SQLXML getSQLXML(String parameterName) throws SQLException {
+ ResultSet rs = getOutputParameters(0); // definitely not going to be
+ // from ?=
+
+ SQLXML retValue = ((com.mysql.jdbc.JDBC4ResultSet)rs).getSQLXML(fixParameterName(parameterName));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+
+ public RowId getRowId(int parameterIndex) throws SQLException {
+ ResultSet rs = getOutputParameters(parameterIndex);
+
+ RowId retValue = ((com.mysql.jdbc.JDBC4ResultSet)rs)
+ .getRowId(mapOutputParameterIndexToRsIndex(parameterIndex));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+
+ public RowId getRowId(String parameterName) throws SQLException {
+ ResultSet rs = getOutputParameters(0); // definitely not going to be
+ // from ?=
+
+ RowId retValue = ((com.mysql.jdbc.JDBC4ResultSet)rs).getRowId(fixParameterName(parameterName));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+
+ public void setNClob(String parameterName, NClob value) throws SQLException {
+ JDBC4PreparedStatementHelper.setNClob(this, getNamedParamIndex(parameterName, false), value);
+
+ }
+
+ public void setNClob(String parameterName, Reader reader) throws SQLException {
+ setNClob(getNamedParamIndex(parameterName, false), reader);
+
+ }
+
+ public void setNClob(String parameterName, Reader reader, long length) throws SQLException {
+ setNClob(getNamedParamIndex(parameterName, false), reader, length);
+
+ }
+
+ public void setNString(String parameterName, String value) throws SQLException {
+ setNString(getNamedParamIndex(parameterName, false), value);
+ }
+
+
+
+ public boolean isWrapperFor(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+
+ }
+
+ public Object unwrap(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+
+ }
+
+ /**
+ * @see java.sql.CallableStatement#getCharacterStream(int)
+ */
+ public Reader getCharacterStream(int parameterIndex) throws SQLException {
+ ResultSet rs = getOutputParameters(parameterIndex);
+
+ Reader retValue = rs
+ .getCharacterStream(mapOutputParameterIndexToRsIndex(parameterIndex));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+
+ /**
+ * @see java.sql.CallableStatement#getCharacterStream(java.lang.String)
+ */
+ public Reader getCharacterStream(String parameterName) throws SQLException {
+ ResultSet rs = getOutputParameters(0); // definitely not going to be
+ // from ?=
+
+ Reader retValue = rs.getCharacterStream(fixParameterName(parameterName));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+
+ /**
+ * @see java.sql.CallableStatement#getNCharacterStream(int)
+ */
+ public Reader getNCharacterStream(int parameterIndex) throws SQLException {
+ ResultSet rs = getOutputParameters(parameterIndex);
+
+ Reader retValue = ((com.mysql.jdbc.JDBC4ResultSet)rs)
+ .getNCharacterStream(mapOutputParameterIndexToRsIndex(parameterIndex));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+
+ /**
+ * @see java.sql.CallableStatement#getNCharacterStream(java.lang.String)
+ */
+ public Reader getNCharacterStream(String parameterName) throws SQLException {
+ ResultSet rs = getOutputParameters(0); // definitely not going to be
+ // from ?=
+
+ Reader retValue = ((com.mysql.jdbc.JDBC4ResultSet)rs).getNCharacterStream(fixParameterName(parameterName));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+
+ /**
+ * @see java.sql.CallableStatement#getNClob(int)
+ */
+ public NClob getNClob(int parameterIndex) throws SQLException {
+ ResultSet rs = getOutputParameters(parameterIndex);
+
+ NClob retValue = ((com.mysql.jdbc.JDBC4ResultSet)rs)
+ .getNClob(mapOutputParameterIndexToRsIndex(parameterIndex));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+
+ /**
+ * @see java.sql.CallableStatement#getNClob(java.lang.String)
+ */
+ public NClob getNClob(String parameterName) throws SQLException {
+ ResultSet rs = getOutputParameters(0); // definitely not going to be
+ // from ?=
+
+ NClob retValue = ((com.mysql.jdbc.JDBC4ResultSet)rs).getNClob(fixParameterName(parameterName));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+
+ /**
+ * @see java.sql.CallableStatement#getNString(int)
+ */
+ public String getNString(int parameterIndex) throws SQLException {
+ ResultSet rs = getOutputParameters(parameterIndex);
+
+ String retValue = ((com.mysql.jdbc.JDBC4ResultSet)rs)
+ .getNString(mapOutputParameterIndexToRsIndex(parameterIndex));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+
+ /**
+ * @see java.sql.CallableStatement#getNString(java.lang.String)
+ */
+ public String getNString(String parameterName) throws SQLException {
+ ResultSet rs = getOutputParameters(0); // definitely not going to be
+ // from ?=
+
+ String retValue = ((com.mysql.jdbc.JDBC4ResultSet)rs).getNString(fixParameterName(parameterName));
+
+ this.outputParamWasNull = rs.wasNull();
+
+ return retValue;
+ }
+}
Added: trunk/connector-j/src/com/mysql/jdbc/JDBC4Connection.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/JDBC4Connection.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/JDBC4Connection.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,106 @@
+/*
+ Copyright (C) 2002-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc;
+
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.SQLClientInfoException;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+import java.sql.NClob;
+import java.sql.Struct;
+import java.util.Properties;
+
+
+import com.mysql.jdbc.Connection;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
+
+public class JDBC4Connection extends Connection {
+
+ JDBC4Connection(String hostToConnectTo, int portToConnectTo, Properties info, String databaseToConnectTo, String url) throws SQLException {
+ super(hostToConnectTo, portToConnectTo, info, databaseToConnectTo, url);
+ // TODO Auto-generated constructor stub
+ }
+
+ public SQLXML createSQLXML() throws SQLException {
+ return new JDBC4MysqlSQLXML();
+ }
+
+ public java.sql.Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public Properties getClientInfo() throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public String getClientInfo(String name) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public boolean isValid(int timeout) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public void setClientInfo(Properties properties) throws SQLClientInfoException {
+ throw new NotYetImplementedException();
+ }
+
+ public void setClientInfo(String name, String value) throws SQLClientInfoException {
+ throw new NotYetImplementedException();
+ }
+
+ public boolean isWrapperFor(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public Object unwrap(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ /**
+ * @see java.sql.Connection#createBlob()
+ */
+ public Blob createBlob() {
+ return new com.mysql.jdbc.Blob();
+ }
+
+ /**
+ * @see java.sql.Connection#createClob()
+ */
+ public Clob createClob() {
+ return new com.mysql.jdbc.Clob();
+ }
+
+ /**
+ * @see java.sql.Connection#createNClob()
+ */
+ public NClob createNClob() {
+ return new com.mysql.jdbc.JDBC4NClob();
+ }
+}
Added: trunk/connector-j/src/com/mysql/jdbc/JDBC4DatabaseMetaData.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/JDBC4DatabaseMetaData.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/JDBC4DatabaseMetaData.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,154 @@
+/*
+ Copyright (C) 2002-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc;
+
+import java.sql.ResultSet;
+import java.sql.RowIdLifetime;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.mysql.jdbc.Connection;
+import com.mysql.jdbc.DatabaseMetaData;
+import com.mysql.jdbc.Field;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
+
+public class JDBC4DatabaseMetaData extends DatabaseMetaData {
+ public JDBC4DatabaseMetaData(Connection connToSet, String databaseToSet) {
+ super(connToSet, databaseToSet);
+ // TODO Auto-generated constructor stub
+ }
+
+ public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
+ return false;
+ }
+
+ public ResultSet getClientInfoProperties() throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public ResultSet getFunctionParameters(String catalog, String schemaPattern, String functionNamePattern, String parameterNamePattern) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ /**
+ * Retrieves a description of the system and user functions available
+ * in the given catalog.
+ * <P>
+ * Only system and user function descriptions matching the schema and
+ * function name criteria are returned. They are ordered by
+ * <code>FUNCTION_CAT</code>, <code>FUNCTION_SCHEM</code>,
+ * <code>FUNCTION_NAME</code> and
+ * <code>SPECIFIC_ NAME</code>.
+ *
+ * <P>Each function description has the the following columns:
+ * <OL>
+ * <LI><B>FUNCTION_CAT</B> String => function catalog (may be <code>null</code>)
+ * <LI><B>FUNCTION_SCHEM</B> String => function schema (may be <code>null</code>)
+ * <LI><B>FUNCTION_NAME</B> String => function name. This is the name
+ * used to invoke the function
+ * <LI><B>REMARKS</B> String => explanatory comment on the function
+ * <LI><B>FUNCTION_TYPE</B> short => kind of function:
+ * <UL>
+ * <LI>functionResultUnknown - Cannot determine if a return value
+ * or table will be returned
+ * <LI> functionNoTable- Does not return a table
+ * <LI> functionReturnsTable - Returns a table
+ * </UL>
+ * <LI><B>SPECIFIC_NAME</B> String => the name which uniquely identifies
+ * this function within its schema. This is a user specified, or DBMS
+ * generated, name that may be different then the <code>FUNCTION_NAME</code>
+ * for example with overload functions
+ * </OL>
+ * <p>
+ * A user may not have permission to execute any of the functions that are
+ * returned by <code>getFunctions</code>
+ *
+ * @param catalog a catalog name; must match the catalog name as it
+ * is stored in the database; "" retrieves those without a catalog;
+ * <code>null</code> means that the catalog name should not be used to narrow
+ * the search
+ * @param schemaPattern a schema name pattern; must match the schema name
+ * as it is stored in the database; "" retrieves those without a schema;
+ * <code>null</code> means that the schema name should not be used to narrow
+ * the search
+ * @param functionNamePattern a function name pattern; must match the
+ * function name as it is stored in the database
+ * @return <code>ResultSet</code> - each row is a function description
+ * @exception SQLException if a database access error occurs
+ * @see #getSearchStringEscape
+ * @since 1.6
+ */
+ public ResultSet getFunctions(String catalog, String schemaPattern,
+ String functionNamePattern) throws SQLException {
+
+ Field[] fields = new Field[6];
+ fields[0] = new Field("", "FUNCTION_CAT", Types.CHAR,
+ MAX_IDENTIFIER_LENGTH);
+ fields[1] = new Field("", "FUNCTION_SCHEM", Types.CHAR,
+ MAX_IDENTIFIER_LENGTH);
+ fields[2] = new Field("", "FUNCTION_NAME", Types.CHAR,
+ MAX_IDENTIFIER_LENGTH);
+ fields[3] = new Field("", "REMARKS", Types.CHAR, MAX_IDENTIFIER_LENGTH);
+ fields[4] = new Field("", "FUNCTION_TYPE", Types.SMALLINT, 0);
+ fields[5] = new Field("", "SPECIFIC_NAME", Types.CHAR,
+ MAX_IDENTIFIER_LENGTH);
+
+ return getProceduresAndOrFunctions(fields, catalog, schemaPattern,
+ functionNamePattern, false, true);
+
+ }
+
+ public RowIdLifetime getRowIdLifetime() throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
+ return true;
+ }
+
+ public boolean isWrapperFor(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public Object unwrap(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public boolean providesQueryObjectGenerator() throws SQLException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ protected int getJDBC4FunctionNoTableConstant() {
+ return functionNoTable;
+ }
+}
Copied: trunk/connector-j/src/com/mysql/jdbc/JDBC4MysqlSQLXML.java (from rev 6339, trunk/connector-j/src/com/mysql/jdbc/MysqlSQLXML.java)
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/MysqlSQLXML.java 2007-03-06 23:55:30 UTC (rev 6339)
+++ trunk/connector-j/src/com/mysql/jdbc/JDBC4MysqlSQLXML.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,565 @@
+/*
+ Copyright (C) 2002-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLXML;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stax.StAXResult;
+import javax.xml.transform.stax.StAXSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
+
+public class JDBC4MysqlSQLXML implements SQLXML, WriterWatcher, OutputStreamWatcher {
+
+ private XMLInputFactory inputFactory;
+
+ private XMLOutputFactory outputFactory;
+
+ private String stringRep;
+
+ private ResultSet owningResultSet;
+
+ private int columnIndexOfXml;
+
+ private boolean fromResultSet;
+
+ private boolean isClosed = false;
+
+ private boolean workingWithResult;
+
+ private DOMResult asDOMResult;
+
+ protected JDBC4MysqlSQLXML(ResultSet owner, int index) {
+ this.owningResultSet = owner;
+ this.columnIndexOfXml = index;
+ this.fromResultSet = true;
+ }
+
+ protected JDBC4MysqlSQLXML() {
+ this.fromResultSet = false;
+ }
+
+ public synchronized void free() throws SQLException {
+ this.inputFactory = null;
+ this.outputFactory = null;
+ this.owningResultSet = null;
+ this.workingWithResult = false;
+ this.isClosed = true;
+
+ }
+
+ public synchronized String getString() throws SQLException {
+ checkClosed();
+ checkWorkingWithResult();
+
+ if (this.fromResultSet) {
+ return this.owningResultSet.getString(this.columnIndexOfXml);
+ }
+
+ return this.stringRep;
+ }
+
+ private synchronized void checkClosed() throws SQLException {
+ if (this.isClosed) {
+ throw SQLError.createSQLException("SQLXMLInstance has been free()d");
+ }
+ }
+
+ private synchronized void checkWorkingWithResult() throws SQLException {
+ if (this.workingWithResult) {
+ throw SQLError.createSQLException("Can't perform requested operation after getResult() has been called to write XML data",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+ }
+
+ /**
+ * Sets the XML value designated by this SQLXML instance to the given String
+ * representation. The format of this String is defined by
+ * org.xml.sax.InputSource, where the characters in the stream represent the
+ * unicode code points for XML according to section 2 and appendix B of the
+ * XML 1.0 specification. Although an encoding declaration other than
+ * unicode may be present, the encoding of the String is unicode. The
+ * behavior of this method is the same as ResultSet.updateString() when the
+ * designated column of the ResultSet has a type java.sql.Types of SQLXML.
+ * <p>
+ * The SQL XML object becomes not writeable when this method is called and
+ * may also become not readable depending on implementation.
+ *
+ * @param value
+ * the XML value
+ * @throws SQLException
+ * if there is an error processing the XML value. The getCause()
+ * method of the exception may provide a more detailed
+ * exception, for example, if the stream does not contain valid
+ * characters. An exception is thrown if the state is not
+ * writable.
+ * @exception SQLFeatureNotSupportedException
+ * if the JDBC driver does not support this method
+ * @since 1.6
+ */
+
+ public synchronized void setString(String str) throws SQLException {
+ checkClosed();
+ checkWorkingWithResult();
+
+ this.stringRep = str;
+ this.fromResultSet = false;
+ }
+
+ public synchronized boolean isEmpty() throws SQLException {
+ checkClosed();
+ checkWorkingWithResult();
+
+ if (!this.fromResultSet) {
+ return this.stringRep == null || this.stringRep.length() == 0;
+ }
+
+ return false;
+ }
+
+ public synchronized InputStream getBinaryStream() throws SQLException {
+ checkClosed();
+ checkWorkingWithResult();
+
+ return this.owningResultSet.getBinaryStream(this.columnIndexOfXml);
+ }
+
+ /**
+ * Retrieves the XML value designated by this SQLXML instance as a
+ * java.io.Reader object. The format of this stream is defined by
+ * org.xml.sax.InputSource, where the characters in the stream represent the
+ * unicode code points for XML according to section 2 and appendix B of the
+ * XML 1.0 specification. Although an encoding declaration other than
+ * unicode may be present, the encoding of the stream is unicode. The
+ * behavior of this method is the same as ResultSet.getCharacterStream()
+ * when the designated column of the ResultSet has a type java.sql.Types of
+ * SQLXML.
+ * <p>
+ * The SQL XML object becomes not readable when this method is called and
+ * may also become not writable depending on implementation.
+ *
+ * @return a stream containing the XML data.
+ * @throws SQLException
+ * if there is an error processing the XML value. The getCause()
+ * method of the exception may provide a more detailed
+ * exception, for example, if the stream does not contain valid
+ * characters. An exception is thrown if the state is not
+ * readable.
+ * @exception SQLFeatureNotSupportedException
+ * if the JDBC driver does not support this method
+ * @since 1.6
+ */
+ public synchronized Reader getCharacterStream() throws SQLException {
+ checkClosed();
+ checkWorkingWithResult();
+
+ return this.owningResultSet.getCharacterStream(this.columnIndexOfXml);
+ }
+
+ /**
+ * Returns a Source for reading the XML value designated by this SQLXML
+ * instance. Sources are used as inputs to XML parsers and XSLT
+ * transformers.
+ * <p>
+ * Sources for XML parsers will have namespace processing on by default. The
+ * systemID of the Source is implementation dependent.
+ * <p>
+ * The SQL XML object becomes not readable when this method is called and
+ * may also become not writable depending on implementation.
+ * <p>
+ * Note that SAX is a callback architecture, so a returned SAXSource should
+ * then be set with a content handler that will receive the SAX events from
+ * parsing. The content handler will receive callbacks based on the contents
+ * of the XML.
+ *
+ * <pre>
+ * SAXSource saxSource = sqlxml.getSource(SAXSource.class);
+ * XMLReader xmlReader = saxSource.getXMLReader();
+ * xmlReader.setContentHandler(myHandler);
+ * xmlReader.parse(saxSource.getInputSource());
+ * </pre>
+ *
+ * @param sourceClass
+ * The class of the source, or null. If the class is null, a
+ * vendor specifc Source implementation will be returned. The
+ * following classes are supported at a minimum:
+ *
+ * (MySQL returns a SAXSource if sourceClass == null)
+ *
+ * <pre>
+ * javax.xml.transform.dom.DOMSource - returns a DOMSource
+ * javax.xml.transform.sax.SAXSource - returns a SAXSource
+ * javax.xml.transform.stax.StAXSource - returns a StAXSource
+ * javax.xml.transform.stream.StreamSource - returns a StreamSource
+ * </pre>
+ *
+ * @return a Source for reading the XML value.
+ * @throws SQLException
+ * if there is an error processing the XML value or if this
+ * feature is not supported. The getCause() method of the
+ * exception may provide a more detailed exception, for example,
+ * if an XML parser exception occurs. An exception is thrown if
+ * the state is not readable.
+ * @exception SQLFeatureNotSupportedException
+ * if the JDBC driver does not support this method
+ * @since 1.6
+ */
+ public synchronized Source getSource(Class clazz) throws SQLException {
+ checkClosed();
+ checkWorkingWithResult();
+
+ // Note that we try and use streams here wherever possible
+ // for the day that the server actually supports streaming
+ // from server -> client (futureproofing)
+
+ if (clazz == null || clazz.equals(SAXSource.class)) {
+
+ InputSource inputSource = null;
+
+ if (this.fromResultSet) {
+ inputSource = new InputSource(
+ this.owningResultSet
+ .getCharacterStream(this.columnIndexOfXml));
+ } else {
+ inputSource = new InputSource(new StringReader(this.stringRep));
+ }
+
+ return new SAXSource(inputSource);
+ } else if (clazz.equals(DOMSource.class)) {
+ try {
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory
+ .newInstance();
+ builderFactory.setNamespaceAware(true);
+ DocumentBuilder builder = builderFactory.newDocumentBuilder();
+
+ InputSource inputSource = null;
+
+ if (this.fromResultSet) {
+ inputSource = new InputSource(
+ this.owningResultSet
+ .getCharacterStream(this.columnIndexOfXml));
+ } else {
+ inputSource = new InputSource(new StringReader(this.stringRep));
+ }
+
+ return new DOMSource(builder.parse(inputSource));
+ } catch (Throwable t) {
+ // FIXME - need to use factory method and set cause here
+
+ throw new SQLException(t);
+ }
+
+ } else if (clazz.equals(StreamSource.class)) {
+ Reader reader = null;
+
+ if (this.fromResultSet) {
+ reader = this.owningResultSet
+ .getCharacterStream(this.columnIndexOfXml);
+ } else {
+ reader = new StringReader(this.stringRep);
+ }
+
+ return new StreamSource(reader);
+ } else if (clazz.equals(StAXSource.class)) {
+ try {
+ Reader reader = null;
+
+ if (this.fromResultSet) {
+ reader = this.owningResultSet
+ .getCharacterStream(this.columnIndexOfXml);
+ } else {
+ reader = new StringReader(this.stringRep);
+ }
+
+ return new StAXSource(this.inputFactory
+ .createXMLStreamReader(reader));
+ } catch (XMLStreamException ex) {
+ SQLException sqlEx = SQLError.createSQLException(ex
+ .getMessage(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ // perhaps setCause here w/ ex?
+ throw sqlEx;
+ }
+ } else {
+ throw SQLError.createSQLException("XML Source of type \""
+ + clazz.toString() + "\" Not supported.",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+ }
+
+ /**
+ * Retrieves a stream that can be used to write the XML value that this
+ * SQLXML instance represents. The stream begins at position 0. The bytes of
+ * the stream are interpreted according to appendix F of the XML 1.0
+ * specification The behavior of this method is the same as
+ * ResultSet.updateBinaryStream() when the designated column of the
+ * ResultSet has a type java.sql.Types of SQLXML.
+ * <p>
+ * The SQL XML object becomes not writeable when this method is called and
+ * may also become not readable depending on implementation.
+ *
+ * @return a stream to which data can be written.
+ * @throws SQLException
+ * if there is an error processing the XML value. An exception
+ * is thrown if the state is not writable.
+ * @exception SQLFeatureNotSupportedException
+ * if the JDBC driver does not support this method
+ * @since 1.6
+ */
+ public synchronized OutputStream setBinaryStream() throws SQLException {
+ checkClosed();
+ checkWorkingWithResult();
+
+ this.workingWithResult = true;
+
+ return setBinaryStreamInternal();
+ }
+
+ private OutputStream setBinaryStreamInternal() throws SQLException {
+ WatchableOutputStream bytesOut = new WatchableOutputStream();
+ bytesOut.setWatcher(this);
+
+ return bytesOut;
+ }
+
+ /**
+ * Retrieves a stream to be used to write the XML value that this SQLXML
+ * instance represents. The format of this stream is defined by
+ * org.xml.sax.InputSource, where the characters in the stream represent the
+ * unicode code points for XML according to section 2 and appendix B of the
+ * XML 1.0 specification. Although an encoding declaration other than
+ * unicode may be present, the encoding of the stream is unicode. The
+ * behavior of this method is the same as ResultSet.updateCharacterStream()
+ * when the designated column of the ResultSet has a type java.sql.Types of
+ * SQLXML.
+ * <p>
+ * The SQL XML object becomes not writeable when this method is called and
+ * may also become not readable depending on implementation.
+ *
+ * @return a stream to which data can be written.
+ * @throws SQLException
+ * if there is an error processing the XML value. The getCause()
+ * method of the exception may provide a more detailed
+ * exception, for example, if the stream does not contain valid
+ * characters. An exception is thrown if the state is not
+ * writable.
+ * @exception SQLFeatureNotSupportedException
+ * if the JDBC driver does not support this method
+ * @since 1.6
+ */
+ public synchronized Writer setCharacterStream() throws SQLException {
+ checkClosed();
+ checkWorkingWithResult();
+
+ this.workingWithResult = true;
+
+ return setCharacterStreamInternal();
+ }
+
+ private Writer setCharacterStreamInternal() throws SQLException {
+ WatchableWriter writer = new WatchableWriter();
+ writer.setWatcher(this);
+
+ return writer;
+ }
+
+ /**
+ * Returns a Result for setting the XML value designated by this SQLXML
+ * instance.
+ * <p>
+ * The systemID of the Result is implementation dependent.
+ * <p>
+ * The SQL XML object becomes not writeable when this method is called and
+ * may also become not readable depending on implementation.
+ * <p>
+ * Note that SAX is a callback architecture and the returned SAXResult has a
+ * content handler assigned that will receive the SAX events based on the
+ * contents of the XML. Call the content handler with the contents of the
+ * XML document to assign the values.
+ *
+ * <pre>
+ * SAXResult saxResult = sqlxml.setResult(SAXResult.class);
+ * ContentHandler contentHandler = saxResult.getXMLReader().getContentHandler();
+ * contentHandler.startDocument();
+ * // set the XML elements and attributes into the result
+ * contentHandler.endDocument();
+ * </pre>
+ *
+ * @param resultClass
+ * The class of the result, or null. If resultClass is null, a
+ * vendor specific Result implementation will be returned. The
+ * following classes are supported at a minimum:
+ *
+ * <pre>
+ * javax.xml.transform.dom.DOMResult - returns a DOMResult
+ * javax.xml.transform.sax.SAXResult - returns a SAXResult
+ * javax.xml.transform.stax.StAXResult - returns a StAXResult
+ * javax.xml.transform.stream.StreamResult - returns a StreamResult
+ * </pre>
+ *
+ * @return Returns a Result for setting the XML value.
+ * @throws SQLException
+ * if there is an error processing the XML value or if this
+ * feature is not supported. The getCause() method of the
+ * exception may provide a more detailed exception, for example,
+ * if an XML parser exception occurs. An exception is thrown if
+ * the state is not writable.
+ * @exception SQLFeatureNotSupportedException
+ * if the JDBC driver does not support this method
+ * @since 1.6
+ */
+ public synchronized Result setResult(Class clazz) throws SQLException {
+ checkClosed();
+ checkWorkingWithResult();
+
+ this.workingWithResult = true;
+ this.asDOMResult = null;
+ this.stringRep = null;
+
+ if (clazz == null || clazz.equals(SAXResult.class)) {
+
+ // TODO: Need to flesh this out
+ return new SAXResult(null);
+ } else if (clazz.equals(DOMResult.class)) {
+
+ this.asDOMResult = new DOMResult();
+ return this.asDOMResult;
+
+ } else if (clazz.equals(StreamResult.class)) {
+ return new StreamResult(setCharacterStreamInternal());
+ } else if (clazz.equals(StAXResult.class)) {
+ try {
+ return new StAXResult(this.outputFactory.createXMLEventWriter(
+ setCharacterStreamInternal()));
+ } catch (XMLStreamException ex) {
+ SQLException sqlEx = SQLError.createSQLException(ex
+ .getMessage(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ // perhaps setCause here w/ ex?
+ throw sqlEx;
+ }
+ } else {
+ throw SQLError.createSQLException("XML Result of type \""
+ + clazz.toString() + "\" Not supported.",
+ SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+ }
+
+ /**
+ * @see com.mysql.jdbc.WriterWatcher#writerClosed(char[])
+ */
+ public void writerClosed(WatchableWriter out) {
+ try {
+ setString(out.toString());
+ } catch (SQLException sqlEx) {
+ // never actually thrown in our impl
+ }
+ }
+
+ public void streamClosed(WatchableOutputStream out) {
+
+ try {
+ // There's got to be an easier way to do this, but
+ // I don't feel like coding up Appendix F of the XML Spec
+ // myself, when there's a reusable way to do it, and we
+ // can warn folks away from BINARY xml streams that have
+ // to be parsed to determine the character encoding :P
+
+ String encoding = "UTF-8";
+
+ try {
+ ByteArrayInputStream bIn = new ByteArrayInputStream(out.toByteArray());
+ XMLStreamReader reader = this.inputFactory.createXMLStreamReader(bIn);
+
+ int eventType = 0;
+
+ while ((eventType = reader.next()) != XMLStreamReader.END_DOCUMENT) {
+ if (eventType == XMLStreamReader.START_DOCUMENT) {
+ String possibleEncoding = reader.getEncoding();
+
+ if (possibleEncoding != null) {
+ encoding = possibleEncoding;
+ }
+
+ break;
+ }
+ }
+ } catch (Throwable t) {
+ // ignore, dealt with later when the string can't be parsed
+ // into valid XML
+ }
+
+ setString(new String(out.toByteArray(), encoding));
+ } catch (UnsupportedEncodingException badEnc) {
+ throw new RuntimeException(badEnc);
+ } catch (SQLException sqlEx) {
+ // never actually thrown in our impl
+ }
+ }
+
+ protected synchronized String serializeAsString() throws SQLException {
+ checkClosed();
+ if (this.workingWithResult) {
+ // figure out what kind of result
+ if (this.stringRep != null) {
+ return this.stringRep;
+ }
+
+ if (this.asDOMResult != null) {
+ // serialize from DOM
+ }
+ }
+
+ return getString();
+ }
+}
Copied: trunk/connector-j/src/com/mysql/jdbc/JDBC4NClob.java (from rev 6339, trunk/connector-j/src/com/mysql/jdbc/NClob.java)
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/NClob.java 2007-03-06 23:55:30 UTC (rev 6339)
+++ trunk/connector-j/src/com/mysql/jdbc/JDBC4NClob.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,42 @@
+/*
+ Copyright (C) 2002-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc;
+
+
+/**
+ * Simplistic implementation of java.sql.NClob for MySQL Connector/J
+ *
+ * @author Tetsuro Ikeda
+ * @version $Id: NClob.java 4963 2006-02-21 13:28:14Z tikeda $
+ */
+public class JDBC4NClob extends Clob implements java.sql.NClob {
+
+ JDBC4NClob() {
+ super();
+ }
+
+ JDBC4NClob(String charDataInit) {
+ super(charDataInit);
+ }
+}
Added: trunk/connector-j/src/com/mysql/jdbc/JDBC4PreparedStatement.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/JDBC4PreparedStatement.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/JDBC4PreparedStatement.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,76 @@
+/*
+ Copyright (C) 2002-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.sql.NClob;
+import java.sql.RowId;
+import java.sql.SQLXML;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.mysql.jdbc.Connection;
+import com.mysql.jdbc.PreparedStatement;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
+
+public class JDBC4PreparedStatement extends PreparedStatement {
+
+ protected JDBC4PreparedStatement(Connection conn, String catalog) throws SQLException {
+ super(conn, catalog);
+ }
+
+ public void setRowId(int parameterIndex, RowId x) throws SQLException {
+ JDBC4PreparedStatementHelper.setRowId(this, parameterIndex, x);
+ }
+
+
+ /**
+ * JDBC 4.0 Set a NCLOB parameter.
+ *
+ * @param i
+ * the first parameter is 1, the second is 2, ...
+ * @param x
+ * an object representing a NCLOB
+ *
+ * @throws SQLException
+ * if a database error occurs
+ */
+ public void setNClob(int parameterIndex, NClob value) throws SQLException {
+ JDBC4PreparedStatementHelper.setNClob(this, parameterIndex, value);
+ }
+
+ public void setSQLXML(int parameterIndex, SQLXML xmlObject)
+ throws SQLException {
+ JDBC4PreparedStatementHelper.setSQLXML(this, parameterIndex, xmlObject);
+ }
+
+ public Object unwrap(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public void setPoolable(boolean poolable) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+}
Added: trunk/connector-j/src/com/mysql/jdbc/JDBC4PreparedStatementHelper.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/JDBC4PreparedStatementHelper.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/JDBC4PreparedStatementHelper.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,76 @@
+package com.mysql.jdbc;
+
+import java.io.Reader;
+import java.sql.NClob;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+import java.sql.Types;
+
+import com.mysql.jdbc.PreparedStatement;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
+
+public class JDBC4PreparedStatementHelper {
+ private JDBC4PreparedStatementHelper() {
+
+ }
+
+ static void setRowId(PreparedStatement pstmt, int parameterIndex, RowId x) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+
+ /**
+ * JDBC 4.0 Set a NCLOB parameter.
+ *
+ * @param i
+ * the first parameter is 1, the second is 2, ...
+ * @param x
+ * an object representing a NCLOB
+ *
+ * @throws SQLException
+ * if a database error occurs
+ */
+ static void setNClob(PreparedStatement pstmt, int parameterIndex, NClob value) throws SQLException {
+ if (value == null) {
+ pstmt.setNull(parameterIndex, java.sql.Types.NCLOB);
+ } else {
+ pstmt.setNCharacterStream(parameterIndex, value.getCharacterStream(), value.length());
+ }
+ }
+
+ static void setNClob(PreparedStatement pstmt, int parameterIndex, Reader reader) throws SQLException {
+ pstmt.setNCharacterStream(parameterIndex, reader);
+ }
+
+ /**
+ * JDBC 4.0 Set a NCLOB parameter.
+ *
+ * @param parameterIndex
+ * the first parameter is 1, the second is 2, ...
+ * @param reader
+ * the java reader which contains the UNICODE data
+ * @param length
+ * the number of characters in the stream
+ *
+ * @throws SQLException
+ * if a database error occurs
+ */
+ static void setNClob(PreparedStatement pstmt, int parameterIndex, Reader reader, long length)
+ throws SQLException {
+ if (reader == null) {
+ pstmt.setNull(parameterIndex, java.sql.Types.NCLOB);
+ } else {
+ pstmt.setNCharacterStream(parameterIndex, reader, length);
+ }
+ }
+
+ static void setSQLXML(PreparedStatement pstmt, int parameterIndex, SQLXML xmlObject)
+ throws SQLException {
+ if (xmlObject == null) {
+ pstmt.setNull(parameterIndex, Types.SQLXML);
+ } else {
+ pstmt.setCharacterStream(parameterIndex, xmlObject.getCharacterStream());
+ }
+ }
+}
Added: trunk/connector-j/src/com/mysql/jdbc/JDBC4ResultSet.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/JDBC4ResultSet.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/JDBC4ResultSet.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,472 @@
+/*
+ Copyright (C) 2002-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.sql.NClob;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+
+import com.mysql.jdbc.Connection;
+import com.mysql.jdbc.NotUpdatable;
+import com.mysql.jdbc.ResultSet;
+import com.mysql.jdbc.SQLError;
+import com.mysql.jdbc.Statement;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
+
+public class JDBC4ResultSet extends ResultSet {
+
+ public JDBC4ResultSet(long updateCount, long updateID, Connection conn, Statement creatorStmt) {
+ super(updateCount, updateID, conn, creatorStmt);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * JDBC 4.0
+ *
+ * <p>
+ * Get the value of a column in the current row as a java.io.Reader.
+ * </p>
+ *
+ * @param columnIndex
+ * the column to get the value from
+ *
+ * @return the value in the column as a java.io.Reader.
+ *
+ * @throws SQLException
+ * if an error occurs
+ */
+ public Reader getNCharacterStream(int columnIndex) throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException(
+ "Can not call getNCharacterStream() when field's charset isn't UTF-8");
+ }
+ return getCharacterStream(columnIndex);
+ }
+
+ /**
+ * JDBC 4.0
+ *
+ * <p>
+ * Get the value of a column in the current row as a java.io.Reader.
+ * </p>
+ *
+ * @param columnName
+ * the column name to retrieve the value from
+ *
+ * @return the value as a java.io.Reader
+ *
+ * @throws SQLException
+ * if an error occurs
+ */
+ public Reader getNCharacterStream(String columnName) throws SQLException {
+ return getNCharacterStream(findColumn(columnName));
+ }
+
+ /**
+ * JDBC 4.0 Get a NCLOB column.
+ *
+ * @param i
+ * the first column is 1, the second is 2, ...
+ *
+ * @return an object representing a NCLOB
+ *
+ * @throws SQLException
+ * if an error occurs
+ */
+ public NClob getNClob(int columnIndex) throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException(
+ "Can not call getNClob() when field's charset isn't UTF-8");
+ }
+ if (!this.isBinaryEncoded) {
+ String asString = getStringForNClob(columnIndex);
+
+ if (asString == null) {
+ return null;
+ }
+
+ return new com.mysql.jdbc.JDBC4NClob(asString);
+ }
+
+ return getNativeNClob(columnIndex);
+ }
+
+ /**
+ * JDBC 4.0 Get a NCLOB column.
+ *
+ * @param colName
+ * the column name
+ *
+ * @return an object representing a NCLOB
+ *
+ * @throws SQLException
+ * if an error occurs
+ */
+ public NClob getNClob(String columnName) throws SQLException {
+ return getNClob(findColumn(columnName));
+ }
+
+ /**
+ * JDBC 4.0 Get a NCLOB column.
+ *
+ * @param columnIndex
+ * the first column is 1, the second is 2, ...
+ *
+ * @return an object representing a NCLOB
+ *
+ * @throws SQLException
+ * if an error occurs
+ */
+ protected java.sql.NClob getNativeNClob(int columnIndex)
+ throws SQLException {
+ String stringVal = getStringForNClob(columnIndex);
+
+ if (stringVal == null) {
+ return null;
+ }
+
+ return getNClobFromString(stringVal, columnIndex);
+ }
+
+ private String getStringForNClob(int columnIndex) throws SQLException {
+ String asString = null;
+
+ String forcedEncoding = "UTF-8";
+
+ try {
+ byte[] asBytes = null;
+
+ if (!this.isBinaryEncoded) {
+ asBytes = getBytes(columnIndex);
+ } else {
+ asBytes = getNativeBytes(columnIndex, true);
+ }
+
+ if (asBytes != null) {
+ asString = new String(asBytes, forcedEncoding);
+ }
+ } catch (UnsupportedEncodingException uee) {
+ throw SQLError.createSQLException("Unsupported character encoding "
+ + forcedEncoding, SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
+ return asString;
+ }
+
+ private final java.sql.NClob getNClobFromString(String stringVal,
+ int columnIndex) throws SQLException {
+ return new com.mysql.jdbc.JDBC4NClob(stringVal);
+ }
+
+ /**
+ * JDBC 4.0
+ *
+ * Get the value of a column in the current row as a Java String
+ *
+ * @param columnIndex
+ * the first column is 1, the second is 2...
+ *
+ * @return the column value, null for SQL NULL
+ *
+ * @exception SQLException
+ * if a database access error occurs
+ */
+ public String getNString(int columnIndex) throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException(
+ "Can not call getNString() when field's charset isn't UTF-8");
+ }
+ return getString(columnIndex);
+ }
+
+ /**
+ * JDBC 4.0
+ *
+ * The following routines simply convert the columnName into a columnIndex
+ * and then call the appropriate routine above.
+ *
+ * @param columnName
+ * is the SQL name of the column
+ *
+ * @return the column value
+ *
+ * @exception SQLException
+ * if a database access error occurs
+ */
+ public String getNString(String columnName) throws SQLException {
+ return getNString(findColumn(columnName));
+ }
+
+ /**
+ * JDBC 4.0 Update a column with a character stream value. The updateXXX()
+ * methods are used to update column values in the current row, or the
+ * insert row. The updateXXX() methods do not update the underlying
+ * database, instead the updateRow() or insertRow() methods are called to
+ * update the database.
+ *
+ * @param columnIndex
+ * the first column is 1, the second is 2, ...
+ * @param x
+ * the new column value
+ * @param length
+ * the length of the stream
+ *
+ * @exception SQLException
+ * if a database-access error occurs
+ * @throws NotUpdatable
+ * DOCUMENT ME!
+ */
+ public void updateNCharacterStream(int columnIndex, Reader x, int length)
+ throws SQLException {
+ throw new NotUpdatable();
+ }
+
+ /**
+ * JDBC 4.0 Update a column with a character stream value. The updateXXX()
+ * methods are used to update column values in the current row, or the
+ * insert row. The updateXXX() methods do not update the underlying
+ * database, instead the updateRow() or insertRow() methods are called to
+ * update the database.
+ *
+ * @param columnName
+ * the name of the column
+ * @param reader
+ * the stream to update the column with
+ * @param length
+ * of the stream
+ *
+ * @throws SQLException
+ * if a database-access error occurs
+ */
+ public void updateNCharacterStream(String columnName, Reader reader,
+ int length) throws SQLException {
+ updateNCharacterStream(findColumn(columnName), reader, length);
+ }
+
+ /**
+ * @see ResultSet#updateNClob(String, NClob)
+ */
+ public void updateNClob(String columnName, NClob nClob) throws SQLException {
+ updateNClob(findColumn(columnName), nClob);
+ }
+
+ public void updateRowId(int columnIndex, RowId x) throws SQLException {
+ throw new NotUpdatable();
+ }
+
+ public void updateRowId(String columnName, RowId x) throws SQLException {
+ updateRowId(findColumn(columnName), x);
+ }
+
+ public int getHoldability() throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public RowId getRowId(int columnIndex) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public RowId getRowId(String columnLabel) throws SQLException {
+ return getRowId(findColumn(columnLabel));
+ }
+
+ public SQLXML getSQLXML(int columnIndex) throws SQLException {
+ return new JDBC4MysqlSQLXML(this, columnIndex);
+ }
+
+ public SQLXML getSQLXML(String columnLabel) throws SQLException {
+ return getSQLXML(findColumn(columnLabel));
+ }
+
+ public synchronized boolean isClosed() throws SQLException {
+ return this.isClosed;
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
+ updateAsciiStream(findColumn(columnLabel), x);
+
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
+ updateAsciiStream(findColumn(columnLabel), x, length);
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
+ updateBinaryStream(findColumn(columnLabel), x);
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
+ updateBinaryStream(findColumn(columnLabel), x, length);
+ }
+
+ public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
+ throw new NotUpdatable();
+ }
+
+ public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException {
+ updateBlob(findColumn(columnLabel), inputStream);
+ }
+
+ public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException {
+ updateBlob(findColumn(columnLabel), inputStream, length);
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException {
+ updateCharacterStream(findColumn(columnLabel), reader);
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
+ updateCharacterStream(findColumn(columnLabel), reader, length);
+ }
+
+ public void updateClob(int columnIndex, Reader reader) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateClob(String columnLabel, Reader reader) throws SQLException {
+ updateClob(findColumn(columnLabel), reader);
+ }
+
+ public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateClob(String columnLabel, Reader reader, long length) throws SQLException {
+ updateClob(findColumn(columnLabel), reader, length);
+ }
+
+ public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException {
+ updateNCharacterStream(findColumn(columnLabel), reader);
+
+ }
+
+ public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
+ updateNCharacterStream(findColumn(columnLabel), reader, length);
+ }
+
+ public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateNClob(int columnIndex, Reader reader) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateNClob(String columnLabel, Reader reader) throws SQLException {
+ updateNClob(findColumn(columnLabel), reader);
+
+ }
+
+ public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
+ throw new NotUpdatable();
+ }
+
+ public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException {
+ updateNClob(findColumn(columnLabel), reader, length);
+ }
+
+ public void updateNString(int columnIndex, String nString) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateNString(String columnLabel, String nString) throws SQLException {
+ updateNString(findColumn(columnLabel), nString);
+ }
+
+ public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException {
+ updateSQLXML(findColumn(columnLabel), xmlObject);
+
+ }
+
+ public boolean isWrapperFor(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public Object unwrap(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+}
Added: trunk/connector-j/src/com/mysql/jdbc/JDBC4ServerPreparedStatement.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/JDBC4ServerPreparedStatement.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/JDBC4ServerPreparedStatement.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,140 @@
+/*
+ Copyright (C) 2002-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc;
+
+import java.io.Reader;
+import java.sql.NClob;
+import java.sql.SQLXML;
+import java.sql.SQLException;
+
+import com.mysql.jdbc.Connection;
+import com.mysql.jdbc.MysqlDefs;
+import com.mysql.jdbc.SQLError;
+import com.mysql.jdbc.ServerPreparedStatement;
+import com.mysql.jdbc.ServerPreparedStatement.BindValue;
+
+public class JDBC4ServerPreparedStatement extends ServerPreparedStatement {
+
+ public JDBC4ServerPreparedStatement(Connection conn, String sql, String catalog, int resultSetType, int resultSetConcurrency) throws SQLException {
+ super(conn, sql, catalog, resultSetType, resultSetConcurrency);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader,
+ * long)
+ */
+ public void setNCharacterStream(int parameterIndex, Reader reader, long length)
+ throws SQLException {
+ // can't take if characterEncoding isn't utf8
+ if (!this.charEncoding.equalsIgnoreCase("UTF-8")
+ && !this.charEncoding.equalsIgnoreCase("utf8")) {
+ throw SQLError.createSQLException(
+ "Can not call setNCharacterStream() when connection character set isn't UTF-8");
+ }
+
+ checkClosed();
+
+ if (reader == null) {
+ setNull(parameterIndex, java.sql.Types.BINARY);
+ } else {
+ BindValue binding = getBinding(parameterIndex, true);
+ setType(binding, MysqlDefs.FIELD_TYPE_BLOB);
+
+ binding.value = reader;
+ binding.isNull = false;
+ binding.isLongData = true;
+
+ if (this.connection.getUseStreamLengthsInPrepStmts()) {
+ binding.bindLength = length;
+ } else {
+ binding.bindLength = -1;
+ }
+ }
+ }
+
+ /**
+ * @see java.sql.PreparedStatement#setNClob(int, java.sql.NClob)
+ */
+ public void setNClob(int parameterIndex, NClob x) throws SQLException {
+ setNClob(parameterIndex, x.getCharacterStream(),
+ this.connection.getUseStreamLengthsInPrepStmts()
+ ? x.length() : -1);
+ }
+
+ /**
+ * JDBC 4.0 Set a NCLOB parameter.
+ *
+ * @param parameterIndex
+ * the first parameter is 1, the second is 2, ...
+ * @param reader
+ * the java reader which contains the UNICODE data
+ * @param length
+ * the number of characters in the stream
+ *
+ * @throws SQLException
+ * if a database error occurs
+ */
+ public void setNClob(int parameterIndex, Reader reader, long length)
+ throws SQLException {
+ // can't take if characterEncoding isn't utf8
+ if (!this.charEncoding.equalsIgnoreCase("UTF-8")
+ && !this.charEncoding.equalsIgnoreCase("utf8")) {
+ throw SQLError.createSQLException(
+ "Can not call setNClob() when connection character set isn't UTF-8");
+ }
+
+ checkClosed();
+
+ if (reader == null) {
+ setNull(parameterIndex, java.sql.Types.NCLOB);
+ } else {
+ BindValue binding = getBinding(parameterIndex, true);
+ setType(binding, MysqlDefs.FIELD_TYPE_BLOB);
+
+ binding.value = reader;
+ binding.isNull = false;
+ binding.isLongData = true;
+
+ if (this.connection.getUseStreamLengthsInPrepStmts()) {
+ binding.bindLength = length;
+ } else {
+ binding.bindLength = -1;
+ }
+ }
+ }
+
+ /**
+ * @see java.sql.PreparedStatement#setNString(int, java.lang.String)
+ */
+ public void setNString(int parameterIndex, String x) throws SQLException {
+ if (this.charEncoding.equalsIgnoreCase("UTF-8")
+ || this.charEncoding.equalsIgnoreCase("utf8")) {
+ setString(parameterIndex, x);
+ } else {
+ throw SQLError.createSQLException(
+ "Can not call setNString() when connection character set isn't UTF-8");
+ }
+ }
+}
Added: trunk/connector-j/src/com/mysql/jdbc/JDBC4UpdatableResultSet.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/JDBC4UpdatableResultSet.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/JDBC4UpdatableResultSet.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,494 @@
+/*
+ Copyright (C) 2002-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+package com.mysql.jdbc;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.sql.NClob;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+
+import com.mysql.jdbc.Connection;
+import com.mysql.jdbc.Field;
+import com.mysql.jdbc.NotUpdatable;
+import com.mysql.jdbc.RowData;
+import com.mysql.jdbc.Statement;
+import com.mysql.jdbc.StringUtils;
+import com.mysql.jdbc.UpdatableResultSet;
+
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
+
+public class JDBC4UpdatableResultSet extends UpdatableResultSet {
+ public JDBC4UpdatableResultSet(String catalog, Field[] fields, RowData tuples, Connection conn, Statement creatorStmt) throws SQLException {
+ super(catalog, fields, tuples, conn, creatorStmt);
+ // TODO Auto-generated constructor stub
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
+ throw new NotUpdatable();
+ }
+
+ public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+
+ public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateClob(int columnIndex, Reader reader) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+ updateNCharacterStream(columnIndex, x, (int) length);
+
+ }
+
+
+ public void updateNClob(int columnIndex, Reader reader) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+ public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
+ throw new NotUpdatable();
+ }
+
+ public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
+ throw new NotUpdatable();
+
+ }
+
+
+
+ public void updateRowId(int columnIndex, RowId x) throws SQLException {
+ throw new NotUpdatable();
+ }
+
+ /**
+ * JDBC 4.0 Update a column with a character stream value. The updateXXX()
+ * methods are used to update column values in the current row, or the
+ * insert row. The updateXXX() methods do not update the underlying
+ * database, instead the updateRow() or insertRow() methods are called to
+ * update the database.
+ *
+ * @param columnIndex
+ * the first column is 1, the second is 2, ...
+ * @param x
+ * the new column value
+ * @param length
+ * the length of the stream
+ *
+ * @exception SQLException
+ * if a database-access error occurs
+ */
+ public synchronized void updateNCharacterStream(int columnIndex,
+ java.io.Reader x, int length) throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException(
+ "Can not call updateNCharacterStream() when field's character set isn't UTF-8");
+ }
+
+ if (!this.onInsertRow) {
+ if (!this.doingUpdates) {
+ this.doingUpdates = true;
+ syncUpdate();
+ }
+
+ ((com.mysql.jdbc.JDBC4PreparedStatement)this.updater).setNCharacterStream(columnIndex, x, length);
+ } else {
+ ((com.mysql.jdbc.JDBC4PreparedStatement)this.inserter).setNCharacterStream(columnIndex, x, length);
+
+ if (x == null) {
+ this.thisRow[columnIndex - 1] = null;
+ } else {
+ this.thisRow[columnIndex - 1] = STREAM_DATA_MARKER;
+ }
+ }
+ }
+
+ /**
+ * JDBC 4.0 Update a column with a character stream value. The updateXXX()
+ * methods are used to update column values in the current row, or the
+ * insert row. The updateXXX() methods do not update the underlying
+ * database, instead the updateRow() or insertRow() methods are called to
+ * update the database.
+ *
+ * @param columnName
+ * the name of the column
+ * @param reader
+ * the new column value
+ * @param length
+ * of the stream
+ *
+ * @exception SQLException
+ * if a database-access error occurs
+ */
+ public synchronized void updateNCharacterStream(String columnName,
+ java.io.Reader reader, int length) throws SQLException {
+ updateNCharacterStream(findColumn(columnName), reader, length);
+ }
+
+ /**
+ * @see ResultSet#updateNClob(int, NClob)
+ */
+ public void updateNClob(int columnIndex, java.sql.NClob nClob)
+ throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException("Can not call updateNClob() when field's character set isn't UTF-8");
+ }
+
+ if (nClob == null) {
+ updateNull(columnIndex);
+ } else {
+ updateNCharacterStream(columnIndex, nClob.getCharacterStream(),
+ (int) nClob.length());
+ }
+ }
+
+ /**
+ * @see ResultSet#updateClob(int, Clob)
+ */
+ public void updateNClob(String columnName, java.sql.NClob nClob)
+ throws SQLException {
+ updateNClob(findColumn(columnName), nClob);
+ }
+
+ /**
+ * JDBC 4.0 Update a column with NATIONAL CHARACTER. The updateXXX() methods are
+ * used to update column values in the current row, or the insert row. The
+ * updateXXX() methods do not update the underlying database, instead the
+ * updateRow() or insertRow() methods are called to update the database.
+ *
+ * @param columnIndex
+ * the first column is 1, the second is 2, ...
+ * @param x
+ * the new column value
+ *
+ * @exception SQLException
+ * if a database-access error occurs
+ */
+ public synchronized void updateNString(int columnIndex, String x)
+ throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException("Can not call updateNString() when field's character set isn't UTF-8");
+ }
+
+ if (!this.onInsertRow) {
+ if (!this.doingUpdates) {
+ this.doingUpdates = true;
+ syncUpdate();
+ }
+
+ ((com.mysql.jdbc.JDBC4PreparedStatement)this.updater).setNString(columnIndex, x);
+ } else {
+ ((com.mysql.jdbc.JDBC4PreparedStatement)this.inserter).setNString(columnIndex, x);
+
+ if (x == null) {
+ this.thisRow[columnIndex - 1] = null;
+ } else {
+ this.thisRow[columnIndex - 1] = StringUtils.getBytes(x,
+ this.charConverter, fieldEncoding,
+ this.connection.getServerCharacterEncoding(),
+ this.connection.parserKnowsUnicode());
+ }
+ }
+ }
+
+ /**
+ * JDBC 4.0 Update a column with NATIONAL CHARACTER. The updateXXX() methods are
+ * used to update column values in the current row, or the insert row. The
+ * updateXXX() methods do not update the underlying database, instead the
+ * updateRow() or insertRow() methods are called to update the database.
+ *
+ * @param columnName
+ * the name of the column
+ * @param x
+ * the new column value
+ *
+ * @exception SQLException
+ * if a database-access error occurs
+ */
+ public synchronized void updateNString(String columnName, String x)
+ throws SQLException {
+ updateNString(findColumn(columnName), x);
+ }
+
+ public int getHoldability() throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ /**
+ * JDBC 4.0 Get a NCLOB column.
+ *
+ * @param columnIndex
+ * the first column is 1, the second is 2, ...
+ *
+ * @return an object representing a NCLOB
+ *
+ * @throws SQLException
+ * if an error occurs
+ */
+ protected java.sql.NClob getNativeNClob(int columnIndex)
+ throws SQLException {
+ String stringVal = getStringForNClob(columnIndex);
+
+ if (stringVal == null) {
+ return null;
+ }
+
+ return getNClobFromString(stringVal, columnIndex);
+ }
+
+ /**
+ * JDBC 4.0
+ *
+ * <p>
+ * Get the value of a column in the current row as a java.io.Reader.
+ * </p>
+ *
+ * @param columnIndex
+ * the column to get the value from
+ *
+ * @return the value in the column as a java.io.Reader.
+ *
+ * @throws SQLException
+ * if an error occurs
+ */
+ public Reader getNCharacterStream(int columnIndex) throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException(
+ "Can not call getNCharacterStream() when field's charset isn't UTF-8");
+ }
+ return getCharacterStream(columnIndex);
+ }
+
+ /**
+ * JDBC 4.0
+ *
+ * <p>
+ * Get the value of a column in the current row as a java.io.Reader.
+ * </p>
+ *
+ * @param columnName
+ * the column name to retrieve the value from
+ *
+ * @return the value as a java.io.Reader
+ *
+ * @throws SQLException
+ * if an error occurs
+ */
+ public Reader getNCharacterStream(String columnName) throws SQLException {
+ return getNCharacterStream(findColumn(columnName));
+ }
+
+ /**
+ * JDBC 4.0 Get a NCLOB column.
+ *
+ * @param i
+ * the first column is 1, the second is 2, ...
+ *
+ * @return an object representing a NCLOB
+ *
+ * @throws SQLException
+ * if an error occurs
+ */
+ public NClob getNClob(int columnIndex) throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException(
+ "Can not call getNClob() when field's charset isn't UTF-8");
+ }
+ if (!this.isBinaryEncoded) {
+ String asString = getStringForNClob(columnIndex);
+
+ if (asString == null) {
+ return null;
+ }
+
+ return new com.mysql.jdbc.JDBC4NClob(asString);
+ }
+
+ return getNativeNClob(columnIndex);
+ }
+
+ /**
+ * JDBC 4.0 Get a NCLOB column.
+ *
+ * @param colName
+ * the column name
+ *
+ * @return an object representing a NCLOB
+ *
+ * @throws SQLException
+ * if an error occurs
+ */
+ public NClob getNClob(String columnName) throws SQLException {
+ return getNClob(findColumn(columnName));
+ }
+
+ private final java.sql.NClob getNClobFromString(String stringVal,
+ int columnIndex) throws SQLException {
+ return new com.mysql.jdbc.JDBC4NClob(stringVal);
+ }
+
+ /**
+ * JDBC 4.0
+ *
+ * Get the value of a column in the current row as a Java String
+ *
+ * @param columnIndex
+ * the first column is 1, the second is 2...
+ *
+ * @return the column value, null for SQL NULL
+ *
+ * @exception SQLException
+ * if a database access error occurs
+ */
+ public String getNString(int columnIndex) throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException(
+ "Can not call getNString() when field's charset isn't UTF-8");
+ }
+ return getString(columnIndex);
+ }
+
+ /**
+ * JDBC 4.0
+ *
+ * The following routines simply convert the columnName into a columnIndex
+ * and then call the appropriate routine above.
+ *
+ * @param columnName
+ * is the SQL name of the column
+ *
+ * @return the column value
+ *
+ * @exception SQLException
+ * if a database access error occurs
+ */
+ public String getNString(String columnName) throws SQLException {
+ return getNString(findColumn(columnName));
+ }
+
+ public RowId getRowId(int columnIndex) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public RowId getRowId(String columnLabel) throws SQLException {
+ return getRowId(findColumn(columnLabel));
+ }
+
+ public SQLXML getSQLXML(int columnIndex) throws SQLException {
+ return new JDBC4MysqlSQLXML(this, columnIndex);
+ }
+
+ public SQLXML getSQLXML(String columnLabel) throws SQLException {
+ return getSQLXML(findColumn(columnLabel));
+ }
+
+ private String getStringForNClob(int columnIndex) throws SQLException {
+ String asString = null;
+
+ String forcedEncoding = "UTF-8";
+
+ try {
+ byte[] asBytes = null;
+
+ if (!this.isBinaryEncoded) {
+ asBytes = getBytes(columnIndex);
+ } else {
+ asBytes = getNativeBytes(columnIndex, true);
+ }
+
+ if (asBytes != null) {
+ asString = new String(asBytes, forcedEncoding);
+ }
+ } catch (UnsupportedEncodingException uee) {
+ throw SQLError.createSQLException("Unsupported character encoding "
+ + forcedEncoding, SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+ }
+
+ return asString;
+ }
+
+ public synchronized boolean isClosed() throws SQLException {
+ return this.isClosed;
+ }
+
+ public boolean isWrapperFor(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+
+ public Object unwrap(Class arg0) throws SQLException {
+ throw new NotYetImplementedException();
+ }
+}
Modified: trunk/connector-j/src/com/mysql/jdbc/MysqlParameterMetadata.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/MysqlParameterMetadata.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/MysqlParameterMetadata.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -27,7 +27,7 @@
import java.sql.SQLException;
import java.sql.Types;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
public class MysqlParameterMetadata implements ParameterMetaData {
boolean returnSimpleMetadata = false;
@@ -165,10 +165,10 @@
}
public boolean isWrapperFor(Class arg0) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
public Object unwrap(Class arg0) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
}
Deleted: trunk/connector-j/src/com/mysql/jdbc/MysqlSQLXML.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/MysqlSQLXML.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/MysqlSQLXML.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -1,565 +0,0 @@
-/*
- Copyright (C) 2002-2007 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of version 2 of the GNU General Public License as
- published by the Free Software Foundation.
-
- There are special exceptions to the terms and conditions of the GPL
- as it is applied to this software. View the full text of the
- exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
- software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- */
-
-package com.mysql.jdbc;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
-import java.sql.SQLXML;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stax.StAXResult;
-import javax.xml.transform.stax.StAXSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
-
-public class MysqlSQLXML implements SQLXML, WriterWatcher, OutputStreamWatcher {
-
- private XMLInputFactory inputFactory;
-
- private XMLOutputFactory outputFactory;
-
- private String stringRep;
-
- private ResultSet owningResultSet;
-
- private int columnIndexOfXml;
-
- private boolean fromResultSet;
-
- private boolean isClosed = false;
-
- private boolean workingWithResult;
-
- private DOMResult asDOMResult;
-
- protected MysqlSQLXML(ResultSet owner, int index) {
- this.owningResultSet = owner;
- this.columnIndexOfXml = index;
- this.fromResultSet = true;
- }
-
- protected MysqlSQLXML() {
- this.fromResultSet = false;
- }
-
- public synchronized void free() throws SQLException {
- this.inputFactory = null;
- this.outputFactory = null;
- this.owningResultSet = null;
- this.workingWithResult = false;
- this.isClosed = true;
-
- }
-
- public synchronized String getString() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- if (this.fromResultSet) {
- return this.owningResultSet.getString(this.columnIndexOfXml);
- }
-
- return this.stringRep;
- }
-
- private synchronized void checkClosed() throws SQLException {
- if (this.isClosed) {
- throw SQLError.createSQLException("SQLXMLInstance has been free()d");
- }
- }
-
- private synchronized void checkWorkingWithResult() throws SQLException {
- if (this.workingWithResult) {
- throw SQLError.createSQLException("Can't perform requested operation after getResult() has been called to write XML data",
- SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
-
- /**
- * Sets the XML value designated by this SQLXML instance to the given String
- * representation. The format of this String is defined by
- * org.xml.sax.InputSource, where the characters in the stream represent the
- * unicode code points for XML according to section 2 and appendix B of the
- * XML 1.0 specification. Although an encoding declaration other than
- * unicode may be present, the encoding of the String is unicode. The
- * behavior of this method is the same as ResultSet.updateString() when the
- * designated column of the ResultSet has a type java.sql.Types of SQLXML.
- * <p>
- * The SQL XML object becomes not writeable when this method is called and
- * may also become not readable depending on implementation.
- *
- * @param value
- * the XML value
- * @throws SQLException
- * if there is an error processing the XML value. The getCause()
- * method of the exception may provide a more detailed
- * exception, for example, if the stream does not contain valid
- * characters. An exception is thrown if the state is not
- * writable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
-
- public synchronized void setString(String str) throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- this.stringRep = str;
- this.fromResultSet = false;
- }
-
- public synchronized boolean isEmpty() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- if (!this.fromResultSet) {
- return this.stringRep == null || this.stringRep.length() == 0;
- }
-
- return false;
- }
-
- public synchronized InputStream getBinaryStream() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- return this.owningResultSet.getBinaryStream(this.columnIndexOfXml);
- }
-
- /**
- * Retrieves the XML value designated by this SQLXML instance as a
- * java.io.Reader object. The format of this stream is defined by
- * org.xml.sax.InputSource, where the characters in the stream represent the
- * unicode code points for XML according to section 2 and appendix B of the
- * XML 1.0 specification. Although an encoding declaration other than
- * unicode may be present, the encoding of the stream is unicode. The
- * behavior of this method is the same as ResultSet.getCharacterStream()
- * when the designated column of the ResultSet has a type java.sql.Types of
- * SQLXML.
- * <p>
- * The SQL XML object becomes not readable when this method is called and
- * may also become not writable depending on implementation.
- *
- * @return a stream containing the XML data.
- * @throws SQLException
- * if there is an error processing the XML value. The getCause()
- * method of the exception may provide a more detailed
- * exception, for example, if the stream does not contain valid
- * characters. An exception is thrown if the state is not
- * readable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
- public synchronized Reader getCharacterStream() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- return this.owningResultSet.getCharacterStream(this.columnIndexOfXml);
- }
-
- /**
- * Returns a Source for reading the XML value designated by this SQLXML
- * instance. Sources are used as inputs to XML parsers and XSLT
- * transformers.
- * <p>
- * Sources for XML parsers will have namespace processing on by default. The
- * systemID of the Source is implementation dependent.
- * <p>
- * The SQL XML object becomes not readable when this method is called and
- * may also become not writable depending on implementation.
- * <p>
- * Note that SAX is a callback architecture, so a returned SAXSource should
- * then be set with a content handler that will receive the SAX events from
- * parsing. The content handler will receive callbacks based on the contents
- * of the XML.
- *
- * <pre>
- * SAXSource saxSource = sqlxml.getSource(SAXSource.class);
- * XMLReader xmlReader = saxSource.getXMLReader();
- * xmlReader.setContentHandler(myHandler);
- * xmlReader.parse(saxSource.getInputSource());
- * </pre>
- *
- * @param sourceClass
- * The class of the source, or null. If the class is null, a
- * vendor specifc Source implementation will be returned. The
- * following classes are supported at a minimum:
- *
- * (MySQL returns a SAXSource if sourceClass == null)
- *
- * <pre>
- * javax.xml.transform.dom.DOMSource - returns a DOMSource
- * javax.xml.transform.sax.SAXSource - returns a SAXSource
- * javax.xml.transform.stax.StAXSource - returns a StAXSource
- * javax.xml.transform.stream.StreamSource - returns a StreamSource
- * </pre>
- *
- * @return a Source for reading the XML value.
- * @throws SQLException
- * if there is an error processing the XML value or if this
- * feature is not supported. The getCause() method of the
- * exception may provide a more detailed exception, for example,
- * if an XML parser exception occurs. An exception is thrown if
- * the state is not readable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
- public synchronized Source getSource(Class clazz) throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- // Note that we try and use streams here wherever possible
- // for the day that the server actually supports streaming
- // from server -> client (futureproofing)
-
- if (clazz == null || clazz.equals(SAXSource.class)) {
-
- InputSource inputSource = null;
-
- if (this.fromResultSet) {
- inputSource = new InputSource(
- this.owningResultSet
- .getCharacterStream(this.columnIndexOfXml));
- } else {
- inputSource = new InputSource(new StringReader(this.stringRep));
- }
-
- return new SAXSource(inputSource);
- } else if (clazz.equals(DOMSource.class)) {
- try {
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory
- .newInstance();
- builderFactory.setNamespaceAware(true);
- DocumentBuilder builder = builderFactory.newDocumentBuilder();
-
- InputSource inputSource = null;
-
- if (this.fromResultSet) {
- inputSource = new InputSource(
- this.owningResultSet
- .getCharacterStream(this.columnIndexOfXml));
- } else {
- inputSource = new InputSource(new StringReader(this.stringRep));
- }
-
- return new DOMSource(builder.parse(inputSource));
- } catch (Throwable t) {
- // FIXME - need to use factory method and set cause here
-
- throw new SQLException(t);
- }
-
- } else if (clazz.equals(StreamSource.class)) {
- Reader reader = null;
-
- if (this.fromResultSet) {
- reader = this.owningResultSet
- .getCharacterStream(this.columnIndexOfXml);
- } else {
- reader = new StringReader(this.stringRep);
- }
-
- return new StreamSource(reader);
- } else if (clazz.equals(StAXSource.class)) {
- try {
- Reader reader = null;
-
- if (this.fromResultSet) {
- reader = this.owningResultSet
- .getCharacterStream(this.columnIndexOfXml);
- } else {
- reader = new StringReader(this.stringRep);
- }
-
- return new StAXSource(this.inputFactory
- .createXMLStreamReader(reader));
- } catch (XMLStreamException ex) {
- SQLException sqlEx = SQLError.createSQLException(ex
- .getMessage(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- // perhaps setCause here w/ ex?
- throw sqlEx;
- }
- } else {
- throw SQLError.createSQLException("XML Source of type \""
- + clazz.toString() + "\" Not supported.",
- SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
-
- /**
- * Retrieves a stream that can be used to write the XML value that this
- * SQLXML instance represents. The stream begins at position 0. The bytes of
- * the stream are interpreted according to appendix F of the XML 1.0
- * specification The behavior of this method is the same as
- * ResultSet.updateBinaryStream() when the designated column of the
- * ResultSet has a type java.sql.Types of SQLXML.
- * <p>
- * The SQL XML object becomes not writeable when this method is called and
- * may also become not readable depending on implementation.
- *
- * @return a stream to which data can be written.
- * @throws SQLException
- * if there is an error processing the XML value. An exception
- * is thrown if the state is not writable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
- public synchronized OutputStream setBinaryStream() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- this.workingWithResult = true;
-
- return setBinaryStreamInternal();
- }
-
- private OutputStream setBinaryStreamInternal() throws SQLException {
- WatchableOutputStream bytesOut = new WatchableOutputStream();
- bytesOut.setWatcher(this);
-
- return bytesOut;
- }
-
- /**
- * Retrieves a stream to be used to write the XML value that this SQLXML
- * instance represents. The format of this stream is defined by
- * org.xml.sax.InputSource, where the characters in the stream represent the
- * unicode code points for XML according to section 2 and appendix B of the
- * XML 1.0 specification. Although an encoding declaration other than
- * unicode may be present, the encoding of the stream is unicode. The
- * behavior of this method is the same as ResultSet.updateCharacterStream()
- * when the designated column of the ResultSet has a type java.sql.Types of
- * SQLXML.
- * <p>
- * The SQL XML object becomes not writeable when this method is called and
- * may also become not readable depending on implementation.
- *
- * @return a stream to which data can be written.
- * @throws SQLException
- * if there is an error processing the XML value. The getCause()
- * method of the exception may provide a more detailed
- * exception, for example, if the stream does not contain valid
- * characters. An exception is thrown if the state is not
- * writable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
- public synchronized Writer setCharacterStream() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- this.workingWithResult = true;
-
- return setCharacterStreamInternal();
- }
-
- private Writer setCharacterStreamInternal() throws SQLException {
- WatchableWriter writer = new WatchableWriter();
- writer.setWatcher(this);
-
- return writer;
- }
-
- /**
- * Returns a Result for setting the XML value designated by this SQLXML
- * instance.
- * <p>
- * The systemID of the Result is implementation dependent.
- * <p>
- * The SQL XML object becomes not writeable when this method is called and
- * may also become not readable depending on implementation.
- * <p>
- * Note that SAX is a callback architecture and the returned SAXResult has a
- * content handler assigned that will receive the SAX events based on the
- * contents of the XML. Call the content handler with the contents of the
- * XML document to assign the values.
- *
- * <pre>
- * SAXResult saxResult = sqlxml.setResult(SAXResult.class);
- * ContentHandler contentHandler = saxResult.getXMLReader().getContentHandler();
- * contentHandler.startDocument();
- * // set the XML elements and attributes into the result
- * contentHandler.endDocument();
- * </pre>
- *
- * @param resultClass
- * The class of the result, or null. If resultClass is null, a
- * vendor specific Result implementation will be returned. The
- * following classes are supported at a minimum:
- *
- * <pre>
- * javax.xml.transform.dom.DOMResult - returns a DOMResult
- * javax.xml.transform.sax.SAXResult - returns a SAXResult
- * javax.xml.transform.stax.StAXResult - returns a StAXResult
- * javax.xml.transform.stream.StreamResult - returns a StreamResult
- * </pre>
- *
- * @return Returns a Result for setting the XML value.
- * @throws SQLException
- * if there is an error processing the XML value or if this
- * feature is not supported. The getCause() method of the
- * exception may provide a more detailed exception, for example,
- * if an XML parser exception occurs. An exception is thrown if
- * the state is not writable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
- public synchronized Result setResult(Class clazz) throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- this.workingWithResult = true;
- this.asDOMResult = null;
- this.stringRep = null;
-
- if (clazz == null || clazz.equals(SAXResult.class)) {
-
- // TODO: Need to flesh this out
- return new SAXResult(null);
- } else if (clazz.equals(DOMResult.class)) {
-
- this.asDOMResult = new DOMResult();
- return this.asDOMResult;
-
- } else if (clazz.equals(StreamResult.class)) {
- return new StreamResult(setCharacterStreamInternal());
- } else if (clazz.equals(StAXResult.class)) {
- try {
- return new StAXResult(this.outputFactory.createXMLEventWriter(
- setCharacterStreamInternal()));
- } catch (XMLStreamException ex) {
- SQLException sqlEx = SQLError.createSQLException(ex
- .getMessage(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- // perhaps setCause here w/ ex?
- throw sqlEx;
- }
- } else {
- throw SQLError.createSQLException("XML Result of type \""
- + clazz.toString() + "\" Not supported.",
- SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
-
- /**
- * @see com.mysql.jdbc.WriterWatcher#writerClosed(char[])
- */
- public void writerClosed(WatchableWriter out) {
- try {
- setString(out.toString());
- } catch (SQLException sqlEx) {
- // never actually thrown in our impl
- }
- }
-
- public void streamClosed(WatchableOutputStream out) {
-
- try {
- // There's got to be an easier way to do this, but
- // I don't feel like coding up Appendix F of the XML Spec
- // myself, when there's a reusable way to do it, and we
- // can warn folks away from BINARY xml streams that have
- // to be parsed to determine the character encoding :P
-
- String encoding = "UTF-8";
-
- try {
- ByteArrayInputStream bIn = new ByteArrayInputStream(out.toByteArray());
- XMLStreamReader reader = this.inputFactory.createXMLStreamReader(bIn);
-
- int eventType = 0;
-
- while ((eventType = reader.next()) != XMLStreamReader.END_DOCUMENT) {
- if (eventType == XMLStreamReader.START_DOCUMENT) {
- String possibleEncoding = reader.getEncoding();
-
- if (possibleEncoding != null) {
- encoding = possibleEncoding;
- }
-
- break;
- }
- }
- } catch (Throwable t) {
- // ignore, dealt with later when the string can't be parsed
- // into valid XML
- }
-
- setString(new String(out.toByteArray(), encoding));
- } catch (UnsupportedEncodingException badEnc) {
- throw new RuntimeException(badEnc);
- } catch (SQLException sqlEx) {
- // never actually thrown in our impl
- }
- }
-
- protected synchronized String serializeAsString() throws SQLException {
- checkClosed();
- if (this.workingWithResult) {
- // figure out what kind of result
- if (this.stringRep != null) {
- return this.stringRep;
- }
-
- if (this.asDOMResult != null) {
- // serialize from DOM
- }
- }
-
- return getString();
- }
-}
Deleted: trunk/connector-j/src/com/mysql/jdbc/NClob.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/NClob.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/NClob.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -1,42 +0,0 @@
-/*
- Copyright (C) 2002-2007 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of version 2 of the GNU General Public License as
- published by the Free Software Foundation.
-
- There are special exceptions to the terms and conditions of the GPL
- as it is applied to this software. View the full text of the
- exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
- software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- */
-
-package com.mysql.jdbc;
-
-
-/**
- * Simplistic implementation of java.sql.NClob for MySQL Connector/J
- *
- * @author Tetsuro Ikeda
- * @version $Id: NClob.java 4963 2006-02-21 13:28:14Z tikeda $
- */
-public class NClob extends Clob implements java.sql.NClob {
-
- NClob() {
- super();
- }
-
- NClob(String charDataInit) {
- super(charDataInit);
- }
-}
Modified: trunk/connector-j/src/com/mysql/jdbc/PreparedStatement.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -51,9 +51,8 @@
import java.util.TimeZone;
import com.mysql.jdbc.Statement.CancelTask;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
import com.mysql.jdbc.exceptions.MySQLTimeoutException;
-import com.mysql.jdbc.jdbc4.MysqlSQLXML;
import com.mysql.jdbc.profiler.ProfilerEvent;
/**
@@ -416,7 +415,7 @@
*/
protected boolean useTrueBoolean = false;
- private boolean usingAnsiMode;
+ protected boolean usingAnsiMode;
private String batchedValuesClause;
@@ -2108,7 +2107,7 @@
}
public boolean isWrapperFor(Class arg0) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
private final int readblock(InputStream i, byte[] b) throws SQLException {
@@ -2741,7 +2740,7 @@
setInternal(parameterIndex, String.valueOf(x));
}
- private final void setInternal(int paramIndex, byte[] val)
+ protected final void setInternal(int paramIndex, byte[] val)
throws SQLException {
if (this.isClosed) {
throw SQLError.createSQLException(Messages.getString("PreparedStatement.48"), //$NON-NLS-1$
@@ -2772,7 +2771,7 @@
this.parameterValues[paramIndex - 1 + parameterIndexOffset] = val;
}
- private final void setInternal(int paramIndex, String val)
+ protected final void setInternal(int paramIndex, String val)
throws SQLException {
checkClosed();
@@ -4053,4 +4052,258 @@
protected int getParameterIndexOffset() {
return 0;
}
+
+ public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
+ setAsciiStream(parameterIndex, x, -1);
+
+ }
+
+ public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
+ setAsciiStream(parameterIndex, x, (int)length);
+
+ }
+
+ public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
+ setBinaryStream(parameterIndex, x, -1);
+
+ }
+
+ public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
+ setBinaryStream(parameterIndex, x, (int)length);
+
+ }
+
+ public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
+ setBinaryStream(parameterIndex, inputStream);
+
+ }
+
+ public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
+ setCharacterStream(parameterIndex, reader, -1);
+
+ }
+
+ public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
+ setCharacterStream(parameterIndex, reader, (int)length);
+
+ }
+
+ public void setClob(int parameterIndex, Reader reader) throws SQLException {
+ setCharacterStream(parameterIndex, reader);
+
+ }
+
+ public void setClob(int parameterIndex, Reader reader, long length)
+ throws SQLException {
+ setCharacterStream(parameterIndex, reader, length);
+ }
+
+ public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
+ setNCharacterStream(parameterIndex, value, -1);
+
+ }
+
+ /**
+ * Set a parameter to a Java String value. The driver converts this to a SQL
+ * VARCHAR or LONGVARCHAR value with introducer _utf8 (depending on the
+ * arguments size relative to the driver's limits on VARCHARs) when it sends
+ * it to the database. If charset is set as utf8, this method just call setString.
+ *
+ * @param parameterIndex
+ * the first parameter is 1...
+ * @param x
+ * the parameter value
+ *
+ * @exception SQLException
+ * if a database access error occurs
+ */
+ public void setNString(int parameterIndex, String x) throws SQLException {
+ if (this.charEncoding.equalsIgnoreCase("UTF-8")
+ || this.charEncoding.equalsIgnoreCase("utf8")) {
+ setString(parameterIndex, x);
+ return;
+ }
+
+ // if the passed string is null, then set this column to null
+ if (x == null) {
+ setNull(parameterIndex, java.sql.Types.CHAR);
+ } else {
+ int stringLength = x.length();
+ // Ignore sql_mode=NO_BACKSLASH_ESCAPES in current implementation.
+
+ // Add introducer _utf8 for NATIONAL CHARACTER
+ StringBuffer buf = new StringBuffer((int) (x.length() * 1.1 + 4));
+ buf.append("_utf8");
+ buf.append('\'');
+
+ //
+ // Note: buf.append(char) is _faster_ than
+ // appending in blocks, because the block
+ // append requires a System.arraycopy()....
+ // go figure...
+ //
+
+ for (int i = 0; i < stringLength; ++i) {
+ char c = x.charAt(i);
+
+ switch (c) {
+ case 0: /* Must be escaped for 'mysql' */
+ buf.append('\\');
+ buf.append('0');
+
+ break;
+
+ case '\n': /* Must be escaped for logs */
+ buf.append('\\');
+ buf.append('n');
+
+ break;
+
+ case '\r':
+ buf.append('\\');
+ buf.append('r');
+
+ break;
+
+ case '\\':
+ buf.append('\\');
+ buf.append('\\');
+
+ break;
+
+ case '\'':
+ buf.append('\\');
+ buf.append('\'');
+
+ break;
+
+ case '"': /* Better safe than sorry */
+ if (this.usingAnsiMode) {
+ buf.append('\\');
+ }
+
+ buf.append('"');
+
+ break;
+
+ case '\032': /* This gives problems on Win32 */
+ buf.append('\\');
+ buf.append('Z');
+
+ break;
+
+ default:
+ buf.append(c);
+ }
+ }
+
+ buf.append('\'');
+
+ String parameterAsString = buf.toString();
+
+ byte[] parameterAsBytes = null;
+
+ if (!this.isLoadDataQuery) {
+ parameterAsBytes = StringUtils.getBytes(parameterAsString,
+ this.connection.getCharsetConverter("UTF-8"), "UTF-8",
+ this.connection.getServerCharacterEncoding(),
+ this.connection.parserKnowsUnicode());
+ } else {
+ // Send with platform character encoding
+ parameterAsBytes = parameterAsString.getBytes();
+ }
+
+ setInternal(parameterIndex, parameterAsBytes);
+ }
+ }
+
+ /**
+ * JDBC 2.0 When a very large UNICODE value is input to a LONGVARCHAR
+ * parameter, it may be more practical to send it via a java.io.Reader. JDBC
+ * will read the data from the stream as needed, until it reaches
+ * end-of-file. The JDBC driver will do any necessary conversion from
+ * UNICODE to the database char format.
+ *
+ * <P>
+ * <B>Note:</B> This stream object can either be a standard Java stream
+ * object or your own subclass that implements the standard interface.
+ * </p>
+ *
+ * @param parameterIndex
+ * the first parameter is 1, the second is 2, ...
+ * @param reader
+ * the java reader which contains the UNICODE data
+ * @param length
+ * the number of characters in the stream
+ *
+ * @exception SQLException
+ * if a database-access error occurs.
+ */
+ public void setNCharacterStream(int parameterIndex, Reader reader,
+ long length) throws SQLException {
+ try {
+ if (reader == null) {
+ setNull(parameterIndex, java.sql.Types.LONGVARCHAR);
+
+ } else {
+ char[] c = null;
+ int len = 0;
+
+ boolean useLength = this.connection
+ .getUseStreamLengthsInPrepStmts();
+
+ // Ignore "clobCharacterEncoding" because utf8 should be used this time.
+
+ if (useLength && (length != -1)) {
+ c = new char[(int) length]; // can't take more than Integer.MAX_VALUE
+
+ int numCharsRead = readFully(reader, c, (int) length); // blocks
+ // until
+ // all
+ // read
+ setNString(parameterIndex, new String(c, 0, numCharsRead));
+
+ } else {
+ c = new char[4096];
+
+ StringBuffer buf = new StringBuffer();
+
+ while ((len = reader.read(c)) != -1) {
+ buf.append(c, 0, len);
+ }
+
+ setNString(parameterIndex, buf.toString());
+ }
+ }
+ } catch (java.io.IOException ioEx) {
+ throw SQLError.createSQLException(ioEx.toString(),
+ SQLError.SQL_STATE_GENERAL_ERROR);
+ }
+ }
+
+ public void setNClob(int parameterIndex, Reader reader) throws SQLException {
+ setNCharacterStream(parameterIndex, reader);
+ }
+
+ /**
+ * JDBC 4.0 Set a NCLOB parameter.
+ *
+ * @param parameterIndex
+ * the first parameter is 1, the second is 2, ...
+ * @param reader
+ * the java reader which contains the UNICODE data
+ * @param length
+ * the number of characters in the stream
+ *
+ * @throws SQLException
+ * if a database error occurs
+ */
+ public void setNClob(int parameterIndex, Reader reader, long length)
+ throws SQLException {
+ if (reader == null) {
+ setNull(parameterIndex, java.sql.Types.LONGVARCHAR);
+ } else {
+ setNCharacterStream(parameterIndex, reader, length);
+ }
+ }
}
Modified: trunk/connector-j/src/com/mysql/jdbc/ResultSet.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/ResultSet.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/ResultSet.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -24,8 +24,7 @@
*/
package com.mysql.jdbc;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
-import com.mysql.jdbc.jdbc4.MysqlSQLXML;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
import com.mysql.jdbc.profiler.ProfileEventSink;
import com.mysql.jdbc.profiler.ProfilerEvent;
@@ -3676,12 +3675,8 @@
} catch (NumberFormatException ex) {
throw SQLError.createSQLException(
Messages
- .getString("ResultSet.Bad_format_for_BigDecimal____86") //$NON-NLS-1$
- + stringVal
- + Messages
- .getString("ResultSet.___in_column__87")
- + columnIndex + "(" //$NON-NLS-1$
- + this.fields[columnIndex - 1] + ").",
+ .getString("ResultSet.Bad_format_for_BigDecimal",
+ new Object[] {stringVal, new Integer(columnIndex)}),
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
Modified: trunk/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -27,7 +27,7 @@
import java.sql.SQLException;
import java.sql.Types;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
/**
* A ResultSetMetaData object can be used to find out about the types and
@@ -807,10 +807,10 @@
}
public boolean isWrapperFor(Class arg0) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
public Object unwrap(Class arg0) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
}
Modified: trunk/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -782,7 +782,7 @@
* @return
* @throws SQLException
*/
- private BindValue getBinding(int parameterIndex, boolean forLongData)
+ protected BindValue getBinding(int parameterIndex, boolean forLongData)
throws SQLException {
checkClosed();
Modified: trunk/connector-j/src/com/mysql/jdbc/Statement.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/Statement.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/Statement.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -24,7 +24,7 @@
*/
package com.mysql.jdbc;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
import com.mysql.jdbc.exceptions.MySQLTimeoutException;
import com.mysql.jdbc.profiler.ProfileEventSink;
import com.mysql.jdbc.profiler.ProfilerEvent;
@@ -2345,10 +2345,10 @@
}
public boolean isWrapperFor(Class arg0) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
public Object unwrap(Class arg0) throws SQLException {
- throw new JDBC40NotYetImplementedException();
+ throw new NotYetImplementedException();
}
}
Deleted: trunk/connector-j/src/com/mysql/jdbc/exceptions/JDBC40NotYetImplementedException.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/exceptions/JDBC40NotYetImplementedException.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/exceptions/JDBC40NotYetImplementedException.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -1,18 +0,0 @@
-package com.mysql.jdbc.exceptions;
-
-public class JDBC40NotYetImplementedException extends RuntimeException {
-
- public JDBC40NotYetImplementedException() {
- // TODO Auto-generated constructor stub
- }
-
- public JDBC40NotYetImplementedException(String reason) {
- super(reason);
- // TODO Auto-generated constructor stub
- }
-
- public JDBC40NotYetImplementedException(Throwable cause) {
- super(cause);
- // TODO Auto-generated constructor stub
- }
-}
Copied: trunk/connector-j/src/com/mysql/jdbc/exceptions/NotYetImplementedException.java (from rev 5749, trunk/connector-j/src/com/mysql/jdbc/exceptions/JDBC40NotYetImplementedException.java)
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/exceptions/JDBC40NotYetImplementedException.java 2006-09-19 01:47:23 UTC (rev 5749)
+++ trunk/connector-j/src/com/mysql/jdbc/exceptions/NotYetImplementedException.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,18 @@
+package com.mysql.jdbc.exceptions;
+
+public class NotYetImplementedException extends RuntimeException {
+
+ public NotYetImplementedException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public NotYetImplementedException(String reason) {
+ super(reason);
+ // TODO Auto-generated constructor stub
+ }
+
+ public NotYetImplementedException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+}
Modified: trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/CallableStatementWrapper.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/CallableStatementWrapper.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/CallableStatementWrapper.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -44,7 +44,7 @@
import java.util.Map;
import com.mysql.jdbc.SQLError;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
/**
* Wraps callable statements created by pooled connections.
@@ -2592,11 +2592,11 @@
// }
//
// public boolean isWrapperFor(Class arg0) throws SQLException {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
//
// public Object unwrap(Class arg0) throws SQLException {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
}
Modified: trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -39,7 +39,7 @@
import com.mysql.jdbc.MysqlErrorNumbers;
import com.mysql.jdbc.SQLError;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
/**
* This class serves as a wrapper for the org.gjt.mm.mysql.jdbc2.Connection
@@ -954,10 +954,10 @@
// }
//
// public boolean isWrapperFor(Class arg0) throws SQLException {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
//
// public Object unwrap(Class arg0) throws SQLException {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
}
Modified: trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSource.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSource.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSource.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -26,7 +26,7 @@
import com.mysql.jdbc.ConnectionProperties;
import com.mysql.jdbc.NonRegisteringDriver;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
import java.io.PrintWriter;
import java.io.Serializable;
@@ -427,10 +427,10 @@
}
//
// public boolean isWrapperFor(Class<?> iface) throws SQLException {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
//
// public <T> T unwrap(Class<T> iface) throws SQLException {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
}
Modified: trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlPooledConnection.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlPooledConnection.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlPooledConnection.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -34,7 +34,7 @@
import javax.sql.PooledConnection;
import com.mysql.jdbc.SQLError;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
/**
* This class is used to wrap and return a physical connection within a logical
@@ -222,7 +222,7 @@
// * @since 1.6
// */
// public void addStatementEventListener(StatementEventListener listener) {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
//
// /**
@@ -237,7 +237,7 @@
// * @since 1.6
// */
// public void removeStatementEventListener(StatementEventListener listener) {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
Modified: trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/PreparedStatementWrapper.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/PreparedStatementWrapper.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/PreparedStatementWrapper.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -25,7 +25,7 @@
package com.mysql.jdbc.jdbc2.optional;
import com.mysql.jdbc.SQLError;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
import java.io.InputStream;
import java.io.Reader;
@@ -1187,10 +1187,10 @@
// }
//
// public boolean isWrapperFor(Class arg0) throws SQLException {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
//
// public Object unwrap(Class arg0) throws SQLException {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
}
Modified: trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/StatementWrapper.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/StatementWrapper.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/jdbc2/optional/StatementWrapper.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -25,7 +25,7 @@
package com.mysql.jdbc.jdbc2.optional;
import com.mysql.jdbc.SQLError;
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
+import com.mysql.jdbc.exceptions.NotYetImplementedException;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -872,10 +872,10 @@
// }
//
// public boolean isWrapperFor(Class arg0) throws SQLException {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
//
// public Object unwrap(Class arg0) throws SQLException {
-// throw new JDBC40NotYetImplementedException();
+// throw new NotYetImplementedException();
// }
}
Deleted: trunk/connector-j/src/com/mysql/jdbc/jdbc4/MysqlSQLXML.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/jdbc4/MysqlSQLXML.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/jdbc4/MysqlSQLXML.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -1,565 +0,0 @@
-/*
- Copyright (C) 2002-2007 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of version 2 of the GNU General Public License as
- published by the Free Software Foundation.
-
- There are special exceptions to the terms and conditions of the GPL
- as it is applied to this software. View the full text of the
- exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
- software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- */
-
-package com.mysql.jdbc.jdbc4;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
-import java.sql.SQLXML;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stax.StAXResult;
-import javax.xml.transform.stax.StAXSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-
-import com.mysql.jdbc.exceptions.JDBC40NotYetImplementedException;
-
-public class MysqlSQLXML implements SQLXML, WriterWatcher, OutputStreamWatcher {
-
- private XMLInputFactory inputFactory;
-
- private XMLOutputFactory outputFactory;
-
- private String stringRep;
-
- private ResultSet owningResultSet;
-
- private int columnIndexOfXml;
-
- private boolean fromResultSet;
-
- private boolean isClosed = false;
-
- private boolean workingWithResult;
-
- private DOMResult asDOMResult;
-
- protected MysqlSQLXML(ResultSet owner, int index) {
- this.owningResultSet = owner;
- this.columnIndexOfXml = index;
- this.fromResultSet = true;
- }
-
- protected MysqlSQLXML() {
- this.fromResultSet = false;
- }
-
- public synchronized void free() throws SQLException {
- this.inputFactory = null;
- this.outputFactory = null;
- this.owningResultSet = null;
- this.workingWithResult = false;
- this.isClosed = true;
-
- }
-
- public synchronized String getString() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- if (this.fromResultSet) {
- return this.owningResultSet.getString(this.columnIndexOfXml);
- }
-
- return this.stringRep;
- }
-
- private synchronized void checkClosed() throws SQLException {
- if (this.isClosed) {
- throw SQLError.createSQLException("SQLXMLInstance has been free()d");
- }
- }
-
- private synchronized void checkWorkingWithResult() throws SQLException {
- if (this.workingWithResult) {
- throw SQLError.createSQLException("Can't perform requested operation after getResult() has been called to write XML data",
- SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
-
- /**
- * Sets the XML value designated by this SQLXML instance to the given String
- * representation. The format of this String is defined by
- * org.xml.sax.InputSource, where the characters in the stream represent the
- * unicode code points for XML according to section 2 and appendix B of the
- * XML 1.0 specification. Although an encoding declaration other than
- * unicode may be present, the encoding of the String is unicode. The
- * behavior of this method is the same as ResultSet.updateString() when the
- * designated column of the ResultSet has a type java.sql.Types of SQLXML.
- * <p>
- * The SQL XML object becomes not writeable when this method is called and
- * may also become not readable depending on implementation.
- *
- * @param value
- * the XML value
- * @throws SQLException
- * if there is an error processing the XML value. The getCause()
- * method of the exception may provide a more detailed
- * exception, for example, if the stream does not contain valid
- * characters. An exception is thrown if the state is not
- * writable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
-
- public synchronized void setString(String str) throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- this.stringRep = str;
- this.fromResultSet = false;
- }
-
- public synchronized boolean isEmpty() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- if (!this.fromResultSet) {
- return this.stringRep == null || this.stringRep.length() == 0;
- }
-
- return false;
- }
-
- public synchronized InputStream getBinaryStream() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- return this.owningResultSet.getBinaryStream(this.columnIndexOfXml);
- }
-
- /**
- * Retrieves the XML value designated by this SQLXML instance as a
- * java.io.Reader object. The format of this stream is defined by
- * org.xml.sax.InputSource, where the characters in the stream represent the
- * unicode code points for XML according to section 2 and appendix B of the
- * XML 1.0 specification. Although an encoding declaration other than
- * unicode may be present, the encoding of the stream is unicode. The
- * behavior of this method is the same as ResultSet.getCharacterStream()
- * when the designated column of the ResultSet has a type java.sql.Types of
- * SQLXML.
- * <p>
- * The SQL XML object becomes not readable when this method is called and
- * may also become not writable depending on implementation.
- *
- * @return a stream containing the XML data.
- * @throws SQLException
- * if there is an error processing the XML value. The getCause()
- * method of the exception may provide a more detailed
- * exception, for example, if the stream does not contain valid
- * characters. An exception is thrown if the state is not
- * readable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
- public synchronized Reader getCharacterStream() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- return this.owningResultSet.getCharacterStream(this.columnIndexOfXml);
- }
-
- /**
- * Returns a Source for reading the XML value designated by this SQLXML
- * instance. Sources are used as inputs to XML parsers and XSLT
- * transformers.
- * <p>
- * Sources for XML parsers will have namespace processing on by default. The
- * systemID of the Source is implementation dependent.
- * <p>
- * The SQL XML object becomes not readable when this method is called and
- * may also become not writable depending on implementation.
- * <p>
- * Note that SAX is a callback architecture, so a returned SAXSource should
- * then be set with a content handler that will receive the SAX events from
- * parsing. The content handler will receive callbacks based on the contents
- * of the XML.
- *
- * <pre>
- * SAXSource saxSource = sqlxml.getSource(SAXSource.class);
- * XMLReader xmlReader = saxSource.getXMLReader();
- * xmlReader.setContentHandler(myHandler);
- * xmlReader.parse(saxSource.getInputSource());
- * </pre>
- *
- * @param sourceClass
- * The class of the source, or null. If the class is null, a
- * vendor specifc Source implementation will be returned. The
- * following classes are supported at a minimum:
- *
- * (MySQL returns a SAXSource if sourceClass == null)
- *
- * <pre>
- * javax.xml.transform.dom.DOMSource - returns a DOMSource
- * javax.xml.transform.sax.SAXSource - returns a SAXSource
- * javax.xml.transform.stax.StAXSource - returns a StAXSource
- * javax.xml.transform.stream.StreamSource - returns a StreamSource
- * </pre>
- *
- * @return a Source for reading the XML value.
- * @throws SQLException
- * if there is an error processing the XML value or if this
- * feature is not supported. The getCause() method of the
- * exception may provide a more detailed exception, for example,
- * if an XML parser exception occurs. An exception is thrown if
- * the state is not readable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
- public synchronized Source getSource(Class clazz) throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- // Note that we try and use streams here wherever possible
- // for the day that the server actually supports streaming
- // from server -> client (futureproofing)
-
- if (clazz == null || clazz.equals(SAXSource.class)) {
-
- InputSource inputSource = null;
-
- if (this.fromResultSet) {
- inputSource = new InputSource(
- this.owningResultSet
- .getCharacterStream(this.columnIndexOfXml));
- } else {
- inputSource = new InputSource(new StringReader(this.stringRep));
- }
-
- return new SAXSource(inputSource);
- } else if (clazz.equals(DOMSource.class)) {
- try {
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory
- .newInstance();
- builderFactory.setNamespaceAware(true);
- DocumentBuilder builder = builderFactory.newDocumentBuilder();
-
- InputSource inputSource = null;
-
- if (this.fromResultSet) {
- inputSource = new InputSource(
- this.owningResultSet
- .getCharacterStream(this.columnIndexOfXml));
- } else {
- inputSource = new InputSource(new StringReader(this.stringRep));
- }
-
- return new DOMSource(builder.parse(inputSource));
- } catch (Throwable t) {
- // FIXME - need to use factory method and set cause here
-
- throw new SQLException(t);
- }
-
- } else if (clazz.equals(StreamSource.class)) {
- Reader reader = null;
-
- if (this.fromResultSet) {
- reader = this.owningResultSet
- .getCharacterStream(this.columnIndexOfXml);
- } else {
- reader = new StringReader(this.stringRep);
- }
-
- return new StreamSource(reader);
- } else if (clazz.equals(StAXSource.class)) {
- try {
- Reader reader = null;
-
- if (this.fromResultSet) {
- reader = this.owningResultSet
- .getCharacterStream(this.columnIndexOfXml);
- } else {
- reader = new StringReader(this.stringRep);
- }
-
- return new StAXSource(this.inputFactory
- .createXMLStreamReader(reader));
- } catch (XMLStreamException ex) {
- SQLException sqlEx = SQLError.createSQLException(ex
- .getMessage(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- // perhaps setCause here w/ ex?
- throw sqlEx;
- }
- } else {
- throw SQLError.createSQLException("XML Source of type \""
- + clazz.toString() + "\" Not supported.",
- SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
-
- /**
- * Retrieves a stream that can be used to write the XML value that this
- * SQLXML instance represents. The stream begins at position 0. The bytes of
- * the stream are interpreted according to appendix F of the XML 1.0
- * specification The behavior of this method is the same as
- * ResultSet.updateBinaryStream() when the designated column of the
- * ResultSet has a type java.sql.Types of SQLXML.
- * <p>
- * The SQL XML object becomes not writeable when this method is called and
- * may also become not readable depending on implementation.
- *
- * @return a stream to which data can be written.
- * @throws SQLException
- * if there is an error processing the XML value. An exception
- * is thrown if the state is not writable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
- public synchronized OutputStream setBinaryStream() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- this.workingWithResult = true;
-
- return setBinaryStreamInternal();
- }
-
- private OutputStream setBinaryStreamInternal() throws SQLException {
- WatchableOutputStream bytesOut = new WatchableOutputStream();
- bytesOut.setWatcher(this);
-
- return bytesOut;
- }
-
- /**
- * Retrieves a stream to be used to write the XML value that this SQLXML
- * instance represents. The format of this stream is defined by
- * org.xml.sax.InputSource, where the characters in the stream represent the
- * unicode code points for XML according to section 2 and appendix B of the
- * XML 1.0 specification. Although an encoding declaration other than
- * unicode may be present, the encoding of the stream is unicode. The
- * behavior of this method is the same as ResultSet.updateCharacterStream()
- * when the designated column of the ResultSet has a type java.sql.Types of
- * SQLXML.
- * <p>
- * The SQL XML object becomes not writeable when this method is called and
- * may also become not readable depending on implementation.
- *
- * @return a stream to which data can be written.
- * @throws SQLException
- * if there is an error processing the XML value. The getCause()
- * method of the exception may provide a more detailed
- * exception, for example, if the stream does not contain valid
- * characters. An exception is thrown if the state is not
- * writable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
- public synchronized Writer setCharacterStream() throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- this.workingWithResult = true;
-
- return setCharacterStreamInternal();
- }
-
- private Writer setCharacterStreamInternal() throws SQLException {
- WatchableWriter writer = new WatchableWriter();
- writer.setWatcher(this);
-
- return writer;
- }
-
- /**
- * Returns a Result for setting the XML value designated by this SQLXML
- * instance.
- * <p>
- * The systemID of the Result is implementation dependent.
- * <p>
- * The SQL XML object becomes not writeable when this method is called and
- * may also become not readable depending on implementation.
- * <p>
- * Note that SAX is a callback architecture and the returned SAXResult has a
- * content handler assigned that will receive the SAX events based on the
- * contents of the XML. Call the content handler with the contents of the
- * XML document to assign the values.
- *
- * <pre>
- * SAXResult saxResult = sqlxml.setResult(SAXResult.class);
- * ContentHandler contentHandler = saxResult.getXMLReader().getContentHandler();
- * contentHandler.startDocument();
- * // set the XML elements and attributes into the result
- * contentHandler.endDocument();
- * </pre>
- *
- * @param resultClass
- * The class of the result, or null. If resultClass is null, a
- * vendor specific Result implementation will be returned. The
- * following classes are supported at a minimum:
- *
- * <pre>
- * javax.xml.transform.dom.DOMResult - returns a DOMResult
- * javax.xml.transform.sax.SAXResult - returns a SAXResult
- * javax.xml.transform.stax.StAXResult - returns a StAXResult
- * javax.xml.transform.stream.StreamResult - returns a StreamResult
- * </pre>
- *
- * @return Returns a Result for setting the XML value.
- * @throws SQLException
- * if there is an error processing the XML value or if this
- * feature is not supported. The getCause() method of the
- * exception may provide a more detailed exception, for example,
- * if an XML parser exception occurs. An exception is thrown if
- * the state is not writable.
- * @exception SQLFeatureNotSupportedException
- * if the JDBC driver does not support this method
- * @since 1.6
- */
- public synchronized Result setResult(Class clazz) throws SQLException {
- checkClosed();
- checkWorkingWithResult();
-
- this.workingWithResult = true;
- this.asDOMResult = null;
- this.stringRep = null;
-
- if (clazz == null || clazz.equals(SAXResult.class)) {
-
- // TODO: Need to flesh this out
- return new SAXResult(null);
- } else if (clazz.equals(DOMResult.class)) {
-
- this.asDOMResult = new DOMResult();
- return this.asDOMResult;
-
- } else if (clazz.equals(StreamResult.class)) {
- return new StreamResult(setCharacterStreamInternal());
- } else if (clazz.equals(StAXResult.class)) {
- try {
- return new StAXResult(this.outputFactory.createXMLEventWriter(
- setCharacterStreamInternal()));
- } catch (XMLStreamException ex) {
- SQLException sqlEx = SQLError.createSQLException(ex
- .getMessage(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- // perhaps setCause here w/ ex?
- throw sqlEx;
- }
- } else {
- throw SQLError.createSQLException("XML Result of type \""
- + clazz.toString() + "\" Not supported.",
- SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
-
- /**
- * @see com.mysql.jdbc.WriterWatcher#writerClosed(char[])
- */
- public void writerClosed(WatchableWriter out) {
- try {
- setString(out.toString());
- } catch (SQLException sqlEx) {
- // never actually thrown in our impl
- }
- }
-
- public void streamClosed(WatchableOutputStream out) {
-
- try {
- // There's got to be an easier way to do this, but
- // I don't feel like coding up Appendix F of the XML Spec
- // myself, when there's a reusable way to do it, and we
- // can warn folks away from BINARY xml streams that have
- // to be parsed to determine the character encoding :P
-
- String encoding = "UTF-8";
-
- try {
- ByteArrayInputStream bIn = new ByteArrayInputStream(out.toByteArray());
- XMLStreamReader reader = this.inputFactory.createXMLStreamReader(bIn);
-
- int eventType = 0;
-
- while ((eventType = reader.next()) != XMLStreamReader.END_DOCUMENT) {
- if (eventType == XMLStreamReader.START_DOCUMENT) {
- String possibleEncoding = reader.getEncoding();
-
- if (possibleEncoding != null) {
- encoding = possibleEncoding;
- }
-
- break;
- }
- }
- } catch (Throwable t) {
- // ignore, dealt with later when the string can't be parsed
- // into valid XML
- }
-
- setString(new String(out.toByteArray(), encoding));
- } catch (UnsupportedEncodingException badEnc) {
- throw new RuntimeException(badEnc);
- } catch (SQLException sqlEx) {
- // never actually thrown in our impl
- }
- }
-
- protected synchronized String serializeAsString() throws SQLException {
- checkClosed();
- if (this.workingWithResult) {
- // figure out what kind of result
- if (this.stringRep != null) {
- return this.stringRep;
- }
-
- if (this.asDOMResult != null) {
- // serialize from DOM
- }
- }
-
- return getString();
- }
-}
Deleted: trunk/connector-j/src/com/mysql/jdbc/jdbc4/NClob.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/jdbc4/NClob.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/com/mysql/jdbc/jdbc4/NClob.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -1,43 +0,0 @@
-/*
- Copyright (C) 2002-2007 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of version 2 of the GNU General Public License as
- published by the Free Software Foundation.
-
- There are special exceptions to the terms and conditions of the GPL
- as it is applied to this software. View the full text of the
- exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
- software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- */
-
-package com.mysql.jdbc.jdbc4;
-
-import com.mysql.jdbc.Clob;
-
-/**
- * Simplistic implementation of java.sql.NClob for MySQL Connector/J
- *
- * @author Tetsuro Ikeda
- * @version $Id: NClob.java 4963 2006-02-21 13:28:14Z tikeda $
- */
-public class NClob extends Clob implements java.sql.NClob {
-
- NClob() {
- super();
- }
-
- NClob(String charDataInit) {
- super(charDataInit);
- }
-}
Added: trunk/connector-j/src/testsuite/simple/jdbc4/StatementsTest.java
===================================================================
--- trunk/connector-j/src/testsuite/simple/jdbc4/StatementsTest.java 2007-03-09 21:13:57 UTC (rev 6341)
+++ trunk/connector-j/src/testsuite/simple/jdbc4/StatementsTest.java 2007-03-09 21:45:01 UTC (rev 6342)
@@ -0,0 +1,623 @@
+/*
+ Copyright (C) 2002-2007 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL
+ as it is applied to this software. View the full text of the
+ exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
+ software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+
+ */
+package testsuite.simple.jdbc4;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import testsuite.BaseTestCase;
+
+public class StatementsTest extends BaseTestCase {
+
+ public StatementsTest(String name) {
+ super(name);
+
+ }
+
+ /**
+ * Tests for ResultSet.getNCharacterStream()
+ *
+ * @throws Exception
+ */
+ public void testGetNCharacterSteram() throws Exception {
+ createTable("testGetNCharacterStream", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10))");
+ this.stmt.executeUpdate("INSERT INTO testGetNCharacterStream (c1, c2) VALUES (_utf8 'aaa', _utf8 'bbb')");
+ this.rs = this.stmt.executeQuery("SELECT c1, c2 FROM testGetNCharacterStream");
+ this.rs.next();
+ char[] c1 = new char[3];
+ this.rs.getNCharacterStream(1).read(c1);
+ assertEquals("aaa", new String(c1));
+ char[] c2 = new char[3];
+ this.rs.getNCharacterStream("c2").read(c2);
+ assertEquals("bbb", new String(c2));
+ this.rs.close();
+ }
+
+ /**
+ * Tests for ResultSet.getNClob()
+ *
+ * @throws Exception
+ */
+ public void testGetNClob() throws Exception {
+ createTable("testGetNClob", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10))");
+ this.stmt.executeUpdate("INSERT INTO testGetNClob (c1, c2) VALUES (_utf8 'aaa', _utf8 'bbb')");
+ this.rs = this.stmt.executeQuery("SELECT c1, c2 FROM testGetNClob");
+ this.rs.next();
+ char[] c1 = new char[3];
+ this.rs.getNClob(1).getCharacterStream().read(c1);
+ assertEquals("aaa", new String(c1));
+ char[] c2 = new char[3];
+ this.rs.getNClob("c2").getCharacterStream().read(c2);
+ assertEquals("bbb", new String(c2));
+ this.rs.close();
+
+ // for isBinaryEncoded = true, using PreparedStatement
+ createTable("testGetNClob", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10))");
+ this.stmt.executeUpdate("INSERT INTO testGetNClob (c1, c2) VALUES (_utf8 'aaa', _utf8 'bbb')");
+ this.pstmt = this.conn.prepareStatement("SELECT c1, c2 FROM testGetNClob");
+ this.rs = this.pstmt.executeQuery();
+ this.rs.next();
+ c1 = new char[3];
+ this.rs.getNClob(1).getCharacterStream().read(c1);
+ assertEquals("aaa", new String(c1));
+ c2 = new char[3];
+ this.rs.getNClob("c2").getCharacterStream().read(c2);
+ assertEquals("bbb", new String(c2));
+ this.rs.close();
+ }
+
+ /**
+ * Tests for ResultSet.getNString()
+ *
+ * @throws Exception
+ */
+ public void testGetNString() throws Exception {
+ createTable("testGetNString", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10))");
+ this.stmt.executeUpdate("INSERT INTO testGetNString (c1, c2) VALUES (_utf8 'aaa', _utf8 'bbb')");
+ this.rs = this.stmt.executeQuery("SELECT c1, c2 FROM testGetNString");
+ this.rs.next();
+ assertEquals("aaa", this.rs.getNString(1));
+ assertEquals("bbb", this.rs.getNString("c2"));
+ this.rs.close();
+ }
+
+ /**
+ * Tests for PreparedStatement.setNCharacterSteam()
+ *
+ * @throws Exception
+ */
+ public void testSetNCharacterStream() throws Exception {
+ // suppose sql_mode don't include "NO_BACKSLASH_ESCAPES"
+
+ createTable("testSetNCharacterStream", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
+ "c3 NATIONAL CHARACTER(10))");
+ Properties props1 = new Properties();
+ props1.put("useServerPrepStmts", "false"); // use client-side prepared statement
+ props1.put("useUnicode", "true");
+ props1.put("characterEncoding", "latin1"); // ensure charset isn't utf8 here
+ Connection conn1 = getConnectionWithProps(props1);
+ com.mysql.jdbc.PreparedStatement pstmt1 = (com.mysql.jdbc.PreparedStatement)
+ conn1.prepareStatement("INSERT INTO testSetNCharacterStream (c1, c2, c3) VALUES (?, ?, ?)");
+ pstmt1.setNCharacterStream(1, null, 0);
+ pstmt1.setNCharacterStream(2, new StringReader("aaa"), 3);
+ pstmt1.setNCharacterStream(3, new StringReader("\'aaa\'"), 5);
+ pstmt1.execute();
+ ResultSet rs1 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNCharacterStream");
+ rs1.next();
+ assertEquals(null, rs1.getString(1));
+ assertEquals("aaa", rs1.getString(2));
+ assertEquals("\'aaa\'", rs1.getString(3));
+ rs1.close();
+ pstmt1.close();
+ conn1.close();
+
+ createTable("testSetNCharacterStream", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
+ "c3 NATIONAL CHARACTER(10))");
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "false"); // use client-side prepared statement
+ props2.put("useUnicode", "true");
+ props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ com.mysql.jdbc.PreparedStatement pstmt2 = (com.mysql.jdbc.PreparedStatement)
+ conn2.prepareStatement("INSERT INTO testSetNCharacterStream (c1, c2, c3) VALUES (?, ?, ?)");
+ pstmt2.setNCharacterStream(1, null, 0);
+ pstmt2.setNCharacterStream(2, new StringReader("aaa"), 3);
+ pstmt2.setNCharacterStream(3, new StringReader("\'aaa\'"), 5);
+ pstmt2.execute();
+ ResultSet rs2 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNCharacterStream");
+ rs2.next();
+ assertEquals(null, rs2.getString(1));
+ assertEquals("aaa", rs2.getString(2));
+ assertEquals("\'aaa\'", rs2.getString(3));
+ rs2.close();
+ pstmt2.close();
+ conn2.close();
+ }
+
+ /**
+ * Tests for ServerPreparedStatement.setNCharacterSteam()
+ *
+ * @throws Exception
+ */
+ public void testSetNCharacterStreamServer() throws Exception {
+ createTable("testSetNCharacterStreamServer", "(c1 NATIONAL CHARACTER(10))");
+ Properties props1 = new Properties();
+ props1.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props1.put("useUnicode", "true");
+ props1.put("characterEncoding", "latin1"); // ensure charset isn't utf8 here
+ Connection conn1 = getConnectionWithProps(props1);
+ PreparedStatement pstmt1 = conn1.prepareStatement("INSERT INTO testSetNCharacterStreamServer (c1) VALUES (?)");
+ try {
+ pstmt1.setNCharacterStream(1, new StringReader("aaa"), 3);
+ fail();
+ } catch (SQLException e) {
+ // ok
+ assertEquals("Can not call setNCharacterStream() when connection character set isn't UTF-8",
+ e.getMessage());
+ }
+ pstmt1.close();
+ conn1.close();
+
+ createTable("testSetNCharacterStreamServer", "(c1 LONGTEXT charset utf8)");
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props2.put("useUnicode", "true");
+ props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 =
+ conn2.prepareStatement("INSERT INTO testSetNCharacterStreamServer (c1) VALUES (?)");
+ pstmt2.setNCharacterStream(1, new StringReader(
+ new String(new char[81921])), 81921); // 10 Full Long Data Packet's chars + 1 char
+ pstmt2.execute();
+ ResultSet rs2 = this.stmt.executeQuery("SELECT c1 FROM testSetNCharacterStreamServer");
+ rs2.next();
+ assertEquals(new String(new char[81921]), rs2.getString(1));
+ rs2.close();
+ pstmt2.close();
+ conn2.close();
+ }
+
+ /**
+ * Tests for PreparedStatement.setNClob()
+ *
+ * @throws Exception
+ */
+ public void testSetNClob() throws Exception {
+ // suppose sql_mode don't include "NO_BACKSLASH_ESCAPES"
+
+ createTable("testSetNClob", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
+ "c3 NATIONAL CHARACTER(10))");
+ Properties props1 = new Properties();
+ props1.put("useServerPrepStmts", "false"); // use client-side prepared statement
+ props1.put("useUnicode", "true");
+ props1.put("characterEncoding", "latin1"); // ensure charset isn't utf8 here
+ Connection conn1 = getConnectionWithProps(props1);
+ PreparedStatement pstmt1 =
+ conn1.prepareStatement("INSERT INTO testSetNClob (c1, c2, c3) VALUES (?, ?, ?)");
+ pstmt1.setNClob(1, (NClob)null);
+ NClob nclob2 = conn1.createNClob();
+ nclob2.setString(1, "aaa");
+ pstmt1.setNClob(2, nclob2); // for setNClob(int, NClob)
+ Reader reader3 = new StringReader("\'aaa\'");
+ pstmt1.setNClob(3, reader3, 5); // for setNClob(int, Reader, long)
+ pstmt1.execute();
+ ResultSet rs1 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNClob");
+ rs1.next();
+ assertEquals(null, rs1.getString(1));
+ assertEquals("aaa", rs1.getString(2));
+ assertEquals("\'aaa\'", rs1.getString(3));
+ rs1.close();
+ pstmt1.close();
+ conn1.close();
+
+ createTable("testSetNClob", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
+ "c3 NATIONAL CHARACTER(10))");
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "false"); // use client-side prepared statement
+ props2.put("useUnicode", "true");
+ props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 =
+ conn2.prepareStatement("INSERT INTO testSetNClob (c1, c2, c3) VALUES (?, ?, ?)");
+ pstmt2.setNClob(1, (NClob)null);
+ nclob2 = conn2.createNClob();
+ nclob2.setString(1, "aaa");
+ pstmt2.setNClob(2, nclob2); // for setNClob(int, NClob)
+ reader3 = new StringReader("\'aaa\'");
+ pstmt2.setNClob(3, reader3, 5); // for setNClob(int, Reader, long)
+ pstmt2.execute();
+ ResultSet rs2 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNClob");
+ rs2.next();
+ assertEquals(null, rs2.getString(1));
+ assertEquals("aaa", rs2.getString(2));
+ assertEquals("\'aaa\'", rs2.getString(3));
+ rs2.close();
+ pstmt2.close();
+ conn2.close();
+ }
+
+ /**
+ * Tests for ServerPreparedStatement.setNClob()
+ *
+ * @throws Exception
+ */
+ public void testSetNClobServer() throws Exception {
+ createTable("testSetNClobServer", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10))");
+ Properties props1 = new Properties();
+ props1.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props1.put("useUnicode", "true");
+ props1.put("characterEncoding", "latin1"); // ensure charset isn't utf8 here
+ Connection conn1 = getConnectionWithProps(props1);
+ PreparedStatement pstmt1 =
+ conn1.prepareStatement("INSERT INTO testSetNClobServer (c1, c2) VALUES (?, ?)");
+ NClob nclob1 = conn1.createNClob();
+ nclob1.setString(1, "aaa");
+ Reader reader2 = new StringReader("aaa");
+ try {
+ pstmt1.setNClob(1, nclob1);
+ fail();
+ } catch (SQLException e) {
+ // ok
+ assertEquals("Can not call setNClob() when connection character set isn't UTF-8",
+ e.getMessage());
+ }
+ try {
+ pstmt1.setNClob(2, reader2, 3);
+ fail();
+ } catch (SQLException e) {
+ // ok
+ assertEquals("Can not call setNClob() when connection character set isn't UTF-8",
+ e.getMessage());
+ }
+ pstmt1.close();
+ conn1.close();
+
+ createTable("testSetNClobServer", "(c1 NATIONAL CHARACTER(10), c2 LONGTEXT charset utf8)");
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props2.put("useUnicode", "true");
+ props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 =
+ conn2.prepareStatement("INSERT INTO testSetNClobServer (c1, c2) VALUES (?, ?)");
+ nclob1 = conn2.createNClob();
+ nclob1.setString(1, "aaa");
+ pstmt2.setNClob(1, nclob1);
+ pstmt2.setNClob(2, new StringReader(
+ new String(new char[81921])), 81921); // 10 Full Long Data Packet's chars + 1 char
+ pstmt2.execute();
+ ResultSet rs2 = this.stmt.executeQuery("SELECT c1, c2 FROM testSetNClobServer");
+ rs2.next();
+ assertEquals("aaa", rs2.getString(1));
+ assertEquals(new String(new char[81921]), rs2.getString(2));
+ rs2.close();
+ pstmt2.close();
+ conn2.close();
+ }
+
+ /**
+ * Tests for PreparedStatement.setNString()
+ *
+ * @throws Exception
+ */
+ public void testSetNString() throws Exception {
+ // suppose sql_mode don't include "NO_BACKSLASH_ESCAPES"
+
+ createTable("testSetNString", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
+ "c3 NATIONAL CHARACTER(10)) DEFAULT CHARACTER SET cp932");
+ Properties props1 = new Properties();
+ props1.put("useServerPrepStmts", "false"); // use client-side prepared statement
+ props1.put("useUnicode", "true");
+ props1.put("characterEncoding", "MS932"); // ensure charset isn't utf8 here
+ Connection conn1 = getConnectionWithProps(props1);
+ PreparedStatement pstmt1 =
+ conn1.prepareStatement("INSERT INTO testSetNString (c1, c2, c3) VALUES (?, ?, ?)");
+ pstmt1.setNString(1, null);
+ pstmt1.setNString(2, "aaa");
+ pstmt1.setNString(3, "\'aaa\'");
+ pstmt1.execute();
+ ResultSet rs1 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNString");
+ rs1.next();
+ assertEquals(null, rs1.getString(1));
+ assertEquals("aaa", rs1.getString(2));
+ assertEquals("\'aaa\'", rs1.getString(3));
+ rs1.close();
+ pstmt1.close();
+ conn1.close();
+
+ createTable("testSetNString", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
+ "c3 NATIONAL CHARACTER(10)) DEFAULT CHARACTER SET cp932");
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "false"); // use client-side prepared statement
+ props2.put("useUnicode", "true");
+ props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 =
+ conn2.prepareStatement("INSERT INTO testSetNString (c1, c2, c3) VALUES (?, ?, ?)");
+ pstmt2.setNString(1, null);
+ pstmt2.setNString(2, "aaa");
+ pstmt2.setNString(3, "\'aaa\'");
+ pstmt2.execute();
+ ResultSet rs2 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNString");
+ rs2.next();
+ assertEquals(null, rs2.getString(1));
+ assertEquals("aaa", rs2.getString(2));
+ assertEquals("\'aaa\'", rs2.getString(3));
+ rs2.close();
+ pstmt2.close();
+ conn2.close();
+ }
+
+ /**
+ * Tests for ServerPreparedStatement.setNString()
+ *
+ * @throws Exception
+ */
+ public void testSetNStringServer() throws Exception {
+ createTable("testSetNStringServer", "(c1 NATIONAL CHARACTER(10))");
+ Properties props1 = new Properties();
+ props1.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props1.put("useUnicode", "true");
+ props1.put("characterEncoding", "latin1"); // ensure charset isn't utf8 here
+ Connection conn1 = getConnectionWithProps(props1);
+ PreparedStatement pstmt1 =
+ conn1.prepareStatement("INSERT INTO testSetNStringServer (c1) VALUES (?)");
+ try {
+ pstmt1.setNString(1, "aaa");
+ fail();
+ } catch (SQLException e) {
+ // ok
+ assertEquals("Can not call setNString() when connection character set isn't UTF-8",
+ e.getMessage());
+ }
+ pstmt1.close();
+ conn1.close();
+
+ createTable("testSetNStringServer", "(c1 NATIONAL CHARACTER(10))");
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props2.put("useUnicode", "true");
+ props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 =
+ conn2.prepareStatement("INSERT INTO testSetNStringServer (c1) VALUES (?)");
+ pstmt2.setNString(1, "\'aaa\'");
+ pstmt2.execute();
+ ResultSet rs2 = this.stmt.executeQuery("SELECT c1 FROM testSetNStringServer");
+ rs2.next();
+ assertEquals("\'aaa\'", rs2.getString(1));
+ rs2.close();
+ pstmt2.close();
+ conn2.close();
+ }
+
+ /**
+ * Tests for ResultSet.updateNCharacterStream()
+ *
+ * @throws Exception
+ */
+ public void testUpdateNCharacterStream() throws Exception {
+ createTable("testUpdateNCharacterStream",
+ "(c1 CHAR(10) PRIMARY KEY, c2 NATIONAL CHARACTER(10)) default character set sjis");
+ Properties props1 = new Properties();
+ props1.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props1.put("characterEncoding", "UTF-8"); // ensure charset isn't utf8 here
+ Connection conn1 = getConnectionWithProps(props1);
+ PreparedStatement pstmt1 = conn1.prepareStatement(
+ "INSERT INTO testUpdateNCharacterStream (c1, c2) VALUES (?, ?)");
+ pstmt1.setString(1, "1");
+ pstmt1.setNCharacterStream(2, new StringReader("aaa"), 3);
+ pstmt1.execute();
+ Statement stmt1 = conn1.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs1 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNCharacterStream");
+ rs1.next();
+ rs1.updateNCharacterStream("c2", new StringReader("bbb"), 3);
+ rs1.updateRow();
+ rs1.moveToInsertRow();
+ rs1.updateString("c1", "2");
+ rs1.updateNCharacterStream("c2", new StringReader("ccc"), 3);
+ rs1.insertRow();
+ ResultSet rs2 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNCharacterStream");
+ rs2.next();
+ assertEquals("1", rs2.getString("c1"));
+ assertEquals("bbb", rs2.getNString("c2"));
+ rs2.next();
+ assertEquals("2", rs2.getString("c1"));
+ assertEquals("ccc", rs2.getNString("c2"));
+ pstmt1.close();
+ stmt1.close();
+ conn1.close();
+
+ createTable("testUpdateNCharacterStream",
+ "(c1 CHAR(10) PRIMARY KEY, c2 CHAR(10)) default character set sjis"); // sjis field
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props2.put("characterEncoding", "SJIS"); // ensure charset isn't utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 = conn2.prepareStatement(
+ "INSERT INTO testUpdateNCharacterStream (c1, c2) VALUES (?, ?)");
+ pstmt2.setString(1, "1");
+ pstmt2.setString(2, "aaa");
+ pstmt2.execute();
+ Statement stmt2 = conn2.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs3 = stmt2.executeQuery("SELECT c1, c2 FROM testUpdateNCharacterStream");
+ rs3.next();
+ try {
+ rs3.updateNCharacterStream("c2", new StringReader("bbb"), 3); // field's charset isn't utf8
+ fail();
+ } catch (SQLException ex) {
+ assertEquals("Can not call updateNCharacterStream() when field's character set isn't UTF-8",
+ ex.getMessage());
+ }
+ rs3.close();
+ pstmt2.close();
+ stmt2.close();
+ conn2.close();
+ }
+
+ /**
+ * Tests for ResultSet.updateNClob()
+ *
+ * @throws Exception
+ */
+ public void testUpdateNClob() throws Exception {
+ createTable("testUpdateNChlob",
+ "(c1 CHAR(10) PRIMARY KEY, c2 NATIONAL CHARACTER(10)) default character set sjis");
+ Properties props1 = new Properties();
+ props1.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props1.put("characterEncoding", "UTF-8"); // ensure charset isn't utf8 here
+ Connection conn1 = getConnectionWithProps(props1);
+ PreparedStatement pstmt1 = conn1.prepareStatement(
+ "INSERT INTO testUpdateNChlob (c1, c2) VALUES (?, ?)");
+ pstmt1.setString(1, "1");
+ NClob nClob1 = conn1.createNClob();
+ nClob1.setString(1, "aaa");
+ pstmt1.setNClob(2, nClob1);
+ pstmt1.execute();
+ Statement stmt1 = conn1.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs1 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNChlob");
+ rs1.next();
+ NClob nClob2 = conn1.createNClob();
+ nClob2.setString(1, "bbb");
+ rs1.updateNClob("c2", nClob2);
+ rs1.updateRow();
+ rs1.moveToInsertRow();
+ rs1.updateString("c1", "2");
+ NClob nClob3 = conn1.createNClob();
+ nClob3.setString(1, "ccc");
+ rs1.updateNClob("c2", nClob3);
+ rs1.insertRow();
+ ResultSet rs2 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNChlob");
+ rs2.next();
+ assertEquals("1", rs2.getString("c1"));
+ assertEquals("bbb", rs2.getNString("c2"));
+ rs2.next();
+ assertEquals("2", rs2.getString("c1"));
+ assertEquals("ccc", rs2.getNString("c2"));
+ pstmt1.close();
+ stmt1.close();
+ conn1.close();
+
+ createTable("testUpdateNChlob",
+ "(c1 CHAR(10) PRIMARY KEY, c2 CHAR(10)) default character set sjis"); // sjis field
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props2.put("characterEncoding", "SJIS"); // ensure charset isn't utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 = conn2.prepareStatement(
+ "INSERT INTO testUpdateNChlob (c1, c2) VALUES (?, ?)");
+ pstmt2.setString(1, "1");
+ pstmt2.setString(2, "aaa");
+ pstmt2.execute();
+ Statement stmt2 = conn2.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs3 = stmt2.executeQuery("SELECT c1, c2 FROM testUpdateNChlob");
+ rs3.next();
+ NClob nClob4 = conn2.createNClob();
+ nClob4.setString(1, "bbb");
+ try {
+ rs3.updateNClob("c2", nClob4); // field's charset isn't utf8
+ fail();
+ } catch (SQLException ex) {
+ assertEquals("Can not call updateNClob() when field's character set isn't UTF-8",
+ ex.getMessage());
+ }
+ rs3.close();
+ pstmt2.close();
+ stmt2.close();
+ conn2.close();
+ }
+
+ /**
+ * Tests for ResultSet.updateNString()
+ *
+ * @throws Exception
+ */
+ public void testUpdateNString() throws Exception {
+ createTable("testUpdateNString",
+ "(c1 CHAR(10) PRIMARY KEY, c2 NATIONAL CHARACTER(10)) default character set sjis");
+ Properties props1 = new Properties();
+ props1.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props1.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
+ Connection conn1 = getConnectionWithProps(props1);
+ PreparedStatement pstmt1 = conn1.prepareStatement(
+ "INSERT INTO testUpdateNString (c1, c2) VALUES (?, ?)");
+ pstmt1.setString(1, "1");
+ pstmt1.setNString(2, "aaa");
+ pstmt1.execute();
+ Statement stmt1 = conn1.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs1 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNString");
+ rs1.next();
+ rs1.updateNString("c2", "bbb");
+ rs1.updateRow();
+ rs1.moveToInsertRow();
+ rs1.updateString("c1", "2");
+ rs1.updateNString("c2", "ccc");
+ rs1.insertRow();
+ ResultSet rs2 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNString");
+ rs2.next();
+ assertEquals("1", rs2.getString("c1"));
+ assertEquals("bbb", rs2.getNString("c2"));
+ rs2.next();
+ assertEquals("2", rs2.getString("c1"));
+ assertEquals("ccc", rs2.getNString("c2"));
+ pstmt1.close();
+ stmt1.close();
+ conn1.close();
+
+ createTable("testUpdateNString",
+ "(c1 CHAR(10) PRIMARY KEY, c2 CHAR(10)) default character set sjis"); // sjis field
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props2.put("characterEncoding", "SJIS"); // ensure charset isn't utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 = conn2.prepareStatement(
+ "INSERT INTO testUpdateNString (c1, c2) VALUES (?, ?)");
+ pstmt2.setString(1, "1");
+ pstmt2.setString(2, "aaa");
+ pstmt2.execute();
+ Statement stmt2 = conn2.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs3 = stmt2.executeQuery("SELECT c1, c2 FROM testUpdateNString");
+ rs3.next();
+ try {
+ rs3.updateNString("c2", "bbb"); // field's charset isn't utf8
+ fail();
+ } catch (SQLException ex) {
+ assertEquals("Can not call updateNString() when field's character set isn't UTF-8",
+ ex.getMessage());
+ }
+ rs3.close();
+ pstmt2.close();
+ stmt2.close();
+ conn2.close();
+ }
+}
\ No newline at end of file
| Thread |
|---|
| • Connector/J commit: r6342 - in trunk/connector-j: . .settings src/com/mysql/jdbc src/com/mysql/jdbc/exceptions src/com/mysql/jdbc/jdbc2/optional src/c... | mmatthews | 9 Mar |