Carve - Sling Object Relational Mapper

Carve is a Sling Model Object Relational Mapper that aims to simplify writing to data with Sling Models. Jetpack Carve aims to provide an ORM-like experience like Hibernate offers for SQL-based systems.

Biggest advantages

Converting resources into Sling Models is not new. With Carve, Sling Models can write the containing information back to the repository. The location is configurable on the CarveModel annotation and the structure inside this location can be determined with a PolicyProvider:

  • SimplePathPolicyProvider: The node is named as the id. This should be used for limited amount of nodes. (e.g. /node-id)
  • BucketPathPolicyProvider: The node is structured in a 2-level bucket, where an MD5 hash is used to split nodes into buckets to avoid hundreds of nodes in 1 single folder. (e.g. /ABC/DEF/node-id)
  • DatePathPolicyProvider: The nodes are structured in a folder following the current date (e.g. /yyyy/MM/dd/HH/mm/node-id)

ChildResources are also supported, which will create a sub-node.

Ready to try this out?

Add the following dependency to your pom.xml file:

    <dependency>
        <groupId>be.ida-mediafoundry.jetpack</groupId>
        <artifactId>carve.core</artifactId>
        <version>1.0.0</version>
        <scope>provided</scope>
    </dependency>

Want to learn more on how this works?

Create a Sling Model, which is also a CarveModel:

 



 
























    @CarveModel(pathPolicyProvider = SimplePathPolicyProvider.class, location = "/etc/patches/completed")
    @Model(adaptables = Resource.class)
    public class PatchResult {
    
        @CarveId
        @Inject
        private String id;
    
        @Inject
        @Named("patch-status")
        private String status;
        
        public PatchResult() {
        }
    
        public PatchResult(String id, String status) {
            this.id = id;
            this.status = status;
        }
        
        public String getId() {
            return id;
        }
    
        public String getStatus() {
            return status;
        }
    }

Use the ModelManager to persist or retrieve the Sling Models:

 







 




 


    import be.ida_mediafoundry.jetpack.carve.manager.ModelManager;
    
    ...
    
    @Reference
    private ModelManager modelManager;

    public PatchResult getResult(String id) throws ModelManagerException {
        return modelManager.retrieve(PatchResult.class, id);
    }

    public void createResult(String id) throws ModelManagerException {
        PatchResult patchResult = new PatchResult(id, "In Progress");
        modelManager.persist(patchResult);
    }