public final class ConnectionManager
extends java.lang.Object
Persistence
service object.
A connection in the sense of this class is not a database-level connection,
such as a JDBC connection. Database-level connections are managed by the
Persistence
class transparently. A connection to this class
is a logical construct inherited from converted Progress code. Connecting
and disconnecting from a database at this level does not create or destroy
a JDBC-level connection resource. However, for transient databases at
least, it may affect the loading and unloading of database configurations
at the DatabaseManager
level. That is, the first time any client
context connects to a transient database (i.e., one that is not always
loaded by the server by default), that database's configuration is loaded
temporarily by the server. The last time a client context disconnects
from a transient database, that database's configuration is unloaded.
Connections register a physical database name to a logical database name, which can be different or the same as the physical name. A database may not be connected more than once without first disconnecting. Once disconnected, it may be connected again. Only one physical database may be registered to a given logical name at a time. Methods are provided to connect and disconnect, as well as to query information about connected databases, such as their physical and logical names, how many are connected, their types and restrictions.
Any number of aliases may be assigned to a given logical name. Aliases may only be created for connected databases, though they survive database disconnect. They may be explicitly deleted, however.
Whenever a new record buffer scope is opened, it is registered with its context's connection manager. References from buffers to their backing, physical databases are tracked, to enable the correct processing of database disconnect requests. Disconnects can only occur immediately if all procedures which reference the target database are complete. This translates to a state where no record buffers reference the database. Furthermore, even if no buffers reference a database, it may not be disconnected if the active code point currently is within a transaction. At the end of the transaction, all disconnects which were deferred are processed.
A single instance of this class is created for each client context. The
constructor is not called directly by client code; rather, access is
provided through the static get()
method.
Currently, the Progress semantic of database-level auto connect lists is not supported.
Modifier and Type | Class and Description |
---|---|
static class |
ConnectionManager.BoolConnectOptionValue
Logical connection option value.
|
private static class |
ConnectionManager.ConnectInfo
Information about a specific database connection (in 4GL terms, not JDBC terms).
|
private static class |
ConnectionManager.ConnectionDispatcher
This class dispatches connect and disconnect events to the listeners which manage related connection
and user statistics metadata.
|
private static class |
ConnectionManager.ConnectOption
CONNECT statement options.
|
private static class |
ConnectionManager.ConnectOptionValue
Connection option value - base class
|
private static class |
ConnectionManager.EOL
EOL marker in a parsed config file.
|
static class |
ConnectionManager.IntConnectOptionValue
Numeric connection option value.
|
private static class |
ConnectionManager.OptBuilder
Config file line line parser helper
|
private static class |
ConnectionManager.OptionsParser
CONNNECT statement options' parser
|
static class |
ConnectionManager.TextConnectOptionValue
Text connection option value.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.String> |
aliases
Map of active aliases to logical database names
|
private java.util.Map<java.lang.String,ClientPrincipal> |
clients
Map of registered CLIENT-PRINCIPAL objects, for each database.
|
private static long |
CONN_RETRY_DELAY
Milliseconds to wait between connection retries
|
private java.util.Map<java.lang.String,ConnectionManager.ConnectInfo> |
connected
Map of logical database names to
ConnectInfo objects |
private java.util.Map<java.lang.String,java.lang.String> |
connectTimeUserid
Stores the userid used at connection time whether the database is connected using
command-line (directory implementation) or programatically using
CONNECT
with -U/-P parameters. |
private static java.util.Map<java.lang.String,java.lang.String> |
dbVersionCache
Cache of database versions, indexed by PDB name
|
private static int |
DEFAULT_CONN_RETRIES
Default number of database connection retries
|
private static java.lang.String |
DEFAULT_DBVERSION
Default DBVERSION text
|
private static java.lang.String |
DICTDB
DICTDB alias name
|
private ConnectionManager.ConnectionDispatcher |
dispatcher
Connect/disconnect event dispatcher
|
private java.util.Map<Database,java.lang.String> |
ldbMap
Map of physical database helper objects to logical database names
|
private static ContextLocal<ConnectionManager> |
local
Context local instance of this class
|
private java.util.Set<java.lang.String> |
locked
Set of locked database.
|
private static java.util.logging.Logger |
LOG
Logger
|
private static ContextLocal<ConnectionManager.ConnectionDispatcher> |
metaCleaner
Collect all the DB connections so that they are cleaned up before anything else (as
these are dependent on persistence and other context-local data.
|
private static long |
nextConnectID
Next available connect ID for metadata updates
|
private java.util.Map<Database,java.util.Set<RecordBuffer>> |
pdbReferences
Map of buffer sets currently referencing databases
|
private java.util.Set<Database> |
pendingDisconn
Databases awaiting disconnect (first level)
|
private java.util.Set<Database> |
pendingTxDisconn
Databases awaiting disconnect (second level)
|
private static char[] |
QUOTES
4GL quote characters that may need to be removed from connect options
|
private int |
registerProgress
This flags a registered (completely build) object.
|
private java.util.Map<Database,Session> |
sessions
Map of database info objects to network sessions
|
private boolean |
singleClient
Equivalent of -1 argument in CONNECT statement.
|
private java.util.Map<java.lang.String,java.lang.String> |
userIds
Map with the userids for the currently connected databases.
|
Modifier | Constructor and Description |
---|---|
private |
ConnectionManager()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
static character |
alias(int index)
Retrieve the alias at the specified index in the current context.
|
static character |
alias(NumberType index)
Retrieve the alias at the specified index in the current context.
|
private character |
aliasImpl(int index)
Retrieve the alias at the specified index in the current context.
|
private static void |
assertKnownValue(BaseDataType data,
java.lang.String description)
Assert that
data does not represent the unknown value. |
static boolean |
authenticate(java.lang.String userid,
java.lang.String password,
java.lang.String dbname)
Authenticates the user for specified DB connection.
|
(package private) void |
closeBufferScope(RecordBuffer buffer)
Called by a record buffer to notify that its scope has been closed,
indicating that it no longer has an active reference to its database.
|
private static void |
connect_(boolean isAutoConnect,
java.lang.Object... args)
Create a logical connection to a database using the specified
parameters.
|
static void |
connect(boolean isAutoConnect,
java.lang.Object... args)
Create a logical connection to a database using the specified parameters.
|
private void |
connect(boolean isAutoConnect,
java.lang.String pdb,
java.lang.String ldb,
java.lang.String host,
java.lang.String service,
java.lang.String user,
java.lang.String password,
java.lang.Integer port,
java.lang.Integer maxRetries)
Establish database connection.
|
static void |
connect(java.lang.Object... args)
Create a logical connection to a database using the specified
parameters.
|
private void |
connectDbImpl(boolean isAutoConnect,
java.util.List<java.util.Map.Entry<ConnectionManager.ConnectOption,ConnectionManager.ConnectOptionValue>> opts)
Create a logical connection to a database using the specified
parameters.
|
static logical |
connected(character name)
Tests whether a logical connection to a database exists in this context,
given a logical database name or alias.
|
static logical |
connected(java.lang.String name)
Tests whether a logical connection to a database exists in this context,
given a logical database name or alias.
|
private logical |
connectedImpl(character name)
Tests whether a logical connection to a database exists in this context,
given a logical database name or alias.
|
private void |
connectImpl(java.util.List<java.lang.Object> args)
Create a logical connection to a database using the specified
parameters.
|
static void |
createAlias(character alias,
character ldbName)
Create an alias for a logical database name within the current context.
|
static void |
createAlias(character alias,
java.lang.String ldbName)
Create an alias for a logical database name within the current context.
|
static void |
createAlias(java.lang.String alias,
character ldbName)
Create an alias for a logical database name within the current context.
|
static void |
createAlias(java.lang.String alias,
java.lang.String ldbName)
Create an alias for a logical database name within the current context.
|
private void |
createAliasImpl(java.lang.String alias,
java.lang.String ldbName)
Create an alias for a logical database name.
|
static character |
dbName()
Get the name of the connected database in this context.
|
static character |
dbParam(character nameOrAlias)
Implementation of the
DBPARAM() Progress function. |
static character |
dbParam(int index)
Implementation of the
DBPARAM() Progress function. |
private static java.lang.String |
dbparam(java.util.List<java.util.Map.Entry<ConnectionManager.ConnectOption,ConnectionManager.ConnectOptionValue>> opts)
Convert CONNECT options to a DBPARAM string.
|
static character |
dbParam(NumberType index)
Implementation of the
DBPARAM() Progress function. |
static character |
dbParam(java.lang.String nameOrAlias)
Implementation of the
DBPARAM() Progress function. |
private character |
dbParamImpl(java.lang.String nameOrAlias,
int index)
Implementation of the
DBPARAM() Progress function. |
static character |
dbRestrictions(character name)
Get a description of restrictions for the connected database with the
specified logical name or alias.
|
static character |
dbRestrictions(character name,
character table)
Get a description of restrictions for the connected database with the
specified logical name or alias.
|
static character |
dbRestrictions(character name,
java.lang.String table)
Get a description of restrictions for the connected database with the
specified logical name or alias.
|
static character |
dbRestrictions(int index)
Get a description of restrictions for the connected database at the
specified index.
|
static character |
dbRestrictions(int index,
character table)
Get a description of restrictions for the connected database at the
specified index.
|
static character |
dbRestrictions(int index,
java.lang.String table)
Get a description of restrictions for the connected database at the
specified index.
|
static character |
dbRestrictions(NumberType index)
Get a description of restrictions for the connected database at the
specified index.
|
static character |
dbRestrictions(NumberType index,
character table)
Get a description of restrictions for the connected database at the
specified index.
|
static character |
dbRestrictions(NumberType index,
java.lang.String table)
Get a description of restrictions for the connected database at the
specified index.
|
static character |
dbRestrictions(java.lang.String name)
Get a description of restrictions for the connected database with the
specified logical name or alias.
|
static character |
dbRestrictions(java.lang.String name,
character table)
Get a description of restrictions for the connected database with the
specified logical name or alias.
|
static character |
dbRestrictions(java.lang.String name,
java.lang.String table)
Get a description of restrictions for the connected database with the
specified logical name or alias.
|
static integer |
dbTaskId(character name)
Get the identifier of the current transaction for the given database.
|
static integer |
dbTaskId(int index)
Get the identifier of the current transaction for the given database.
|
static integer |
dbTaskId(NumberType index)
Get the identifier of the current transaction for the given database.
|
static integer |
dbTaskId(java.lang.String name)
Get the identifier of the current transaction for the given database.
|
private integer |
dbTaskIdImpl(java.lang.String name,
int index)
Get the version number of the target database.
|
static character |
dbType(character name)
Get a brief descriptor of the database type with the specified logical
name or alias.
|
static character |
dbType(int index)
Get a brief descriptor of the database type with the specified
connection index.
|
static character |
dbType(NumberType index)
Get a brief descriptor of the database type with the specified
connection index.
|
static character |
dbType(java.lang.String name)
Get a brief descriptor of the database type with the specified logical
name or alias.
|
static character |
dbVersion(character name)
Get the version number of the target database.
|
static character |
dbVersion(int index)
Get the version number of the target database.
|
static character |
dbVersion(NumberType index)
Get the version number of the target database.
|
static character |
dbVersion(java.lang.String name)
Get the version number of the target database.
|
private character |
dbVersionImpl(java.lang.String name,
int index)
Get the version number of the target database.
|
static void |
deleteAlias(character alias)
Delete the specified alias immediately.
|
static void |
deleteAlias(java.lang.String alias)
Delete the specified alias immediately.
|
private void |
deleteAliasImpl(java.lang.String alias)
Delete the specified alias immediately.
|
static void |
disconnect(character ldbName)
Request a disconnect from a logical database.
|
static void |
disconnect(java.lang.String ldbName)
Request a disconnect from a logical database.
|
private void |
disconnectImmediately(Database database,
boolean sessionCleanup)
Disconnect the specified database by deregistering it with the
DatabaseManager
and terminating the associated network session. |
private void |
disconnectImmediately(java.util.Set<Database> pending,
boolean sessionCleanup)
Disconnect all databases in the specified set by deregistering them with the
DatabaseManager and removing them from the set. |
private void |
disconnectImpl(java.lang.String ldbName)
Request a disconnect from a logical database.
|
(package private) static ConnectionManager |
get()
Retrieve the
ConnectionManager instance for the local context. |
(package private) java.util.List<Database> |
getActiveDatabases()
Get a list of active databases, which is meant to include the temp-table database and all
connected, persistent databases.
|
(package private) java.util.Map<java.lang.String,java.lang.String> |
getAliasesByLDB()
Get the currently connected aliases by their logical database name.
|
static int |
getAuthLevel(java.lang.String ldbname)
Check the access level for a database based on metadata of that database.
|
static int |
getConnectedDbCount()
Get the number of databases currently connected in this context.
|
static java.lang.String |
getCurrentUserid(java.lang.String ldbName)
Returns a string representing the user ID used for authentication to a database.
|
private java.lang.String |
getCurrentUseridImpl(java.lang.String ldbName)
Returns the current id used by the user to authenticated to a database
identified by its logical name.
|
(package private) Database |
getDatabase(java.lang.String name)
Get the database information object for the given database name, which
may be a logical name, physical name, or alias.
|
static ClientPrincipal |
getDbClient(java.lang.String dbName)
Get the CLIENT-PRINCIPAL associated with the given database name.
|
static java.lang.String |
getDefaultDatabase()
Return the default logical database.
|
(package private) java.lang.String |
getLDBName(Database database)
Get the logical database name for a connected physical database.
|
(package private) java.lang.String |
getLDBName(java.lang.String name)
Get the logical database name for the given logical database name or
alias.
|
(package private) java.lang.String |
getPDBName(java.lang.String name,
boolean normalize)
Get the physical database name for the given logical database name or
alias.
|
static Persistence |
getPersistence(java.lang.String name)
Get the
Persistence instance associated with the given database
name, which may be a physical or logical name, or an alias. |
static Session |
getSession(Database database)
Retrieve the network session which manages the connection to the remote
server which is authoritative for the specified database.
|
static Session |
getSession(java.lang.String name)
Retrieve the network session which manages the connection to the remote server which is
authoritative for the specified database name, which may be a logical name, physical name,
or alias.
|
private static java.lang.Long |
getSQLResultAsLong(java.lang.Object ufo)
Dynamically analyze (by class type) and convert a value returned by a SQL statement of an
unknown type (but assumed to be integer-like) to Long value.
|
static java.util.List<java.lang.String> |
getUnlocked()
Get the list of unlocked database connections.
|
static boolean |
isLocked(java.lang.String dbName)
Check if database connection is locked.
|
private static <X> X |
iterateToIndex(java.util.Collection<X> coll,
int index)
Iterate over the specified collection, returning the element at index
index . |
static character |
ldbName(character name)
Get the logical database name for the connected database with the given
logical name or alias.
|
static character |
ldbName(int index)
Get the logical database name for the connected database at the given
index.
|
static character |
ldbName(NumberType index)
Get the logical database name for the connected database at the given
index.
|
static character |
ldbName(java.lang.Object dmo)
Get the logical database name for the record buffer associated with the
given DMO.
|
static character |
ldbName(java.lang.String name)
Get the logical database name for the connected database with the given
logical name or alias.
|
private character |
ldbNameImpl(java.lang.String name,
int index)
Get the logical name for a database, given an alias (which may be the
logical name itself), or its index among all connected databases in
this context.
|
private java.lang.String |
makeConnection(Database database,
java.lang.String ldbName,
java.lang.String certAlias,
boolean isAutoConnect)
Create a logical connection to the database with the specified physical
name, creating the specified logical name for it.
|
private static character |
normalizeAliasOrLDB(character name)
Normalize an alias or logical database name by right trimming whitespace and lowercasing.
|
private static java.lang.String |
normalizeFilename(java.lang.String name)
Normalize the given filename by extracting the root name (removing the
file path and the filename extension).
|
static integer |
numAliases()
Get the number of aliases currently defined in this context.
|
static integer |
numDBs()
Get the number of databases currently connected in this context.
|
(package private) void |
openBufferScope(RecordBuffer buffer)
Register that a reference from a record buffer to its database has
become active.
|
static java.util.List<java.util.List<java.util.Map.Entry<ConnectionManager.ConnectOption,ConnectionManager.ConnectOptionValue>>> |
parse(java.util.List<java.lang.Object> args)
Parse CONNECT statement options.
|
static character |
pdbName(character name)
Get the physical database name for the connected database with the
given logical name or alias.
|
static character |
pdbName(int index)
Get the physical database name for the connected database at the given
index.
|
static character |
pdbName(NumberType index)
Get the physical database name for the connected database at the given
index.
|
static character |
pdbName(java.lang.String name)
Get the physical database name for the connected database with the
given logical name or alias.
|
private character |
pdbNameImpl(java.lang.String name,
int index)
Get the physical name for a database, given its logical name or alias,
or its index among all connected databases in this context.
|
private void |
putConnected(java.lang.String ldbName,
Database database,
java.lang.String userId)
Update the various housekeeping data structures to reflect a successful connection event,
and update connection metadata if it is in use.
|
static void |
readQueryResults(java.lang.String sql,
Persistence persistence,
java.util.function.Consumer<ScrollableResults<?>> consumer)
Read query results.
|
static void |
readUserTable(Persistence persistence,
java.util.function.Consumer<java.lang.String[]> consumer)
Read _User table from the database supplying String array: {userid, domain-name, password}
to a consumer.
|
private void |
register()
Registers with the transaction manager for master and global finish notifications.
|
private Database |
removeConnected(java.lang.String ldbName,
boolean sessionCleanup)
Update the various housekeeping data structures to reflect a disconnection event, and update
connection metadata if it is in use.
|
static character |
sdbName(character name)
Get the logical database name for the connected database with the given
logical name or alias.
|
static character |
sdbName(int index)
Get the logical database name for the connected database at the given
index.
|
static character |
sdbName(NumberType index)
Get the logical database name for the connected database at the given
index.
|
static character |
sdbName(java.lang.String name)
Get the logical database name for the connected database with the given
logical name or alias.
|
private void |
sessionClosed()
Perform end of session cleanup; disconnects all connected databases
without regard to transaction state or buffer reference status.
|
static void |
setAuthenticatedUserid(java.lang.String dbName,
java.lang.String userid,
boolean byConnect)
Set the currently authenticated userid for a database.
|
private void |
setConnectUserImpl(java.lang.String ldbName)
Mark the current user for the database as the connection parameter.
|
private void |
setCurrentUseridImpl(java.lang.String ldbName,
java.lang.String newUserId)
Sets the currently authenticated
userid for a database. |
static void |
setDbClient(ClientPrincipal client,
java.lang.String dbName)
Associate the specified CLIENT-PRINCIPAL with the given database name.
|
private static java.lang.String |
stripQuotes(java.lang.String s)
Strip any 4GL quote characters from option.
|
(package private) void |
transactionEnded()
This method is invoked after a master transaction commit/rollback; any databases awaiting
the end of the current transaction to disconnect are now deregistered with the database
manager.
|
(package private) void |
transactionEnded(Database database)
This method is invoked after a master transaction commit/rollback; if the specified
database is waiting for the end of the current transaction to disconnect, it will be
deregistered with the database manager.
|
static void |
unlock(java.lang.String dbName)
Unlock the database connection.
|
private static final java.util.logging.Logger LOG
private static final ContextLocal<ConnectionManager> local
private static final ContextLocal<ConnectionManager.ConnectionDispatcher> metaCleaner
private static final java.lang.String DICTDB
private static final java.lang.String DEFAULT_DBVERSION
private static final int DEFAULT_CONN_RETRIES
private static final long CONN_RETRY_DELAY
private static final java.util.Map<java.lang.String,java.lang.String> dbVersionCache
private static final char[] QUOTES
private static long nextConnectID
private final java.util.Set<java.lang.String> locked
private final java.util.Map<java.lang.String,ClientPrincipal> clients
private final java.util.Map<java.lang.String,java.lang.String> userIds
connected
map of the databases.private final java.util.Map<java.lang.String,java.lang.String> connectTimeUserid
CONNECT
with -U/-P parameters.
This list is not affected by later SETUSERID
calls.private final java.util.Map<java.lang.String,ConnectionManager.ConnectInfo> connected
ConnectInfo
objectsprivate final java.util.Map<Database,java.lang.String> ldbMap
private final java.util.Set<Database> pendingDisconn
private final java.util.Set<Database> pendingTxDisconn
private final java.util.Map<java.lang.String,java.lang.String> aliases
private final java.util.Map<Database,java.util.Set<RecordBuffer>> pdbReferences
private final java.util.Map<Database,Session> sessions
private final ConnectionManager.ConnectionDispatcher dispatcher
private boolean singleClient
private int registerProgress
register()
.private ConnectionManager()
Call register()
ASAP to actually connects to all permanent databases and register
with the transaction manager for master and global finish notifications.
private void register()
WARNING: Only call this method once!
public static void connect(java.lang.Object... args)
args
- One or more connection parameters. This may take one of several forms:
-db mydb -ld logical_name -H
192.168.1.12 -S 3333
. After -db
,
parameters can be in any order, so long as each is
preceded by the specified option identifier.
ErrorConditionException
- if any parameter is null or represents the unknown value;
if any parameter is neither a text value nor an integral
value;
if there is an error registering the database with the
database manager.public static void connect(boolean isAutoConnect, java.lang.Object... args)
isAutoConnect
- flag indication that is is an implicit auto-connect operationargs
- One or more connection parameters. This may take one of several forms:
-db mydb -ld logical_name -H
192.168.1.12 -S 3333
. After -db
,
parameters can be in any order, so long as each is
preceded by the specified option identifier.
ErrorConditionException
- if any parameter is null or represents the unknown value;
if any parameter is neither a text value nor an integral
value;
if there is an error registering the database with the
database manager.private static void connect_(boolean isAutoConnect, java.lang.Object... args)
isAutoConnect
- flag indication that is is an implicit auto-connect operationargs
- One or more connection parameters. This may take one of several forms:ErrorConditionException
- see abovepublic static java.util.List<java.util.List<java.util.Map.Entry<ConnectionManager.ConnectOption,ConnectionManager.ConnectOptionValue>>> parse(java.util.List<java.lang.Object> args) throws PersistenceException
args
- statement arguments.PersistenceException
- if a fatal error was encounteredpublic static void disconnect(character ldbName)
ldbName
for disconnect at the appropriate time: once no buffers reference the
database, and at the end of the current transaction (if any).ldbName
- Logical name of the database to disconnect.ErrorConditionException
- if the specified database has not been opened.public static void disconnect(java.lang.String ldbName)
ldbName
for disconnect at the appropriate time: once no buffers reference the
database, and at the end of the current transaction (if any).ldbName
- Logical name of the database to disconnect.ErrorConditionException
- if the specified database has not been opened.public static logical connected(character name)
name
- Logical database name or alias.true
if a logical connection exists; else
false
.public static logical connected(java.lang.String name)
name
- Logical database name or alias.true
if a logical connection exists; else
false
.public static integer numAliases()
public static int getConnectedDbCount()
public static integer numDBs()
public static character dbName()
public static character dbParam(int index)
DBPARAM()
Progress function.
Returns, as a character string, a comma-separated list of the parameters
used to connect to the database.
The sequence number of a database the Progress session is connected to. For example, DBPARAM(1) returns information on the first database the Progress session is connected to, DBPARAM(2) returns information on the second database the Progress session is connected to, etc. If you specify a sequence number that does not correspond to a database the Progress session is connected to, the DBPARAM function returns the unknown value (?).
index
- One-based index of the target database among all databases
currently connected in this context.public static character dbParam(NumberType index)
DBPARAM()
Progress function.
Returns, as a character string, a comma-separated list of the parameters
used to connect to the database.
The sequence number of a database the Progress session is connected to. For example, DBPARAM(1) returns information on the first database the Progress session is connected to, DBPARAM(2) returns information on the second database the Progress session is connected to, etc. If you specify a sequence number that does not correspond to a database the Progress session is connected to, the DBPARAM function returns the unknown value (?).
index
- One-based index of the target database among all databases
currently connected in this context.public static character dbParam(java.lang.String nameOrAlias)
DBPARAM()
Progress function.
Returns, as a character string, a comma-separated list of the parameters
used to connect to the database.
This forms of the DBPARAM()
function require a character
expression as a parameter. If the parameter is an alias or the logical
name of a connected database, then Progress returns the comma-separated
parameter list. Otherwise, it returns the unknown value (?).
nameOrAlias
- The logical-name or alias of a connected databasepublic static character dbParam(character nameOrAlias)
DBPARAM()
Progress function.
Returns, as a character string, a comma-separated list of the parameters
used to connect to the database.
This forms of the DBPARAM()
function require a character
expression as a parameter. If the parameter is an alias or the logical
name of a connected database, then Progress returns the comma-separated
parameter list. Otherwise, it returns the unknown value (?).
nameOrAlias
- The logical-name or alias of a connected databasepublic static character dbType(NumberType index)
index
- One-based index of the target database among all databases
currently connected in this context.index
represents the unknown value or is outside of the range of
connected databases.public static character dbType(int index)
index
- One-based index of the target database among all databases
currently connected in this context.index
represents the unknown value or is outside of the range of
connected databases.public static character dbType(character name)
name
- Logical name or alias of the target database.name
is not a recognized logical name or alias.public static character dbType(java.lang.String name)
name
- Logical name or alias of the target database.name
is not a recognized logical name or alias.public static integer dbTaskId(character name)
name
- Logical name or alias of a connected database.name
is not the name
or an alias for a connected database, or if there is no active transaction.public static integer dbTaskId(java.lang.String name)
name
- Logical name or alias of a connected database.name
is not the name
or an alias for a connected database, or if there is no active transaction.public static integer dbTaskId(NumberType index)
index
- One-based index of the target database among all databases currently connected in
this context.index
is not an index
of a connected database, or if there is no active transaction.public static integer dbTaskId(int index)
index
- One-based index of the target database among all databases currently connected in
this context.index
is not an index
of a connected database, or if there is no active transaction.public static character dbVersion(NumberType index)
index
- One-based index of the target database among all databases currently connected in
this context.index
represents the unknown value or is outside of the range of
connected databases.public static character dbVersion(int index)
index
- One-based index of the target database among all databases currently connected in
this context.index
is outside of the range of connected databases.public static character dbVersion(character name)
name
- Logical name or alias of the target database.name
represents the unknown value or is not a recognized logical
name or alias.public static character dbVersion(java.lang.String name)
name
- Logical name or alias of the target database.name
is not a recognized logical name or alias.public static character dbRestrictions(NumberType index)
index
- One-based index of the target database among all databases
currently connected in this context.index
represents the unknown value or is outside of the range of
connected databases.public static character dbRestrictions(int index)
index
- One-based index of the target database among all databases
currently connected in this context.index
is
invalid.public static character dbRestrictions(NumberType index, character table)
table
is ignored.index
- One-based index of the target database among all databases
currently connected in this context.table
- Name of a table within the target database. Ignored.index
is
invalid.public static character dbRestrictions(NumberType index, java.lang.String table)
table
is ignored.index
- One-based index of the target database among all databases
currently connected in this context.table
- Name of a table within the target database. Ignored.index
is
invalid.public static character dbRestrictions(int index, character table)
table
is ignored.index
- One-based index of the target database among all databases
currently connected in this context.table
- Name of a table within the target database. Ignored.index
is
invalid.public static character dbRestrictions(int index, java.lang.String table)
table
is ignored.index
- One-based index of the target database among all databases
currently connected in this context.table
- Name of a table within the target database. Ignored.index
is
invalid.public static character dbRestrictions(character name)
name
- Logical name or alias of the target database.name
is not a recognized logical name or alias.public static character dbRestrictions(java.lang.String name)
name
- Logical name or alias of the target database.name
is not a recognized logical name or alias.public static character dbRestrictions(character name, character table)
table
is
ignored.name
- Logical name or alias of the target database.table
- Name of a table within the target database. Ignored.name
is not a recognized logical name or alias.public static character dbRestrictions(character name, java.lang.String table)
table
is
ignored.name
- Logical name or alias of the target database.table
- Name of a table within the target database. Ignored.name
is not a recognized logical name or alias.public static character dbRestrictions(java.lang.String name, character table)
table
is
ignored.name
- Logical name or alias of the target database.table
- Name of a table within the target database. Ignored.name
is not a recognized logical name or alias.public static character dbRestrictions(java.lang.String name, java.lang.String table)
table
is
ignored.name
- Logical name or alias of the target database.table
- Name of a table within the target database. Ignored.name
is not a recognized logical name or alias.public static void createAlias(character alias, character ldbName)
deleteAlias
method, or until the current session ends.alias
- Alias to be created.ldbName
- Logical name of the database to which the alias is assigned.ErrorConditionException
- if silent error mode is disabled and any of the following:
alias
represents the unknown value;
ldbName
represents the unknown value;
ldbName
.
public static void createAlias(java.lang.String alias, character ldbName)
deleteAlias
method, or until the current session ends.alias
- Alias to be created.ldbName
- Logical name of the database to which the alias is assigned.ErrorConditionException
- if silent error mode is disabled and any of the following:
ldbName
represents the unknown value;
ldbName
.
public static void createAlias(character alias, java.lang.String ldbName)
deleteAlias
method, or until the current session ends.alias
- Alias to be created.ldbName
- Logical name of the database to which the alias is assigned.ErrorConditionException
- if silent error mode is disabled and any of the following:
alias
represents the unknown value;
ldbName
.
public static void createAlias(java.lang.String alias, java.lang.String ldbName)
deleteAlias
method, or until the current session ends.alias
- Alias to be created.ldbName
- Logical name of the database to which the alias is assigned.ErrorConditionException
- if silent error mode is disabled and any of the following:
ldbName
.
public static void deleteAlias(character alias)
alias
- Alias to be deleted.public static void deleteAlias(java.lang.String alias)
alias
- Alias to be deleted.public static character alias(NumberType index)
index
- One-based index of the alias (aliases are stored in the order
in which they were created).index
is
invalid.public static character alias(int index)
index
- One-based index of the alias (aliases are stored in the order
in which they were created).index
is
invalid.public static character ldbName(NumberType index)
index
- One-based index of the target database among all databases
currently connected in this context.index
is
invalid.public static character ldbName(int index)
index
- One-based index of the target database among all databases
currently connected in this context.index
is
invalid.public static character ldbName(character name)
name
- Logical name or alias of the target database.name
is
invalid.public static character ldbName(java.lang.String name)
name
- Logical name or alias of the target database.name
is
invalid.public static character ldbName(java.lang.Object dmo)
dmo
- Data model object returned by a previous call to RecordBuffer.define(java.lang.Class<T>, java.lang.String, java.lang.String)
.public static character pdbName(NumberType index)
index
- One-based index of the target database among all databases
currently connected in this context.index
is
invalid.public static character pdbName(int index)
index
- One-based index of the target database among all databases
currently connected in this context.index
is
invalid.public static character pdbName(character name)
name
- Logical name or alias of the target database.name
is
invalid.public static character pdbName(java.lang.String name)
name
- Logical name or alias of the target database.name
is
invalid.public static character sdbName(NumberType index)
The current implementation delegates to ldbName(NumberType)
.
index
- One-based index of the target database among all databases
currently connected in this context.index
is
invalid.public static character sdbName(int index)
The current implementation delegates to ldbName(int)
.
index
- One-based index of the target database among all databases
currently connected in this context.index
is
invalid.public static character sdbName(character name)
The current implementation delegates to ldbName(character)
.
name
- Logical name or alias of the target database.name
is
invalid.public static character sdbName(java.lang.String name)
The current implementation delegates to ldbName(String)
.
name
- Logical name or alias of the target database.name
is
invalid.public static Session getSession(Database database)
database
- Database to which the target session is mapped.null
if there is no current connection.public static Session getSession(java.lang.String name)
name
- Logical name, physical name, or alias for database.null
if there is no current
connection.public static Persistence getPersistence(java.lang.String name)
Persistence
instance associated with the given database
name, which may be a physical or logical name, or an alias.name
- Physical or logical database name, or alias.null
if no database with such name is connectedpublic static java.lang.String getCurrentUserid(java.lang.String ldbName)
ldbName
- The logical name of the database for which the userid is requested.public static java.lang.String getDefaultDatabase()
setuserid
and
userid
with default (missing argument) for database parameter.public static boolean authenticate(java.lang.String userid, java.lang.String password, java.lang.String dbname)
ENCODE
to password string it is compared to existing record from database in case
sensitive, taking into consideration trailing spaces
userid
- The name of the user to set as UserID.password
- The users password.dbname
- Logical database name.true
in case of valid user match false
otherwise.public static int getAuthLevel(java.lang.String ldbname)
SecurityOps.FREE_ACCESS
if
the meta table is not populated and SecurityOps.BLANK_ALLOWED
otherwise.ldbname
- The logical database name to query.public static void setDbClient(ClientPrincipal client, java.lang.String dbName)
A copy of the CLIENT-PRINCIPAL object is saved in the clients
map.
client
- The CLIENT-PRINCIPAL object.dbName
- A valid database name.java.lang.IllegalArgumentException
- If the database name is not valid.public static java.util.List<java.lang.String> getUnlocked()
public static boolean isLocked(java.lang.String dbName)
dbName
- A valid database name.true
if the database connection is locked.java.lang.IllegalArgumentException
- If the database name is not valid.public static void unlock(java.lang.String dbName)
dbName
- A valid database name.java.lang.IllegalArgumentException
- If the database name is not valid.public static ClientPrincipal getDbClient(java.lang.String dbName)
dbName
- A valid database name.null
if none associated.java.lang.IllegalArgumentException
- If the database name is not valid.public static void setAuthenticatedUserid(java.lang.String dbName, java.lang.String userid, boolean byConnect)
authenticate()
method.
If byConnect
then the userid is stored and will be reported by
dbparam
function with -U tag.dbName
- A valid database name.userid
- The name of the user to set as UserID.byConnect
- true
if the authentication was done from a connect (at startup time
or later) or false
if the authentication was done using the
setuserid
function.java.lang.IllegalArgumentException
- If the database name is not valid.public static void readUserTable(Persistence persistence, java.util.function.Consumer<java.lang.String[]> consumer)
persistence
- Persistence
instance for the databaseconsumer
- Consumer<String[]>
instancepublic static void readQueryResults(java.lang.String sql, Persistence persistence, java.util.function.Consumer<ScrollableResults<?>> consumer)
sql
- SQL statement to be executedpersistence
- Persistence
instance for the databaseconsumer
- Result set consumerstatic ConnectionManager get()
ConnectionManager
instance for the local context.private static void assertKnownValue(BaseDataType data, java.lang.String description) throws PersistenceException
data
does not represent the unknown value.
If the assertion fails, an exception is thrown.data
- The data value to be checked.description
- A brief description of data
's purpose; this will
be used in an error message if the assertion fails.PersistenceException
- if the assertion fails.private static <X> X iterateToIndex(java.util.Collection<X> coll, int index)
index
.coll
- Collection over which to iterate.index
- The 1-based index of the target element in the collection.null
if index
was never
reached.private static java.lang.String normalizeFilename(java.lang.String name)
name
- File name.private static character normalizeAliasOrLDB(character name)
name
- Alias or LDB name to be normalized.private static java.lang.String stripQuotes(java.lang.String s)
s
- Original option value.void transactionEnded()
void transactionEnded(Database database)
database
- The database for which to process the transaction end - as this will be executed
for every database which was used in this transaction block.void openBufferScope(RecordBuffer buffer)
buffer
- Record buffer whose scope has been opened.closeBufferScope(com.goldencode.p2j.persist.RecordBuffer)
,
disconnect(com.goldencode.p2j.util.character)
void closeBufferScope(RecordBuffer buffer)
If all three conditions are met, the database is disconnected immediately, and removed from the first level pending disconnect list. If the first two conditions are met, but the third is not, the database is moved from the first level to the second level disconnect list, where it will await the end of the transaction for disconnect.
buffer
- Record buffer whose scope has been closed.openBufferScope(com.goldencode.p2j.persist.RecordBuffer)
,
disconnect(com.goldencode.p2j.util.character)
java.lang.String getLDBName(java.lang.String name)
name
represents an alias.name
- Logical database name or alias.null
if name
is not recognized.java.lang.String getPDBName(java.lang.String name, boolean normalize)
name
- Logical database name or alias.normalize
- true
to return the normalized name; else
false
to return the unaltered (possibly fully
qualified name), as provided by the caller of the connect(java.lang.Object...)
method.null
if
name
is not recognized.Database getDatabase(java.lang.String name)
name
- Logical name, physical name, or alias for database.name
,
or null
if no such database currently is
connected.java.lang.String getLDBName(Database database)
database
- Physical database helper object.null
.java.util.List<Database> getActiveDatabases()
java.util.Map<java.lang.String,java.lang.String> getAliasesByLDB()
private static java.lang.Long getSQLResultAsLong(java.lang.Object ufo)
null
is returned.ufo
- The value from a SQL result. It is assumed to be some kind of integer/long.null
if its type could not be
detected.private java.lang.String getCurrentUseridImpl(java.lang.String ldbName)
ldbName
- The logical name of the database for which the userid is requested.private void setCurrentUseridImpl(java.lang.String ldbName, java.lang.String newUserId)
userid
for a database.
The only authority to set this is an instance of MetadataSecurityOps
and only
after checking the user/password combination against the _User
meta-table.
Notes:
CONNECT
statement with -U
and -P
parameters will have to
call SecurityOps
to verify if the user/password combination if correct. ConnectionManager
does not support these parameters, yet).
ldbName
- The logical database name for which the userid
is set/updated.newUserId
- The newly newUserId for this database context.private void setConnectUserImpl(java.lang.String ldbName)
dbparam
function with -U
tag.ldbName
- The logical database name for which the userid is marked as connection parameter.private void sessionClosed()
DatabaseManager
's transient database reference
counts are not corrupted when client sessions end.private void disconnectImmediately(java.util.Set<Database> pending, boolean sessionCleanup)
DatabaseManager
and removing them from the set. Network sessions associated
with the databases in the set are terminated accordingly. If being called at the end of a
user's session, clean up internal data structures and update _connect metadata as well.pending
- Set of databases to disconnect.sessionCleanup
- true
if this action is being taken as part of cleanup for a session
that is terminating; false
if a normal disconnect.private void disconnectImmediately(Database database, boolean sessionCleanup)
DatabaseManager
and terminating the associated network session.database
- Database to disconnect.sessionCleanup
- true
if this action is being taken as part of cleanup for a session
that is terminating; false
if a normal disconnect.private character ldbNameImpl(java.lang.String name, int index)
name
- Logical database name or alias. May be null
,
but only if index
is non-null
.index
- Index of the database among connected databases. May be
null
, but only if name
is
non-null
. This is a one-based index.name
is not recognized.private character pdbNameImpl(java.lang.String name, int index)
name
- Logical database name or alias. May be null
,
but only if index
is non-null
.index
- One-based index of the database among connected databases.name
is not recognized.private void connectDbImpl(boolean isAutoConnect, java.util.List<java.util.Map.Entry<ConnectionManager.ConnectOption,ConnectionManager.ConnectOptionValue>> opts) throws PersistenceException
isAutoConnect
- flag indication that is is an implicit auto-connect operationopts
- A list of one or more connection parameters.PersistenceException
- if any parameter is null;
if any parameter is neither a text value nor an integral
value;
if there is an error registering the database with the
database manager.private void connectImpl(java.util.List<java.lang.Object> args) throws PersistenceException
args
- A list of one or more connection parameters. This may take one
of several forms:
PersistenceException
- if any parameter is null;
if any parameter is neither a text value nor an integral
value;
if there is an error registering the database with the
database manager.private void connect(boolean isAutoConnect, java.lang.String pdb, java.lang.String ldb, java.lang.String host, java.lang.String service, java.lang.String user, java.lang.String password, java.lang.Integer port, java.lang.Integer maxRetries) throws PersistenceException
isAutoConnect
- flag indication that is is an implicit auto-connect operationpdb
- database physical name.ldb
- database logical name.host
- remote host name.service
- remote service name.user
- used id.password
- user password.port
- remote port number.maxRetries
- max connection attempts.PersistenceException
- if any parameter is null;
if any parameter is neither a text value nor an integral value;
if there is an error registering the database with the database manager.private java.lang.String makeConnection(Database database, java.lang.String ldbName, java.lang.String certAlias, boolean isAutoConnect) throws PersistenceException
database
- Database information object.ldbName
- Logical database name. If null
, root name of
physical database name will be used.certAlias
- Alias of certificate to be read from trust store to enable
certificate-based, server-to-server authentication. This
should match the server ID of the remote node.isAutoConnect
- flag indication that is is an implicit auto-connect operationnull
, but a new logical name will be computed and returned)
and null
otherwise.ErrorConditionException
- if the given database already is connected.PersistenceException
- if there is an error registering the database with the
database manager or establishing a network session with the
remote server.private void disconnectImpl(java.lang.String ldbName) throws PersistenceException
ldbName
for disconnect at the appropriate time: once no buffers reference the
database, and at the end of the current transaction (if any).ldbName
- Logical name of the database to disconnect.PersistenceException
- if the specified database has not been opened.private logical connectedImpl(character name)
name
- Logical database name or alias.true
if a logical connection exists; else
false
.private void createAliasImpl(java.lang.String alias, java.lang.String ldbName) throws PersistenceException
deleteAlias
method, or
until the current session ends.alias
- Alias to be created.ldbName
- Logical name of the database to which the alias is assigned.PersistenceException
- if the alias conflicts with an existing logical database name,
other than ldbName
.ErrorConditionException
- if the target database is not connected, and we are not in
silent error mode.private void deleteAliasImpl(java.lang.String alias)
alias
- Alias to be deleted.private character aliasImpl(int index)
index
- One-based index of the alias (aliases are stored in the order
in which they were created).index
is
invalid.private character dbParamImpl(java.lang.String nameOrAlias, int index)
DBPARAM()
Progress function.
Returns, as a character string, a comma-separated list of the parameters
used to connect to the database.
The method does a lookup on the database's name, or id it is null, the alias will extracted using the index.
Parameters returned by this method generally will not match those
returned by the original 4GL implementation, since we don't support any
others than those handled by ConnectionManager.connect()
.
nameOrAlias
- Logical database name or alias.index
- One-based index of the alias (aliases are stored in the order
in which they were created).nameOrAlias
or index
cannot be resolved to a
database.private static java.lang.String dbparam(java.util.List<java.util.Map.Entry<ConnectionManager.ConnectOption,ConnectionManager.ConnectOptionValue>> opts)
opts
- CONNECT options.private character dbVersionImpl(java.lang.String name, int index)
name
- Logical name or alias of the target database. If null
, then
index
is used instead.index
- One-based index of the target database among all databases currently connected in
this context.index
represents the unknown value or is outside of the range of
connected databases.java.lang.RuntimeException
- if there is an error binding to the directory service to retrieve runtime
configuration information.private void putConnected(java.lang.String ldbName, Database database, java.lang.String userId)
ldbName
- Logical name of connected database.database
- Object describing physical database.userId
- Current user's ID.private Database removeConnected(java.lang.String ldbName, boolean sessionCleanup)
ldbName
- Logical name of disconnected database.sessionCleanup
- true
if this action is being taken as part of cleanup for a session
that is terminating; false
if a normal disconnect.private integer dbTaskIdImpl(java.lang.String name, int index)
name
- Logical name or alias of the target database. If null
, then
index
is used instead.index
- One-based index of the target database among all databases currently connected in
this context.unknown
value if name
is not a
valid database name or index
is outside of the range of connected
databases.java.lang.RuntimeException
- if there is an error binding to the directory service to retrieve runtime
configuration information.