Search in sources :

Example 1 with VersionQuery

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.VersionQuery in project elide by yahoo.

the class SQLQueryEngine method getTableVersion.

@Override
public String getTableVersion(Table table, Transaction transaction) {
    String tableVersion = null;
    SQLTable sqlTable = (SQLTable) table;
    Type<?> tableClass = metadataDictionary.getEntityClass(table.getName(), table.getVersion());
    VersionQuery versionAnnotation = tableClass.getAnnotation(VersionQuery.class);
    if (versionAnnotation != null) {
        String versionQueryString = versionAnnotation.sql();
        SqlTransaction sqlTransaction = (SqlTransaction) transaction;
        ConnectionDetails details = sqlTable.getConnectionDetails();
        DataSource dataSource = details.getDataSource();
        NamedParamPreparedStatement stmt = sqlTransaction.initializeStatement(versionQueryString, dataSource);
        tableVersion = CoerceUtil.coerce(runQuery(stmt, versionQueryString, SINGLE_RESULT_MAPPER), String.class);
    }
    return tableVersion;
}
Also used : SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) VersionQuery(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.VersionQuery) DataSource(javax.sql.DataSource)

Aggregations

VersionQuery (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.VersionQuery)1 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)1 DataSource (javax.sql.DataSource)1