Package org.dspace.storage.rdbms

Examples of org.dspace.storage.rdbms.TableRowIterator


            paramArr = new Object[] {int_param,params,params,params,limit};
        else if (offset > 0)
            paramArr = new Object[] {int_param,params,params,params,offset};

        // Get all the epeople that match the query
    TableRowIterator rows = DatabaseManager.query(context, dbquery, paramArr);
    try
        {
            List epeopleRows = rows.toList();
            EPerson[] epeople = new EPerson[epeopleRows.size()];

            for (int i = 0; i < epeopleRows.size(); i++)
            {
                TableRow row = (TableRow) epeopleRows.get(i);

                // First check the cache
                EPerson fromCache = (EPerson) context.fromCache(EPerson.class, row
                        .getIntColumn("eperson_id"));

                if (fromCache != null)
                {
                    epeople[i] = fromCache;
                }
                else
                {
                    epeople[i] = new EPerson(context, row);
                }
            }

            return epeople;
        }
        finally
        {
            if (rows != null)
                rows.close();
        }
    }
View Full Code Here


            s = "lastname";
        }

        // NOTE: The use of 's' in the order by clause can not cause an sql
        // injection because the string is derived from constant values above.
        TableRowIterator rows = DatabaseManager.query(context,
                "SELECT * FROM eperson ORDER BY "+s);

        try
        {
            List epeopleRows = rows.toList();

            EPerson[] epeople = new EPerson[epeopleRows.size()];

            for (int i = 0; i < epeopleRows.size(); i++)
            {
                TableRow row = (TableRow) epeopleRows.get(i);

                // First check the cache
                EPerson fromCache = (EPerson) context.fromCache(EPerson.class, row
                        .getIntColumn("eperson_id"));

                if (fromCache != null)
                {
                    epeople[i] = fromCache;
                }
                else
                {
                    epeople[i] = new EPerson(context, row);
                }
            }

            return epeople;
        }
        finally
        {
            if (rows != null)
                rows.close();
        }
    }
View Full Code Here

    public Vector<String> getDeleteConstraints() throws SQLException
    {
        Vector<String> tableList = new Vector<String>();

        // check for eperson in item table
        TableRowIterator tri = DatabaseManager.query(myContext,
                "SELECT * from item where submitter_id= ? ",
                getID());

        try
        {
            if (tri.hasNext())
            {
                tableList.add("item");
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
                tri.close();
        }

        // check for eperson in workflowitem table
        tri = DatabaseManager.query(myContext,
                "SELECT * from workflowitem where owner= ? ",
                getID());

        try
        {
            if (tri.hasNext())
            {
                tableList.add("workflowitem");
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
                tri.close();
        }

        // check for eperson in tasklistitem table
        tri = DatabaseManager.query(myContext,
                "SELECT * from tasklistitem where eperson_id= ? ",
                getID());

        try
        {
            if (tri.hasNext())
            {
                tableList.add("tasklistitem");
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
                tri.close();
        }
       
        // the list of tables can be used to construct an error message
        // explaining to the user why the eperson cannot be deleted.
        return tableList;
View Full Code Here

   * @throws ItemCountException
   */
  public void collectionCount(Collection collection, int count)
    throws ItemCountException
  {
        TableRowIterator tri = null;
        try
    {
      // first find out if we have a record
      Object[] sparams = { new Integer(collection.getID()) };
      tri = DatabaseManager.query(context, collectionSelect, sparams);
     
      if (tri.hasNext())
      {
        Object[] params = { new Integer(count), new Integer(collection.getID()) };
        DatabaseManager.updateQuery(context, collectionUpdate, params);
      }
      else
      {
        Object[] params = { new Integer(collection.getID()), new Integer(count) };
        DatabaseManager.updateQuery(context, collectionInsert, params);
      }
    }
    catch (SQLException e)
    {
      log.error("caught exception: ", e);
      throw new ItemCountException(e);
    }
        finally
        {
            if (tri != null)
                tri.close();
        }
    }
View Full Code Here

   * @throws ItemCountException
   */
  public void communityCount(Community community, int count)
    throws ItemCountException
  {
        TableRowIterator tri = null;
        try
    {
      // first find out if we have a record
      Object[] sparams = { new Integer(community.getID()) };
      tri = DatabaseManager.query(context, communitySelect, sparams);
     
      if (tri.hasNext())
      {
        Object[] params = { new Integer(count), new Integer(community.getID()) };
        DatabaseManager.updateQuery(context, communityUpdate, params);
      }
      else
      {
        Object[] params = { new Integer(community.getID()), new Integer(count) };
        DatabaseManager.updateQuery(context, communityInsert, params);
      }
    }
    catch (SQLException e)
    {
      log.error("caught exception: ", e);
      throw new ItemCountException(e);
    }
        finally
        {
            if (tri != null)
                tri.close();
        }
    }
View Full Code Here

   * @throws ItemCountException
   */
  private int getCollectionCount(Collection collection)
    throws ItemCountException
  {
        TableRowIterator tri = null;
        try
    {
      Object[] params = { new Integer(collection.getID()) };
      tri = DatabaseManager.query(context, collectionSelect, params);
     
      if (!tri.hasNext())
      {
        return 0;
      }
     
      TableRow tr = tri.next();
     
      if (tri.hasNext())
      {
        throw new ItemCountException("More than one count row in the database");
      }

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

   * @throws ItemCountException
   */
  private int getCommunityCount(Community community)
    throws ItemCountException
  {
        TableRowIterator tri = null;
        try
    {
      Object[] params = { new Integer(community.getID()) };
      tri = DatabaseManager.query(context, communitySelect, params);
     
      if (!tri.hasNext())
      {
        return 0;
      }
     
      TableRow tr = tri.next();
     
      if (tri.hasNext())
      {
        throw new ItemCountException("More than one count row in the database");
      }

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

        return new Bitstream(context, row);
    }

    public static Bitstream[] findAll(Context context) throws SQLException
    {
        TableRowIterator tri = DatabaseManager.queryTable(context, "bitstream",
                "SELECT * FROM bitstream");

        List<Bitstream> bitstreams = new ArrayList<Bitstream>();

        try
        {
            while (tri.hasNext())
            {
                TableRow row = tri.next();

                // First check the cache
                Bitstream fromCache = (Bitstream) context.fromCache(
                        Bitstream.class, row.getIntColumn("bitstream_id"));

                if (fromCache != null)
                {
                    bitstreams.add(fromCache);
                }
                else
                {
                    bitstreams.add(new Bitstream(context, row));
                }
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
                tri.close();
        }

        Bitstream[] bitstreamArray = new Bitstream[bitstreams.size()];
        bitstreamArray = bitstreams.toArray(bitstreamArray);

View Full Code Here

     * @throws SQLException
     */
    public Bundle[] getBundles() throws SQLException
    {
        // Get the bundle table rows
        TableRowIterator tri = DatabaseManager.queryTable(bContext, "bundle",
                "SELECT bundle.* FROM bundle, bundle2bitstream WHERE " +
                "bundle.bundle_id=bundle2bitstream.bundle_id AND " +
                "bundle2bitstream.bitstream_id= ? ",
                 bRow.getIntColumn("bitstream_id"));

        // Build a list of Bundle objects
        List<Bundle> bundles = new ArrayList<Bundle>();
        try
        {
            while (tri.hasNext())
            {
                TableRow r = tri.next();

                // First check the cache
                Bundle fromCache = (Bundle) bContext.fromCache(Bundle.class, r
                        .getIntColumn("bundle_id"));

                if (fromCache != null)
                {
                    bundles.add(fromCache);
                }
                else
                {
                    bundles.add(new Bundle(bContext, r));
                }
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
                tri.close();
        }

        Bundle[] bundleArray = new Bundle[bundles.size()];
        bundleArray = (Bundle[]) bundles.toArray(bundleArray);

View Full Code Here

            // a RuntimeException - a hack to avoid changing the API all over
            // the place
            try
            {
                // get epeople objects
                TableRowIterator tri = DatabaseManager.queryTable(myContext,"eperson",
                                "SELECT eperson.* FROM eperson, epersongroup2eperson WHERE " +
                                "epersongroup2eperson.eperson_id=eperson.eperson_id AND " +
                                "epersongroup2eperson.eperson_group_id= ?",
                                myRow.getIntColumn("eperson_group_id"));

                try
                {
                    while (tri.hasNext())
                    {
                        TableRow r = (TableRow) tri.next();

                        // First check the cache
                        EPerson fromCache = (EPerson) myContext.fromCache(
                                EPerson.class, r.getIntColumn("eperson_id"));

                        if (fromCache != null)
                        {
                            epeople.add(fromCache);
                        }
                        else
                        {
                            epeople.add(new EPerson(myContext, r));
                        }
                    }
                }
                finally
                {
                    // close the TableRowIterator to free up resources
                    if (tri != null)
                        tri.close();
                }

                // now get Group objects
                tri = DatabaseManager.queryTable(myContext,"epersongroup",
                                "SELECT epersongroup.* FROM epersongroup, group2group WHERE " +
                                "group2group.child_id=epersongroup.eperson_group_id AND "+
                                "group2group.parent_id= ? ",
                                myRow.getIntColumn("eperson_group_id"));

                try
                {
                    while (tri.hasNext())
                    {
                        TableRow r = (TableRow) tri.next();

                        // First check the cache
                        Group fromCache = (Group) myContext.fromCache(Group.class,
                                r.getIntColumn("eperson_group_id"));

                        if (fromCache != null)
                        {
                            groups.add(fromCache);
                        }
                        else
                        {
                            groups.add(new Group(myContext, r));
                        }
                    }
                }
                finally
                {
                    // close the TableRowIterator to free up resources
                    if (tri != null)
                        tri.close();
                }

            }
            catch (Exception e)
            {
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.