13 #include "RelationalAccess/IConnectionServiceConfiguration.h"
14 #include "RelationalAccess/ISessionProxy.h"
15 #include "RelationalAccess/ITransaction.h"
26 std::map<int, unsigned int>::iterator iC = m_table.find( contId );
27 if( iC == m_table.end() ){
28 iC = m_table.insert( std::make_pair( contId, 0 ) ).first;
34 m_table.erase( contId );
48 m_connectionString(
"" ),
53 m_containerUpdateTable(),
61 m_connectionPool( connectionPool ),
63 m_connectionString(
"" ),
68 m_containerUpdateTable(),
79 m_dbSession = m_connectionPool->connect( connectionString, readOnly?coral::ReadOnly:coral::Update );
80 if(m_dbSession.isValid()) {
81 m_connectionString = connectionString;
92 m_dbSession = m_connectionPool->connect( connectionString, asRole, readOnly?coral::ReadOnly:coral::Update );
93 if(m_dbSession.isValid()) {
94 m_connectionString = connectionString;
103 m_transactionCache.reset();
105 m_contIdSequence.reset();
107 m_containerUpdateTable.clear();
112 if( isTransactionActive()) rollbackTransaction();
116 m_connectionString.clear();
117 if(m_monitoring) m_monitoring->stop();
121 return m_dbSession.isValid();
125 return m_connectionString;
129 if( !m_transactionCache.get() ){
130 m_dbSession.get().transaction().start( readOnly );
136 m_monitoring->newTransaction();
142 if( m_transactionCache.get() ){
143 m_schema->containerHeaderTable().updateNumberOfObjects( m_containerUpdateTable.table() );
144 m_dbSession.get().transaction().commit();
147 m_monitoring->stopTransaction();
153 if( m_transactionCache.get() ){
154 m_dbSession.get().transaction().rollback();
157 m_monitoring->stopTransaction(
false);
164 if( m_dbSession.get().transaction().isActive() ){
165 if( checkIfReadOnly ){
166 if( m_dbSession.get().transaction().isReadOnly() ) ret =
true;
175 if(!m_transactionCache->dbExistsLoaded()){
176 m_transactionCache->setDbExists( m_schema->exists() );
178 return m_transactionCache->dbExists();
182 m_schema->create( userSchemaVersion );
183 m_contIdSequence->create();
184 m_mappingDb->setUp();
185 m_transactionCache->setDbExists(
true );
189 if(!testDropPermission()){
190 throwException(
"Drop permission has been denied for the current user.",
191 "DatabaseSession::drop");
194 m_transactionCache->dropDatabase();
199 m_schema->setAccessPermission( principal, forWrite );
203 if(!m_transactionCache->dropPermissionLoaded()){
204 m_transactionCache->setDropPermission( m_schema->testDropPermission() );
206 return m_transactionCache->dropPermission();
210 if(!m_transactionCache->isLoaded()){
211 std::map<std::string, ContainerHeaderData> containersData;
212 m_schema->containerHeaderTable().getContainerData( containersData );
213 for(std::map<std::string, ContainerHeaderData>::iterator iC = containersData.begin();
214 iC != containersData.end(); ++iC){
216 iC->second.className,
217 iC->second.numberOfObjects, *
this ) );
218 m_transactionCache->addContainer( iC->second.id, iC->first, container );
220 m_schema->mainTable().getParameters( m_transactionCache->dbParams() );
221 m_transactionCache->setLoaded();
226 std::map<std::string,std::string>& params = m_transactionCache->dbParams();
230 std::map<std::string,std::string>::const_iterator iPar = params.find( paramName );
231 if( iPar != params.end() ){
232 version = iPar->second;
239 int newContId = m_contIdSequence->getNextId(
true );
240 m_schema->containerHeaderTable().addContainer( newContId, containerName, className );
242 className, 0, *
this ) );
243 m_transactionCache->addContainer( newContId, containerName, container );
251 int newContId = m_contIdSequence->getNextId(
true );
253 m_transactionCache->addContainer( newContId, containerName, newCont );
260 m_transactionCache->eraseContainer( cont->
id(),
name );
265 return m_transactionCache->getContainer( name );
269 return m_transactionCache->getContainer( contId );
273 return m_transactionCache->containers();
279 m_schema->namingServiceTable().setObjectName( name, containerId, itemId );
283 return m_schema->namingServiceTable().eraseObjectName( name );
287 return m_schema->namingServiceTable().eraseAllNames();
292 std::pair<int,int> oid;
293 if( m_schema->namingServiceTable().getObjectByName( name, oid ) ){
301 std::pair<int,int> oidData;
302 if( m_schema->namingServiceTable().getObjectByName( name, oidData ) ){
303 destination =
OId( oidData.first, oidData.second );
311 boost::shared_ptr<void>
ret = m_transactionCache->getNamedReference( name );
313 std::pair<int,int> oid;
314 if( m_schema->namingServiceTable().getObjectByName( name, oid ) ){
319 if( ptr) ret = boost::shared_ptr<void>( ptr,
RflxDeleter( cont->
type() ) );
322 if( ret.get() ) m_transactionCache->setNamedReference( name, ret );
328 std::vector<std::string>& destination ){
329 return m_schema->namingServiceTable().getNamesForContainer( containerId, destination );
334 std::vector<std::string>& destination ){
335 return m_schema->namingServiceTable().getNamesForObject( containerId, itemId, destination );
340 return m_schema->namingServiceTable().getAllNames( destination );
344 if( !m_transactionCache->utility() ){
346 m_transactionCache->setUtility( util );
348 return m_transactionCache->utility();
356 return *m_contIdSequence;
364 return m_configuration;
372 return m_connectionPool;
376 return m_containerUpdateTable;
static std::string versionParameterName()
Handle< DatabaseContainer > containerHandle(const std::string &name)
const std::string & connectionString()
To be moved in DBCommon, has to serve also the pure coral use case.
static std::string userSchemaVersionParameterName()
const Reflex::Type & type()
Object fetchObjectByName(const std::string &name)
bool listObjectNames(std::vector< std::string > &destination)
void takeNote(int contId, unsigned int size)
SharedSession & storageAccessSession()
boost::shared_ptr< ConnectionPool > & connectionPool()
bool getItemId(const std::string &name, OId &destination)
void dropContainer(const std::string &name)
boost::shared_ptr< void > fetchTypedObjectByName(const std::string &name, const Reflex::Type &asType)
const std::map< int, unsigned int > & table()
static Monitoring & get()
std::string schemaVersion(bool userSchema)
bool eraseObjectName(const std::string &name)
void setAccessPermission(const std::string &principal, bool forWrite)
bool testDropPermission()
SessionMonitoringData * startSession(const std::string &connectionString)
bool connect(const std::string &connectionString, bool readOnly)
IDatabaseSchema & schema()
bool getNamesForContainer(int containerId, std::vector< std::string > &destination)
Handle< DatabaseUtilitySession > utility()
ContainerUpdateTable & containerUpdateTable()
void setObjectName(const std::string &name, int containerId, int itemId)
bool getNamesForObject(int containerId, int itemId, std::vector< std::string > &destination)
const std::map< int, Handle< DatabaseContainer > > & containers()
static IDatabaseSchema * createSchemaHandle(coral::ISchema &schema)
void startTransaction(bool readOnly)
virtual ~DatabaseSession()
NamedSequence & containerIdSequence()
MappingDatabase & mappingDatabase()
void create(const std::string &userSchemaVersion=std::string(""))
bool isTransactionActive(bool checkIfReadOnly=false)
Handle< DatabaseContainer > createContainer(const std::string &containerName, const Reflex::Type &type)
void * fetchItem(int itemId)
Configuration & configuration()
void rollbackTransaction()
void * fetchItemAsType(int itemId, const Reflex::Type &asType)
static std::string sequenceNameForContainerId()
sequence names
void throwException(const std::string &message, const std::string &methodName)
tuple size
Write out results.
std::string className(const T &t)
boost::shared_ptr< ConnectionPool > m_connectionPool
Handle< ora::DatabaseContainer > addContainer(const std::string &containerName, const std::string &className)