@Transactional
@Override
public void create(final LanguageForm lang) {
KeyHolder keyHolder = new GeneratedKeyHolder();
getJdbcOperations().update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con)
throws SQLException {
String sql = "INSERT INTO "+quoteTable("language")+"(name, code, locale, " +
"directory, filename, image, sort_order, status) VALUES(?,?,?,?,?,?,?,?)";
PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, lang.getName());
ps.setString(2, lang.getCode());
ps.setString(3, lang.getLocaleAsString());
ps.setString(4, lang.getDirectory());
ps.setString(5, lang.getFilename());
ps.setString(6, lang.getImage());
ps.setInt(7, lang.getSortOrder());
ps.setInt(8, lang.getStatus());
return ps;
}
}, keyHolder);
int langId = keyHolder.getKey().intValue();
//find default language. We're going to copy text from default language to the new one.
String langCode = getJdbcOperations().queryForObject("SELECT value FROM "+quoteTable("setting")
+" WHERE "+quoteName("group")+" = 'config' AND "+quoteName("key")
+" = 'config_language' AND store_id=0", String.class);