transport: pass correct channel
[abstract.git] / storage / base / aaSaveIncome.cpp
blob931b29ec082a463754471e9f27445705a133852a
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: */
3 /*
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"
24 #include "nsCOMPtr.h"
25 #include "nsStringAPI.h"
26 #include "nsComponentManagerUtils.h"
28 /* Unfrozen API */
30 /* Project includes */
31 #include "aaIMoney.h"
32 #include "aaIFlow.h"
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,
46 aaISqlTransaction,
47 aaIStorager)
48 /* aaISqlTransaction */
49 NS_IMETHODIMP
50 aaSaveIncome::SetParam(nsISupports *aParam)
52 nsresult rv;
53 mIncome = do_QueryInterface(aParam, &rv);
54 NS_ENSURE_SUCCESS(rv, rv);
56 return NS_OK;
59 NS_IMETHODIMP
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);
69 /* aaIStorager */
70 NS_IMETHODIMP
71 aaSaveIncome::Insert(aaISqliteChannel *aChannel)
73 nsresult rv;
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);
85 return NS_OK;
88 NS_IMETHODIMP
89 aaSaveIncome::Update(aaISqliteChannel *aChannel)
91 nsresult rv;
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);
104 return NS_OK;
107 NS_IMETHODIMP
108 aaSaveIncome::Close(aaISqliteChannel *aChannel)
110 nsresult rv;
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);
123 return NS_OK;
126 NS_IMETHODIMP
127 aaSaveIncome::Delete(aaISqliteChannel *aChannel)
129 nsresult rv;
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);
142 return NS_OK;