GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Xiermires/EntityMatcher at 363f17cb8319eb32779fbda39c463e73c346ad3e

BranchesTags
Open more actions menu

Latest commit

 

History

11 Commits
11 Commits

Folders and files

NameName
Last commit message
Last commit date
.settings
.settings
 
 
src
src
 
 
.classpath
.classpath
 
 
.gitignore
.gitignore
 
 
.project
.project
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

Repository files navigation

EntityMatcher

Create JPQL queries through matching Entity classes in the "hamcrest way".

The matcher user can extend the functionality with its own statements (created in similar fashion as in the Statements class).

By default it translates the queries into JPQL. Native SQL support can be enabled by calling the #nativeQuery(true) method.

TODOs :

  • Flexible return types
  • Allow nesting classes
  • Static #match(T, Statement matcher)

Examples

    public void like()
    {
        final TestClass tc = EntityMatcher.matcher(TestClass.class);
        final Builder<TestClass> builder = EntityMatcher.builder(tc);

        final PreparedQuery<TestClass> query = builder.match(tc.getBar(), like("Hell%")).build();
        final List<TestClass> tcs = query.getMatching(em);
    }
    
    public void not()
    {
        final TestClass tc = EntityMatcher.matcher(TestClass.class);
        final Builder<TestClass> builder = EntityMatcher.builder(tc);

        final PreparedQuery<TestClass> query = builder.match(tc.getBar(), not(like("Hell%"))).build();
        final List<TestClass> tcs = query.getMatching(em);
    }
    
    public void greaterThan()
    {
        final TestClass tc = EntityMatcher.matcher(TestClass.class);
        final Builder<TestClass> builder = EntityMatcher.builder(tc);

        final PreparedQuery<TestClass> query = builder.match(tc.getFoo(), gt(4)).build();
        final List<TestClass> tcs = query.getMatching(em);
    }
    
    public void and()
    {
        final TestClass tc = EntityMatcher.matcher(TestClass.class);
        final Builder<TestClass> builder = EntityMatcher.builder(tc);

        final PreparedQuery<TestClass> query = builder.match(tc.getFoo(), lt(4)).and(tc.getBar(), eq("Bye")).build();
        final List<TestClass> tcs = query.getMatching(em);
    }
    
    public void columnOr()
    {
        final TestClass tc = EntityMatcher.matcher(TestClass.class);
        final Builder<TestClass> builder = EntityMatcher.builder(tc);

        final PreparedQuery<TestClass> query = builder.match(tc.getBar(), eq("Hello").or(eq("Bye"))).build();
        final List<TestClass> tcs = query.getMatching(em);
    }   

    public void join()
    {
        final TestClass tc = EntityMatcher.matcher(TestClass.class);
        final TestJoin tj = EntityMatcher.matcher(TestJoin.class);
        final Builder<TestClass> builder = EntityMatcher.builder(tc, tj);

        final PreparedQuery<TestClass> query = builder.match(tc.getBar(), join(tj.getBar())).build();
        final List<TestClass> tcs = query.getMatching(em);
    }    
    
    @Entity
    @Table(name = "TestClass")
    public static class TestClass
    {
        @Id
        @GeneratedValue
        long id;
        
        int foo;
        
        @Column(name = "Bar_v2")
        String bar;

        // test only
        TestClass(int foo, String bar)
        {
            this.foo = foo;
            this.bar = bar;
        }

        public TestClass()
        {   
        }
        
        public int getFoo()
        {
            return foo;
        }

        public void setFoo(int foo)
        {
            this.foo = foo;
        }

        public String getBar()
        {
            return bar;
        }

        public void setBar(String bar)
        {
            this.bar = bar;
        }
    }
    
    @Entity
    @Table(name = "TestJoin")
    public class TestJoin
    {
        @Id
        @GeneratedValue
        long id;

        int foo;

        @Column(name = "Bar_v2")
        String bar;

        // test only
        TestJoin(int foo, String bar)
        {
            this.foo = foo;
            this.bar = bar;
        }

        public TestJoin()
        {
        }

        public int getFoo()
        {
            return foo;
        }

        public void setFoo(int foo)
        {
            this.foo = foo;
        }

        public String getBar()
        {
            return bar;
        }

        public void setBar(String bar)
        {
            this.bar = bar;
        }
    }    

About

Create JPQL queries through matching Entity classes.

Topics

jpajpqlmatcherstatement

Resources

Readme
License
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.