Java Code Examples for org.springframework.jdbc.core.JdbcTemplate#queryForInt()

The following examples show how to use org.springframework.jdbc.core.JdbcTemplate#queryForInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Schema38.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
@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)");
    }

    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.");
    }
}
 
Example 2
Source File: StatisticsCache.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method will be called by CacheHelper and is synchronized via getData();
 */
protected void refresh()
{
  log.info("Initializing StatisticsCache ...");
  numberOfEntitiesMap = new HashMap<Class< ? extends BaseDO< ? >>, Integer>();
  final JdbcTemplate jdbc = new JdbcTemplate(dataSource);
  for (final RegistryEntry registryEntry : Registry.instance().getOrderedList()) {
    try {
      final int number = jdbc.queryForInt("SELECT COUNT(*) FROM " + HibernateUtils.getDBTableName(registryEntry.getDOClass()));
      numberOfEntitiesMap.put(registryEntry.getDOClass(), number);
    } catch (final Exception ex) {
      log.error(ex.getMessage(), ex);
      continue;
    }
  }
  log.info("Initializing of StatisticsCache done.");
}
 
Example 3
Source File: TAtomDataSourceTest.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitTAtomDataSource_初始化() throws Exception {
    String appName = "tddl_sample";
    String dbKey = "tddl_sample_0";
    // Oracle测试
    // TAtomDataSource tAtomDataSource = createTAtomDataSource(appName,
    // dbKey, "oracle");
    // JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    // int actual = jtp.queryForInt(TAtomDataSourceUnitTest.TEST_SQL);
    // Assert.assertEquals(actual, 1);
    // tAtomDataSource.destroyDataSource();
    // mysql测试
    TAtomDataSource tAtomDataSource = createTAtomDataSource(appName, dbKey, "mysql");
    JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    int actual = jtp.queryForInt(TAtomDataSourceTest.TEST_SQL);
    Assert.assertEquals(actual, 1);
    tAtomDataSource.destroyDataSource();
}
 
Example 4
Source File: TAtomDataSourceTest.java    From tddl with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitTAtomDataSource_初始化() throws Exception {
    String appName = "tddl_sample";
    String dbKey = "tddl_sample_0";
    // Oracle测试
    // TAtomDataSource tAtomDataSource = createTAtomDataSource(appName,
    // dbKey, "oracle");
    // JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    // int actual = jtp.queryForInt(TAtomDataSourceUnitTest.TEST_SQL);
    // Assert.assertEquals(actual, 1);
    // tAtomDataSource.destroyDataSource();
    // mysql测试
    TAtomDataSource tAtomDataSource = createTAtomDataSource(appName, dbKey, "mysql");
    JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    int actual = jtp.queryForInt(TAtomDataSourceTest.TEST_SQL);
    Assert.assertEquals(actual, 1);
    tAtomDataSource.destroyDataSource();
}
 
Example 5
Source File: Schema31.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
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)");
        }

        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.");
        }
    }
 
Example 6
Source File: StaticTAtomDataSourceTest.java    From tddl with Apache License 2.0 6 votes vote down vote up
@Test
public void createStaticTAtomDataSource() throws Exception {
    StaticTAtomDataSource dataSource = new StaticTAtomDataSource();
    dataSource.setIp("10.232.31.154");
    dataSource.setPort("3306");
    dataSource.setDbName("test");
    dataSource.setDbType("mysql");
    dataSource.setUserName("tddl");
    dataSource.setPasswd("tddl");
    dataSource.setMinPoolSize(1);
    dataSource.setMaxPoolSize(2);
    // 初始化
    dataSource.init();
    JdbcTemplate jtp = new JdbcTemplate();
    jtp.setDataSource(dataSource);
    int actual = jtp.queryForInt("select 1 from dual");
    Assert.assertEquals(actual, 1);
    dataSource.destroyDataSource();
}
 
Example 7
Source File: Schema35.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
private void createAvatar(JdbcTemplate template, String avatar) {
    if (template.queryForInt("select count(*) from system_avatar where name = ?", new Object[]{avatar}) == 0) {

        InputStream in = null;
        try {
            in = getClass().getResourceAsStream("/net/sourceforge/subsonic/dao/schema/" + avatar + ".png");
            byte[] imageData = IOUtils.toByteArray(in);
            template.update("insert into system_avatar values (null, ?, ?, ?, ?, ?, ?)",
                            new Object[]{avatar, new Date(), "image/png", 48, 48, imageData});
            LOG.info("Created avatar '" + avatar + "'.");
        } catch (IOException x) {
            LOG.error("Failed to create avatar '" + avatar + "'.", x);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
}
 
Example 8
Source File: Schema51.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(JdbcTemplate template) {

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

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

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

    if (!columnExists(template, "view_as_list", "user_settings")) {
        LOG.info("Database column 'user_settings.view_as_list' not found.  Creating it.");
        template.execute("alter table user_settings add view_as_list boolean default false not null");
        LOG.info("Database column 'user_settings.view_as_list' was added successfully.");
    }
}
 
Example 9
Source File: ToDoDao.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called by ToDoCache to get the number of open entries for the given users.
 * @param userId
 * @return Number of open to-do entries.
 */
int internalGetOpenEntries(final Integer userId)
{
  final JdbcTemplate jdbc = new JdbcTemplate(dataSource);
  try {
    return jdbc.queryForInt("SELECT COUNT(*) FROM "
        + table.getName()
        + " where assignee_fk="
        + userId
        + " and recent=true and deleted=false");
  } catch (final Exception ex) {
    log.error(ex.getMessage(), ex);
    return 0;
  }
}
 
Example 10
Source File: Schema50.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(JdbcTemplate template) {

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

        template.execute("insert into transcoding2(name, source_formats, target_format, step1, default_active) values('mkv video', " +
                "'avi mpg mpeg mp4 m4v mkv mov wmv ogv divx m2ts', 'mkv', " +
                "'ffmpeg -ss %o -i %s -c:v libx264 -preset superfast -b:v %bk -c:a libvorbis -f matroska -threads 0 -', 'true')");

        template.execute("insert into player_transcoding2(player_id, transcoding_id) " +
                "select distinct p.id, t.id from player p, transcoding2 t where t.name='mkv video'");
        LOG.info("Added mkv transcoding.");
    }

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

    // Added in 5.0.beta2
    if (template.queryForInt("select count(*) from version where version = 23") == 0) {
        LOG.info("Updating database schema to version 23.");
        template.execute("insert into version values (23)");
        template.execute("update transcoding2 set step1='ffmpeg -i %s -map 0:0 -b:a %bk -v 0 -f mp3 -' where name='mp3 audio'");
    }
}
 
Example 11
Source File: SystemInfoCache.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
private boolean hasTableEntries(final JdbcTemplate jdbc, final Class< ? > entity)
{
  try {
    final int count = jdbc.queryForInt("SELECT COUNT(*) FROM " + HibernateUtils.getDBTableName(entity));
    return count > 0;
  } catch (final Exception ex) {
    log.error(ex.getMessage(), ex);
    return false;
  }
}
 
Example 12
Source File: LoginDefaultHandler.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
public boolean isAdminUser(final PFUserDO user)
{
  final JdbcTemplate jdbc = new JdbcTemplate(dataSource);
  String sql = "select pk from t_group where name=?";
  final int adminGroupId = jdbc.queryForInt(sql, new Object[] { ProjectForgeGroup.ADMIN_GROUP.getKey()});
  sql = "select count(*) from t_group_user where group_id=? and user_id=?";
  final int count = jdbc.queryForInt(sql, new Object[] { adminGroupId, user.getId()});
  if (count != 1) {
    log.info("Admin login for maintenance (data-base update) failed for user '"
        + user.getUsername()
        + "' (user not member of admin group).");
    return false;
  }
  return true;
}
 
Example 13
Source File: ShardJdbcTemplate.java    From compass with Apache License 2.0 5 votes vote down vote up
@Override
public Integer call() throws Exception {
	JdbcTemplate jdbcTemplate = createJdbcTemplate(shard.getTargetDataSource(), ShardJdbcTemplate.this);
       String interceptedSql = shardDataSource.getSqlInterceptor().intercept(sql, shard.getTableContext());
       StringBuilder countIt = new StringBuilder()
       			.append("select count(*) from (")
                   .append(interceptedSql)
                   .append(") t");
       Integer rowCount = jdbcTemplate.queryForInt(countIt.toString(), args);

       return rowCount;
}
 
Example 14
Source File: Schema37.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(JdbcTemplate template) {

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

    if (template.queryForInt("select count(*) from role where id = 9") == 0) {
        LOG.info("Role 'settings' not found in database. Creating it.");
        template.execute("insert into role values (9, 'settings')");
        template.execute("insert into user_role select distinct u.username, 9 from user u");
        LOG.info("Role 'settings' was created successfully.");
    }

    if (template.queryForInt("select count(*) from role where id = 10") == 0) {
        LOG.info("Role 'jukebox' not found in database. Creating it.");
        template.execute("insert into role values (10, 'jukebox')");
        template.execute("insert into user_role " +
                         "select distinct u.username, 10 from user u, user_role ur " +
                         "where u.username = ur.username and ur.role_id = 1");
        LOG.info("Role 'jukebox' was created successfully.");
    }

    if (!columnExists(template, "changed", "music_folder")) {
        LOG.info("Database column 'music_folder.changed' not found.  Creating it.");
        template.execute("alter table music_folder add changed datetime default 0 not null");
        LOG.info("Database column 'music_folder.changed' was added successfully.");
    }

    if (!columnExists(template, "changed", "internet_radio")) {
        LOG.info("Database column 'internet_radio.changed' not found.  Creating it.");
        template.execute("alter table internet_radio add changed datetime default 0 not null");
        LOG.info("Database column 'internet_radio.changed' was added successfully.");
    }

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

}
 
Example 15
Source File: Schema52.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(JdbcTemplate template) {

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

    if (!tableExists(template, "music_folder_user")) {
        LOG.info("Database table 'music_folder_user' not found.  Creating it.");
        template.execute("create table music_folder_user (" +
                         "music_folder_id int not null," +
                         "username varchar not null, " +
                         "foreign key (username) references user(username) on delete cascade, " +
                         "foreign key (music_folder_id) references music_folder(id) on delete cascade)");
        template.execute("create index idx_music_folder_user_username on music_folder_user(username)");
        template.execute("insert into music_folder_user select music_folder.id, user.username from music_folder, user");
        LOG.info("Database table 'music_folder_user' was created successfully.");
    }

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

    if (!tableExists(template, "play_queue")) {
        LOG.info("Database table 'play_queue' not found.  Creating it.");
        template.execute("create table play_queue (" +
                         "id identity," +
                         "username varchar not null," +
                         "current int," +
                         "position_millis bigint," +
                         "changed datetime not null," +
                         "changed_by varchar not null," +
                         "foreign key (username) references user(username) on delete cascade)");
        LOG.info("Database table 'play_queue' was created successfully.");
    }

    if (!tableExists(template, "play_queue_file")) {
        LOG.info("Database table 'play_queue_file' not found.  Creating it.");
        template.execute("create cached table play_queue_file (" +
                         "id identity," +
                         "play_queue_id int not null," +
                         "media_file_id int not null," +
                         "foreign key (play_queue_id) references play_queue(id) on delete cascade," +
                         "foreign key (media_file_id) references media_file(id) on delete cascade)");

        LOG.info("Database table 'play_queue_file' was created successfully.");
    }
}
 
Example 16
Source File: TAtomDataSourceTest.java    From tddl5 with Apache License 2.0 4 votes vote down vote up
private void testChangePasswd(ChangeTestConfig change, ChangeTestConfig restore, String dbType) throws IOException,
                                                                                               TddlException,
                                                                                               Exception {
    String appName = "tddl_sample";
    String dbKey = "unitTestDb-" + dbType;
    String configName = "";
    String testSql = TAtomDataSourceTest.TEST_SQL;
    configName = dbType;
    TAtomDataSource tAtomDataSource = createTAtomDataSource(appName, dbKey, configName);
    JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    int actual = jtp.queryForInt(testSql);
    Assert.assertEquals(actual, 1);
    // 设置错误的IP进行推送
    // 全局配置
    String globaStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/globa.properties");
    MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(dbKey), globaStr);
    // 应用配置
    String appStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/app.properties");
    MockServer.setConfigInfo(TAtomConstants.getAppDataId(appName, dbKey), appStr);
    // 解析配置
    TAtomDsConfDO tAtomDsConfDO = TAtomConfParser.parserTAtomDsConfDO(globaStr, appStr);
    Properties passwdProp = PropLoadTestUtil.loadPropFromFile("conf/" + configName + "/passwd.properties");
    String passwdDataId = TAtomConstants.getPasswdDataId(tAtomDsConfDO.getDbName(),
        tAtomDsConfDO.getDbType(),
        tAtomDsConfDO.getUserName());
    MockServer.setConfigInfo(passwdDataId, PropLoadTestUtil.convertProp2Str(change.doChange(passwdProp)));
    Thread.sleep(3000);
    // 期待出现错误
    boolean result = false;
    try {
        actual = jtp.queryForInt(testSql);
    } catch (Throwable e) {
        result = true;
    }
    Assert.assertTrue(result);
    MockServer.setConfigInfo(passwdDataId,
        PropLoadTestUtil.convertProp2Str(restore.doChange(PropLoadTestUtil.loadPropFromFile("conf/" + configName
                                                                                            + "/passwd.properties"))));
    Thread.sleep(3000);
    // 期待结果正常
    actual = jtp.queryForInt(testSql);
    Assert.assertEquals(actual, 1);
    tAtomDataSource.destroyDataSource();

}
 
Example 17
Source File: Schema32.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
public void execute(JdbcTemplate template) {

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

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

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

        if (!tableExists(template, "podcast_channel")) {
            LOG.info("Database table 'podcast_channel' not found.  Creating it.");
            template.execute("create table podcast_channel (" +
                             "id identity," +
                             "url varchar not null," +
                             "title varchar," +
                             "description varchar," +
                             "status varchar not null," +
                             "error_message varchar)");
            LOG.info("Database table 'podcast_channel' was created successfully.");
        }

        if (!tableExists(template, "podcast_episode")) {
            LOG.info("Database table 'podcast_episode' not found.  Creating it.");
            template.execute("create table podcast_episode (" +
                             "id identity," +
                             "channel_id int not null," +
                             "url varchar not null," +
                             "path varchar," +
                             "title varchar," +
                             "description varchar," +
                             "publish_date datetime," +
                             "duration varchar," +
                             "bytes_total bigint," +
                             "bytes_downloaded bigint," +
                             "status varchar not null," +
                             "error_message varchar," +
                             "foreign key (channel_id) references podcast_channel(id) on delete cascade)");
            LOG.info("Database table 'podcast_episode' was created successfully.");
        }

        if (template.queryForInt("select count(*) from role where id = 7") == 0) {
            LOG.info("Role 'podcast' not found in database. Creating it.");
            template.execute("insert into role values (7, 'podcast')");
            template.execute("insert into user_role " +
                             "select distinct u.username, 7 from user u, user_role ur " +
                             "where u.username = ur.username and ur.role_id = 1");
            LOG.info("Role 'podcast' was created successfully.");
        }

    }
 
Example 18
Source File: Schema45.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(JdbcTemplate template) {

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

    if (template.queryForInt("select count(*) from role where id = 11") == 0) {
        LOG.info("Role 'share' not found in database. Creating it.");
        template.execute("insert into role values (11, 'share')");
        template.execute("insert into user_role " +
                         "select distinct u.username, 11 from user u, user_role ur " +
                         "where u.username = ur.username and ur.role_id = 1");
        LOG.info("Role 'share' was created successfully.");
    }

    if (!tableExists(template, "share")) {
        LOG.info("Table 'share' not found in database. Creating it.");
        template.execute("create cached table share (" +
                "id identity," +
                "name varchar not null," +
                "description varchar," +
                "username varchar not null," +
                "created datetime not null," +
                "expires datetime," +
                "last_visited datetime," +
                "visit_count int default 0 not null," +
                "unique (name)," +
                "foreign key (username) references user(username) on delete cascade)");
        template.execute("create index idx_share_name on share(name)");

        LOG.info("Table 'share' was created successfully.");
        LOG.info("Table 'share_file' not found in database. Creating it.");
        template.execute("create cached table share_file (" +
                "id identity," +
                "share_id int not null," +
                "path varchar not null," +
                "foreign key (share_id) references share(id) on delete cascade)");
        LOG.info("Table 'share_file' was created successfully.");
    }
}
 
Example 19
Source File: Schema53.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(JdbcTemplate template) {

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

    if (!rowExists(template, "table_name='PODCAST_EPISODE' and column_name='URL' and ordinal_position=1",
                   "information_schema.system_indexinfo")) {
        template.execute("create index idx_podcast_episode_url on podcast_episode(url)");
        LOG.info("Created index for podcast_episode.url");
    }

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

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

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

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

    if (!columnExists(template, "folder_id", "artist")) {
        LOG.info("Database column 'artist.folder_id' not found.  Creating it.");
        template.execute("alter table artist add folder_id int");
        LOG.info("Database column 'artist.folder_id' was added successfully.");
    }
}
 
Example 20
Source File: Schema46.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(JdbcTemplate template) {

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

    if (!tableExists(template, "transcoding2")) {
        LOG.info("Database table 'transcoding2' not found.  Creating it.");
        template.execute("create table transcoding2 (" +
                         "id identity," +
                         "name varchar not null," +
                         "source_formats varchar not null," +
                         "target_format varchar not null," +
                         "step1 varchar not null," +
                         "step2 varchar," +
                         "step3 varchar)");

        template.execute("insert into transcoding2(name, source_formats, target_format, step1) values('mp3 audio'," +
                "'ogg oga aac m4a flac wav wma aif aiff ape mpc shn', 'mp3', " +
                "'ffmpeg -i %s -ab %bk -v 0 -f mp3 -')");

        template.execute("insert into transcoding2(name, source_formats, target_format, step1) values('flv/h264 video', " +
                "'avi mpg mpeg mp4 m4v mkv mov wmv ogv divx m2ts', 'flv', " +
                "'ffmpeg -ss %o -i %s -async 1 -b %bk -s %wx%h -ar 44100 -ac 2 -v 0 -f flv -vcodec libx264 -preset superfast -threads 0 -')");

        LOG.info("Database table 'transcoding2' was created successfully.");
    }

    if (!tableExists(template, "player_transcoding2")) {
        LOG.info("Database table 'player_transcoding2' not found.  Creating it.");
        template.execute("create table player_transcoding2 (" +
                         "player_id int not null," +
                         "transcoding_id int not null," +
                         "primary key (player_id, transcoding_id)," +
                         "foreign key (player_id) references player(id) on delete cascade," +
                         "foreign key (transcoding_id) references transcoding2(id) on delete cascade)");

        template.execute("insert into player_transcoding2(player_id, transcoding_id) " +
                "select distinct p.id, t.id from player p, transcoding2 t");

        LOG.info("Database table 'player_transcoding2' was created successfully.");
    }

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