3 #include "RelationalAccess/ISessionProxy.h"
4 #include "RelationalAccess/ITransaction.h"
5 #include "RelationalAccess/ConnectionService.h"
6 #include "RelationalAccess/IConnectionServiceConfiguration.h"
7 #include "RelationalAccess/ISchema.h"
8 #include "RelationalAccess/ITable.h"
9 #include "RelationalAccess/TableDescription.h"
10 #include "RelationalAccess/ITableSchemaEditor.h"
11 #include "RelationalAccess/ITablePrivilegeManager.h"
12 #include "RelationalAccess/ITableDataEditor.h"
13 #include "RelationalAccess/IForeignKey.h"
14 #include "RelationalAccess/IQuery.h"
15 #include "RelationalAccess/ICursor.h"
16 #include "CoralBase/AttributeSpecification.h"
17 #include "CoralBase/AttributeList.h"
18 #include "CoralBase/Attribute.h"
23 coral::ConnectionService connServ;
24 std::auto_ptr<coral::ISessionProxy>
session( connServ.connect( connectionString, coral::Update ));
28 std::set<std::string>
tables = schema.listTables();
29 for( std::set<std::string>::const_iterator iEx = exclusionList.begin();
30 iEx != exclusionList.end(); ++iEx ){
33 for( std::set<std::string>::const_iterator iT = tables.begin();
34 iT != tables.end(); ++iT ){
35 coral::ITable&
t = schema.tableHandle( *iT );
36 int numFKs = t.description().numberOfForeignKeys();
37 for(
int ifk=0; ifk < numFKs; ifk++ ){
39 t.schemaEditor().dropForeignKey( t.description().foreignKey( 0 ).name() );
42 for( std::set<std::string>::const_iterator iT = tables.begin();
43 iT != tables.end(); ++iT ){
44 schema.dropIfExistsTable( *iT );
46 session->transaction().commit();
48 session->transaction().rollback();
59 m_connServ( new coral::ConnectionService ),
70 m_connServ->configuration().setConnectionTimeOut(0);
71 m_session.reset( m_connServ->connect( connectionString, coral::Update ) );
72 m_session->transaction().start(
false );
73 coral::ISchema&
schema = m_session->nominalSchema();
75 coral::TableDescription descr(
"OraDb" );
77 descr.insertColumn(
"P_LOCK",
78 coral::AttributeSpecification::typeNameForType<int>() );
79 descr.setNotNullConstraint(
"P_LOCK" );
80 descr.setPrimaryKey( std::vector<std::string>( 1,
"P_LOCK" ) );
81 coral::ITable&
table = schema.createTable( descr );
82 table.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
86 std::auto_ptr<coral::IQuery>
query( table.newQuery() );
87 query->addToOutputList(
"P_LOCK" );
88 query->defineOutputType(
"P_LOCK", coral::AttributeSpecification::typeNameForType<int>());
89 query->setCondition( condition, coral::AttributeList() );
90 query->setForUpdate();
91 coral::ICursor& cursor =
query->execute();
92 coral::AttributeList
data;
93 data.extend<
int>(
"P_LOCK" );
94 data[
"P_LOCK"].data<
int>() = 1;
98 table.dataEditor().updateRows( setCLause, condition , data );
101 table.dataEditor().insertRow( data );
111 m_session->transaction().commit();
static const std::string & tableName()
void cleanUp(const std::string &connectionString, std::set< std::string > exclusionList=std::set< std::string >())
volatile std::atomic< bool > shutdown_flag false
void lock(const std::string &connectionString)