Ejemplo n.º 1
0
  /**
   * Perform a database query to obtain the string array of values corresponding to the passed
   * parameters. This is only really called from <code>
   * getMetadata(schema, element, qualifier, lang);
   * </code> which will obtain the value from cache if available first.
   *
   * @param schema
   * @param element
   * @param qualifier
   * @param lang
   */
  @Override
  public List<DCValue> getMetadata(
      Item item, String schema, String element, String qualifier, String lang) {
    List<DCValue> metadata = new ArrayList<DCValue>();
    try {
      TableRowIterator tri;

      if (qualifier == null) {
        Object[] params = {item.getID(), element, schema};
        tri = DatabaseManager.query(context, getByMetadataElement, params);
      } else if (Item.ANY.equals(qualifier)) {
        Object[] params = {item.getID(), element, schema};
        tri = DatabaseManager.query(context, getByMetadataAnyQualifier, params);
      } else {
        Object[] params = {item.getID(), element, qualifier, schema};
        tri = DatabaseManager.query(context, getByMetadata, params);
      }

      while (tri.hasNext()) {
        TableRow tr = tri.next();
        DCValue dcv = new DCValue();
        dcv.schema = schema;
        dcv.element = element;
        dcv.qualifier = qualifier;
        dcv.language = lang;
        dcv.value = tr.getStringColumn("text_value");
        metadata.add(dcv);
      }
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
    return metadata;
  }
Ejemplo n.º 2
0
  @Override
  public void loadMetadata(Item item) {
    MetadataFieldDAO mfDAO = MetadataFieldDAOFactory.getInstance(context);
    MetadataSchemaDAO msDAO = MetadataSchemaDAOFactory.getInstance(context);

    try {
      TableRowIterator tri =
          DatabaseManager.queryTable(
              context,
              "metadatavalue",
              "SELECT * FROM MetadataValue "
                  + "WHERE item_id = ? "
                  + "ORDER BY metadata_field_id, place",
              item.getID());

      List<DCValue> metadata = new ArrayList<DCValue>();

      for (TableRow row : tri.toList()) {
        // Get the associated metadata field and schema information
        int fieldID = row.getIntColumn("metadata_field_id");
        MetadataField field = mfDAO.retrieve(fieldID);

        if (field == null) {
          log.error("Loading item - cannot find metadata field " + fieldID);
        } else {
          MetadataSchema schema = msDAO.retrieve(field.getSchemaID());

          // Make a DCValue object
          DCValue dcv = new DCValue();
          dcv.schema = schema.getName();
          dcv.element = field.getElement();
          dcv.qualifier = field.getQualifier();
          dcv.language = row.getStringColumn("text_lang");
          dcv.value = row.getStringColumn("text_value");

          // Add it to the item
          metadata.add(dcv);
        }
      }

      item.setMetadata(metadata);
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
  }