Exemplo n.º 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;
  }
Exemplo n.º 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;
  }
Exemplo n.º 3
0
  @Override
  public ElementBean getElement(final String uri, final int schemaid)
      throws DataSourceConnectionException, QueryException {
    log.debug("Trying to get an element");
    ElementBean bean = null;
    Connection con = null;
    PreparedStatement pst = null;
    ResultSet rs = null;

    con = factory.getConnection();
    try {
      pst = con.prepareStatement(SQL_GET_ELEMENT);
      pst.setInt(1, schemaid);
      pst.setString(2, uri);
      rs = pst.executeQuery();

      if (rs.next()) {
        log.debug("The element was found. Creating the bean and indentifying the type");
        // ok, the element exists
        // verify what type of element is it
        if (rs.getObject("class") != null) {
          // is a class
          log.debug("The element is a class");
          final ClassBean cbean = new ClassBean();
          cbean.setMatchableid(rs.getLong("matchclass"));
          // put the matchableid
          bean = cbean;
        } else if (rs.getObject("property") != null) {
          // is a property
          log.debug("The element is a property");
          final PropertyBean pbean = new PropertyBean();
          pbean.setDatatype(rs.getString("datatype"));
          bean = pbean;
        } else if (rs.getObject("instance") != null) {
          // is a instace
          log.debug("The element is an instance");
          final InstanceBean ibean = new InstanceBean();
          ibean.setClassURI(rs.getString("class_uri"));
          ibean.setDataSetSeq(rs.getInt("datasetseq"));
          ibean.setMatchableid(rs.getLong("matchInstance"));
          bean = ibean;
        }
        // now treats the element itself
        bean.setUri(rs.getString(2));
        bean.setSchemaid(rs.getInt(1));
        bean.setLabel(rs.getString(3));
        bean.setComment(rs.getString(4));
      }
    } catch (final SQLException ex) {
      log.error("Error trying to get an element", 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 prepared statement", ex);
      }
      rs = null;
      pst = null;
      con = null; // does not close the connection (It will be closed by
      // the command)
    }
    return bean;
  }