Skip to content

Support detection of CRUD operations and queries for JDBC #112

Description

@rahlk

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:

ClassMethodDescriptionCRUD Operation
StatementaddBatch(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)
PreparedStatementaddBatch()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
CallableStatementexecute()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

ClassMethodDescriptionCRUD OperationTransactional Operation
Connectionabort(Executor executor)Terminates an open connection.NoneAbort
clearWarnings()Clears all warnings for this Connection object.NoneNone
close()Closes the connection and releases JDBC resources.NoneEnd 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.CREATENone
createBlob()Creates a Blob object.CREATENone
createClob()Creates a Clob object.CREATENone
createNClob()Creates an NClob object.CREATENone
createSQLXML()Creates an SQLXML object.CREATENone
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.CREATENone
getAutoCommit()Retrieves the current auto-commit mode.NoneTransaction Mode Inquiry
getCatalog()Retrieves the current catalog name.NoneNone
getClientInfo()Retrieves client info properties.NoneNone
getClientInfo(String name)Retrieves a specific client info property.NoneNone
getHoldability()Retrieves the current ResultSet holdability.NoneNone
getMetaData()Retrieves database metadata.READNone
getNetworkTimeout()Retrieves the network timeout setting.NoneNone
getSchema()Retrieves the current schema.NoneNone
getTransactionIsolation()Retrieves the transaction isolation level.NoneTransaction Mode Inquiry
getTypeMap()Retrieves the type map for this connection.NoneNone
getWarnings()Retrieves the first warning reported on this Connection.NoneNone
isClosed()Checks if the connection is closed.NoneConnection Status Inquiry
isReadOnly()Checks if the connection is in read-only mode.NoneTransaction Mode Inquiry
isValid(int timeout)Checks if the connection is valid.NoneConnection Status Inquiry
nativeSQL(String sql)Converts SQL to the system's native SQL grammar.NoneNone
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.NoneSavepoint 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.NoneTransaction Mode Setting
setCatalog(String catalog)Sets the catalog name for the connection.NoneNone
setClientInfo(Properties properties)Sets client info properties.NoneNone
setClientInfo(String name, String value)Sets a specific client info property.NoneNone
setHoldability(int holdability)Sets the default holdability for ResultSet objects.NoneNone
setNetworkTimeout(Executor executor, int ms)Sets the maximum period to wait for a database response.NoneNone
setReadOnly(boolean readOnly)Puts the connection in read-only mode.NoneTransaction 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.NoneNone
setTransactionIsolation(int level)Sets the transaction isolation level.NoneTransaction Mode Setting
setTypeMap(Map<String, Class<?>> map)Sets the type map for custom mapping of SQL types to Java objects.NoneNone

3. ResultSet

ClassMethodDescriptionCRUD OperationTransactional Operation
ResultSetnext()Moves the cursor forward one row from its current position.READCursor Movement
previous()Moves the cursor to the previous row.READCursor Movement
first()Moves the cursor to the first row.READCursor Movement
last()Moves the cursor to the last row.READCursor Movement
absolute(int row)Moves the cursor to the specified row number.READCursor Movement
relative(int rows)Moves the cursor relative to its current position.READCursor Movement
beforeFirst()Positions the cursor before the first row.READCursor Movement
afterLast()Positions the cursor after the last row.READCursor 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.CREATECursor Movement (Insert Mode)
moveToCurrentRow()Moves the cursor back to the current row from the insert row.READCursor 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.READCursor State Inquiry
isAfterLast()Checks if the cursor is after the last row.READCursor State Inquiry
isFirst()Checks if the cursor is on the first row.READCursor State Inquiry
isLast()Checks if the cursor is on the last row.READCursor State Inquiry
getRow()Retrieves the current row number.READCursor State Inquiry

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

ClassMethodDescriptionCRUD OperationTransactional Operation
RowSetexecute()Populates the RowSet with data.READ
CachedRowSetacceptChanges()Accepts changes made to the RowSet and commits them to the database.UPDATE/CREATE/DELETECommit (Row Level)
restoreOriginal()Reverts the RowSet to its original state before modifications.RollbackRollback (Row Level)
FilteredRowSetsetFilter(Predicate predicate)Applies a filter to the rows in the RowSet.READ
JoinRowSetaddRowSet(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
SyncResolvergetConflictValue(int columnIndex)Retrieves the value causing a conflict during synchronization.READConflict Resolution
setResolvedValue(int columnIndex, Object value)Resolves a conflict by setting a new value for the conflicting column.UPDATEConflict Resolution
WebRowSetwriteXml(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@AllArgsConstructorpublicclassTransactionOperation {
privateintlineNumber = -1;
privateTransactionOperationTypeoperationType;
@NotImplementedprivateStringsavepointName;
@NotImplementedprivateStringtransactionIsolationLevel;
@NotImplementedprivatebooleanautoCommitEnabled;
}
packagecom.ibm.cldk.javaee.utils.enums;
publicenumTransactionOperationType {
COMMIT,
ROLLBACK,
SAVEPOINT,
SET_AUTOCOMMIT,
SET_ISOLATION_LEVEL,
ABORT,
OTHER;
}

References

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions