Search in sources :

Example 61 with NamedParameterJdbcTemplate

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));
        }
    });
}
Also used : AbstractLobCreatingPreparedStatementCallback(org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) DefaultLobHandler(org.springframework.jdbc.support.lob.DefaultLobHandler) PreparedStatement(java.sql.PreparedStatement) LobHandler(org.springframework.jdbc.support.lob.LobHandler) DefaultLobHandler(org.springframework.jdbc.support.lob.DefaultLobHandler) LobCreator(org.springframework.jdbc.support.lob.LobCreator)

Example 62 with NamedParameterJdbcTemplate

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));
        }
    }
}
Also used : ExtensionService(alfio.extension.ExtensionService) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DataSource(javax.sql.DataSource) Extension(alfio.extension.Extension) ExtensionRepository(alfio.repository.ExtensionRepository) ExtensionLogRepository(alfio.repository.ExtensionLogRepository) ExternalConfiguration(alfio.manager.system.ExternalConfiguration) ScriptingExecutionService(alfio.extension.ScriptingExecutionService) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager)

Example 63 with NamedParameterJdbcTemplate

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;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) DataSource(javax.sql.DataSource)

Example 64 with NamedParameterJdbcTemplate

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;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) NotSupportException(com.kyj.fx.voeditor.visual.exceptions.NotSupportException)

Example 65 with NamedParameterJdbcTemplate

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);
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) HashMap(java.util.HashMap)

Aggregations

NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)119 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)66 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)42 HashMap (java.util.HashMap)30 ResultSet (java.sql.ResultSet)16 SQLException (java.sql.SQLException)16 DbXref (org.nextprot.api.core.domain.DbXref)8 NextProtException (org.nextprot.api.commons.exception.NextProtException)7 PublicationDbXref (org.nextprot.api.core.domain.PublicationDbXref)7 ArrayList (java.util.ArrayList)5 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)5 List (java.util.List)4 Map (java.util.Map)4 CvTerm (org.nextprot.api.core.domain.CvTerm)4 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)3 NotSupportException (com.kyj.fx.voeditor.visual.exceptions.NotSupportException)3 DataSource (javax.sql.DataSource)3 UserProteinList (org.nextprot.api.user.domain.UserProteinList)3 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)2 Date (java.util.Date)2