The PolyStatement object in the Polypheny JDBC Multimodel Extension serves as the specialized tool for executing queries and operations across different data models and languages. Similar to the capabilities of JDBC’s native Statement objectss it allows to execute queries and retrieve their results.
execute
public Result execute(String namespaceName, String languageName, String statement)
The execute method in the Polypheny JDBC Driver allows for query execution across various namespaces and languages supported by the Polypheny database. The method returns a Result object that encapsulates the outcome of the executed query.
Parameters:
| Parameter | Type | Description |
|---|---|---|
namespaceName |
String | The namespace that exists on the queried Polypheny instance. |
languageName |
String | The query language currently loaded by the Polypheny database. Refer to the Overview page of the multi model expansion for further details on the supported languages. |
statement |
String | The query string written in the specified query language. |
Return Type:
- Returns a
Resultobject, a wrapper for different result types such asRelationalResult,DocumentResult, andGraphResult.
Exceptions:
- Throws a
SQLExceptionif a database access error occurs, an unsupported query is executed, or the method is invoked on a closed connection.
Result Types:
| Result Type | Unwrap To | Description |
|---|---|---|
Result.RELATIONAL |
RelationalResult.class |
The result contains relational data and can be unwrapped to a RelationalResult object. |
Result.DOCUMENT |
DocumentResult.class |
The result contains document-based data and can be unwrapped to a DocumentResult object. |
Result.GRAPH |
GraphResult.class |
The result contains graph-based data and can be unwrapped to a GraphResult object. |
Result.SCALAR |
ScalarResult.class |
The result contains scalar values and can be unwrapped to a ScalarResult object. |
To determine the type of the result, you can use the getResultType() method on the Result object. Once you know the type, you can unwrap the Result object to its specific class using the unwrap method as demonstrated in the usage example above.
Usage:
try (
Connection connection = DriverManager.getConnection("jdbc:polypheny://localhost:20590");
) {
if (connection.isWrapperFor(PolyConnection.class)) {
PolyConnection polyConnection = connection.unwrap(PolyConnection.class);
Result result = polyConnection.execute("public", "sql", "SELECT * FROM tableName");
switch (result.getResultType()) {
case Result.RELATIONAL:
RelationalResult relationalResult = result.unwrap(RelationalResult.class);
// Process the relational result...
break;
case Result.DOCUMENT:
DocumentResult documentResult = result.unwrap(DocumentResult.class);
// Process the document result...
break;
case Result.GRAPH:
GraphResult graphResult = result.unwrap(GraphResult.class);
// Process the graph result...
break;
case Result.SCALAR:
ScalarResult scalarResult = result.unwrap(ScalarResult.class);
// Process the scalar result...
break;
default:
// Handle other types...
}
}
} catch (SQLException e) {
e.printStackTrace();
}