use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project alf.io by alfio-event.
the class FileUploadRepository method upload.
default void upload(UploadBase64FileModification file, String digest, Map<String, String> attributes) {
LobHandler lobHandler = new DefaultLobHandler();
NamedParameterJdbcTemplate jdbc = getNamedParameterJdbcTemplate();
jdbc.getJdbcOperations().execute("insert into file_blob (id, name, content_size, content, content_type, attributes) values(?, ?, ?, ?, ?, ?)", new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
@Override
protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
ps.setString(1, digest);
ps.setString(2, file.getName());
ps.setLong(3, file.getFile().length);
lobCreator.setBlobAsBytes(ps, 4, file.getFile());
ps.setString(5, file.getType());
ps.setString(6, Json.GSON.toJson(attributes));
}
});
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project alf.io by alfio-event.
the class V22_1_14_8__MigrateMailchimp method migrate.
@Override
public void migrate(Context context) throws Exception {
var jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true));
Integer enabledCount = jdbcTemplate.queryForObject("select count(*) from plugin_configuration where plugin_id = 'alfio.mailchimp' and conf_name = 'enabled' and conf_value = 'true'", Integer.class);
if (enabledCount == null || enabledCount == 0) {
return;
}
DataSource dataSource = Objects.requireNonNull(jdbcTemplate.getDataSource());
ExtensionRepository extensionRepository = QueryFactory.from(ExtensionRepository.class, "PGSQL", dataSource);
ExtensionLogRepository extensionLogRepository = QueryFactory.from(ExtensionLogRepository.class, "PGSQL", dataSource);
PluginRepository pluginRepository = QueryFactory.from(PluginRepository.class, "PGSQL", dataSource);
ExtensionService extensionService = new ExtensionService(new ScriptingExecutionService(HttpClient.newHttpClient(), null, Executors::newSingleThreadExecutor), extensionRepository, extensionLogRepository, new DataSourceTransactionManager(dataSource), new ExternalConfiguration(), new NamedParameterJdbcTemplate(jdbcTemplate));
extensionService.createOrUpdate(null, null, new Extension("-", "mailchimp", getMailChimpScript(), true));
int extensionId = extensionRepository.getExtensionIdFor("-", "mailchimp");
int apiKeyId = pluginRepository.getConfigurationMetadataIdFor(extensionId, "apiKey", "EVENT");
int listIdId = pluginRepository.getConfigurationMetadataIdFor(extensionId, "listId", "EVENT");
List<ConfValue> confValues = pluginRepository.findAllMailChimpConfigurationValues();
for (ConfValue cv : confValues) {
if (cv.value != null) {
optionally(() -> jdbcTemplate.queryForObject("select org_id from event where id = " + cv.eventId, Integer.class)).ifPresent(orgId -> extensionRepository.insertSettingValue("apiKey".equals(cv.name) ? apiKeyId : listIdId, "-" + orgId + "-" + cv.eventId, cv.value));
}
}
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project camel by apache.
the class ElsqlComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
DataSource target = null;
// endpoint options overrule component configured datasource
DataSource ds = resolveAndRemoveReferenceParameter(parameters, "dataSource", DataSource.class);
if (ds != null) {
target = ds;
}
String dataSourceRef = getAndRemoveParameter(parameters, "dataSourceRef", String.class);
if (target == null && dataSourceRef != null) {
target = CamelContextHelper.mandatoryLookup(getCamelContext(), dataSourceRef, DataSource.class);
}
if (target == null) {
// fallback and use component
target = getDataSource();
}
if (target == null) {
throw new IllegalArgumentException("DataSource must be configured");
}
NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(target);
IntrospectionSupport.setProperties(jdbcTemplate, parameters, "template.");
String elsqlName = remaining;
String resUri = resourceUri;
String[] part = remaining.split(":");
if (part.length == 2) {
elsqlName = part[0];
resUri = part[1];
} else if (part.length > 2) {
throw new IllegalArgumentException("Invalid uri. Must by elsql:elsqlName:resourceUri, was: " + uri);
}
String onConsume = getAndRemoveParameter(parameters, "consumer.onConsume", String.class);
if (onConsume == null) {
onConsume = getAndRemoveParameter(parameters, "onConsume", String.class);
}
String onConsumeFailed = getAndRemoveParameter(parameters, "consumer.onConsumeFailed", String.class);
if (onConsumeFailed == null) {
onConsumeFailed = getAndRemoveParameter(parameters, "onConsumeFailed", String.class);
}
String onConsumeBatchComplete = getAndRemoveParameter(parameters, "consumer.onConsumeBatchComplete", String.class);
if (onConsumeBatchComplete == null) {
onConsumeBatchComplete = getAndRemoveParameter(parameters, "onConsumeBatchComplete", String.class);
}
ElsqlEndpoint endpoint = new ElsqlEndpoint(uri, this, jdbcTemplate, target, elsqlName, resUri);
endpoint.setElSqlConfig(elSqlConfig);
endpoint.setDatabaseVendor(databaseVendor);
endpoint.setDataSource(target);
endpoint.setDataSourceRef(dataSourceRef);
endpoint.setOnConsume(onConsume);
endpoint.setOnConsumeFailed(onConsumeFailed);
endpoint.setOnConsumeBatchComplete(onConsumeBatchComplete);
return endpoint;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project Gargoyle by callakrsos.
the class DbUtil method select.
public static <T> List<T> select(DataSource dataSource, final String sql, Map<String, Object> paramMap, RowMapper<T> rowMapper) throws Exception {
List<T> query = null;
try {
noticeQuery(sql);
NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
// String _sql = ValueUtil.getVelocityToText(sql, paramMap);
// LOGGER.debug(_sql);
query = jdbcTemplate.query(sql, new MapSqlParameterSource(paramMap), rowMapper);
} catch (Exception e) {
throw e;
}
return query;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project bamboobsc by billchen198318.
the class CleanJasperReportTempDataForContextInitAndDestroy method clean.
private void clean() throws Exception {
NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate) AppContext.getBean("namedParameterJdbcTemplate");
Map<String, Object> paramMap = new HashMap<String, Object>();
namedParameterJdbcTemplate.update("delete from bb_swot_report_mst", paramMap);
namedParameterJdbcTemplate.update("delete from bb_swot_report_dtl", paramMap);
}
Aggregations