@Override public CachePool createCachePool(String poolName, int cacheSize, int expiredSeconds) { CacheManager cacheManager = CacheManager.create(); Cache enCache = cacheManager.getCache(poolName); if (enCache == null) { CacheConfiguration cacheConf = cacheManager.getConfiguration() .getDefaultCacheConfiguration().clone(); cacheConf.setName(poolName); if (cacheConf.getMaxEntriesLocalHeap() != 0) { cacheConf.setMaxEntriesLocalHeap(cacheSize); } else { cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize)); } cacheConf.setTimeToIdleSeconds(expiredSeconds); Cache cache = new Cache(cacheConf); cacheManager.addCache(cache); return new EnchachePool(poolName,cache,cacheSize); } else { return new EnchachePool(poolName,enCache,cacheSize); } }
@Test public void update() { final SystemConfiguration value = em.createQuery("FROM SystemConfiguration WHERE name=:name", SystemConfiguration.class) .setParameter("name", "test-key5").getSingleResult(); em.clear(); Assert.assertNotEquals("new-value-db5", value.getValue()); Assert.assertEquals("value-db5", resource.get("test-key5")); resource.saveOrUpdate("test-key5", "new-value-db5"); // Check the data from the cache Assert.assertEquals("new-value-db5", resource.get("test-key5")); SystemConfiguration newValue = em.createQuery("FROM SystemConfiguration WHERE name=:name", SystemConfiguration.class) .setParameter("name", "test-key5").getSingleResult(); // Check data is encrypted Assert.assertNotEquals("new-value-db5", newValue.getValue()); Assert.assertEquals("new-value-db5", cryptoHelper.decrypt(newValue.getValue())); // Check previous id is kept Assert.assertEquals(value.getId(), newValue.getId()); // Check persistence of data and cache CacheManager.getInstance().getCache("configuration").removeAll(); Assert.assertEquals("new-value-db5", resource.get("test-key5")); }
@At @Ok("json") public Map<String,String> save(@Param("action")int action, @Param("..")Productlevel productlevel){ Object rtnObject; if (productlevel.getId() == null || productlevel.getId() == 0) { rtnObject = productlevelService.dao().insert(productlevel); }else{ if (action == 3) { productlevel.setId(null); rtnObject = productlevelService.dao().insert(productlevel); }else{ rtnObject = productlevelService.dao().updateIgnoreNull(productlevel); } } CacheManager.getInstance().getCache(ProductlevelService.CACHE_NAME).removeAll(); return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_productlevel", true); }
@At @Ok("json") public Map<String, String> save(@Param("action") int action, @Param("..") Aporialevel aporialevel) { Object rtnObject; if (aporialevel.getId() == null || aporialevel.getId() == 0) { rtnObject = aporialevelService.dao().insert(aporialevel); } else { if (action == 3) { aporialevel.setId(null); rtnObject = aporialevelService.dao().insert(aporialevel); } else { rtnObject = aporialevelService.dao().updateIgnoreNull(aporialevel); } } CacheManager.getInstance().getCache(AporialevelService.CACHE_NAME).removeAll(); return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_aporialevel", true); }
@Before public void prepareData() throws IOException { persistEntities("csv", new Class[] { DelegateOrg.class, ContainerScope.class, CacheCompany.class, CacheUser.class, CacheGroup.class, CacheMembership.class }, StandardCharsets.UTF_8.name()); CacheManager.getInstance().getCache("container-scopes").removeAll(); iamProvider = Mockito.mock(IamProvider.class); final IamConfiguration configuration = Mockito.mock(IamConfiguration.class); Mockito.when(iamProvider.getConfiguration()).thenReturn(configuration); userRepository = Mockito.mock(IUserRepository.class); groupRepository = Mockito.mock(IGroupRepository.class); companyRepository = Mockito.mock(ICompanyRepository.class); Mockito.when(configuration.getUserRepository()).thenReturn(userRepository); Mockito.when(configuration.getCompanyRepository()).thenReturn(companyRepository); Mockito.when(configuration.getGroupRepository()).thenReturn(groupRepository); }
@At @Ok("json") public Map<String,String> save(@Param("action")int action, @Param("..")Technicalpoint technicalpoint){ Object rtnObject; if (technicalpoint.getId() == null || technicalpoint.getId() == 0) { rtnObject = technicalpointService.dao().insert(technicalpoint); }else{ if (action == 3) { technicalpoint.setId(null); rtnObject = technicalpointService.dao().insert(technicalpoint); }else{ rtnObject = technicalpointService.dao().updateIgnoreNull(technicalpoint); } } CacheManager.getInstance().getCache(TechnicalpointService.CACHE_NAME).removeAll(); return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_technicalpoint", true); }
@At @Ok("json") public Map<String,String> save(@Param("action")int action, @Param("..")Aporia aporia){ Object rtnObject; if (aporia.getId() == null || aporia.getId() == 0) { rtnObject = aporiaService.dao().insert(aporia); }else{ if (action == 3) { aporia.setId(null); rtnObject = aporiaService.dao().insert(aporia); }else{ rtnObject = aporiaService.dao().updateIgnoreNull(aporia); } } CacheManager.getInstance().getCache(AporiaService.CACHE_NAME).removeAll(); return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_aporia", true); }
@At @Ok("json") public Map<String,String> save(@Param("action")int action, @Param("..")Product product){ Object rtnObject; if (product.getId() == null || product.getId() == 0) { rtnObject = productService.dao().insert(product); }else{ if (action == 3) { product.setId(null); rtnObject = productService.dao().insert(product); }else{ rtnObject = productService.dao().updateIgnoreNull(product); } } CacheManager.getInstance().getCache(ProductService.CACHE_NAME).removeAll(); return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_product", true); }
@Test public void verifyEhCacheTicketRegistryWithClearPass() { final Cache serviceTicketsCache = new Cache("serviceTicketsCache", 200, false, false, 100, 100); final Cache ticketGrantingTicketCache = new Cache("ticketGrantingTicketCache", 200, false, false, 100, 100); final CacheManager manager = new CacheManager(this.getClass().getClassLoader().getResourceAsStream("ehcacheClearPass.xml")); manager.addCache(serviceTicketsCache); manager.addCache(ticketGrantingTicketCache); final Map<String, String> map = new HashMap<>(); final TicketRegistry ticketRegistry = new EhCacheTicketRegistry(serviceTicketsCache, ticketGrantingTicketCache); final TicketRegistryDecorator decorator = new TicketRegistryDecorator(ticketRegistry, map); assertNotNull(decorator); assertEquals(decorator.serviceTicketCount(), 0); assertEquals(decorator.sessionCount(), 0); manager.removalAll(); manager.shutdown(); }
static Cache createLifeCache(CacheManager manager, String name) { CacheConfiguration configuration = new CacheConfiguration(name, MAX_ENTRIES); configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO) .timeToLiveSeconds(LIFE_TIME_SEC); Cache cache = new Cache(configuration); manager.addCache(cache); return cache; }
@At @Ok("json") public Map<String,String> save( @Param("..")Linktype linktype){ Object rtnObject; if (linktype.getId() == null || linktype.getId() == 0) { rtnObject = linktypeService.dao().insert(linktype); }else{ rtnObject = linktypeService.dao().updateIgnoreNull(linktype); } CacheManager.getInstance().getCache(LinktypeService.CACHE_NAME).removeAll(); return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_linktype", true); }
public int listCount(Cnd c) { Long num = 0L; Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(CACHE_COUNT_KEY) == null) { num = Long.valueOf(this.count(c)); cache.put(new Element(CACHE_COUNT_KEY, num)); }else{ num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue(); } return num.intValue(); }
@At @Ok("json") public Map<String,String> save( @Param("..")Employee employee){ Object rtnObject; if (employee.getId() == null || employee.getId() == 0) { rtnObject = employeeService.dao().insert(employee); }else{ rtnObject = employeeService.dao().updateIgnoreNull(employee); } CacheManager.getInstance().getCache(EmployeeService.CACHE_NAME).removeAll(); return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_employee", true); }
@Before public void prepareData() throws IOException { persistEntities( "csv", new Class[] { DelegateOrg.class, ContainerScope.class, CacheCompany.class, CacheUser.class, CacheGroup.class, CacheMembership.class, Project.class, Node.class, Parameter.class, Subscription.class, ParameterValue.class, CacheProjectGroup.class }, StandardCharsets.UTF_8.name()); CacheManager.getInstance().getCache("container-scopes").removeAll(); // Only with Spring context this.subscription = getSubscription("gStack", IdentityResource.SERVICE_KEY); // Coverage only resource.getKey(); }
/** * Reload the LDAP cache */ private void reloadLdapCache() { // Ensure LDAP cache is loaded CacheManager.getInstance().getCache("ldap").removeAll(); cache.getLdapData(); em.flush(); em.clear(); }
@Before public void prep() { this.manager = CacheManager.create(); this.manager.addCache("cascache"); this.cache = this.manager.getCache("cascache"); this.map = new EhcacheBackedMap(this.cache); }
static Cache createEternalCache(CacheManager manager, String name) { CacheConfiguration configuration = new CacheConfiguration(name, MAX_ENTRIES); configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO) .eternal(true); Cache cache = new Cache(configuration); manager.addCache(cache); return cache; }
public int listCount(Condition c) { Long num = 0L; Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(CACHE_COUNT_KEY) == null) { num = Long.valueOf(this.count(c)); cache.put(new Element(CACHE_COUNT_KEY, num)); }else{ num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue(); } return num.intValue(); }
@At @Ok("json") public Map<String,String> del(@Param("id")Long id) { int num = partyService.delete(id); CacheManager.getInstance().getCache(PartyService.CACHE_NAME).removeAll(); return Bjui.rtnMap((num > 0) ? true : false , "tab_party",false); }
public List<Productgroup> queryCache(Condition c,Page p) { List<Productgroup> list_productgroup = null; String cacheKey = "productgroup_list_" + p.getPageCurrent(); Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(cacheKey) == null) { list_productgroup = this.query(c, p); cache.put(new Element(cacheKey, list_productgroup)); }else{ list_productgroup = (List<Productgroup>)cache.get(cacheKey).getObjectValue(); } return list_productgroup; }
static Cache createIdleCache(CacheManager manager, String name) { return createCache( manager, name, configuration -> configuration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.FIFO) .timeToIdleSeconds(IDLE_TIME_SEC)); }
public List<Aporialevel> queryCache(Condition c,Page p) { List<Aporialevel> list_aporialevel = null; String cacheKey = "aporialevel_list_" + p.getPageCurrent(); Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(cacheKey) == null) { list_aporialevel = this.query(c, p); cache.put(new Element(cacheKey, list_aporialevel)); }else{ list_aporialevel = (List<Aporialevel>)cache.get(cacheKey).getObjectValue(); } return list_aporialevel; }
public List<Code> queryCache(Condition c,Page p) { List<Code> list_code = null; String cacheKey = "code_list_" + p.getPageCurrent(); Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(cacheKey) == null) { list_code = this.query(c, p); cache.put(new Element(cacheKey, list_code)); }else{ list_code = (List<Code>)cache.get(cacheKey).getObjectValue(); } return list_code; }
/** * Attempts to init cache to default values ignoring * exceptions. */ private void initCacheHard() { try { CacheManager.create(); } catch (Exception e) { log.error("Error creating cache", e); } }
protected void onSetUpInTransaction() { // make a cache CacheManager cacheManager = CacheManager.create(); if (! cacheManager.cacheExists("ehcache.sakai.kaltura.entries")) { cacheManager.addCache("ehcache.sakai.kaltura.entries"); } Ehcache entriesCache = cacheManager.getCache("ehcache.sakai.kaltura.entries"); // create and setup the object to be tested external = new ExternalLogicStub(); service = new KalturaAPIService(); service.setExternal(external); service.setEntriesCache(entriesCache); service.setOffline(true); // for testing we do not try to fetch real data // run the init external.currentUserId = FakeDataPreload.ADMIN_USER_ID; // DEFAULT ADMIN // UNICON settings for testing external.config.put("kaltura.partnerid", 166762); external.config.put("kaltura.adminsecret", "26d08a0ba54c911492bbc7599028295f"); external.config.put("kaltura.secret", "6e4755b613a38b19e4cfb5d7405ed170"); service.testWSInit(); // SPECIAL INIT service.getKalturaClient(); }
@At @Ok("json") public Map<String,String> del(@Param("id")Long id) { int num = studioService.delete(id); CacheManager.getInstance().getCache(StudioService.CACHE_NAME).removeAll(); return Bjui.rtnMap((num > 0) ? true : false , "tab_studio",false); }
@At @Ok("json") public Map<String,String> save( @Param("..")Marital marital){ Object rtnObject; if (marital.getId() == null || marital.getId() == 0) { rtnObject = maritalService.dao().insert(marital); }else{ rtnObject = maritalService.dao().updateIgnoreNull(marital); } CacheManager.getInstance().getCache(MaritalService.CACHE_NAME).removeAll(); return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_marital", true); }
@At @Ok("json") public Map<String,String> del(@Param("id")Long id) { int num = codeService.delete(id); CacheManager.getInstance().getCache(CodeService.CACHE_NAME).removeAll(); return Bjui.rtnMap((num > 0) ? true : false , "tab_code",false); }
@At @Ok("json") public Map<String,String> del(@Param("id")Long id) { int num = linkmanService.delete(id); CacheManager.getInstance().getCache(LinkmanService.CACHE_NAME).removeAll(); return Bjui.rtnMap((num > 0) ? true : false , "tab_linkman",false); }
@At @Ok("json") public Map<String,String> del(@Param("id")Long id) { int num = productgroupService.delete(id); CacheManager.getInstance().getCache(ProductgroupService.CACHE_NAME).removeAll(); return Bjui.rtnMap((num > 0) ? true : false , "tab_productgroup",false); }
@Test public void getCrlFromLdapWithNoCaching() throws Exception { for (int i = 0; i < 10; i++) { CacheManager.getInstance().removeAllCaches(); final Cache cache = new Cache("crlCache-1", 100, false, false, 20, 10); CacheManager.getInstance().addCache(cache); final CRLDistributionPointRevocationChecker checker = new CRLDistributionPointRevocationChecker(cache, fetcher); checker.setThrowOnFetchFailure(true); checker.setUnavailableCRLPolicy(new AllowRevocationPolicy()); final X509Certificate cert = CertUtils.readCertificate(new ClassPathResource("ldap-crl.crt")); checker.init(); checker.check(cert); } }
@At @Ok("json") public Map<String,String> save( @Param("..")Unit unit){ Object rtnObject; if (unit.getId() == null || unit.getId() == 0) { rtnObject = unitService.dao().insert(unit); }else{ rtnObject = unitService.dao().updateIgnoreNull(unit); } CacheManager.getInstance().getCache(UnitService.CACHE_NAME).removeAll(); return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_unit", true); }
@At @Ok("json") public Map<String,String> save( @Param("..")Contract contract){ Object rtnObject; if (contract.getId() == null || contract.getId() == 0) { rtnObject = contractService.dao().insert(contract); }else{ rtnObject = contractService.dao().updateIgnoreNull(contract); } CacheManager.getInstance().getCache(ContractService.CACHE_NAME).removeAll(); return Bjui.rtnMap((rtnObject == null) ? false : true, "tab_contract", true); }