13 #include "RelationalAccess/ISessionProxy.h"
20 std::size_t
pos=userconnect.find_first_of(
':');
21 if( pos!=std::string::npos ){
22 protocol=userconnect.substr(0,pos);
23 std::size_t
p=protocol.find_first_of(
'_');
24 if(p!=std::string::npos){
25 protocol=protocol.substr(0,p);
31 (*ptr).initialize(connection);
58 void open(
const std::string& connectionString,
59 const std::string& role,
64 throw cond::Exception(
"DbSession::open: cannot open session. Underlying connection is closed.");
66 boost::shared_ptr<ora::ConnectionPool> connPool =
connection->connectionPool();
70 if(!blobStreamer)
throw cond::Exception(
"DbSession::open: cannot find required plugin. No instance of ora::IBlobStreamingService has been loaded..");
71 database->configuration().setBlobStreamingService( blobStreamer );
76 std::string connStr = (*technologyProxy).getRealConnectString( connectionString );
77 database->connect( connStr, role, readOnly );
84 const std::string& transactionId ){
88 throw cond::Exception(
"DbSession::open: cannot open session. Underlying connection is closed.");
90 boost::shared_ptr<ora::ConnectionPool> connPool =
connection->connectionPool();
94 if(!blobStreamer)
throw cond::Exception(
"DbSession::open: cannot find required plugin. No instance of ora::IBlobStreamingService has been loaded..");
95 database->configuration().setBlobStreamingService( blobStreamer );
98 std::string connStr = (*technologyProxy).getRealConnectString(connectionString, transactionId);
129 m_implementation( new
SessionImpl ( connection ) ){
133 m_implementation( rhs.m_implementation ){
146 std::string emptyRole(
"");
147 m_implementation->open( connectionString, emptyRole, readOnly );
152 m_implementation->open( connectionString, asRole, readOnly );
157 m_implementation->openReadOnly( connectionString,
id );
162 m_implementation->close();
166 return m_implementation->isOpen;
170 if(!m_implementation->database.get())
171 throw cond::Exception(
"DbSession::connectionString: cannot get connection string. Session has not been open.");
172 return m_implementation->database->connectionString();
176 return *(m_implementation->connection);
181 return m_implementation->technologyProxy->isTransactional();
186 return m_implementation->blobStreamingService;
191 if(!m_implementation->connection.get() || !m_implementation->connection->isOpen())
192 throw cond::Exception(
"DbSession::transaction: cannot open transaction. Underlying connection is closed.");
193 if(!m_implementation->transaction.get())
194 throw cond::Exception(
"DbSession::transaction: cannot get transaction. Session has not been open.");
195 return *m_implementation->transaction;
199 if(!m_implementation->connection.get() || !m_implementation->connection->isOpen())
200 throw cond::Exception(
"DbSession::storage: cannot access the storage. Underlying connection is closed.");
201 if(!m_implementation->database.get())
202 throw cond::Exception(
"DbSession::storage: cannot access the database. Session has not been open.");
203 return *m_implementation->database;
207 bool created =
false;
208 if ( !storage().exists() ){
210 storage().create( std::string(COND_SCHEMA_VERSION) );
219 dbVer = storage().schemaVersion(
true );
225 return storage().storageAccessSession().get().schema( schemaName );
230 return storage().storageAccessSession().get().nominalSchema();
240 const std::string& contName ){
242 std::auto_ptr<cond::TechnologyProxy> technologyProxy =
buildTechnologyProxy(sourceConnectionString, *(m_implementation->connection));
243 utility.
importContainerSchema( (*technologyProxy).getRealConnectString( sourceConnectionString ), contName );
248 ora::OId oid = storage().insertItem( containerName,
object );
256 return storage().fetchItem( oid );
262 storage().erase( oid );
272 std::string
ret = storeObject( data, cont.
name() );
297 std::pair<std::string,int> oidData =
parseToken( poolToken );
298 if( oidData.first.empty() ){
299 throwException(
"Could not resolve Container name from token=\""+poolToken+
"\".",
"PoolTokenParser::parse");
PoolTokenParser(ora::Database &db)
boost::shared_ptr< SessionImpl > m_implementation
const std::string & connectionString() const
std::string write(const ora::OId &oid)
bool deleteObject(const std::string &objectId)
std::string classNameForItem(const std::string &objectId)
std::auto_ptr< cond::TechnologyProxy > buildTechnologyProxy(const std::string &userconnect, const DbConnection &connection)
static Version fromString(const std::string &versionString)
std::pair< std::string, int > parseToken(const std::string &objectId)
DbTransaction & transaction()
void open(const std::string &connectionString, bool readOnly=false)
const std::string & blobStreamingService() const
const std::string & name()
void openReadOnly(const std::string &connectionString, const std::string &id)
std::auto_ptr< DbConnection > connection
bool deleteMapping(const std::string &mappingVersion)
static std::string automaticContainerCreation()
coral::ISchema & schema(const std::string &schemaName)
static const char * CHANGE_SCHEMA_VERSION
SessionImpl(const DbConnection &connection)
const std::string & className()
std::auto_ptr< DbTransaction > transaction
static const char * COND_SCHEMA_VERSION
void importContainerSchema(const std::string &sourceConnectionString, const std::string &containerName)
Container containerHandle(const std::string &name)
std::auto_ptr< ora::Database > database
ora::OId parse(const std::string &poolToken)
bool isTransactional() const
bool importMapping(const std::string &sourceConnectionString, const std::string &contName)
DbSession & operator=(const DbSession &rhs)
std::auto_ptr< cond::TechnologyProxy > technologyProxy
std::string storeObject(const T *object, const std::string &containerName)
static const std::string COND_READER_ROLE
PoolTokenWriter(ora::Database &db)
std::string className(const std::string &poolToken)
void throwException(std::string const &message, std::string const &methodName)
Interface for a Streaming Service.
coral::ISchema & nominalSchema()
void openReadOnly(const std::string &connectionString, const std::string &transactionId)
std::string toString() const
std::string importObject(cond::DbSession &fromDatabase, const std::string &objectId)
char data[epos_bytes_allocation]
static Version & poolSchemaVersion()
std::string const blobStreamingService
std::string writeToken(const std::string &containerName, int oid0, int oid1, const std::string &className)
ora::Object getObject(const std::string &objectId)
bool fromString(const std::string &s)
void eraseMapping(const std::string &mappingVersion)
ora::Database & storage()
T get(const Candidate &c)
void open(const std::string &connectionString, const std::string &role, bool readOnly)
const DbConnection & connection() const