Class Redis

java.lang.Object
org.proto4j.redis.Redis

public final class Redis
extends java.lang.Object
Redis adapts a Java interface into calls to a connected database by using annotations on the declared methods and its parameters. Create instances with providing your interface class and the SQLConfiguration or SQLSource to the create(java.lang.Class<API>, org.proto4j.redis.sql.SQLConfiguration) method.

For example (with usage of the SQLite factory),


 SQLConfiguration config = new SQLiteConfiguration("mydb");
 MyApi api = Redis.create(MyApi.class, config);

 List<User> list = api.fetchUsersFrom("table_two");
 
Version:
1.0
Author:
MatrixEditor
  • Method Summary

    Modifier and Type Method Description
    static <API> API create​(java.lang.Class<API> cls, SQLConfiguration configuration)
    Create an implementation of the API methods defined by the api interface.
    static <API> API create​(java.lang.Class<API> cls, SQLSource source)
    Create an implementation of the API methods defined by the api interface.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static <API> API create​(java.lang.Class<API> cls, SQLConfiguration configuration)
      Create an implementation of the API methods defined by the api interface.

      Method parameters annotated with Param can be used to dynamically replace parts of the sql statement. Replacement sections are denoted by an identifier surrounded by curly braces (e.g., "{abc}").

      The creation of SQLSource and SQLService objects are delegated to the specified class that implements the basic functions from the SQLFactory interface.

      For example,

       @SQL(SQLiteFactory.FACTORY)
       public interface UserStorage {
           @SQL.Select("select * from {table}")
           public List<User> fetchUsersFrom(@Param("table") String tb);
       }
       
      Type Parameters:
      API - the type of the api
      Parameters:
      cls - the interface tha will be implemented
      configuration - the SQLConfiguration instance used to create a SQLSource.
      Returns:
      a new instance for the specified interface type
    • create

      public static <API> API create​(java.lang.Class<API> cls, SQLSource source)
      Create an implementation of the API methods defined by the api interface.
      Type Parameters:
      API - the type of the api
      Parameters:
      cls - the interface tha will be implemented
      source - the SQLSource instance with a SQLConfiguration.
      Returns:
      a new instance for the specified interface type
      See Also:
      create(Class, SQLConfiguration)