Your First Dao - Andy-Shao/GearEE-Neo4j GitHub Wiki
This is an example, how you quick can do it.
The domain class just need which is a pojo class. Your domain class should be a java bean class. For others is not the necessary.
@Data
public class ApiKey {
private String apiName;
private String systemAlias;
}
@Data
@EqualsAndHashCode(callSuper = true)
public class Api extends ApiKey{
private String apiDescription;
}Similar with Mybatis. Simple & easy to use.
@Neo4jDao
public interface ApiDao {
@Match(sql = "MATCH (n: Api {systemAlias: #{pk.systemAlias}, apiName: #{pk.apiName}}) RETURN n")
CompletionStage<Optional<Api>> findByPk(@Param("pk") ApiKey apiKey, @Param("tx") Transaction tx);
@Create(sql = "CREATE (n:Api) SET n.systemAlias = #{api.systemAlias}, n.apiName = #{api.apiName} RETURN n")
CompletionStage<Optional<Api>> save(@Param("api) Api api, @Param("tx") Transaction tx);
@Match(sql = "MATCH (n:Api {systemAlias:$pk.systemAlias, apiName:$pk.apiName}) DETACH DELETE n")
CompletionStage<Void> removeByPk(@Param("pk") ApiKey apiKey, @Param("tx") Transaction tx);
@Match(sql = "MATCH (n:Api {systemAlias:$sys}) RETURN n")
CompletionStage<List<Api>> findSameSystem(@Param("sys")String systemAlias, @Param("tx")Transaction tx);
@Match(sql = "MATCH (n:Api {systemAlias:$page.data}) RETURN n")
CompletionStage<PageReturn<Api>> findSameSystem(@Param("page")Pageable<String> pageable, @Param("tx")Transaction tx);
default CompletionStage<Optional<Api>> trySaveOrFind(Api api, Transaction tx) {
return findByPk(api, tx).thenComposeAsync(op -> {
if(op.isPresent()) return op;
return save(api, tx);
});
}
}- java.util.concurrent.CompletionStage is a interface ,which is a new api in JDK 8, supports async processor.
- org.neo4j.driver.v1.Transaction must be include in method parameter. the sequence of parameter is not important.
- All return type of interface method must be CompletionStage.
- If the return type has com.github.andyshao.neo4j.model.PageReturn and Parameters has com.github.andyshao.neo4j.model.Pageable too, then page search is auto-creating.