Author: tdraier
Date: Thu Sep 27 17:48:11 2007
New Revision: 18701

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18701&repname=
=3Djahia
Log:
add traces and avoid crash if a sequence cannot be generated (JAHIA-2416)

Modified:
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/dao/IDGe=
neratorDAO.java

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/da=
o/IDGeneratorDAO.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/hibernate/dao/IDGeneratorDAO.java&rev=3D187=
01&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
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/dao/IDGe=
neratorDAO.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/dao/IDGe=
neratorDAO.java Thu Sep 27 17:48:11 2007
@@ -17,15 +17,13 @@
  */package org.jahia.hibernate.dao;
 =

 import org.jahia.exceptions.JahiaException;
-import org.jboss.cache.DataNode;
-import org.jboss.cache.Node;
-import org.jboss.cache.ReplicationException;
-import org.jboss.cache.TreeCache;
+import org.jboss.cache.*;
 import org.jboss.cache.lock.IsolationLevel;
 import org.jboss.cache.lock.TimeoutException;
 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 import org.hibernate.Hibernate;
 import org.hibernate.Session;
+import org.hibernate.HibernateException;
 =

 import java.util.Map;
 import java.util.Iterator;
@@ -177,52 +175,56 @@
                 String sequenceName =3D (String) curEntry.getKey();
                 String fqnID =3D (String) curEntry.getValue();
 =

-                int separatorPos =3D fqnID.indexOf(".");
-                String tableName =3D fqnID.substring(0, separatorPos);
-                String columnName =3D fqnID.substring(separatorPos + 1);
-
-                long initialHighValue;
-                long initialLowValue;
-
-                Long curClusterHighValue =3D (Long) cache.get("/idgenerato=
rs/"
-                        + sequenceName, CACHE_ENTRY_KEY);
-                if (curClusterHighValue =3D=3D null) {
-                    // not found in cluster cache, let's initialize.
-                    // @todo add code to perform SELECT MAX() query on dat=
abase
-                    Long maxValue =3D (Long) session.createSQLQuery(
-                            "SELECT MAX(" + columnName + ") as maxValue FR=
OM "
-                                    + tableName).addScalar("maxValue",
-                            Hibernate.LONG).uniqueResult();
-                    initialHighValue =3D 0;
-                    initialLowValue =3D 0;
-                    if (maxValue =3D=3D null) {
-                        maxValue =3D new Long(0);
+                try {
+                    int separatorPos =3D fqnID.indexOf(".");
+                    String tableName =3D fqnID.substring(0, separatorPos);
+                    String columnName =3D fqnID.substring(separatorPos + 1=
);
+
+                    long initialHighValue;
+                    long initialLowValue;
+
+                    Long curClusterHighValue =3D (Long) cache.get("/idgene=
rators/"
+                            + sequenceName, CACHE_ENTRY_KEY);
+                    if (curClusterHighValue =3D=3D null) {
+                        // not found in cluster cache, let's initialize.
+                        // @todo add code to perform SELECT MAX() query on=
 database
+                        Long maxValue =3D (Long) session.createSQLQuery(
+                                "SELECT MAX(" + columnName + ") as maxValu=
e FROM "
+                                        + tableName).addScalar("maxValue",
+                                Hibernate.LONG).uniqueResult();
+                        initialHighValue =3D 0;
+                        initialLowValue =3D 0;
+                        if (maxValue =3D=3D null) {
+                            maxValue =3D new Long(0);
+                        } else {
+                            initialHighValue =3D ((maxValue.longValue() / =
maxLo))
+                                    * maxLo;
+                            initialLowValue =3D maxValue.longValue() % max=
Lo;
+                            lowCounters
+                                    .put(sequenceName, new Long(initialLow=
Value));
+                        }
+                        highCounters.put(sequenceName, new Long(initialHig=
hValue));
+                        logger.debug("Sequence " + sequenceName
+                                + " initial values : low=3D" + initialLowV=
alue
+                                + " high=3D" + initialHighValue);
+                        try {
+                            cache.put("/idgenerators/" + sequenceName,
+                                    CACHE_ENTRY_KEY, new Long(initialHighV=
alue));
+                        } catch (ReplicationException re) {
+                            logger
+                                    .warn(
+                                            "Error while replicating last =
used high value "
+                                                    + initialHighValue
+                                                    + ", cluster nodes may=
 have crashed or unreacheable",
+                                            re);
+                        }
                     } else {
-                        initialHighValue =3D ((maxValue.longValue() / maxL=
o))
-                                * maxLo;
-                        initialLowValue =3D maxValue.longValue() % maxLo;
-                        lowCounters
-                                .put(sequenceName, new Long(initialLowValu=
e));
-                    }
-                    highCounters.put(sequenceName, new Long(initialHighVal=
ue));
-                    logger.debug("Sequence " + sequenceName
-                            + " initial values : low=3D" + initialLowValue
-                            + " high=3D" + initialHighValue);
-                    try {
-                        cache.put("/idgenerators/" + sequenceName,
-                                CACHE_ENTRY_KEY, new Long(initialHighValue=
));
-                    } catch (org.jboss.cache.ReplicationException re) {
-                        logger
-                                .warn(
-                                        "Error while replicating last used=
 high value "
-                                                + initialHighValue
-                                                + ", cluster nodes may hav=
e crashed or unreacheable",
-                                        re);
+                        initialLowValue =3D maxLo; // force high increment=
 on first retrieval.
+                        highCounters.put(sequenceName, curClusterHighValue=
);
+                        lowCounters.put(sequenceName, new Long(initialLowV=
alue));
                     }
-                } else {
-                    initialLowValue =3D maxLo; // force high increment on =
first retrieval.
-                    highCounters.put(sequenceName, curClusterHighValue);
-                    lowCounters.put(sequenceName, new Long(initialLowValue=
));
+                } catch (HibernateException e) {
+                    logger.error("Problem when creating sequence for " + s=
equenceName + " ("+fqnID+")",e);
                 }
             }
             session.flush();

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to