Skip navigation
Toggle Sidebar

Getting started

To start using PackRat library, you need to take following simple steps:

  1. Put lib packer.jar into application classpath.
  2. Define by annotations (see Compression Schema Description) what fields will be compressed, indexed or left as is.
    import org.openspaces.packrat.annotations.*
    
    @CompressedClass(type = "entry")
    public class ExamplePojo {
    
        @IndexField
        private Integer name;
    
        private Integer integerValue;
    
        @CompressedField
        private Double doubleValue;
        // ...................................

    It is common practive to store all your domain POJOs in one package

  3. Run code generator for package with target POJOs
    PackageGenerator packageGenerator = new PackageGenerator();
    packageGenerator.generate("org.openspaces.packrat.example");

    This will generate and write code for Packer and Packed objects into the working directory (will be fixed shortly).

  4. Put newly generated files (in this example ExamplePojoPacked.java, ExamplePojoPacker.java) into package of your choice.
  5. Start using it!
    Packer packer = new Packer();
    
      IJSpace space = (IJSpace) SpaceFinder.find("jini://*/*/mySpace");
    
      ExamplePojo example = new ExamplePojo();
    
      pojo.setId(12);
      pojo.setBoolValue(true);
      pojo.setIntegerValue(12);
      // ...................................
    
      //write packed entry to space
      space.write(packer.pack(example), null, Lease.FOREVER);
    
      //search pojo by template
      ExamplePojo template = new ExamplePojo();
      Entry[] entries = space.readMultiple(packer.packForTemplate(template), null, 1000);
      for(Entry entry:entries){
          ExamplePojo res = packer.unpack(entry);
      }
  6. Enjoy reduced footprint of your POJOs!
Adaptavist Theme Builder Powered by Atlassian Confluence