package fr.gouv.finances.dgfip.xemelios.batch.suivi;
-import fr.gouv.finances.dgfip.xemelios.data.impl.pool.PoolManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
+
import org.apache.log4j.Logger;
+import fr.gouv.finances.dgfip.xemelios.data.impl.pool.PoolManager;
+
/**
- *
+ *
* @author cmarchand
*/
public class Message {
- private static final Logger logger = Logger.getLogger(Message.class);
- private Traitement traitement;
- private long messageId;
- private String severity;
- private Timestamp dateMessage;
- private String message;
- private String category;
- private String infoCompl;
+ private static final Logger logger = Logger.getLogger(Message.class);
+ private final Traitement traitement;
+ private long messageId;
+ private String severity;
+ private final Timestamp dateMessage;
+ private final String message;
+ private String infoCompl;
+
+ public Message(final Traitement traitement, final String severity, final String message) {
+ super();
+ this.traitement = traitement;
+ this.severity = severity;
+ this.message = message;
+ this.dateMessage = new Timestamp(System.currentTimeMillis());
+ this.__createInDatabase();
+ }
+
+ public void setSeverity(final String newSeverity) {
+ Connection con = null;
+ try {
+ con = PoolManager.getInstance().getConnection();
+ final String sql = "update MESSAGE_TRAITEMENT set MTR_CODE_GRAVITE=? where TRT_ID=? and MTR_ID=?";
+ final PreparedStatement ps = con.prepareStatement(sql);
+ ps.setString(1, newSeverity);
+ ps.setLong(2, this.traitement.getId());
+ ps.setLong(3, this.messageId);
+ ps.executeUpdate();
+ this.severity = newSeverity;
+ this.traitement.__updateSeverity(newSeverity);
+ } catch (final Exception ex) {
+ logger.error("Message.setSeverity(String)", ex);
+ } finally {
+ if (con != null) {
+ PoolManager.getInstance().releaseConnection(con);
+ }
+ }
+ }
+
+ public String getInfoCompl() {
+ return this.infoCompl;
+ }
- public Message(final Traitement traitement, final String severity, final String message) {
- super();
- this.traitement = traitement;
- this.severity = severity;
- this.message=message;
- this.dateMessage = new Timestamp(System.currentTimeMillis());
- __createInDatabase();
- }
- public void setSeverity(String newSeverity) {
- Connection con = null;
- try {
- con = PoolManager.getInstance().getConnection();
- String sql = "update MESSAGE_TRAITEMENT set MTR_CODE_GRAVITE=? where TRT_ID=? and MTR_ID=?";
- PreparedStatement ps = con.prepareStatement(sql);
- ps.setString(1, newSeverity);
- ps.setLong(2, traitement.getId());
- ps.setLong(3, messageId);
- ps.executeUpdate();
- this.severity = newSeverity;
- traitement.__updateSeverity(newSeverity);
- } catch(Exception ex) {
- logger.error("Message.setSeverity(String)", ex);
- } finally {
- if(con!=null) PoolManager.getInstance().releaseConnection(con);
- }
- }
- public String getInfoCompl() { return infoCompl; }
- public void setInfoCompl(String info) {
- Connection con = null;
- if(info.length()>4000) info = info.substring(0, 4000);
- try {
- con = PoolManager.getInstance().getConnection();
- String sql = "update MESSAGE_TRAITEMENT set MTR_INFO_COMP=? where TRT_ID=? and MTR_ID=?";
- PreparedStatement ps = con.prepareStatement(sql);
- ps.setString(1, info);
- ps.setLong(2, traitement.getId());
- ps.setLong(3, messageId);
- ps.executeUpdate();
- this.infoCompl = info;
- } catch(Exception ex) {
- logger.error("Message.setInfoCompl(String)", ex);
- } finally {
- if(con!=null) PoolManager.getInstance().releaseConnection(con);
- }
- }
+ public void setInfoCompl(String info) {
+ Connection con = null;
+ if (info.length() > 4000) {
+ info = info.substring(0, 4000);
+ }
+ try {
+ con = PoolManager.getInstance().getConnection();
+ final String sql = "update MESSAGE_TRAITEMENT set MTR_INFO_COMP=? where TRT_ID=? and MTR_ID=?";
+ final PreparedStatement ps = con.prepareStatement(sql);
+ ps.setString(1, info);
+ ps.setLong(2, this.traitement.getId());
+ ps.setLong(3, this.messageId);
+ ps.executeUpdate();
+ this.infoCompl = info;
+ } catch (final Exception ex) {
+ logger.error("Message.setInfoCompl(String)", ex);
+ } finally {
+ if (con != null) {
+ PoolManager.getInstance().releaseConnection(con);
+ }
+ }
+ }
- protected void __createInDatabase() {
- Connection con = null;
- try {
- con = PoolManager.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT MAX(MTR_ID) FROM MESSAGE_TRAITEMENT WHERE TRT_ID=?");
- ps.setLong(1,traitement.getId());
- ResultSet rs = ps.executeQuery();
- if(rs.next()) {
- messageId = rs.getLong(1)+1;
- } else {
- messageId = 1;
- }
- String sql = "insert into MESSAGE_TRAITEMENT (TRT_ID, MTR_ID, MTR_CODE_GRAVITE, MTR_MESSAGE) values (?,?,?,?)";
- ps = con.prepareStatement(sql);
- ps.setLong(1, traitement.getId());
- ps.setLong(2, messageId);
- ps.setString(3, severity);
- ps.setString(4, message);
- ps.executeUpdate();
- ps.close();
- } catch(Exception ex) {
- logger.error("Message.__createInDatabase()", ex);
- } finally {
- if(con!=null) PoolManager.getInstance().releaseConnection(con);
- }
- }
+ protected void __createInDatabase() {
+ Connection con = null;
+ try {
+ con = PoolManager.getInstance().getConnection();
+ PreparedStatement ps = con.prepareStatement("SELECT MAX(MTR_ID) FROM MESSAGE_TRAITEMENT WHERE TRT_ID=?");
+ ps.setLong(1, this.traitement.getId());
+ final ResultSet rs = ps.executeQuery();
+ if (rs.next()) {
+ this.messageId = rs.getLong(1) + 1;
+ } else {
+ this.messageId = 1;
+ }
+ final String sql = "insert into MESSAGE_TRAITEMENT (TRT_ID, MTR_ID, MTR_CODE_GRAVITE, MTR_MESSAGE) values (?,?,?,?)";
+ ps = con.prepareStatement(sql);
+ ps.setLong(1, this.traitement.getId());
+ ps.setLong(2, this.messageId);
+ ps.setString(3, this.severity);
+ ps.setString(4, this.message);
+ ps.executeUpdate();
+ ps.close();
+ } catch (final Exception ex) {
+ logger.error("Message.__createInDatabase()", ex);
+ } finally {
+ if (con != null) {
+ PoolManager.getInstance().releaseConnection(con);
+ }
+ }
+ }
}