1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
4 * Copyright (C) 2008 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
25 #include "nsStringAPI.h"
26 #include "nsComponentManagerUtils.h"
30 /* Project includes */
33 #include "aaIBalance.h"
34 #include "aaISqliteChannel.h"
35 #include "aaISqlRequest.h"
36 #include "aaBaseLoaders.h"
37 #include "aaSaveKeys.h"
39 #include "aaSaveIncome.h"
41 aaSaveIncome::aaSaveIncome()
45 NS_IMPL_ISUPPORTS2(aaSaveIncome
,
48 /* aaISqlTransaction */
50 aaSaveIncome::SetParam(nsISupports
*aParam
)
53 mIncome
= do_QueryInterface(aParam
, &rv
);
54 NS_ENSURE_SUCCESS(rv
, rv
);
60 aaSaveIncome::Execute(aaISqliteChannel
*aChannel
, nsISupports
* * _retval
)
62 NS_ENSURE_ARG_POINTER(aChannel
);
63 NS_ENSURE_TRUE(mIncome
, NS_ERROR_NOT_INITIALIZED
);
64 NS_ENSURE_ARG_POINTER(mIncome
->PickFlow());
66 return mIncome
->Sync(this, aChannel
);
71 aaSaveIncome::Insert(aaISqliteChannel
*aChannel
)
74 if (!mIncomeInserter
) {
75 mIncomeInserter
= do_CreateInstance(AA_INCOME_INSERT_CONTRACT
, &rv
);
76 NS_ENSURE_SUCCESS(rv
, rv
);
79 rv
= mIncomeInserter
->SetFilter(mIncome
);
80 NS_ENSURE_SUCCESS(rv
, rv
);
82 rv
= aChannel
->Open(mIncomeInserter
, nsnull
);
83 NS_ENSURE_SUCCESS(rv
, rv
);
89 aaSaveIncome::Update(aaISqliteChannel
*aChannel
)
93 if (!mIncomeUpdater
) {
94 mIncomeUpdater
= do_CreateInstance(AA_INCOME_UPDATE_CONTRACT
, &rv
);
95 NS_ENSURE_SUCCESS(rv
, rv
);
98 rv
= mIncomeUpdater
->SetFilter(mIncome
);
99 NS_ENSURE_SUCCESS(rv
, rv
);
101 rv
= aChannel
->Open(mIncomeUpdater
, nsnull
);
102 NS_ENSURE_SUCCESS(rv
, rv
);
108 aaSaveIncome::Close(aaISqliteChannel
*aChannel
)
112 if (!mIncomeCloser
) {
113 mIncomeCloser
= do_CreateInstance(AA_INCOME_CLOSE_CONTRACT
, &rv
);
114 NS_ENSURE_SUCCESS(rv
, rv
);
117 rv
= mIncomeCloser
->SetFilter(mIncome
);
118 NS_ENSURE_SUCCESS(rv
, rv
);
120 rv
= aChannel
->Open(mIncomeCloser
, nsnull
);
121 NS_ENSURE_SUCCESS(rv
, rv
);
127 aaSaveIncome::Delete(aaISqliteChannel
*aChannel
)
131 if (!mIncomeDeleter
) {
132 mIncomeDeleter
= do_CreateInstance(AA_INCOME_DELETE_CONTRACT
, &rv
);
133 NS_ENSURE_SUCCESS(rv
, rv
);
136 rv
= mIncomeDeleter
->SetFilter(mIncome
);
137 NS_ENSURE_SUCCESS(rv
, rv
);
139 rv
= aChannel
->Open(mIncomeDeleter
, nsnull
);
140 NS_ENSURE_SUCCESS(rv
, rv
);