Package custom.energypro.vinnica.analysis

Source Code of custom.energypro.vinnica.analysis.AnalizByObjectsScriptlet

package custom.energypro.vinnica.analysis;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;

import net.sf.jasperreports.engine.JRDefaultScriptlet;
import net.sf.jasperreports.engine.JRScriptletException;

import com.uens.query.dao.SqlUtil;

public class AnalizByObjectsScriptlet extends JRDefaultScriptlet {

  private static final String CR = System.getProperty("line.separator");

  public String getPowerSource(Integer objCode) throws JRScriptletException {
    Connection conn = (Connection) getParameterValue("REPORT_CONNECTION");
    String sql = SqlUtil.loadSQL(getClass(), "getPowerSources.sql");

    PreparedStatement st = null;
    ResultSet rs = null;
    StringBuffer result = new StringBuffer();

    try {
      st = conn.prepareStatement(sql);
      st.setInt(1, objCode);
      rs = st.executeQuery();
      Set<String> srcSet = new HashSet<String>();
      while (rs.next()) {
        StringBuffer src = new StringBuffer();
        String lineName = rs.getString(1);
        if (rs.wasNull()) {
          lineName = null;
        }
        String balanceLimitNote = rs.getString(2);
        if (rs.wasNull()) {
          balanceLimitNote = null;
        }
        if (lineName == null && balanceLimitNote == null) {
          continue;
        }
        src.append("�� ");
        if (lineName != null) {
          src.append(lineName);
        }
        if (balanceLimitNote != null) {
          src.append(", ");
          src.append(balanceLimitNote);

        }
        if (!srcSet.contains(src)) {
          srcSet.add(src.toString());
          if (result.length() > 0) {
            result.append(CR);
          }
          result.append(src);
        }
      }
      return result.toString();
    } catch (SQLException e) {
      throw new JRScriptletException(e.getMessage(), e);
    } finally {
      SqlUtil.close(rs);
      SqlUtil.close(st);
    }
  }
}
TOP

Related Classes of custom.energypro.vinnica.analysis.AnalizByObjectsScriptlet

TOP
Copyright © 2018 www.massapi.com. 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.