Package org.dspace.storage.rdbms

Examples of org.dspace.storage.rdbms.TableRowIterator


     * @see org.dspace.browse.BrowseDAO#doDistinctOffsetQuery(java.lang.String, java.lang.String, java.lang.String)
     */
    public int doDistinctOffsetQuery(String column, String value, boolean isAscending)
            throws BrowseException
    {
        TableRowIterator tri = null;

        try
        {
            List paramsList = new ArrayList();
            StringBuffer queryBuf = new StringBuffer();

            queryBuf.append("COUNT(").append(column).append(") AS offset ");

            buildSelectStatementDistinct(queryBuf, paramsList);
            if (isAscending)
            {
                queryBuf.append(" WHERE ").append(column).append("<?");
                paramsList.add(value);
            }
            else
            {
                queryBuf.append(" WHERE ").append(column).append(">?");
                paramsList.add(value + Character.MAX_VALUE);
            }

            if (containerTable != null && tableMap != null)
            {
                queryBuf.append(" AND ").append("mappings.distinct_id=");
                queryBuf.append(table).append(".id");
            }

            tri = DatabaseManager.query(context, queryBuf.toString(), paramsList.toArray());

            TableRow row;
            if (tri.hasNext())
            {
                row = tri.next();
                return row.getIntColumn("offset");
            }
            else
            {
                return 0;
            }
        }
        catch (SQLException e)
        {
            throw new BrowseException(e);
        }
        finally
        {
            if (tri != null)
            {
                tri.close();
            }
        }
    }
View Full Code Here


        if (log.isDebugEnabled())
        {
            log.debug(LogManager.getHeader(context, "executing_full_query", "query=" + query));
        }

        TableRowIterator tri = null;
        try
        {
            // now run the query
            tri = DatabaseManager.query(context, query, params);

            // go over the query results and process
            List results = new ArrayList();
            while (tri.hasNext())
            {
                TableRow row = tri.next();
                BrowseItem browseItem = new BrowseItem(context, row.getIntColumn("item_id"),
                                                  itemsInArchive,
                                                  itemsWithdrawn);
                results.add(browseItem);
            }

            return results;
        }
        catch (SQLException e)
        {
            log.error("caught exception: ", e);
            throw new BrowseException("problem with query: " + query, e);
        }
        finally
        {
            if (tri != null)
            {
                tri.close();
            }
        }
    }
View Full Code Here

        if (log.isDebugEnabled())
        {
            log.debug(LogManager.getHeader(context, "executing_value_query", "query=" + query));
        }

        TableRowIterator tri = null;

        try
        {
            // now run the query
            tri = DatabaseManager.query(context, query, params);

            // go over the query results and process
            List results = new ArrayList();
            while (tri.hasNext())
            {
                TableRow row = tri.next();
                String valueResult = row.getStringColumn("value");
                String authorityResult = row.getStringColumn("authority");
                results.add(new String[]{valueResult,authorityResult});
            }

            return results;
        }
        catch (SQLException e)
        {
            log.error("caught exception: ", e);
            throw new BrowseException(e);
        }
        finally
        {
            if (tri != null)
            {
                tri.close();
            }
        }
    }
View Full Code Here

    calendar.setTime(startTime);
    calendar.add(Calendar.HOUR, -2 * expirationInterval);
    expirationTime = calendar.getTime();
     
      /* Select all collections whose last_harvest is before our start time, whose harvest_type *is not* 0 and whose status *is* 0 (available) or 3 (OAI Error). */
      TableRowIterator tri = DatabaseManager.queryTable(c, "harvested_collection",
          "SELECT * FROM harvested_collection WHERE (last_harvested < ? or last_harvested is null) and harvest_type > ? and (harvest_status = ? or harvest_status = ? or (harvest_status=? and harvest_start_time < ?)) ORDER BY last_harvested",
          new java.sql.Timestamp(startTime.getTime()), 0, HarvestedCollection.STATUS_READY, HarvestedCollection.STATUS_OAI_ERROR, HarvestedCollection.STATUS_BUSY, new java.sql.Timestamp(expirationTime.getTime()));
     
      List<Integer> collectionIds = new ArrayList<Integer>();

      while (tri.hasNext())
      {
        TableRow row = tri.next();
        collectionIds.add(row.getIntColumn("collection_id"));
      }
     
      return collectionIds;
    }
View Full Code Here

     * @param status, see HarvestInstance.STATUS_...
     * @return
     * @throws SQLException
     */
    public static List<Integer> findByStatus(Context c, int status) throws SQLException {
      TableRowIterator tri = DatabaseManager.queryTable(c, "harvested_collection"
          "SELECT * FROM harvested_collection WHERE harvest_status = ?", status);
 
    List<Integer> collectionIds = new ArrayList<Integer>();
    while (tri.hasNext())
    {
      TableRow row = tri.next();
      collectionIds.add(row.getIntColumn("collection_id"));
    }
   
    return collectionIds;
    }
View Full Code Here

      String query = "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ? order by last_harvested asc limit 1";
       
      if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
          query = "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ? and rownum <= 1  order by last_harvested asc";
         
        TableRowIterator tri = DatabaseManager.queryTable(c, "harvested_collection",
          query, 0, 0);
      TableRow row = tri.next();
     
      if (row != null)
        return row.getIntColumn("collection_id");
      else
        return -1;
View Full Code Here

        String query = "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ? order by last_harvested desc limit 1";
       
        if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
            query = "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ? and rownum <= 1 order by last_harvested desc";
       
      TableRowIterator tri = DatabaseManager.queryTable(c, "harvested_collection",
          query , 0, 0);
      TableRow row = tri.next();
   
      if (row != null)
        return row.getIntColumn("collection_id");
      else
        return -1;
View Full Code Here

        this.context = context;
    }

    public BrowseItem[] findAll() throws SQLException
    {
        TableRowIterator tri = null;
        List<BrowseItem> items = new ArrayList<BrowseItem>();

        try
        {
            tri = DatabaseManager.query(context, findAll);
            while (tri.hasNext())
            {
                TableRow row = tri.next();
                items.add(new BrowseItem(context, row.getIntColumn("item_id"),
                                                  row.getBooleanColumn("in_archive"),
                                                  row.getBooleanColumn("withdrawn")));
            }
        }
        finally
        {
            if (tri != null)
                tri.close();
        }
       
        BrowseItem[] bis = new BrowseItem[items.size()];
        return items.toArray(bis);
    }
View Full Code Here

    public DCValue[] queryMetadata(int itemId, String schema, String element, String qualifier, String lang)
      throws SQLException
    {
      List<DCValue> values = new ArrayList<DCValue>();
      TableRowIterator tri = null;

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

            if (!tri.hasNext())
            {
                return new DCValue[0];
            }

            while (tri.hasNext())
            {
                TableRow tr = tri.next();
                DCValue dcv = new DCValue();
                dcv.schema = schema;
                dcv.element = tr.getStringColumn("element");
                dcv.qualifier = tr.getStringColumn("qualifier");
                dcv.language = tr.getStringColumn("text_lang");
                dcv.value = tr.getStringColumn("text_value");
                dcv.authority = tr.getStringColumn("authority");
                dcv.confidence = tr.getIntColumn("confidence");
                values.add(dcv);
            }
        }
        finally
        {
            if (tri != null)
                tri.close();
        }
       
        DCValue[] dcvs = new DCValue[values.size()];
        return values.toArray(dcvs);
    }
View Full Code Here

         * FYI: This method has to be scoped to a collection. Otherwise, we could have collisions as more
         * than one collection might be importing the same item. That is OAI_ID's might be unique to the
         * provider but not to the harvester.
         */
        Item resolvedItem = null;
        TableRowIterator tri = null;
        final String selectItemFromOaiId = "SELECT dsi.item_id FROM " +
          "(SELECT item.item_id, item.owning_collection FROM item JOIN harvested_item ON item.item_id=harvested_item.item_id WHERE harvested_item.oai_id=?) " +
          "dsi JOIN collection ON dsi.owning_collection=collection.collection_id WHERE collection.collection_id=?";
       
        try
        {
            tri = DatabaseManager.query(context, selectItemFromOaiId, itemOaiID, collectionID);

            if (tri.hasNext())
            {
                TableRow row = tri.next();
                int itemID = row.getIntColumn("item_id");
                resolvedItem = Item.find(context, itemID);
            }
            else {
              return null;
            }
        }
        finally {
            if (tri != null)
                tri.close();
        }

        return resolvedItem;
    }
View Full Code Here

TOP

Related Classes of org.dspace.storage.rdbms.TableRowIterator

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.