Changeset 5203
- Timestamp:
- Dec 16, 2009, 12:56:43 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/SessionControl.java
r5185 r5203 47 47 import net.sf.basedb.core.authentication.AuthenticationInformation; 48 48 49 import java.util.ArrayList; 49 50 import java.util.Date; 50 51 import java.util.Iterator; … … 1631 1632 1632 1633 /** 1634 Get a list with the current default contexts. The list may include, 1635 only in-memory contexts, in-database contexts, or both. If both 1636 options are enabled and an in-memory context also has a database 1637 representation, both are included in the list. Eg. the list 1638 may include more than one context were {@link ItemContext#getContextId()} 1639 returns the same value. 1640 1641 @param inMemory If TRUE, the in-memory contexts are included in the list 1642 @param inDatabase If TRUE, the in-database contexts are included in the list 1643 @return A list with ItemContext objects 1644 @since 2.15 1645 */ 1646 public List<ItemContext> getAllCurrentContexts(boolean inMemory, boolean inDatabase) 1647 { 1648 List<ItemContext> all = new ArrayList<ItemContext>(); 1649 if (inMemory) 1650 { 1651 all.addAll(currentContexts.values()); 1652 } 1653 if (inDatabase) 1654 { 1655 org.hibernate.Session session = null; 1656 org.hibernate.Transaction tx = null; 1657 ItemContext context = null; 1658 try 1659 { 1660 session = HibernateUtil.newSession(); 1661 tx = HibernateUtil.newTransaction(session); 1662 1663 org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, 1664 "LOAD_USER_CONTEXTS"); 1665 /* 1666 SELECT ctx 1667 FROM ContextData ctx 1668 WHERE ctx.user.id = :user 1669 AND ctx.client.id = :client 1670 AND ctx.name = :name 1671 */ 1672 query.setInteger("user", loginInfo.userId); 1673 query.setInteger("client", getClientId()); 1674 query.setString("name", ItemContext.DEFAULT_NAME); 1675 List<ContextData> contexts = HibernateUtil.loadList(ContextData.class, query, this); 1676 for (ContextData ctx : contexts) 1677 { 1678 all.add(new ItemContext(ctx)); 1679 } 1680 HibernateUtil.commit(tx); 1681 } 1682 catch (BaseException ex) 1683 { 1684 if (tx != null) HibernateUtil.rollback(tx); 1685 throw ex; 1686 } 1687 finally 1688 { 1689 if (session != null) HibernateUtil.close(session); 1690 } 1691 } 1692 return all; 1693 } 1694 1695 /** 1633 1696 Delete all default contexts for the logged in user. 1634 1697 -
trunk/www/my_base/user/reset_filters.jsp
r4889 r5203 26 26 import="net.sf.basedb.core.SessionControl" 27 27 import="net.sf.basedb.core.Item" 28 import="net.sf.basedb.core.ItemContext" 28 29 import="net.sf.basedb.core.DbControl" 29 30 import="net.sf.basedb.core.User" … … 31 32 import="net.sf.basedb.clients.web.util.HTML" 32 33 import="net.sf.basedb.util.Values" 34 import="net.sf.basedb.util.ToStringComparator" 35 import="net.sf.basedb.util.NestedIterator" 36 import="java.util.Iterator" 33 37 import="java.util.List" 34 38 import="java.util.Set" … … 47 51 { 48 52 final User user = User.getById(dc, sc.getLoggedInUserId()); 53 final List<ItemContext> inMemory = sc.getAllCurrentContexts(true, false); 54 final List<ItemContext> inDatabase = sc.getAllCurrentContexts(false, true); 55 final Set<Item> items = new TreeSet<Item>(new ToStringComparator<Item>(false)); 56 final Set<Item> dbOnly = new HashSet<Item>(); 57 Iterator<ItemContext> it = new NestedIterator(inMemory, inDatabase); 58 for (ItemContext ctx : inMemory) 59 { 60 if (ctx.getNumPropertyFilters() > 0 || ctx.getSortProperty() != null) 61 { 62 items.add(ctx.getItemType()); 63 } 64 } 65 for (ItemContext ctx : inDatabase) 66 { 67 if (ctx.getNumPropertyFilters() > 0 || ctx.getSortProperty() != null) 68 { 69 if (items.add(ctx.getItemType())) dbOnly.add(ctx.getItemType()); 70 } 71 } 49 72 %> 50 51 73 <base:page type="popup" title="<%="Reset list settings for "+HTML.encodeTags(user.getName())%>"> 52 74 <base:head> … … 56 78 var frm = document.forms['preferences']; 57 79 frm.submit(); 80 } 81 function itemTypeOnChange() 82 { 83 var frm = document.forms['preferences']; 84 var dbOnly = frm.item_type[frm.item_type.selectedIndex].text.indexOf('*') >= 0; 85 frm.database.checked = dbOnly; 58 86 } 59 87 </script> … … 72 100 <table class="form" cellspacing=0> 73 101 <tr> 74 <td class="prompt">Which?</td> 102 <td class="prompt">Which list?</td> 103 <td> 104 <select name="item_type" onchange="itemTypeOnChange()"> 105 <option value="">- all - 106 <% 107 for (Item item : items) 108 { 109 %> 110 <option value="<%=item.name()%>"><%=dbOnly.contains(item) ? "* " : "" %><%=item%> 111 <% 112 } 113 %> 114 </select><br> 115 * = This setting is only in the database 116 </td> 117 </tr> 118 <tr> 119 <td class="prompt">Location</td> 75 120 <td> 76 121 <input type="checkbox" name="memory" value="1" checked disabled>In-memory<br> -
trunk/www/my_base/user/submit_user.jsp
r5060 r5203 157 157 { 158 158 boolean inDatabase = Values.getBoolean(request.getParameter("database")); 159 int numDeleted = sc.deleteCurrentContexts(null, true, inDatabase); 159 String itemType = Values.getStringOrNull(request.getParameter("item_type")); 160 Item item = itemType == null ? null : Item.valueOf(itemType); 161 int numDeleted = sc.deleteCurrentContexts(item, true, inDatabase); 160 162 message = numDeleted + " list settings deleted"; 161 163 }
Note: See TracChangeset
for help on using the changeset viewer.