public abstract class BaseJDBCStorage extends java.lang.Object implements PersistentStorage, JDBCstorage
Modifier and Type | Class and Description |
---|---|
class |
BaseJDBCStorage.SQLExecution<E>
A class allowing to pass as argument the planned execution of a query to a
service that provides relaunch
|
Modifier and Type | Field and Description |
---|---|
protected java.sql.Connection |
connection |
static int |
MAX_SQLERROR_RETRY |
static int |
TIMEOUT_SQLERROR_RETRY_MS |
INDEX_DIFFERENT, INDEX_NOT_PRESENT, INDEX_OK
Constructor and Description |
---|
BaseJDBCStorage(java.sql.Connection connection,
java.util.function.Function<java.lang.StringBuffer,StoredFieldSchema.Visitor> fieldvisitorgenerator)
creates a new JDBC storage
|
Modifier and Type | Method and Description |
---|---|
void |
cleanup()
cleans up the connection
|
void |
closeConnections()
close all connections of the persistence layer
|
void |
commitTransaction()
in case of manual commit, finishes a transaction
|
void |
createField(StoredTableSchema object,
int fieldindex)
creates the n-th field of the specified object
|
void |
createObject(StoredTableSchema object)
creates a new table in the persistence layer
|
void |
createSearchIndex(java.lang.String name,
StoredTableSchema object,
StoredFieldSchema[] fields,
boolean unique) |
void |
createSequence(java.lang.String sequencename,
int firstvalue)
creates a unique sequence in the database
|
void |
DeleteOnDB(DeleteQuery dq)
deletes a single line in the database
|
boolean |
DoesFieldExist(StoredTableSchema object,
int fieldindex) |
int |
DoesIndexExist(StoredTableSchema object,
StoredFieldSchema[] columns,
java.lang.String name)
checks if the index exists and indexes the specified fields
|
boolean |
DoesObjectExist(StoredTableSchema object)
Introspection of the datamodel: checks if the table exists
|
void |
dropIndex(java.lang.String name)
drops the index as specified by name
|
<E> E |
executeWithRelaunch(BaseJDBCStorage.SQLExecution<E> execution) |
void |
finalize() |
java.sql.Connection |
getConnection() |
int |
getNextValue(java.lang.String sequencename)
gets the next value from the sequence
|
void |
initMedaData() |
void |
insertOnDB(StoredTableRow row)
Insert a single row in the persistent storage
|
boolean |
isSequenceExisting(java.lang.String sequencename)
Checks if a sequence already exists
|
void |
MassiveDeleteOnDB(MultipleTableRow rowstodelete)
deletes multiple rows in the persistent storage
|
void |
MassiveInsertOnDB(MultipleTableRow multiplerow)
Insert multiple rows in the persistent storage
|
void |
MassiveUpdateOnDB(MultipleTableRow multiplerow)
updates multiple rows in the persistent storage
|
void |
refreshConnection(java.sql.Connection connection) |
void |
rollbackTransaction()
in case of manual commit, rollbacks a transaction
|
Row |
selectOnDB(SelectQuery sq)
selects data in the persistent storage
|
void |
setAutoCommit(boolean autocommit)
sets the persistence layer as either autocommit (each action is persisted) or
manual commit (several actions can be packaged in )
|
void |
startTransaction()
in case of manual commit, starts a transaction
|
void |
technicalInit()
This method will be played once at the launch of the server.
|
java.lang.RuntimeException |
treatThrowable(java.lang.Throwable t,
java.lang.String query)
Processes an error
|
void |
UpdateOnDB(UpdateQuery uq)
updates a single line in the database
|
public static int MAX_SQLERROR_RETRY
public static int TIMEOUT_SQLERROR_RETRY_MS
protected java.sql.Connection connection
public BaseJDBCStorage(java.sql.Connection connection, java.util.function.Function<java.lang.StringBuffer,StoredFieldSchema.Visitor> fieldvisitorgenerator)
connection
- the connectionfieldvisitorgenerator
- relevant field visitorpublic java.sql.Connection getConnection()
getConnection
in interface JDBCstorage
public java.lang.RuntimeException treatThrowable(java.lang.Throwable t, java.lang.String query)
t
- a throwablequery
- context querypublic <E> E executeWithRelaunch(BaseJDBCStorage.SQLExecution<E> execution)
execution
- the sql executionpublic Row selectOnDB(SelectQuery sq)
PersistentStorage
selectOnDB
in interface PersistentStorage
sq
- select querypublic void MassiveInsertOnDB(MultipleTableRow multiplerow)
PersistentStorage
MassiveInsertOnDB
in interface PersistentStorage
multiplerow
- multiple rows to insertpublic void MassiveDeleteOnDB(MultipleTableRow rowstodelete)
PersistentStorage
MassiveDeleteOnDB
in interface PersistentStorage
public void MassiveUpdateOnDB(MultipleTableRow multiplerow)
PersistentStorage
MassiveUpdateOnDB
in interface PersistentStorage
multiplerow
- multiple rows to updatepublic void insertOnDB(StoredTableRow row)
PersistentStorage
insertOnDB
in interface PersistentStorage
row
- the row to insertpublic void UpdateOnDB(UpdateQuery uq)
PersistentStorage
UpdateOnDB
in interface PersistentStorage
uq
- query to update a single rowpublic void initMedaData() throws java.sql.SQLException
java.sql.SQLException
public boolean DoesObjectExist(StoredTableSchema object)
PersistentStorage
DoesObjectExist
in interface PersistentStorage
object
- the table schema to checkpublic boolean DoesFieldExist(StoredTableSchema object, int fieldindex)
DoesFieldExist
in interface PersistentStorage
object
- the table schema to checkfieldindex
- field to check (by index)public int DoesIndexExist(StoredTableSchema object, StoredFieldSchema[] columns, java.lang.String name)
PersistentStorage
DoesIndexExist
in interface PersistentStorage
object
- object to create the index oncolumns
- ordered list of fieldsname
- name of the indexpublic void createObject(StoredTableSchema object)
PersistentStorage
createObject
in interface PersistentStorage
object
- definition (schema) of the stored tablepublic void createField(StoredTableSchema object, int fieldindex)
PersistentStorage
createField
in interface PersistentStorage
object
- object definition (schema) of the stored tablefieldindex
- index of the field to createpublic void createSearchIndex(java.lang.String name, StoredTableSchema object, StoredFieldSchema[] fields, boolean unique)
createSearchIndex
in interface PersistentStorage
public void setAutoCommit(boolean autocommit)
PersistentStorage
setAutoCommit
in interface PersistentStorage
autocommit
- true for autocommit, false for manual commitpublic void startTransaction()
PersistentStorage
startTransaction
in interface PersistentStorage
public void commitTransaction()
PersistentStorage
commitTransaction
in interface PersistentStorage
public void rollbackTransaction()
PersistentStorage
rollbackTransaction
in interface PersistentStorage
public void closeConnections()
PersistentStorage
closeConnections
in interface PersistentStorage
public void DeleteOnDB(DeleteQuery dq)
PersistentStorage
DeleteOnDB
in interface PersistentStorage
dq
- query to delete a single rowpublic void cleanup()
JDBCstorage
cleanup
in interface JDBCstorage
public void finalize()
finalize
in class java.lang.Object
public void dropIndex(java.lang.String name)
PersistentStorage
dropIndex
in interface PersistentStorage
name
- name of the indexpublic void refreshConnection(java.sql.Connection connection)
refreshConnection
in interface JDBCstorage
connection
- refresh the given connectionpublic void technicalInit()
PersistentStorage
technicalInit
in interface PersistentStorage
public boolean isSequenceExisting(java.lang.String sequencename)
PersistentStorage
isSequenceExisting
in interface PersistentStorage
sequencename
- name of the sequencepublic void createSequence(java.lang.String sequencename, int firstvalue)
PersistentStorage
createSequence
in interface PersistentStorage
sequencename
- name of the sequencefirstvalue
- first integer value of the sequencepublic int getNextValue(java.lang.String sequencename)
PersistentStorage
getNextValue
in interface PersistentStorage
sequencename
- name of the sequence