1 DB
Class Ax.db
Method Summary
Modifier and Type | Method | Description |
---|---|---|
static Object | NVL(Object expr1, Object expr2) | Implements the NVL function. |
static JSQBE | QBE() | Returns a QBE (query by example). |
static Object | apply(String name, Object[] args) | Called to invoke another script from connection. |
static void | beginWork() | Initiates a transaction within the connection. |
static Object | call(String name, Object[] args) | Called to invoke another script from connection. |
static void | clearDatabaseMetaData() | Force a refresh of tables metadata cache. |
static void | clearTableMetaData(String tabname) | Force a refresh of table metadata cache. |
static JSConnection | cloned() | An alternative connection to be used to handle dual transactions. |
static void | commitWork() | It makes that all the changes made after the previous commit/rollback be permanent and sets free all the locks in the database generated by this object. |
static TableCopyEvent | copy(JSConnection other, String tableName, Consumer<TableCopyOptions> options) | Copies a table from the connection db to another db. |
static JSDBCopy | dbcopy(JSConnection dst) | Creates a DBCopy instance for this database to target dst database. |
static JSSQLCA | delete(String tableName, Map<StringObject> args) | Deletes the rows from the specified table with the same column values as defined by args. |
static JSSQLCA | delete(String tableName, Map<StringObject> args, String where) | Deletes the rows from the specified table with the same column values as defined by args, and that fulfill the where clause conditions. |
static JSSQLCA | delete(String tableName, String where) | Deletes the rows from the specified table that fulfill the where clause conditions. |
static void | deregisterResultSet(JSResultSet<JDBCResultSet> rs) | When a JSResultSet is manually closed by application, remove it from close list. |
static void | disableTransactions() | Disables transactions on physical connection. |
static void | enableTransactions() | Enables transactions on physical connection. |
static String | escape(String token) | It prevents sql injection when embedding a variable content directly inside SQL Statement. |
static JSSQLCA | execute(String sql, Object[] args) | Execute an SQL statement that may return a ResultSet or not depending statement type. |
static JSResultSet | executeCachedQuery(String sql) | Executes a query and caches the ResultSet. |
static JSResultSet | executeCachedQuery(String sql, Object[] args) | |
static JSResultSet | executeCachedQuery(String sql, int ttl, Object[] args) | |
static JSResultSet | executeFunction(String name, Object[] args) | Executes the specified native SQL function. |
static JSResultSet | executeFunction(String name, Function<IntegerString> columnNameMap, Object[] args) | Executes the specified native SQL function. |
static Map | executeFunction(String name, Consumer<AbstractFunctionCallConfigurator> options) | Executes the specified native SQL function. |
static Object | executeGet(String sql, Object[] args) | Executes a SQL query and returns a single value, when possible, converted to native javascript type. |
static double | executeGetDouble(String sql, Object[] args) | Executes the query and returns a double value, when possible. |
static int | executeGetInt(String sql, Object[] args) | Executes the query and returns an integer value, when possible. |
static long | executeGetLong(String sql, Object[] args) | Executes the query and returns a long value, when possible. |
static JSResultSet | executeProcedure(String name, Object[] args) | Executes the specified native SQL procedure. |
static JSResultSet | executeProcedure(String name, Function<IntegerString> columnNameMap, Object[] args) | Executes the specified native SQL procedure. |
static JSResultSet | executeQuery(String sql, Object[] args) | Executes the given SQL query with the specified arguments. |
static JSResultSet | executeScriptOrQuery(String sql) | Executes a query or a XSQL-Script. |
static JSResultSet | executeScrollableQuery(String sql, Object[] args) | Returns a scrollable Resultset. |
static boolean | existsFunction(String functionName) | Checks if a function exists in the database. |
static boolean | existsProcedure(String procedureName) | Checks if a procedure exists in the database. |
static boolean | existsTable(String tableName) | Checks if a table exists in the database. |
static String | fn(String fname) | Returns the function name according specific database agent. |
static boolean | getAutoCommit() | |
static String | getBasicTextSearch(String colname, String text) | Returns the basic text search statement for the engine. |
static String | getBestTextSearch(String tabname, String colname, String text, boolean fuzzy) | Returns the best text search possible for the column. |
static JSConnection | getConnection(String server, String name) | Gets a connection by db name from provider on a given server an database name. |
static String | getDatabaseAtServer() | Returns a string with the connection database and server names with the format: db@srv . |
static JDBCDriver | getDriver() | Returns the database driver. |
static String | getFuzzyTextSearch(String colname, String text) | Returns the fuzzy (approximate) text search statement. |
static String | getLogicalCode() | Returns the databas logical code. |
static String | getLogicalUser() | Returns the logical user executing the connection. |
static JSDatabaseMetaData | getMetaData() | Gets the database metadata wrapper. |
static JSDatabaseMetaData | getMetaData(boolean refresh) | Returns the database metadata wrapper and forces a refresh of tables metadata cache if refresh is true. |
static String | getName() | Returns the database name (logical code). |
static int | getOpenResultSets() | Returns the context open ResultSets. |
static String | getPhysicalCode() | Returns the database logical code. |
static String | getPhysicalUser() | Returns the physical user executing the connection. |
static List | getProgressMonitor() | Gets the list of active progress (useful for debug). |
static String | getSPLDebug() | Returns the content of the debug file. |
static String | getServer() | Returns the server code. |
static int | getSessionId() | Gets the id of the session. |
static JSConnection | getSharedConnection() | Creates a new JSConnection instance sharing the original connection. |
static LimitedStringWriter | getStderr() | Gets the standard error of the connection's monitoring console. |
static LimitedStringWriter | getStdout() | Gets the standard output of the connection's monitoring console. |
static String | getTempTableName(String pattern) | Creates a temporary table for the duration of the script execution and returns its name. |
static String | getUser() | Get user from http request (till we do no have a better way). |
static boolean | hasInitializationError() | Checks if there is any initialization error. |
static boolean | hasTextSearch() | Checks if database has text search extensions. |
static JSSQLCA | insert(String tableName, Map<StringObject> args) | Inserts a map(JSON) into a table. |
static int | insert(String tableName, List<Map> list) | Inserts an array of maps(JSON) into a table [{colname: value, . |
static JSBatchInsert | insertBatch(String tableName) | Returns a JSBatchInsert to allow Javascript operate in batch inserts. |
static JSSQLCA | insertOrUpdate(String tableName, Map<StringObject> rowData) | Inserts a JSON object. |
static JSSQLCA | insertOrUpdate(String tableName, Map<StringObject> dataMap, Map<StringObject> keysMap) | Try insert data, if already exists row with same values in the key columns, then update. |
static boolean | isOnTransaction() | Returns true or false if there is a open transaction. |
static boolean | isReadOnly() | Checks if the conection is read only. |
static void | lockTable(String tableName) | Locks the specified table in th default mode. |
static void | lockTable(String tableName, String mode) | Locks the table in the spedified mode. |
static void | moveTableRow(String tabname, String colname, int from, int to, String condition) | A move row operation. |
static JSConnection | of(String name) | Gets a connection by db name from provider on same "connection" server. |
static JSConnection | of(String server, String name) | Gets a connection by db name from provider on a given server an database name. |
static void | releaseConnections() | This method is called at JSScriptRunner end. |
static void | rollbackWork() | Ends a failed transaction. |
static void | setDebug(boolean debug) | Notify database connection debug is enabled, this will cause some classes using connection may enable debug log. |
static void | setPreparedStatementCache(boolean mode) | Enable or disable the use of prepared statements cache. |
static void | setPreparedStatementCache(int size) | Sets the cache size. |
static String | setSPLDebug(boolean on) | Creates a SPL procedure named set_debug on current database. |
static JSConnectionStatistics | statistics() | Gets the statistics at this moment. |
static boolean | supportsTransactions() | Checks if the connection supports transactions. |
static String | toString() | Returns a string with the connection database and server names with the format: db@srv . |
static JSSQLCA | update(String tableName, Map<StringObject> rowData) | Updates a row using automatic primary key detection and NO where condition rowData is a JSON with the format {colname: value, . |
static JSSQLCA | update(String tableName, Map<StringObject> rowData, String condition) | Updates a row using a where condition and NO primary key: |
static JSSQLCA | update(String tableName, Map<StringObject> dataMap, Map<StringObject> keysMap) | Updates a row. |
static JSSQLCA | update(String tableName, Map<StringObject> dataMap, Map<StringObject> keysMap, String condition) | Updates a row. |
static JSBatchUpdate | updateBatch(String tableName) | Creates an update batch object to update table passed as parameter. |
static JSSQLCA | updateOrInsert(String tableName, Map<StringObject> rowData) | Insert or Updates row provided in columnMap. |
static JSSQLCA | updateOrInsert(String tableName, Map<StringObject> dataMap, Map<StringObject> keysMap) | Try insert data, if it fails ( eg: tried to duplicate a pk), then update The keysMap and dataMap in JS are a JSON of the form {colname: value, . |
Method Detail
NVL
-
static Object NVL(Object expr1, Object expr2)
- Info:
-
Implements the NVL function. If expr1 is null, expr2's value is applied. - Parameters:
- expr1 - expression espression to return if it is not null
- expr2 - expression to return in case expr1 is null
- Returns:
- if expr is null, expr 2 is returned, otherwise, expr2 is returned <pre> {@code var char1 = null; //var char1 = 'a'; return Ax.db.executeQuery(` SELECT ${Ax.db.NVL(char1, 'hello')} FROM systables WHERE tabid = 1 `); } </pre>
var char1 = null; //var char1 = 'a'; return Ax.db.executeQuery(` SELECT ${Ax.db.NVL(char1, 'hello')} FROM systables WHERE tabid = 1 `);
QBE
-
static JSQBE QBE()
- Info:
-
Returns a QBE (query by example). - Returns:
- A QBE object
apply
-
static Object apply(String name, Object[] args)
- Info:
-
Called to invoke another script from connection. - Parameters:
- name - name of the script to call
- args - array with the script parameters
- Returns:
- the return of the called script
Ax.db.apply('my_script_name', [arg1, arg2...]) //or Ax.db.apply('my_script_name', arguments)
beginWork
-
static void beginWork()
- Info:
-
Initiates a transaction within the connection. If a transaction is already openned, this command closes previous transaction executing a "commit work" and opens a new database transaction.
call
clearDatabaseMetaData
-
static void clearDatabaseMetaData()
- Info:
-
Force a refresh of tables metadata cache. It may be useful when we are changing a table schema on a table already used by database. For example during TableInsert or TableUpdate operations metadata is always cached.
clearTableMetaData
-
static void clearTableMetaData(String tabname)
- Info:
-
Force a refresh of table metadata cache. It may be useful when we are changing a table schema on a table already used by database. For example during TableInsert or TableUpdate operations metadata is always cached. - Parameters:
- tabname - table to clear metadata on
cloned
-
static JSConnection cloned()
- Info:
-
An alternative connection to be used to handle dual transactions. The case: Use alternate connection to block a specific table (A) Use general connection to perform multiple transactions on other table (B) while we keep a lock on (A). Finally we will unlock A either by an implicit commit or by the automatic release of connection on finalization. Same as of(name) - Returns:
- a new connection instance to the same db.
commitWork
-
static void commitWork()
- Info:
-
It makes that all the changes made after the previous commit/rollback be permanent and sets free all the locks in the database generated by this object.
copy
-
static TableCopyEvent copy(JSConnection other, String tableName, Consumer<TableCopyOptions> options)
- Info:
-
Copies a table from the connection db to another db. - Parameters:
- other - destination connection
- tableName - name of the table to copy
- options - copying options
- Returns:
dbcopy
-
static JSDBCopy dbcopy(JSConnection dst)
- Info:
-
Creates a DBCopy instance for this database to target dst database. - Parameters:
- dst - destination database
- Returns:
- a DBCopy instance for this database to target dst database
delete
-
static JSSQLCA delete(String tableName, Map<StringObject> args)
- Info:
-
Deletes the rows from the specified table with the same column values as defined by args. args is a JSON with the format: {colname: value, ...} If a row has the same values as defined in args, it will be deleted. - Parameters:
- tableName - name of the table to do the delete
- args - map(JSON) with the columns and values to check for deletion
- Returns:
- SQLCA object with transaction info
delete
-
static JSSQLCA delete(String tableName, Map<StringObject> args, String where)
- Info:
-
Deletes the rows from the specified table with the same column values as defined by args, and that fulfill the where clause conditions. args is a JSON with the format: {colname: value, ...} If a row has the same values as defined in args (and fulfills where clause conditions), it will be deleted. - Parameters:
- tableName - name of the table to do the delete
- args - map(JSON) with the columns and values to check for deletion
- where - sql where clause for deletion
- Returns:
- SQLCA object with transaction info
delete
deregisterResultSet
-
static void deregisterResultSet(JSResultSet<JDBCResultSet> rs)
- Info:
-
When a JSResultSet is manually closed by application, remove it from close list. It also happens when JSResultSet is returned to Javascript caller. In that case we de-register it to avoid it's being closed before connection release. Called from JSResultSet. - Parameters:
- rs - ResultSet to deregister
disableTransactions
-
static void disableTransactions()
- Info:
-
Disables transactions on physical connection. In case of using a physical connection, obtained from de JSConnection, but not the JSConnection itself. It is the case of a Javascript invoking a Report execution.
enableTransactions
-
static void enableTransactions()
- Info:
-
Enables transactions on physical connection.
escape
execute
executeCachedQuery
-
static JSResultSet executeCachedQuery(String sql)
- Info:
-
Executes a query and caches the ResultSet. - Parameters:
- sql - query to execute
- Returns:
- cached ResultSet
executeCachedQuery
-
static JSResultSet executeCachedQuery(String sql, Object[] args)
- Parameters:
- sql - query to execute
- args - query arguments
- Returns:
- cached ResultSet
executeCachedQuery
-
static JSResultSet executeCachedQuery(String sql, int ttl, Object[] args)
- Parameters:
- sql - query to execute
- ttl - time to live in seconds
- args - query arguments
- Returns:
- cached ResultSet
executeFunction
-
static JSResultSet executeFunction(String name, Object[] args)
- Info:
-
Executes the specified native SQL function. - Parameters:
- name - name of the function
- args - function arguments
- Returns:
- a ResultSet with the result of the function execution
return Ax.db.executeFunction('informix_function1', 'systables');
executeFunction
-
static JSResultSet executeFunction(String name, Function<IntegerString> columnNameMap, Object[] args)
- Info:
-
Executes the specified native SQL function. Applies to Informix function call style - - Parameters:
- name - name of the function
- columnNameMap - Function to specify the name of the columns of the Resultset
- args - function arguments
- Returns:
- a ResultSet with the result of the function execution
return Ax.db.executeFunction('informix_function1', columnIndex => { switch (columnIndex) { case 1: return "tabid"; case 2: return "nrows"; default: return c + columnIndex; } }, 'systables');
executeFunction
-
static Map executeFunction(String name, Consumer<AbstractFunctionCallConfigurator> options)
- Info:
-
Executes the specified native SQL function. Applies to ORACLE function call style - - Parameters:
- name - name of the function
- options - function configuration options
- Returns:
- a ResultSet with the result of the procedure execution
return Ax.db.executeFunction("informix_function_registerOut", config => { config.setString(1, "systables"); config.registerOutParameter(1, java.sql.JDBCType.INTEGER, "tabid"); config.registerOutParameter(2, java.sql.JDBCType.INTEGER, "nrows"); });
executeGet
-
static Object executeGet(String sql, Object[] args)
- Info:
-
Executes a SQL query and returns a single value, when possible, converted to native javascript type. For example, Object[], List, Map and java.util.Date are transformed. Notice that java.sql.Date is keep of original type to prevent GMT offset date change. - Parameters:
- sql - SQL query to execute
- args - query arguments
- Returns:
- the single value resulting from the query, converted to native javascript type
executeGetDouble
executeGetInt
executeGetLong
executeProcedure
-
static JSResultSet executeProcedure(String name, Object[] args)
- Info:
-
Executes the specified native SQL procedure. - Parameters:
- name - name of the procedure
- args - procedure arguments
- Returns:
- a ResultSet with the result of the function execution
executeProcedure
-
static JSResultSet executeProcedure(String name, Function<IntegerString> columnNameMap, Object[] args)
- Info:
-
Executes the specified native SQL procedure. columnNameMap is used to set names for the columns of the returned ResultSet. Useful in case the ResultSet's column names are like "(expression)". - Parameters:
- name - name of the procedure
- columnNameMap - Function to specify the name of the columns of the Resultset
- args - procedure arguments
- Returns:
- a ResultSet with the result of the function execution
executeQuery
-
static JSResultSet executeQuery(String sql, Object[] args)
- Info:
-
Executes the given SQL query with the specified arguments. - Parameters:
- sql - query to execute
- args - query arguments
- Returns:
- the ResultSet obtained from the query execution
executeScriptOrQuery
-
static JSResultSet executeScriptOrQuery(String sql)
- Info:
-
Executes a query or a XSQL-Script. - Parameters:
- sql - query or call to a script
- Returns:
- the ResultSet obtained from the
executeScrollableQuery
-
static JSResultSet executeScrollableQuery(String sql, Object[] args)
- Info:
-
Returns a scrollable Resultset. By default ResultSets are iterable only forwards. If it is scrollable, it does not have that retriction. - Parameters:
- sql - query to execute
- args - query arguments
- Returns:
- a scrollable RseultSet
existsFunction
-
static boolean existsFunction(String functionName)
- Info:
-
Checks if a function exists in the database. - Parameters:
- functionName - the name of the function to check
- Returns:
- true if the function exists in the database, false otherwise
existsProcedure
-
static boolean existsProcedure(String procedureName)
- Info:
-
Checks if a procedure exists in the database. - Parameters:
- procedureName - the name of the procedure to check
- Returns:
- true if the procedure exists in the database, false otherwise
existsTable
-
static boolean existsTable(String tableName)
- Info:
-
Checks if a table exists in the database. - Parameters:
- tableName - the name of the table to check
- Returns:
- true if the table exists in the database, false otherwise
fn
-
static String fn(String fname)
- Info:
-
Returns the function name according specific database agent. - Parameters:
- fname - the function name
- Returns:
- the native function name in the specific database
return Ax.db.executeQuery(` SELECT TRIM(tabname), ${Ax.db.fn("trim")}(tabname) FROM systables WHERE tabid = 1 `);
getAutoCommit
-
static boolean getAutoCommit()
- Returns:
getBasicTextSearch
-
static String getBasicTextSearch(String colname, String text)
- Info:
-
Returns the basic text search statement for the engine. It does not check if column has text search eanbled. - Parameters:
- colname - the column to search on
- text - the text to search
- Returns:
- the basic text search statement for the engine
getBestTextSearch
-
static String getBestTextSearch(String tabname, String colname, String text, boolean fuzzy)
- Info:
-
Returns the best text search possible for the column. This can be a specific text search statement if database has a text search module or a simple LIKE if no TS module is available. Probably the best option to get a LIKE or BASIC text search. - Parameters:
- tabname - the table to search on
- colname - the column of the table to search on
- text - the text to search
- fuzzy -
- Returns:
- the best text search possible for the column
getConnection
-
static JSConnection getConnection(String server, String name)
- Info:
-
Gets a connection by db name from provider on a given server an database name. Same as of(server, name). - Parameters:
- server - name of the db to connect to
- name - name of the server to connect to
- Returns:
- a new JSConnection to the db
getDatabaseAtServer
-
static String getDatabaseAtServer()
- Info:
-
Returns a string with the connection database and server names with the format: db@srv . Same as toString(). - Returns:
- the connection database and server names
getDriver
-
static JDBCDriver getDriver()
- Info:
-
Returns the database driver. It's needed for dbexport model SQL. - Returns:
- the database driver <pre> {@code new Ax.rs.Writer(rs).sql(options => { options.setTableName("systables"); options.setDriver(Ax.db.getDriver()); }); } </pre>
new Ax.rs.Writer(rs).sql(options => { options.setTableName("systables"); options.setDriver(Ax.db.getDriver()); });
getFuzzyTextSearch
-
static String getFuzzyTextSearch(String colname, String text)
- Info:
-
Returns the fuzzy (approximate) text search statement. It does not check if column has text search eanbled. - Parameters:
- colname - the column to search on
- text - the text to search
- Returns:
- the fuzzy (approximate) text search statement
getLogicalCode
-
static String getLogicalCode()
- Info:
-
Returns the databas logical code. Same as getName(). - Returns:
- the databas logical code
getLogicalUser
-
static String getLogicalUser()
- Info:
-
Returns the logical user executing the connection. - Returns:
- the logical user
getMetaData
-
static JSDatabaseMetaData getMetaData()
- Info:
-
Gets the database metadata wrapper. - Returns:
- the database metadata wrapper
getMetaData
-
static JSDatabaseMetaData getMetaData(boolean refresh)
- Info:
-
Returns the database metadata wrapper and forces a refresh of tables metadata cache if refresh is true. - Parameters:
- refresh - true to clear metadata, false otherwise
- Returns:
- the database metadata wrapper
getName
-
static String getName()
- Info:
-
Returns the database name (logical code). Same as getLogicalCode(). - Returns:
- the database logical code
getOpenResultSets
-
static int getOpenResultSets()
- Info:
-
Returns the context open ResultSets. It's useful for tests to ensure the number of open statements are as expected. - Returns:
- the context open ResultSets
getPhysicalCode
-
static String getPhysicalCode()
- Info:
-
Returns the database logical code. - Returns:
- the database logical code
getPhysicalUser
-
static String getPhysicalUser()
- Info:
-
Returns the physical user executing the connection. - Returns:
- the physical user
getProgressMonitor
-
static List getProgressMonitor()
- Info:
-
Gets the list of active progress (useful for debug). - Returns:
- the list of active progress
getSPLDebug
-
static String getSPLDebug()
- Info:
-
Returns the content of the debug file. - Returns:
- the content of the debug file
getServer
-
static String getServer()
- Info:
-
Returns the server code. - Returns:
- the server code
getSessionId
-
static int getSessionId()
- Info:
-
Gets the id of the session. - Returns:
- the id of the session
getSharedConnection
-
static JSConnection getSharedConnection()
- Info:
-
Creates a new JSConnection instance sharing the original connection. - Returns:
- a new connection
getStderr
-
static LimitedStringWriter getStderr()
- Info:
-
Gets the standard error of the connection's monitoring console. - Returns:
- the standard error of the connection's monitoring console.
getStdout
-
static LimitedStringWriter getStdout()
- Info:
-
Gets the standard output of the connection's monitoring console. - Returns:
- the standard output of the connection's monitoring console
getTempTableName
getUser
-
static String getUser()
- Info:
-
Get user from http request (till we do no have a better way). - Returns:
- the user from http request
hasInitializationError
-
static boolean hasInitializationError()
- Info:
-
Checks if there is any initialization error. - Returns:
- true if there is an initialization error, false otherwise
hasTextSearch
-
static boolean hasTextSearch()
- Info:
-
Checks if database has text search extensions. - Returns:
- if database has text search extensions, false otherwise
insert
insert
insertBatch
-
static JSBatchInsert insertBatch(String tableName)
- Info:
-
Returns a JSBatchInsert to allow Javascript operate in batch inserts. - Parameters:
- tableName - table name whee the batch insert will be done
- Returns:
- a JSBatchInsert to allow Javascript operate in batch inserts
insertOrUpdate
-
static JSSQLCA insertOrUpdate(String tableName, Map<StringObject> rowData)
- Info:
-
Inserts a JSON object. If insert fails with duplicated row, an update is executed by autodiscovering primary key from row data. rowData is a JSON with the format {'olname: value, ...}. - Parameters:
- tableName - name of the table
- rowData - data to insert / update
- Returns:
- SQLCA object with transaction info
insertOrUpdate
-
static JSSQLCA insertOrUpdate(String tableName, Map<StringObject> dataMap, Map<StringObject> keysMap)
- Info:
-
Try insert data, if already exists row with same values in the key columns, then update. dataMap and keysMap are JSON with the format {colname: value, ...}. - Parameters:
- tableName - name of the table
- dataMap - map(JSON) to do the insert/update
- keysMap - key columns to check if insert or update
- Returns:
- SQLCA object with transaction info
isOnTransaction
-
static boolean isOnTransaction()
- Info:
-
Returns true or false if there is a open transaction. - Returns:
- true if there is an open transaction, false otherwise
isReadOnly
-
static boolean isReadOnly()
- Info:
-
Checks if the conection is read only. - Returns:
- true if the connection is read only, false otherwise
lockTable
-
static void lockTable(String tableName)
- Info:
-
Locks the specified table in th default mode. AUTO LOCK TABLE table-Name (default mode) Notice that MYSQL and SQLServer are not standard and don't support SHARE|EXCLUSIVE modes. - Parameters:
- tableName - name of the table to lock
lockTable
moveTableRow
-
static void moveTableRow(String tabname, String colname, int from, int to, String condition)
- Info:
-
A move row operation. Assuming that in the table the rows are ordered by sequence number, it moves the row from the 'from' position, to the 'to' position if the condition is satisfied. Given the following example: - Parameters:
- tabname - table wher the move is taking place
- colname - sequence number column to use as from and to
- from - sequence number of the origin row
- to - sequence number of the destination row
- condition - moving condition, like "1=1"
+------+----------+ |seqno |fruit | +------+----------+ | 1|Banana | | 2|Mango | | 3|Apple | | 4|Carrot | +------+----------+ MOVE 2(Mango) - 3(Apple) +------+----------+ |seqno |fruit | +------+----------+ | 1|Banana | | 2|Apple | | 3|Mango | | 4|Carrot | +------+----------+
of
-
static JSConnection of(String name)
- Info:
-
Gets a connection by db name from provider on same "connection" server. - Parameters:
- name - the name of the db to connect
- Returns:
- a new JSConnection to the db
of
-
static JSConnection of(String server, String name)
- Info:
-
Gets a connection by db name from provider on a given server an database name. - Parameters:
- server - name of the server to connect to
- name - name of the db to connect to
- Returns:
- a new JSConnection to the db
releaseConnections
-
static void releaseConnections()
- Info:
-
This method is called at JSScriptRunner end. So it's not a Closeable and it's not handled like other Closeable script classes
rollbackWork
-
static void rollbackWork()
- Info:
-
Ends a failed transaction.
setDebug
-
static void setDebug(boolean debug)
- Info:
-
Notify database connection debug is enabled, this will cause some classes using connection may enable debug log. For example, TableInsert ... - Parameters:
- debug - true to enable debug, false otherwise
setPreparedStatementCache
-
static void setPreparedStatementCache(boolean mode)
- Info:
-
Enable or disable the use of prepared statements cache. True by default. - Parameters:
- mode - true to enable cache, false to disable it
setPreparedStatementCache
-
static void setPreparedStatementCache(int size)
- Info:
-
Sets the cache size. Default size is 1000. - Parameters:
- size - cache size
setSPLDebug
-
static String setSPLDebug(boolean on)
- Info:
-
Creates a SPL procedure named set_debug on current database. It sets a global variable gl_debug to the input value. If debug is on, it also setup debug to a file with the format DATABASE.USER.SESSIONID.log Returns the file name that will be used for debug - Parameters:
- on - value of gl_debug
- Returns:
- the file name that will be used for debug
statistics
-
static JSConnectionStatistics statistics()
- Info:
-
Gets the statistics at this moment. - Returns:
- the statistics at this moment
supportsTransactions
-
static boolean supportsTransactions()
- Info:
-
Checks if the connection supports transactions. - Returns:
- true if it supports transactions, false otherwise
toString
-
static String toString()
- Info:
-
Returns a string with the connection database and server names with the format: db@srv . Same as getDatabaseAtServer(). - Returns:
- the connection database and server names
update
-
static JSSQLCA update(String tableName, Map<StringObject> rowData)
- Info:
-
Updates a row using automatic primary key detection and NO where condition rowData is a JSON with the format {colname: value, ...}. It does not work with temporary tables as primary key can not be automatically determined. - Parameters:
- tableName - name of thetable to update
- rowData - map(JSON) with update data
- Returns:
- SQLCA object with transaction info
Ax.db.update("t1", { "c1": 1, "c2" : "bye" });
update
-
static JSSQLCA update(String tableName, Map<StringObject> rowData, String condition)
- Info:
-
Updates a row using a where condition and NO primary key: - Parameters:
- tableName - name of the table
- rowData - update data
- condition -
- Returns:
- SQLCA object with transaction info
Ax.db.update("t1", { "c2" : "bye" }, "c1 = 1");
Ax.db.update("t1", { "c1": 1, "c2" : "bye" }, null);
Ax.db.update("t1", { "c1": 1, "c2" : "bye" }, "c3 IS NULL");
update
-
static JSSQLCA update(String tableName, Map<StringObject> dataMap, Map<StringObject> keysMap)
- Info:
-
Updates a row. keysMap contains the key columns for 'recognizing' the column to update. The keysMap and dataMap in JS are a JSON of the form {colname: value, ...}. - Parameters:
- tableName - name of the table
- dataMap - map(JSON) with the update data
- keysMap - map(JSON) with the key columns for the update
- Returns:
- SQLCA object with transaction info
update
-
static JSSQLCA update(String tableName, Map<StringObject> dataMap, Map<StringObject> keysMap, String condition)
- Info:
-
Updates a row. keysMap contains the key columns for 'recognizing' the column to update. The keysMap and dataMap in JS are a JSON of the form {colname: value, ...}. - Parameters:
- tableName - name of the table
- dataMap - map(JSON) with the update data
- keysMap - map(JSON) with the key columns for the update
- condition - optional extra where condition (EXISTS ... CASE .. etc)
- Returns:
- SQLCA object with transaction info
updateBatch
-
static JSBatchUpdate updateBatch(String tableName)
- Info:
-
Creates an update batch object to update table passed as parameter. - Parameters:
- tableName - name of the table to execute the batch update
- Returns:
- a JSBatchUpdate to allow Javascript operate in batch updates
updateOrInsert
-
static JSSQLCA updateOrInsert(String tableName, Map<StringObject> rowData)
- Info:
-
Insert or Updates row provided in columnMap. pk columns are automatically extracted from rowData. rowData in JS is a JSON of the form {colname: value, ...} - Parameters:
- tableName - name of the table
- rowData - data to insert / update
- Returns:
- SQLCA object with transaction info
updateOrInsert
-
static JSSQLCA updateOrInsert(String tableName, Map<StringObject> dataMap, Map<StringObject> keysMap)
- Info:
-
Try insert data, if it fails ( eg: tried to duplicate a pk), then update The keysMap and dataMap in JS are a JSON of the form {colname: value, ...}. - Parameters:
- tableName - name of the table
- dataMap - map(JSON) with the data to insert / update
- keysMap - map(JSON) with the key columns for the update
- Returns:
- SQLCA object with transaction info
2 JSResultSet
Class deister.axional.script.lib.ax.rs.JSResultSet
Constructor Summary
Method | Description |
---|---|
JSResultSet(JSConnection conn, T rs) | |
JSResultSet(T rs) |
Method Summary
Method Detail
JSResultSet
-
JSResultSet(JSConnection conn, T rs)
- Parameters:
- conn -
- rs -
JSResultSet
-
JSResultSet(T rs)
- Parameters:
- rs -
asJSON
-
String asJSON()
- Returns:
asJSON
-
void asJSON(Consumer<JSONExportOptions> arg0)
- Parameters:
- arg0 -
beforeFirst
-
void beforeFirst()
close
-
void close()
- Info:
-
var rs = Ax.db.executeQuery("SELECT .."); rs.close();
closeIfNeed
-
boolean closeIfNeed(String cause)
- Parameters:
- cause -
- Returns:
cols
-
ISQLResultSetCols cols()
- Returns:
compare
-
ResultSetComparator compare(IResultSetConvertible arg0)
- Parameters:
- arg0 -
- Returns:
compare
-
ResultSetComparator compare(IResultSetConvertible arg0, double arg1)
- Parameters:
- arg0 -
- arg1 -
- Returns:
cursor
-
ResultSetCursorGroup cursor()
- Returns:
equals
-
boolean equals(IResultSetConvertible arg0)
- Parameters:
- arg0 -
- Returns:
equals
-
boolean equals(IResultSetConvertible arg0, double arg1)
- Parameters:
- arg0 -
- arg1 -
- Returns:
findColumn
-
int findColumn(String columnName)
- Parameters:
- columnName -
- Returns:
firstOne
-
ResultSetRowMap firstOne()
- Info:
-
Like toOne but will not fail if more than one row. It's like SQL SELECT FIRST 1 - Returns:
getColumnLocalizedValue
getColumnLocalizedValue
-
String getColumnLocalizedValue(LocaleFormatter formater, int columnIndex)
- Parameters:
- formater -
- columnIndex -
- Returns:
getColumnLocalizedValue
-
String getColumnLocalizedValue(JSLocaleFormatter formater, int columnIndex)
- Parameters:
- formater -
- columnIndex -
- Returns:
getColumnType
getConnection
-
JSConnection getConnection()
- Returns:
getMetaData
-
ExtendedResultSetMetaData getMetaData()
- Returns:
getObjectId
-
int getObjectId()
- Returns:
getParentId
-
int getParentId()
- Returns:
getRow
-
int getRow()
- Returns:
getRowCount
-
int getRowCount()
- Returns:
- the number of rows loaded in memory ResultSet or -1 if it's unknown (cause it's a JDBC ResultSet)
getSQL
-
String getSQL()
- Returns:
getTitle
-
String getTitle()
- Returns:
isColumnNullable
-
boolean isColumnNullable(String colname)
- Parameters:
- colname -
- Returns:
isColumnNumeric
-
boolean isColumnNumeric(int arg0)
- Parameters:
- arg0 -
- Returns:
isMemory
-
boolean isMemory()
- Returns:
isResultSet
-
boolean isResultSet(Object arg0)
- Parameters:
- arg0 -
- Returns:
iterator
-
Iterator iterator()
- Returns:
next
-
boolean next()
- Returns:
pivot
-
SQLResultSetArray pivot(Consumer<ResultSetPivotOptions> config)
- Parameters:
- config -
- Returns:
previous
-
boolean previous()
- Returns:
rows
-
ISQLResultSetRows rows()
- Returns:
stream
-
ResultSetTupleStream stream()
- Returns:
toArray
-
List toArray()
- Info:
-
Returns the resultSet as a Java array (array of arrays) - Returns:
toArray
toCSV
-
String toCSV()
- Returns:
toCSV
-
void toCSV(Consumer<CSVExportOptions> arg0)
- Parameters:
- arg0 -
toExcel
-
byte[] toExcel()
- Returns:
toExcel
-
void toExcel(Consumer<ExcelExportOptions> arg0)
- Parameters:
- arg0 -
toFOP
-
String toFOP()
- Returns:
toFOP
-
String toFOP(Consumer<FOPReportConfig> arg0)
- Parameters:
- arg0 -
- Returns:
toFOPTableBody
-
String toFOPTableBody(double arg0)
- Parameters:
- arg0 -
- Returns:
toFOPTableBody
-
String toFOPTableBody(Consumer<FOPReportConfig> arg0, double arg1)
- Parameters:
- arg0 -
- arg1 -
- Returns:
toHTML
-
String toHTML()
- Returns:
toHTML
-
String toHTML(Consumer<HtmlConfigurator> arg0)
- Parameters:
- arg0 -
- Returns:
toJSON
-
String toJSON()
- Returns:
- a JSON in a format that is convertible back to a ResultSet
toJSON
-
String toJSON(Consumer<JSONConfigurator> arg0)
- Parameters:
- arg0 -
- Returns:
toJSONArray
-
List toJSONArray()
- Info:
-
Same as toOne() we should return a JSON array (at least immutable) - Returns:
- the resultSet as a List of JSON rows
toJavaScript
-
String toJavaScript()
- Returns:
toMemory
-
SQLResultSetArray toMemory()
- Returns:
- a JSResultSet wrapping a memory SQLResultSetArray so it can be iterated many times.
toOne
-
ResultSetRowMap toOne()
- Returns:
- the current row as JSON map fetching it and ensuring no more rows exists. We return a JSObject instead of ResultSetRowMap cause even Nashorn hanles perfectly the Map in javascript, if we want to compose a JSON object using this as element it will not really be composed of JSONs. The case comes when we want to send a composed JSON object combining various JSONs and JSON arrays. var json = { invoice : Ax.db.executeQuery("SELECT invoiceNumber, invocieDate as date, total FROM invoice WHERE invoiceNumber = ?", number).toOne(), company : Ax.db.executeQuery("SELECT * FROM company where company_id = (SELECT company_id FROM invoice WHERE invoiceNumber = ?)", number).toOne(), items : Ax.db.executeQuery("SELECT * FROM items WHERE invoiceNumber = ? ORDER BY seqno", number).toArray() } Even this object can be handled by Nashorn, if we build it using ResultSetRowMap for invoice an company and and List <ResultSetRowMap> for items, it is not really composed of JSON objects. If not rows, the map contains the keys with null values
toPDF
-
byte[] toPDF()
- Returns:
toPDF
-
byte[] toPDF(Consumer<FOPReportConfig> arg0)
- Parameters:
- arg0 -
- Returns:
toPDF
-
byte[] toPDF(String arg0)
- Parameters:
- arg0 -
- Returns:
toResultSet
-
ResultSet toResultSet()
- Returns:
toRow
-
ResultSetRowMap toRow()
- Returns:
toString
-
String toString()
- Info:
-
Allow print(db.executeQuery(...)); - Returns:
toText
-
String toText()
- Returns:
toText
-
String toText(Consumer<ResultSetPrinterConfig> arg0)
- Parameters:
- arg0 -
- Returns:
toValue
-
Object toValue()
- Returns:
- a single column on a single row resultset