use of org.irods.jargon.core.pub.domain.SpecificQueryDefinition in project metalnx-web by irods-contrib.
the class SpecQueryServiceImpl method searchByMetadata.
@Override
public SpecificQueryResultSet searchByMetadata(List<DataGridMetadataSearch> metadataSearch, String zone, boolean searchAgainstColls, DataGridPageContext pageContext, int offset, int limit) throws DataGridConnectionRefusedException, JargonException {
SpecificQueryAO specificQueryAO = null;
SpecificQuery specQuery = null;
SpecificQueryResultSet queryResultSet = null;
String userSQLAlias = "metalnxUserQuery_" + System.currentTimeMillis();
try {
specificQueryAO = adminServices.getSpecificQueryAO();
ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
String query = provider.buildSpecificQueryForMetadataSearch(metadataSearch, zone, searchAgainstColls);
// Creating Specific Query instance
SpecificQueryDefinition queryDef = new SpecificQueryDefinition();
queryDef.setAlias(userSQLAlias);
queryDef.setSql(query);
// Creating spec query on iRODS
specificQueryAO.addSpecificQuery(queryDef);
specQuery = SpecificQuery.instanceWithNoArguments(userSQLAlias, 0, zone);
logger.info("Specific query: {}", query.toString());
queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, 99999, 0);
} catch (JargonException e) {
logger.error("Could not get specific query: ", e);
throw e;
} catch (JargonQueryException e) {
logger.error("Could not get specific query: ", e);
throw new JargonException(e);
} catch (UnsupportedDataGridFeatureException e) {
logger.error("Could not get specific query: ", e);
throw new JargonException(e);
} finally {
try {
// after running the user specific query, we need to remove from the database
specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
} catch (JargonException e) {
logger.error("Could not remove specific query {}: ", userSQLAlias, e.getMessage());
}
}
return queryResultSet;
}
Aggregations