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 "aaLoadFlow.h"
41 #define AA_LOADFLOW_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"
51 aaLoadFlow::aaLoadFlow(nsISupports
*aOuter
)
56 aaLoadFlow::~aaLoadFlow()
60 NS_IMPL_ISUPPORTS_INHERITED0(aaLoadFlow
,
65 aaLoadFlow::getSelectQuery() const
67 return AA_LOADFLOW_SELECT_QUERY
;
71 aaLoadFlow::fetchRow()
74 PRInt64 flowId
, entityId
, giveId
, takeId
;
77 rv
= mStatement
->GetInt64(0, &flowId
);
81 rv
= mStatement
->GetUTF8String(1, tag
);
85 rv
= mStatement
->GetInt64(2, &entityId
);
89 nsEmbedCString entityTag
;
90 rv
= mStatement
->GetUTF8String(3, entityTag
);
94 rv
= mStatement
->GetInt64(4, &giveId
);
98 nsEmbedCString giveTag
;
99 rv
= mStatement
->GetUTF8String(5, giveTag
);
103 rv
= mStatement
->GetInt64(6, &takeId
);
107 nsEmbedCString takeTag
;
108 rv
= mStatement
->GetUTF8String(7, takeTag
);
112 rv
= mStatement
->GetDouble(8, &rate
);
116 nsCOMPtr
<aaIEntity
> entity(do_CreateInstance("@aasii.org/base/entity;1"));
120 rv
= entity
->SetId(entityId
);
124 rv
= entity
->SetTag(NS_ConvertUTF8toUTF16(entityTag
));
128 nsCOMPtr
<aaIResource
> give(do_CreateInstance("@aasii.org/base/resource;1"));
132 rv
= give
->SetId(giveId
);
136 rv
= give
->SetTag(NS_ConvertUTF8toUTF16(giveTag
));
140 nsCOMPtr
<aaIResource
> take(do_CreateInstance("@aasii.org/base/resource;1"));
144 rv
= take
->SetId(takeId
);
148 rv
= take
->SetTag(NS_ConvertUTF8toUTF16(takeTag
));
153 CallCreateInstance("@aasii.org/base/flow;1", nsnull
, &flow
);
158 flow
->SetTag(NS_ConvertUTF8toUTF16(tag
));
159 flow
->SetEntity(entity
);
160 flow
->SetGiveResource(give
);
161 flow
->SetTakeResource(take
);