Package org.dspace.storage.rdbms

Examples of org.dspace.storage.rdbms.TableRowIterator


        if (e != null)
        {
            // two queries - first to get groups eperson is a member of
            // second query gets parent groups for groups eperson is a member of

            TableRowIterator tri = DatabaseManager.queryTable(c,
                    "epersongroup2eperson",
                    "SELECT * FROM epersongroup2eperson WHERE eperson_id= ?", e
                            .getID());

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

                    int childID = row.getIntColumn("eperson_group_id");

                    groupIDs.add(new Integer(childID));
                }
            }
            finally
            {
                // close the TableRowIterator to free up resources
                if (tri != null)
                    tri.close();
            }
        }
        // Also need to get all "Special Groups" user is a member of!
        // Otherwise, you're ignoring the user's membership to these groups!
        // However, we only do this is we are looking up the special groups
        // of the current user, as we cannot look up the special groups
        // of a user who is not logged in.
        if ((c.getCurrentUser() == null) || (((c.getCurrentUser() != null) && (c.getCurrentUser().getID() == e.getID()))))
        {
            Group[] specialGroups = c.getSpecialGroups();
            for(Group special : specialGroups)
            {
                groupIDs.add(new Integer(special.getID()));
            }
        }

        // all the users are members of the anonymous group
        groupIDs.add(new Integer(0));
       
        // now we have all owning groups, also grab all parents of owning groups
        // yes, I know this could have been done as one big query and a union,
        // but doing the Oracle port taught me to keep to simple SQL!

        String groupQuery = "";

        Iterator i = groupIDs.iterator();

        // Build a list of query parameters
        Object[] parameters = new Object[groupIDs.size()];
        int idx = 0;
        while (i.hasNext())
        {
            int groupID = ((Integer) i.next()).intValue();

            parameters[idx++] = new Integer(groupID);
           
            groupQuery += "child_id= ? ";
            if (i.hasNext())
                groupQuery += " OR ";
        }

        // was member of at least one group
        // NOTE: even through the query is built dynamicaly all data is seperated into the
        // the parameters array.
        TableRowIterator tri = DatabaseManager.queryTable(c, "group2groupcache",
                "SELECT * FROM group2groupcache WHERE " + groupQuery,
                parameters);

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

                int parentID = row.getIntColumn("parent_id");

                groupIDs.add(new Integer(parentID));
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
                tri.close();
        }

        return groupIDs;
    }
View Full Code Here


        // two queries - first to get all groups which are a member of this group
        // second query gets all members of each group in the first query
        Set<Integer> epeopleIDs = new HashSet<Integer>();
       
        // Get all groups which are a member of this group
        TableRowIterator tri = DatabaseManager.queryTable(c, "group2groupcache",
                "SELECT * FROM group2groupcache WHERE parent_id= ? ",
                g.getID());
       
        Set<Integer> groupIDs = new HashSet<Integer>();

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

                int childID = row.getIntColumn("child_id");

                groupIDs.add(new Integer(childID));
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
                tri.close();
        }

        // now we have all the groups (including this one)
        // it is time to find all the EPeople who belong to those groups
        // and filter out all duplicates

        Object[] parameters = new Object[groupIDs.size()+1];
        int idx = 0;
        Iterator i = groupIDs.iterator();

        // don't forget to add the current group to this query!
        parameters[idx++] = new Integer(g.getID());
        String epersonQuery = "eperson_group_id= ? ";
        if (i.hasNext())
            epersonQuery += " OR ";
       
        while (i.hasNext())
        {
            int groupID = ((Integer) i.next()).intValue();
            parameters[idx++] = new Integer(groupID);
           
            epersonQuery += "eperson_group_id= ? ";
            if (i.hasNext())
                epersonQuery += " OR ";
        }

        //get all the EPerson IDs
        // Note: even through the query is dynamicaly built all data is seperated
        // into the parameters array.
        tri = DatabaseManager.queryTable(c, "epersongroup2eperson",
                "SELECT * FROM epersongroup2eperson WHERE " + epersonQuery,
                parameters);

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

                int epersonID = row.getIntColumn("eperson_id");

                epeopleIDs.add(new Integer(epersonID));
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
                tri.close();
        }

        return epeopleIDs;
    }
View Full Code Here

            s = "name";
        }

        // 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.queryTable(
            context, "epersongroup",
                "SELECT * FROM epersongroup ORDER BY "+s);

        try
        {
            List gRows = rows.toList();

            Group[] groups = new Group[gRows.size()];

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

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

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

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

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

        TableRowIterator rows =
      DatabaseManager.query(context, dbquery, paramArr);

        try
        {
            List groupRows = rows.toList();
            Group[] groups = new Group[groupRows.size()];

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

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

                if (fromCache != null)
                {
                    groups[i] = fromCache;
                }
                else
                {
                    groups[i] = new Group(context, row);
                }
            }
            return groups;
        }
        finally
        {
            if (rows != null)
                rows.close();
        }
  }
View Full Code Here

     *
     */
    private void rethinkGroupCache() throws SQLException
    {
        // read in the group2group table
        TableRowIterator tri = DatabaseManager.queryTable(myContext, "group2group",
                "SELECT * FROM group2group");

        Map<Integer,Set<Integer>> parents = new HashMap<Integer,Set<Integer>>();

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

                Integer parentID = new Integer(row.getIntColumn("parent_id"));
                Integer childID = new Integer(row.getIntColumn("child_id"));

                // if parent doesn't have an entry, create one
                if (!parents.containsKey(parentID))
                {
                    Set<Integer> children = new HashSet<Integer>();

                    // add child id to the list
                    children.add(childID);
                    parents.put(parentID, children);
                }
                else
                {
                    // parent has an entry, now add the child to the parent's record
                    // of children
                    Set<Integer> children =  parents.get(parentID);
                    children.add(childID);
                }
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
                tri.close();
        }

        // now parents is a hash of all of the IDs of groups that are parents
        // and each hash entry is a hash of all of the IDs of children of those
        // parent groups
View Full Code Here

    {
        ArrayList mylist = new ArrayList();

        String myquery = "SELECT * FROM WorkflowItem WHERE owner= ? ";

        TableRowIterator tri = DatabaseManager.queryTable(c,
            "workflowitem", myquery,e.getID());

        try
        {
            while (tri.hasNext())
            {
                mylist.add(new WorkflowItem(c, tri.next()));
            }
        }
        finally
        {
            if (tri != null)
                tri.close();
        }

        return mylist;
    }
View Full Code Here

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

        TableRowIterator tri = null;

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

            if (tri.hasNext())
            {
                TableRow row = tri.next();
                return (int) row.getLongColumn("num");
            }
            else
            {
                return 0;
            }
        }
        catch (SQLException e)
        {
            log.error("caught exception: ", e);
            throw new BrowseException(e);
        }
        finally
        {
            if (tri != null)
            {
                tri.close();
            }
        }
    }
View Full Code Here

        String myquery = "SELECT workflowitem.* FROM workflowitem, TaskListItem" +
            " WHERE tasklistitem.eperson_id= ? " +
            " AND tasklistitem.workflow_id=workflowitem.workflow_id";

        TableRowIterator tri = DatabaseManager
                .queryTable(c, "workflowitem", myquery, e.getID());

        try
        {
            while (tri.hasNext())
            {
                mylist.add(new WorkflowItem(c, tri.next()));
            }
        }
        finally
        {
            if (tri != null)
                tri.close();
        }
       
        return mylist;
    }
View Full Code Here

     * @see org.dspace.browse.BrowseDAO#doMaxQuery(java.lang.String, java.lang.String, int)
     */
    public String doMaxQuery(String column, String table, int itemID)
            throws BrowseException
    {
        TableRowIterator tri = null;

        try
        {
            String query = "SELECT MAX(" + column + ") AS max_value FROM " + table + " WHERE item_id=?";

            Object[] params = { new Integer(itemID) };
            tri = DatabaseManager.query(context, query, params);

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

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

        if (column == null || value == null)
            return 0;

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

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

            buildSelectStatement(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 || (value != null && valueField != null && tableDis != null && tableMap != null))
            {
                queryBuf.append(" AND ").append("mappings.item_id=");
                queryBuf.append(table).append(".item_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

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.