Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.mapdb;
  
  
  import org.junit.Test;
  
  import java.io.DataInput;
  import java.io.DataOutput;
 import java.util.Map;
 
 public class Issue150Test {
 
     @Test
     public void test() {
         // TxMaker txMaker = DBMaker.newFileDB(new File("/tmp/mapdb.test"))
         // .closeOnJvmShutdown().asyncWriteDisable().makeTxMaker();
         TxMaker txMaker = DBMaker.newMemoryDB().closeOnJvmShutdown()
                 .makeTxMaker();
 
         DB db = txMaker.makeTx();
 
         EntityA x = new EntityA();
         x.setId(126l);
         x.setName("nameXXX");
 
         Serializer<EntityAvalueSerializer = new CustomSerializer();
         Map<LongEntityAmap = db.createHashMap("entitya").valueSerializer(valueSerializer).make();
 
         map.put(x.getId(), x);
 
         db.commit();
 
         EntityA y = (EntityAtxMaker.makeTx().getHashMap("entitya")
                 .get(x.getId());
         ..println(x.equals(y));
 
         txMaker.close();
     }
 
     private static final class CustomSerializer implements
             Serializer<Issue150Test.EntityA>, Serializable {
 
         @Override
         public void serialize(DataOutput outEntityA valuethrows IOException {
             out.writeLong(value.getId());
             out.writeUTF(value.getName());
         }
 
         @Override
         public EntityA deserialize(DataInput inint available)
                 throws IOException {
 
             EntityA a = new EntityA();
             a.setId(in.readLong());
             a.setName(in.readUTF());
             return a;
         }
 
         @Override
         public int fixedSize() {
             return -1;
         }
 
     }
 
     public static class EntityA implements Serializable {
 
         private Long id;
 
         private String name;
 
         public Long getId() {
             return ;
         }
 
         public void setId(Long id) {
             this. = id;
         }
 
         public String getName() {
             return ;
         }
 
         public void setName(String name) {
             this. = name;
         }
 
         @Override
         public int hashCode() {
             final int prime = 31;
             int result = 1;
             result = prime * result + (( == null) ? 0 : .hashCode());
             result = prime * result + (( == null) ? 0 : .hashCode());
             return result;
         }
 
         @Override
         public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            EntityA other = (EntityAobj;
            if ( == null) {
                if (other.id != null)
                    return false;
            } else if (!.equals(other.id))
                return false;
            if ( == null) {
                if (other.name != null)
                    return false;
            } else if (!.equals(other.name))
                return false;
            return true;
        }
    }
New to GrepCode? Check out our FAQ X