org.hibernate.Cache Java Examples
The following examples show how to use
org.hibernate.Cache.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HibernateCacheMonitorController.java From es with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/evictQuery") @ResponseBody public String evictQuery( @RequestParam(value = "queries", required = false) String[] queries) { boolean queriesEmpty = ArrayUtils.isEmpty(queries); Cache cache = HibernateUtils.getCache(em); if(queriesEmpty) { cache.evictQueryRegions(); cache.evictDefaultQueryRegion(); } else { for(String query : queries) { cache.evictQueryRegion(query); } } return "操作成功"; }
Example #2
Source File: ToolsServiceImpl.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void handleClearHibernateCache() throws Exception { Session session = sessionFactory.getCurrentSession(); if (session != null) { session.clear(); // internal cache clear } Cache cache = sessionFactory.getCache(); if (cache != null) { cache.evictCollectionRegions(); cache.evictDefaultQueryRegion(); cache.evictEntityRegions(); cache.evictQueryRegions(); } }
Example #3
Source File: LegacySessionFactory.java From judgels with GNU General Public License v2.0 | 4 votes |
@Override public Cache getCache() { return null; }
Example #4
Source File: CacheHibernateStoreFactorySelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public Cache getCache() { return null; }
Example #5
Source File: CacheHibernateStoreFactorySelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public Cache getCache() { return null; }
Example #6
Source File: CacheHibernateStoreFactorySelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public Cache getCache() { return null; }
Example #7
Source File: GoConfigMigratorIntegrationTest.java From gocd with Apache License 2.0 | 4 votes |
@Test public void shouldMigrateAgentsOutOfXMLIntoDBAsPartOf128() throws Exception { String configContent = "" + " <environments>\n" + " <environment name=\"bar\">\n" + " </environment>\n" + " <environment name=\"baz\">\n" + " <agents>\n" + " <physical uuid=\"elastic-one\" />\n" + " <physical uuid=\"elastic-two\" />\n" + " </agents>\n" + " </environment>\n" + " <environment name=\"foo\">\n" + " <agents>\n" + " <physical uuid=\"one\" />\n" + " <physical uuid=\"two\" />\n" + " <physical uuid=\"elastic-two\" />\n" + " </agents>\n" + " </environment>\n" + " </environments>" + " <agents>" + " <agent uuid='one' hostname='one-host' ipaddress='127.0.0.1' >" + " <resources>" + " <resource>repos</resource>" + " <resource>db</resource>" + " </resources>" + " </agent>" + " <agent uuid='two' hostname='two-host' ipaddress='127.0.0.2'/>" + " <agent uuid='elastic-one' hostname='one-elastic-host' ipaddress='172.10.20.30' elasticAgentId='docker.foo1' elasticPluginId='docker'/>" + " <agent uuid='elastic-two' hostname='two-elastic-host' ipaddress='172.10.20.31' elasticAgentId='docker.foo2' elasticPluginId='docker'/>" + " </agents>"; String configXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<cruise schemaVersion=\"127\">\n" + configContent + "</cruise>"; int initialAgentCountInDb = agentDao.getAllAgents().size(); CruiseConfig migratedConfig = migrateConfigAndLoadTheNewConfig(configXml); String newConfigFile = FileUtils.readFileToString(configFile, UTF_8); // clearing out the hibernate cache so that the service fetches from the DB Cache cache = sessionFactory.getCache(); if (cache != null) { cache.evictDefaultQueryRegion(); } int newAgentCountInDb = agentDao.getAllAgents().size(); assertThat(newAgentCountInDb).isEqualTo(initialAgentCountInDb + 4); Agent staticAgent = agentDao.fetchAgentFromDBByUUID("one"); assertThat(staticAgent.getResourcesAsList()).contains("repos", "db"); assertThat(staticAgent.getEnvironmentsAsList()).contains("foo"); assertThat(staticAgent.getHostname()).isEqualTo("one-host"); assertThat(staticAgent.getIpaddress()).isEqualTo("127.0.0.1"); assertThat(staticAgent.isDisabled()).isFalse(); assertThat(staticAgent.isDeleted()).isFalse(); Agent staticAgent2 = agentDao.fetchAgentFromDBByUUID("two"); assertThat(staticAgent2.getResources()).isEmpty(); assertThat(staticAgent2.getEnvironments()).isEqualTo("foo"); assertThat(staticAgent2.getHostname()).isEqualTo("two-host"); assertThat(staticAgent2.getIpaddress()).isEqualTo("127.0.0.2"); assertThat(staticAgent2.isDisabled()).isFalse(); assertThat(staticAgent2.isDeleted()).isFalse(); Agent elasticAgent = agentDao.fetchAgentFromDBByUUID("elastic-two"); assertThat(elasticAgent.getEnvironmentsAsList()).contains("foo", "baz"); assertThat(elasticAgent.getHostname()).isEqualTo("two-elastic-host"); assertThat(elasticAgent.getIpaddress()).isEqualTo("172.10.20.31"); assertThat(elasticAgent.getElasticPluginId()).isEqualTo("docker"); assertThat(elasticAgent.getElasticAgentId()).isEqualTo("docker.foo2"); assertThat(elasticAgent.isDisabled()).isFalse(); assertThat(elasticAgent.isDeleted()).isFalse(); Agent elasticAgent1 = agentDao.fetchAgentFromDBByUUID("elastic-one"); assertThat(elasticAgent1.getEnvironments()).isEqualTo("baz"); assertThat(elasticAgent1.getHostname()).isEqualTo("one-elastic-host"); assertThat(elasticAgent1.getIpaddress()).isEqualTo("172.10.20.30"); assertThat(elasticAgent1.getElasticPluginId()).isEqualTo("docker"); assertThat(elasticAgent1.getElasticAgentId()).isEqualTo("docker.foo1"); assertThat(elasticAgent1.isDisabled()).isFalse(); assertThat(elasticAgent1.isDeleted()).isFalse(); XmlAssert.assertThat(newConfigFile).doesNotHaveXPath("//agents"); XmlAssert.assertThat(newConfigFile).doesNotHaveXPath("//environments/environment/agents"); }
Example #8
Source File: SessionFactoryWrapper.java From lemon with Apache License 2.0 | 4 votes |
public Cache getCache() { return sessionFactoryImplementor.getCache(); }
Example #9
Source File: HibernateUtils.java From es with Apache License 2.0 | 3 votes |
/** * 根据jpa EntityManagerFactory 清空二级缓存 包括: * 1、实体缓存 * 2、集合缓存 * 3、查询缓存 * 注意: * jpa Cache api 只能evict 实体缓存,其他缓存是删不掉的。。。 * * @param emf * @see org.hibernate.ejb.EntityManagerFactoryImpl.JPACache#evictAll() */ public static void evictLevel2Cache(EntityManagerFactory emf) { Cache cache = HibernateUtils.getCache(emf); cache.evictEntityRegions(); cache.evictCollectionRegions(); cache.evictDefaultQueryRegion(); cache.evictQueryRegions(); cache.evictNaturalIdRegions(); }
Example #10
Source File: HibernateUtils.java From es with Apache License 2.0 | 2 votes |
/** * 根据 jpa EntityManager 获取hibernate Cache API * * @param em * @return * @see #getCache(javax.persistence.EntityManagerFactory) */ public static Cache getCache(EntityManager em) { return getCache(em.getEntityManagerFactory()); }
Example #11
Source File: HibernateUtils.java From es with Apache License 2.0 | 2 votes |
/** * 根据jpa EntityManagerFactory 获取 hibernate Cache API * * @param emf * @return */ public static Cache getCache(EntityManagerFactory emf) { return getSessionFactory(emf).getCache(); }