Package com.mrivanplays.sqlhelper
Class SQLHelper
- java.lang.Object
-
- com.mrivanplays.sqlhelper.SQLHelper
-
public final class SQLHelper extends Object
Represents the heart of the library "SQLHelper".
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AlterStatement
alterTable()
Creates a new "ALTER" query object.void
close()
Closes the connection to the remote database.void
connect()
Connects to the remote database.CreateStatement
create()
Creates a new "CREATE TABLE IF NOT EXISTS" query object.DeleteStatement
delete()
Creates a new "DELETE" query object.DropStatement
dropTable()
Creates a new "DROP" query object.SQLConnectionFactory
getConnectionFactory()
Returns theSQLConnectionFactory
, which corresponds to the specifiedConnectionType
Set<ConnectionType>
getKnownConnectionTypes()
Returns an unmodifiableSet
, containing all knownConnectionTypes
InsertStatement
insert()
Creates a new "INSERT" query object.boolean
isRegistered(ConnectionType connectionType)
Returns whenever the specifiedConnectionType
is already registered.void
registerConnectionFactory(ConnectionType connectionType, SQLConnectionFactory connectionFactory)
Registers a new connection factorySelectStatement
select()
Creates a new "SELECT" query object.void
setAsyncExecutor(Executor async)
Sets a newExecutor
for async queries.void
setConnectionConfig(ConnectionConfig connectionConfig)
Sets a newConnectionConfig
.TruncateStatement
truncate()
Creates a new "TRUNCATE" query object.UpdateStatement
update()
Creates a new "UPDATE" query object.
-
-
-
Constructor Detail
-
SQLHelper
public SQLHelper(ConnectionConfig connectionConfig, Executor async)
Creates a new instance of this class.- Parameters:
connectionConfig
- connection configasync
- executor for asynchronous queries. If you want them synchronous, you can specify null.
-
SQLHelper
public SQLHelper(Executor async)
-
SQLHelper
public SQLHelper()
-
-
Method Detail
-
connect
public void connect()
Connects to the remote database.
-
close
public void close()
Closes the connection to the remote database.
-
getConnectionFactory
public SQLConnectionFactory getConnectionFactory()
Returns theSQLConnectionFactory
, which corresponds to the specifiedConnectionType
- Returns:
- connection factory
-
registerConnectionFactory
public void registerConnectionFactory(ConnectionType connectionType, SQLConnectionFactory connectionFactory)
Registers a new connection factory- Parameters:
connectionType
- the connection type you want to register a factory forconnectionFactory
- the connection factory you want to register- Throws:
IllegalArgumentException
- if the connection type has already a registered factory
-
isRegistered
public boolean isRegistered(ConnectionType connectionType)
Returns whenever the specifiedConnectionType
is already registered.- Parameters:
connectionType
- the connection type you want to check if its registered or not- Returns:
true
if registered,false
otherwise
-
setConnectionConfig
public void setConnectionConfig(ConnectionConfig connectionConfig)
Sets a newConnectionConfig
.- Parameters:
connectionConfig
- value
-
setAsyncExecutor
public void setAsyncExecutor(Executor async)
Sets a newExecutor
for async queries.- Parameters:
async
- executor
-
getKnownConnectionTypes
public Set<ConnectionType> getKnownConnectionTypes()
Returns an unmodifiableSet
, containing all knownConnectionTypes
- Returns:
- connection types
-
select
public SelectStatement select()
Creates a new "SELECT" query object.- Returns:
- select statement
-
insert
public InsertStatement insert()
Creates a new "INSERT" query object.- Returns:
- insert statement
-
create
public CreateStatement create()
Creates a new "CREATE TABLE IF NOT EXISTS" query object.- Returns:
- create statement
-
update
public UpdateStatement update()
Creates a new "UPDATE" query object.- Returns:
- update statement
-
delete
public DeleteStatement delete()
Creates a new "DELETE" query object.- Returns:
- delete statement
-
alterTable
public AlterStatement alterTable()
Creates a new "ALTER" query object.- Returns:
- alter statement
-
dropTable
public DropStatement dropTable()
Creates a new "DROP" query object.- Returns:
- drop statement
-
truncate
public TruncateStatement truncate()
Creates a new "TRUNCATE" query object.- Returns:
- truncate statement
-
-