Map readAclsById()

in plugin-acl/plugin/src/main/groovy/grails/plugin/springsecurity/acl/jdbc/GormAclLookupStrategy.groovy [71:115]


	Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> objects, List<Sid> sids) {
		Map<ObjectIdentity, Acl> result = [:]
		Set<ObjectIdentity> currentBatchToLoad = []

		for ( int i = 0; i < objects.size(); i++ ) {
			ObjectIdentity object = objects.get(i)
			// Check we don't already have this ACL in the results
			boolean aclFound = result.containsKey(object)

			// Check cache for the present ACL entry
			if (!aclFound) {
				Acl acl = aclCache.getFromCache(object)

				// Ensure any cached element supports all the requested SIDs
				// (they should always, as our base impl doesn't filter on SID)
				if (acl) {
					Assert.state(acl.isSidLoaded(sids),
						'Error: SID-filtered element detected when implementation does not perform SID filtering ' +
						'- have you added something to the cache manually?')

					result[acl.objectIdentity] = acl
					aclFound = true
				}
			}

			// Load the ACL from the database
			if (!aclFound) {
				currentBatchToLoad << object
			}

			// Is it time to load from JDBC the currentBatchToLoad?
			if (currentBatchToLoad.size() == batchSize || (i + 1) == objects.size()) {
				if (currentBatchToLoad) {
					Map<ObjectIdentity, Acl> loadedBatch = lookupObjectIdentities(currentBatchToLoad, sids)
					// Add loaded batch (all elements 100% initialized) to results
					result.putAll loadedBatch
					// Add the loaded batch to the cache
					loadedBatch.values().each { aclCache.putInCache it }
					currentBatchToLoad.clear()
				}
			}
		}

		result
	}