Ignore:
Timestamp:
2013-09-04T15:19:34+12:00 (11 years ago)
Author:
sjm84
Message:

Some fixes for when using the derby database as well as some improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java

    r28201 r28210  
    197197        try
    198198        {
    199             String query = "SELECT username, action FROM usertracker WHERE site = '" + site + "' and collection = '" + collection + "' and oid = '" + oid + "' ORDER BY time";
     199            String query = "SELECT username, action, time FROM usertracker WHERE site = '" + site + "' and collection = '" + collection + "' and oid = '" + oid + "' ORDER BY time";
    200200            Statement state = conn.createStatement();
    201201            ResultSet rs = state.executeQuery(query);
     
    203203
    204204            HashSet<String> usernamesSeen = new HashSet<String>();
    205 
    206205            while (rs.next())
    207206            {
     207                String timeStr = rs.getString("time");
     208                long time = Long.parseLong(timeStr);
     209
     210                if (System.currentTimeMillis() - time > 6000)
     211                {
     212                    continue;
     213                }
     214
    208215                HashMap<String, String> action = new HashMap<String, String>();
    209216                if (!usernamesSeen.contains(rs.getString("username")))
     
    217224            }
    218225            state.close();
     226
     227            clearOldUserActions();
    219228        }
    220229        catch (Exception ex)
     
    223232        }
    224233        return actions;
     234    }
     235
     236    public void clearOldUserActions()
     237    {
     238        try
     239        {
     240            Statement state = conn.createStatement();
     241            state.execute("DELETE FROM usertracker WHERE (CAST (time AS BIGINT)) < " + (System.currentTimeMillis() - 20000));
     242            conn.commit();
     243            state.close();
     244        }
     245        catch (Exception ex)
     246        {
     247            ex.printStackTrace();
     248        }
    225249    }
    226250
     
    572596        Statement state = conn.createStatement();
    573597        ResultSet rs = state.executeQuery(sql_find_user);
     598        conn.commit();
    574599        while (rs.next())
    575600        {
     
    583608            users.add(user);
    584609        }
    585         conn.commit();
    586 
     610        state.close();
     611
     612        state = conn.createStatement();
    587613        for (HashMap<String, String> user : users)
    588614        {
    589615            ResultSet gs = state.executeQuery("SELECT role FROM " + ROLES + " WHERE username = '" + user.get("username") + "'");
     616            conn.commit();
    590617
    591618            String group = "";
Note: See TracChangeset for help on using the changeset viewer.