Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jesper W
Supported method of running batch SQL updates in 5.1?
July 24, 2008 1:40 AM
Answer

Jesper W

Rank: Expert

Posts: 315

Join Date: March 25, 2007

Recent Posts

(First of all by the way, I am starting to feel like I am the only one posting in this thread these days, I kind of wonder where the rest of the discussion is going on...?)

Anyways... In our work to upgrade from v4 to v5 we have hit a snag in the way that the Spring/Hibernate usage has been reworked for ServiceBuilder entities.

We have a number of XxxPersistenceImpl methods that use SQL Update statements. For example our TV guide updating needs this to make the updates execute in reasonable amounts of time (Iterating across all entities takes over 1.5 hours, batch SQL statements a couple of minutes...)

However it seems the only supported entry point into the database now is SQLQuery.list(), which doesn't work with Updates.

(All the occurences of this kind of batch update are such that they do not need instant updates on the public pages, they can very well be deferred until they fall out of the server cache)

How should an issue like this be handeled in 5.1?

/jesper
Jesper W
RE: Supported method of running batch SQL updates in 5.1?
July 24, 2008 3:19 AM
Answer

Jesper W

Rank: Expert

Posts: 315

Join Date: March 25, 2007

Recent Posts

The following simple patch appears to solve the issue. But since I have limited insight into the reasoning behind the v5 rework I am not certain it is an acceptable way to go....

Index: portal-impl/src/com/liferay/portal/dao/orm/hibernate/QueryImpl.java
===================================================================
--- portal-impl/src/com/liferay/portal/dao/orm/hibernate/QueryImpl.java    (revision 18471)
+++ portal-impl/src/com/liferay/portal/dao/orm/hibernate/QueryImpl.java    (working copy)
@@ -147,6 +147,15 @@
         }
     }

+    public int executeUpdate() throws ORMException {
+        try {
+            return _query.executeUpdate();
+        }
+        catch (Exception e) {
+            throw ExceptionTranslator.translate(e);
+        }
+    }
+
     private org.hibernate.Query _query;

}
\ No newline at end of file
Index: portal-impl/src/com/liferay/portal/dao/orm/hibernate/SQLQueryImpl.java
===================================================================
--- portal-impl/src/com/liferay/portal/dao/orm/hibernate/SQLQueryImpl.java    (revision 18471)
+++ portal-impl/src/com/liferay/portal/dao/orm/hibernate/SQLQueryImpl.java    (working copy)
@@ -161,6 +161,15 @@
         }
     }

-    private org.hibernate.SQLQuery _sqlQuery;
+    public int executeUpdate() throws ORMException {
+        try {
+            return _sqlQuery.executeUpdate();
+        }
+        catch (Exception e) {
+            throw ExceptionTranslator.translate(e);
+        }
+    }

-}
\ No newline at end of file
+    private org.hibernate.SQLQuery _sqlQuery;
+
+}
Index: portal-kernel/src/com/liferay/portal/kernel/dao/orm/Query.java
===================================================================
--- portal-kernel/src/com/liferay/portal/kernel/dao/orm/Query.java    (revision 18471)
+++ portal-kernel/src/com/liferay/portal/kernel/dao/orm/Query.java    (working copy)
@@ -67,4 +67,6 @@

     public Object uniqueResult() throws ORMException;

-}
\ No newline at end of file
+    public int executeUpdate() throws ORMException;
+
+}
Ray Augé
Re: [Liferay Forums][Liferay Core Developers] RE: Supported method of runni
July 24, 2008 7:07 AM
Answer

Ray Augé

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1129

Join Date: February 7, 2005

Recent Posts

Sorry for the silence Jesper,

It's not that we're discussing elsewhere... it's that we're so taxed at
the moment that we're barely discussing at all. We don't have such a
large team that some of use are purely tasked on engineering. We often
are all tasked on client projects.

So, that being said, I think your patch is well conceived and would be
very useful.