Author: tdraier
Date: Mon Jun 25 15:57:25 2007
New Revision: 17770

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17770&repname=
=3Djahia
Log:
optimize workflow on metadata ( backport 17687 , 16816 )

Modified:
    trunk/core/src/java/org/jahia/content/ContentObject.java
    trunk/core/src/java/org/jahia/hibernate/dao/JahiaFieldsDataDAO.java
    trunk/core/src/java/org/jahia/hibernate/manager/JahiaFieldsDataManager.=
java
    trunk/core/src/java/org/jahia/services/fields/ContentFieldTools.java

Modified: trunk/core/src/java/org/jahia/content/ContentObject.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/content/ContentObject.java&rev=3D17770&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/content/ContentObject.java (original)
+++ trunk/core/src/java/org/jahia/content/ContentObject.java Mon Jun 25 15:=
57:25 2007
@@ -1,18 +1,18 @@
 /*
  * Copyright 2002-2006 Jahia Ltd
  *
- * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL), =

- * Version 1.0 (the "License"), or (at your option) any later version; you=
 may =

- * not use this file except in compliance with the License. You should hav=
e =

- * received a copy of the License along with this program; if not, you may=
 obtain =

- * a copy of the License at =

+ * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL),
+ * Version 1.0 (the "License"), or (at your option) any later version; you=
 may
+ * not use this file except in compliance with the License. You should have
+ * received a copy of the License along with this program; if not, you may=
 obtain
+ * a copy of the License at
  *
  *  http://www.jahia.org/license/
  *
- * Unless required by applicable law or agreed to in writing, software =

- * distributed under the License is distributed on an "AS IS" BASIS, =

- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied=
. =

- * See the License for the specific language governing permissions and =

+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jahia.content;
@@ -69,7 +69,7 @@
     private String pickedObjectType =3D null;
 =

     protected static long lastClusterSyncTime =3D 0;
-    =

+
     protected ContentObject(ObjectKey objectKey) {
         super(objectKey);
         linkManager =3D (JahiaLinkManager) SpringContextSingleton.getInsta=
nce().getContext().getBean(JahiaLinkManager.class.getName());
@@ -1349,7 +1349,7 @@
 =

         long now =3D System.currentTimeMillis();
         if ( now-lastClusterSyncTime>3000 ){
-            lastClusterSyncTime =3D now; =

+            lastClusterSyncTime =3D now;
             ServicesRegistry.getInstance().getCacheService().syncClusterNo=
w();
             JahiaBatchingClusterCacheHibernateProvider.syncClusterNow();
         }
@@ -1367,35 +1367,40 @@
      * @throws JahiaException
      * @return ActivationTestResults
      */
-    public synchronized ActivationTestResults activateMetadatas (
-            Set languageCodes,
-            boolean versioningActive, JahiaSaveVersion saveVersion,
-            JahiaUser user,
-            ProcessingContext jParams,
-            StateModificationContext stateModifContext) throws JahiaExcept=
ion {
+    public synchronized ActivationTestResults activateMetadatas(Set langua=
geCodes,
+                                                                boolean ve=
rsioningActive,
+                                                                JahiaSaveV=
ersion saveVersion,
+                                                                JahiaUser =
user,
+                                                                Processing=
Context jParams,
+                                                                StateModif=
icationContext stateModifContext) throws JahiaException {
 =

         ActivationTestResults result =3D new ActivationTestResults();
         try {
-            Iterator iterator =3D getMetadatas(true).iterator();
+            Iterator iterator =3D getStagedMetadatas().iterator();
             ContentField contentField =3D null;
             while (iterator.hasNext()) {
                 contentField =3D (ContentField) iterator.next();
-                if ( contentField.hasStagingEntries() ){
-                    try {
-                        contentField.activate(languageCodes,
-                                              versioningActive, saveVersio=
n,
-                                              user, jParams, stateModifCon=
text);
-                    } catch (Throwable t) {
-                        logger.debug("Exception activating content object'=
s metadata",t);
-                    }
+                try {
+                    contentField.activate(languageCodes,
+                                          versioningActive,
+                                          saveVersion,
+                                          user,
+                                          jParams,
+                                          stateModifContext);
+                } catch (Throwable t) {
+                    logger.debug("Exception activating content object's me=
tadata", t);
                 }
             }
         } catch (Throwable t) {
-            logger.debug("Exception activating content object's metadatas =
", t);
+            logger.error("Exception activating content object's metadatas =
", t);
         }
         return result;
     }
 =

+    private List getStagedMetadatas() throws JahiaException {
+        return getMetadatas(getObjectKey(), true, true);
+    }
+
     /**
      * Must be called by Subclasses activate method.
      *
@@ -1641,6 +1646,10 @@
         return getMetadatas(objectKey,false);
     }
 =

+    public static ArrayList getMetadatas(ObjectKey objectKey, boolean with=
OldEntryStates) {
+        return getMetadatas(objectKey, withOldEntryStates, false);
+    }
+
     /**
      * Return an Array of ContentField that have a core "metadata" strutur=
al relationship
      * with the given objectKey. @see StructuralRelationship.METADATA_LINK
@@ -1649,9 +1658,14 @@
      * @param withOldEntryStates if true, batch load field's old entrystat=
es for better performance issue
      * @return ArrayList of JahiaObject
      */
-    public static ArrayList getMetadatas(ObjectKey objectKey, boolean with=
OldEntryStates) {
+    public static ArrayList getMetadatas(ObjectKey objectKey, boolean with=
OldEntryStates, boolean stagedOnly) {
         ArrayList objects =3D new ArrayList();
-        List ids =3D jahiaFieldsDataManager.findMetadatasByOwner(objectKey=
);
+        List ids;
+        if (stagedOnly) {
+            ids =3D jahiaFieldsDataManager.findStagedFieldsByMetadataOwner=
(objectKey);
+        } else {
+            ids =3D jahiaFieldsDataManager.findMetadatasByOwner(objectKey);
+        }
         Integer id =3D null;
         ContentField contentField =3D null;
 =

@@ -1663,17 +1677,21 @@
         if ( withOldEntryStates ){
             oldEntryStates =3D jahiaFieldsDataManager.findOldEntryStateFor=
Metadatas(objectKey);
         }
-        id =3D (Integer)((Object[])ids.get(0))[0];
+        id =3D (Integer)ids.get(0);
         if ( ContentFieldTools.getInstance().getFieldFromCacheOnly(id.intV=
alue()) =3D=3D null ){
             try {
-                ContentFieldTools.getInstance().preloadActiveOrStagedField=
sByMetadataOwner(objectKey);
+                if (stagedOnly) {
+                    ContentFieldTools.getInstance().preloadStagedFieldsByM=
etadataOwner(objectKey);
+                } else {
+                    ContentFieldTools.getInstance().preloadActiveOrStagedF=
ieldsByMetadataOwner(objectKey);
+                }
             } catch ( Throwable t ){
                 logger.debug("Error preloading metadatas for object " + ob=
jectKey,t);
             }
         }
 =

         for ( int i=3D0 ; i<ids.size(); i++ ){
-            id =3D (Integer)((Object[])ids.get(i))[0];
+            id =3D (Integer)ids.get(i);
             try {
                 contentField =3D ContentField.getField(id.intValue());
                 if ( contentField !=3D null ){

Modified: trunk/core/src/java/org/jahia/hibernate/dao/JahiaFieldsDataDAO.ja=
va
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/hibernate/dao/JahiaFieldsDataDAO.java&rev=3D17770&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/JahiaFieldsDataDAO.java (or=
iginal)
+++ trunk/core/src/java/org/jahia/hibernate/dao/JahiaFieldsDataDAO.java Mon=
 Jun 25 15:57:25 2007
@@ -1,18 +1,18 @@
 /*
  * Copyright 2002-2006 Jahia Ltd
  *
- * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL), =

- * Version 1.0 (the "License"), or (at your option) any later version; you=
 may =

- * not use this file except in compliance with the License. You should hav=
e =

- * received a copy of the License along with this program; if not, you may=
 obtain =

- * a copy of the License at =

+ * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL),
+ * Version 1.0 (the "License"), or (at your option) any later version; you=
 may
+ * not use this file except in compliance with the License. You should have
+ * received a copy of the License along with this program; if not, you may=
 obtain
+ * a copy of the License at
  *
  *  http://www.jahia.org/license/
  *
- * Unless required by applicable law or agreed to in writing, software =

- * distributed under the License is distributed on an "AS IS" BASIS, =

- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied=
. =

- * See the License for the specific language governing permissions and =

+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
  * limitations under the License.
  *//*
  * Copyright (c) 2005 Your Corporation. All Rights Reserved.
@@ -273,7 +273,7 @@
     }
 =

     public List findMetadatasByOwner(JahiaObjectPK ownerKey) {
-        String hql =3D "select distinct f.comp_id.id, f.fieldDefinition.id=
 from JahiaFieldsData f where f.isMetadata=3D1 AND f.metadataOwner.comp_id.=
id=3D? AND f.metadataOwner.comp_id.type=3D? order by f.fieldDefinition.id";
+        String hql =3D "select distinct f.comp_id.id from JahiaFieldsData =
f where f.isMetadata=3D1 AND f.metadataOwner.comp_id.id=3D? AND f.metadataO=
wner.comp_id.type=3D?";
         final HibernateTemplate template =3D getHibernateTemplate();
         template.setCacheQueries(true);
         template.setFlushMode(HibernateTemplate.FLUSH_NEVER);
@@ -510,7 +510,7 @@
     }
 =

     public List findVersionedFieldsIdInContainer(Integer containerID, Inte=
ger version) {
-        return findVersionedFieldsIdInContainer(containerID, version, fals=
e); =

+        return findVersionedFieldsIdInContainer(containerID, version, fals=
e);
     }
 =

     public List findVersionedFieldsIdInContainer(Integer containerID, Inte=
ger version, boolean withTypes) {
@@ -819,6 +819,14 @@
         return template.find(hql, new Object[]{ownerKey.getIDInType(), own=
erKey.getType()});
     }
 =

+    public List loadAllStagedFieldsByMetadataOwner(JahiaObjectPK ownerKey)=
 {
+        String hql =3D "from JahiaFieldsData f where f.metadataOwner.comp_=
id.id=3D? AND f.metadataOwner.comp_id.type=3D? AND f.comp_id.workflowState>=
1 order by f.comp_id.id";
+        final HibernateTemplate template =3D getHibernateTemplate();
+        template.setCacheQueries(false);
+        template.setFlushMode(HibernateTemplate.FLUSH_NEVER);
+        return template.find(hql, new Object[]{ownerKey.getIDInType(), own=
erKey.getType()});
+    }
+
     public List findStagedFieldsByMetadataOwner(JahiaObjectPK ownerKey) {
         String hql =3D "select f.comp_id.id from JahiaFieldsData f where f=
.metadataOwner.comp_id.id=3D? AND f.metadataOwner.comp_id.type=3D? AND f.co=
mp_id.workflowState>1";
         final HibernateTemplate template =3D getHibernateTemplate();

Modified: trunk/core/src/java/org/jahia/hibernate/manager/JahiaFieldsDataMa=
nager.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/hibernate/manager/JahiaFieldsDataManager.java&rev=3D17770&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/manager/JahiaFieldsDataManager.=
java (original)
+++ trunk/core/src/java/org/jahia/hibernate/manager/JahiaFieldsDataManager.=
java Mon Jun 25 15:57:25 2007
@@ -1,18 +1,18 @@
 /*
  * Copyright 2002-2006 Jahia Ltd
  *
- * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL), =

- * Version 1.0 (the "License"), or (at your option) any later version; you=
 may =

- * not use this file except in compliance with the License. You should hav=
e =

- * received a copy of the License along with this program; if not, you may=
 obtain =

- * a copy of the License at =

+ * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL),
+ * Version 1.0 (the "License"), or (at your option) any later version; you=
 may
+ * not use this file except in compliance with the License. You should have
+ * received a copy of the License along with this program; if not, you may=
 obtain
+ * a copy of the License at
  *
  *  http://www.jahia.org/license/
  *
- * Unless required by applicable law or agreed to in writing, software =

- * distributed under the License is distributed on an "AS IS" BASIS, =

- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied=
. =

- * See the License for the specific language governing permissions and =

+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
  * limitations under the License.
  *//*
  * Copyright (c) 2005 Your Corporation. All Rights Reserved.
@@ -51,6 +51,7 @@
 import org.jahia.services.webdav.UsageEntry;
 import org.jahia.bin.Jahia;
 import org.springframework.orm.ObjectRetrievalFailureException;
+import org.springframework.dao.DataIntegrityViolationException;
 =

 import java.util.*;
 =

@@ -127,14 +128,19 @@
         try {
             dao.backupFieldsData(new Integer(contentField.getID()), new Lo=
ng(entryState.getVersionID()),
                                  new Integer(entryState.getWorkflowState()=
), entryState.getLanguageCode());
-            flushCache(contentField.getID(),contentField.getSiteID(), cont=
entField.getContainerID());
-            return new ContentObjectEntryState(0, entryState.getVersionID(=
), entryState.getLanguageCode());
         } catch (ObjectRetrievalFailureException e) {
             log.warn("Warning field not found for backuping : " + contentF=
ield.getID() + " " +
                      entryState.getLanguageCode(),
                      e);
             return null;
+        } catch(DataIntegrityViolationException e) {
+            // The object is already backuped
+            log.warn("Warning field already backuped : " + contentField.ge=
tID() + " " +
+                     entryState.getLanguageCode(),
+                     e);
         }
+        flushCache(contentField.getID(),contentField.getSiteID(), contentF=
ield.getContainerID());
+        return new ContentObjectEntryState(0, entryState.getVersionID(), e=
ntryState.getLanguageCode());
     }
 =

     private void flushCache(int id, int siteID, int containerId) {
@@ -168,12 +174,12 @@
                                                          new Integer(newEn=
tryState.getWorkflowState()),
                                                          newEntryState.get=
LanguageCode());
                 if ( !pk.equals(data.getComp_id()) ){
-                JahiaFieldsData fieldsData =3D (JahiaFieldsData) data.clon=
e();
-                dao.deleteJahiaField(data);
-                fieldsData.setComp_id(pk);
-                dao.save(fieldsData);
-                flushCache(contentField.getID(),contentField.getSiteID(), =
contentField.getContainerID());
-            }
+                    JahiaFieldsData fieldsData =3D (JahiaFieldsData) data.=
clone();
+                    dao.deleteJahiaField(data);
+                    fieldsData.setComp_id(pk);
+                    dao.save(fieldsData);
+                    flushCache(contentField.getID(),contentField.getSiteID=
(), contentField.getContainerID());
+                }
             }
         } catch (ObjectRetrievalFailureException e) {
             log.warn("Field not found in database ", e);
@@ -769,6 +775,26 @@
         }
     }
 =

+    public void preloadStagedFieldsByMetadataOwner(ObjectKey metadataOwner=
) {
+        try {
+            List list =3D dao.loadAllStagedFieldsByMetadataOwner(new Jahia=
ObjectPK(metadataOwner.getType(),
+                    new Integer(metadataOwner.getIdInType())));
+            fillCache(list);
+        } catch (JahiaException e) {
+            log.warn("Exception during preload of fieds by metadata owner =
" + metadataOwner, e);
+        }
+    }
+
+    public List findStagedFieldsByMetadataOwner(ObjectKey metadataOwner) {
+        try {
+            return dao.findStagedFieldsByMetadataOwner(new JahiaObjectPK(m=
etadataOwner.getType(),
+                    new Integer(metadataOwner.getIdInType())));
+        } catch (RuntimeException e) {
+            log.warn("Exception during find of staged fields by metadata o=
wner " + metadataOwner, e);
+            return null;
+        }
+    }
+
     public void purgeField(ContentField id) {
         dao.purgeJahiaFields(new Integer(id.getID()));
         flushCache(id.getID(),id.getSiteID(), id.getContainerID());

Modified: trunk/core/src/java/org/jahia/services/fields/ContentFieldTools.j=
ava
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/services/fields/ContentFieldTools.java&rev=3D17770&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/services/fields/ContentFieldTools.java (o=
riginal)
+++ trunk/core/src/java/org/jahia/services/fields/ContentFieldTools.java Mo=
n Jun 25 15:57:25 2007
@@ -1,18 +1,18 @@
 /*
  * Copyright 2002-2006 Jahia Ltd
  *
- * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL), =

- * Version 1.0 (the "License"), or (at your option) any later version; you=
 may =

- * not use this file except in compliance with the License. You should hav=
e =

- * received a copy of the License along with this program; if not, you may=
 obtain =

- * a copy of the License at =

+ * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL),
+ * Version 1.0 (the "License"), or (at your option) any later version; you=
 may
+ * not use this file except in compliance with the License. You should have
+ * received a copy of the License along with this program; if not, you may=
 obtain
+ * a copy of the License at
  *
  *  http://www.jahia.org/license/
  *
- * Unless required by applicable law or agreed to in writing, software =

- * distributed under the License is distributed on an "AS IS" BASIS, =

- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied=
. =

- * See the License for the specific language governing permissions and =

+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 =

@@ -155,6 +155,30 @@
     }
 =

     /**
+     * Preloads all the staged fields for a given metadata owner key into =
the
+     * field cache.
+     *
+     * @param metadataOwnerKey
+     * @throws JahiaException thrown if there was an error while loading t=
he fields from the database.
+     */
+    public void preloadStagedFieldsByMetadataOwner (ObjectKey metadataOwne=
rKey)
+            throws JahiaException {
+        fieldsDataManager.preloadStagedFieldsByMetadataOwner (metadataOwne=
rKey);
+    }
+
+    /**
+     * loads all the staged fields for a given metadata owner key into the
+     * field cache.
+     *
+     * @param metadataOwnerKey
+     * @throws JahiaException thrown if there was an error while loading t=
he fields from the database.
+     */
+    public void findStagedFieldsByMetadataOwner(ObjectKey metadataOwnerKey)
+            throws JahiaException {
+        fieldsDataManager.findStagedFieldsByMetadataOwner(metadataOwnerKey=
);
+    }
+
+    /**
      * Get a ContentField from its ID
      *
      * @param fieldID

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

Reply via email to