Author: thomas.heute(a)jboss.com
Date: 2008-07-17 06:29:52 -0400 (Thu, 17 Jul 2008)
New Revision: 11473
Added:
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/DialectFactory.java
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/conf/hibernate/instance/domain.hbm.xml
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/conf/hibernate/portal/domain.hbm.xml
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
Log:
- Sybase fixings
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/conf/hibernate/instance/domain.hbm.xml
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/conf/hibernate/instance/domain.hbm.xml 2008-07-17
10:10:18 UTC (rev 11472)
+++
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/conf/hibernate/instance/domain.hbm.xml 2008-07-17
10:29:52 UTC (rev 11473)
@@ -69,7 +69,7 @@
fetch="join">
<cache usage="@portal.hibernate.cache.usage(a)"/>
<key column="INSTANCE_PK"/>
- <index column="ROLE" type="string"/>
+ <index column="`ROLE`" type="string"/>
<one-to-many
class="org.jboss.portal.core.impl.model.instance.persistent.PersistentRoleSecurityBinding"/>
</map>
<map
@@ -148,7 +148,7 @@
</id>
<property
name="role"
- column="ROLE"
+ column="`ROLE`"
not-null="true"
unique="false"/>
<set
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/conf/hibernate/portal/domain.hbm.xml
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/conf/hibernate/portal/domain.hbm.xml 2008-07-17
10:10:18 UTC (rev 11472)
+++
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/conf/hibernate/portal/domain.hbm.xml 2008-07-17
10:29:52 UTC (rev 11473)
@@ -41,7 +41,7 @@
<natural-id>
<property
name="path"
- column="PATH"
+ column="`PATH`"
type="org.jboss.portal.core.impl.model.portal.PortalObjectIdUserType"
not-null="false"
unique="false"/>
@@ -83,7 +83,7 @@
<cache usage="@portal.hibernate.cache.usage(a)"/>
<key column="NODE_KEY"/>
<index
- column="ROLE"
+ column="`ROLE`"
type="string"/>
<one-to-many
class="org.jboss.portal.core.impl.model.portal.ObjectNodeSecurityConstraint"/>
</map>
@@ -191,7 +191,7 @@
</id>
<property
name="role"
- column="ROLE"
+ column="`ROLE`"
not-null="true"
unique="false"/>
<set
Copied:
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/DialectFactory.java
(from rev 11462,
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/DialectFactory.java)
===================================================================
---
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/DialectFactory.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/DialectFactory.java 2008-07-17
10:29:52 UTC (rev 11473)
@@ -0,0 +1,119 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software 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 *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.jems.hibernate;
+
+import org.hibernate.HibernateException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Ripped off hibernate 3.1 that is not in 3.0. A factory for generating Dialect
instances.
+ *
+ * @author Steve Ebersole
+ * @version $Revision$
+ */
+public class DialectFactory
+{
+
+
+ private DialectFactory()
+ {
+ }
+
+ /**
+ * Determine the appropriate Dialect to use given the database product name and major
version.
+ *
+ * @param databaseName The name of the database product (obtained from
metadata).
+ * @param databaseMajorVersion The major version of the database product (obtained
from metadata).
+ * @return An appropriate dialect instance.
+ */
+ public static String determineDialect(String databaseName, int databaseMajorVersion)
+ {
+ if (databaseName == null)
+ {
+ throw new HibernateException("Hibernate Dialect must be explicitly
set");
+ }
+
+ DatabaseDialectMapper mapper = (DatabaseDialectMapper)MAPPERS.get(databaseName);
+ if (mapper == null)
+ {
+ throw new HibernateException("Hibernate Dialect must be explicitly set for
database: " + databaseName);
+ }
+
+ return mapper.getDialectClass(databaseMajorVersion);
+ }
+
+ /**
+ * For a given database product name, instances of DatabaseDialectMapper know which
Dialect to use for different
+ * versions.
+ */
+ public static interface DatabaseDialectMapper
+ {
+ public String getDialectClass(int majorVersion);
+ }
+
+ /** A simple DatabaseDialectMapper for dialects which are independent of the
underlying database product version. */
+ public static class VersionInsensitiveMapper implements DatabaseDialectMapper
+ {
+ private String dialectClassName;
+
+ public VersionInsensitiveMapper(String dialectClassName)
+ {
+ this.dialectClassName = dialectClassName;
+ }
+
+ public String getDialectClass(int majorVersion)
+ {
+ return dialectClassName;
+ }
+ }
+
+ private static final Map MAPPERS = new HashMap();
+
+ static
+ {
+ // TODO : this is the stuff it'd be nice to move to a properties file or some
other easily user-editable place
+ MAPPERS.put("HSQL Database Engine", new
VersionInsensitiveMapper("org.hibernate.dialect.HSQLDialect"));
+ MAPPERS.put("DB2/NT", new
VersionInsensitiveMapper("org.hibernate.dialect.DB2Dialect"));
+ MAPPERS.put("MySQL", new
VersionInsensitiveMapper("org.hibernate.dialect.MySQLDialect"));
+ MAPPERS.put("PostgreSQL", new
VersionInsensitiveMapper("org.hibernate.dialect.PostgreSQLDialect"));
+ MAPPERS.put("Microsoft SQL Server Database", new
VersionInsensitiveMapper("org.hibernate.dialect.SQLServerDialect"));
+ MAPPERS.put("Microsoft SQL Server", new
VersionInsensitiveMapper("org.hibernate.dialect.SQLServerDialect"));
+ MAPPERS.put("Sybase SQL Server", new
VersionInsensitiveMapper("org.hibernate.dialect.SybaseDialect"));
+ MAPPERS.put("Informix Dynamic Server", new
VersionInsensitiveMapper("org.hibernate.dialect.InformixDialect"));
+
+ MAPPERS.put(
+ "Oracle",
+ new DatabaseDialectMapper()
+ {
+ public String getDialectClass(int majorVersion)
+ {
+ return majorVersion > 8
+ ? "org.hibernate.dialect.Oracle9Dialect"
+ : "org.hibernate.dialect.OracleDialect";
+ }
+ }
+ );
+ }
+}
Modified:
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java 2008-07-17
10:10:18 UTC (rev 11472)
+++
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java 2008-07-17
10:29:52 UTC (rev 11473)
@@ -22,22 +22,13 @@
******************************************************************************/
package org.jboss.portal.jems.hibernate;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.util.Collection;
-import java.util.Iterator;
-
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-
+import bsh.EvalError;
+import bsh.Interpreter;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
-import org.hibernate.dialect.DialectFactory;
import org.hibernate.exception.SQLGrammarException;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.tool.hbm2ddl.SchemaExport;
@@ -48,8 +39,14 @@
import org.jboss.portal.common.util.LoaderResource;
import org.jboss.portal.jems.as.system.AbstractJBossService;
-import bsh.EvalError;
-import bsh.Interpreter;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.util.Collection;
+import java.util.Iterator;
/**
* Configures and binds the hibernate session factory.
@@ -233,7 +230,7 @@
DatabaseMetaData meta = conn.getMetaData();
String databaseName = meta.getDatabaseProductName();
int databaseMajorVersion = getDatabaseMajorVersion(meta);
- dialectName = DialectFactory.determineDialect(databaseName,
databaseMajorVersion).getClass().getCanonicalName();
+ dialectName = DialectFactory.determineDialect(databaseName,
databaseMajorVersion);
config.setProperty(Environment.DIALECT, dialectName);
log.debug("Detected dialect " + dialectName + ", database is
(" + databaseName + "," + databaseMajorVersion + ")");
}