java.lang.Object
org.proto4j.redis.sql.SQLService
public abstract class SQLService
extends java.lang.Object
The base class for all services that execute the given sql statement on
the connected database. This class is provided by a
SQLFactory
in order to make this framework more applicable to extensions.- Since:
- 1.0
-
Constructor Summary
Constructors Constructor Description SQLService(SQLSource source)
Creates a new SQLService with the given data source. -
Method Summary
Modifier and Type Method Description abstract boolean
create(java.lang.String sql)
Executes the given CREATE-statement.abstract boolean
drop(java.lang.String sql)
Executes the given DROP-statement.SQLSource
getSource()
abstract boolean
insert(java.lang.String sql)
Executes the given INSERT-statement.abstract java.lang.Object
raw(java.lang.String sql)
Executes the given sql statement and returns the result wrapped into an object.abstract <T> T
select(java.lang.String sql, SQLExtractor<? extends T> extractor)
Executes a SELECT-statement and wraps the returnedResultSet
with the givenSQLExtractor
to a given type.void
setSource(SQLSource source)
Sets a new data source instance.abstract boolean
update(java.lang.String sql)
Executes the given UPDATE-statement.
-
Constructor Details
-
SQLService
Creates a new SQLService with the given data source. The connection to the database might not be opened yet, because will be initiated lazily.- Parameters:
source
- a source storing the database connection.
-
-
Method Details
-
select
public abstract <T> T select(java.lang.String sql, SQLExtractor<? extends T> extractor) throws java.sql.SQLExceptionExecutes a SELECT-statement and wraps the returnedResultSet
with the givenSQLExtractor
to a given type.- Type Parameters:
T
- the type to be extracted- Parameters:
sql
- the sql statementextractor
- the type extractor to create the type instance- Returns:
- a new instance of type
T
- Throws:
java.sql.SQLException
- if an error occurs
-
insert
public abstract boolean insert(java.lang.String sql) throws java.sql.SQLExceptionExecutes the given INSERT-statement.- Parameters:
sql
- the sql statement- Returns:
true
if the statement was executed successfully, otherwisefalse
- Throws:
java.sql.SQLException
- if an error occurs
-
update
public abstract boolean update(java.lang.String sql) throws java.sql.SQLExceptionExecutes the given UPDATE-statement.- Parameters:
sql
- the sql statement- Returns:
true
if the statement was executed successfully, otherwisefalse
- Throws:
java.sql.SQLException
- if an error occurs
-
create
public abstract boolean create(java.lang.String sql) throws java.sql.SQLExceptionExecutes the given CREATE-statement.- Parameters:
sql
- the sql statement- Returns:
true
if the statement was executed successfully, otherwisefalse
- Throws:
java.sql.SQLException
- if an error occurs
-
drop
public abstract boolean drop(java.lang.String sql) throws java.sql.SQLExceptionExecutes the given DROP-statement.- Parameters:
sql
- the sql statement- Returns:
true
if the statement was executed successfully, otherwisefalse
- Throws:
java.sql.SQLException
- if an error occurs
-
raw
public abstract java.lang.Object raw(java.lang.String sql) throws java.sql.SQLExceptionExecutes the given sql statement and returns the result wrapped into an object.It is strongly recommended to NOT return a
ResultSet
which was opened within a try-catch block, because it will be closed automatically and no data would be read.- Parameters:
sql
- the sql statement- Returns:
true
if the statement was executed successfully, otherwisefalse
- Throws:
java.sql.SQLException
- if an error occurs
-
getSource
- Returns:
- the data source
-
setSource
Sets a new data source instance.- Parameters:
source
- the new data source.
-