com.agiletec.aps.system.services.i18n.I18nDAO Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of entando-engine Show documentation
Show all versions of entando-engine Show documentation
Entando Engine: an agile, modern and user-centric open source Portal platform.
/*
* Copyright 2015-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.agiletec.aps.system.services.i18n;
import java.sql.BatchUpdateException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.agiletec.aps.system.common.AbstractDAO;
import com.agiletec.aps.system.exception.ApsSystemException;
import com.agiletec.aps.util.ApsProperties;
/**
* Data Access Object per gli oggetti label (I18n).
* @author S.Didaci- E.Santoboni
*/
public class I18nDAO extends AbstractDAO implements II18nDAO {
private static final Logger _logger = LoggerFactory.getLogger(I18nDAO.class);
/**
* Carica la mappa che contiene tutte le label in tutte le lingue.
* @return La mappa contenente tutte le label.
*/
public Map loadLabelGroups() {
Connection conn = null;
Statement stat = null;
ResultSet res = null;
Map labels = null;
try {
conn = this.getConnection();
stat = conn.createStatement();
res = stat.executeQuery(LOAD_ALL_LABELS);
labels = this.createLabels(res);
} catch (Throwable t) {
_logger.error("Error loading labels", t);
throw new RuntimeException("Error loading labels", t);
//processDaoException(t, "Error loading label", "loadLabelMap");
} finally{
closeDaoResources(res, stat, conn);
}
return labels;
}
public void updateLabelGroup(String key, ApsProperties labels) {
Connection conn = null;
try {
conn = this.getConnection();
conn.setAutoCommit(false);
this.deleteLabelGroup(key, conn);
this.addLabelGroup(key, labels, conn);
conn.commit();
} catch (Throwable t) {
this.executeRollback(conn);
_logger.error("Error while updating a label '{}'", key, t);
throw new RuntimeException("Error while updating a label", t);
//processDaoException(t, "Error while updating a label", "updateLabel");
} finally {
this.closeConnection(conn);
}
}
public void addLabelGroup(String key, ApsProperties labels) {
Connection conn = null;
try {
conn = this.getConnection();
conn.setAutoCommit(false);
this.addLabelGroup(key, labels, conn);
conn.commit();
} catch (Throwable t) {
this.executeRollback(conn);
_logger.error("Error while adding a label '{}'", key, t);
throw new RuntimeException("Error while adding a label", t);
//processDaoException(t, "Error while adding a label", "addLabelGroup");
} finally {
this.closeConnection(conn);
}
}
private void addLabelGroup(String key, ApsProperties labels, Connection conn) throws ApsSystemException {
PreparedStatement stat = null;
try {
stat = conn.prepareStatement(ADD_LABEL);
Iterator