|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "LOGDUP.H" |
|
17 #include "LOGFILTQ.H" |
|
18 #include "LOGQUERY.H" |
|
19 #include "logservpanic.h" |
|
20 #include "LogServDatabaseTransactionInterface.h" |
|
21 #include "LogServResourceInterpreter.h" |
|
22 #include "LogServDatabaseChangeInterface.h" |
|
23 #include "LogServSqlStrings.h" |
|
24 |
|
25 CLogDuplicate::CLogDuplicate(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority) : |
|
26 CLogActive(aPriority), |
|
27 iDatabase(aDatabase) |
|
28 { |
|
29 } |
|
30 |
|
31 CLogDuplicate::~CLogDuplicate() |
|
32 { |
|
33 Cancel(); |
|
34 delete iFilterList; |
|
35 } |
|
36 |
|
37 void CLogDuplicate::ConstructL() |
|
38 { |
|
39 iFilterList = new(ELeave) CLogFilterList; |
|
40 } |
|
41 |
|
42 CLogDuplicate* CLogDuplicate::NewL(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority) |
|
43 { |
|
44 CLogDuplicate* self = new(ELeave) CLogDuplicate(aDatabase, aPriority); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 TBool CLogDuplicate::StartL(TLogId aId, TLogRecentList aRecentList, const CLogFilter& aFilter, TRequestStatus& aStatus) |
|
52 { |
|
53 if (aRecentList == KLogNullRecentList) |
|
54 return EFalse; |
|
55 |
|
56 iId = aId; |
|
57 iRecentList = aRecentList; |
|
58 iFilterList->Reset(); |
|
59 iFilterList->AppendL(&aFilter); |
|
60 |
|
61 Queue(aStatus); |
|
62 TRequestStatus* status = &iStatus; |
|
63 User::RequestComplete(status, KErrNone); |
|
64 SetActive(); |
|
65 return ETrue; |
|
66 } |
|
67 |
|
68 void CLogDuplicate::DoRunL() |
|
69 { |
|
70 RLogDynBuf expr; |
|
71 TLogFilterExprBuilder exprBuilder(iDatabase); |
|
72 exprBuilder.BuildExprLC(expr, *iFilterList, KLogAnd); |
|
73 TheSql.Format(KLogSqlSelectDuplicateString, iRecentList, &expr.DesC(), iId); |
|
74 CleanupStack::PopAndDestroy(&expr); |
|
75 |
|
76 RLogDbView view; |
|
77 view.PrepareLC(iDatabase.DTIDatabase(), TheSql); |
|
78 if(view.FirstL()) |
|
79 { |
|
80 // Begin a transaction |
|
81 TBool inTransaction = iDatabase.DTIInTransaction(); |
|
82 if(!inTransaction) |
|
83 { |
|
84 iDatabase.DTIBeginWithRollBackProtectionLC(); |
|
85 } |
|
86 // Get column ids |
|
87 static TDbColNo idColNo = 0; |
|
88 static TDbColNo duplicateColNo = 0; |
|
89 if(idColNo == 0) |
|
90 { |
|
91 CDbColSet* cs = view.ColSetL(); |
|
92 idColNo = cs->ColNo(KLogFieldIdString); |
|
93 duplicateColNo = cs->ColNo(KLogFieldEventDuplicateString); |
|
94 delete cs; |
|
95 } |
|
96 // Iterate through the events |
|
97 do |
|
98 { |
|
99 // Get current event id |
|
100 view.GetL(); |
|
101 const TLogId id = view.ColInt32(idColNo); |
|
102 // Set the latest recent? |
|
103 if(iId < 0) |
|
104 { |
|
105 iId = id; |
|
106 } |
|
107 // Make the change |
|
108 view.UpdateL(); |
|
109 iId == id ? view.SetColNullL(duplicateColNo) : view.SetColL(duplicateColNo, iId); |
|
110 view.PutL(); |
|
111 // This is a "hidden" change. It may affect the contents of a view, but the actual event hasn't changed |
|
112 iDatabase.DTIChangeInterface().DCISubmitChangedEventContextL(ELogChangeTypeEventChangedHidden, id); |
|
113 } |
|
114 while(view.NextL()); |
|
115 // Commit changes |
|
116 if(!inTransaction) |
|
117 { |
|
118 iDatabase.DTICommitAndCancelRollbackProtectionL(); |
|
119 } |
|
120 } |
|
121 CleanupStack::PopAndDestroy(&view); |
|
122 } |
|
123 |
|
124 void CLogDuplicate::DoComplete(TInt& aStatus) |
|
125 { |
|
126 // Ignoring all errors because if an error occurs whilst detecting duplicate events |
|
127 // it should not stop us actually adding the event to the log |
|
128 aStatus = KErrNone; |
|
129 } |