[picketlink-commits] Picketlink SVN: r1214 - in idm/trunk: example/idm-servlet and 7 other directories.

picketlink-commits at lists.jboss.org picketlink-commits at lists.jboss.org
Mon Sep 12 17:25:14 EDT 2011


Author: bdaw
Date: 2011-09-12 17:25:13 -0400 (Mon, 12 Sep 2011)
New Revision: 1214

Removed:
   idm/trunk/picketlink-idm-jpa/
Modified:
   idm/trunk/example/idm-servlet/jboss-idm-servlet.iml
   idm/trunk/picketlink-idm-api/src/main/java/org/picketlink/idm/api/RelationshipManager.java
   idm/trunk/picketlink-idm-api/src/main/java/org/picketlink/idm/api/RoleManager.java
   idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/api/session/managers/RelationshipManagerImpl.java
   idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/api/session/managers/RoleManagerImpl.java
   idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/AbstractSPISearchImpl.java
   idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/IdentityObjectRelationshipSearchImpl.java
   idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/JBossCacheIdentityStoreWrapper.java
   idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/repository/FallbackIdentityStoreRepository.java
   idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/repository/WrapperIdentityStoreRepository.java
   idm/trunk/picketlink-idm-hibernate/src/main/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreImpl.java
   idm/trunk/picketlink-idm-ldap/src/main/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreImpl.java
   idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/IdentityStore.java
   idm/trunk/pom.xml
Log:
- remove jpa store for now as it is not maintained 
- add new methods for better paginated searches
- performance tweaks for hibernate queries 


Modified: idm/trunk/example/idm-servlet/jboss-idm-servlet.iml
===================================================================
--- idm/trunk/example/idm-servlet/jboss-idm-servlet.iml	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/example/idm-servlet/jboss-idm-servlet.iml	2011-09-12 21:25:13 UTC (rev 1214)
@@ -16,11 +16,12 @@
   <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
     <output url="file://$MODULE_DIR$/target/classes" />
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
+    <exclude-output />
     <content url="file://$MODULE_DIR$">
-      <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/target" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />

Modified: idm/trunk/picketlink-idm-api/src/main/java/org/picketlink/idm/api/RelationshipManager.java
===================================================================
--- idm/trunk/picketlink-idm-api/src/main/java/org/picketlink/idm/api/RelationshipManager.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-api/src/main/java/org/picketlink/idm/api/RelationshipManager.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -311,7 +311,28 @@
                                         boolean parent,
                                         boolean cascade) throws IdentityException;
 
+
    /**
+    * Get count of groups that are associated with given group.
+    * If 'parent' parameter is set to false, all parent group will be returned. If parent parameter is
+    * set to true and 'cascade' is set to true all nested subgroubs will be returned.
+    *
+    * @param group parent group
+    * @param groupType can be null
+    * @param parent defines if given identity is parent or child side in the
+    * relationship - default is true (parent)
+    * @param cascade if true also identities from subgroubs will be retreived. Matters only when parent is set to true.
+    * Default is false
+    * @return
+    * @throws org.picketlink.idm.common.exception.IdentityException
+    */
+   int getAssociatedGroupsCount(Group group,
+                                String groupType,
+                                boolean parent,
+                                boolean cascade,
+                                IdentitySearchCriteria criteria) throws IdentityException;
+
+   /**
     * Find groups that are associated with given group.
     * If 'parent' parameter is set to false, all parent group will be returned. If parent parameter is
     * set to true and 'cascade' is set to true all nested subgroubs will be returned.

Modified: idm/trunk/picketlink-idm-api/src/main/java/org/picketlink/idm/api/RoleManager.java
===================================================================
--- idm/trunk/picketlink-idm-api/src/main/java/org/picketlink/idm/api/RoleManager.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-api/src/main/java/org/picketlink/idm/api/RoleManager.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -344,7 +344,32 @@
    <T extends IdentityType> Collection<Role> findRoles(T identityType,
                                                        RoleType roleType) throws IdentityException;
 
+
    /**
+    * Find Role objects count with a given RoleType associated with a given IdentityType
+    * @param identityType
+    * @param roleType
+    * @param criteria
+    * @return
+    * @throws IdentityException
+    */
+   int getRolesCount(IdentityType identityType,
+                     RoleType roleType,
+                     IdentitySearchCriteria criteria) throws IdentityException;
+
+   /**
+    * Find Role objects with a given RoleType associated with a given IdentityType
+    * @param identityType
+    * @param roleType
+    * @param criteria
+    * @return
+    * @throws IdentityException
+    */
+   <T extends IdentityType> Collection<Role> findRoles(T identityType,
+                                                       RoleType roleType,
+                                                       IdentitySearchCriteria criteria) throws IdentityException;
+
+   /**
     * Find Role objects with a given RoleType name associated with IdentityType for a given key
     * @param key
     * @param roleTypeName
@@ -354,7 +379,20 @@
    <T extends IdentityType> Collection<Role> findRoles(String key,
                                                        String roleTypeName) throws IdentityException;
 
+
    /**
+    * Find Role objects with a given RoleType name associated with IdentityType for a given key
+    * @param key
+    * @param roleTypeName
+    * @param criteria
+    * @return
+    * @throws IdentityException
+    */
+   <T extends IdentityType> Collection<Role> findRoles(String key,
+                                                       String roleTypeName,
+                                                       IdentitySearchCriteria criteria) throws IdentityException;
+
+   /**
     *
     * @param role
     * @return

Modified: idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/api/session/managers/RelationshipManagerImpl.java
===================================================================
--- idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/api/session/managers/RelationshipManagerImpl.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/api/session/managers/RelationshipManagerImpl.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -856,6 +856,8 @@
 
    private Collection<Group> findAssociatedGroupsCascaded(Collection<Group> previous, Group group, String groupType, boolean parent, IdentitySearchCriteria criteria) throws IdentityException
    {
+      getIdentitySession().save();
+
       Collection<Group> results = findAssociatedGroups(group, groupType, parent, false, criteria);
 
       List<Group> newResults = new LinkedList<Group>();
@@ -868,6 +870,9 @@
          {
             newResults.add(result);
             previous.add(result);
+
+            getIdentitySession().save();
+
             newResults.addAll(findAssociatedGroupsCascaded(previous, result, groupType, parent, criteria));
          }
       }
@@ -876,6 +881,14 @@
 
    }
 
+   public int getAssociatedGroupsCount(Group group, String groupType, boolean parent, boolean cascade, IdentitySearchCriteria criteria) throws IdentityException
+   {
+
+      //TODO: implement!
+      return findAssociatedGroups(group, groupType, parent, cascade, criteria).size();
+
+   }
+
    public Collection<Group> findAssociatedGroups(Group group, String groupType, boolean parent, boolean cascade, IdentitySearchCriteria criteria) throws IdentityException
    {
 
@@ -930,7 +943,6 @@
          else
          {
 
-
             Collection<IdentityObject> ios = getRepository().
                findIdentityObject(
                   getInvocationContext(),

Modified: idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/api/session/managers/RoleManagerImpl.java
===================================================================
--- idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/api/session/managers/RoleManagerImpl.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/api/session/managers/RoleManagerImpl.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -842,9 +842,73 @@
       return findGroupsWithRelatedRole(user, groupType, criteria);
    }
 
-   public Collection<Role> findRoles(IdentityType identityType, RoleType roleType) throws IdentityException
+   public int getRolesCount(IdentityType identityType, RoleType roleType, IdentitySearchCriteria criteria) throws IdentityException
    {
+      //TODO: cache support
+
       checkNotNullArgument(identityType, "IdentityType");
+
+
+//      if (cache != null)
+//      {
+//         RoleSearchImpl search = new RoleSearchImpl();
+//         search.setIdentityTypeId(identityType.getKey());
+//         search.setRoleType(roleType);
+//
+//         Collection<Role> results = cache.getRoleSearch(cacheNS, search);
+//         if (results != null)
+//         {
+//            return results;
+//         }
+//      }
+
+      int relationshipsCount = 0;
+
+      // If Identity then search for parent relationships
+      if (identityType instanceof User)
+      {
+         relationshipsCount = getRepository().
+            getRelationshipsCount(
+               getInvocationContext(),
+               createIdentityObject(identityType),
+               ROLE,
+               false,
+               true,
+               null,
+               convertSearchControls(criteria));
+      }
+      // If Group then search for child relationships
+      else
+      {
+         relationshipsCount = getRepository().
+            getRelationshipsCount(
+               getInvocationContext(),
+               createIdentityObject(identityType),
+               ROLE,
+               true,
+               true,
+               null,
+               convertSearchControls(criteria));
+      }
+
+
+//      if (cache != null)
+//      {
+//         RoleSearchImpl search = new RoleSearchImpl();
+//         search.setIdentityTypeId(identityType.getKey());
+//         search.setRoleType(roleType);
+//
+//          cache.putRoleSearch(cacheNS, search, roles);
+//
+//      }
+
+      return relationshipsCount;
+
+   }
+
+   public Collection<Role> findRoles(IdentityType identityType, RoleType roleType, IdentitySearchCriteria criteria) throws IdentityException
+   {
+      checkNotNullArgument(identityType, "IdentityType");
       //checkNotNullArgument(roleType, "RoleType");
 
       Set<Role> roles = new HashSet<Role>();
@@ -867,12 +931,28 @@
       // If Identity then search for parent relationships
       if (identityType instanceof User)
       {
-         relationships = getRepository().resolveRelationships(getInvocationContext(), createIdentityObject(identityType), ROLE, false, true, null);
+         relationships = getRepository().
+            resolveRelationships(
+               getInvocationContext(),
+               createIdentityObject(identityType),
+               ROLE,
+               false,
+               true,
+               null,
+               convertSearchControls(criteria));
       }
       // If Group then search for child relationships
       else
       {
-         relationships = getRepository().resolveRelationships(getInvocationContext(), createIdentityObject(identityType), ROLE, true, true, null);
+         relationships = getRepository().
+            resolveRelationships(
+               getInvocationContext(),
+               createIdentityObject(identityType),
+               ROLE,
+               true,
+               true,
+               null,
+               convertSearchControls(criteria));
       }
 
       for (IdentityObjectRelationship relationship : relationships)
@@ -904,14 +984,24 @@
 
    }
 
-   public Collection<Role> findRoles(String id, String roleTypeName) throws IdentityException
+   public Collection<Role> findRoles(IdentityType identityType, RoleType roleType) throws IdentityException
    {
+      return findRoles(identityType, roleType, null);
+   }
+
+   public Collection<Role> findRoles(String id, String roleTypeName, IdentitySearchCriteria criteria) throws IdentityException
+   {
       checkNotNullArgument(id, "Group id or User name");
 
       RoleType roleType = roleTypeName != null ? new SimpleRoleType(roleTypeName) : null;
-      return findRoles(createIdentityTypeFromId(id), roleType);
+      return findRoles(createIdentityTypeFromId(id), roleType, criteria);
    }
 
+   public <T extends IdentityType> Collection<Role> findRoles(String key, String roleTypeName) throws IdentityException
+   {
+      return findRoles(key, roleTypeName, null);
+   }
+
    public Map<String, String> getProperties(RoleType roleType)  throws IdentityException
    {
       checkNotNullArgument(roleType, "RoleType name");

Modified: idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/AbstractSPISearchImpl.java
===================================================================
--- idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/AbstractSPISearchImpl.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/AbstractSPISearchImpl.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -39,4 +39,32 @@
    {
       this.identityObjectSearchCriteria = identityObjectSearchCriteria;
    }
+
+   @Override
+   public boolean equals(Object o)
+   {
+      if (this == o)
+      {
+         return true;
+      }
+      if (!(o instanceof AbstractSPISearchImpl))
+      {
+         return false;
+      }
+
+      AbstractSPISearchImpl that = (AbstractSPISearchImpl)o;
+
+      if (identityObjectSearchCriteria != null ? !identityObjectSearchCriteria.equals(that.identityObjectSearchCriteria) : that.identityObjectSearchCriteria != null)
+      {
+         return false;
+      }
+
+      return true;
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return identityObjectSearchCriteria != null ? identityObjectSearchCriteria.hashCode() : 0;
+   }
 }

Modified: idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/IdentityObjectRelationshipSearchImpl.java
===================================================================
--- idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/IdentityObjectRelationshipSearchImpl.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/IdentityObjectRelationshipSearchImpl.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -206,4 +206,21 @@
 
       return true;
    }
+
+   @Override
+   public int hashCode()
+   {
+      int result = super.hashCode();
+      result = 31 * result + (fromIOName != null ? fromIOName.hashCode() : 0);
+      result = 31 * result + (fromIOType != null ? fromIOType.hashCode() : 0);
+      result = 31 * result + (toIOName != null ? toIOName.hashCode() : 0);
+      result = 31 * result + (toIOType != null ? toIOType.hashCode() : 0);
+      result = 31 * result + (relationshipType != null ? relationshipType.hashCode() : 0);
+      result = 31 * result + (ioName != null ? ioName.hashCode() : 0);
+      result = 31 * result + (ioType != null ? ioType.hashCode() : 0);
+      result = 31 * result + (parent ? 1 : 0);
+      result = 31 * result + (named ? 1 : 0);
+      result = 31 * result + (name != null ? name.hashCode() : 0);
+      return result;
+   }
 }

Modified: idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/JBossCacheIdentityStoreWrapper.java
===================================================================
--- idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/JBossCacheIdentityStoreWrapper.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/cache/JBossCacheIdentityStoreWrapper.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -245,6 +245,38 @@
 
    }
 
+   public int getIdentityObjectCount(IdentityStoreInvocationContext invocationCxt,
+                                     IdentityObject identity,
+                                     IdentityObjectRelationshipType relationshipType,
+                                     boolean parent,
+                                     IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
+      return identityStore.getIdentityObjectCount(
+         invocationCxt,
+         identity,
+         relationshipType,
+         parent,
+         criteria
+      );
+   }
+
+   public int getIdentityObjectCount(IdentityStoreInvocationContext ctx,
+                                     IdentityObject identity,
+                                     IdentityObjectRelationshipType relationshipType,
+                                     Collection<IdentityObjectType> excludes,
+                                     boolean parent,
+                                     IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
+      return identityStore.getIdentityObjectCount(
+         ctx,
+         identity,
+         relationshipType,
+         excludes,
+         parent,
+         criteria
+      );
+   }
+
    public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCxt,
                                                         IdentityObject identity,
                                                         IdentityObjectRelationshipType relationshipType,
@@ -381,12 +413,36 @@
 
    }
 
+   public int getRelationshipsCount(IdentityStoreInvocationContext ctx,
+                                    IdentityObject identity,
+                                    IdentityObjectRelationshipType type,
+                                    boolean parent,
+                                    boolean named,
+                                    String name,
+                                    IdentityObjectSearchCriteria searchCriteria) throws IdentityException
+   {
+
+      //TODO implement cache
+
+      return identityStore.getRelationshipsCount(
+         ctx,
+         identity,
+         type,
+         parent,
+         named,
+         name,
+         searchCriteria
+      );
+   }
+
+
    public Set<IdentityObjectRelationship> resolveRelationships(IdentityStoreInvocationContext invocationCtx,
                                                                IdentityObject identity,
                                                                IdentityObjectRelationshipType relationshipType,
                                                                boolean parent,
                                                                boolean named,
-                                                               String name) throws IdentityException
+                                                               String name,
+                                                               IdentityObjectSearchCriteria criteria) throws IdentityException
    {
 
       IdentityObjectRelationshipSearchImpl search = new IdentityObjectRelationshipSearchImpl();
@@ -402,6 +458,7 @@
       search.setParent(parent);
       search.setNamed(named);
       search.setName(name);
+      search.setIdentityObjectSearchCriteria(criteria);
 
       Set<IdentityObjectRelationship> results = cacheSupport.getIdentityObjectRelationshipSearch(getCacheNS(invocationCtx), search);
 
@@ -411,7 +468,7 @@
       }
 
       results = identityStore.resolveRelationships(invocationCtx,
-         identity, relationshipType, parent, named, name);
+         identity, relationshipType, parent, named, name, criteria);
 
       cacheSupport.putIdentityObjectRelationshipSearch(getCacheNS(invocationCtx), search, results);
 

Modified: idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/repository/FallbackIdentityStoreRepository.java
===================================================================
--- idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/repository/FallbackIdentityStoreRepository.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/repository/FallbackIdentityStoreRepository.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -828,6 +828,62 @@
 
    }
 
+   public int getIdentityObjectCount(IdentityStoreInvocationContext invocationCxt,
+                                     IdentityObject identity,
+                                     IdentityObjectRelationshipType relationshipType,
+                                     boolean parent,
+                                     IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
+      //TODO: merge vs sum strategy
+
+      int count = 0;
+
+      Collection<IdentityStore> mappedStores = getConfiguredIdentityStores();
+
+      for (IdentityStore mappedStore : mappedStores)
+      {
+         count += mappedStore.getIdentityObjectCount(
+            invocationCxt,
+            identity,
+            relationshipType,
+            parent,
+            criteria
+         );
+
+      }
+
+      return count;
+   }
+
+   public int getIdentityObjectCount(IdentityStoreInvocationContext ctx,
+                                     IdentityObject identity,
+                                     IdentityObjectRelationshipType relationshipType,
+                                     Collection<IdentityObjectType> excludes,
+                                     boolean parent,
+                                     IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
+
+      //TODO: merge vs sum strategy
+
+      int count = 0;
+
+      Collection<IdentityStore> mappedStores = getConfiguredIdentityStores();
+
+      for (IdentityStore mappedStore : mappedStores)
+      {
+         count += mappedStore.getIdentityObjectCount(
+            ctx,
+            identity,
+            relationshipType,
+            excludes,
+            parent,
+            criteria
+         );
+      }
+      return count;
+   }
+
+
    public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCxt,
                                                         IdentityObject identity,
                                                         IdentityObjectRelationshipType relationshipType,
@@ -1153,8 +1209,46 @@
       }
    }
 
-   public Set<IdentityObjectRelationship> resolveRelationships(IdentityStoreInvocationContext ctx, IdentityObject identity, IdentityObjectRelationshipType relationshipType, boolean parent, boolean named, String name) throws IdentityException
+   public int getRelationshipsCount(IdentityStoreInvocationContext ctx,
+                                    IdentityObject identity,
+                                    IdentityObjectRelationshipType type,
+                                    boolean parent,
+                                    boolean named,
+                                    String name,
+                                    IdentityObjectSearchCriteria searchCriteria) throws IdentityException
    {
+
+      //TODO: merge vs sum strategy
+
+      int count = 0;
+
+      Collection<IdentityStore> mappedStores = getConfiguredIdentityStores();
+
+      for (IdentityStore mappedStore : mappedStores)
+      {
+         count += mappedStore.getRelationshipsCount(
+            ctx,
+            identity,
+            type,
+            parent,
+            named,
+            name,
+            searchCriteria
+         );
+      }
+
+      return count;
+
+   }
+
+   public Set<IdentityObjectRelationship> resolveRelationships(IdentityStoreInvocationContext ctx,
+                                                               IdentityObject identity,
+                                                               IdentityObjectRelationshipType relationshipType,
+                                                               boolean parent,
+                                                               boolean named,
+                                                               String name,
+                                                               IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
       try
       {
          Set<IdentityObjectRelationship> relationships = new HashSet<IdentityObjectRelationship>();
@@ -1173,7 +1267,8 @@
             if ((!named || (named && identityStore.getSupportedFeatures().isNamedRelationshipsSupported()))
                && hasIdentityObject(storeCtx, identityStore, identity))
             {
-               relationships.addAll(identityStore.resolveRelationships(storeCtx, identity, relationshipType, parent, named, name));
+               relationships.addAll(identityStore.
+                  resolveRelationships(storeCtx, identity, relationshipType, parent, named, name, criteria));
             }
          }
 

Modified: idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/repository/WrapperIdentityStoreRepository.java
===================================================================
--- idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/repository/WrapperIdentityStoreRepository.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/repository/WrapperIdentityStoreRepository.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -184,6 +184,38 @@
       return defaultIdentityStore.findIdentityObject(resolveIdentityStoreInvocationContext(invocationCtx), identityType, criteria);
    }
 
+   public int getIdentityObjectCount(IdentityStoreInvocationContext invocationCxt,
+                                     IdentityObject identity,
+                                     IdentityObjectRelationshipType relationshipType,
+                                     boolean parent,
+                                     IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
+      return defaultIdentityStore.getIdentityObjectCount(
+         invocationCxt,
+         identity,
+         relationshipType,
+         parent,
+         criteria
+      );
+   }
+
+   public int getIdentityObjectCount(IdentityStoreInvocationContext ctx,
+                                     IdentityObject identity,
+                                     IdentityObjectRelationshipType relationshipType,
+                                     Collection<IdentityObjectType> excludes,
+                                     boolean parent,
+                                     IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
+      return defaultIdentityStore.getIdentityObjectCount(
+         ctx,
+         identity,
+         relationshipType,
+         excludes,
+         parent,
+         criteria
+      );
+   }
+
    public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCtx,
                                                         IdentityObject identity,
                                                         IdentityObjectRelationshipType relationshipType,
@@ -239,15 +271,37 @@
       return defaultIdentityStore.resolveRelationships(resolveIdentityStoreInvocationContext(invocationCxt), fromIdentity, toIdentity, relationshipType);
    }
 
+
+
+   public int getRelationshipsCount(IdentityStoreInvocationContext ctx,
+                                    IdentityObject identity,
+                                    IdentityObjectRelationshipType type,
+                                    boolean parent,
+                                    boolean named,
+                                    String name,
+                                    IdentityObjectSearchCriteria searchCriteria) throws IdentityException
+   {
+      return defaultIdentityStore.getRelationshipsCount(
+         ctx,
+         identity,
+         type,
+         parent,
+         named,
+         name,
+         searchCriteria
+      );
+   }
+
    public Set<IdentityObjectRelationship> resolveRelationships(IdentityStoreInvocationContext invocationCtx,
                                                                IdentityObject identity,
                                                                IdentityObjectRelationshipType relationshipType,
                                                                boolean parent,
                                                                boolean named,
-                                                               String name) throws IdentityException
+                                                               String name,
+                                                               IdentityObjectSearchCriteria criteria) throws IdentityException
    {
       return defaultIdentityStore.resolveRelationships(resolveIdentityStoreInvocationContext(invocationCtx),
-         identity, relationshipType, parent, named, name);
+         identity, relationshipType, parent, named, name, criteria);
    }
 
    public String createRelationshipName(IdentityStoreInvocationContext ctx,

Modified: idm/trunk/picketlink-idm-hibernate/src/main/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreImpl.java
===================================================================
--- idm/trunk/picketlink-idm-hibernate/src/main/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreImpl.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-hibernate/src/main/java/org/picketlink/idm/impl/store/hibernate/HibernateIdentityStoreImpl.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -795,17 +795,63 @@
       return findIdentityObject(ctx, identityType, null);
    }
 
+   public int getIdentityObjectCount(IdentityStoreInvocationContext invocationCxt,
+                                                        IdentityObject identity,
+                                                        IdentityObjectRelationshipType relationshipType,
+                                                        boolean parent,
+                                                       IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
+      return getIdentityObjectCount(invocationCxt, identity, relationshipType, null, parent, criteria);
+   }
 
    @SuppressWarnings("unchecked")
    public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCxt,
                                                         IdentityObject identity,
                                                         IdentityObjectRelationshipType relationshipType,
                                                         boolean parent,
-                                                       IdentityObjectSearchCriteria criteria) throws IdentityException
+                                                        IdentityObjectSearchCriteria criteria) throws IdentityException
    {
       return findIdentityObject(invocationCxt, identity, relationshipType, null, parent, criteria);
    }
 
+
+   public int getIdentityObjectCount(IdentityStoreInvocationContext ctx,
+                                                        IdentityObject identity,
+                                                        IdentityObjectRelationshipType relationshipType,
+                                                        Collection<IdentityObjectType> excludes,
+                                                        boolean parent,
+                                                        IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
+      int result;
+
+      try
+      {
+         org.hibernate.Query q = prepareIdentityObjectQuery(
+            ctx,
+            identity,
+            relationshipType,
+            excludes,
+            parent,
+            criteria,
+            false);
+
+
+         result = ((Integer)q.iterate().next() ).intValue();
+      }
+      catch (Exception e)
+      {
+         if (log.isLoggable(Level.FINER))
+         {
+            log.log(Level.FINER, "Exception occurred: ", e);
+         }
+
+         throw new IdentityException("Cannot get IdentityObject count", e);
+      }
+
+      return result;
+
+   }
+
    @SuppressWarnings("unchecked")
    public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext ctx,
                                                         IdentityObject identity,
@@ -814,12 +860,61 @@
                                                         boolean parent,
                                                        IdentityObjectSearchCriteria criteria) throws IdentityException
    {
+
+      List<IdentityObject> results;
+
+      try
+      {
+         org.hibernate.Query q = prepareIdentityObjectQuery(
+            ctx,
+            identity,
+            relationshipType,
+            excludes,
+            parent,
+            criteria,
+            false);
+
+
+         results = q.list();
+         Hibernate.initialize(results);
+
+
+      }
+      catch (Exception e)
+      {
+         if (log.isLoggable(Level.FINER))
+         {
+            log.log(Level.FINER, "Exception occurred: ", e);
+         }
+
+         throw new IdentityException("Cannot find IdentityObjects", e);
+      }
+
+      if (criteria != null && criteria.isFiltered())
+      {
+         filterByAttributesValues(results, criteria.getValues());
+         if (criteria.isPaged())
+         {
+            results = (LinkedList)cutPageFromResults(results, criteria);
+         }
+      }
+
+      return results;
+   }
+
+   @SuppressWarnings("unchecked")
+   public org.hibernate.Query prepareIdentityObjectQuery(IdentityStoreInvocationContext ctx,
+                                                        IdentityObject identity,
+                                                        IdentityObjectRelationshipType relationshipType,
+                                                        Collection<IdentityObjectType> excludes,
+                                                        boolean parent,
+                                                        IdentityObjectSearchCriteria criteria,
+                                                        boolean count) throws IdentityException
+   {
       //TODO:test
 
       HibernateIdentityObject hibernateObject = safeGet(ctx, identity);
 
-      List<IdentityObject> results;
-
       boolean orderByName = false;
       boolean ascending = true;
 
@@ -829,10 +924,12 @@
          ascending = criteria.isAscending();
       }
 
+      org.hibernate.Query q = null;
+
       try
       {
-         org.hibernate.Query q = null;
 
+
          StringBuilder hqlString = new StringBuilder("");
 
 
@@ -841,16 +938,24 @@
          if (parent)
          {
 
+            if (count)
+            {
+               hqlString.append("select count(distinct ior.toIdentityObject) from HibernateIdentityObjectRelationship ior where ");
+
+            }
+            else
+            {
+               hqlString.append("select distinct ior.toIdentityObject from HibernateIdentityObjectRelationship ior where ");
+            }
+
             if (relationshipType != null)
             {
 
-               hqlString.append("select distinct ior.toIdentityObject from HibernateIdentityObjectRelationship ior where " +
-                  "ior.toIdentityObject.name like :nameFilter and ior.type.name = :relType and ior.fromIdentityObject = :identity");
+               hqlString.append("ior.toIdentityObject.name like :nameFilter and ior.type.name = :relType and ior.fromIdentityObject = :identity");
             }
             else
             {
-               hqlString.append("select distinct ior.toIdentityObject from HibernateIdentityObjectRelationship ior where " +
-                  "ior.toIdentityObject.name like :nameFilter and ior.fromIdentityObject = :identity");
+               hqlString.append("ior.toIdentityObject.name like :nameFilter and ior.fromIdentityObject = :identity");
             }
 
             if (excludes != null && excludes.size() > 0)
@@ -859,7 +964,7 @@
                int i = 0;
                for (IdentityObjectType exclude : excludes)
                {
-                  hqlString.append(" and ior.toIdentityObject.identityType.name != ")
+                  hqlString.append(" and ior.toIdentityObject.identityType.id <> ")
                   .append(":exclude" + i++);
                }
             }
@@ -875,15 +980,24 @@
          }
          else
          {
+
+            if (count)
+            {
+               hqlString.append("select count(distinct ior.fromIdentityObject) from HibernateIdentityObjectRelationship ior where ");
+
+            }
+            else
+            {
+               hqlString.append("select distinct ior.fromIdentityObject from HibernateIdentityObjectRelationship ior where ");
+            }
+
             if (relationshipType != null)
             {
-               hqlString.append("select distinct ior.fromIdentityObject from HibernateIdentityObjectRelationship ior where " +
-                  "ior.fromIdentityObject.name like :nameFilter and ior.type.name = :relType and ior.toIdentityObject = :identity");
+               hqlString.append("ior.fromIdentityObject.name like :nameFilter and ior.type.name = :relType and ior.toIdentityObject = :identity");
             }
             else
             {
-              hqlString.append("select distinct ior.fromIdentityObject from HibernateIdentityObjectRelationship ior where " +
-                  "ior.fromIdentityObject.name like :nameFilter and ior.toIdentityObject = :identity");
+              hqlString.append("ior.fromIdentityObject.name like :nameFilter and ior.toIdentityObject = :identity");
             }
 
             if (excludes != null && excludes.size() > 0)
@@ -891,7 +1005,7 @@
                int i = 0;
                for (IdentityObjectType exclude : excludes)
                {
-                  hqlString.append(" and ior.fromIdentityObject.identityType.name != ")
+                  hqlString.append(" and ior.fromIdentityObject.identityType.id <> ")
                   .append(":exclude" + i++);
                }
             }
@@ -930,7 +1044,8 @@
             int i = 0;
             for (IdentityObjectType exclude : excludes)
             {
-               q.setParameter("exclude" + i++, exclude.getName());
+               HibernateIdentityObjectType exType = getHibernateIdentityObjectType(ctx, exclude);
+               q.setParameter("exclude" + i++, exType.getId());
             }
          }
          if (criteria != null && criteria.isPaged() && !criteria.isFiltered())
@@ -944,10 +1059,6 @@
 
 
          q.setCacheable(true);
-         results = q.list();
-         Hibernate.initialize(results);
-
-
       }
       catch (Exception e)
       {
@@ -956,19 +1067,10 @@
             log.log(Level.FINER, "Exception occurred: ", e);
          }
 
-         throw new IdentityException("Cannot find IdentityObjects", e);
+         throw new IdentityException("Cannot prepare hibernate query", e);
       }
 
-      if (criteria != null && criteria.isFiltered())
-      {
-         filterByAttributesValues(results, criteria.getValues());
-         if (criteria.isPaged())
-         {
-            results = (LinkedList)cutPageFromResults(results, criteria);
-         }
-      }
-
-      return results;
+      return q;
    }
 
    public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext ctx,
@@ -1219,16 +1321,80 @@
       return new HashSet<IdentityObjectRelationship>(results);
    }
 
+
+   public int getRelationshipsCount(IdentityStoreInvocationContext ctx,
+                                                               IdentityObject identity,
+                                                               IdentityObjectRelationshipType type,
+                                                               boolean parent,
+                                                               boolean named,
+                                                               String name,
+                                                               IdentityObjectSearchCriteria searchCriteria) throws IdentityException
+   {
+
+      Criteria criteria = prepareResolveRelationshipsCriteria(
+         ctx,
+         identity,
+         type,
+         parent,
+         named,
+         name,
+         searchCriteria
+      );
+
+      criteria.setProjection(Projections.rowCount());
+
+      Iterator result = criteria.list().iterator();
+
+
+      if (!result.hasNext())
+      {
+         return 0;
+      }
+
+      return (Integer)result.next();
+
+   }
+
+
    public Set<IdentityObjectRelationship> resolveRelationships(IdentityStoreInvocationContext ctx,
                                                                IdentityObject identity,
                                                                IdentityObjectRelationshipType type,
                                                                boolean parent,
                                                                boolean named,
-                                                               String name) throws IdentityException
+                                                               String name,
+                                                               IdentityObjectSearchCriteria searchCriteria) throws IdentityException
    {
       HibernateIdentityObject hio = safeGet(ctx, identity);
 
 
+      Criteria criteria = prepareResolveRelationshipsCriteria(
+         ctx,
+         identity,
+         type,
+         parent,
+         named,
+         name,
+         searchCriteria
+      );
+
+      List<HibernateIdentityObjectRelationship> results = criteria.list();
+
+      Hibernate.initialize(results);
+
+      return new HashSet<IdentityObjectRelationship>(results);
+   }
+
+   public Criteria prepareResolveRelationshipsCriteria(IdentityStoreInvocationContext ctx,
+                                                               IdentityObject identity,
+                                                               IdentityObjectRelationshipType type,
+                                                               boolean parent,
+                                                               boolean named,
+                                                               String name,
+                                                               IdentityObjectSearchCriteria searchCriteria) throws IdentityException
+   {
+      HibernateIdentityObject hio = safeGet(ctx, identity);
+
+
       Criteria criteria = getHibernateSession(ctx).createCriteria(HibernateIdentityObjectRelationship.class);
       criteria.setCacheable(true);
 
@@ -1264,11 +1430,17 @@
       criteria.setFetchMode("fromIdentityObject", FetchMode.JOIN);
       criteria.setFetchMode("toIdentityObject", FetchMode.JOIN);
 
-      List<HibernateIdentityObjectRelationship> results = criteria.list();
+      if (searchCriteria != null && searchCriteria.isPaged() && !searchCriteria.isFiltered())
+      {
+         if (searchCriteria.getMaxResults() > 0)
+         {
+            criteria.setMaxResults(searchCriteria.getMaxResults());
+         }
+         criteria.setFirstResult(searchCriteria.getFirstResult());
+      }
 
-      Hibernate.initialize(results);
 
-      return new HashSet<IdentityObjectRelationship>(results);
+      return criteria;
    }
 
    public String createRelationshipName(IdentityStoreInvocationContext ctx, String name) throws IdentityException, OperationNotSupportedException

Modified: idm/trunk/picketlink-idm-ldap/src/main/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreImpl.java
===================================================================
--- idm/trunk/picketlink-idm-ldap/src/main/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreImpl.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-ldap/src/main/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreImpl.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -1120,7 +1120,37 @@
       return findIdentityObject(invocationCxt, identity, relationshipType, null, parent, criteria);
    }
 
+   public int getIdentityObjectCount(IdentityStoreInvocationContext invocationCxt,
+                                     IdentityObject identity,
+                                     IdentityObjectRelationshipType relationshipType,
+                                     boolean parent,
+                                     IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
+      return findIdentityObject(
+         invocationCxt,
+         identity,
+         relationshipType,
+         parent,
+         criteria).size();
+   }
 
+   public int getIdentityObjectCount(IdentityStoreInvocationContext ctx,
+                                     IdentityObject identity,
+                                     IdentityObjectRelationshipType relationshipType,
+                                     Collection<IdentityObjectType> excludes,
+                                     boolean parent,
+                                     IdentityObjectSearchCriteria criteria) throws IdentityException
+   {
+      return findIdentityObject(
+         ctx,
+         identity,
+         relationshipType,
+         excludes,
+         parent,
+         criteria
+      ).size();
+   }
+
    public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext ctx,
                                                         IdentityObject identity,
                                                         IdentityObjectRelationshipType relationshipType,
@@ -1531,12 +1561,18 @@
       return objects;
    }
 
+   public int getRelationshipsCount(IdentityStoreInvocationContext ctx, IdentityObject identity, IdentityObjectRelationshipType type, boolean parent, boolean named, String name, IdentityObjectSearchCriteria searchCriteria) throws IdentityException
+   {
+      return resolveRelationships(ctx, identity, type, parent, named, name, searchCriteria).size();
+   }
+
    public Set<IdentityObjectRelationship> resolveRelationships(IdentityStoreInvocationContext ctx,
                                                                IdentityObject identity,
                                                                IdentityObjectRelationshipType type,
                                                                boolean parent,
                                                                boolean named,
-                                                               String name) throws IdentityException
+                                                               String name,
+                                                               IdentityObjectSearchCriteria searchCriteria) throws IdentityException
    {
 
       if (log.isLoggable(Level.FINER))

Modified: idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/IdentityStore.java
===================================================================
--- idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/IdentityStore.java	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/IdentityStore.java	2011-09-12 21:25:13 UTC (rev 1214)
@@ -182,12 +182,51 @@
     * @throws IdentityException
     */
    Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationContext invocationCxt, IdentityObject identity,
-                                                    IdentityObjectRelationshipType relationshipType,
-                                                    Collection<IdentityObjectType> excludes,
-                                                    boolean parent,
-                                                    IdentityObjectSearchCriteria criteria) throws IdentityException;
+                                                 IdentityObjectRelationshipType relationshipType,
+                                                 Collection<IdentityObjectType> excludes,
+                                                 boolean parent,
+                                                 IdentityObjectSearchCriteria criteria) throws IdentityException;
 
+   /**
+    * Get count of relationship with given identity. Relationships are directional (from parent to child).
+    *
+    * @param invocationCxt
+    * @param identity
+    * @param relationshipType
+    * @param parent defines if given identity is parent or child side in the
+    *                         relationship - default is true (parent)
+    * @param criteria
+    * @return
+    * @throws IdentityException
+    */
+   int getIdentityObjectCount(IdentityStoreInvocationContext invocationCxt,
+                              IdentityObject identity,
+                              IdentityObjectRelationshipType relationshipType,
+                              boolean parent,
+                              IdentityObjectSearchCriteria criteria) throws IdentityException;
 
+
+    /**
+    * Get count of relationship with given identity. Relationships are directional (from parent to child).
+    *
+    * @param ctx
+    * @param identity
+    * @param relationshipType
+    * @param excludes list of object types to not include in search
+    * @param parent defines if given identity is parent or child side in the
+    *                         relationship - default is true (parent)
+    * @param criteria
+    * @return
+    * @throws IdentityException
+    */
+   public int getIdentityObjectCount(IdentityStoreInvocationContext ctx,
+                                     IdentityObject identity,
+                                     IdentityObjectRelationshipType relationshipType,
+                                     Collection<IdentityObjectType> excludes,
+                                     boolean parent,
+                                     IdentityObjectSearchCriteria criteria) throws IdentityException;
+
+
    /**
     * Create directional relationship of a given type between identities
     *
@@ -252,12 +291,32 @@
 
 
    /**
+    * Get count of relationships for a given IdentityObject. Relationships can be directional and parent switch defines which
+    * role identity play in it.
+    * @param ctx
+    * @param identity
+    * @param named
+    * @param name - can be null
+    * @param searchCriteria
+    * @return
+    * @throws IdentityException
+    */
+   public int getRelationshipsCount(IdentityStoreInvocationContext ctx,
+                                    IdentityObject identity,
+                                    IdentityObjectRelationshipType type,
+                                    boolean parent,
+                                    boolean named,
+                                    String name,
+                                    IdentityObjectSearchCriteria searchCriteria) throws IdentityException;
+
+   /**
     * Resolve relationships for a given IdentityObject. Relationships can be directional and parent switch defines which
     * role identity play in it.
     * @param invocationCxt
     * @param identity
     * @param named
-    * @param name - can be null 
+    * @param name - can be null
+    * @param criteria
     * @return
     * @throws IdentityException
     */
@@ -266,10 +325,12 @@
                                                         IdentityObjectRelationshipType relationshipType,
                                                         boolean parent,
                                                         boolean named,
-                                                        String name)
+                                                        String name,
+                                                        IdentityObjectSearchCriteria criteria)
       throws IdentityException;
 
 
+
    // Named relationships
 
    /**

Modified: idm/trunk/pom.xml
===================================================================
--- idm/trunk/pom.xml	2011-09-12 12:09:55 UTC (rev 1213)
+++ idm/trunk/pom.xml	2011-09-12 21:25:13 UTC (rev 1214)
@@ -35,13 +35,10 @@
         <module>picketlink-idm-core</module>
         <module>picketlink-idm-testsuite/common</module>
         <module>picketlink-idm-hibernate</module>
-        <module>picketlink-idm-jpa</module>
         <module>picketlink-idm-ldap</module>
         <module>picketlink-idm-cache</module>
         <module>picketlink-idm-auth</module>
         <module>picketlink-idm-testsuite/integration</module>
-        <module>integration</module>
-        <module>picketlink-idm-docs</module>
       </modules>
     </profile>
     <profile>
@@ -57,7 +54,6 @@
         <module>picketlink-idm-core</module>
         <module>picketlink-idm-testsuite/common</module>
         <module>picketlink-idm-hibernate</module>
-        <module>picketlink-idm-jpa</module>
         <module>picketlink-idm-ldap</module>
         <module>picketlink-idm-cache</module>
         <module>picketlink-idm-auth</module>
@@ -74,7 +70,6 @@
         <module>picketlink-idm-core</module>
         <module>picketlink-idm-testsuite/common</module>
         <module>picketlink-idm-hibernate</module>
-        <module>picketlink-idm-jpa</module>
         <module>picketlink-idm-ldap</module>
         <module>picketlink-idm-cache</module>
         <module>picketlink-idm-auth</module>
@@ -107,7 +102,6 @@
         <module>picketlink-idm-core</module>
         <module>picketlink-idm-testsuite/common</module>
         <module>picketlink-idm-hibernate</module>
-        <module>picketlink-idm-jpa</module>
         <module>picketlink-idm-ldap</module>
         <module>picketlink-idm-cache</module>
         <module>picketlink-idm-auth</module>



More information about the picketlink-commits mailing list