Package org.infinispan.cli.interpreter.codec

Examples of org.infinispan.cli.interpreter.codec.Codec


      return codec;
   }

   @Override
   public Codec getCodec(String codec) throws CodecException {
      Codec c = codecRegistry.getCodec(codec);
      if (c == null) {
         throw log.noSuchCodec(codec);
      } else {
         return c;
      }
View Full Code Here


   }

   @Override
   public Result execute(Session session) throws StatementException {
      Cache<Object, Object> cache = session.getCache(keyData.getCacheName());
      Codec codec = session.getCodec();
      if (options.size() > 0) {
         for (Option option : options) {
            switch (option.toEnum(Options.class)) {
            case CODEC: {
               if(option.getParameter()==null) {
                  throw log.missingOptionParameter(option.getName());
               } else {
                  codec = session.getCodec(option.getParameter());
               }
               break;
            }
            }
         }
      }
      Object encodedKey = codec.encodeKey(keyData.getKey());
      Object encodedOldValue = codec.encodeValue(oldValue);
      Object encodedNewValue = codec.encodeValue(newValue);
      if (expires == null) {
         if(oldValue!=null) {
            cache.replace(encodedKey, encodedOldValue, encodedNewValue);
         } else {
            cache.replace(encodedKey, encodedNewValue);
View Full Code Here

   }

   @Override
   public Result execute(Session session) throws StatementException {
      Cache<Object, Object> cache = session.getCache(keyData.getCacheName());
      Codec codec = session.getCodec();
      if (options.size() > 0) {
         for (Option option : options) {
            switch (option.toEnum(Options.class)) {
            case CODEC: {
               if (option.getParameter() == null) {
                  throw log.missingOptionParameter(option.getName());
               } else {
                  codec = session.getCodec(option.getParameter());
               }
            }
            }
         }
      }
      DistributionManager distributionManager = cache.getAdvancedCache().getDistributionManager();
      if(distributionManager!=null) {
         Object key = keyData.getKey();
         List<Address> addresses = distributionManager.locate(codec.encodeKey(key));
         return new StringResult(addresses.toString());
      } else {
         throw log.cacheNotDistributed();
      }
   }
View Full Code Here

   }

   @Override
   public Result execute(Session session) throws StatementException {
      Cache<Object, Object> cache = session.getCache(keyData.getCacheName());
      Codec codec = session.getCodec();
      boolean overwrite = true;
      if (options.size() > 0) {
         for (Option option : options) {
            switch (option.toEnum(Options.class)) {
            case CODEC: {
               if (option.getParameter() == null) {
                  throw log.missingOptionParameter(option.getName());
               } else {
                  codec = session.getCodec(option.getParameter());
               }
               break;
            }
            case IFABSENT: {
               overwrite = false;
               break;
            }
            }
         }
      }
      Object encodedKey = codec.encodeKey(keyData.getKey());
      Object encodedValue = codec.encodeValue(value);
      if (expires == null) {
         if (overwrite) {
            cache.put(encodedKey, encodedValue);
         } else {
            cache.putIfAbsent(encodedKey, encodedValue);
View Full Code Here

   @Override
   public Result execute(Session session) throws StatementException {
      Cache<Object, Object> cache = session.getCache(keyData.getCacheName());
      Object key = keyData.key;
      Codec codec = session.getCodec();
      if (options.size() > 0) {
         for (Option option : options) {
            switch (option.toEnum(Options.class)) {
            case CODEC: {
               if (option.getParameter() == null) {
                  throw log.missingOptionParameter(option.getName());
               } else {
                  codec = session.getCodec(option.getParameter());
               }
            }
            }
         }
      }
      Object value = cache.get(codec.encodeKey(key));
      if (value == null) {
         return new StringResult("null");
      } else {
         Object decoded = codec.decodeValue(value);
         if (decoded instanceof String) {
            return new StringResult((String) decoded);
         } else if (decoded.getClass().isPrimitive()) {
            return new StringResult(decoded.toString());
         } else {
View Full Code Here

      return codec;
   }

   @Override
   public Codec getCodec(String codec) throws CodecException {
      Codec c = codecRegistry.getCodec(codec);
      if (c == null) {
         throw log.noSuchCodec(codec);
      } else {
         return c;
      }
View Full Code Here

      return codec;
   }

   @Override
   public Codec getCodec(String codec) throws CodecException {
      Codec c = codecRegistry.getCodec(codec);
      if (c == null) {
         throw log.noSuchCodec(codec);
      } else {
         return c;
      }
View Full Code Here

   }

   @Override
   public Result execute(Session session) throws StatementException {
      Cache<Object, Object> cache = session.getCache(keyData.getCacheName());
      Codec codec = session.getCodec();
      if (options.size() > 0) {
         for (Option option : options) {
            switch (option.toEnum(Options.class)) {
            case CODEC: {
               if(option.getParameter()==null) {
                  throw log.missingOptionParameter(option.getName());
               } else {
                  codec = session.getCodec(option.getParameter());
               }
               break;
            }
            }
         }
      }
      Object encodedKey = codec.encodeKey(keyData.getKey());
      Object encodedOldValue = codec.encodeValue(oldValue);
      Object encodedNewValue = codec.encodeValue(newValue);
      if (expires == null) {
         if(oldValue!=null) {
            cache.replace(encodedKey, encodedOldValue, encodedNewValue);
         } else {
            cache.replace(encodedKey, encodedNewValue);
View Full Code Here

   }

   @Override
   public Result execute(Session session) throws StatementException {
      Cache<Object, Object> cache = session.getCache(keyData.getCacheName());
      Codec codec = session.getCodec();
      if (options.size() > 0) {
         for (Option option : options) {
            switch (option.toEnum(Options.class)) {
            case CODEC: {
               if (option.getParameter() == null) {
                  throw log.missingOptionParameter(option.getName());
               } else {
                  codec = session.getCodec(option.getParameter());
               }
            }
            }
         }
      }
      DistributionManager distributionManager = cache.getAdvancedCache().getDistributionManager();
      if(distributionManager!=null) {
         Object key = keyData.getKey();
         List<Address> addresses = distributionManager.locate(codec.encodeKey(key));
         return new StringResult(addresses.toString());
      } else {
         throw log.cacheNotDistributed();
      }
   }
View Full Code Here

   }

   @Override
   public Result execute(Session session) throws StatementException {
      AdvancedCache<Object, Object> cache = session.getCache(keyData.getCacheName()).getAdvancedCache();
      Codec codec = session.getCodec();
      boolean overwrite = true;
      if (options.size() > 0) {
         for (Option option : options) {
            switch (option.toEnum(Options.class)) {
            case CODEC: {
               if (option.getParameter() == null) {
                  throw log.missingOptionParameter(option.getName());
               } else {
                  codec = session.getCodec(option.getParameter());
               }
               break;
            }
            case IFABSENT: {
               overwrite = false;
               break;
            }
            }
         }
      }
      Object encodedKey = codec.encodeKey(keyData.getKey());
      Object encodedValue = codec.encodeValue(value);
      Metadata metadata = codec.encodeMetadata(cache, expires, maxIdle);

      if (overwrite) {
         cache.put(encodedKey, encodedValue, metadata);
      } else {
         cache.putIfAbsent(encodedKey, encodedValue, metadata);
View Full Code Here

TOP

Related Classes of org.infinispan.cli.interpreter.codec.Codec

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.