811 ASSERT(result == KErrNone); |
811 ASSERT(result == KErrNone); |
812 ASSERT(aTransactor.iTransactionErrorKey == KUnspecifiedKey); |
812 ASSERT(aTransactor.iTransactionErrorKey == KUnspecifiedKey); |
813 aKeyInfo = 0; |
813 aKeyInfo = 0; |
814 // must release locks otherwise shared repository will not commit changes |
814 // must release locks otherwise shared repository will not commit changes |
815 // failed transactions have already released their locks |
815 // failed transactions have already released their locks |
816 ReleaseTransactionLock(aTransactor); |
816 TServerResources::iObserver->ReleaseTransactionLock(aTransactor,iSimRep->Uid()); |
817 } |
817 } |
818 |
818 |
819 // transactions that haven't made any changes can be closed at any time |
819 // transactions that haven't made any changes can be closed at any time |
820 if (aTransactor.IsInActiveReadWriteTransaction() && |
820 if (aTransactor.IsInActiveReadWriteTransaction() && |
821 (aTransactor.iTransactionSettings.Count() > 0)) |
821 (aTransactor.iTransactionSettings.Count() > 0)) |
832 aTransactor.Deque(); |
832 aTransactor.Deque(); |
833 |
833 |
834 return result; |
834 return result; |
835 } |
835 } |
836 |
836 |
837 /** Cancels the transaction, discarding changes. |
|
838 @post Not in a transaction |
|
839 */ |
|
840 void CSharedRepository::CancelTransaction(CRepositoryTransactor& aTransactor) |
|
841 { |
|
842 if (aTransactor.IsInTransaction()) |
|
843 { |
|
844 ReleaseTransactionLock(aTransactor); |
|
845 CObservable::TSharedRepositoryInfo* shrepinfo = TServerResources::iObserver->SharedRepositoryInfo(iSimRep->Uid()); |
|
846 ASSERT(shrepinfo); |
|
847 shrepinfo->iTransactors.Remove(aTransactor); |
|
848 //Remove the link to the next transaction |
|
849 aTransactor.iLink.iNext = NULL; |
|
850 aTransactor.Deque(); |
|
851 } |
|
852 } |
|
853 |
|
854 TInt CSharedRepository::FailTransaction(CRepositoryTransactor& aTransactor, TInt aError, TUint32 aErrorKey) |
837 TInt CSharedRepository::FailTransaction(CRepositoryTransactor& aTransactor, TInt aError, TUint32 aErrorKey) |
855 { |
838 { |
856 ASSERT(aError != KErrNone); // must fail for a reason |
839 ASSERT(aError != KErrNone); // must fail for a reason |
857 if (aTransactor.IsInActiveTransaction()) |
840 if (aTransactor.IsInActiveTransaction()) |
858 { |
841 { |
859 // locks cannot be removed from a failed transaction, so release before failing |
842 // locks cannot be removed from a failed transaction, so release before failing |
860 ReleaseTransactionLock(aTransactor); |
843 TServerResources::iObserver->ReleaseTransactionLock(aTransactor,iSimRep->Uid()); |
861 aTransactor.SetFailed(aError, aErrorKey); |
844 aTransactor.SetFailed(aError, aErrorKey); |
862 } |
845 } |
863 return aError; // to allow "return FailTransaction(error, errorKey);" - error written once |
846 return aError; // to allow "return FailTransaction(error, errorKey);" - error written once |
864 } |
847 } |
865 |
848 |
909 return KErrNone; |
892 return KErrNone; |
910 } |
893 } |
911 return KErrLocked; |
894 return KErrLocked; |
912 } |
895 } |
913 |
896 |
914 /** Private helper method which releases any read/write locks held in the shared repository |
897 |
915 by this transactor. Caller must set transactor's state or remove from queue as appropriate. |
|
916 @param aTransactor transactor whose read/write locks are to be released. |
|
917 @post Any read/write locks held by transactor are released. |
|
918 */ |
|
919 void CSharedRepository::ReleaseTransactionLock(CRepositoryTransactor& aTransactor) |
|
920 { |
|
921 CObservable::TSharedRepositoryInfo* shrepinfo = TServerResources::iObserver->SharedRepositoryInfo(iSimRep->Uid()); |
|
922 ASSERT(shrepinfo); |
|
923 if (aTransactor.IsInActiveConcurrentReadWriteTransaction()) |
|
924 { |
|
925 shrepinfo->iNumActiveConcurrentReadWriteTransactions--; |
|
926 ASSERT(shrepinfo->iNumActiveConcurrentReadWriteTransactions >= 0); // sanity check |
|
927 } |
|
928 else if (aTransactor.IsInActiveReadTransaction()) |
|
929 { |
|
930 shrepinfo->iPessimisticTransactionLockCount--; |
|
931 ASSERT(shrepinfo->iPessimisticTransactionLockCount >= 0); // sanity check |
|
932 } |
|
933 else if (aTransactor.IsInActiveExclusiveReadWriteTransaction()) |
|
934 { |
|
935 // can only be one exclusive read/write transaction active (lock value -1) |
|
936 ASSERT(shrepinfo->iPessimisticTransactionLockCount == -1); |
|
937 shrepinfo->iPessimisticTransactionLockCount = 0; |
|
938 } |
|
939 } |
|
940 |
898 |
941 void CSharedRepository::ExternalizeCre(RWriteStream& aStream) const |
899 void CSharedRepository::ExternalizeCre(RWriteStream& aStream) const |
942 { |
900 { |
943 iSimRep->ExternalizeCre(TServerResources::iPersistsVersion,aStream); |
901 iSimRep->ExternalizeCre(TServerResources::iPersistsVersion,aStream); |
944 } |
902 } |