1 16 17 package org.pentaho.core.audit; 18 19 import java.math.BigDecimal ; 20 import java.sql.Connection ; 21 import java.sql.PreparedStatement ; 22 import java.sql.SQLException ; 23 import java.sql.Types ; 24 25 import org.pentaho.messages.Messages; 26 import org.pentaho.util.logging.Logger; 27 28 32 public class AuditSQLEntry implements IAuditEntry { 33 private static AuditConnection audc; 34 35 private static final String INSERT_STMT = Messages.getString("AUDSQLENT.CODE_AUDIT_INSERT_STATEMENT"); 37 static { 38 try { 39 audc = new AuditConnection(); 40 audc.initialize(); 41 } catch (Exception ex) { 42 Logger.error(AuditHelper.class.getName(), Messages.getErrorString("AUDSQLENT.ERROR_0001_INVALID_CONNECTION"), ex); } 44 } 45 46 public AuditSQLEntry() { 47 } 49 50 private void setString(PreparedStatement stmt, int num, String val) throws SQLException { 51 if (val != null) { 52 stmt.setString(num, val); 53 } else { 54 stmt.setNull(num, Types.VARCHAR); 55 } 56 } 57 58 private void setText(PreparedStatement stmt, int num, String val) throws SQLException { 59 if (val != null) { 60 stmt.setBytes(num, val.getBytes()); 61 } else { 62 stmt.setNull(num, Types.CLOB); 63 } 64 } 65 66 private void setBigDec(PreparedStatement stmt, int num, BigDecimal val) throws SQLException { 67 if (val != null) { 68 stmt.setBigDecimal(num, val); 69 } else { 70 stmt.setNull(num, Types.DECIMAL); 71 } 72 } 73 74 79 public void auditAll(String jobId, String instId, String objId, String objType, String actor, String messageType, String messageName, String messageTxtValue, BigDecimal messageNumValue, BigDecimal duration) throws AuditException { 80 81 try { 82 Connection con = audc.getAuditConnection(); 83 try { 84 PreparedStatement stmt = con.prepareStatement(INSERT_STMT); 85 try { 86 setString(stmt, 1, jobId); 87 setString(stmt, 2, instId); 88 setString(stmt, 3, objId); 89 setString(stmt, 4, objType); 90 setString(stmt, 5, actor); 91 setString(stmt, 6, messageType); 92 setString(stmt, 7, messageName); 93 setText(stmt, 8, messageTxtValue); 94 setBigDec(stmt, 9, messageNumValue); 95 setBigDec(stmt, 10, duration); 96 stmt.executeUpdate(); 97 } finally { 98 stmt.close(); 99 } 100 } finally { 101 con.close(); 102 } 103 } catch (SQLException ex) { 104 throw new AuditException(ex); 105 } 106 107 } 108 109 } 110 | Popular Tags |