Class SQLService

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 returned ResultSet with the given SQLExtractor 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.

    Methods inherited from class java.lang.Object

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

    • SQLService

      public SQLService​(SQLSource source)
      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.SQLException
      Executes a SELECT-statement and wraps the returned ResultSet with the given SQLExtractor to a given type.
      Type Parameters:
      T - the type to be extracted
      Parameters:
      sql - the sql statement
      extractor - 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.SQLException
      Executes the given INSERT-statement.
      Parameters:
      sql - the sql statement
      Returns:
      true if the statement was executed successfully, otherwise false
      Throws:
      java.sql.SQLException - if an error occurs
    • update

      public abstract boolean update​(java.lang.String sql) throws java.sql.SQLException
      Executes the given UPDATE-statement.
      Parameters:
      sql - the sql statement
      Returns:
      true if the statement was executed successfully, otherwise false
      Throws:
      java.sql.SQLException - if an error occurs
    • create

      public abstract boolean create​(java.lang.String sql) throws java.sql.SQLException
      Executes the given CREATE-statement.
      Parameters:
      sql - the sql statement
      Returns:
      true if the statement was executed successfully, otherwise false
      Throws:
      java.sql.SQLException - if an error occurs
    • drop

      public abstract boolean drop​(java.lang.String sql) throws java.sql.SQLException
      Executes the given DROP-statement.
      Parameters:
      sql - the sql statement
      Returns:
      true if the statement was executed successfully, otherwise false
      Throws:
      java.sql.SQLException - if an error occurs
    • raw

      public abstract java.lang.Object raw​(java.lang.String sql) throws java.sql.SQLException
      Executes 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, otherwise false
      Throws:
      java.sql.SQLException - if an error occurs
    • getSource

      public SQLSource getSource()
      Returns:
      the data source
    • setSource

      public void setSource​(SQLSource source)
      Sets a new data source instance.
      Parameters:
      source - the new data source.