Changeset 3593
- Timestamp:
- Jul 24, 2007, 9:55:04 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/DbControl.java
r3526 r3593 982 982 983 983 /** 984 Reload the item from the database. If the item isn't attached to this 985 DbControl it is automatically reattaced first. 986 987 @param item The item to reload 988 @since 2.4 989 */ 990 public void refreshItem(BasicItem item) 991 { 992 if (isClosed()) throw new ConnectionClosedException(); 993 sc.updateLastAccess(); 994 if (!isAttached(item)) reattachItem(item); 995 HibernateUtil.refresh(hSession, item.getData()); 996 } 997 998 /** 984 999 Check if an item is attached to this <code>DbControl</code>. 985 1000 An item is attached if it is found in either the item cache (existing items -
trunk/src/core/net/sf/basedb/core/HibernateUtil.java
r3526 r3593 1087 1087 } 1088 1088 1089 /** 1090 Reload the data from the database for a given entity. 1091 @param session The Hibernate session which is connected to the 1092 database 1093 @param data The entity to reload 1094 @since 2.4 1095 */ 1096 static void refresh(Session session, BasicData data) 1097 { 1098 assert session != null : "session == null"; 1099 try 1100 { 1101 session.refresh(data); 1102 } 1103 catch(HibernateException ex) 1104 { 1105 throw new BaseException(ex); 1106 } 1107 } 1108 1089 1109 /** 1090 1110 Checks if an item with the specified ID exists in the database. -
trunk/src/core/net/sf/basedb/core/Install.java
r3592 r3593 101 101 method. 102 102 */ 103 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(3 7).intValue();103 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(38).intValue(); 104 104 105 105 public static synchronized void createTables(boolean update, final ProgressReporter progress) -
trunk/src/core/net/sf/basedb/core/Job.java
r3523 r3593 25 25 26 26 import net.sf.basedb.core.Transactional.Action; 27 import net.sf.basedb.core.data.ExperimentData; 27 28 import net.sf.basedb.core.data.JobData; 28 29 import net.sf.basedb.core.data.MessageData; … … 283 284 } 284 285 } 286 /** 287 Grant read permission if the logged in user has read permission to the 288 experiment the job belongs to. 289 */ 290 @Override 291 void initPermissions(int granted, int denied) 292 { 293 ExperimentData parent = getData().getExperiment(); 294 if (parent != null) 295 { 296 int parentPermission = 0; 297 if (parent.getId() != 0) 298 { 299 parentPermission = getSessionControl().getAllPermissions(parent); 300 } 301 else 302 { 303 BasicItem<?> basicParent = getDbControl().getItem(BasicItem.class, parent); 304 parentPermission = Permission.grant(basicParent.getPermissions()); 305 } 306 if (Permission.hasPermission(parentPermission, Permission.READ)) 307 { 308 granted |= Permission.grant(Permission.READ); 309 } 310 } 311 super.initPermissions(granted, denied); 312 } 285 313 // ------------------------------------------- 286 314 … … 351 379 getData().setPluginConfiguration(pluginConfiguration.getData()); 352 380 getData().setParameterVersion(pluginConfiguration.getParameterVersion()); 381 } 382 } 383 384 /** 385 Get the experiment this job is a part of. 386 @return The <code>Experiment</code> item, or null if this job 387 isn't part of an experiment 388 @since 2.4 389 */ 390 public Experiment getExperiment() 391 { 392 return getDbControl().getItem(Experiment.class, getData().getExperiment()); 393 } 394 /** 395 Set the experiment this job is part of. Once an experiment has been set, it 396 can't be changed. 397 @since 2.4 398 */ 399 void setExperiment(Experiment experiment) 400 { 401 ExperimentData current = getData().getExperiment(); 402 ExperimentData next = experiment == null ? null : experiment.getData(); 403 if (current == null) 404 { 405 getData().setExperiment(next); 406 } 407 else if (!current.equals(next)) 408 { 409 throw new PermissionDeniedException("A job can only be part of one experiment: " + this); 353 410 } 354 411 } -
trunk/src/core/net/sf/basedb/core/Transformation.java
r2998 r3593 151 151 } 152 152 153 // Keep reference to job so we can call Job.setExperiment at end of transaction 154 private Job job; 155 153 156 /** 154 157 Creates a new experiment item from the given data. … … 215 218 */ 216 219 /** 217 Delete the product bioassaysets. 220 Delete the product bioassaysets when deleting this transction. 221 Set the experiment for the job when creating this transction. 218 222 */ 219 223 void onBeforeCommit(Transactional.Action action) … … 224 228 { 225 229 deleteProducts(); 230 } 231 else if (action == Transactional.Action.CREATE) 232 { 233 if (job != null) 234 { 235 getDbControl().refreshItem(job); 236 job.setExperiment(getExperiment()); 237 } 226 238 } 227 239 } … … 358 370 private void setJob(Job job) 359 371 { 372 this.job = job; 360 373 getData().setJob(job == null ? null : job.getData()); 361 374 } -
trunk/src/core/net/sf/basedb/core/Update.java
r3557 r3593 31 31 import java.util.Date; 32 32 import java.util.HashMap; 33 import java.util.HashSet; 33 34 import java.util.List; 34 35 import java.util.Map; 36 import java.util.Set; 35 37 36 38 import org.hibernate.mapping.Table; 37 39 38 40 import net.sf.basedb.core.data.DataCubeData; 41 import net.sf.basedb.core.data.ExperimentData; 39 42 import net.sf.basedb.core.data.FileData; 40 43 import net.sf.basedb.core.data.FormulaData; 44 import net.sf.basedb.core.data.JobData; 41 45 import net.sf.basedb.core.data.MeasuredBioMaterialData; 42 46 import net.sf.basedb.core.data.PlateData; 43 47 import net.sf.basedb.core.data.PlateMappingData; 44 48 import net.sf.basedb.core.data.SchemaVersionData; 49 import net.sf.basedb.core.data.TransformationData; 45 50 import net.sf.basedb.core.dbengine.DbEngine; 46 51 import net.sf.basedb.core.dbengine.TableInfo; … … 439 444 </td> 440 445 </tr> 446 447 <tr> 448 <td>38</td> 449 <td> 450 <ul> 451 <li>Added {@link net.sf.basedb.core.data.JobData#getExperiment()}. 452 </ul> 453 The update sets the experiment for jobs that belong to a single 454 transformation. 455 </td> 456 </tr> 441 457 442 458 </table> … … 617 633 } 618 634 619 if (schemaVersion < 36) 620 { 621 if (progress != null) progress.display((int)(35*progress_factor), "--Updating schema version: " + schemaVersion + " -> 36..."); 622 schemaVersion = setSchemaVersionInTransaction(session, 36); 623 } 624 625 635 // Schemaversion 36-37 only updates the version number 626 636 if (schemaVersion < 37) 627 637 { … … 630 640 } 631 641 642 if (schemaVersion < 38) 643 { 644 if (progress != null) progress.display((int)(37*progress_factor), "--Updating schema version: " + schemaVersion + " -> 38..."); 645 schemaVersion = updateToSchemaVersion38(session); 646 } 647 632 648 /* 633 if (schemaVersion < 3 8)634 { 635 if (progress != null) progress.display((int)(3 7*progress_factor), "--Updating schema version: " + schemaVersion + " -> 38...");636 schemaVersion = setSchemaVersionInTransaction(session, 3 8);649 if (schemaVersion < 39) 650 { 651 if (progress != null) progress.display((int)(38*progress_factor), "--Updating schema version: " + schemaVersion + " -> 39..."); 652 schemaVersion = setSchemaVersionInTransaction(session, 39); 637 653 - or - 638 schemaVersion = updateToSchemaVersion3 8(session);654 schemaVersion = updateToSchemaVersion39(session); 639 655 } 640 656 ... etc... … … 1386 1402 return schemaVersion; 1387 1403 } 1404 1405 /** 1406 Set the experiment for jobs that belong to a single transformation. 1407 @return The new schema version (=38) 1408 */ 1409 private static int updateToSchemaVersion38(org.hibernate.Session session) 1410 { 1411 final int schemaVersion = 38; 1412 org.hibernate.Transaction tx = null; 1413 try 1414 { 1415 tx = HibernateUtil.newTransaction(session); 1416 1417 // Load all transformations 1418 org.hibernate.Query query = HibernateUtil.createQuery(session, 1419 "SELECT t FROM TransformationData t"); 1420 1421 List<TransformationData> transformations = HibernateUtil.loadList(TransformationData.class, query); 1422 Map<JobData, Set<ExperimentData>> experiments = new HashMap<JobData, Set<ExperimentData>>(); 1423 for (TransformationData transformation : transformations) 1424 { 1425 JobData job = transformation.getJob(); 1426 ExperimentData experiment = transformation.getExperiment(); 1427 if (!experiments.containsKey(job)) 1428 { 1429 experiments.put(job, new HashSet<ExperimentData>()); 1430 } 1431 experiments.get(job).add(experiment); 1432 } 1433 1434 for (Map.Entry<JobData, Set<ExperimentData>> entry : experiments.entrySet()) 1435 { 1436 JobData job = entry.getKey(); 1437 Set<ExperimentData> jobExperiments = entry.getValue(); 1438 if (jobExperiments.size() == 1) 1439 { 1440 job.setExperiment(jobExperiments.iterator().next()); 1441 System.out.println("Setting experiment '" + job.getExperiment().getName() + "' to job " + job.getName()); 1442 } 1443 } 1444 1445 // Update the shcema version number 1446 setSchemaVersion(session, schemaVersion); 1447 1448 // Commit the changes 1449 HibernateUtil.commit(tx); 1450 log.info("updateToSchemaVersion38: OK"); 1451 } 1452 catch (BaseException ex) 1453 { 1454 if (tx != null) HibernateUtil.rollback(tx); 1455 log.error("updateToSchemaVersion38: FAILED", ex); 1456 throw ex; 1457 } 1458 return schemaVersion; 1459 } 1460 1388 1461 1389 1462 /** -
trunk/src/core/net/sf/basedb/core/data/ExperimentData.java
r2962 r3593 313 313 this.transformations = transformations; 314 314 } 315 316 private Set<JobData> jobs; 317 /** 318 This is the inverse end. 319 @see JobData#getExperiment() 320 @since 2.4 321 @hibernate.set lazy="true" inverse="true" cascade="delete" 322 @hibernate.collection-key column="`experiment_id`" 323 @hibernate.collection-one-to-many class="net.sf.basedb.core.data.JobData" 324 */ 325 Set<JobData> getJobs() 326 { 327 return jobs; 328 } 329 void setJobs(Set<JobData> jobs) 330 { 331 this.jobs = jobs; 332 } 315 333 316 334 private Set<AnnotationTypeData> experimentalFactors; -
trunk/src/core/net/sf/basedb/core/data/JobData.java
r3480 r3593 128 128 } 129 129 130 private ExperimentData experiment; 131 132 /** 133 The experiment this job is a part of. 134 @since 2.4 135 @hibernate.many-to-one column="`experiment_id`" not-null="false" outer-join="false" 136 */ 137 public ExperimentData getExperiment() 138 { 139 return experiment; 140 } 141 public void setExperiment(ExperimentData experiment) 142 { 143 this.experiment = experiment; 144 } 145 130 146 private int parameterVersion; 131 147 /** -
trunk/www/my_base/messages/view_message.jsp
r2978 r3593 157 157 <td><%=HTML.encodeTags(job.getName())%></td> 158 158 </tr> 159 <tr valign= top>159 <tr valign="top"> 160 160 <td class="prompt">Description</td> 161 161 <td> … … 163 163 </td> 164 164 </tr> 165 <tr valign= top>165 <tr valign="top"> 166 166 <td class="prompt">Priority</td> 167 167 <td> … … 169 169 </td> 170 170 </tr> 171 <tr valign= top>171 <tr valign="top"> 172 172 <td class="prompt">Status</td> 173 173 <td> … … 175 175 </td> 176 176 </tr> 177 <tr valign= top>177 <tr valign="top"> 178 178 <td class="prompt">Percent complete</td> 179 179 <td> … … 206 206 </td> 207 207 </tr> 208 <tr valign= top>208 <tr valign="top"> 209 209 <td class="prompt">Created</td> 210 210 <td> … … 212 212 </td> 213 213 </tr> 214 <tr valign= top>214 <tr valign="top"> 215 215 <td class="prompt">Started</td> 216 216 <td> … … 218 218 </td> 219 219 </tr> 220 <tr valign= top>220 <tr valign="top"> 221 221 <td class="prompt">Ended</td> 222 222 <td> … … 224 224 </td> 225 225 </tr> 226 <tr valign= top>226 <tr valign="top"> 227 227 <td class="prompt">Server</td> 228 228 <td> … … 230 230 </td> 231 231 </tr> 232 <tr valign=top> 232 <tr valign="top"> 233 <td class="prompt">User</td> 234 <td> 235 <base:propertyvalue item="<%=job%>" property="owner.name" /> 236 </td> 237 </tr> 238 <tr valign="top"> 239 <td class="prompt">Experiment</td> 240 <td> 241 <base:propertyvalue item="<%=job%>" property="experiment.name" /> 242 </td> 243 </tr> 244 <tr valign="top"> 233 245 <td class="prompt">Plugin</td> 234 246 <td> … … 236 248 </td> 237 249 </tr> 238 <tr valign= top>250 <tr valign="top"> 239 251 <td class="prompt">Configuration</td> 240 252 <td> -
trunk/www/views/jobs/list_jobs.jsp
r3190 r3593 329 329 title="Type" 330 330 enumeration="<%=pluginTypes%>" 331 sortable="true" 332 filterable="true" 333 exportable="true" 334 /> 335 <tbl:columndef 336 id="experiment" 337 property="experiment.name" 338 datatype="string" 339 title="Experiment" 331 340 sortable="true" 332 341 filterable="true" … … 579 588 %> 580 589 </tbl:cell> 590 <tbl:cell column="experiment" 591 ><base:propertyvalue 592 item="<%=item%>" 593 property="experiment" 594 enableEditLink="<%=mode.hasEditLink()%>" 595 enablePropertyLink="<%=mode.hasPropertyLink()%>" 596 /></tbl:cell> 581 597 <tbl:cell column="plugin"> 582 598 <% -
trunk/www/views/jobs/view_job.jsp
r3523 r3593 155 155 <td><%=HTML.niceFormat(job.getDescription())%></td> 156 156 </tr> 157 <tr valign= top>157 <tr valign="top"> 158 158 <td class="prompt">Priority</td> 159 159 <td> … … 161 161 </td> 162 162 </tr> 163 <tr valign= top>163 <tr valign="top"> 164 164 <td class="prompt">Status</td> 165 165 <td> … … 198 198 </td> 199 199 </tr> 200 <tr valign= top>200 <tr valign="top"> 201 201 <td class="prompt">Created</td> 202 202 <td> … … 204 204 </td> 205 205 </tr> 206 <tr valign= top>206 <tr valign="top"> 207 207 <td class="prompt">Started</td> 208 208 <td> … … 210 210 </td> 211 211 </tr> 212 <tr valign= top>212 <tr valign="top"> 213 213 <td class="prompt">Ended</td> 214 214 <td> … … 216 216 </td> 217 217 </tr> 218 <tr valign= top>218 <tr valign="top"> 219 219 <td class="prompt">Server</td> 220 220 <td> … … 222 222 </td> 223 223 </tr> 224 <tr valign=top> 224 <tr valign="top"> 225 <td class="prompt">User</td> 226 <td> 227 <base:propertyvalue item="<%=job%>" property="owner.name" /> 228 </td> 229 </tr> 230 <tr valign="top"> 231 <td class="prompt">Experiment</td> 232 <td> 233 <base:propertyvalue item="<%=job%>" property="experiment.name" /> 234 </td> 235 </tr> 236 <tr valign="top"> 225 237 <td class="prompt">Plugin</td> 226 238 <td> … … 228 240 </td> 229 241 </tr> 230 <tr valign= top>242 <tr valign="top"> 231 243 <td class="prompt">Configuration</td> 232 244 <td>
Note: See TracChangeset
for help on using the changeset viewer.