Package com.avaje.ebean.cache

Examples of com.avaje.ebean.cache.ServerCache


    queryCache.put(id, query);
  }


  public void manyPropRemove(Object parentId, String propertyName) {
    ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName);
    if (manyLog.isDebugEnabled()) {
      manyLog.debug("   REMOVE {}({}).{}", cacheName, parentId, propertyName);
    }
    collectionIdsCache.remove(parentId);
  }
View Full Code Here


    }
    collectionIdsCache.remove(parentId);
  }

  public void manyPropClear(String propertyName) {
    ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName);
    if (manyLog.isDebugEnabled()) {
      manyLog.debug("   CLEAR {}(*).{} ", cacheName, propertyName);
    }
    collectionIdsCache.clear();
  }
View Full Code Here

  /**
   * Return the CachedManyIds for a given bean many property. Returns null if not in the cache.
   */
  public CachedManyIds manyPropGet(Object parentId, String propertyName) {
    ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName);
    CachedManyIds entry = (CachedManyIds) collectionIdsCache.get(parentId);
    if (entry == null) {
      if (manyLog.isTraceEnabled()) {
        manyLog.trace("   GET {}({}).{} - cache miss", cacheName, parentId, propertyName);
      }
    } else if (manyLog.isDebugEnabled()) {
View Full Code Here

      // Collect the id values
      idList.add(targetDescriptor.getId((EntityBean) bean));
    }
   
    CachedManyIds entry = new CachedManyIds(idList);
    ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, many.getName());
    if (manyLog.isDebugEnabled()) {
      manyLog.debug("   PUT {}({}).{} - ids:{}", cacheName, parentId, many.getName(), entry);
    }
    collectionIdsCache.put(parentId, entry);
  }
View Full Code Here

   
    // check if the bean itself was updated
    if (!updateRequest.isUpdatedManysOnly()) {
     
      // update the bean cache entry if it exists
      ServerCache cache = getBeanCache();
      CachedBeanData existingData = (CachedBeanData) cache.get(id);
      if (existingData != null) {
       
        if (isCachedDataTooOld(existingData)) {
          // just remove the entry from the cache
          if (beanLog.isDebugEnabled()) {
            beanLog.debug("   REMOVE {}({}) - entry too old", cacheName, id);
          }
          cache.remove(id);
         
        } else {
          // Update the cache data with the changes from our update
          CachedBeanData newData = CachedBeanDataUpdate.update(desc, existingData, updateRequest.getEntityBean());
          if (beanLog.isDebugEnabled()) {
            beanLog.debug("   UPDATE {}({})", cacheName, id);
          }
          cache.put(id, newData);
          if (newData.isNaturalKeyUpdate() && naturalKeyCache != null) {
           
            Object oldKey = newData.getOldNaturalKey();
            Object newKey = newData.getNaturalKey();
            if (natLog.isDebugEnabled()) {
View Full Code Here

  @Test
  public void test() {

    ResetBasicData.reset();

    ServerCache contactCache = Ebean.getServerCacheManager().getBeanCache(Contact.class);

    List<Contact> list = Ebean.find(Contact.class).setLoadBeanCache(true).findList();

    Assert.assertTrue(contactCache.size() > 0);

    String emailToSearch = null;
    for (Contact contact : list) {
      if (contact.getEmail() != null) {
        emailToSearch = contact.getEmail();
        break;
      }
    }

    contactCache.getStatistics(true);

    Contact c0 = Ebean.find(Contact.class).where().eq("email", emailToSearch).findUnique();

    ServerCacheStatistics stats0 = contactCache.getStatistics(false);

    Contact c1 = Ebean.find(Contact.class).where().eq("email", emailToSearch).findUnique();

    ServerCacheStatistics stats1 = contactCache.getStatistics(false);

    Assert.assertNotNull(c0);
    Assert.assertNotNull(c1);

    Assert.assertEquals(1, stats0.getHitCount());
    Assert.assertEquals(2, stats1.getHitCount());

    c1.setEmail("mychangedemail@what.com");
    Ebean.save(c1);

    Contact c2 = Ebean.find(Contact.class).where().eq("email", "mychangedemail@what.com")
        .findUnique();

    ServerCacheStatistics stats2 = contactCache.getStatistics(false);

    Assert.assertNotNull(c2);
    Assert.assertEquals(c2.getId(), c1.getId());
    Assert.assertEquals(c0.getId(), c1.getId());
    Assert.assertTrue(stats2.getHitCount() > stats1.getHitCount());
View Full Code Here

    f1.setName("one");
    f1.setDescription(null);

    Ebean.save(f1);

    ServerCache beanCache = Ebean.getServerCacheManager().getBeanCache(FeatureDescription.class);
    beanCache.getStatistics(true);

    OrmQueryDetail tunedDetail = new OrmQueryDetail();
    tunedDetail.select("name");
    TunedQueryInfo tunedInfo = new TunedQueryInfo(null, tunedDetail, 0);

    Query<FeatureDescription> query = Ebean.find(FeatureDescription.class).setId(f1.getId());

    tunedInfo.autoFetchTune((SpiQuery<?>) query);

    query.findUnique(); // PUT into cache

    FeatureDescription fd2 = query.findUnique(); // LOAD cache

    fd2.getDescription(); // invoke lazy load (this fails)

    // load the cache
    FeatureDescription fetchOne = Ebean.find(FeatureDescription.class, f1.getId());
    Assert.assertNotNull(fetchOne);
    Assert.assertEquals(1, beanCache.getStatistics(false).getSize());

    FeatureDescription fetchTwo = Ebean.find(FeatureDescription.class, f1.getId());
    FeatureDescription fetchThree = Ebean.find(FeatureDescription.class, f1.getId());
    Assert.assertSame(fetchTwo, fetchThree);
View Full Code Here

  @Test
  public void test() {

    ResetBasicData.reset();

    ServerCache custCache = cacheManager.getBeanCache(Customer.class);
    ServerCache contactCache = cacheManager.getBeanCache(Contact.class);
    ServerCache custManyIdsCache = cacheManager.getCollectionIdsCache(Customer.class, "contacts");

    // cacheManager.setCaching(Customer.class, true);
    // cacheManager.setCaching(Contact.class, true);

    custCache.clear();
    custManyIdsCache.clear();

    List<Customer> list = Ebean.find(Customer.class).setAutofetch(false).setLoadBeanCache(true)
        .order().asc("id").findList();

    Assert.assertTrue(list.size() > 1);
    // Assert.assertEquals(list.size(),
    // custCache.getStatistics(false).getSize());

    Customer customer = list.get(0);
    List<Contact> contacts = customer.getContacts();
    // Assert.assertEquals(0, custManyIdsCache.getStatistics(false).getSize());
    contacts.size();
    Assert.assertTrue(contacts.size() > 1);
    // Assert.assertEquals(1, custManyIdsCache.getStatistics(false).getSize());
    // Assert.assertEquals(0,
    // custManyIdsCache.getStatistics(false).getHitCount());

    fetchCustomer(customer.getId());
    // Assert.assertEquals(1,
    // custManyIdsCache.getStatistics(false).getHitCount());

    fetchCustomer(customer.getId());
    // Assert.assertEquals(2,
    // custManyIdsCache.getStatistics(false).getHitCount());

    int currentNumContacts = fetchCustomer(customer.getId());
    // Assert.assertEquals(3,
    // custManyIdsCache.getStatistics(false).getHitCount());

    Contact newContact = ResetBasicData.createContact("Check", "CollIds");
    newContact.setCustomer(customer);

    Ebean.save(newContact);

    int currentNumContacts2 = fetchCustomer(customer.getId());
    Assert.assertEquals(currentNumContacts + 1, currentNumContacts2);

    System.out.println("custCache:" + custCache.getStatistics(false));
    System.out.println("contactCache:" + contactCache.getStatistics(false));
    System.out.println("custManyIdsCache:" + custManyIdsCache.getStatistics(false));

  }
View Full Code Here

    // used to just load the cache - trigger loading
    OCachedBean dummyToLoad = Ebean.find(OCachedBean.class, cachedBean.getId());
    dummyToLoad.getCountries().size();
   
    ServerCache cachedBeanCountriesCache = cacheManager.getCollectionIdsCache(OCachedBean.class, "countries");
    CachedManyIds cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(cachedBean.getId());
   
    // confirm the starting data and cache entry
    Assert.assertEquals(2, dummyToLoad.getCountries().size());
    Assert.assertEquals(2, cachedManyIds.getIdList().size());

   
    // act
    OCachedBean loadedBean = Ebean.find(OCachedBean.class, cachedBean.getId());
    loadedBean.getCountries().clear();
    loadedBean.getCountries().add(Ebean.find(Country.class, "AU"));

    Ebean.save(loadedBean);

    // Get the data to assert/check against
    OCachedBean result = Ebean.find(OCachedBean.class, cachedBean.getId());
    cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(result.getId());

    // assert that data and cache both show correct data
    Assert.assertEquals(1, result.getCountries().size());
    Assert.assertEquals(1, cachedManyIds.getIdList().size());
    Assert.assertFalse(cachedManyIds.getIdList().contains("NZ"));
View Full Code Here

    // used to just load the cache - trigger loading
    OCachedBean dummyToLoad = Ebean.find(OCachedBean.class, cachedBean.getId());
    dummyToLoad.getCountries().size();
   
    ServerCache cachedBeanCountriesCache = cacheManager.getCollectionIdsCache(OCachedBean.class, "countries");
    CachedManyIds cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(cachedBean.getId());
   
    // confirm the starting data and cache entry
    Assert.assertEquals(2, dummyToLoad.getCountries().size());
    Assert.assertEquals(2, cachedManyIds.getIdList().size());

   
    // act - this time update the name property so the bean is dirty
    OCachedBean loadedBean = Ebean.find(OCachedBean.class, cachedBean.getId());
    loadedBean.setName("goodbye");
    loadedBean.getCountries().clear();
    loadedBean.getCountries().add(Ebean.find(Country.class, "AU"));

    Ebean.save(loadedBean);

    // Get the data to assert/check against
    OCachedBean result = Ebean.find(OCachedBean.class, cachedBean.getId());
    cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(result.getId());

    // assert that data and cache both show correct data
    Assert.assertEquals(1, result.getCountries().size());
    Assert.assertEquals(1, cachedManyIds.getIdList().size());
    Assert.assertFalse(cachedManyIds.getIdList().contains("NZ"));
View Full Code Here

TOP

Related Classes of com.avaje.ebean.cache.ServerCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.