Author: tomdz
Date: Tue Feb 7 15:47:10 2006
New Revision: 375780
URL: http://svn.apache.org/viewcvs?rev=375780&view=rev
Log:
Fixed/enhanced support for Sql Server
Added support for the new Sql Server 2005 jdbc driver
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformUtils.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformUtils.java
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformUtils.java?rev=375780&r1=375779&r2=375780&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformUtils.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformUtils.java Tue Feb
7 15:47:10 2006
@@ -150,6 +150,8 @@
jdbcSubProtocolToPlatform.put(SapDbPlatform.JDBC_SUBPROTOCOL,
MaxDbPlatform.DATABASENAME);
jdbcSubProtocolToPlatform.put(MckoiPlatform.JDBC_SUBPROTOCOL,
MckoiPlatform.DATABASENAME);
jdbcSubProtocolToPlatform.put(MSSqlPlatform.JDBC_SUBPROTOCOL,
MSSqlPlatform.DATABASENAME);
+ jdbcSubProtocolToPlatform.put(MSSqlPlatform.JDBC_SUBPROTOCOL_NEW,
MSSqlPlatform.DATABASENAME);
+ jdbcSubProtocolToPlatform.put(MSSqlPlatform.JDBC_SUBPROTOCOL_INTERNAL,
MSSqlPlatform.DATABASENAME);
jdbcSubProtocolToPlatform.put(PlatformUtils.JDBC_SUBPROTOCOL_DATADIRECT_SQLSERVER,
MSSqlPlatform.DATABASENAME);
jdbcSubProtocolToPlatform.put(PlatformUtils.JDBC_SUBPROTOCOL_INET_SQLSERVER,
MSSqlPlatform.DATABASENAME);
jdbcSubProtocolToPlatform.put(PlatformUtils.JDBC_SUBPROTOCOL_INET_SQLSERVER6,
MSSqlPlatform.DATABASENAME);
@@ -193,6 +195,7 @@
jdbcDriverToPlatform.put(SapDbPlatform.JDBC_DRIVER,
MaxDbPlatform.DATABASENAME);
jdbcDriverToPlatform.put(MckoiPlatform.JDBC_DRIVER,
MckoiPlatform.DATABASENAME);
jdbcDriverToPlatform.put(MSSqlPlatform.JDBC_DRIVER,
MSSqlPlatform.DATABASENAME);
+ jdbcDriverToPlatform.put(MSSqlPlatform.JDBC_DRIVER_NEW,
MSSqlPlatform.DATABASENAME);
jdbcDriverToPlatform.put(PlatformUtils.JDBC_DRIVER_DATADIRECT_SQLSERVER,
MSSqlPlatform.DATABASENAME);
jdbcDriverToPlatform.put(PlatformUtils.JDBC_DRIVER_INET_SQLSERVER,
MSSqlPlatform.DATABASENAME);
jdbcDriverToPlatform.put(PlatformUtils.JDBC_DRIVER_JSQLCONNECT_SQLSERVER,
MSSqlPlatform.DATABASENAME);
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java?rev=375780&r1=375779&r2=375780&view=diff
==============================================================================
---
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java
(original)
+++
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java
Tue Feb 7 15:47:10 2006
@@ -17,6 +17,9 @@
*/
import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.sql.Types;
import java.util.Map;
import org.apache.ddlutils.PlatformInfo;
@@ -26,6 +29,7 @@
import org.apache.ddlutils.model.Index;
import org.apache.ddlutils.model.Table;
import org.apache.ddlutils.platform.SqlBuilder;
+import org.apache.ddlutils.util.Jdbc3Utils;
/**
* The SQL Builder for the Microsoft SQL Server.
@@ -60,8 +64,24 @@
*/
protected void alterTable(Database currentModel, Table currentTable,
Database desiredModel, Table desiredTable, boolean doDrops, boolean
modifyColumns) throws IOException
{
- writeQuotationOnStatement();
+ // we only want to generate the quotation start statement if there is
something to write
+ // thus we write the alteration commands into a temporary writer
+ // and only if something was written, write the quotation start
statement and the
+ // alteration commands to the original writer
+ Writer originalWriter = getWriter();
+ StringWriter tempWriter = new StringWriter();
+
+ setWriter(tempWriter);
super.alterTable(currentModel, currentTable, desiredModel,
desiredTable, doDrops, modifyColumns);
+ setWriter(originalWriter);
+
+ String alterationCommands = tempWriter.toString();
+
+ if (alterationCommands.trim().length() > 0)
+ {
+ writeQuotationOnStatement();
+ getWriter().write(alterationCommands);
+ }
}
/**
@@ -110,6 +130,23 @@
{
writeQuotationOnStatement();
super.dropExternalForeignKeys(table);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ protected String getNativeDefaultValue(Column column)
+ {
+ // Sql Server wants BIT default values as 0 or 1
+ if ((column.getTypeCode() == Types.BIT) ||
+ (Jdbc3Utils.supportsJava14JdbcTypes() && (column.getTypeCode() ==
Jdbc3Utils.determineBooleanTypeCode())))
+ {
+ return getDefaultValueHelper().convert(column.getDefaultValue(),
column.getTypeCode(), Types.SMALLINT).toString();
+ }
+ else
+ {
+ return super.getNativeDefaultValue(column);
+ }
}
/**
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java?rev=375780&r1=375779&r2=375780&view=diff
==============================================================================
---
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java
(original)
+++
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java
Tue Feb 7 15:47:10 2006
@@ -30,11 +30,17 @@
public class MSSqlPlatform extends PlatformImplBase
{
/** Database name of this platform. */
- public static final String DATABASENAME = "MsSql";
+ public static final String DATABASENAME = "MsSql";
/** The standard SQLServer jdbc driver. */
- public static final String JDBC_DRIVER =
"com.microsoft.jdbc.sqlserver.SQLServerDriver";
- /** The subprotocol used by the standard SQLServer driver. */
- public static final String JDBC_SUBPROTOCOL = "microsoft:sqlserver";
+ public static final String JDBC_DRIVER =
"com.microsoft.jdbc.sqlserver.SQLServerDriver";
+ /** The new SQLServer 2005 jdbc driver which can also be used for SQL
Server 2000. */
+ public static final String JDBC_DRIVER_NEW =
"com.microsoft.sqlserver.jdbc.SQLServerDriver";
+ /** The subprotocol used by the standard SQL Server driver. */
+ public static final String JDBC_SUBPROTOCOL = "microsoft:sqlserver";
+ /** The subprotocol recommended for the newer SQL Server 2005 driver. */
+ public static final String JDBC_SUBPROTOCOL_NEW = "sqlserver";
+ /** The subprotocol internally returned by the newer SQL Server 2005
driver. */
+ public static final String JDBC_SUBPROTOCOL_INTERNAL = "sqljdbc";
/**
* Creates a new platform instance.
@@ -51,27 +57,29 @@
//info.setCommentPrefix("#");
info.addNativeTypeMapping(Types.ARRAY, "IMAGE");
+ // BIGINT will be mapped back to BIGINT by the model reader
info.addNativeTypeMapping(Types.BIGINT, "DECIMAL(19,0)");
- info.addNativeTypeMapping(Types.BLOB, "IMAGE");
- info.addNativeTypeMapping(Types.CLOB, "TEXT");
- info.addNativeTypeMapping(Types.DATE, "DATETIME");
+ info.addNativeTypeMapping(Types.BLOB, "IMAGE",
Types.LONGVARBINARY);
+ info.addNativeTypeMapping(Types.CLOB, "TEXT",
Types.LONGVARCHAR);
+ info.addNativeTypeMapping(Types.DATE, "DATETIME",
Types.TIMESTAMP);
info.addNativeTypeMapping(Types.DISTINCT, "IMAGE");
- info.addNativeTypeMapping(Types.DOUBLE, "FLOAT");
+ info.addNativeTypeMapping(Types.DOUBLE, "FLOAT",
Types.FLOAT);
info.addNativeTypeMapping(Types.INTEGER, "INT");
- info.addNativeTypeMapping(Types.JAVA_OBJECT, "IMAGE");
+ info.addNativeTypeMapping(Types.JAVA_OBJECT, "IMAGE",
Types.LONGVARBINARY);
info.addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE");
info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT");
- info.addNativeTypeMapping(Types.NULL, "IMAGE");
- info.addNativeTypeMapping(Types.OTHER, "IMAGE");
- info.addNativeTypeMapping(Types.REF, "IMAGE");
- info.addNativeTypeMapping(Types.STRUCT, "IMAGE");
- info.addNativeTypeMapping(Types.TIME, "DATETIME");
+ info.addNativeTypeMapping(Types.NULL, "IMAGE",
Types.LONGVARBINARY);
+ info.addNativeTypeMapping(Types.OTHER, "IMAGE",
Types.LONGVARBINARY);
+ info.addNativeTypeMapping(Types.REF, "IMAGE",
Types.LONGVARBINARY);
+ info.addNativeTypeMapping(Types.STRUCT, "IMAGE",
Types.LONGVARBINARY);
+ info.addNativeTypeMapping(Types.TIME, "DATETIME",
Types.TIMESTAMP);
info.addNativeTypeMapping(Types.TIMESTAMP, "DATETIME");
- info.addNativeTypeMapping(Types.TINYINT, "SMALLINT");
- info.addNativeTypeMapping("BOOLEAN", "BIT");
- info.addNativeTypeMapping("DATALINK", "IMAGE");
+ info.addNativeTypeMapping(Types.TINYINT, "SMALLINT",
Types.SMALLINT);
+ info.addNativeTypeMapping("BOOLEAN", "BIT", "BIT");
+ info.addNativeTypeMapping("DATALINK", "IMAGE", "LONGVARBINARY");
setSqlBuilder(new MSSqlBuilder(info));
+ setModelReader(new MSSqlModelReader(info));
}
/**