use of nl.nn.adapterframework.jdbc.FixedQuerySender in project iaf by ibissource.
the class ConfigurationUtilsTest method mockDatabase.
private void mockDatabase() throws Exception {
// Mock a FixedQuerySender
FixedQuerySender fq = mock(FixedQuerySender.class);
doReturn(new GenericDbmsSupport()).when(fq).getDbmsSupport();
Connection conn = mock(Connection.class);
doReturn(conn).when(fq).getConnection();
// Override prepareStatement(String query) and return a mock to validate the parameters
doAnswer(new Answer<PreparedStatementMock>() {
@Override
public PreparedStatementMock answer(InvocationOnMock invocation) throws Throwable {
String query = (String) invocation.getArguments()[0];
stmt = PreparedStatementMock.newInstance(query);
return stmt;
}
}).when(conn).prepareStatement(anyString());
doReturn(fq).when(ibisContext).createBeanAutowireByName(FixedQuerySender.class);
// STUB a TransactionManager
PlatformTransactionManager ptm = new PlatformTransactionManager() {
@Override
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
return mock(TransactionStatus.class);
}
@Override
public void commit(TransactionStatus status) throws TransactionException {
// STUB
}
@Override
public void rollback(TransactionStatus status) throws TransactionException {
// STUB
}
};
doReturn(ptm).when(ibisContext).getBean("txManager", PlatformTransactionManager.class);
}
use of nl.nn.adapterframework.jdbc.FixedQuerySender in project iaf by ibissource.
the class ShowConfiguration method getConfigsFromDatabase.
private List<Map<String, Object>> getConfigsFromDatabase(String configurationName, String dataSourceName) {
List<Map<String, Object>> returnMap = new ArrayList<Map<String, Object>>();
if (StringUtils.isEmpty(dataSourceName)) {
dataSourceName = JndiDataSourceFactory.GLOBAL_DEFAULT_DATASOURCE_NAME;
if (StringUtils.isEmpty(dataSourceName)) {
return null;
}
}
FixedQuerySender qs = getIbisContext().createBeanAutowireByName(FixedQuerySender.class);
qs.setDatasourceName(dataSourceName);
qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG");
try {
qs.configure();
qs.open();
try (Connection conn = qs.getConnection()) {
String query = "SELECT NAME, VERSION, FILENAME, RUSER, ACTIVECONFIG, AUTORELOAD, CRE_TYDST FROM IBISCONFIG WHERE NAME=?";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
stmt.setString(1, configurationName);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
Map<String, Object> config = new HashMap<>();
config.put("name", rs.getString(1));
config.put("version", rs.getString(2));
config.put("filename", rs.getString(3));
config.put("user", rs.getString(4));
config.put("active", rs.getBoolean(5));
config.put("autoreload", rs.getBoolean(6));
Date creationDate = rs.getDate(7);
config.put("created", DateUtils.format(creationDate, DateUtils.FORMAT_GENERICDATETIME));
returnMap.add(config);
}
}
}
}
} catch (Exception e) {
throw new ApiException(e);
} finally {
qs.close();
}
returnMap.sort(new NameComparatorBase<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> obj1, Map<String, Object> obj2) {
String filename1 = (String) obj1.get(orderBy);
String filename2 = (String) obj2.get(orderBy);
// invert the results as we want the latest version first
return -compareNames(filename1, filename2);
}
});
return returnMap;
}
Aggregations