9 #include "RelationalAccess/ISessionProxy.h"
10 #include "RelationalAccess/ITransaction.h"
11 #include "RelationalAccess/ISchema.h"
12 #include "RelationalAccess/ITable.h"
13 #include "RelationalAccess/ITableDescription.h"
14 #include "RelationalAccess/ITableDataEditor.h"
15 #include "RelationalAccess/IBulkOperation.h"
16 #include "RelationalAccess/IColumn.h"
17 #include "RelationalAccess/IQuery.h"
18 #include "RelationalAccess/ICursor.h"
19 #include "RelationalAccess/SchemaException.h"
20 #include "CoralBase/Attribute.h"
21 #include "CoralBase/Exception.h"
22 #include "CoolKernel/ValidityKey.h"
23 #include "CoolKernel/IDatabase.h"
24 #include "CoolKernel/IFolder.h"
25 #include "CoolKernel/IObject.h"
26 #include "CoolKernel/Record.h"
27 #include "CoolKernel/StorageType.h"
41 coral::ISessionProxy*
proxy, cool::IDatabasePtr cooldb,
44 m_foldername(coolfolder),
45 m_proxy(
proxy),m_cooldb(cooldb),m_coradb(coradb),
47 m_bulkactive(false),m_payloadbuf(0),m_bulki(0),m_seqpk(0),m_seqfk(0),
48 m_nextpk(0),m_usedpk(0),m_nextfk(0),m_usedfk(0)
53 m_log << coral::Debug <<
"Initialize CoraCoolFolder " << coolfolder <<
56 std::string folderdesc;
61 catch (cool::Exception&
e) {
64 m_log << coral::Debug <<
"COOL Folder description is: " << folderdesc
73 "CoraCoolFolder::CoraCoolFolder");
78 m_proxy->transaction().start(
true);
85 "Problem extracting attribute specification",
86 "CoraCoolFolder::CoraCoolFolder");
87 m_proxy->transaction().commit();
89 catch (coral::SessionException&
e) {
91 "CoraCoolFolder::CoraCoolFolder");
106 const cool::RecordSpecification
110 cool::RecordSpecification atrspec;
120 atrlist.extend(itr->first,
121 cool::StorageType::storageType(
nameToCoolType(itr->second)).cppType());
126 const cool::ValidityKey
until,
130 const std::string& tagName,
131 const bool userTagOnly) {
145 m_log << coral::Debug <<
"Storing " << nrow <<
" rows in CoraCool folder "
152 m_proxy->transaction().start(
false);
157 pkey=seqfk.
fetch(nrow);
162 m_proxy->transaction().commit();
164 catch (coral::Exception&
e) {
170 m_proxy->transaction().start(
false);
173 coral::ITableDataEditor& editor=
m_table->dataEditor();
175 coral::IBulkOperation* bulki=editor.bulkInsert(
data,
WB_SIZE);
179 data.fastCopyData(*payitr);
184 bulki->processNextIteration();
187 m_proxy->transaction().commit();
189 catch (coral::Exception&
e) {
196 cool::Record coolfk(
m_coolfolder->payloadSpecification());
202 catch (cool::Exception &
e) {
223 m_proxy->transaction().start(
false);
226 coral::ITableDataEditor& editor=
m_table->dataEditor();
252 m_proxy->transaction().commit();
254 catch (coral::Exception&
e) {
262 const cool::ValidityKey&
until,
263 const coral::Attribute& fkey,
265 const std::string& tagName,
266 const bool userTagOnly) {
270 cool::Record fkeylist(
m_coolfolder->payloadSpecification());
276 "CoraCool::Folder::referenceObject");
281 const cool::ValidityKey&
until,
284 const std::string& tagName,
285 const bool userTagOnly) {
287 cool::Record fkeylist(
m_coolfolder->payloadSpecification());
299 "CoralCoolFolder::addPayload");
307 m_log << coral::Debug <<
"Adding " << nrow <<
" into CoraCool folder "
312 m_proxy->transaction().start(
false);
314 pkey=seqfk.
fetch(nrow);
316 m_proxy->transaction().commit();
318 catch (coral::Exception&
e) {
323 m_proxy->transaction().start(
false);
326 coral::ITableDataEditor& editor=
m_table->dataEditor();
332 editor.insertRow(
data);
334 m_proxy->transaction().commit();
336 catch (coral::Exception&
e) {
345 const std::string typen=attr.specification().typeName();
347 attr.data<
int>()=keyval;
348 }
else if (typen==
"unsigned int") {
349 attr.data<
unsigned int>()=keyval;
350 }
else if (typen==
"long long") {
351 attr.data<
long long>()=keyval;
352 }
else if (typen==
"unsigned long long") {
353 attr.data<
unsigned long long>()=keyval;
356 m_log << coral::Error <<
"Unrecognised key type " << typen <<
366 const cool::StorageType& typen=attr.specification().storageType();
367 if (typen==cool::StorageType::Int32) {
368 attr.setValue<
int>(keyval);
369 }
else if (typen==cool::StorageType::UInt32) {
370 attr.setValue<
unsigned int>(keyval);
371 }
else if (typen==cool::StorageType::Int64) {
372 attr.setValue<
long long>(keyval);
373 }
else if (typen==cool::StorageType::UInt63) {
374 attr.setValue<
unsigned long long>(keyval);
377 m_log << coral::Error <<
"Unrecognised key type " << typen.name() <<
385 const coral::Attribute& keyval) {
387 const cool::StorageType& typen=attr.specification().storageType();
388 if (typen==cool::StorageType::Int32) {
389 attr.setValue<
int>(keyval.data<
int>());
390 }
else if (typen==cool::StorageType::UInt32) {
391 attr.setValue<
unsigned int>(keyval.data<
unsigned int>());
392 }
else if (typen==cool::StorageType::Int64) {
393 attr.setValue<
long long>(keyval.data<
long long>());
394 }
else if (typen==cool::StorageType::UInt63) {
395 attr.setValue<
unsigned long long>(keyval.data<
unsigned long long>());
398 m_log << coral::Error <<
"Unrecognised key type " << typen.name() <<
407 const std::string typen=attr.specification().typeName();
409 return attr.data<
int>();
410 }
else if (typen==
"unsigned int") {
411 return static_cast<int>(attr.data<
unsigned int>());
412 }
else if (typen==
"long long") {
413 return static_cast<int>(attr.data<
long long>());
414 }
else if (typen==
"unsigned long long") {
415 return static_cast<int>(attr.data<
unsigned long long>());
417 m_log << coral::Error <<
"Unrecognised key type " << typen <<
426 coral::IQuery*
query=0;
428 coral::ITable&
table=
m_proxy->nominalSchema().tableHandle(
432 bindvar.extend<std::string>(
"SNAME");
434 query->setCondition(
"NAME=:SNAME",bindvar);
435 query->setRowCacheSize(1);
436 query->defineOutputType(
"NAME",
"string");
440 std::string
spec=
res[
"ATTRSPEC"].data<std::string>();
442 std::string::size_type iofs1,iofs2,iofs3;
446 iofs2=
spec.find(
':',iofs1);
447 iofs3=
spec.find(
',',iofs2);
448 if (iofs3==std::string::npos) {
452 m_attrvec.emplace_back(
spec.substr(iofs1,iofs2-iofs1),
spec.substr(iofs2+1,iofs3-iofs2-1));
453 if (!last) iofs1=iofs3+1;
457 m_log << coral::Error <<
"No data obtained for CORACOOLATTR" <<
461 catch (coral::Exception &
e) {
462 m_log << coral::Error <<
"Exception reading CORACOOLATTR table: "
470 const std::string& coolName)
const {
471 if (coolName==
"Int16")
return cool::StorageType::Int16;
472 if (coolName==
"UInt16")
return cool::StorageType::UInt16;
473 if (coolName==
"Int32")
return cool::StorageType::Int32;
474 if (coolName==
"UInt32")
return cool::StorageType::UInt32;
475 if (coolName==
"UInt63")
return cool::StorageType::UInt63;
476 if (coolName==
"Int64")
return cool::StorageType::Int64;
477 if (coolName==
"Float")
return cool::StorageType::Float;
478 if (coolName==
"Double")
return cool::StorageType::Double;
479 if (coolName==
"String255")
return cool::StorageType::String255;
480 if (coolName==
"String4k")
return cool::StorageType::String4k;
481 if (coolName==
"String64k")
return cool::StorageType::String64k;
482 if (coolName==
"String16M")
return cool::StorageType::String16M;
483 if (coolName==
"Blob64k")
return cool::StorageType::Blob64k;
486 "CoraCoolFolder::nameToCoolType");
491 query->defineOutputType(itr->first,
492 coral::AttributeSpecification::typeNameForId(
493 cool::StorageType::storageType(
nameToCoolType(itr->second)).cppType()));
497 const int fkey,
bool updatefk) {
511 m_bulki->processNextIteration();
514 catch (coral::Exception&
e) {
521 const std::string& tagName) {
531 m_proxy->transaction().start(
true);
542 m_proxy->transaction().commit();
544 catch (coral::Exception&
e) {
552 const cool::ChannelSelection&
channels,
553 const std::string& tagName) {
558 const cool::ValidityKey&
since,
559 const cool::ValidityKey&
until,
560 const cool::ChannelSelection&
channels,
561 const std::string& tagName)