Search in sources :

Example 66 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project opennms by OpenNMS.

the class TicketNotificationStrategy method getAlarmStateFromEvent.

/**
 * <p>Helper function that gets the alarmid from the eventid</p>
 *
 * @return 0 if alarmid is null
 */
protected AlarmState getAlarmStateFromEvent(int eventID) {
    AlarmStateRowCallbackHandler callbackHandler = new AlarmStateRowCallbackHandler();
    JdbcTemplate template = new JdbcTemplate(DataSourceFactory.getInstance());
    template.query("SELECT a.alarmid, a.tticketid, a.tticketstate FROM events AS e " + "LEFT JOIN alarms AS a ON a.alarmid = e.alarmid " + "WHERE e.eventid = ?", new Object[] { eventID }, callbackHandler);
    return callbackHandler.getAlarmState();
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 67 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project cas by apereo.

the class JpaLockingStrategyTests method getOwner.

private String getOwner(final String appId) {
    final JdbcTemplate simpleJdbcTemplate = new JdbcTemplate(dataSource);
    final List<Map<String, Object>> results = simpleJdbcTemplate.queryForList("SELECT unique_id FROM locks WHERE application_id=?", appId);
    if (results.isEmpty()) {
        return null;
    }
    return (String) results.get(0).get("unique_id");
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Map(java.util.Map)

Example 68 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project musiccabinet by hakko.

the class PostgreSQLUtil method loadFunction.

/**
	 * Load a named SQL function to database.
	 * 
	 * If a previous version with the same name exists, it is dropped by a call to
	 * function drop_procedure (creation of this function is part of database set-up).
	 * 
	 * @param rc			RequestContext for call
	 * @param functionName	Name of function
	 * @param functionBody	Body of function
	 * @throws ApplicationException On failure
	 */
public static void loadFunction(JdbcTemplateDao dao, PostgreSQLFunction dbFunction) throws ApplicationException {
    JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
    // initialize drop procedure, if database has been dropped
    jdbcTemplate.execute(new ResourceUtil(DROP_FUNCTION.getURI()).getContent());
    // drop previous function version, if necessary
    jdbcTemplate.queryForInt("select util.drop_function( ?,? )", dbFunction.getSchema(), dbFunction.getFunctionName());
    // load new function body
    jdbcTemplate.execute(new ResourceUtil(dbFunction.getURI()).getContent());
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 69 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.

the class SqlStoredComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String template, 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;
    }
    if (target == null) {
        // fallback and use component
        target = dataSource;
    }
    if (target == null) {
        // check if the registry contains a single instance of DataSource
        Set<DataSource> dataSources = getCamelContext().getRegistry().findByType(DataSource.class);
        if (dataSources.size() > 1) {
            throw new IllegalArgumentException("Multiple DataSources found in the registry and no explicit configuration provided");
        } else if (dataSources.size() == 1) {
            target = dataSources.stream().findFirst().orElse(null);
        }
    }
    if (target == null) {
        throw new IllegalArgumentException("DataSource must be configured");
    }
    JdbcTemplate jdbcTemplate = new JdbcTemplate(target);
    SqlStoredEndpoint endpoint = new SqlStoredEndpoint(uri, this, jdbcTemplate);
    endpoint.setTemplate(template);
    return endpoint;
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataSource(javax.sql.DataSource)

Example 70 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.

the class JdbcAggregationRepository method setDataSource.

public final void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
    jdbcTemplate = new JdbcTemplate(dataSource);
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Aggregations

JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)124 Test (org.junit.Test)46 DataSource (javax.sql.DataSource)37 Before (org.junit.Before)19 SQLException (java.sql.SQLException)11 EmbeddedDatabaseBuilder (org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder)11 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)6 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)6 DbMediaSource (com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource)6 Connection (java.sql.Connection)6 JdbcOperations (org.springframework.jdbc.core.JdbcOperations)6 TransactionStatus (org.springframework.transaction.TransactionStatus)6 Test (org.testng.annotations.Test)6 SqlTemplate (com.alibaba.otter.node.etl.common.db.dialect.SqlTemplate)5 PreparedStatement (java.sql.PreparedStatement)5 Table (org.apache.ddlutils.model.Table)5 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 DataAccessException (org.springframework.dao.DataAccessException)5 AbstractDriverBasedDataSource (org.springframework.jdbc.datasource.AbstractDriverBasedDataSource)5 TransactionCallback (org.springframework.transaction.support.TransactionCallback)5