Skip to content

Support detection of CRUD operations and queries for JDBC #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rahlk opened this issue Feb 9, 2025 · 0 comments
Open

Support detection of CRUD operations and queries for JDBC #112

rahlk opened this issue Feb 9, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@rahlk
Copy link
Collaborator

rahlk commented Feb 9, 2025

Parent: #100

Is your feature request related to a problem? Please describe

Yes, for issue #100, support JDBC database operations.

Describe the solution you'd like

The generated analysis.json must be able to capture JDBC including operations using Connection, Statement, PreparedStatement, and ResultSet.

1. If the callsite ReceiverType is Statement, PreparedStatement, and CallableStatement

We want to look for the following methods:

Class Method Description CRUD Operation
Statement addBatch(String sql) Adds an SQL command to batch. ANY (C/U/D)
  execute(String sql) Executes an SQL statement that may return multiple results. ANY (C/R/U/D)
  executeBatch() Executes a batch of SQL commands. ANY (C/U/D)
  executeLargeBatch() Executes a large batch of SQL commands. ANY (C/U/D)
  executeLargeUpdate(String sql) Executes INSERT, UPDATE, DELETE, or DDL statements. C/U/D
  executeQuery(String sql) Executes a SELECT query and returns a ResultSet. READ
  executeUpdate(String sql) Executes INSERT, UPDATE, DELETE, or DDL statements. C/U/D
  getResultSet() Retrieves the current ResultSet. READ
  getGeneratedKeys() Retrieves auto-generated keys from an INSERT operation. READ (post-C)
  getUpdateCount() Returns the number of rows affected by an UPDATE, INSERT, or DELETE. READ (post-U/D)
PreparedStatement addBatch() Adds the current parameters to the batch of commands. ANY (C/U/D)
  execute() Executes any SQL statement. ANY (C/R/U/D)
  executeLargeUpdate() Executes INSERT, UPDATE, DELETE, or DDL statements. C/U/D
  executeQuery() Executes a SELECT query and returns a ResultSet. READ
  executeUpdate() Executes INSERT, UPDATE, or DELETE statements. C/U/D
  getMetaData() Retrieves metadata about the ResultSet. READ
  getParameterMetaData() Retrieves metadata about parameters. READ
CallableStatement execute() Executes a stored procedure. ANY (C/R/U/D)
  executeQuery() Executes a stored procedure that returns a ResultSet. READ
  executeUpdate() Executes a stored procedure that performs INSERT, UPDATE, or DELETE. C/U/D
  getXxx(int parameterIndex) Retrieves output parameters from the stored procedure (e.g., getInt, getString). READ
  registerOutParameter(...) Registers output parameters for stored procedures. Setup (not CRUD)
  setXxx(...) Sets parameters for the SQL command (e.g., setString, setInt). Setup (not CRUD)

2. CONNECTION and TRANSACTIONAL

Class Method Description CRUD Operation Transactional Operation
Connection abort(Executor executor) Terminates an open connection. None Abort
  clearWarnings() Clears all warnings for this Connection object. None None
  close() Closes the connection and releases JDBC resources. None End Connection
  commit() Commits the current transaction, making all changes permanent. Commit (Post-C/U/D) Commit
  createArrayOf(String typeName, Object[] elements) Creates an Array object. CREATE None
  createBlob() Creates a Blob object. CREATE None
  createClob() Creates a Clob object. CREATE None
  createNClob() Creates an NClob object. CREATE None
  createSQLXML() Creates an SQLXML object. CREATE None
  createStatement() Creates a Statement object for executing SQL. None (Setup) None
  createStatement(int, int) Creates a Statement with specified ResultSet type and concurrency. None (Setup) None
  createStatement(int, int, int) Creates a Statement with specified type, concurrency, and holdability. None (Setup) None
  createStruct(String typeName, Object[] attributes) Creates a Struct object. CREATE None
  getAutoCommit() Retrieves the current auto-commit mode. None Transaction Mode Inquiry
  getCatalog() Retrieves the current catalog name. None None
  getClientInfo() Retrieves client info properties. None None
  getClientInfo(String name) Retrieves a specific client info property. None None
  getHoldability() Retrieves the current ResultSet holdability. None None
  getMetaData() Retrieves database metadata. READ None
  getNetworkTimeout() Retrieves the network timeout setting. None None
  getSchema() Retrieves the current schema. None None
  getTransactionIsolation() Retrieves the transaction isolation level. None Transaction Mode Inquiry
  getTypeMap() Retrieves the type map for this connection. None None
  getWarnings() Retrieves the first warning reported on this Connection. None None
  isClosed() Checks if the connection is closed. None Connection Status Inquiry
  isReadOnly() Checks if the connection is in read-only mode. None Transaction Mode Inquiry
  isValid(int timeout) Checks if the connection is valid. None Connection Status Inquiry
  nativeSQL(String sql) Converts SQL to the system's native SQL grammar. None None
  prepareCall(String sql) Prepares a callable statement for stored procedures. None (Setup) None
  prepareCall(String sql, int, int) Prepares a callable statement with specified ResultSet type and concurrency. None (Setup) None
  prepareCall(String sql, int, int, int) Prepares a callable statement with specified type, concurrency, and holdability. None (Setup) None
  prepareStatement(String sql) Prepares a parameterized SQL statement. None (Setup) None
  prepareStatement(String sql, int autoGeneratedKeys) Prepares a statement capable of returning auto-generated keys. None (Setup) None
  prepareStatement(String sql, int[] columnIndexes) Prepares a statement capable of returning specified columns' auto-generated keys. None (Setup) None
  prepareStatement(String sql, int, int) Prepares a statement with specified ResultSet type and concurrency. None (Setup) None
  prepareStatement(String sql, int, int, int) Prepares a statement with specified type, concurrency, and holdability. None (Setup) None
  prepareStatement(String sql, String[] columnNames) Prepares a statement capable of returning specified columns' auto-generated keys. None (Setup) None
  releaseSavepoint(Savepoint savepoint) Releases a specified savepoint. None Savepoint Management
  rollback() Rolls back all changes made in the current transaction. Rollback (Undo C/U/D) Rollback
  rollback(Savepoint savepoint) Rolls back changes to the specified savepoint. Rollback (Undo C/U/D) Rollback (to Savepoint)
  setAutoCommit(boolean autoCommit) Sets the auto-commit mode. None Transaction Mode Setting
  setCatalog(String catalog) Sets the catalog name for the connection. None None
  setClientInfo(Properties properties) Sets client info properties. None None
  setClientInfo(String name, String value) Sets a specific client info property. None None
  setHoldability(int holdability) Sets the default holdability for ResultSet objects. None None
  setNetworkTimeout(Executor executor, int ms) Sets the maximum period to wait for a database response. None None
  setReadOnly(boolean readOnly) Puts the connection in read-only mode. None Transaction Mode Setting
  setSavepoint() Creates an unnamed savepoint in the current transaction. None (Setup) Savepoint Management
  setSavepoint(String name) Creates a named savepoint in the current transaction. None (Setup) Savepoint Management
  setSchema(String schema) Sets the current schema name. None None
  setTransactionIsolation(int level) Sets the transaction isolation level. None Transaction Mode Setting
  setTypeMap(Map<String, Class<?>> map) Sets the type map for custom mapping of SQL types to Java objects. None None

3. ResultSet

Class Method Description CRUD Operation Transactional Operation
ResultSet next() Moves the cursor forward one row from its current position. READ Cursor Movement
  previous() Moves the cursor to the previous row. READ Cursor Movement
  first() Moves the cursor to the first row. READ Cursor Movement
  last() Moves the cursor to the last row. READ Cursor Movement
  absolute(int row) Moves the cursor to the specified row number. READ Cursor Movement
  relative(int rows) Moves the cursor relative to its current position. READ Cursor Movement
  beforeFirst() Positions the cursor before the first row. READ Cursor Movement
  afterLast() Positions the cursor after the last row. READ Cursor Movement
  getXxx(int columnIndex) Retrieves the value of the specified column (e.g., getString, getInt). READ  
  getXxx(String columnLabel) Retrieves the value of the specified column by name. READ  
  updateXxx(int columnIndex, value) Updates the specified column in the current row with the given value. UPDATE  
  updateXxx(String columnLabel, value) Updates the specified column by name in the current row with the given value. UPDATE  
  updateRow() Updates the current row in the database. UPDATE  
  deleteRow() Deletes the current row from the database. DELETE  
  insertRow() Inserts the current row into the database. CREATE  
  moveToInsertRow() Moves the cursor to the insert row for adding a new row. CREATE Cursor Movement (Insert Mode)
  moveToCurrentRow() Moves the cursor back to the current row from the insert row. READ Cursor Movement
  cancelRowUpdates() Cancels updates made to the current row.   Rollback (Row Level)
  refreshRow() Refreshes the current row with the latest data from the database. READ/UPDATE  
  rowInserted() Checks if the current row has been inserted. READ  
  rowUpdated() Checks if the current row has been updated. READ  
  rowDeleted() Checks if the current row has been deleted. READ  
  isBeforeFirst() Checks if the cursor is before the first row. READ Cursor State Inquiry
  isAfterLast() Checks if the cursor is after the last row. READ Cursor State Inquiry
  isFirst() Checks if the cursor is on the first row. READ Cursor State Inquiry
  isLast() Checks if the cursor is on the last row. READ Cursor State Inquiry
  getRow() Retrieves the current row number. READ Cursor State Inquiry

4. CachedRowSet, FilteredRowSet, JdbcRowSet, JoinRowSet, RowSet, SyncResolver, WebRowSet

Class Method Description CRUD Operation Transactional Operation
RowSet execute() Populates the RowSet with data. READ
CachedRowSet acceptChanges() Accepts changes made to the RowSet and commits them to the database. UPDATE/CREATE/DELETE Commit (Row Level)
restoreOriginal() Reverts the RowSet to its original state before modifications. Rollback Rollback (Row Level)
FilteredRowSet setFilter(Predicate predicate) Applies a filter to the rows in the RowSet. READ
JoinRowSet addRowSet(RowSet rowset) Adds a RowSet to be joined. READ
setJoinType(int joinType) Specifies the type of SQL join (e.g., INNER JOIN, LEFT JOIN). READ
SyncResolver getConflictValue(int columnIndex) Retrieves the value causing a conflict during synchronization. READ Conflict Resolution
setResolvedValue(int columnIndex, Object value) Resolves a conflict by setting a new value for the conflicting column. UPDATE Conflict Resolution
WebRowSet writeXml(Writer writer) Writes the WebRowSet data to XML format. READ
readXml(Reader reader) Reads XML data into the WebRowSet. READ

Describe alternatives you've considered

Same as #100

Additional context

@Data
@NoArgsConstructor
@AllArgsConstructor
public class TransactionOperation {
    private int lineNumber = -1;
    private TransactionOperationType operationType;

    @NotImplemented
    private String savepointName;
    
    @NotImplemented
    private String transactionIsolationLevel;
    
    @NotImplemented
    private boolean autoCommitEnabled;
}
package com.ibm.cldk.javaee.utils.enums;

public enum TransactionOperationType {
    COMMIT,
    ROLLBACK,
    SAVEPOINT,
    SET_AUTOCOMMIT,
    SET_ISOLATION_LEVEL,
    ABORT,
    OTHER;
}

References

@rahlk rahlk added the enhancement New feature or request label Feb 9, 2025
@rahlk rahlk self-assigned this Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant