You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2009/04/30 21:23:21 UTC
svn commit: r770405 - in /openjpa/branches/1.3.x:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
openjpa-persistence-jdbc/pom.xml
Author: mikedd
Date: Thu Apr 30 19:23:20 2009
New Revision: 770405
URL: http://svn.apache.org/viewvc?rev=770405&view=rev
Log:
OPENJPA-1029. Committing patch provided by Donald Woods.
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
openjpa/branches/1.3.x/openjpa-persistence-jdbc/pom.xml
Modified: openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java?rev=770405&r1=770404&r2=770405&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java (original)
+++ openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java Thu Apr 30 19:23:20 2009
@@ -64,49 +64,73 @@
public void connectedConfiguration(Connection conn)
throws SQLException {
super.connectedConfiguration(conn);
-
+ boolean requiresWarnings = true;
DatabaseMetaData meta = conn.getMetaData();
String driverName = meta.getDriverName();
String url = meta.getURL();
if (driverVendor == null) {
- if ("NetDirect JSQLConnect".equals(driverName))
- driverVendor = VENDOR_NETDIRECT;
- else if (driverName != null && driverName.startsWith("jTDS"))
- driverVendor = VENDOR_JTDS;
- else if ("SQLServer".equals(driverName)) {
- if (url != null && url.startsWith("jdbc:microsoft:sqlserver:"))
- driverVendor = VENDOR_MICROSOFT;
- else if (url != null
- && url.startsWith("jdbc:datadirect:sqlserver:"))
- driverVendor = VENDOR_DATADIRECT;
- else
- driverVendor = VENDOR_OTHER;
- } else
+ if (driverName != null) {
+ if (driverName.startsWith("Microsoft SQL Server")) {
+ // v1.1, 1.2 or 2.0 driver
+ driverVendor = VENDOR_MICROSOFT;
+ // serverMajorVersion of 8==2000, 9==2005, 10==2008
+ if (meta.getDatabaseMajorVersion() >= 9)
+ supportsXMLColumn = true;
+ if (meta.getDriverMajorVersion() >= 2) {
+ // see http://blogs.msdn.com/jdbcteam/archive/2007/05/\
+ // 02/what-is-adaptive-response-buffering-and-why-\
+ // should-i-use-it.aspx
+ // 2.0 driver conenctURL automatically includes
+ // responseBuffering=adaptive
+ // and disableStatementPooling=true
+ requiresWarnings = false;
+ }
+ } else {
+ if ("NetDirect JSQLConnect".equals(driverName))
+ driverVendor = VENDOR_NETDIRECT;
+ else if (driverName.startsWith("jTDS"))
+ driverVendor = VENDOR_JTDS;
+ else if ("SQLServer".equals(driverName)) {
+ if (url != null &&
+ url.startsWith("jdbc:microsoft:sqlserver:"))
+ driverVendor = VENDOR_MICROSOFT;
+ else if (url != null
+ && url.startsWith("jdbc:datadirect:sqlserver:"))
+ driverVendor = VENDOR_DATADIRECT;
+ else
+ driverVendor = VENDOR_OTHER;
+ }
+ // old way of determining xml support
+ if (driverName.indexOf(platform) != -1) {
+ String versionString = driverName.
+ substring(platform.length() + 1);
+ if (versionString.indexOf(" ") != -1)
+ versionString = versionString.substring(0,
+ versionString.indexOf(" "));
+ int version = Integer.parseInt(versionString);
+ if (version >= 2005)
+ supportsXMLColumn = true;
+ }
+ }
+ } else {
driverVendor = VENDOR_OTHER;
- if (driverName.indexOf(platform) != -1) {
- String versionString = driverName.
- substring(platform.length() + 1);
- if (versionString.indexOf(" ") != -1)
- versionString = versionString.substring(0,
- versionString.indexOf(" "));
- int version = Integer.parseInt(versionString);
- if (version >= 2005)
- supportsXMLColumn = true;
}
}
- // warn about using cursors
- if ((VENDOR_MICROSOFT.equalsIgnoreCase(driverVendor)
+ // warn about not using cursors for pre-2.0 MS driver
+ // as connectURL includes selectMethod=direct
+ if (((VENDOR_MICROSOFT.equalsIgnoreCase(driverVendor)
+ && requiresWarnings)
|| VENDOR_DATADIRECT.equalsIgnoreCase(driverVendor))
- && url.toLowerCase().indexOf("selectmethod=cursor") == -1)
+ && (url.toLowerCase().indexOf("selectmethod=cursor") == -1))
log.warn(_loc.get("sqlserver-cursor", url));
- // warn about prepared statement caching if using ms driver
+ // warn about prepared statement caching if using pre-2.0 MS drivers
+ // as connectURL includes responseBuffering=full
String props = conf.getConnectionFactoryProperties();
- if (props == null)
- props = "";
- if (VENDOR_MICROSOFT.equalsIgnoreCase(driverVendor)
- && props.toLowerCase().indexOf("maxcachedstatements=0") == -1)
+ if ((props != null) &&
+ VENDOR_MICROSOFT.equalsIgnoreCase(driverVendor) && requiresWarnings
+ && (props.toLowerCase().indexOf("maxcachedstatements=0") == -1))
log.warn(_loc.get("sqlserver-cachedstmnts"));
}
@@ -141,7 +165,8 @@
protected void appendLength(SQLBuffer buf, int type) {
if (type == Types.VARCHAR)
- buf.append("(").append(Integer.toString(characterColumnSize)).append(")");
+ buf.append("(").append(Integer.toString(characterColumnSize)).
+ append(")");
}
/**
Modified: openjpa/branches/1.3.x/openjpa-persistence-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/pom.xml?rev=770405&r1=770404&r2=770405&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/pom.xml (original)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/pom.xml Thu Apr 30 19:23:20 2009
@@ -128,6 +128,69 @@
</properties>
</profile>
+ <!-- Profile for testing with SQLServer DB using MS JDBC driver -->
+ <profile>
+ <!--
+ Example MS SQL profile. You can use this profile if you:
+ 1) have the MS SQL artifacts installed in a local repo and
+ supply the URL:
+ -Dmssql.maven.repo=http://my.local.repo
+ 2) have a copy of the MS SQL JDBC driver from:
+ http://msdn.microsoft.com/en-us/data/aa937724.aspx
+ and run the following commands :
+ mvn install:install-file -Dfile=${path to sqljdbc.jar} \
+ -DgroupId=com.microsoft.sqlserver \
+ -DartifactId=sqljdbc \
+ -Dversion=2.0 \
+ -Dpackaging=jar
+
+ You must also set the following properties:
+ -Dopenjpa.mssql.url=jdbc:sqlserver://<HOST>:<PORT>;\
+ DataBaseName=<DBNAME>
+ -Dopenjpa.mssql.username=<mssql_uid>
+ -Dopenjpa.mssql.password=<mssql_pwd>
+
+ Optionally, you can override the default groupId and version
+ by also supplying the following properties:
+ -Dmssql.groupid=com.microsoft.sqlserver
+ -Dmssql.version=2.0
+ -->
+ <id>test-mssql</id>
+ <dependencies>
+ <dependency>
+ <groupId>${mssql.groupid}</groupId>
+ <artifactId>${mssql.artifactid}</artifactId>
+ <version>${mssql.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <properties>
+ <mssql.maven.repo>http://not.real.repository</mssql.maven.repo>
+ <mssql.groupid>com.microsoft.sqlserver</mssql.groupid>
+ <mssql.artifactid>sqljdbc</mssql.artifactid>
+ <mssql.version>2.0</mssql.version>
+ <connection.driver.name>com.microsoft.sqlserver.jdbc.SQLServerDriver</connection.driver.name>
+ <connection.url>${openjpa.mssql.url}</connection.url>
+ <connection.username>${openjpa.mssql.username}</connection.username>
+ <connection.password>${openjpa.mssql.password}</connection.password>
+ </properties>
+ <repositories>
+ <repository>
+ <id>mssql.repository</id>
+ <name>MSSQL Repository</name>
+ <url>${mssql.maven.repo}</url>
+ <layout>default</layout>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ <checksumPolicy>ignore</checksumPolicy>
+ </releases>
+ </repository>
+ </repositories>
+ </profile>
+
<!-- Profile for testing with SQLServer DB using the jTDS driver -->
<profile>
<id>test-sqlserver</id>