Search in sources :

Example 6 with JRParameter

use of net.sf.jasperreports.engine.JRParameter in project adempiere by adempiere.

the class JRQueryExecuter method getStatement.

/**
     *
     */
private PreparedStatement getStatement(Connection conn) throws JRException {
    PreparedStatement pstmt = null;
    if (queryString != null && queryString.trim().length() > 0) {
        try {
            pstmt = conn.prepareStatement(queryString);
            if (parameterNames != null && parameterNames.size() > 0) {
                JRParameter parameter = null;
                String parameterName = null;
                Class clazz = null;
                Object parameterValue = null;
                for (int i = 0; i < parameterNames.size(); i++) {
                    parameterName = (String) parameterNames.get(i);
                    parameter = (JRParameter) parametersMap.get(parameterName);
                    clazz = parameter.getValueClass();
                    //FIXMEparameterValue = jrParameter.getValue();
                    parameterValue = parameterValues.get(parameterName);
                    if (clazz.equals(java.lang.Object.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.JAVA_OBJECT);
                        } else {
                            pstmt.setObject(i + 1, parameterValue);
                        }
                    } else if (clazz.equals(java.lang.Boolean.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.BIT);
                        } else {
                            pstmt.setBoolean(i + 1, ((Boolean) parameterValue).booleanValue());
                        }
                    } else if (clazz.equals(java.lang.Byte.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.TINYINT);
                        } else {
                            pstmt.setByte(i + 1, ((Byte) parameterValue).byteValue());
                        }
                    } else if (clazz.equals(java.lang.Double.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.DOUBLE);
                        } else {
                            pstmt.setDouble(i + 1, ((Double) parameterValue).doubleValue());
                        }
                    } else if (clazz.equals(java.lang.Float.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.FLOAT);
                        } else {
                            pstmt.setFloat(i + 1, ((Float) parameterValue).floatValue());
                        }
                    } else if (clazz.equals(java.lang.Integer.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.INTEGER);
                        } else {
                            pstmt.setInt(i + 1, ((Integer) parameterValue).intValue());
                        }
                    } else if (clazz.equals(java.lang.Long.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.BIGINT);
                        } else {
                            pstmt.setLong(i + 1, ((Long) parameterValue).longValue());
                        }
                    } else if (clazz.equals(java.lang.Short.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.SMALLINT);
                        } else {
                            pstmt.setShort(i + 1, ((Short) parameterValue).shortValue());
                        }
                    } else if (clazz.equals(java.math.BigDecimal.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.DECIMAL);
                        } else {
                            pstmt.setBigDecimal(i + 1, (BigDecimal) parameterValue);
                        }
                    } else if (clazz.equals(java.lang.String.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.VARCHAR);
                        } else {
                            pstmt.setString(i + 1, parameterValue.toString());
                        }
                    } else if (clazz.equals(java.util.Date.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.DATE);
                        } else {
                            pstmt.setDate(i + 1, new java.sql.Date(((java.util.Date) parameterValue).getTime()));
                        }
                    } else if (clazz.equals(java.sql.Timestamp.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.TIMESTAMP);
                        } else {
                            pstmt.setTimestamp(i + 1, (java.sql.Timestamp) parameterValue);
                        }
                    } else if (clazz.equals(java.sql.Time.class)) {
                        if (parameterValue == null) {
                            pstmt.setNull(i + 1, Types.TIME);
                        } else {
                            pstmt.setTime(i + 1, (java.sql.Time) parameterValue);
                        }
                    } else {
                        throw new JRException("Parameter type not supported in query : " + parameterName + " class " + clazz.getName());
                    }
                }
            }
        } catch (SQLException e) {
            throw new JRException("Error preparing statement for executing the report query : " + "\n\n" + queryString + "\n\n", e);
        }
    }
    return pstmt;
}
Also used : JRException(net.sf.jasperreports.engine.JRException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) JRParameter(net.sf.jasperreports.engine.JRParameter)

Aggregations

JRParameter (net.sf.jasperreports.engine.JRParameter)6 HashMap (java.util.HashMap)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 JRException (net.sf.jasperreports.engine.JRException)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 QName (javax.xml.namespace.QName)2 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 Map (java.util.Map)1 JRField (net.sf.jasperreports.engine.JRField)1 JasperPrint (net.sf.jasperreports.engine.JasperPrint)1 ReportException (org.opennms.api.reporting.ReportException)1