You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/03/23 00:07:45 UTC

svn commit: r387965 - in /incubator/roller/trunk: ./ metadata/database/ metadata/database/hibernate/ src/org/roller/business/hibernate/

Author: snoopdave
Date: Wed Mar 22 15:07:41 2006
New Revision: 387965

URL: http://svn.apache.org/viewcvs?rev=387965&view=rev
Log:
ROL-1044: MS SQLServer patch from George Daswani

Added:
    incubator/roller/trunk/metadata/database/mssql.properties
Modified:
    incubator/roller/trunk/build.xml
    incubator/roller/trunk/metadata/database/createdb.vm
    incubator/roller/trunk/metadata/database/db2.properties
    incubator/roller/trunk/metadata/database/derby.properties
    incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml
    incubator/roller/trunk/metadata/database/hsqldb.properties
    incubator/roller/trunk/metadata/database/mysql.properties
    incubator/roller/trunk/metadata/database/oracle.properties
    incubator/roller/trunk/metadata/database/postgresql.properties
    incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java

Modified: incubator/roller/trunk/build.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/build.xml?rev=387965&r1=387964&r2=387965&view=diff
==============================================================================
--- incubator/roller/trunk/build.xml (original)
+++ incubator/roller/trunk/build.xml Wed Mar 22 15:07:41 2006
@@ -522,6 +522,12 @@
          templatePath="${basedir}/metadata/database/" 
          outputDirectory="build/roller/WEB-INF/dbscripts/oracle/" 
          outputFile="README.txt" />
+    <texen 
+        controlTemplate="control.vm" 
+        contextProperties="${basedir}/metadata/database/mssql.properties"
+        templatePath="${basedir}/metadata/database/" 
+        outputDirectory="build/roller/WEB-INF/dbscripts/mssql/" 
+        outputFile="README.txt" />
 </target>
 
 <!-- ********************************************************************* -->

Modified: incubator/roller/trunk/metadata/database/createdb.vm
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/database/createdb.vm?rev=387965&r1=387964&r2=387965&view=diff
==============================================================================
--- incubator/roller/trunk/metadata/database/createdb.vm (original)
+++ incubator/roller/trunk/metadata/database/createdb.vm Wed Mar 22 15:07:41 2006
@@ -15,7 +15,7 @@
     passphrase      varchar(255) not null,
     fullname        varchar(255) not null,
     emailaddress    varchar(255) not null,
-    datecreated     timestamp not null,
+    datecreated     $TIMESTAMP_SQL_TYPE not null,
     locale          varchar(20),  
     timezone        varchar(50),    
     isenabled       $BOOLEAN_SQL_TYPE_TRUE not null
@@ -54,14 +54,14 @@
     object_id       varchar(48),           
     object_class    varchar(255),          
     comment_text    varchar(255) not null, 
-    change_time     timestamp              
+    change_time     $TIMESTAMP_SQL_TYPE              
 );
 
 create table usercookie (
     id              varchar(48) not null primary key,
     username        varchar(255) not null,
     cookieid        varchar(100) not null,
-    datecreated     timestamp not null
+    datecreated     $TIMESTAMP_SQL_TYPE not null
 );
 create index uc_username_idx on usercookie( username$!INDEXSIZE );
 create index uc_cookieid_idx on usercookie( cookieid$!INDEXSIZE );
@@ -73,7 +73,7 @@
     link            varchar(255),
     websiteid       varchar(48)  not null,
     template        $TEXT_SQL_TYPE not null,
-    updatetime      timestamp     not null
+    updatetime      $TIMESTAMP_SQL_TYPE     not null
 );
 create index wp_name_idx on webpage( name$!INDEXSIZE );
 create index wp_link_idx on webpage( link$!INDEXSIZE );
@@ -102,7 +102,7 @@
     defaultplugins    varchar(255),
     isenabled         $BOOLEAN_SQL_TYPE_TRUE not null,
     isactive          $BOOLEAN_SQL_TYPE_TRUE not null,
-    datecreated      timestamp not null,
+    datecreated      $TIMESTAMP_SQL_TYPE not null,
     blacklist            $TEXT_SQL_TYPE,
     defaultallowcomments $BOOLEAN_SQL_TYPE_TRUE not null,
     defaultcommentdays   integer default 7 not null,
@@ -175,7 +175,7 @@
     title           varchar(255)  not null,
     text            $TEXT_SQL_TYPE not null,
     pubtime         $TIMESTAMP_SQL_TYPE_NULL,
-    updatetime      timestamp     not null,
+    updatetime      $TIMESTAMP_SQL_TYPE     not null,
     websiteid       varchar(48)  not null,
     categoryid      varchar(48)  not null,
     publishentry    $BOOLEAN_SQL_TYPE_TRUE not null,
@@ -213,7 +213,7 @@
     email   varchar(255),
     url     varchar(255),
     content $TEXT_SQL_TYPE,
-    posttime timestamp   not null,
+    posttime $TIMESTAMP_SQL_TYPE   not null,
     spam    $BOOLEAN_SQL_TYPE_FALSE not null,
     notify  $BOOLEAN_SQL_TYPE_FALSE not null,
     remotehost varchar(128),
@@ -236,7 +236,7 @@
     pingurl      varchar(255) not null,
     websiteid    varchar(48),
     conditioncode    integer default 0 not null,
-    lastsuccess  timestamp
+    lastsuccess  $TIMESTAMP_SQL_TYPE
 );
 create index pt_websiteid_idx on pingtarget( websiteid );
 
@@ -267,7 +267,7 @@
 -- attempts:  number of ping attempts that have been made for this entry
 create table pingqueueentry (
     id             varchar(48) not null primary key,
-    entrytime      timestamp not null, 
+    entrytime      $TIMESTAMP_SQL_TYPE not null, 
     pingtargetid   varchar(48) not null,  
     websiteid      varchar(48) not null,  
     attempts       integer not null
@@ -285,7 +285,7 @@
     datestr   varchar(10),
     refurl    varchar(255) not null,
     refpermalink varchar(255),
-    reftime   timestamp,
+    reftime   $TIMESTAMP_SQL_TYPE,
     requrl    varchar(255),
     title     varchar(255),
     excerpt   $TEXT_SQL_TYPE,
@@ -394,7 +394,7 @@
     feed_url         varchar(255) not null,
     site_url         varchar(255),
     author           varchar(255),
-    last_updated     timestamp,
+    last_updated     $TIMESTAMP_SQL_TYPE,
     inbound_links    integer default -1,
     inbound_blogs    integer default -1
 );
@@ -410,8 +410,8 @@
     author           varchar(255),
     content          $TEXT_SQL_TYPE,
     categories       $TEXT_SQL_TYPE,
-    published        timestamp not null,
-    updated          timestamp    
+    published        $TIMESTAMP_SQL_TYPE not null,
+    updated          $TIMESTAMP_SQL_TYPE    
 );
 create index rage_sid_idx on rag_entry(subscription_id$!INDEXSIZE); 
 

Modified: incubator/roller/trunk/metadata/database/db2.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/database/db2.properties?rev=387965&r1=387964&r2=387965&view=diff
==============================================================================
--- incubator/roller/trunk/metadata/database/db2.properties (original)
+++ incubator/roller/trunk/metadata/database/db2.properties Wed Mar 22 15:07:41 2006
@@ -9,3 +9,4 @@
 INDEXSIZE_LARGE=
 ADDL_FK_PARAMS=on delete no action on update no action enforced enable query optimization
 TIMESTAMP_SQL_TYPE_NULL=timestamp null
+TIMESTAMP_SQL_TYPE=timestamp

Modified: incubator/roller/trunk/metadata/database/derby.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/database/derby.properties?rev=387965&r1=387964&r2=387965&view=diff
==============================================================================
--- incubator/roller/trunk/metadata/database/derby.properties (original)
+++ incubator/roller/trunk/metadata/database/derby.properties Wed Mar 22 15:07:41 2006
@@ -9,4 +9,5 @@
 INDEXSIZE_LARGE=
 ADDL_FK_PARAMS=
 TIMESTAMP_SQL_TYPE_NULL=timestamp
+TIMESTAMP_SQL_TYPE=timestamp
 

Modified: incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml?rev=387965&r1=387964&r2=387965&view=diff
==============================================================================
--- incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml (original)
+++ incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml Wed Mar 22 15:07:41 2006
@@ -11,12 +11,13 @@
         <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
         
         <!--
-        If you want to use HSQLDB, PostgreSQL, DB2 or Derby, Oracle then use the right dialect   
+        If you want to use HSQLDB, PostgreSQL, DB2 or Derby, Oracle, SQLServer then use the right dialect   
         <property name="dialect">org.hibernate.dialect.HQLDBDialect</property> 
         <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
         <property name="dialect">org.hibernate.dialect.DB2Dialect</property>
         <property name="dialect">org.hibernate.dialect.DerbyDialect</property>
         <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
+        <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
         -->
 
         <!--

Modified: incubator/roller/trunk/metadata/database/hsqldb.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/database/hsqldb.properties?rev=387965&r1=387964&r2=387965&view=diff
==============================================================================
--- incubator/roller/trunk/metadata/database/hsqldb.properties (original)
+++ incubator/roller/trunk/metadata/database/hsqldb.properties Wed Mar 22 15:07:41 2006
@@ -9,3 +9,4 @@
 INDEXSIZE_LARGE=
 ADDL_FK_PARAMS=
 TIMESTAMP_SQL_TYPE_NULL=timestamp null
+TIMESTAMP_SQL_TYPE=timestamp

Added: incubator/roller/trunk/metadata/database/mssql.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/database/mssql.properties?rev=387965&view=auto
==============================================================================
--- incubator/roller/trunk/metadata/database/mssql.properties (added)
+++ incubator/roller/trunk/metadata/database/mssql.properties Wed Mar 22 15:07:41 2006
@@ -0,0 +1,12 @@
+DBTYPE=MSSQL
+TEXT_SQL_TYPE=text
+BOOLEAN_SQL_TYPE_FALSE=bit default 0
+BOOLEAN_SQL_TYPE_TRUE=bit default 1
+BOOLEAN_SQL_TYPE=bit
+BOOLEAN_FALSE=0
+BOOLEAN_TRUE=1
+INDEXSIZE=
+INDEXSIZE_LARGE=
+ADDL_FK_PARAMS=
+TIMESTAMP_SQL_TYPE_NULL=datetime null
+TIMESTAMP_SQL_TYPE=datetime

Modified: incubator/roller/trunk/metadata/database/mysql.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/database/mysql.properties?rev=387965&r1=387964&r2=387965&view=diff
==============================================================================
--- incubator/roller/trunk/metadata/database/mysql.properties (original)
+++ incubator/roller/trunk/metadata/database/mysql.properties Wed Mar 22 15:07:41 2006
@@ -9,3 +9,4 @@
 INDEXSIZE_LARGE=(100)
 ADDL_FK_PARAMS=    
 TIMESTAMP_SQL_TYPE_NULL=datetime NULL
+TIMESTAMP_SQL_TYPE=datetime

Modified: incubator/roller/trunk/metadata/database/oracle.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/database/oracle.properties?rev=387965&r1=387964&r2=387965&view=diff
==============================================================================
--- incubator/roller/trunk/metadata/database/oracle.properties (original)
+++ incubator/roller/trunk/metadata/database/oracle.properties Wed Mar 22 15:07:41 2006
@@ -9,3 +9,4 @@
 INDEXSIZE_LARGE=
 ADDL_FK_PARAMS=
 TIMESTAMP_SQL_TYPE_NULL=timestamp null
+TIMESTAMP_SQL_TYPE=timestamp

Modified: incubator/roller/trunk/metadata/database/postgresql.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/database/postgresql.properties?rev=387965&r1=387964&r2=387965&view=diff
==============================================================================
--- incubator/roller/trunk/metadata/database/postgresql.properties (original)
+++ incubator/roller/trunk/metadata/database/postgresql.properties Wed Mar 22 15:07:41 2006
@@ -9,3 +9,4 @@
 INDEXSIZE_LARGE=
 ADDL_FK_PARAMS=
 TIMESTAMP_SQL_TYPE_NULL=timestamp null
+TIMESTAMP_SQL_TYPE=timestamp

Modified: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java?rev=387965&r1=387964&r2=387965&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java Wed Mar 22 15:07:41 2006
@@ -31,6 +31,13 @@
 import org.roller.pojos.WeblogEntryData;
 import org.roller.pojos.WebsiteData;
 import org.roller.pojos.WebsiteDisplayData;
+import org.hibernate.dialect.DB2Dialect;
+import org.hibernate.dialect.DerbyDialect;
+import org.hibernate.dialect.HSQLDialect;
+import org.hibernate.dialect.OracleDialect;
+import org.hibernate.dialect.SQLServerDialect;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.dialect.Dialect;
 
 
 /**
@@ -178,7 +185,10 @@
             con = ses.connection();
             
             final PreparedStatement stmt;
-            if (con.getMetaData().getDriverName().startsWith("HSQL")) {
+            
+            Dialect currentDialect = ((SessionFactoryImplementor)ses.getSessionFactory()).getDialect();
+            
+            if (currentDialect instanceof HSQLDialect) {
                 // special handling for HSQLDB
                 stmt = con.prepareStatement(
                     "select top ? w.id, w.name, w.handle, sum(r.dayhits) as s "+
@@ -188,7 +198,7 @@
                 stmt.setInt(1, max);
                 stmt.setBoolean(2, true);
                 stmt.setBoolean(3, true);
-            } else if(con.getMetaData().getDriverName().startsWith("Apache Derby")) {
+            } else if(currentDialect instanceof DerbyDialect) {
 	           // special handling for Derby
 				stmt = con.prepareStatement(
 				    "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
@@ -198,7 +208,7 @@
 				stmt.setBoolean(1, true);				
                 stmt.setBoolean(2, true);
                 stmt.setMaxRows(max);
-            } else if(con.getMetaData().getDriverName().startsWith("IBM DB2")) {
+            } else if(currentDialect instanceof DB2Dialect) {
                 // special handling for IBM DB2
                 stmt = con.prepareStatement(
                     "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
@@ -208,7 +218,7 @@
                     Integer.toString(max) + " rows only");
                 stmt.setBoolean(1, true);
                 stmt.setBoolean(2, true);
-            } else if (con.getMetaData().getDriverName().startsWith("Oracle")) {
+            } else if (currentDialect instanceof OracleDialect) {
 				stmt = con.prepareStatement(
                     "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
                     "from website w, referer r "+
@@ -216,7 +226,13 @@
                     "group by w.name, w.handle, w.id order by s desc");
 				stmt.setBoolean(1, true);
 				stmt.setBoolean(2, true);
-				stmt.setInt(3, max );				
+				stmt.setInt(3, max );
+            } else if (currentDialect instanceof SQLServerDialect) {
+            	stmt = con.prepareStatement("select top " + max + " w.id, w.name, w.handle, sum(r.dayhits) as s " +
+            	     "from website as w, referer as r where r.websiteid=w.id and w.isenabled=? and w.isactive=? " +
+            	     "group by w.name, w.handle, w.id order by s desc");
+            	stmt.setBoolean(1, true);
+                stmt.setBoolean(2, true);
             } else { // for MySQL and PostgreSQL
                 stmt = con.prepareStatement(
                     "select w.id, w.name, w.handle, sum(r.dayhits) as s "+
@@ -483,9 +499,15 @@
         }       
         try {
             Session session = ((HibernateStrategy)mStrategy).getSession();
+            Dialect currentDialect = ((SessionFactoryImplementor)session.getSessionFactory()).getDialect();
             String reset = "update RefererData set dayHits=0";
             session.createQuery(reset).executeUpdate();
-            String delete = "delete RefererData where excerpt is null or excerpt=''";
+            String delete = null;
+            if ( currentDialect instanceof SQLServerDialect || currentDialect instanceof OracleDialect ){
+            	delete = "delete RefererData where excerpt is null or excerpt like ''";
+            } else {
+            	delete = "delete RefererData where excerpt is null or excerpt=''";	
+            }
             session.createQuery(delete).executeUpdate();
         } catch (Exception e) {
             mLogger.error("EXCEPTION resetting referers",e);
@@ -502,10 +524,16 @@
         }       
         try {
             Session session = ((HibernateStrategy)mStrategy).getSession();
+            Dialect currentDialect = ((SessionFactoryImplementor)session.getSessionFactory()).getDialect();
             String reset = "update RefererData set dayHits=0 where website=:site";
             session.createQuery(reset)
                 .setParameter("site",website).executeUpdate();
-            String delete = "delete RefererData where website=:site and (excerpt is null or excerpt='')";
+            String delete = null;
+            if ( currentDialect instanceof SQLServerDialect || currentDialect instanceof OracleDialect ){
+            	delete = "delete RefererData where website=:site and (excerpt is null or excerpt like '')";
+            } else {
+            	delete = "delete RefererData where website=:site and (excerpt is null or excerpt='')";            	
+            }
             session.createQuery(delete)
                 .setParameter("site",website).executeUpdate();
         } catch (Exception e) {