00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #include "CdbBdbShared/CdbBdbSTestRegistryP.hh"
00012 #include "CdbBdbShared/CdbBdbSUtils.hh"
00013 #include "CdbBdbShared/CdbBdbSOriginP.hh"
00014
00015 #include "BdbClustering/BdbCondIndexClusteringHint.hh"
00016
00017 #include <iostream>
00018 #include <assert.h>
00019
00020 #include <string>
00021 using std::cout;
00022 using std::endl;
00023
00024 CdbStatus
00025 CdbBdbSTestRegistryP::create( BdbHandle(CdbBdbSRegistryP)& theRegistryH,
00026 const char* theDescription )
00027 {
00028 const char* errorStr = "CdbBdbSTestRegistryP::create() -- ERROR";
00029
00030 theRegistryH = 0;
00031
00032 CdbStatus result = CdbStatus::Error;
00033 do {
00034
00035
00036
00037 BdbHandle(CdbBdbSRegistryP) localRegistryH;
00038 if( CdbStatus::Success == findLocal( localRegistryH )) {
00039 cout << errorStr << endl
00040 << " There local registry already exists in the current Condition/DB." << endl;
00041 break;
00042 }
00043
00044
00045
00046
00047 BdbHandle(CdbBdbSRegistryP) masterRegistryH;
00048 if( CdbStatus::Success != findMaster( masterRegistryH )) {
00049 cout << errorStr << endl
00050 << " Failed to locate MASTER registry in the current federation." << endl
00051 << " The federation has to be preloaded with at least a partial" << endl
00052 << " snapshot of the MASTER database in order to initialize a TEST one." << endl;
00053 break;
00054 }
00055
00056
00057
00058
00059 std::string localDbIdRangeName;
00060 if( CdbStatus::Success != CdbBdbSUtils::getLocalDbIdRange( localDbIdRangeName )) {
00061 cout << errorStr << endl
00062 << " Failed to find the local DBID range." << endl;
00063 break;
00064 }
00065 if( localDbIdRangeName != defaultDbIdRange( )) {
00066 cout << errorStr << endl
00067 << " The current federation has inappropriate local DBID range, which" << endl
00068 << " can't be used to create a TEST kind of database." << endl
00069 << " LOCAL RANGE: " << localDbIdRangeName.c_str( ) << endl
00070 << " EXPECTED RANGE: " << defaultDbIdRange( ) << endl;
00071 break;
00072 }
00073
00074
00075
00076 std::string databaseSuffix = std::string( "database_" ) + localDbIdRangeName;
00077
00078 BdbCondIndexClusteringHint hint( "cdb",
00079 "System",
00080 databaseSuffix.c_str( ));
00081
00082 BdbHandle(BdbContObj) contH = hint.updatedHint( );
00083 if( BdbIsNull(contH)) {
00084 cout << errorStr << endl
00085 << " Failed to create a container for persistent objects." << endl;
00086 break;
00087 }
00088
00089
00090
00091
00092
00093 if( ! hint.newContainerCreated( )) {
00094 cout << errorStr << endl
00095 << " The clustering hint has not created a new persistent container." << endl;
00096 break;
00097 }
00098
00099
00100
00101 theRegistryH = new( contH ) CdbBdbSTestRegistryP( theDescription,
00102 BdbTime::now( ),
00103 masterRegistryH->id( ));
00104 if( BdbIsNull(theRegistryH)) {
00105 cout << errorStr << endl
00106 << " Failed to create a persistent registry object." << endl;
00107 break;
00108 }
00109
00110
00111
00112 result = CdbStatus::Success;
00113
00114 } while( false );
00115
00116 return result;
00117 }
00118
00119 CdbBdbSTestRegistryP::CdbBdbSTestRegistryP( const char* theDescription,
00120 const BdbTime& theCreationTime,
00121 const BdbTime& theId ) :
00122 CdbBdbSRegistryP( CdbBdbSOriginP::TEST_ID,
00123 theDescription,
00124 theCreationTime,
00125 theId,
00126 true )
00127 {
00128
00129
00130 std::string localRangeName;
00131 {
00132 CdbStatus result = CdbBdbSUtils::getLocalDbIdRange( localRangeName );
00133 assert( CdbStatus::Success == result );
00134
00135
00136
00137
00138
00139 assert( localRangeName == defaultDbIdRange( ));
00140 }
00141 }
00142
00143 CdbBdbSTestRegistryP::~CdbBdbSTestRegistryP( )
00144 { }
00145
00146 bool
00147 CdbBdbSTestRegistryP::isMaster( ) const
00148 {
00149 return false;
00150 }
00151
00152 BdbRef(CdbBdbSOriginCollectionP)
00153 CdbBdbSTestRegistryP::originCollection( ) const
00154 {
00155 return 0;
00156 }
00157
00158 BdbRef(CdbBdbSPartitionsLayoutP)
00159 CdbBdbSTestRegistryP::partitionsLayout( ) const
00160 {
00161 return 0;
00162 }
00163
00164 BdbRef(CdbBdbSClusterCollectionP)
00165 CdbBdbSTestRegistryP::pClusterCollection( ) const
00166 {
00167 return 0;
00168 }
00169
00170 BdbRef(CdbBdbSRallocatorP< d_UShort >)
00171 CdbBdbSTestRegistryP::originRallocator( ) const
00172 {
00173 return 0;
00174 }
00175
00176 BdbRef(CdbBdbSRallocatorP< d_UShort >)
00177 CdbBdbSTestRegistryP::partitionRallocator( ) const
00178 {
00179 return 0;
00180 }
00181
00182 BdbRef(CdbBdbSRallocatorP< d_UShort >)
00183 CdbBdbSTestRegistryP::pClusterRallocator( ) const
00184 {
00185 return 0;
00186 }
00187
00188
00189
00190