Author: bpapez
Date: Fri Nov 9 23:27:29 2007
New Revision: 19111
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19111&repname=
=3Djahia
Log:
JAHIA-2633 Engines performances improvements - display page logs =
* refactor Hibernate queries
Modified:
trunk/core/src/java/org/jahia/hibernate/dao/JahiaAuditLogDAO.java
trunk/core/src/java/org/jahia/hibernate/manager/JahiaAuditLogManager.ja=
va
Modified: trunk/core/src/java/org/jahia/hibernate/dao/JahiaAuditLogDAO.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/hibernate/dao/JahiaAuditLogDAO.java&rev=3D19111&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/hibernate/dao/JahiaAuditLogDAO.java (orig=
inal)
+++ trunk/core/src/java/org/jahia/hibernate/dao/JahiaAuditLogDAO.java Fri N=
ov 9 23:27:29 2007
@@ -28,8 +28,10 @@
import org.springframework.orm.hibernate3.HibernateTemplate;
=
import java.sql.SQLException;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
=
/**
* Created by IntelliJ IDEA.
@@ -61,20 +63,21 @@
=
public List getLogs(Integer objectType, Integer objectID, List childre=
nObjectList) {
List retList =3D null;
- HibernateTemplate template =3D getHibernateTemplate();
- template.setFlushMode(HibernateTemplate.FLUSH_NEVER);
- template.setCacheQueries(true);
+
if (objectType !=3D null && objectID !=3D null) {
- StringBuffer buffer =3D new StringBuffer("from JahiaAuditLog l=
where " +
- "l.objecttype=3D" + objectType + " and l.objectid=3D" =
+ objectID);
- for (int i =3D 0; i < childrenObjectList.size(); i++) {
- Integer[] integers =3D (Integer[]) childrenObjectList.get(=
i);
- buffer.append(" or (l.objecttype =3D").append(integers[0]);
- buffer.append(" and l.objectid=3D").append(integers[1]).ap=
pend(")");
- }
- buffer.append(" order by l.site asc, l.time desc");
- retList =3D template.find(buffer.toString());
- }
+ Set objectIds =3D new
HashSet(childrenObjectList.size());
+ objectIds.add(objectID); =
+ for (Iterator it =3D childrenObjectList.iterator(); it.hasNext=
(); ) {
+ Integer[] integers =3D (Integer[]) it.next();
+ objectIds.add(integers[1]);
+ } =
+
+ Query query =3D this.getSession().createQuery(
+ "from JahiaAuditLog l "
+ + "where l.objectid in
(:objectIDs)");
+ query.setParameterList("objectIDs", objectIds);
+ retList =3D query.list();
+ }
return retList;
}
=
@@ -92,92 +95,38 @@
=
public int flushLogs(Integer objectType, Integer objectID, List childr=
enObjectList) {
int retList =3D 0;
- HibernateTemplate template =3D getHibernateTemplate();
- template.setFlushMode(HibernateTemplate.FLUSH_AUTO);
+ =
if (objectType !=3D null && objectID !=3D null) {
- final StringBuffer buffer =3D new StringBuffer("from JahiaAudi=
tLog l where " +
- "l.objecttype=3D" + objectType + " and l.objectid=3D" =
+ objectID);
- for (int i =3D 0; i < childrenObjectList.size(); i++) {
- Integer[] integers =3D (Integer[]) childrenObjectList.get(=
i);
- buffer.append(" or (l.objecttype =3D").append(integers[0]);
- buffer.append(" and l.objectid=3D").append(integers[1]).ap=
pend(")");
- }
- buffer.append(" order by l.site asc, l.time desc");
- deleteAll(template, buffer.toString());
+ Set objectIds =3D new
HashSet(childrenObjectList.size());
+ objectIds.add(objectID); =
+ for (Iterator it =3D childrenObjectList.iterator(); it.hasNext=
(); ) {
+ Integer[] integers =3D (Integer[]) it.next();
+ objectIds.add(integers[1]);
+ } =
+
+ Query query =3D this.getSession().createQuery(
+ "delete from JahiaAuditLog "
+ + "where objectid in
(:objectIDs)");
+ query.setParameterList("objectIDs", objectIds);
+ retList =3D query.executeUpdate();
}
return retList;
}
=
- private void deleteAll(HibernateTemplate template, final String buffer=
) {
- template.execute(new HibernateCallback() {
- public Object doInHibernate(Session session) throws HibernateE=
xception, SQLException {
- Transaction transaction =3D session.beginTransaction();
- try {
- Iterator iterator2 =3D session.createQuery(buffer.toSt=
ring()).iterate();
- while (iterator2.hasNext()) {
- session.delete(iterator2.next());
- }
- transaction.commit();
- } catch (Throwable t) {
- transaction.rollback();
- }
- return null;
- }
- });
- }
-
public void flushLogs(final Long oldestEntryTime) {
- HibernateTemplate template =3D getHibernateTemplate();
- template.setFlushMode(HibernateTemplate.FLUSH_AUTO);
- final String s =3D "from JahiaAuditLog l where l.time < ?";
- deletAllWithCriteria(template, s, oldestEntryTime);
- }
-
- private void deletAllWithCriteria(HibernateTemplate template, final St=
ring s, final Long oldestEntryTime) {
- template.execute(new HibernateCallback() {
- public Object doInHibernate(Session session) throws HibernateE=
xception, SQLException {
- Transaction transaction =3D session.beginTransaction();
- try {
- Query query =3D session.createQuery(s);
- query.setLong(0, oldestEntryTime.longValue());
- Iterator iterator2 =3D query.iterate();
- while (iterator2.hasNext()) {
- session.delete(iterator2.next());
- }
- transaction.commit();
- } catch (Throwable t) {
- transaction.rollback();
- }
- return null;
- }
- });
-
- }
-
- private void deletAllWithCriteria(HibernateTemplate template, final St=
ring s, final String value) {
- template.execute(new HibernateCallback() {
- public Object doInHibernate(Session session) throws HibernateE=
xception, SQLException {
- Transaction transaction =3D session.beginTransaction();
- try {
- Query query =3D session.createQuery(s);
- query.setString(0, value);
- Iterator iterator2 =3D query.iterate();
- while (iterator2.hasNext()) {
- session.delete(iterator2.next());
- }
- transaction.commit();
- } catch (Throwable t) {
- transaction.rollback();
- }
- return null;
- }
- });
+ Query query =3D this.getSession().createQuery(
+ "delete from JahiaAuditLog "
+ + "where time < ?");
+ query.setParameter(0, oldestEntryTime);
+ query.executeUpdate();
}
=
public void flushSiteLogs(String siteKey) {
- HibernateTemplate template =3D getHibernateTemplate();
- template.setFlushMode(HibernateTemplate.FLUSH_AUTO);
- deletAllWithCriteria(template, "from JahiaAuditLog l where l.site =
=3D ?", siteKey);
+ Query query =3D this.getSession().createQuery(
+ "delete from JahiaAuditLog "
+ + "where site =3D ?");
+ query.setParameter(0, siteKey);
+ query.executeUpdate(); =
}
=
public int enforceMaxLogs(int maxLogs) {
@@ -189,50 +138,20 @@
// if rows need to be deleted, get the highest ID to be deleted
if (numDeletes > 0) {
for (int i =3D 0; i < numDeletes; i++) {
- deleteOldestRow(template);
+ deleteOldestRow();
}
}
return numDeletes;
}
=
public int deleteAllLogs() {
- HibernateTemplate template =3D getHibernateTemplate();
- Object o =3D template.execute(new HibernateCallback() {
- public Object doInHibernate(Session session) throws HibernateE=
xception, SQLException {
- Transaction transaction =3D session.beginTransaction();
- try {
- String hqlDelete =3D "delete JahiaAuditLog";
- Query deleteQuery =3D session.createQuery( hqlDelete );
- int deletedEntities =3D deleteQuery.executeUpdate();
- logger.debug("delete all logs entries: "+deletedEntiti=
es);
- transaction.commit();
- return new Integer(deletedEntities);
- } catch (Throwable t) {
- transaction.rollback();
- }
- return null;
- }
- });
-
- // return nb deleted objects
- if(o =3D=3D null){
- return 0;
- }else{
- return ((Integer)o).intValue();
- }
- }
-
- private void deleteOldestRow(HibernateTemplate template) {
- List ret =3D template.find("select min(l.id) from JahiaAuditLog l"=
);
- if (ret.size() > 0) {
- int numRows =3D ((Integer) ret.get(0)).intValue();
- deleteAll(template, "from JahiaAuditLog l where l.id=3D" + num=
Rows);
- }
+ return this.getSession().createQuery(
+ "delete from JahiaAuditLog ").executeUpdate();
=
}
=
public void deleteOldestRow() {
- HibernateTemplate template =3D getHibernateTemplate();
- template.setFlushMode(HibernateTemplate.FLUSH_AUTO);
- deleteOldestRow(template);
+ this.getSession().createQuery(
+ "delete from JahiaAuditLog where id =3D
min(id)")
+ .executeUpdate();
}
}
Modified: trunk/core/src/java/org/jahia/hibernate/manager/JahiaAuditLogMana=
ger.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/hibernate/manager/JahiaAuditLogManager.java&rev=3D19111&repname=3D=
jahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/hibernate/manager/JahiaAuditLogManager.ja=
va (original)
+++ trunk/core/src/java/org/jahia/hibernate/manager/JahiaAuditLogManager.ja=
va Fri Nov 9 23:27:29 2007
@@ -40,6 +40,7 @@
import java.text.DateFormat;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
=
@@ -94,21 +95,18 @@
return false;
}
=
- public List getAllChildren(int objectType, int objectID, List parents)=
{
+ public List getAllChildren(int objectType, int objectID, List parents) {
List fullChildrenList =3D parents =3D=3D null ? new FastArrayList(=
103) : parents;
- List tempChildrenList =3D getChildrenList(objectType, objectID); =
// create sublist on current level
- if (!tempChildrenList.isEmpty())
- { // C=
HILDREN FOUND ->
- for (int i =3D 0; i < tempChildrenList.size(); i++)
- { // loop on childr=
en list
- fullChildrenList.add(tempChildrenList.get(i)); =
// add child to Full List
- Integer[] newChild =3D (Integer[]) tempChildrenList.get(i);
- Integer newObjType =3D newChild[0];
- Integer newObjID =3D newChild[1];
- getAllChildren(newObjType.intValue(), newObjID.intValue(),=
fullChildrenList); // call myself !
- }
- }
- return fullChildrenList;
+ List tempChildrenList =3D getChildrenList(objectType, objectID);
+ for (Iterator it =3D tempChildrenList.iterator();
it.hasNext();) {
+ Integer[] newChild =3D (Integer[]) it.next();
=
+ fullChildrenList.add(newChild);
+ Integer newObjType =3D newChild[0];
+ Integer newObjID =3D newChild[1];
+ getAllChildren(newObjType.intValue(),
newObjID.intValue(),
+ fullChildrenList);
+ }
+ return fullChildrenList;
}
=
private List getChildrenList(int objectType, int objectID) {
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list