Package edu.uga.galileo.voci.db

Examples of edu.uga.galileo.voci.db.QueryParser


    sql.append("and qualifier=? ");
    sql.append("and project_id=? ");
    sql.append("and content_type=? ");
    sql.append("and active=true ");

    QueryParser qp = new QueryParser(sql.toString());
    qp.addPreparedStmtElementDefinition(element);
    qp.addPreparedStmtElementDefinition(qualifier == null ? "" : qualifier);
    qp.addPreparedStmtElementDefinition(projectId);
    qp.addPreparedStmtElementDefinition(contentType);

    try {
      Configuration.getConnectionPool().executeQuery(qp);
      if (qp.getResultCount() > 0) {
        try {
          return qp.getResult(Integer.class, "metadata_id")
              .intValue();
        } catch (DataTypeMismatchException e) {
          Logger
              .error("Your metadata_id column appears to not be an int");
        }
View Full Code Here


    sql.append("   from projects ");
    sql.append("   where handle=?) ");
    sql.append("and content_type=? ");
    sql.append("and metadata_id=? ");

    QueryParser qp = new QueryParser(sql.toString());
    // this is a unique use of the query parser, in that we're taking
    // advantage of its option to manipulate the connection object (no
    // autocommit) before handing it to the connection pool for
    // processing. to do that, we have to get and manage our own
    // connection object, getting it from the pool, using it in the parser,
    // and returning it in the "finally" portion of the "try/catch/finally"
    // block
    Connection myConn = null;
    try {
      myConn = ConnectionPoolFactory.getConnectionPool().getConnection();
    } catch (NoAvailablePoolException e1) {
      throw new NoSuchMetadataException(
          "Couldn't get metadata b/c of a connection pool problem: "
              + e1.toString());
    }

    myConn.setAutoCommit(false);

    qp.setConnection(myConn);
    qp.addPreparedStmtElementDefinition(projectHandle);
    qp.addPreparedStmtElementDefinition(type.getValue());
    qp.addPreparedStmtElementDefinition(metadataId);

    try {
      if (!Configuration.getConnectionPool().executeInsertOrUpdate(qp)) {
        throw new NoSuchMetadataException(
            "No matching row was found to update");
      } else {
        // if that worked, then set the rest of the fields for
        // this projectId+contentType combination to false
        qp.clearForNewSQL();

        sql = new StringBuffer();
        sql.append("update metadata_registry ");
        sql.append("set is_key_field=false ");
        sql.append("where project_id=");
        sql.append("  (select project_id ");
        sql.append("   from projects ");
        sql.append("   where handle=?) ");
        sql.append("and content_type=? ");
        sql.append("and metadata_id!=? ");

        qp.setSql(sql.toString());
        qp.addPreparedStmtElementDefinition(projectHandle);
        qp.addPreparedStmtElementDefinition(type.getValue());
        qp.addPreparedStmtElementDefinition(metadataId);

        Configuration.getConnectionPool().executeInsertOrUpdate(qp);

        qp.getConnection().commit();
      }
    } catch (SQLException e) {
      Logger.error(
          "Metadata record couldn't be updated ... rolling back", e);
      qp.getConnection().rollback();
      throw new NoSuchMetadataException(
          "SQLException prevented metadata record update: "
              + e.getMessage());
    } finally {
      qp.setConnection(null);
      myConn.setAutoCommit(true); // reset to true before returning it
      Configuration.getConnectionPool().returnConnection(myConn);
    }
  }
View Full Code Here

    sql.append("where ");
    sql.append(contentDescriptor);
    sql.append("_id=? ");
    sql.append("and metadata_id=? ");

    QueryParser qp = new QueryParser(sql.toString());
    qp.addPreparedStmtElementDefinition(vboID);
    qp.addPreparedStmtElementDefinition(metadataId);

    try {
      Configuration.getConnectionPool().executeQuery(qp);
      if (qp.getResultCount() > 0) {
        try {
          return qp.getResult(String.class, "value");
        } catch (DataTypeMismatchException e) {
          Logger.error("Your 'value' column in the metadata2"
              + contentDescriptor
              + " table appears to not be a String");
        }
View Full Code Here

    sql.append(" ");
    sql.append("where ");
    sql.append(contentDescriptor);
    sql.append("_id=? ");

    QueryParser qp = new QueryParser(sql.toString());
    qp.addPreparedStmtElementDefinition(vboID);

    try {
      Configuration.getConnectionPool().executeQuery(qp);
      if (qp.getResultCount() > 0) {
        ArrayList row;
        for (int m = 0; m < qp.getResultCount(); m++) {
          row = qp.getRowResults(m);
          results.put((Integer) row.get(0), (String) row.get(1));
        }
      }
    } catch (SQLException e) {
      Logger.error("Metadata values couldn't be retrieved for "
View Full Code Here

    sql.append(" ");
    sql.append("where ");
    sql.append(contentTypeDescriptor);
    sql.append("_id=? ");

    QueryParser qp = new QueryParser(sql.toString());
    qp.addPreparedStmtElementDefinition(vboId);

    if (connection != null) {
      qp.setConnection(connection);
    }

    try {
      Configuration.getConnectionPool().executeInsertOrUpdate(qp);
    } catch (SQLException e) {
View Full Code Here

    sql.append(" (");
    sql.append(contentTypeDescriptor);
    sql.append("_id, metadata_id, value) ");
    sql.append("values (?, ?, ?) ");

    QueryParser qp = new QueryParser(sql.toString());
    qp.addPreparedStmtElementDefinition(vboId);
    qp.addPreparedStmtElementDefinition(metadataId);
    qp.addPreparedStmtElementDefinition(value);

    if (connection != null) {
      qp.setConnection(connection);
    }

    try {
      Configuration.getConnectionPool().executeInsertOrUpdate(qp);
    } catch (SQLException e) {
View Full Code Here

    sql.append(contentDescriptor);
    sql.append("_id!=? ");
    sql.append("and metadata_id=? ");
    sql.append("and value=? ");

    QueryParser qp = new QueryParser(sql.toString());
    qp.addPreparedStmtElementDefinition(elementId);
    qp.addPreparedStmtElementDefinition(metadataId);
    qp.addPreparedStmtElementDefinition(value);

    try {
      Configuration.getConnectionPool().executeQuery(qp);
      if (qp.getResult(Integer.class, "dupeCount") == 0) {
        return true;
      }
    } catch (SQLException e) {
      Logger.error("Metadata uniqueness couldn't be checked "
          + "due to SQLException", e);
View Full Code Here

TOP

Related Classes of edu.uga.galileo.voci.db.QueryParser

Copyright © 2018 www.massapicom. 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.