Permalink
Browse files

Merge pull request #31 from koentsje/4.0.x-devel

4.0.x devel
  • Loading branch information...
2 parents 6930bb3 + 3ed4f65 commit a512bc1f69590769bf09239c21a0dffbfce20030 @koentsje koentsje committed Sep 13, 2012
View
78 pom.xml
@@ -147,12 +147,12 @@
<version>r8-20060801</version>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>org.eclipse.jdt</groupId>
- <artifactId>core</artifactId>
- <version>3.2.0.666</version>
- <scope>compile</scope>
- </dependency>
+ <dependency>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>org.eclipse.jdt.core</artifactId>
+ <version>3.8.0.v_C03</version>
+ <scope>compile</scope>
+ </dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>text</artifactId>
@@ -498,6 +498,7 @@
<jdbc.driver.groupId>com.h2database</jdbc.driver.groupId>
<jdbc.driver.artifactId>h2</jdbc.driver.artifactId>
<db.dialect>org.hibernate.dialect.H2Dialect</db.dialect>
+ <jdbc.driver.jdbc.driver.version>1.2.124</jdbc.driver.jdbc.driver.version>
<jdbc.driver>org.h2.Driver</jdbc.driver>
<jdbc.url>jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE</jdbc.url>
<jdbc.user>sa</jdbc.user>
@@ -676,10 +677,10 @@
<profile>
<id>oracle9i</id>
<properties>
- <jdbc.driver.groupId>com.oracle</jdbc.driver.groupId>
- <jdbc.driver.artifactId>ojdbc14</jdbc.driver.artifactId>
- <!-- use the 10g drivers which are surprisingly largely bug free -->
- <jdbc.driver.version>10.0.2.0</jdbc.driver.version>
+ <jdbc.driver.groupId>com.oracle</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>ojdbc14</jdbc.driver.artifactId>
+ <!-- use the 10g drivers which are surprisingly largely bug free -->
+ <jdbc.driver.jdbc.driver.version>10.0.2.0</jdbc.driver.jdbc.driver.version>
<db.dialect>org.hibernate.dialect.Oracle9iDialect</db.dialect>
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
<jdbc.url>jdbc:oracle:thin:@dev20.qa.atl.jboss.com:1521:qa</jdbc.url>
@@ -693,10 +694,10 @@
<profile>
<id>oracle10g</id>
<properties>
- <jdbc.driver.groupId>com.oracle</jdbc.driver.groupId>
- <jdbc.driver.artifactId>ojdbc14</jdbc.driver.artifactId>
- <!-- use the 10g drivers which are surprisingly largely bug free -->
- <jdbc.driver.version>10.0.2.0</jdbc.driver.version>
+ <jdbc.driver.groupId>com.oracle</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>ojdbc14</jdbc.driver.artifactId>
+ <!-- use the 10g drivers which are surprisingly largely bug free -->
+ <jdbc.driver.jdbc.driver.version>10.0.2.0</jdbc.driver.jdbc.driver.version>
<db.dialect>org.hibernate.dialect.Oracle10gDialect</db.dialect>
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
<jdbc.url>jdbc:oracle:thin:@vmg05.mw.lab.eng.bos.redhat.com:1521:qaora10</jdbc.url>
@@ -710,9 +711,9 @@
<profile>
<id>oracle11g</id>
<properties>
- <jdbc.driver.groupId>com.oracle</jdbc.driver.groupId>
- <jdbc.driver.artifactId>ojdbc5</jdbc.driver.artifactId>
- <jdbc.driver.version>11.1.0.7.0</jdbc.driver.version>
+ <jdbc.driver.groupId>com.oracle</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>ojdbc5</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>11.1.0.7.0</jdbc.driver.jdbc.driver.version>
<db.dialect>org.hibernate.dialect.Oracle10gDialect</db.dialect>
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
<jdbc.url>jdbc:oracle:thin:@dev04.qa.atl2.redhat.com:1521:qaora11</jdbc.url>
@@ -726,10 +727,10 @@
<profile>
<id>oracle11gRAC</id>
<properties>
- <jdbc.driver.groupId>com.oracle</jdbc.driver.groupId>
- <jdbc.driver.artifactId>ojdbc5</jdbc.driver.artifactId>
- <jdbc.driver.version>11.1.0.7.0</jdbc.driver.version>
- <scope>test</scope>
+ <jdbc.driver.groupId>com.oracle</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>ojdbc5</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>11.1.0.7.0</jdbc.driver.jdbc.driver.version>
+ <scope>test</scope>
<db.dialect>org.hibernate.dialect.Oracle10gDialect</db.dialect>
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
<jdbc.url>
@@ -745,9 +746,9 @@
<profile>
<id>sybase15</id>
<properties>
- <jdbc.driver.groupId>com.sybase</jdbc.driver.groupId>
- <jdbc.driver.artifactId>jconnect</jdbc.driver.artifactId>
- <jdbc.driver.version>6.0.5</jdbc.driver.version>
+ <jdbc.driver.groupId>com.sybase</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>jconnect</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>6.0.5</jdbc.driver.jdbc.driver.version>
<db.dialect>org.hibernate.dialect.SybaseASE15Dialect</db.dialect>
<jdbc.driver>com.sybase.jdbc3.jdbc.SybDriver</jdbc.driver>
<jdbc.url>jdbc:sybase:Tds:vmg07.mw.lab.eng.bos.redhat.com:5000/hibbrtru</jdbc.url>
@@ -761,9 +762,9 @@
<profile>
<id>mssql2005</id>
<properties>
- <jdbc.driver.groupId>com.microsoft.sqlserver</jdbc.driver.groupId>
- <jdbc.driver.artifactId>msjdbc</jdbc.driver.artifactId>
- <jdbc.driver.version>2.0.1008.2</jdbc.driver.version>
+ <jdbc.driver.groupId>com.microsoft.sqlserver</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>msjdbc</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>2.0.1008.2</jdbc.driver.jdbc.driver.version>
<db.dialect>org.hibernate.dialect.SQLServerDialect</db.dialect>
<jdbc.driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbc.driver>
<jdbc.url>jdbc:sqlserver://dev30.qa.atl.jboss.com:3918</jdbc.url>
@@ -772,15 +773,30 @@
<jdbc.isolation>4096</jdbc.isolation>
</properties>
</profile>
+
+ <!-- The SQLServer2005 (MS JDBC) test envionment -->
+ <profile>
+ <id>mssql2005_jtds</id>
+ <properties>
+ <jdbc.driver.groupId>net.sourceforge.jtds</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>jtds</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>1.2.4</jdbc.driver.jdbc.driver.version><!-- newest is 1.2.5 but not in repo -->
+ <db.dialect>org.hibernate.dialect.SQLServerDialect</db.dialect>
+ <jdbc.driver>net.sourceforge.jtds.jdbc.Driver</jdbc.driver>
+ <jdbc.url>jdbc:jtds:sqlserver://dev30.qa.atl.jboss.com:3918</jdbc.url>
+ <jdbc.user>hibbrtru</jdbc.user>
+ <jdbc.pass>hibbrtru</jdbc.pass>
+ <jdbc.isolation>4096</jdbc.isolation>
+ </properties>
+ </profile>
<!-- The SQLServer2005 (MS JDBC) test envionment -->
<profile>
<id>mssql2008</id>
<properties>
- <jdbc.driver.groupId>com.microsoft.sqlserver</jdbc.driver.groupId>
- <jdbc.driver.artifactId>msjdbc</jdbc.driver.artifactId>
- <jdbc.driver.version>2.0.1008.2</jdbc.driver.version>
-
+ <jdbc.driver.groupId>com.microsoft.sqlserver</jdbc.driver.groupId>
+ <jdbc.driver.artifactId>msjdbc</jdbc.driver.artifactId>
+ <jdbc.driver.jdbc.driver.version>2.0.1008.2</jdbc.driver.jdbc.driver.version>
<db.dialect>org.hibernate.dialect.SQLServerDialect</db.dialect>
<jdbc.driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbc.driver>
<jdbc.url>jdbc:sqlserver://vmg04.mw.lab.eng.bos.redhat.com:1433</jdbc.url>
@@ -8,13 +8,15 @@
import org.hibernate.cfg.reveng.dialect.MetaDataDialect;
import org.hibernate.cfg.reveng.dialect.MySQLMetaDataDialect;
import org.hibernate.cfg.reveng.dialect.OracleMetaDataDialect;
+//import org.hibernate.cfg.reveng.dialect.SQLServerMetaDataDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.dialect.Oracle9Dialect;
import org.hibernate.internal.util.ReflectHelper;
+//import org.hibernate.dialect.SQLServerDialect;
public class MetaDataDialectFactory {
@@ -60,6 +62,8 @@ public MetaDataDialect fromDialect(Dialect dialect) {
return new MySQLMetaDataDialect();
} else if (dialect instanceof HSQLDialect) {
return new HSQLMetaDataDialect();
+// }else if (dialect instanceof SQLServerDialect) {
+// return new SQLServerMetaDataDialect();
}
}
return null;
@@ -78,6 +82,9 @@ public MetaDataDialect fromDialectName(String dialect) {
if (dialect.toLowerCase().contains("hsql")) {
return new HSQLMetaDataDialect();
}
+// if (dialect.toLowerCase().contains("sqlserver")) {
+// return new SQLServerMetaDataDialect();
+// }
return null;
}
@@ -128,14 +128,25 @@ public static String toUpperCamelCase(String s) {
static public String simplePluralize(String singular) {
char last = singular.charAt( singular.length()-1 );
+ Character prev = singular.length() > 1 ? singular.charAt( singular.length() - 2 ) : null;
+ String vowels = "aeiouy";
switch (last) {
case 'x':
case 's':
singular += "es";
break;
case 'y':
- singular = singular.substring( 0, singular.length()-1 ) + "ies";
+ if (prev != null && vowels.indexOf(prev) >= 0){
+ singular += "s";
+ } else {
+ singular = singular.substring( 0, singular.length()-1 ) + "ies";
+ }
break;
+ case 'h':
+ if (prev == 'c' || prev == 's'){
+ singular += "es";
+ break;
+ }
default:
singular += "s";
}
@@ -40,14 +40,14 @@ public OracleMetaDataDialect() {
private static final String SQL_TABLE_NONE = SQL_TABLE_BASE + SQL_TABLE_VIEW;
private static final String SQL_TABLE_SCHEMA = SQL_TABLE_BASE
- + "where a.owner = ? " + SQL_TABLE_VIEW + " where owner = ?";
+ + "where a.owner like ? " + SQL_TABLE_VIEW + " where owner like ?";
private static final String SQL_TABLE_TABLE = SQL_TABLE_BASE
- + "where a.table_name = ?" + SQL_TABLE_VIEW + "where view_name = ?";
+ + "where a.table_name like ?" + SQL_TABLE_VIEW + "where view_name like ?";
private static final String SQL_TABLE_SCHEMA_AND_TABLE = SQL_TABLE_BASE
- + "where a.owner = ? and a.table_name = ?" + SQL_TABLE_VIEW
- + "where owner = ? and view_name = ?";
+ + "where a.owner like ? and a.table_name like ?" + SQL_TABLE_VIEW
+ + "where owner like ? and view_name like ?";
private PreparedStatement prepTableNone;
@@ -74,13 +74,13 @@ public OracleMetaDataDialect() {
+ SQL_INDEX_ORDER;
private static final String SQL_INDEX_SCHEMA = SQL_INDEX_BASE
- + "where a.table_owner = ? " + SQL_INDEX_ORDER;
+ + "where a.table_owner like ? " + SQL_INDEX_ORDER;
private static final String SQL_INDEX_TABLE = SQL_INDEX_BASE
- + "where a.table_name = ? " + SQL_INDEX_ORDER;
+ + "where a.table_name like ? " + SQL_INDEX_ORDER;
private static final String SQL_INDEX_SCHEMA_AND_TABLE = SQL_INDEX_BASE
- + "where a.table_owner = ? and a.table_name = ? " + SQL_INDEX_ORDER;
+ + "where a.table_owner like ? and a.table_name like ? " + SQL_INDEX_ORDER;
private PreparedStatement prepIndexNone;
@@ -112,26 +112,26 @@ public OracleMetaDataDialect() {
+ SQL_COLUMN_ORDER;
private static final String SQL_COLUMN_SCHEMA = SQL_COLUMN_BASE
- + "where a.owner = ? " + SQL_COLUMN_ORDER;
+ + "where a.owner like ? " + SQL_COLUMN_ORDER;
private static final String SQL_COLUMN_TABLE = SQL_COLUMN_BASE
- + "where a.table_name = ? " + SQL_COLUMN_ORDER;
+ + "where a.table_name like ? " + SQL_COLUMN_ORDER;
private static final String SQL_COLUMN_COLUMN = SQL_COLUMN_BASE
- + "where a.column_name = ? " + SQL_COLUMN_ORDER;
+ + "where a.column_name like ? " + SQL_COLUMN_ORDER;
private static final String SQL_COLUMN_SCHEMA_AND_TABLE = SQL_COLUMN_BASE
- + "where a.owner = ? and a.table_name = ? " + SQL_COLUMN_ORDER;
+ + "where a.owner like ? and a.table_name like ? " + SQL_COLUMN_ORDER;
private static final String SQL_COLUMN_SCHEMA_AND_COLUMN = SQL_COLUMN_BASE
- + "where a.owner = ? and a.column_name = ? " + SQL_COLUMN_ORDER;
+ + "where a.owner like ? and a.column_name like ? " + SQL_COLUMN_ORDER;
private static final String SQL_COLUMN_TABLE_AND_COLUMN = SQL_COLUMN_BASE
- + "where a.table_name = ? and a.column_name = ? "
+ + "where a.table_name like ? and a.column_name like ? "
+ SQL_COLUMN_ORDER;
private static final String SQL_COLUMN_SCHEMA_AND_TABLE_AND_COLUMN = SQL_COLUMN_BASE
- + "where a.owner = ? and a.table_name = ? and a.column_name = ? "
+ + "where a.owner like ? and a.table_name like ? and a.column_name like ? "
+ SQL_COLUMN_ORDER;
private PreparedStatement prepColumnNone;
@@ -163,13 +163,13 @@ public OracleMetaDataDialect() {
private static final String SQL_PK_NONE = SQL_PK_BASE + SQL_PK_ORDER;
private static final String SQL_PK_SCHEMA = SQL_PK_BASE
- + " and c.owner = ? " + SQL_PK_ORDER;
+ + " and c.owner like ? " + SQL_PK_ORDER;
private static final String SQL_PK_TABLE = SQL_PK_BASE
- + " and c.table_name = ? " + SQL_PK_ORDER;
+ + " and c.table_name like ? " + SQL_PK_ORDER;
private static final String SQL_PK_SCHEMA_AND_TABLE = SQL_PK_BASE
- + " and c.owner = ? and c.table_name = ? " + SQL_PK_ORDER;
+ + " and c.owner like ? and c.table_name like ? " + SQL_PK_ORDER;
private PreparedStatement prepPkNone;
@@ -196,13 +196,13 @@ public OracleMetaDataDialect() {
private static final String SQL_FK_NONE = SQL_FK_BASE + SQL_FK_ORDER;
private static final String SQL_FK_SCHEMA = SQL_FK_BASE
- + " and p.owner = ? " + SQL_FK_ORDER;
+ + " and p.owner like ? " + SQL_FK_ORDER;
private static final String SQL_FK_TABLE = SQL_FK_BASE
- + " and p.table_name = ? " + SQL_FK_ORDER;
+ + " and p.table_name like ? " + SQL_FK_ORDER;
private static final String SQL_FK_SCHEMA_AND_TABLE = SQL_FK_BASE
- + " and p.owner = ? and p.table_name = ? " + SQL_FK_ORDER;
+ + " and p.owner like ? and p.table_name like ? " + SQL_FK_ORDER;
private PreparedStatement prepFkNone;
@@ -0,0 +1,74 @@
+package org.hibernate.cfg.reveng.dialect;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ *
+ * @author ddukker
+ *
+ */
+public class SQLServerMetaDataDialect extends JDBCMetaDataDialect {
+
+ public Iterator getSuggestedPrimaryKeyStrategyName(String catalog, String schema, String table) {
+ String sql = null;
+ try {
+ catalog = caseForSearch( catalog );
+ schema = caseForSearch( schema );
+ table = caseForSearch( table );
+
+ log.debug("geSuggestedPrimaryKeyStrategyName(" + catalog + "." + schema + "." + table + ")");
+
+ sql = "SELECT a.TABLE_CATALOG, a.TABLE_SCHEMA, a.TABLE_NAME as table_name, c.DATA_TYPE as data_type, b.CONSTRAINT_TYPE, OBJECTPROPERTY(OBJECT_ID(a.TABLE_NAME),'TableHasIdentity') as hasIdentity " +
+ "FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE a " +
+ "INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS b on a.CONSTRAINT_NAME = b.CONSTRAINT_NAME " +
+ "INNER JOIN INFORMATION_SCHEMA.Columns c on a.TABLE_CATALOG = c.TABLE_CATALOG AND a.TABLE_SCHEMA = c.TABLE_SCHEMA AND a.TABLE_NAME = c.TABLE_NAME AND a.COLUMN_NAME = c.COLUMN_NAME " +
+ "WHERE a.TABLE_NAME='"+table+"' AND a.TABLE_SCHEMA='"+schema+"' AND a.TABLE_CATALOG='"+catalog+"' AND b.CONSTRAINT_TYPE = 'Primary key'";
+
+ PreparedStatement statement = getConnection().prepareStatement( sql );
+
+ final String sc = schema;
+ final String cat = catalog;
+ return new ResultSetIterator(statement.executeQuery(), getSQLExceptionConverter()) {
+
+ Map element = new HashMap();
+ protected Object convertRow(ResultSet tableRs) throws SQLException {
+ element.clear();
+ element.put("TABLE_NAME", tableRs.getString("table_name"));
+ element.put("TABLE_SCHEM", sc);
+ element.put("TABLE_CAT", cat);
+
+ String string = tableRs.getString("data_type");
+
+ boolean bool = tableRs.getBoolean("hasIdentity");
+ if(string!=null) {
+ if(string.equalsIgnoreCase("uniqueidentifier")){
+ element.put("HIBERNATE_STRATEGY", "guid");
+ }else if(bool){
+ element.put("HIBERNATE_STRATEGY", "identity");
+ }else{
+ element.put("HIBERNATE_STRATEGY", null);
+ }
+ }else {
+ element.put("HIBERNATE_STRATEGY", null);
+ }
+ return element;
+ }
+ protected Throwable handleSQLException(SQLException e) {
+ // schemaRs and catalogRs are only used for error reporting if
+ // we get an exception
+ throw getSQLExceptionConverter().convert( e,
+ "Could not get list of suggested identity strategies from database. Probably a JDBC driver problem. ", null);
+ }
+ };
+ } catch (SQLException e) {
+ throw getSQLExceptionConverter().convert(e, "Could not get list of suggested identity strategies from database. Probably a JDBC driver problem. ", sql);
+ }
+ }
+
+ }
+
Oops, something went wrong.

0 comments on commit a512bc1

Please sign in to comment.