if (insertMode) {
LabelValueBean beans[] = loadKeyFromProperties();
Vector<LangTranDetailForm> vector = new Vector<LangTranDetailForm>();
for (int i = 0; i < beans.length; i++) {
LanguageTranslation langTran = new LanguageTranslation();
langTran.setLangTranKey(beans[i].getLabel());
langTran.setLangTranValue("");
langTran.setLangSource(Constants.LANGUAGETRANSLATION_SOURCE_SYSTEM);
langTran.setRecCreateBy(adminBean.getUser().getUserId());
langTran.setRecCreateDatetime(new Date(System.currentTimeMillis()));
langTran.setRecUpdateBy(adminBean.getUser().getUserId());
langTran.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
langTran.setLanguage(language);
em.persist(langTran);
LangTranDetailForm detail = new LangTranDetailForm();
detail.setLangTranKey(beans[i].getLabel());
detail.setLangTranEnglish(beans[i].getValue());
detail.setLangTranValue(beans[i].getValue());
vector.add(detail);
}
LangTranDetailForm langTrans[] = new LangTranDetailForm[vector.size()];
vector.copyInto(langTrans);
form.setLangTrans(langTrans);
}
else {
String sql = "delete " +
"from LanguageTranslation languageTranslation " +
"where languageTranslation.language.langId = :langId";
Query query = em.createQuery(sql);
query.setParameter("langId", language.getLangId());
query.executeUpdate();
for (int i = 0; i < form.getLangTrans().length; i++) {
LangTranDetailForm langTranDetailForm = form.getLangTrans()[i];
LanguageTranslation langTran = new LanguageTranslation();
langTran.setLangSource(Constants.LANGUAGETRANSLATION_SOURCE_SYSTEM);
langTran.setLangTranKey(langTranDetailForm.getLangTranKey());
langTran.setRecCreateBy(adminBean.getUser().getUserId());
langTran.setRecCreateDatetime(new Date(System.currentTimeMillis()));
langTran.setLanguage(language);
if (langTranDetailForm.getLangTranValue().length() > 255) {
langTranDetailForm.setLangTranValue(langTranDetailForm.getLangTranValue().substring(0, 255 - 1));
}
langTran.setLangTranValue(langTranDetailForm.getLangTranValue());
langTran.setRecUpdateBy(adminBean.getUser().getUserId());
langTran.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
em.persist(langTran);
}
}
Languages.init();
CacheDAO.removeAll();