litesoft
@ 948
litesoft / trunk / GWT_Sandbox / Prioritizer / src / org / litesoft / prioritizer / server / pos / Story.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
package org.litesoft.prioritizer.server.pos; import org.litesoft.commonfoundation.typeutils.*; import org.litesoft.core.simpletypes.*; import org.litesoft.core.util.*; import org.litesoft.orsup.base.*; import org.litesoft.orsup.selection.*; import org.litesoft.orsup.transact.*; import org.litesoft.prioritizer.server.*; import java.io.*; import java.sql.*; public class Story extends StoryGO { public Story( Transaction pTransaction ) { super( pTransaction ); } public Story( ConstructionControl pConstructionControl ) { super( pConstructionControl ); } @Override protected void transactionDisposed() { mCommitUpdate = null; super.transactionDisposed(); } private transient StoryUpdate mCommitUpdate = null; @Override public Serializable aboutToCommit( Timestamp pTransactionTimestamp ) { Transaction zTransaction = getTransaction(); if ( isNew() ) { if ( getRestrictedResource() == null ) { setRestrictedResource( CurrentRestrictedResourceAccessor.get().getRequiredRestrictedResource().freshIntoIfNotAlreadyIn( zTransaction ) ); } if ( getCreator() == null ) { setCreator( CurrentUserAccessor.get().getRequiredUser().freshIntoIfNotAlreadyIn( zTransaction ) ); } } else if ( isAnyAttributeChanged() && notJustPriorityLastChangedBy() ) { if ( mCommitUpdate != null ) { removeUpdates( mCommitUpdate ); mCommitUpdate.requestDelete(); mCommitUpdate = null; } User zUser = CurrentUserAccessor.get().getRequiredUser().freshIntoIfNotAlreadyIn( zTransaction ); addUpdates( mCommitUpdate = new StoryUpdate( zTransaction, zUser ) ); for ( String zChangedAttributeName : getChangedAttributeNames() ) { AttributeAccessorSCD<Story> zACD = getAccessorSCDrequired( zChangedAttributeName ); if ( zACD.isPersisted() ) { if ( zACD == CD_Priority ) { setPriorityLastChangedBy( zUser.getFullName() ); } if ( zACD != CD_PriorityLastChangedBy ) { String zName = zACD.getName(); String zOldValue = Objects.toString( getOriginalValueFor( zName ) ); mCommitUpdate.addChanges( new StoryChange( zTransaction, zName, zOldValue ) ); } } } } return super.aboutToCommit( pTransactionTimestamp ); } private boolean notJustPriorityLastChangedBy() { int changes = numberOfAttributeChanged(); return (changes > 1) || ((changes == 1) && !isAttributeChanged( CD_PriorityLastChangedBy )); } private GenericReference<String> mChanges = null; @Override protected void LLclearChanges() { mChanges = GenericReference.dispose( mChanges ); } @Override public String getChanges() { if ( mChanges == null ) { mChanges = new GenericReference<String>( createChanges() ); } return mChanges.get(); } private String createChanges() { StringBuilder sb = new StringBuilder(); for ( StoryUpdate zUpdate : getUpdates() ) { zUpdate.toString( sb ); } return sb.toString(); } public static WhereClause getLimitToCurrentRestrictedResource() { // Add filter to where clause to only select based on RestrictedResource. RestrictedResource zRestrictedResource = CurrentRestrictedResourceAccessor.get().getRequiredRestrictedResource(); return WhereClauseFactory.INSTANCE.isEqual( CD_RestrictedResource, zRestrictedResource ); } } |