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 "nsStringAPI.h"
29 /* Project includes */
30 #include "aaIHandler.h"
31 #include "aaLoadFlow.h"
33 #include "aaIColumnNameConverter.h"
34 #include "aaICondition.h"
36 #define AA_LOADFLOW_SELECT_QUERY "SELECT flow.id, flow.tag, flow.entity_id,\
37 entity.tag, giveT.resource_type, giveT.resource_id, giveM.alpha_code,\
38 giveA.tag, takeT.resource_type, takeT.resource_id, takeM.alpha_code,\
39 takeA.tag, flow.rate, flow.off_balance\
41 LEFT JOIN entity ON flow.entity_id == entity.id\
42 LEFT JOIN term AS giveT ON giveT.flow_id = flow.id AND giveT.side = 0\
43 LEFT JOIN money AS giveM ON giveT.resource_type = 1 AND giveM.id = giveT.resource_id\
44 LEFT JOIN asset AS giveA ON giveT.resource_type = 2 AND giveA.id = giveT.resource_id\
45 LEFT JOIN term AS takeT ON takeT.flow_id = flow.id AND takeT.side = 1\
46 LEFT JOIN money AS takeM ON takeT.resource_type = 1 AND takeM.id = takeT.resource_id\
47 LEFT JOIN asset AS takeA ON takeT.resource_type = 2 AND takeA.id = takeT.resource_id"
49 #define AA_LOADFLOW_SELECT_QUERY_FILTERED \
50 AA_LOADFLOW_SELECT_QUERY AA_SQL_WHERE_FILTER_MARK AA_SQL_ORDER_MARK
52 static struct aaLoadRequest::ColumnMap map
[] = {
57 ,{"give_resource.type", 4}
58 ,{"give_resource.id", 5}
59 ,{"give_resource.alpha_code", 6}
60 ,{"give_resource.tag", 7}
61 ,{"take_resource.type", 8}
62 ,{"take_resource.id", 9}
63 ,{"take_resource.alpha_code", 10}
64 ,{"take_resource.tag", 11}
70 /******************************************************************/
71 class CFlowNameConverter
: public aaIColumnNameConverter
74 CFlowNameConverter() {}
75 ~CFlowNameConverter() {}
77 NS_IMETHOD_(nsCAutoString
) convertName(const nsACString
& name
) const
80 if (name
.Compare("flow.tag") == 0) {
82 } else if(name
.Compare("flow.entity.tag") == 0) {
88 /******************************************************************/
90 aaLoadFlow::aaLoadFlow()
92 mSql
= AA_LOADFLOW_SELECT_QUERY
;
93 mSqlFiltered
= AA_LOADFLOW_SELECT_QUERY_FILTERED
;
97 NS_IMPL_ISUPPORTS_INHERITED0(aaLoadFlow
,
102 aaLoadFlow::GetParams(nsIArray
* * aParams
)
104 NS_ENSURE_ARG_POINTER(aParams
);
112 aaLoadFlow::Accept(aaIHandler
*aQuery
)
114 return aQuery
->HandleFlow(nsnull
);
118 aaLoadFlow::GetCondition(aaICondition
* pCondition
, nsACString
& aCondition
)
120 CFlowNameConverter cnvrt
;
121 NS_ENSURE_ARG_POINTER(pCondition
);
122 aCondition
.Truncate();
123 pCondition
->ToString(&cnvrt
, aCondition
);