- Timestamp:
- Mar 13, 2007, 11:05:42 AM (16 years ago)
- Location:
- trunk/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/formatter/FormatterSettings.java
r2981 r3190 80 80 { 81 81 sc.setUserClientSetting("formatter.number.decimals", Integer.toString(numDecimals)); 82 sc.setSessionSetting("formatter.number", null); 82 sc.setSessionSetting("formatter.double", null); 83 sc.setSessionSetting("formatter.float", null); 83 84 } 84 85 -
trunk/src/core/common-queries.xml
r3086 r3190 202 202 <description> 203 203 Load the ID of all users which has a quota group from one of the given groups. 204 </description> 205 </query> 206 207 <query id="GET_USER_IDS_FOR_PROJECT" type="HQL"> 208 <sql> 209 SELECT up.userId 210 FROM UserProjects up 211 WHERE up.projectId = :projectId 212 </sql> 213 <description> 214 Load the ID of all users which are direct member of the given project 215 </description> 216 </query> 217 218 <query id="GET_GROUP_IDS_FOR_PROJECT" type="HQL"> 219 <sql> 220 SELECT gp.groupId 221 FROM GroupProjects gp 222 WHERE gp.projectId = :projectId 223 </sql> 224 <description> 225 Load the ID of all groups which are direct member of the given project 204 226 </description> 205 227 </query> … … 2523 2545 </query> 2524 2546 2525 <query id="GET_ SUM_USED_QUANTITY_EVENTS" type="HQL">2526 <sql> 2527 SELECT evt.bioMaterial, SUM(evt.usedQuantity)2547 <query id="GET_USED_QUANTITY_EVENTS" type="HQL"> 2548 <sql> 2549 SELECT evt.bioMaterial, evt.usedQuantity 2528 2550 FROM BioMaterialEventData evt 2529 GROUP BY evt.bioMaterial 2530 </sql> 2531 <description> 2532 A HQL query that loads the sum of the used quantity 2533 grouped by the biomaterial for all BioMaterialEvent:s. 2534 </description> 2535 </query> 2536 2537 <query id="GET_SUM_USED_QUANTITY_SOURCES" type="HQL"> 2538 <sql> 2539 SELECT index(src), SUM(src.usedQuantity) 2551 </sql> 2552 <description> 2553 A HQL query that loads the biomaterial and the used quantity 2554 for all BioMaterialEvent:s. 2555 </description> 2556 </query> 2557 2558 <query id="GET_USED_QUANTITY_SOURCES" type="HQL"> 2559 <sql> 2560 SELECT index(src), src.usedQuantity 2540 2561 FROM BioMaterialEventData evt 2541 2562 JOIN evt.sources src 2542 GROUP BY index(src) 2543 </sql> 2544 <description> 2545 A HQL query that loads the sum of the used quantity 2546 grouped by the biomaterial for all sources to 2547 BioMaterialEvent:s. 2563 </sql> 2564 <description> 2565 A HQL query that loads the used quantity 2566 for all sources to BioMaterialEvent:s. 2548 2567 </description> 2549 2568 </query> -
trunk/src/core/net/sf/basedb/core/Group.java
r2898 r3190 29 29 import net.sf.basedb.core.query.Hql; 30 30 31 import java.util.Collection; 31 32 import java.util.HashSet; 32 33 import java.util.Set; … … 124 125 public static Set<Integer> getGroupsRecursive(DbControl dc, Set<Integer> groups) 125 126 { 127 return getGroupsRecursive(dc.getHibernateSession(), groups); 128 } 129 130 static Set<Integer> getGroupsRecursive(org.hibernate.Session session, Collection<Integer> groups) 131 { 126 132 Set<Integer> allGroups = new HashSet<Integer>(groups); 127 133 if (allGroups.size() > 0) 128 134 { 129 135 130 org.hibernate.Query query = HibernateUtil.getPredefinedQuery( dc.getHibernateSession(),136 org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, 131 137 "GET_CHILDGROUPS_IDS_FOR_GROUPS"); 132 138 /* … … 143 149 return allGroups; 144 150 } 151 145 152 146 153 /** -
trunk/src/core/net/sf/basedb/core/Install.java
r3086 r3190 102 102 method. 103 103 */ 104 public static final int NEW_SCHEMA_VERSION = 29;105 104 public static final int NEW_SCHEMA_VERSION = 30; 105 106 106 public static synchronized void createTables(boolean update, final ProgressReporter progress) 107 107 throws BaseException -
trunk/src/core/net/sf/basedb/core/Keyring.java
r2981 r3190 450 450 Load all users which are member of at least one group where the 451 451 logged in user is also a member and put that information 452 in the {@link #users} variable. 452 in the {@link #users} variable. If a project is active, also load the members 453 and owner of that project. 453 454 */ 454 455 private void loadUsers(org.hibernate.Session session) 455 456 throws BaseException 456 457 { 457 Set<Integer> temp ;458 Set<Integer> temp = new HashSet<Integer>(); 458 459 try 459 460 { … … 468 469 */ 469 470 query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER); 470 temp = new HashSet<Integer>(HibernateUtil.loadList(Integer.class, query));471 temp.addAll(HibernateUtil.loadList(Integer.class, query)); 471 472 472 473 // Get the users that have a quota group among the same groups … … 479 480 query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER); 480 481 temp.addAll(HibernateUtil.loadList(Integer.class, query)); 482 } 483 484 if (projectId != 0) 485 { 486 // Get the owner of the active project 487 ProjectData pd = HibernateUtil.loadData(session, ProjectData.class, projectId); 488 temp.add(pd.getOwner().getId()); 481 489 482 users = Collections.unmodifiableSet(temp); 483 } 490 // Get direct members of the active project 491 org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_IDS_FOR_PROJECT"); 492 /* 493 SELECT up.userId 494 FROM UserProjects up 495 WHERE up.projectId = :projectId 496 */ 497 query.setInteger("projectId", projectId); 498 temp.addAll(HibernateUtil.loadList(Integer.class, query)); 499 500 // Get groups that are direct members of the active project 501 query = HibernateUtil.getPredefinedQuery(session, "GET_GROUP_IDS_FOR_PROJECT"); 502 /* 503 SELECT gp.groupId 504 FROM GroupProjects gp 505 WHERE gp.projectId = :projectId 506 */ 507 query.setInteger("projectId", projectId); 508 // Load the direct groups and subgroups 509 Set<Integer> projectGroups = Group.getGroupsRecursive(session, HibernateUtil.loadList(Integer.class, query)); 510 511 // Load users that are members of the project groups 512 temp.addAll(User.getAllMembers(session, projectGroups)); 513 514 } 515 users = Collections.unmodifiableSet(temp); 484 516 } 485 517 catch (HibernateException ex) … … 717 749 { 718 750 if (getReload() && !reload()) projectData = null; 751 int oldProjectId = projectId; 719 752 if (projectData == null) 720 753 { … … 725 758 { 726 759 projectId = projectData.getId(); 727 org.hibernate.Session session = null; 728 org.hibernate.Transaction tx = null; 729 try 730 { 731 session = HibernateUtil.newSession(); 732 tx = HibernateUtil.newTransaction(session); 733 loadMaxProjectPermission(session, projectData); 734 loadProjectKeys(session); 735 } 736 catch (BaseException ex) 737 { 738 projectId = 0; 739 maxProjectPermission = 0; 740 throw ex; 741 } 742 finally 743 { 744 if (tx != null) HibernateUtil.commit(tx); 745 if (session != null) HibernateUtil.close(session); 746 } 747 } 760 } 761 reload = projectId != oldProjectId; 748 762 } 749 763 -
trunk/src/core/net/sf/basedb/core/Trashcan.java
r2218 r3190 90 90 if (item.hasPermission(Permission.DELETE)) 91 91 { 92 if (!useLimit || (index >= firstItem && index < lastItem)) 92 SharedItem parent = item instanceof ChildItem ? 93 dc.getItem(SharedItem.class, ((ChildItem)item).getSharedParent()) : null; 94 95 if ( (parent != null && parent.isOwner()) || (parent == null)) 93 96 { 94 items.add((Removable)item); 97 if (!useLimit || (index >= firstItem && index < lastItem)) 98 { 99 items.add((Removable)item); 100 } 101 index++; 102 totalItems++; 95 103 } 96 index++;97 totalItems++;98 104 } 99 105 } -
trunk/src/core/net/sf/basedb/core/Update.java
r3120 r3190 346 346 <tr> 347 347 <td>29</td> 348 <td> 349 No changes at all except increasing the schema version number. 350 The veryfication of remaining quantity is moved to next update of schema version. 351 </td> 352 </tr> 353 354 <tr> 355 <td>30</td> 348 356 <td> 349 357 No schema change as such, but we need to verify and possibly update the … … 505 513 } 506 514 515 516 if (schemaVersion < 30) 517 { 518 if (progress != null) progress.display((int)(29*progress_factor), "--Updating schema version: " + schemaVersion + " -> 30..."); 519 schemaVersion = updateToSchemaVersion30(session); 520 } 521 507 522 /* 508 if (schemaVersion < 3 0)509 { 510 if (progress != null) progress.display((int)( 29*progress_factor), "--Updating schema version: " + schemaVersion + " -> 30...");511 schemaVersion = setSchemaVersionInTransaction(session, 3 0);523 if (schemaVersion < 31) 524 { 525 if (progress != null) progress.display((int)(30*progress_factor), "--Updating schema version: " + schemaVersion + " -> 30..."); 526 schemaVersion = setSchemaVersionInTransaction(session, 31); 512 527 - or - 513 schemaVersion = updateToSchemaVersion3 0(session);528 schemaVersion = updateToSchemaVersion31(session); 514 529 } 515 530 ... etc... … … 1071 1086 /** 1072 1087 Vefify and update the remaining quantity of all biomaterials. 1073 @return The new schema version (= 29)1088 @return The new schema version (=30) 1074 1089 */ 1075 private static int updateToSchemaVersion 29(org.hibernate.Session session)1090 private static int updateToSchemaVersion30(org.hibernate.Session session) 1076 1091 throws BaseException 1077 1092 { 1078 final int schemaVersion = 29;1093 final int schemaVersion = 30; 1079 1094 1080 1095 org.hibernate.Transaction tx = null; … … 1086 1101 Map<MeasuredBioMaterialData, Float> remaining = new HashMap<MeasuredBioMaterialData, Float>(); 1087 1102 1088 // Load sum ofused quantity for all events1103 // Load used quantity for all events 1089 1104 org.hibernate.Query eventQuery = HibernateUtil.getPredefinedQuery(session, 1090 "GET_ SUM_USED_QUANTITY_EVENTS");1091 /*1092 SELECT evt.bioMaterial, SUM(evt.usedQuantity)1093 FROM BioMaterialEventData evt1094 GROUP BY evt.bioMaterial1095 */1096 // Load sum ofused quantity for sources to all events1105 "GET_USED_QUANTITY_EVENTS"); 1106 /* 1107 SELECT evt.bioMaterial, evt.usedQuantity 1108 FROM BioMaterialEventData evt 1109 */ 1110 1111 // Load used quantity for sources to all events 1097 1112 org.hibernate.Query sourcesQuery = HibernateUtil.getPredefinedQuery(session, 1098 "GET_ SUM_USED_QUANTITY_SOURCES");1113 "GET_USED_QUANTITY_SOURCES"); 1099 1114 /* 1100 SELECT index(src), SUM(src.usedQuantity)1115 SELECT index(src), src.usedQuantity 1101 1116 FROM BioMaterialEventData evt 1102 JOIN evt.sources src 1103 GROUP BY index(src) 1117 JOIN evt.sources src 1104 1118 */ 1105 1119 List<Object[]> events = HibernateUtil.loadList(Object[].class, eventQuery); … … 1107 1121 1108 1122 // Calculate the remaining quantity for each biomaterial 1109 // o[0] = biomaterial, o[1] = sum of used quantity1123 // o[0] = biomaterial, o[1] = used quantity 1110 1124 for (Object[] o : events) 1111 1125 { 1112 MeasuredBioMaterialData bioMaterial = (MeasuredBioMaterialData)o[0]; 1113 Double sumUsedQuantity = (Double)o[1];1114 if ( sumUsedQuantity != null)1126 MeasuredBioMaterialData bioMaterial = (MeasuredBioMaterialData)o[0]; 1127 Float usedQuantity = (Float)o[1]; 1128 if (usedQuantity != null) 1115 1129 { 1116 1130 Float currentRemaining = remaining.get(bioMaterial); 1117 1131 if (currentRemaining == null) currentRemaining = 0.0f; 1118 currentRemaining = currentRemaining - sumUsedQuantity.floatValue();1132 currentRemaining = currentRemaining - usedQuantity; 1119 1133 remaining.put(bioMaterial, currentRemaining); 1120 1134 } … … 1143 1157 // Commit the changes 1144 1158 HibernateUtil.commit(tx); 1145 log.info("updateToSchemaVersion 29: OK");1159 log.info("updateToSchemaVersion30: OK"); 1146 1160 } 1147 1161 catch (BaseException ex) 1148 1162 { 1149 1163 if (tx != null) HibernateUtil.rollback(tx); 1150 log.error("updateToSchemaVersion 29: FAILED", ex);1164 log.error("updateToSchemaVersion30: FAILED", ex); 1151 1165 throw ex; 1152 1166 } -
trunk/src/core/net/sf/basedb/core/User.java
r2902 r3190 36 36 37 37 import java.util.ArrayList; 38 import java.util.Collection; 38 39 import java.util.Date; 39 40 import java.util.HashSet; … … 124 125 public static Set<Integer> getAllMembers(DbControl dc, Set<Integer> groupIds) 125 126 { 127 return getAllMembers(dc.getHibernateSession(), groupIds); 128 } 129 130 static Set<Integer> getAllMembers(org.hibernate.Session session, Collection<Integer> groupIds) 131 { 126 132 Set<Integer> userIds = new HashSet<Integer>(); 127 133 if (groupIds != null && groupIds.size() > 0) 128 134 { 129 org.hibernate.Session session = dc.getHibernateSession();130 135 // Get the users which are members of the same groups 131 136 org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_IDS_FOR_GROUPS"); … … 149 154 } 150 155 return userIds; 151 152 } 156 } 157 153 158 154 159 /** -
trunk/src/core/net/sf/basedb/core/query/Hql.java
r2497 r3190 27 27 import net.sf.basedb.core.InvalidDataException; 28 28 import net.sf.basedb.core.InvalidUseOfNullException; 29 import net.sf.basedb.core.data.BasicData; 29 30 30 31 import java.util.regex.Pattern; … … 55 56 56 57 /** 57 Create an expression representing an item . In the query the actual58 value used is the id of the entity. See {@link #property(String, String)}59 for a code example.58 Create an expression representing an item which is a subclass of BasicItem. 59 In the query the actual value used is the id of the entity. 60 See {@link #property(String, String)} for a code example. 60 61 61 62 @param entity The entity 62 @throws InvalidDataException If the etity is null 63 @throws InvalidDataException If the entity is null 64 @see #entity(BasicData) 63 65 */ 64 66 public static Expression entity(BasicItem entity) … … 69 71 } 70 72 73 /** 74 Create an expression representing an item which is a subclass of BasicData, 75 for example a reporter. In the query the actual value used is the id of the entity. 76 See {@link #property(String, String)} for a code example. 77 78 @param entity The entity 79 @throws InvalidDataException If the entity is null 80 @see #entity(BasicItem) 81 @since 2.2.2 82 */ 83 public static Expression entity(BasicData entity) 84 throws InvalidDataException 85 { 86 if (entity == null) throw new InvalidUseOfNullException("entity"); 87 return new HqlEntityExpression(entity); 88 } 89 71 90 /** 72 91 Same as <code>property(null, property)</code>. -
trunk/src/core/net/sf/basedb/core/query/HqlEntityExpression.java
r2667 r3190 29 29 import net.sf.basedb.core.BasicItem; 30 30 import net.sf.basedb.core.BaseException; 31 import net.sf.basedb.core.data.BasicData; 31 32 32 33 /** … … 39 40 @version 2.0 40 41 @see Hql#entity(BasicItem) 42 @see Hql#entity(BasicData) 41 43 @base.modified $Date$ 42 44 */ … … 44 46 implements Expression 45 47 { 46 private final BasicItem item; 48 private final int id; 49 private final String item; 47 50 48 51 HqlEntityExpression(BasicItem item) 49 52 { 50 this.item = item; 53 this.id = item.getId(); 54 this.item = item.toString(); 55 } 56 57 /** 58 @since 2.2.2 59 */ 60 HqlEntityExpression(BasicData data) 61 { 62 this.id = data.getId(); 63 this.item = data.toString(); 51 64 } 52 65 … … 60 73 if (query.getQueryType() == QueryType.HQL) 61 74 { 62 return Integer.toString(i tem.getId());75 return Integer.toString(id); 63 76 } 64 77 else … … 81 94 public String toString() 82 95 { 83 return item .toString();96 return item; 84 97 } 85 98 // ------------------------------------------- -
trunk/src/core/net/sf/basedb/util/Values.java
r2981 r3190 628 628 result.append(lNumber).append("."); 629 629 String theDecimals = Long.toString(Math.round(fNumber*exp-lNumber*exp)); 630 result.append(theDecimals);631 630 if (theDecimals.length() < decimals) 632 631 { … … 636 635 } 637 636 } 637 result.append(theDecimals); 638 638 } 639 639 if (unit != null) result.append(unit); -
trunk/src/core/net/sf/basedb/util/overview/ExperimentOverview.java
r3062 r3190 281 281 this.annotatableParents = new HashMap<Annotatable, Set<Annotatable>>(); 282 282 283 // Load 'Required for MIAME' annotation types 283 // Load 'Required for MIAME' annotation types (parameter='false' must also be set) 284 284 ItemQuery<AnnotationType> query = initQuery(AnnotationType.getQuery(null), "name"); 285 285 query.restrict( 286 286 Restrictions.eq( 287 287 Hql.property("requiredForMiame"), 288 Expressions.parameter("flag", true, Type.BOOLEAN) 288 Expressions.parameter("miameFlag", true, Type.BOOLEAN) 289 ) 290 ); 291 query.restrict( 292 Restrictions.eq( 293 Hql.property("protocolParameter"), 294 Expressions.parameter("parameterFlag", false, Type.BOOLEAN) 289 295 ) 290 296 ); … … 619 625 for (Node factorNode : efNode.getChildren()) 620 626 { 621 Node annotationNode = annotationsNode.getChild("annotationtype." + factorNode.getItem().getId()); 627 Node annotationNode = annotationsNode == null ? 628 null : annotationsNode.getChild("annotationtype." + factorNode.getItem().getId()); 622 629 if (annotationNode == null) 623 630 { … … 1541 1548 failures.add(new Failure(Validator.MISSING_PARAMETER, parentNode, 1542 1549 "Missing parameter value: " + pp.getName(), 1543 new Fix("Add parameter value ", parentItem, pp, false)));1550 new Fix("Add parameter value for: " + pp.getName(), parentItem, pp, false))); 1544 1551 } 1545 1552 } … … 1579 1586 { 1580 1587 AnnotationType at = a.getAnnotationType(); 1581 if (protocol == null || protocol.isParameter(at)) 1588 // Protocol parameters are handled elsewhere 1589 if (protocol == null || !protocol.isParameter(at)) 1582 1590 { 1583 1591 Node atNode = new Node("annotationtype."+at.getId(), at.getName(), annotationsNode, at);
Note: See TracChangeset
for help on using the changeset viewer.