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

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

Introduction

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

Prototype

@Override
    public void execute(final String sql) throws DataAccessException 

Source Link

Usage

From source file:net.sourceforge.subsonic.dao.schema.hsql.Schema29.java

public void execute(JdbcTemplate template) {

    if (template.queryForInt("select count(*) from version where version = 5") == 0) {
        LOG.info("Updating database schema to version 5.");
        template.execute("insert into version values (5)");
    }/* ww  w.j a  va 2 s  .  co m*/

    if (!tableExists(template, "user_rating")) {
        LOG.info("Database table 'user_rating' not found.  Creating it.");
        template.execute("create table user_rating (" + "username varchar not null," + "path varchar not null,"
                + "rating double not null," + "primary key (username, path),"
                + "foreign key (username) references user(username) on delete cascade)");
        LOG.info("Database table 'user_rating' was created successfully.");

        template.execute("insert into user_rating select 'admin', path, rating from music_file_info "
                + "where rating is not null and rating > 0");
        LOG.info("Migrated data from 'music_file_info' to 'user_rating'.");
    }
}

From source file:net.sourceforge.subsonic.dao.schema.hsql.Schema31.java

public void execute(JdbcTemplate template) {

    if (template.queryForInt("select count(*) from version where version = 7") == 0) {
        LOG.info("Updating database schema to version 7.");
        template.execute("insert into version values (7)");
    }/*  w w  w  .  ja v a2  s . co  m*/

    if (!columnExists(template, "enabled", "music_file_info")) {
        LOG.info("Database column 'music_file_info.enabled' not found.  Creating it.");
        template.execute("alter table music_file_info add enabled boolean default true not null");
        LOG.info("Database column 'music_file_info.enabled' was added successfully.");
    }

    if (!columnExists(template, "default_active", "transcoding")) {
        LOG.info("Database column 'transcoding.default_active' not found.  Creating it.");
        template.execute("alter table transcoding add default_active boolean default true not null");
        LOG.info("Database column 'transcoding.default_active' was added successfully.");
    }
}

From source file:net.sourceforge.subsonic.dao.schema.hsql.Schema34.java

public void execute(JdbcTemplate template) {

    if (template.queryForInt("select count(*) from version where version = 10") == 0) {
        LOG.info("Updating database schema to version 10.");
        template.execute("insert into version values (10)");
    }/*  www . j a va  2s . co  m*/

    if (!columnExists(template, "ldap_authenticated", "user")) {
        LOG.info("Database column 'user.ldap_authenticated' not found.  Creating it.");
        template.execute("alter table user add ldap_authenticated boolean default false not null");
        LOG.info("Database column 'user.ldap_authenticated' was added successfully.");
    }

    if (!columnExists(template, "party_mode_enabled", "user_settings")) {
        LOG.info("Database column 'user_settings.party_mode_enabled' not found.  Creating it.");
        template.execute("alter table user_settings add party_mode_enabled boolean default false not null");
        LOG.info("Database column 'user_settings.party_mode_enabled' was added successfully.");
    }
}

From source file:net.sourceforge.subsonic.dao.schema.hsql.Schema27.java

public void execute(JdbcTemplate template) {

    if (template.queryForInt("select count(*) from version where version = 3") == 0) {
        LOG.info("Updating database schema to version 3.");
        template.execute("insert into version values (3)");

        LOG.info("Converting database column 'music_file_info.path' to varchar_ignorecase.");
        template.execute("drop index idx_music_file_info_path");
        template.execute("alter table music_file_info alter column path varchar_ignorecase not null");
        template.execute("create index idx_music_file_info_path on music_file_info(path)");
        LOG.info("Database column 'music_file_info.path' was converted successfully.");
    }/*  w  w  w. j av a  2s . c o m*/

    if (!columnExists(template, "bytes_streamed", "user")) {
        LOG.info("Database columns 'user.bytes_streamed/downloaded/uploaded' not found.  Creating them.");
        template.execute("alter table user add bytes_streamed bigint default 0 not null");
        template.execute("alter table user add bytes_downloaded bigint default 0 not null");
        template.execute("alter table user add bytes_uploaded bigint default 0 not null");
        LOG.info("Database columns 'user.bytes_streamed/downloaded/uploaded' were added successfully.");
    }
}

From source file:net.sourceforge.subsonic.dao.schema.hsql.Schema38.java

@Override
public void execute(JdbcTemplate template) {

    if (template.queryForInt("select count(*) from version where version = 14") == 0) {
        LOG.info("Updating database schema to version 14.");
        template.execute("insert into version values (14)");
    }//from  w w w  . ja  va 2s. c  o m

    if (!columnExists(template, "client_id", "player")) {
        LOG.info("Database column 'player.client_id' not found.  Creating it.");
        template.execute("alter table player add client_id varchar");
        LOG.info("Database column 'player.client_id' was added successfully.");
    }

    if (!columnExists(template, "show_chat", "user_settings")) {
        LOG.info("Database column 'user_settings.show_chat' not found.  Creating it.");
        template.execute("alter table user_settings add show_chat boolean default true not null");
        LOG.info("Database column 'user_settings.show_chat' was added successfully.");
    }
}

From source file:net.sourceforge.subsonic.dao.schema.hsql.Schema30.java

public void execute(JdbcTemplate template) {

    if (template.queryForInt("select count(*) from version where version = 6") == 0) {
        LOG.info("Updating database schema to version 6.");
        template.execute("insert into version values (6)");
    }/*from   w  ww . j av  a  2  s  . c o  m*/

    if (!columnExists(template, "last_fm_enabled", "user_settings")) {
        LOG.info("Database columns 'user_settings.last_fm_*' not found.  Creating them.");
        template.execute("alter table user_settings add last_fm_enabled boolean default false not null");
        template.execute("alter table user_settings add last_fm_username varchar null");
        template.execute("alter table user_settings add last_fm_password varchar null");
        LOG.info("Database columns 'user_settings.last_fm_*' were added successfully.");
    }

    if (!columnExists(template, "transcode_scheme", "user_settings")) {
        LOG.info("Database column 'user_settings.transcode_scheme' not found.  Creating it.");
        template.execute("alter table user_settings add transcode_scheme varchar default '"
                + TranscodeScheme.OFF.name() + "' not null");
        LOG.info("Database column 'user_settings.transcode_scheme' was added successfully.");
    }
}

From source file:com.tsg.addressbookmvc.dao.AddressBookDaoTest.java

@Before
public void setUp() {

    ApplicationContext ctx = new ClassPathXmlApplicationContext("test-applicationContext.xml");
    dao = ctx.getBean("addressBookDAO", AddressBookDAO.class);

    JdbcTemplate cleaner = (JdbcTemplate) ctx.getBean("jdbcTemplate");
    cleaner.execute("delete from addresses");

    ad1 = new Address();
    ad1.setFirstName("Walt");
    ad1.setLastName("Brown");
    ad1.setAddress("1234 Dock St.");
    ad1.setCity("Akron");
    ad1.setState("Ohio");
    ad1.setZipCode("43221");

    ad2 = new Address();
    ad2.setFirstName("Mike");
    ad2.setLastName("Jones");
    ad2.setAddress("45 W 12th ave.");
    ad2.setCity("Stringtown");
    ad2.setState("Georgia");
    ad2.setZipCode("98637");

    // Create new address - same last name as first address but different
    // address/*from  ww  w . java  2 s.  c  o m*/
    ad3 = new Address();
    ad3.setFirstName("Ricky");
    ad3.setLastName("Brown");
    ad3.setAddress("3451 Roswell Dr.");
    ad3.setCity("Columbus");
    ad3.setState("Ohio");
    ad3.setZipCode("43227");
}

From source file:com.sg.capstone.dao.tests.TagDaoDbImplTests.java

@Before
public void setUp() {
    // Ask Spring for my DAO
    ApplicationContext ctx = new ClassPathXmlApplicationContext("test-applicationContext.xml");
    dao = (TagDao) ctx.getBean("TagDao");
    blogDao = (BlogDao) ctx.getBean("BlogDao");
    // Grab a JdbcTemplate to use for cleaning up
    JdbcTemplate cleaner = (JdbcTemplate) ctx.getBean("jdbcTemplate");

    cleaner.execute("truncate blogPost_tags");
    cleaner.execute("truncate blogPost");
    cleaner.execute("truncate tags");

    Tag tag1 = new Tag();
    tag1.setName("cake");

    Tag tag2 = new Tag();
    tag2.setName("space jam");

    Tag tag3 = new Tag();
    tag3.setName("cookies");

    tagsForTesting[0] = tag1;/* w  w  w  . j av  a  2  s .  c o  m*/
    tagsForTesting[1] = tag2;
    tagsForTesting[2] = tag3;

    ArrayList<Integer> categoriesForInsertion = new ArrayList<>();

    BlogPost blogPost1 = new BlogPost();
    blogPost1.setTitle("Post1");
    blogPost1.setDate("2016-12-06 21:38:31");
    blogPost1.setCategoryIds(categoriesForInsertion);

    BlogPost blogPost2 = new BlogPost();
    blogPost2.setTitle("Post2");
    blogPost2.setDate("2016-12-07 09:34:38");
    blogPost2.setCategoryIds(categoriesForInsertion);

    BlogPost blogPost3 = new BlogPost();
    blogPost3.setTitle("Post3");
    blogPost3.setDate("2016-12-01 13:36:50");
    blogPost3.setCategoryIds(categoriesForInsertion);

    blogPostsForTesting[0] = blogPost1;
    blogPostsForTesting[1] = blogPost2;
    blogPostsForTesting[2] = blogPost3;
}