コード例 #1
0
 private void registerEntityNameResolvers(EntityPersister persister) {
   if (persister.getEntityMetamodel() == null
       || persister.getEntityMetamodel().getTuplizerMapping() == null) {
     return;
   }
   Iterator itr = persister.getEntityMetamodel().getTuplizerMapping().iterateTuplizers();
   while (itr.hasNext()) {
     final EntityTuplizer tuplizer = (EntityTuplizer) itr.next();
     registerEntityNameResolvers(tuplizer);
   }
 }
コード例 #2
0
  private void evictCache(
      Object entity, EntityPersister persister, EventSource session, Object[] oldState) {
    try {
      SessionFactoryImplementor factory = persister.getFactory();

      Set<String> collectionRoles =
          factory.getCollectionRolesByEntityParticipant(persister.getEntityName());
      if (collectionRoles == null || collectionRoles.isEmpty()) {
        return;
      }
      for (String role : collectionRoles) {
        CollectionPersister collectionPersister = factory.getCollectionPersister(role);
        if (!collectionPersister.hasCache()) {
          // ignore collection if no caching is used
          continue;
        }
        // this is the property this OneToMany relation is mapped by
        String mappedBy = collectionPersister.getMappedByProperty();
        if (mappedBy != null) {
          int i = persister.getEntityMetamodel().getPropertyIndex(mappedBy);
          Serializable oldId = null;
          if (oldState != null) {
            // in case of updating an entity we perhaps have to decache 2 entity collections, this
            // is the
            // old one
            oldId = session.getIdentifier(oldState[i]);
          }
          Object ref = persister.getPropertyValue(entity, i);
          Serializable id = null;
          if (ref != null) {
            id = session.getIdentifier(ref);
          }
          // only evict if the related entity has changed
          if (id != null && !id.equals(oldId)) {
            evict(id, collectionPersister, session);
            if (oldId != null) {
              evict(oldId, collectionPersister, session);
            }
          }
        } else {
          LOG.debug("Evict CollectionRegion " + role);
          collectionPersister.getCacheAccessStrategy().evictAll();
        }
      }
    } catch (Exception e) {
      // don't let decaching influence other logic
      LOG.error("", e);
    }
  }