Exemplo n.º 1
0
  /*
   * (non-Javadoc)
   *
   * @see com.hazelcast.core.MapStore#storeAll(java.util.Map)
   */
  @Override
  public void storeAll(Map<String, String> pairs) {
    HTable table = null;
    try {
      List<Put> puts = new ArrayList<Put>(pairs.size());
      for (Map.Entry<String, String> pair : pairs.entrySet()) {
        try {
          byte[] rowId =
              prefixDate ? IdUtil.bucketizeId(pair.getKey()) : Bytes.toBytes(pair.getKey());
          Put p = new Put(rowId);
          if (outputFormatType == StoreFormatType.SMILE) {
            p.add(family, qualifier, jsonSmileConverter.convertToSmile(pair.getValue()));
          } else {
            p.add(family, qualifier, Bytes.toBytes(pair.getValue()));
          }
          puts.add(p);
        } catch (NumberFormatException nfe) {
          LOG.error("Encountered bad key: " + pair.getKey(), nfe);
        }
      }

      table = (HTable) pool.getTable(tableName);
      table.setAutoFlush(false);
      table.put(puts);
      table.flushCommits();
    } catch (IOException e) {
      LOG.error("Error during puts", e);
    } finally {
      if (table != null) {
        pool.putTable(table);
      }
    }
  }
Exemplo n.º 2
0
 /*
  * (non-Javadoc)
  *
  * @see com.hazelcast.core.MapStore#store(java.lang.Object,
  * java.lang.Object)
  */
 @Override
 public void store(String key, String value) {
   HTableInterface table = null;
   try {
     table = pool.getTable(tableName);
     try {
       byte[] rowId = prefixDate ? IdUtil.bucketizeId(key) : Bytes.toBytes(key);
       Put p = new Put(rowId);
       if (outputFormatType == StoreFormatType.SMILE) {
         p.add(family, qualifier, jsonSmileConverter.convertToSmile(value));
       } else {
         p.add(family, qualifier, Bytes.toBytes(value));
       }
       table.put(p);
     } catch (NumberFormatException nfe) {
       LOG.error("Encountered bad key: " + key, nfe);
     }
   } catch (IOException e) {
     LOG.error("Error during put", e);
   } finally {
     if (table != null) {
       pool.putTable(table);
     }
   }
 }