예제 #1
0
  @Override
  public Set<ClassBean> getSchemaClasses(final int schemaid)
      throws DataSourceConnectionException, QueryException {
    final Set<ClassBean> set = new HashSet<ClassBean>();

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

    try {
      pst = con.prepareStatement(SQL_GET_SCHEMA_CLASSES);
      pst.setInt(1, schemaid);
      rs = pst.executeQuery();

      while (rs.next()) {
        final ClassBean bean = new ClassBean();
        // fill the bean
        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"));
        // 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 classes of the schema with id "
              + schemaid,
          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
  @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;
  }