Skip to content

Latest commit

 

History

History
77 lines (49 loc) · 1.85 KB

mahuta_spring_data.md

File metadata and controls

77 lines (49 loc) · 1.85 KB

Mahuta Spring Data

Mahuta Spring data allows to use Spring-data abstraction repository against Mahuta to easily store and index content on IPFS.

The content is serialised in JSON using Jackson.

Entity

Define your domain entity :

@IPFSDocument(index = "entity", indexConfiguration = "index_mapping.json", indexContent = true)
public class Entity {
    
    @Id
    private String id;

    @Hash
    private String hash;

    @Indexfield @Fulltext
    private String name;

    @Indexfield
    private int age;

    @Indexfield
    private Set<String> tags;
}

@IPFSDocument: optional Class annotation to configure the index with

  • indexName (optional): Specify the name of the index (default is entity class name)
  • indexConfiguration (optional): Specify a configuration file (classpath) for the index
  • indexContent (optional, default: false): Cache the content in the index

@Id: optional Field annotation to specify the field used to read and write the ID identifying the file

@Hash: optional Field annotation to specify a container to get the contentId after saving

@Indexfield: Optional Field annotation to indicate that the field must be indexed

@Fulltext: Optional Field annotation to indicate that the field must be indexed and used for fulltext search

Repository

Setup the repository:

Operation
E save(E entity)
E save(E entity, Map<String, Object> externalIndexFields)
Optional findById(ID id)
Iterable findAll()
Iterable findAll(Sort sort)
Page findAll(Pageable pageable)
boolean existsById(ID id)
void deleteById(ID id)
void updateIndexField(ID id, String field, Object value)
public class EntityRepository extends MahutaRepositoryImpl<Entity, String> {

    public EntityRepository(Mahuta mahuta) {
        super(mahuta); // <<< Mahuta instance
    }
}