1 43 package net.jforum.repository; 44 45 import net.jforum.cache.CacheEngine; 46 import net.jforum.cache.Cacheable; 47 import net.jforum.security.RoleCollection; 48 49 53 public class RolesRepository implements Cacheable 54 { 55 private static final String FQN = "roles"; 56 private static CacheEngine cache; 57 58 61 public void setCacheEngine(CacheEngine engine) 62 { 63 cache = engine; 64 } 65 66 72 public static RoleCollection getGroupRoles(int groupId) 73 { 74 return (RoleCollection)cache.get(FQN, Integer.toString(groupId)); 75 } 76 77 80 public static void clear() 81 { 82 cache.add(FQN, null); 83 } 84 85 90 public static RoleCollection getGroupRoles(int[] ids) 91 { 92 return (RoleCollection)cache.get(FQN, makeId(ids)); 93 } 94 95 private static String makeId(int[] ids) 96 { 97 String id = ""; 98 99 for (int i = 0; i < ids.length; i++) { 100 id += ids[i]; 101 } 102 103 return id; 104 } 105 106 112 public static void addMergedGroupRoles(int[] ids, RoleCollection roles) 113 { 114 cache.add(FQN, makeId(ids), roles); 115 } 116 117 123 public static void addGroupRoles(int groupId, RoleCollection roles) 124 { 125 cache.add(FQN, Integer.toString(groupId), roles); 126 } 127 } 128 | Popular Tags |