类org.hibernate.Cache源码实例Demo

下面列出了怎么用org.hibernate.Cache的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: es   文件: HibernateCacheMonitorController.java
@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 "操作成功";
}
 
源代码2 项目: ctsms   文件: ToolsServiceImpl.java
@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();
	}
}
 
源代码3 项目: judgels   文件: LegacySessionFactory.java
@Override
public Cache getCache() {
    return null;
}
 
/** {@inheritDoc} */
@Override public Cache getCache() {
    return null;
}
 
/** {@inheritDoc} */
@Override public Cache getCache() {
    return null;
}
 
/** {@inheritDoc} */
@Override public Cache getCache() {
    return null;
}
 
源代码7 项目: gocd   文件: GoConfigMigratorIntegrationTest.java
@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");
}
 
源代码8 项目: lemon   文件: SessionFactoryWrapper.java
public Cache getCache() {
    return sessionFactoryImplementor.getCache();
}
 
源代码9 项目: es   文件: HibernateUtils.java
/**
 * 根据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();
}
 
源代码10 项目: es   文件: HibernateUtils.java
/**
 * 根据 jpa EntityManager 获取hibernate Cache API
 *
 * @param em
 * @return
 * @see #getCache(javax.persistence.EntityManagerFactory)
 */
public static Cache getCache(EntityManager em) {
    return getCache(em.getEntityManagerFactory());
}
 
源代码11 项目: es   文件: HibernateUtils.java
/**
 * 根据jpa EntityManagerFactory 获取 hibernate Cache API
 *
 * @param emf
 * @return
 */
public static Cache getCache(EntityManagerFactory emf) {
    return getSessionFactory(emf).getCache();
}
 
 类所在包
 同包方法