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) 2007,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 "nsISupportsPrimitives.h"
26 #include "nsStringAPI.h"
27 #include "nsComponentManagerUtils.h"
31 /* Project includes */
32 #include "aaIResource.h"
33 #include "aaISqliteChannel.h"
34 #include "aaISqlRequest.h"
35 #include "aaBaseLoaders.h"
36 #include "aaSaveKeys.h"
37 #include "aaSaveAsset.h"
39 aaSaveAsset::aaSaveAsset()
43 NS_IMPL_ISUPPORTS1(aaSaveAsset
,
45 /* aaISqlTransaction */
47 aaSaveAsset::SetParam(nsISupports
*aParam
)
50 mAsset
= do_QueryInterface(aParam
, &rv
);
51 NS_ENSURE_SUCCESS(rv
, rv
);
57 aaSaveAsset::Execute(aaISqliteChannel
*aChannel
, nsISupports
* * _retval
)
59 NS_ENSURE_ARG_POINTER(aChannel
);
60 NS_ENSURE_TRUE(mAsset
, NS_ERROR_NOT_INITIALIZED
);
64 rv
= mAsset
->GetId(&id
);
65 NS_ENSURE_SUCCESS(rv
, rv
);
68 rv
= insert(aChannel
);
69 NS_ENSURE_SUCCESS(rv
, rv
);
72 rv
= update(aChannel
);
73 if (NS_FAILED(rv
)) return rv
;
84 aaSaveAsset::insert(aaISqliteChannel
*aChannel
)
88 mResourceInserter
= do_CreateInstance(AA_INSERT_RESOURCE_CONTRACT
, &rv
);
89 NS_ENSURE_SUCCESS(rv
, rv
);
91 mIdLoader
= do_CreateInstance(AA_LOADLASTID_CONTRACT
, &rv
);
92 NS_ENSURE_SUCCESS(rv
, rv
);
94 nsCOMPtr
<nsISupportsCString
> filter
95 = do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID
, &rv
);
96 NS_ENSURE_SUCCESS(rv
, rv
);
98 rv
= filter
->SetData(NS_LITERAL_CSTRING("asset"));
99 NS_ENSURE_SUCCESS(rv
, rv
);
101 rv
= mIdLoader
->SetFilter(filter
);
102 NS_ENSURE_SUCCESS(rv
, rv
);
104 mInserter
= do_CreateInstance(AA_INSERT_ASSET_CONTRACT
, &rv
);
105 NS_ENSURE_SUCCESS(rv
, rv
);
108 rv
= mInserter
->SetFilter(mAsset
);
109 NS_ENSURE_SUCCESS(rv
, rv
);
111 rv
= aChannel
->Open(mInserter
, nsnull
);
112 NS_ENSURE_SUCCESS(rv
, rv
);
114 nsCOMPtr
<aaILoadObserver
> id
115 = do_CreateInstance(AA_SQLIDLISTENER_CONTRACT
, mAsset
, &rv
);
116 NS_ENSURE_SUCCESS(rv
, rv
);
118 rv
= aChannel
->Open(mIdLoader
, id
);
119 NS_ENSURE_SUCCESS(rv
, rv
);
121 rv
= mResourceInserter
->SetFilter(mAsset
);
122 NS_ENSURE_SUCCESS(rv
, rv
);
124 rv
= aChannel
->Open(mResourceInserter
, nsnull
);
125 NS_ENSURE_SUCCESS(rv
, rv
);
131 aaSaveAsset::update(aaISqliteChannel
*aChannel
)
135 mUpdater
= do_CreateInstance(AA_UPDATE_ASSET_CONTRACT
, &rv
);
136 NS_ENSURE_SUCCESS(rv
, rv
);
139 rv
= mUpdater
->SetFilter(mAsset
);
140 NS_ENSURE_SUCCESS(rv
, rv
);
142 rv
= aChannel
->Open(mUpdater
, nsnull
);
143 if (NS_FAILED(rv
)) return rv
;