コード例 #1
0
ファイル: OracleSchemaDAO.java プロジェクト: guylerme/Bench
  @Override
  public Set<InstanceBean> getClassInstances(
      final int schemaid, final int dataSetSeq, final String classURI)
      throws DataSourceConnectionException, QueryException {
    final Set<InstanceBean> set = new HashSet<InstanceBean>();

    final Connection con = factory.getConnection();
    PreparedStatement pst = null;
    ResultSet rs = null;

    try {
      pst = con.prepareStatement(SQL_GET_CLASS_INSTANCES);
      pst.setInt(1, schemaid);
      pst.setString(2, classURI);
      pst.setInt(3, dataSetSeq);
      rs = pst.executeQuery();

      while (rs.next()) {
        final InstanceBean bean = new InstanceBean();
        // fill the bean
        bean.setSchemaid(rs.getInt("SCHEMAID"));
        bean.setUri(rs.getString("URI"));
        bean.setLabel(rs.getString("LABEL"));
        bean.setComment(rs.getString("COMMENT"));
        bean.setMatchableid(rs.getLong("MATCHABLEID"));
        bean.setClassURI(classURI);
        // add the bean to the set
        set.add(bean);
      }
    } catch (final SQLException ex) {
      log.error("An error ocurred when trying to get the set of instances of a class", ex);
      throw new QueryException(ex);
    } finally {
      try {
        if (rs != null) {
          rs.close();
        }
        if (pst != null) {
          pst.close();
        }
      } catch (final SQLException ex) {
        log.error("Error trying to close a resultset or a prepared statement", ex);
      }
      rs = null;
      pst = null;
    }
    return set;
  }
コード例 #2
0
ファイル: OracleSchemaDAO.java プロジェクト: guylerme/Bench
  @Override
  public Matchable getMatchable(final long matchable)
      throws DataSourceConnectionException, QueryException {
    Matchable mat = null;
    try {
      // try a property
      PreparedStatement pst = factory.getConnection().prepareStatement(SQL_GET_MATCHABLE_PROP);
      pst.setLong(1, matchable);
      ResultSet rs = pst.executeQuery();
      if (rs.next()) {
        // is a cproperty
        final CPropertyBean bean = new CPropertyBean();
        // fill the bean
        bean.setSchemaid(rs.getInt(1));
        bean.setUri(rs.getString(2));
        bean.setLabel(rs.getString(3));
        bean.setComment(rs.getString(4));
        bean.setDatatype(rs.getString(5));
        bean.setMatchableid(rs.getLong(6));
        bean.setClassURI(rs.getString(7));
        mat = bean;
      }
      rs.close();
      pst.close();

      // try a instance
      if (mat == null) {
        pst = factory.getConnection().prepareStatement(SQL_GET_MATCHABLE_INS);
        pst.setLong(1, matchable);
        rs = pst.executeQuery();
        if (rs.next()) {
          final InstanceBean bean = new InstanceBean();
          // fill the bean
          bean.setSchemaid(rs.getInt("SCHEMAID"));
          bean.setUri(rs.getString("URI"));
          bean.setLabel(rs.getString("LABEL"));
          bean.setComment(rs.getString("COMMENT"));
          bean.setMatchableid(rs.getLong("MATCHABLEID"));
          bean.setClassURI(rs.getString("CLASS_URI"));
          mat = bean;
        }
      }
      rs.close();
      pst.close();
      // try a class
      if (mat == null) {
        pst = factory.getConnection().prepareStatement(SQL_GET_MATCHABLE_CLS);
        pst.setLong(1, matchable);
        rs = pst.executeQuery();
        if (rs.next()) {
          final ClassBean bean = new ClassBean();
          bean.setSchemaid(rs.getInt(1));
          bean.setUri(rs.getString(2));
          bean.setLabel(rs.getString(3));
          bean.setComment(rs.getString(4));
          bean.setMatchableid(rs.getLong("MATCHABLEID"));
          mat = bean;
        }
      }

    } catch (final SQLException e) {
      throw new QueryException(e);
    }
    return mat;
  }