Skip to content

Commit

Permalink
Update Cassandra DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
pawankashyapollion committed Jan 8, 2025
1 parent d97d421 commit 9e61826
Showing 1 changed file with 0 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,4 @@ public void write(DMLGeneratorResponse dmlGeneratorResponse) throws Exception {
session.execute(boundStatement);
}
}

/**
* Reads metadata for the specified Cassandra keyspace.
*
* <p>This method retrieves metadata from the Cassandra system schema, including table names,
* column names, column types, and kinds, for the given keyspace. It uses a prepared statement for
* safe and efficient execution.
*
* @param keyspace The name of the Cassandra keyspace for which metadata is to be retrieved. Must
* not be {@code null} or empty.
* @return A {@link ResultSet} containing the metadata rows with columns:
* <ul>
* <li>{@code table_name} - The name of the table.
* <li>{@code column_name} - The name of the column.
* <li>{@code type} - The data type of the column.
* <li>{@code kind} - The column kind (e.g., partition_key, clustering).
* </ul>
*
* @throws IllegalArgumentException If the provided keyspace name is {@code null} or empty.
* @throws ConnectionException If a connection to the Cassandra database could not be established.
* @throws Exception If any other unexpected error occurs during the operation.
*/
public ResultSet readMetadata(String keyspace) throws Exception {
if (keyspace == null || keyspace.isEmpty()) {
throw new IllegalArgumentException("Keyspace name cannot be null or empty.");
}

String query =
"SELECT table_name, column_name, type, kind FROM system_schema.columns WHERE keyspace_name = ?";

try (CqlSession session = (CqlSession) connectionHelper.getConnection(this.cassandraUrl)) {
if (session == null) {
throw new ConnectionException("Failed to establish a connection.");
}

PreparedStatement preparedStatement = session.prepare(query);
BoundStatement boundStatement = preparedStatement.bind(keyspace);
return session.execute(boundStatement);
}
}
}

0 comments on commit 9e61826

Please sign in to comment.