Example usage for org.springframework.jdbc.core JdbcTemplate JdbcTemplate

List of usage examples for org.springframework.jdbc.core JdbcTemplate JdbcTemplate

Introduction

In this page you can find the example usage for org.springframework.jdbc.core JdbcTemplate JdbcTemplate.

Prototype

public JdbcTemplate(DataSource dataSource) 

Source Link

Document

Construct a new JdbcTemplate, given a DataSource to obtain connections from.

Usage

From source file:org.smigo.plants.JdbcPlantDao.java

@Autowired
public void setDataSource(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    this.insertPlant = new SimpleJdbcInsert(dataSource).withTableName("plants").usingGeneratedKeyColumns("id")
            .usingColumns("x", "y", "year", "species_Id", "variety_Id", "user_Id");
}

From source file:com.iucosoft.eavertizare.dao.impl.FirmaDaoImpl.java

@Override
public void save(Firma firma) {
    String query = "INSERT INTO firme "
            + "(id, nume_firma, adresa, descriere, tabela_clienti, mesaj_clienti, id_configuratie)"
            + " VALUES (?, ?, ?, ?, ?, ?, ?)";

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    Object[] args = new Object[] { null, firma.getNumeFirma(), firma.getAdresaFirma(),
            firma.getDescriereFirma(), firma.getNumeFirma() + "_clienti", firma.getMesajPentruClienti(),
            firma.getConfiguratii().getId() };

    jdbcTemplate.update(query, args);//from  w  w w.ja v  a 2s  . co  m
}

From source file:com.orange.clara.cloud.cleaner.db.Cleaner.java

public void init() {
    if (!enabled) {
        LOGGER.info("DB Cleaner is disabled");
        return;/*  www  .j a v a  2  s  . co m*/
    }
    jdbcTemplate = new JdbcTemplate(dataSource);
    LOGGER.warn("DB Cleaner is ENABLED. Starting reset of database {}", dataSource);

    perfomCleanup();
}

From source file:ar.com.zauber.commons.gis.street.OptionsTestDriver.java

private JdbcTemplate makeJdbcTemplate() {
    DataSource dataSource = new DriverManagerDataSource(driver, url, user, password);
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    return jdbcTemplate;
}

From source file:ru.org.linux.user.MemoriesDao.java

@Autowired
public void setDataSource(DataSource ds) {
    jdbcTemplate = new JdbcTemplate(ds);
    insertTemplate = new SimpleJdbcInsert(ds).withTableName("memories").usingGeneratedKeyColumns("id")
            .usingColumns("userid", "topic", "watch");
}

From source file:ch.digitalfondue.npjt.query.BooleanQueriesTest.java

@Test
public void simpleQueriesTest() {
    QueryFactory qf = new QueryFactory("hsqldb", new JdbcTemplate(dataSource));

    BoolQueries bq = qf.from(BoolQueries.class);

    bq.createTable();/* w ww.  j  ava2 s.co  m*/

    bq.insertValue("KEY", true, true, true);

    BoolConf bc = bq.findByKey("KEY");

    Assert.assertTrue(bc.confBool);
    Assert.assertTrue(bc.confStr);
    Assert.assertTrue(bc.confInt);

    bq.insertValue("KEY2", false, true, false);
    BoolConf bc2 = bq.findByKey("KEY2");

    Assert.assertFalse(bc2.confBool);
    Assert.assertTrue(bc2.confStr);
    Assert.assertFalse(bc2.confInt);

    Assert.assertTrue(bq.findConfBoolByKey("KEY"));
    Assert.assertFalse(bq.findConfBoolByKey("KEY2"));

}

From source file:ch.digitalfondue.npjt.query.EnumQueriesTest.java

@Test
public void enumQueriesTest() {
    QueryFactory qf = new QueryFactory("hsqldb", new JdbcTemplate(dataSource));
    EnumQueries eq = qf.from(EnumQueries.class);

    eq.createTable();/*w w  w.  j av a 2s.  c  o m*/

    eq.insert(TestEnum.TEST);
    eq.insert(TestEnum.TEST2);

    Assert.assertEquals(TestEnum.TEST, eq.findByKey(TestEnum.TEST));
    Assert.assertEquals(TestEnum.TEST2, eq.findByKey(TestEnum.TEST2));

    Assert.assertEquals(TestEnum.TEST, eq.findContainerByKey(TestEnum.TEST).key);

    List<TestEnum> all = eq.findAll();
    Assert.assertTrue(all.contains(TestEnum.TEST));
    Assert.assertTrue(all.contains(TestEnum.TEST2));
}

From source file:gov.nih.nci.ncicb.cadsr.common.persistence.dao.jdbc.JDBCDataElementDAO.java

public Map<String, ValidValue> getPermissibleValues(Collection<String> deIdSeqs) {
    if (deIdSeqs == null || deIdSeqs.size() < 1) {
        return new HashMap<String, ValidValue>();
    }// w w  w  .j  a v  a2 s  . c om
    JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());
    String qry = "select a.*, c.DE_IDSEQ as cdeIdSeq, sbrext_common_routines.return_number(a.VALUE) display_order from PERMISSIBLE_VALUES_VIEW a, VD_PVS_VIEW b, DATA_ELEMENTS_VIEW c "
            + "where a.PV_IDSEQ=b.PV_IDSEQ and b.VD_IDSEQ=c.VD_IDSEQ and c.de_idseq in ( ";
    for (String deIdSeq : deIdSeqs) {
        qry += "'" + deIdSeq + "',";
    }
    if (qry.lastIndexOf(",") == -1) {
        qry += "'')";
    } else {
        qry = qry.substring(0, qry.length() - 1) + ")";
    }

    qry += " order by display_order, upper(a.VALUE)";

    Map<String, ValidValue> pvMap = (Map<String, ValidValue>) jdbcTemplate.query(qry, new ResultSetExtractor() {
        public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
            final Map<String, List<ValidValue>> pvMap = new HashMap<String, List<ValidValue>>();
            Map<String, List<ValidValue>> vmIdMap = new HashMap<String, List<ValidValue>>();
            while (rs.next()) {
                ValidValue vv = new ValidValueTransferObject();
                vv.setShortMeaningValue(rs.getString(2));
                vv.setShortMeaning(rs.getString(2));
                vv.setShortMeaningDescription(rs.getString(4));
                vv.setBeginDate(rs.getString(5));

                String cdeIdSeq = rs.getString("cdeIdSeq");
                List<ValidValue> vvList = null;

                if (pvMap.get(cdeIdSeq) == null) {
                    vvList = new ArrayList<ValidValue>();
                    pvMap.put(cdeIdSeq, vvList);
                } else {
                    vvList = pvMap.get(cdeIdSeq);
                }
                vvList.add(vv);
                pvMap.put(cdeIdSeq, vvList);

                String vmIdSeq = rs.getString(13);

                List<ValidValue> vmVV = null;
                if (vmIdMap.get(vmIdSeq) == null) {
                    vmVV = new ArrayList<ValidValue>();
                    vmIdMap.put(vmIdSeq, vmVV);
                } else {
                    vmVV = vmIdMap.get(vmIdSeq);
                }
                vmVV.add(vv);
            }

            Map<String, ValueMeaning> vms = getValueMeanings(vmIdMap.keySet());

            for (String vmId : vmIdMap.keySet()) {
                ValueMeaning vm = vms.get(vmId);
                if (vm != null) {
                    for (ValidValue valVal : vmIdMap.get(vmId)) {
                        valVal.setValueMeaning(vm);
                    }
                }
            }
            return pvMap;
        }
    });

    return pvMap;
}

From source file:org.jasig.cas.monitor.DataSourceMonitor.java

/**
 * Creates a new instance that monitors the given data source.
 *
 * @param dataSource Data source to monitor.
 *///from w  w w  . j  a v a2s  . c o  m
public DataSourceMonitor(final DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
}

From source file:com.tmg.fuse.poc.DatabaseBean.java

public void create() throws Exception {
    JdbcTemplate jdbc = new JdbcTemplate(dataSource);

    // TODO: load sql from classpath (can be tricky in OSGi)
    String sql = "CREATE TABLE account( ID INT not null primary key GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), NAME VARCHAR(100) DEFAULT NULL, XREFID INT DEFAULT NULL, CRMID INT DEFAULT NULL, PSPID INT DEFAULT NULL )";
    String sql2 = "CREATE SEQUENCE seq_xrefId START WITH 10000";
    String sql3 = "INSERT INTO account (NAME, XREFID, CRMID) VALUES ('Jon Walton',1234, 100)";
    String sql4 = "INSERT INTO account (NAME, XREFID, CRMID) VALUES ('Graeme Colman',5678, 200)";

    LOG.info("Creating table account ...");

    try {// w  w  w . j  av a 2 s  . c  o m
        jdbc.execute("drop table account");
    } catch (Throwable e) {
        // ignore
    }

    jdbc.execute(sql);
    jdbc.execute(sql2);
    jdbc.execute(sql3);
    jdbc.execute(sql4);

    LOG.info("... created table account");
}