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 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 <abstract/aacore.h>
25 #include "nsIMutableArray.h"
26 #include "nsComponentManagerUtils.h"
27 #include "nsStringAPI.h"
28 #include "nsEmbedString.h"
31 #include "unstable/mozIStorageConnection.h"
32 #include "unstable/mozIStorageStatement.h"
34 /* Project includes */
35 #include <abstract/base/aaIEntity.h>
36 #include <abstract/base/aaIResource.h>
37 #include <abstract/base/aaIFlow.h>
38 #include <abstract/storage/aaILoadQuery.h>
39 #include "aaLoadFlowChart.h"
41 #define AA_LOADFLOWEXT_SELECT_QUERY "SELECT flow.id, flow.tag, flow.entity_id,\
42 entity.tag, giveR.id, giveR.tag, takeR.id, takeR.tag, flow.rate\
44 LEFT JOIN entity ON flow.entity_id == entity.id\
45 LEFT JOIN term AS giveT ON giveT.flow_id = flow.id AND giveT.side = 0\
46 LEFT JOIN resource AS giveR ON giveR.id = giveT.resource_id\
47 LEFT JOIN term AS takeT ON takeT.flow_id = flow.id AND takeT.side = 1\
48 LEFT JOIN resource AS takeR ON takeR.id = takeT.resource_id"
49 #define AA_FLOW_ITEM_CONTRACT "@aasii.org/base/flow;1"
50 #define AA_INCOMEFLOW_CONTRACT "@aasii.org/base/income-flow;1"
52 aaLoadFlowChart::aaLoadFlowChart(nsISupports
*aOuter
)
57 aaLoadFlowChart::~aaLoadFlowChart()
61 NS_IMPL_ISUPPORTS_INHERITED0(aaLoadFlowChart
,
65 aaLoadFlowChart::Load()
68 rv
= aaLoadQuery::Load();
69 NS_ENSURE_SUCCESS(rv
, rv
);
71 nsCOMPtr
<aaIFlow
> pl
= do_CreateInstance(AA_INCOMEFLOW_CONTRACT
, &rv
);
72 NS_ENSURE_TRUE(pl
, rv
);
74 return mData
->AppendElement(pl
, PR_FALSE
);
79 aaLoadFlowChart::getSelectQuery() const
81 return AA_LOADFLOWEXT_SELECT_QUERY
;
85 aaLoadFlowChart::fetchRow()
88 PRInt64 flowId
, entityId
, giveId
, takeId
;
91 rv
= mStatement
->GetInt64(0, &flowId
);
95 rv
= mStatement
->GetUTF8String(1, tag
);
99 rv
= mStatement
->GetInt64(2, &entityId
);
103 nsEmbedCString entityTag
;
104 rv
= mStatement
->GetUTF8String(3, entityTag
);
108 rv
= mStatement
->GetInt64(4, &giveId
);
112 nsEmbedCString giveTag
;
113 rv
= mStatement
->GetUTF8String(5, giveTag
);
117 rv
= mStatement
->GetInt64(6, &takeId
);
121 nsEmbedCString takeTag
;
122 rv
= mStatement
->GetUTF8String(7, takeTag
);
126 rv
= mStatement
->GetDouble(8, &rate
);
130 nsCOMPtr
<aaIEntity
> entity(do_CreateInstance("@aasii.org/base/entity;1"));
134 rv
= entity
->SetId(entityId
);
138 rv
= entity
->SetTag(NS_ConvertUTF8toUTF16(entityTag
));
142 nsCOMPtr
<aaIResource
> give(do_CreateInstance("@aasii.org/base/resource;1"));
146 rv
= give
->SetId(giveId
);
150 rv
= give
->SetTag(NS_ConvertUTF8toUTF16(giveTag
));
154 nsCOMPtr
<aaIResource
> take(do_CreateInstance("@aasii.org/base/resource;1"));
158 rv
= take
->SetId(takeId
);
162 rv
= take
->SetTag(NS_ConvertUTF8toUTF16(takeTag
));
167 CallCreateInstance("@aasii.org/base/flow;1", nsnull
, &flow
);
172 flow
->SetTag(NS_ConvertUTF8toUTF16(tag
));
173 flow
->SetEntity(entity
);
174 flow
->SetGiveResource(give
);
175 flow
->SetTakeResource(take
);