10 #include "RelationalAccess/ISessionProxy.h"
11 #include "RelationalAccess/ITransaction.h"
12 #include "RelationalAccess/ITable.h"
13 #include "RelationalAccess/IQuery.h"
14 #include "RelationalAccess/ICursor.h"
15 #include "CoolKernel/IObject.h"
16 #include "CoolKernel/Record.h"
21 #include <unordered_map>
29 #define OI_BUFLEN 4200
30 #define OI_ROWCACHE 4200
33 cool::IObjectIteratorPtr coolitr) :
34 m_buflen(
OI_BUFLEN),m_inbuf(0),m_nextobj(0),
35 m_refValid(false),m_allDone(false),
36 m_folder(coracoolfolder),m_coolitr(coolitr) {
41 m_spec=
new coral::AttributeListSpecification();
42 for (coral::AttributeList::const_iterator itr=speclist.begin();
43 itr!=speclist.end();++itr) {
44 const coral::AttributeSpecification& aspec=itr->specification();
45 m_spec->extend(aspec.name(),aspec.typeName());
61 "CoraCoolObjectIter::next");
74 std::string fktypestr;
76 typedef std::vector<unsigned int> KeyVec;
77 typedef std::unordered_map<long long,KeyVec > KeyMap;
83 const cool::IObject& coolobj=
m_coolitr->currentRef();
88 coolobj.until(),coolobj.channelId(),
m_spec));
94 fktypestr=
payload[0].specification().typeName();
100 if (kdata==keymap.end()) {
102 kdata=keymap.insert(kdata,
103 KeyMap::value_type(ikeyval,KeyVec(8)));
104 KeyVec& keyvec=kdata->second;
109 KeyVec& keyvec=kdata->second;
117 qbuf.
getQuery(bwhere,coralkey,bfkeys,fktype[0].specification());
122 query->setCondition(bwhere,bfkeys);
126 KeyMap::const_iterator kdata=keymap.end();
133 const long long keyval=
numAttr(fktypestr,
res[coralkey]);
134 if (keyval!=okeyval || kdata==keymap.end()) {
135 kdata=keymap.find(keyval);
138 if (kdata!=keymap.end()) {
139 KeyVec keyvec=kdata->second;
140 for (KeyVec::const_iterator kitr=keyvec.begin();
141 kitr!=keyvec.end();++kitr) {
145 std::ostringstream skey;
146 skey <<
"CoraCool key remapping error for key " << keyval;
153 catch (coral::Exception&
e) {
167 const bool nextExists=
hasNext();
195 std::string spec1=a1.specification().typeName();
196 std::string spec2=a2.specification().typeName();
201 long long v1=
numAttr(spec1,a1);
226 return (
spec==
"long long" ||
spec==
"unsigned long long" ||
227 spec==
"int" ||
spec==
"unsigned int" ||
228 spec==
"long" ||
spec==
"unsigned long");
232 const coral::Attribute&
a)
const {
234 if (
spec==
"long long") {
235 v=
a.data<
long long>();
236 }
else if (
spec==
"unsigned long long") {
237 v=
static_cast<long long>(
a.data<
unsigned long long>());
238 }
else if (
spec==
"int") {
239 v=
static_cast<long long>(
a.data<
int>());
240 }
else if (
spec==
"unsigned int") {
241 v=
static_cast<long long>(
a.data<
unsigned int>());
242 }
else if (
spec==
"long") {
243 v=
static_cast<long long>(
a.data<
long>());
244 }
else if (
spec==
"unsigned long") {
245 v=
static_cast<long long>(
a.data<
unsigned long>());
251 m_terms(0), m_size(0), m_maxsize(
size) {
267 for (
unsigned int i=0;
i<m_size;++
i) {
271 if (m_lower[
i]-
value==1) --m_lower[
i];
272 if (
value-m_upper[
i]==1) ++m_upper[
i];
274 if (m_upper[
i]-m_lower[
i]==1) ++m_terms;
279 if (m_upper[
i]<
value) ++j;
284 if (m_size<m_maxsize) {
285 for (
i=m_size;
i!=j;--
i) {
286 m_lower[
i]=m_lower[
i-1];
287 m_upper[
i]=m_upper[
i-1];
303 const std::string& coralkey,
307 for (
unsigned int i=0;
i<m_size;++
i) {
308 long long lower=m_lower[
i];
309 long long upper=m_upper[
i];
312 if (m_lower[
i]-m_upper[j]<2) {
315 m_upper[j]=m_upper[
i];
327 for (
unsigned int i=0;
i<m_size;++
i) {
329 if (m_lower[
i]==m_upper[
i]) {
331 std::string keyname=addKey(ikey,fkeys,
spec,m_lower[
i]);
337 std::string keyname=addKey(ikey,fkeys,
spec,m_lower[
i]);
346 keyname=addKey(ikey,fkeys,
spec,m_upper[
i]);
355 const long long value) {
357 std::ostringstream skey;
359 std::string keyname=skey.str();
360 fkeys.extend(keyname,
spec.type());
363 fkeys[keyname].data<
long long>()=
value;
364 }
else if (
typeName==
"unsigned long long") {
365 fkeys[keyname].data<
unsigned long long>()=
value;
367 fkeys[keyname].data<
int>()=
value;
368 }
else if (
typeName==
"unsigned int") {
369 fkeys[keyname].data<
unsigned int>()=
value;
371 fkeys[keyname].data<
long>()=
value;
372 }
else if (
typeName==
"unsigned long") {
373 fkeys[keyname].data<
unsigned long>()=
value;
376 "CoraCoolObjectIter::QueryBuilder::addKey");