Package org.wijiscommons.ssaf.exception

Examples of org.wijiscommons.ssaf.exception.SSAFHistoryException


    }


    public boolean record(Event event) throws SSAFHistoryException {
        if (event == null) {
            throw new SSAFHistoryException();
        }

        byte[] b = null;
       
        byte[] b1 = null;
       
        if (event.getXMLString() != null) {
            b = SerializationUtility.serialize(event.getXMLString());

            // Check if the byte array  can fit in the 'object' column.
            // the 'object' column is a BIGINT and has the same max size as Integer.MAX_VALUE
            if (b.length > Integer.MAX_VALUE) {
                throw new IllegalArgumentException("The Object is to large, it can only be " + Integer.MAX_VALUE + " bytes.");
            }
        }
       
        if (event.getThrowable() != null) {
            b1 = SerializationUtility.serialize(event.getThrowable());

            // Check if the byte array  can fit in the 'object' column.
            // the 'object' column is a BIGINT and has the same max size as Integer.MAX_VALUE
            if (b1.length > Integer.MAX_VALUE) {
                throw new IllegalArgumentException("The Object is to large, it can only be " + Integer.MAX_VALUE + " bytes.");
            }
        }


        try {
            PreparedStatement ps = null;
            if (b != null && b1 != null) {
                ps = conn.prepareStatement("INSERT INTO history (messageid, description, time, iserrormessage, errormessage, xmlString) VALUES(?, ?, ?, ?, ?, ?)");
                ps.setBinaryStream(5, new ByteArrayInputStream(b1), b1.length);
                ps.setBinaryStream(6, new ByteArrayInputStream(b), b.length);
           
           
            if (b != null && b1 == null) {
                ps = conn.prepareStatement("INSERT INTO history (messageid, description, time, iserrormessage, xmlString) VALUES(?, ?, ?, ?, ?)");
                ps.setBinaryStream(5, new ByteArrayInputStream(b), b.length);
            }
           
            if (b == null && b1 != null) {
                ps = conn.prepareStatement("INSERT INTO history (messageid, description, time, iserrormessage, errormessage) VALUES(?, ?, ?, ?, ?)");
                ps.setBinaryStream(5, new ByteArrayInputStream(b1), b1.length);
            }
           
           
            if (b == null && b1 == null) {
                ps = conn.prepareStatement("INSERT INTO message (messageid, description, time, ) VALUES(?, ?, ?, ?, ?)");
            }
           
            ps.setString(1, event.getMessageID());
            ps.setString(2, event.getDescription());
            ps.setLong(3, event.getTimeStamp().getTimeInMillis());
            ps.setBoolean(4, event.isError());
            ps.executeUpdate();
            ps.close();

            return true;
        } catch (SQLException e) {
            logger.error(e);
            throw new SSAFHistoryException();
        }
       
    }
View Full Code Here

TOP

Related Classes of org.wijiscommons.ssaf.exception.SSAFHistoryException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.