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 theapi
interface.static <API> API
create(java.lang.Class<API> cls, SQLSource source)
Create an implementation of the API methods defined by theapi
interface.
-
Method Details
-
create
Create an implementation of the API methods defined by theapi
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
andSQLService
objects are delegated to the specified class that implements the basic functions from theSQLFactory
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 implementedconfiguration
- theSQLConfiguration
instance used to create aSQLSource
.- Returns:
- a new instance for the specified interface type
-
create
Create an implementation of the API methods defined by theapi
interface.- Type Parameters:
API
- the type of the api- Parameters:
cls
- the interface tha will be implementedsource
- theSQLSource
instance with aSQLConfiguration
.- Returns:
- a new instance for the specified interface type
- See Also:
create(Class, SQLConfiguration)
-