The JDBC standard is inherently oriented towards relational databases and SQL queries. However, Polypheny extends beyond these limitations, supporting multiple data models and languages. To accommodate this, the JDBC standard has been extended in a feature known as the Multimodel Extension which goes beyond what is traditionally available through JDBC.
Supported Data Models
The Multimodel Extension of the Polypheny JDBC Driver is designed to accommodate a diverse range of data models. Specifically, it supports the Relational model the Labeled Property Graph model (LPG) and the Document model. This allows Java applications to interact with all datamodels currently supported by Polypheny using a single driver.
Supported Query Languages
The Polypheny JDBC Driver officially supports the following query languages. While other query languages support by Polypheny might work as well, they are not test for compatibility.
Query Language | Name used for the languageName parameter |
---|---|
SQL | sql |
MongoDB Query Language | mql |
When using the execute
method, the languageName
parameter should needs to be set to one of these strings.
Unwrapping for Multi-Model Support
To access the features of the Multimodel Extension, the JDBC Connection
object must be unwrapped to a PolyConnection
object, which provides Polypheny-specific features. Specifically, you can use the createPolyStatement
method to generate a statement object aligned with the Multimodel Extension.
For detailed documentation on the PolyStatement object please refer to the corresponding documentation.
Usage:
try (
Connection connection = DriverManager.getConnection("jdbc:polypheny://localhost:20590");
) {
if (connection.isWrapperFor(PolyConnection.class)) {
PolyConnection polyConnection = connection.unwrap(PolyConnection.class);
PolyStatement polyStatement = polyConnection.createPolyStatement();
// You can now use polyStatement to execute multi-model queries...
}
} catch (SQLException e) {
e.printStackTrace();
}
Executing an MQL Query
The PolyStatement yeld by the unwrapping process above can now be used to execute statements in any of the supported languages. An example for the MongoDB Query Language (MQL) is given below.
For detailed documentation on the PolyStatement object please refer to the corresponding documentation.
Imagine a collection of documents, each storing information about a specific type of item stored at a warehouse. To retrieve all items currently in stock and print them to system.out we can use the code below.
Result result = polyConnection.execute("public", "mql", "db.products.find({ inStock: true })");
if (result.getResultType = ResultType.DOCUMENT) {
DocumentResult documentResult = result.unwrap(DocumentResult.class);
Iterator<PolyDocument> documentIterator = documentResult.iterator();
while (documentIterator.hasNext()) {
PolyDocument polyDocument = documentIterator.next();
// print the field "product_name" of all retrieved documents
System.out.println(polyDocument.get(new PolyString("product_name")))
}
}
Executing an SQL Statement
The PolyStatement yeld by the unwrapping process can now be used to execute statements in any of the supported languages. An example for SQL is given below.
For detailed documentation on the PolyStatement object please refer to the corresponding documentation.
Imagine a table contianing information about items stored in a warehouse. To retrieve all items currently in stock we can use the code below:
Result result = polyConnection.execute("public", "sql", "SELECT * FROM emps");
if (result.getResultType = ResultType.RELATIONAL) {
RelationalResult relationalResult = result.unwrap(RelationalResult.class);
Iterator<PolyRow> rowIterator = relationalResult.iterator();
while (rowIterator.hasNext()) {
PolyRow row = rowIterator.next();
System.out.println(row.get(1))
}
}