11 #include "Reflex/Type.h"
14 m_session( dbSession ){
21 std::set<std::string> mappingList;
22 m_session.mappingDatabase().getMappingVersionsForContainer( containerId, mappingList );
27 std::map<std::string,std::string> versionMap;
28 m_session.mappingDatabase().getClassVersionListForContainer( containerId, versionMap );
33 std::ostream& outputStream ){
35 if(m_session.mappingDatabase().getMappingByVersion( mappingVersion, dest )){
44 if(!m_session.exists()){
49 throwException(
"ORA Database not found in \""+m_session.connectionString()+
"\".",
50 "DatabaseUtilitySession::importContainerSchema");
54 if( existsContainer( containerName ) ){
55 throwException(
"A Container named \""+containerName+
"\" already exists in the database.",
56 "DatabaseUtilitySession::importContainerSchema" );
60 Sequences containerSchemaSequences( m_session.schema() );
66 std::set<std::string> existingVersions = m_session.mappingDatabase().versions();
67 std::set<std::string> baseVersions;
71 throwException(
"Base mapping for class \""+cont->className()+
"\" has not been found in the database.",
72 "DatabaseUtilitySession::importContainerSchema");
74 std::set<std::string> classVersions;
77 "DatabaseUtilitySession::importContainerSchema");
79 if( existingVersions.find( baseMapping.
version() )!= existingVersions.end() ){
80 throwException(
"Mapping version \""+baseMapping.
version()+
"\" for base mapping of class \""+cont->className()+
"\" already exists in the database.",
"DatabaseUtilitySession::importContainerSchema");
82 if( !mapping2Schema.check( baseMapping ) ){
83 throwException(
"Schema base for class \""+baseMapping.
className()+
"\" cannot be replicated, because some schema objects have been found with the same name.",
"DatabaseUtilitySession::importContainerSchema");
85 baseVersions.insert( baseMapping.
version() );
86 existingVersions.insert( baseMapping.
version() );
87 m_session.mappingDatabase().storeMapping( baseMapping );
89 for( std::set<std::string>::const_iterator iCv = classVersions.begin(); iCv != classVersions.end(); ++iCv ){
90 m_session.mappingDatabase().insertClassVersion( cont->className(), *iCv , 0, newCont->
id(), baseMapping.
version(),
first );
96 mapping2Schema.create( baseMapping );
98 std::set<std::string> dependentClasses;
100 for( std::set<std::string>::const_iterator iCl = dependentClasses.begin(); iCl != dependentClasses.end(); ++iCl ){
103 throwException(
"Base mapping for class \""+*iCl+
"\" has not been found in the database.",
104 "DatabaseUtilitySession::importContainerSchema");
106 std::set<std::string> depClassVersions;
109 "DatabaseUtilitySession::importContainerSchema");
111 if( existingVersions.find( baseDepMapping.
version() )!= existingVersions.end() ){
112 throwException(
"Mapping version \""+baseDepMapping.
version()+
"\" for base mapping of class \""+*iCl+
"\" already exists in the database.",
"DatabaseUtilitySession::importContainerSchema");
114 if( !mapping2Schema.check( baseDepMapping ) ){
115 throwException(
"Schema base for class \""+baseDepMapping.
className()+
"\" cannot be replicated, because some schema objects have been found with the same name.",
"DatabaseUtilitySession::importContainerSchema");
117 baseVersions.insert( baseDepMapping.
version() );
118 existingVersions.insert( baseDepMapping.
version() );
119 m_session.mappingDatabase().storeMapping( baseDepMapping );
121 for( std::set<std::string>::const_iterator iCv = depClassVersions.begin(); iCv != depClassVersions.end(); ++iCv ){
122 m_session.mappingDatabase().insertClassVersion( *iCl, *iCv , 1, newCont->
id(), baseDepMapping.
version(),
first );
128 mapping2Schema.create( baseDepMapping );
131 std::set<std::string> allVersions;
133 std::stringstream mess;
134 mess <<
"No mapping versions found for container id="<<cont->id();
135 throwException( mess.str(),
"DatabaseUtilitySession::importContainerSchema");
137 for( std::set<std::string>::const_iterator iVer = allVersions.begin(); iVer != allVersions.end(); ++iVer ){
139 if( baseVersions.find( *iVer )== baseVersions.end() ){
142 throwException(
"Mapping version \""+*iVer+
"\" has not been found in the database.",
143 "DatabaseUtilitySession::importContainerSchema");
145 std::set<std::string> cvs;
148 "DatabaseUtilitySession::importContainerSchema");
150 if( existingVersions.find( *iVer )!= existingVersions.end() ){
151 throwException(
"Mapping version \""+*iVer+
"\" for mapping of class \""+evMapping.
className()+
"\" already exists in the database.",
"DatabaseUtilitySession::importContainerSchema");
153 if( !mapping2Schema.check( evMapping ) ){
154 throwException(
"Evolved schema for class \""+evMapping.
className()+
"\" cannot be replicated, because some schema objects have been found with the same name.",
"DatabaseUtilitySession::importContainerSchema");
156 m_session.mappingDatabase().storeMapping( evMapping );
157 existingVersions.insert( evMapping.
version() );
164 for( std::set<std::string>::const_iterator iCv = cvs.begin(); iCv != cvs.end(); ++iCv ){
165 m_session.mappingDatabase().insertClassVersion( evMapping.
className(), *iCv , depIndex, newCont->
id(), evMapping.
version() );
168 mapping2Schema.alter( evMapping );
177 sourceSession.
connect(sourceConnectionString,
true );
178 sourceSession.startTransaction(
true );
179 importContainerSchema(containerName, sourceSession );
180 sourceSession.commitTransaction();
187 iC != m_session.containers().end(); ++iC ){
188 if( iC->second->name() == containerName ) {
199 sourceSession.
connect(sourceConnectionString,
true );
200 sourceSession.startTransaction(
true );
204 std::vector<void*> objects;
206 while( iterator->
next() ){
208 objects.push_back( data );
212 for( std::vector<void*>::const_iterator iO = objects.begin(); iO != objects.end(); iO++ ){
213 contType.Destruct( *iO );
215 sourceSession.commitTransaction();
219 if( !m_session.exists() ){
220 throwException(
"ORA Database not found in \""+m_session.connectionString()+
"\".",
221 "DatabaseUtilitySession::eraseMapping");
224 m_session.mappingDatabase().removeMapping( mappingVersion );
228 if( !m_session.exists() ){
229 throwException(
"ORA Database not found in \""+m_session.connectionString()+
"\".",
230 "DatabaseUtilitySession::containerHandle");
234 return m_session.containerHandle( name );
Handle< DatabaseContainer > containerHandle(const std::string &name)
void eraseMapping(const std::string &mappingVersion)
const Reflex::Type & type()
bool getBaseMappingForContainer(const std::string &className, int containerId, MappingTree &destination)
const std::string & className() const
bool getClassVersionListForMappingVersion(const std::string &mappingVersion, std::set< std::string > &destination)
const std::string & version() const
bool dumpMapping(const std::string &mappingVersion, std::ostream &outputStream)
int insertItem(const void *data, const Reflex::Type &type)
static std::string automaticDatabaseCreation()
bool connect(const std::string &connectionString, bool readOnly)
void importContainerSchema(const std::string &sourceConnectionString, const std::string &containerName)
void importContainer(const std::string &sourceConnectionString, const std::string &containerName)
bool getMappingVersionsForContainer(int containerId, std::set< std::string > &versionList)
DatabaseUtilitySession(DatabaseSession &dbSession)
const std::string & className()
MappingDatabase & mappingDatabase()
void printXML(std::ostream &outputStream) const
bool getDependentClassesForContainer(int containerId, std::set< std::string > &list)
bool getMappingByVersion(const std::string &version, MappingTree &destination)
char data[epos_bytes_allocation]
Handle< IteratorBuffer > iteratorBuffer()
virtual ~DatabaseUtilitySession()
std::map< std::string, std::string > listMappings(int containerId)
bool existsContainer(const std::string &containerName)
static std::string sequenceNameForContainer(const std::string &containerName)
void throwException(const std::string &message, const std::string &methodName)
static std::string sequenceNameForDependentClass(const std::string &containerName, const std::string &className)
Handle< DatabaseContainer > containerHandle(const std::string &name)
std::set< std::string > listMappingVersions(int containerId)
std::string className(const T &t)