public class DirectAccessHelper
extends java.lang.Object
| Constructor and Description |
|---|
DirectAccessHelper() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
clearPrimaryKey(Session session,
TempRecord dmo)
When a
DmoState.NEW record is being deleted or undone in the same transaction, without having
a chance to occupy the reserved slot (by primary key) via an explicit or implicit flush, that slot
needs to be cleared. |
static Record |
findByRowid(Session session,
DmoMeta meta,
long recid)
Direct access attempt on database structures to retrieve a single record based on recid.
|
static Record |
findByUniqueIndex(Session session,
DmoMeta meta,
UniqueIndexLookup lookup)
Direct access attempt on database structures to retrieve a single record based on a
unique index.
|
private static org.h2.jdbc.JdbcConnection |
getH2Connection(Session session)
Retrieve the H2 connection straight from the provided session.
|
static boolean |
hasDirectAccess(Session session)
Check if the provided session allows a direct access interface.
|
static boolean |
hasRecords(Session session,
java.lang.String tableName,
int multiplex)
Retrieve the number of rows that are currently in a specified table.
|
private static Record |
interpretResponse(Session session,
DmoMeta meta,
org.h2.embedded.DirectAccessResponse response)
Core method of hydrating a record from the retrieved result set.
|
static void |
killMultiplex(Session session,
java.lang.String tableName,
int multiplex)
Forcefully clear the multiplex in the FWD-H2.
|
static long |
nextPrimaryKey(Session session,
java.lang.String tableName,
int multiplex)
Direct access attempt to retrieve the next primary key available for the mentioned
table and multiplex.
|
private static java.lang.Object |
normalizeValue(java.lang.Object arg)
Normalize the FWD specific data types into Java native types.
|
static org.h2.embedded.DirectAccessDriver |
startValidate(Session session)
Mark that server-side unique index validation has stopped and notify H2 that it should handle
the process.
|
static void |
stopValidate(Session session)
Mark that H2 no longer needs to handle unique index validation, as it will be done server-side.
|
public static long nextPrimaryKey(Session session, java.lang.String tableName, int multiplex) throws DirectAccessException
MULTIPLEXED
to allow the generation of a proper index to be used by this routine.
In essence, this retrieves the next primary key and reserves its spot. Unless a further
insert is done with that key, the reserved slot will leak. Use this carefully.
If you want to do a bulk insert, use the bulk option. This will no reserve any spot as
the number of intended keys is unknown. If bulk is set, this will return the first key
that is available and no higher keys are already reserved / used. Such key should be used
immediately, otherwise the previous mentioned invariant may not hold (an insert happens in
the mean-time).session - The session with a database with direct access interface.tableName - The name of the table from which the next key is needed.multiplex - The multiplex for which the next key is needed. This is mandatory, as 4GL does
the reclaiming of keys per-multiplex (e.g. one multiplex won't reclaim the keys
from another multiplex, even if they are in the same physical table).bulk value.DirectAccessException - An exception is thrown if the table doesn't exist.public static boolean clearPrimaryKey(Session session, TempRecord dmo) throws DirectAccessException
DmoState.NEW record is being deleted or undone in the same transaction, without having
a chance to occupy the reserved slot (by primary key) via an explicit or implicit flush, that slot
needs to be cleared.session - The session with a database with direct access interface.dmo - The temporary DMO instance in DmoState.NEW state.true if the primary key was found and removed from this multiplex.DirectAccessException - An exception is thrown if the table doesn't exist.public static boolean hasRecords(Session session, java.lang.String tableName, int multiplex) throws DirectAccessException
session - The session with a database with direct access interface.tableName - The name of the table for which we want the number of rows.multiplex - The multiplex for which the query is done.DirectAccessExceptionpublic static Record findByRowid(Session session, DmoMeta meta, long recid) throws DirectAccessException
session - The session with a database with direct access interface.meta - The meta of the table to be queried.recid - The value of the recid for the record to be retrieved.DirectAccessException - An exception is thrown if the table doesn't exist. An exception is also
thrown if the prerequisites are not met (no recid primary key).public static Record findByUniqueIndex(Session session, DmoMeta meta, UniqueIndexLookup lookup) throws DirectAccessException
session - The session with a database with direct access interface.meta - The meta of the table to be queried.lookup - Specific object which contains low-level information about the properties
and values needed for unique index lookup.DirectAccessException - An exception is thrown if the table doesn't exist. Also, if the properties don't
match any unique index, then an exception is thrown.public static void killMultiplex(Session session, java.lang.String tableName, int multiplex)
session - The session with a database with direct access interface.tableName - The name of the table for which we wan't to kill the multiplexmultiplex - The multiplex whose scope was closed.public static boolean hasDirectAccess(Session session)
session - The session with a database with direct access interface.true if this session allows direct access.public static org.h2.embedded.DirectAccessDriver startValidate(Session session)
session - The session with a database with direct access interface.public static void stopValidate(Session session)
session - The session with a database with direct access interface.private static java.lang.Object normalizeValue(java.lang.Object arg)
throws DirectAccessException
arg - The object to be "normalized" (converted to Java native type)DirectAccessException - An exception is thrown when a provided argument couldn't be converted to a
Java representation which can be passed to the H2 engine.private static Record interpretResponse(Session session, DmoMeta meta, org.h2.embedded.DirectAccessResponse response) throws PersistenceException, java.sql.SQLException
session - The session with a database with direct access interface.meta - The meta of the table to be queried.response - The response returned by the direct-access interface.java.sql.SQLException - An exception is thrown when anything goes wrong with the dummy JDBC API (result-set).PersistenceException - This method does a session cache look-up. If this goes wrong, an exception is thrown.private static org.h2.jdbc.JdbcConnection getH2Connection(Session session)
null
if the H2 connection doesn't allows direct access interface of if this is not a H2 connection.
This should be refactored maybe to be more generic (not necessarily that close related to H2)session - The session with a database with direct access interface.