Author: tdraier
Date: Tue Jun 26 18:45:53 2007
New Revision: 17782

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17782&repname=
=3Djahia
Log:
acl optimization : do not request jahia_acl_entries if it's empty

Modified:
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/model/Ja=
hiaAcl.java

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/mo=
del/JahiaAcl.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/hibernate/model/JahiaAcl.java&rev=3D17782&r=
epname=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/model/Ja=
hiaAcl.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/model/Ja=
hiaAcl.java Tue Jun 26 18:45:53 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.hibernate.model;
 =

@@ -58,12 +58,14 @@
      * nullable persistent field
      */
     private Integer inheritance;
-    =

+
     private transient static Logger logger =3D Logger.getLogger (JahiaAcl.=
class);
     private transient JahiaBaseACL mAcl =3D null;
 =

     private Map entries;
 =

+    private Boolean hasEntries;
+
     private Map groupEntries;
 =

     /**
@@ -81,12 +83,13 @@
      */
     public JahiaAcl() {
         entries =3D new FastHashMap(11);
+        hasEntries =3D Boolean.FALSE;
     }
 =

 // --------------------- GETTER / SETTER METHODS ---------------------
 =

     /**
-     * @hibernate.map lazy=3D"false"
+     * @hibernate.map lazy=3D"true"
      * inverse=3D"true"
      * cascade=3D"none"
      * @hibernate.collection-key column=3D"id_jahia_acl"
@@ -94,18 +97,25 @@
      * @hibernate.collection-index column=3D"target_jahia_acl_entries" typ=
e=3D"string"
      */
     public Map getEntries() {
+        if (hasEntries !=3D null && !hasEntries.booleanValue()) {
+            this.groupEntries =3D new HashMap();
+            this.userEntries =3D new HashMap();
+            return new HashMap();
+        }
         if (userEntries =3D=3D null) {
             this.groupEntries =3D new HashMap();
             this.userEntries =3D new HashMap();
-            for (Iterator iterator =3D entries.keySet().iterator(); iterat=
or.hasNext();) {
+            Map loadedEntries =3D getEntries();
+            for (Iterator iterator =3D loadedEntries.keySet().iterator(); =
iterator.hasNext();) {
                 String s =3D (String) iterator.next();
-                JahiaAclEntry ace =3D (JahiaAclEntry) entries.get(s);
+                JahiaAclEntry ace =3D (JahiaAclEntry) loadedEntries.get(s);
                 if (ace.getComp_id().getType().intValue() =3D=3D 1) {
                     userEntries.put(s,ace);
                 } else {
                     groupEntries.put(s,ace);
                 }
             }
+            return loadedEntries;
         }
         return entries;
     }
@@ -121,7 +131,13 @@
 =

     public void setUserEntries(Map userEntries) {
         getEntries().keySet().removeAll(this.userEntries.keySet());
+        if (!userEntries.isEmpty()) {
+            setHasEntries(Boolean.TRUE);
+        }
         getEntries().putAll(userEntries);
+        if (entries.isEmpty()) {
+            setHasEntries(Boolean.FALSE);
+        }
         this.userEntries =3D userEntries;
     }
 =

@@ -132,7 +148,13 @@
 =

     public void setGroupEntries(Map groupEntries) {
         getEntries().keySet().removeAll(this.groupEntries.keySet());
+        if (!groupEntries.isEmpty()) {
+            setHasEntries(Boolean.TRUE);
+        }
         getEntries().putAll(groupEntries);
+        if (entries.isEmpty()) {
+            setHasEntries(Boolean.FALSE);
+        }
         this.groupEntries =3D groupEntries;
     }
 =

@@ -163,6 +185,18 @@
         return true;
     }
 =

+    /**
+     * @hibernate.property column=3D"hasentries_jahia_acl"
+     * length=3D"11"
+     */
+    public Boolean getHasEntries() {
+        return hasEntries;
+    }
+
+    public void setHasEntries(Boolean hasEntries) {
+        this.hasEntries =3D hasEntries;
+    }
+
     private transient JahiaAcl parent;
 =

     private Integer parentId;
@@ -211,13 +245,14 @@
         acl.setParentId(parentId);
         acl.setInheritance(inheritance);
         acl.setId(id);
-        acl.setEntries(new HashMap(entries));
+        acl.setEntries(new HashMap(getEntries()));
+        acl.setHasEntries(getHasEntries());
         return acl;
     }
 =

     public boolean equals(Object obj) {
         if (this =3D=3D obj) return true;
-        =

+
         if (obj !=3D null && this.getClass() =3D=3D obj.getClass()) {
             final JahiaAcl castOther =3D (JahiaAcl) obj;
             return new EqualsBuilder()
@@ -242,6 +277,9 @@
 // -------------------------- OTHER METHODS --------------------------
 =

     public boolean clearEntries(int userTypeEntry) {
+        if (getEntries().isEmpty()) {
+            return true;
+        }
         if (userTypeEntry =3D=3D ACLInfo.USER_TYPE_ENTRY) {
             entries.keySet().removeAll(getUserEntries().keySet());
             userEntries.clear();
@@ -249,6 +287,9 @@
             entries.keySet().removeAll(getGroupEntries().keySet());
             groupEntries.clear();
         }
+        if (entries.isEmpty()) {
+            setHasEntries(Boolean.FALSE);
+        }
         return true;
     }
 =

@@ -579,12 +620,18 @@
     public boolean removeGroupEntry(JahiaGroup group) {
         getGroupEntries().remove(group.getName());
         entries.remove(group.getName());
+        if (entries.isEmpty()) {
+            setHasEntries(Boolean.FALSE);
+        }
         return true;
     }
 =

     public boolean removeUserEntry(JahiaUser user) {
         getUserEntries().remove(user.getName());
         entries.remove(user.getName());
+        if (entries.isEmpty()) {
+            setHasEntries(Boolean.FALSE);
+        }
         return true;
     }
 =

@@ -599,6 +646,7 @@
 =

         } else {
             //Create new jahiaAclEntry to ensure presence of pk
+            setHasEntries(Boolean.TRUE);
             current =3D new JahiaAclEntry(
                     new JahiaAclEntryPK(this, new Integer(ACLInfo.GROUP_TY=
PE_ENTRY), group.getName()),
                     entry.getEntryState(), entry.getEntryTri());
@@ -614,6 +662,7 @@
             current.setEntryState(entry.getEntryState());
             current.setEntryTri(entry.getEntryTri());
         } else {
+            setHasEntries(Boolean.TRUE);
             current =3D new JahiaAclEntry(
                     new JahiaAclEntryPK(this, new Integer(ACLInfo.USER_TYP=
E_ENTRY),
                     user.getName()),

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

Reply via email to