Simple Cuba JPA Repositories AddOn

Hi,

i just created an addon about Spring Query Interfaces in CUBA
aka Simple Cuba JPA Repositories (Service End for Bintray, JCenter, GoCenter, and ChartCenter | JFrog) modified from Spring Query Interfaces in CUBA – Jmix (GitHub - cuba-rnd/cuba-jpa-repositories: Example of working with Spring Data JPA repositories)

hopefully useful for you guys…

Before usage, install it to the local repository:

  • Create database and build the artifact gradlew startDb createDb build - you need database for tests.
  • Install artifact to a local repository gradlew publishToMavenLocal

Add the module to build file as an additional component in your build.gradle:
add maven url from addon’s bintray

repositories {
        .......
        maven {
            url 'https://dl.bintray.com/bitsolution/main'
        }
        .......        
    }

then, add depedencies

dependencies {
    appComponent("com.haulmont.cuba:cuba-global:$cubaVersion")
    appComponent("com.bitsolution.addons.simple.cuba.jpa.repositories:simple-cuba-jpa-repositories-global:0.1.1")
}

Then, XML configuration to enable query interfaces:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:beans="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:repositories="http://www.bitsolution.co.id/schema/data/jpa"
       xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-4.3.xsd
   http://www.bitsolution.co.id/schema/data/jpa
   http://www.bisolution.co.id/schema/data/jpa/simple-cuba-repositories.xsd">

    <!-- Annotation-based beans -->
    <context:component-scan base-package="com.bitsolution.cubaproject"/>
    
    <repositories:repositories base-package="com.bitsolution.cubaproject.repository"/>

</beans>

Voila, now it’s working

Example :

Bank.java

@Table(name = "CUBAPROJECT_BANK")
@Entity(name = "cubaproject_Bank")
@NamePattern("%s|label")
public class Bank extends BaseGenericIdEntity<String> {
    private static final long serialVersionUID = -6460255337403979003L;

    public Bank() {
        id = UUID.randomUUID().toString();
    }

    @Id
    @Column(name = "ID", nullable = false)
    protected String id;

    @Column(name = "CODE", length = 100)
    private String code;

    @NotNull
    @Column(name = "LABEL", nullable = false, length = 100)
    private String label;

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }    
}

BankRepository.java

public interface BankRepository extends SimpleCubaJpaRepository<Bank, String> {

    @SimpleJpqlQuery("SELECT Count(Bank) FROM cubaproject_Bank Bank")
    Long countAll();

    @SimpleCubaView("_local")
    @SimpleJpqlQuery("SELECT  Bank FROM cubaproject_Bank Bank ORDER BY Bank.label ASC")
    Bank findFirstByOrderByLabelDesc();

    @SimpleCubaView("_local")
    @SimpleJpqlQuery("SELECT  Bank FROM cubaproject_Bank Bank ORDER BY Bank.label ASC")
    List<Bank> findAllByOrderByLabelAsc(Pageable pageable);

    @SimpleCubaView("_local")
    @SimpleJpqlQuery(value = "SELECT  Bank FROM cubaproject_Bank Bank ORDER BY Bank.label ASC",
                     countQuery = "SELECT Count(Bank) FROM cubaproject_Bank Bank")
    Page<Bank> findPageByOrderByLabelAsc(Pageable pageable);

}
1 Like

Hi!
Thanks for your contribution. Please fill this form so that the team could review your add-on and publish it on the Marketplace.

Regards,
Natalia