Examples of MetadataEntity


Examples of org.infinispan.persistence.jpa.impl.MetadataEntity

      try {
         Object entity = findEntity(em, key);
         if (entity == null) {
            return false;
         }
         MetadataEntity metadata = null;
         if (configuration.storeMetadata()) {
            byte[] keyBytes;
            try {
               keyBytes = marshaller.objectToByteBuffer(key);
            } catch (Exception e) {
View Full Code Here

Examples of org.infinispan.persistence.jpa.impl.MetadataEntity

   @Override
   public void write(MarshalledEntry entry) {
      EntityManager em = emf.createEntityManager();

      Object entity = entry.getValue();
      MetadataEntity metadata = configuration.storeMetadata() ?
            new MetadataEntity(entry.getKeyBytes(), entry.getMetadataBytes(),
                  entry.getMetadata() == null ? Long.MAX_VALUE : entry.getMetadata().expiryTime()) : null;
      try {
         if (!configuration.entityClass().isAssignableFrom(entity.getClass())) {
            throw new JpaStoreException(String.format(
                  "This cache is configured with JPA CacheStore to only store values of type %s - cannot write %s = %s",
                  configuration.entityClass().getName(), entity, entity.getClass().getName()));
         } else {
            EntityTransaction txn = em.getTransaction();
            Object id = emf.getPersistenceUnitUtil().getIdentifier(entity);
            if (!entry.getKey().equals(id)) {
               throw new JpaStoreException(
                     "Entity id value must equal to key of cache entry: "
                           + "key = [" + entry.getKey() + "], id = ["
                           + id + "]");
            }
            long txnBegin = timeService.time();
            try {
               if (trace) log.trace("Writing " + entity + "(" + toString(metadata) + ")");
               txn.begin();

               mergeEntity(em, entity);
               if (metadata != null && metadata.hasBytes()) {
                  mergeMetadata(em, metadata);
               }

               txn.commit();
               stats.addWriteTxCommited(timeService.time() - txnBegin);
View Full Code Here

Examples of org.infinispan.persistence.jpa.impl.MetadataEntity

                  try {
                     keyBytes = marshaller.objectToByteBuffer(key);
                  } catch (Exception e) {
                     throw new JpaStoreException("Cannot marshall key", e);
                  }
                  MetadataEntity metadata = findMetadata(em, new MetadataEntityKey(keyBytes));
                  if (trace) log.trace("Metadata " + key + " -> " + toString(metadata));
                  return metadata == null || metadata.getExpiration() > timeService.wallClockTime();
               } else {
                  return true;
               }
            } finally {
               txn.commit();
View Full Code Here

Examples of org.infinispan.persistence.jpa.impl.MetadataEntity

                  try {
                     keyBytes = marshaller.objectToByteBuffer(key);
                  } catch (Exception e) {
                     throw new JpaStoreException("Failed to marshall key", e);
                  }
                  MetadataEntity metadata = findMetadata(em, new MetadataEntityKey(keyBytes));
                  if (metadata != null && metadata.getMetadata() != null) {
                     try {
                        m = (InternalMetadata) marshaller.objectFromByteBuffer(metadata.getMetadata());
                     } catch (Exception e) {
                        throw new JpaStoreException("Failed to unmarshall metadata", e);
                     }
                     if (m.isExpired(timeService.wallClockTime())) {
                        return null;
View Full Code Here

Examples of org.infinispan.persistence.jpa.impl.MetadataEntity

      try {
         keyBytes = marshaller.objectToByteBuffer(key);
      } catch (Exception e) {
         throw new JpaStoreException("Failed to marshall key", e);
      }
      MetadataEntity m = findMetadata(em, new MetadataEntityKey(keyBytes));
      if (m == null) return null;

      try {
         return (InternalMetadata) marshaller.objectFromByteBuffer(m.getMetadata());
      } catch (Exception e) {
         throw new JpaStoreException("Failed to unmarshall metadata", e);
      }
   }
View Full Code Here

Examples of org.infinispan.persistence.jpa.impl.MetadataEntity

      try {
         EntityTransaction txn = emExec.getTransaction();
         txn.begin();
         try {
            for (MetadataEntityKey metadataKey : batch) {
               MetadataEntity metadata = findMetadata(emExec, metadataKey);
               // check for transaction - I hope write skew check is done here
               if (metadata.getExpiration() > currentTime) {
                  continue;
               }

               final Object key;
               try {
                  key = marshaller.objectFromByteBuffer(metadata.getKeyBytes());
               } catch (Exception e) {
                  throw new JpaStoreException("Cannot unmarshall key", e);
               }
               Object entity = null;
               try {
View Full Code Here

Examples of org.infinispan.persistence.jpa.impl.MetadataEntity

      try {
         Object entity = findEntity(em, key);
         if (entity == null) {
            return false;
         }
         MetadataEntity metadata = null;
         if (configuration.storeMetadata()) {
            byte[] keyBytes;
            try {
               keyBytes = marshaller.objectToByteBuffer(key);
            } catch (Exception e) {
View Full Code Here

Examples of org.infinispan.persistence.jpa.impl.MetadataEntity

   @Override
   public void write(MarshalledEntry entry) {
      EntityManager em = emf.createEntityManager();

      Object entity = entry.getValue();
      MetadataEntity metadata = configuration.storeMetadata() ?
            new MetadataEntity(entry.getKeyBytes(), entry.getMetadataBytes(),
                  entry.getMetadata() == null ? Long.MAX_VALUE : entry.getMetadata().expiryTime()) : null;
      try {
         if (!configuration.entityClass().isAssignableFrom(entity.getClass())) {
            throw new JpaStoreException(String.format(
                  "This cache is configured with JPA CacheStore to only store values of type %s - cannot write %s = %s",
                  configuration.entityClass().getName(), entity, entity.getClass().getName()));
         } else {
            EntityTransaction txn = em.getTransaction();
            Object id = emf.getPersistenceUnitUtil().getIdentifier(entity);
            if (!entry.getKey().equals(id)) {
               throw new JpaStoreException(
                     "Entity id value must equal to key of cache entry: "
                           + "key = [" + entry.getKey() + "], id = ["
                           + id + "]");
            }
            long txnBegin = timeService.time();
            try {
               if (trace) log.trace("Writing " + entity + "(" + toString(metadata) + ")");
               txn.begin();

               mergeEntity(em, entity);
               if (metadata != null && metadata.hasBytes()) {
                  mergeMetadata(em, metadata);
               }

               txn.commit();
               stats.addWriteTxCommited(timeService.time() - txnBegin);
View Full Code Here

Examples of org.infinispan.persistence.jpa.impl.MetadataEntity

                  try {
                     keyBytes = marshaller.objectToByteBuffer(key);
                  } catch (Exception e) {
                     throw new JpaStoreException("Cannot marshall key", e);
                  }
                  MetadataEntity metadata = findMetadata(em, new MetadataEntityKey(keyBytes));
                  if (trace) log.trace("Metadata " + key + " -> " + toString(metadata));
                  return metadata == null || metadata.getExpiration() > timeService.wallClockTime();
               } else {
                  return true;
               }
            } finally {
               txn.commit();
View Full Code Here

Examples of org.infinispan.persistence.jpa.impl.MetadataEntity

                  try {
                     keyBytes = marshaller.objectToByteBuffer(key);
                  } catch (Exception e) {
                     throw new JpaStoreException("Failed to marshall key", e);
                  }
                  MetadataEntity metadata = findMetadata(em, new MetadataEntityKey(keyBytes));
                  if (metadata != null && metadata.getMetadata() != null) {
                     try {
                        m = (InternalMetadata) marshaller.objectFromByteBuffer(metadata.getMetadata());
                     } catch (Exception e) {
                        throw new JpaStoreException("Failed to unmarshall metadata", e);
                     }
                     if (m.isExpired(timeService.wallClockTime())) {
                        return null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.