@@ -1222,22 +1222,17 @@ dbInst* dbInst::create(dbBlock* block_,
12221222 dbModule* parent_module)
12231223{
12241224 _dbBlock* block = (_dbBlock*) block_;
1225+ if (block->_inst_hash .hasMember (name_)) {
1226+ return nullptr ;
1227+ }
1228+
12251229 _dbMaster* master = (_dbMaster*) master_;
12261230 _dbInstHdr* inst_hdr = block->_inst_hdr_hash .find (master->_id );
1227-
12281231 if (inst_hdr == nullptr ) {
12291232 inst_hdr
12301233 = (_dbInstHdr*) dbInstHdr::create ((dbBlock*) block, (dbMaster*) master);
12311234 }
12321235
1233- if (block->_inst_hash .hasMember (name_)) {
1234- block->getImpl ()->getLogger ()->error (
1235- utl::ODB ,
1236- 385 ,
1237- " Attempt to create instance with duplicate name: {}" ,
1238- name_);
1239- }
1240-
12411236 _dbInst* inst = block->_inst_tbl ->create ();
12421237
12431238 if (block->_journal ) {
@@ -1354,6 +1349,35 @@ dbInst* dbInst::create(dbBlock* top_block,
13541349 return inst;
13551350}
13561351
1352+ dbInst* dbInst::makeUniqueDbInst (dbBlock* block,
1353+ dbMaster* master,
1354+ const char * name,
1355+ bool physical_only,
1356+ dbModule* target_module)
1357+ {
1358+ dbInst* inst
1359+ = dbInst::create (block, master, name, physical_only, target_module);
1360+ if (inst) {
1361+ return inst;
1362+ }
1363+
1364+ std::unordered_map<std::string, int >& name_id_map
1365+ = ((_dbBlock*) block)->_inst_name_id_map ;
1366+ std::string inst_base_name (name);
1367+ do {
1368+ std::string full_name = inst_base_name;
1369+ int & id = name_id_map[inst_base_name];
1370+ if (id > 0 ) {
1371+ full_name += " _" + std::to_string (id);
1372+ }
1373+ ++id;
1374+ inst = dbInst::create (
1375+ block, master, full_name.c_str (), physical_only, target_module);
1376+ } while (inst == nullptr );
1377+
1378+ return inst;
1379+ }
1380+
13571381void dbInst::destroy (dbInst* inst_)
13581382{
13591383 _dbInst* inst = (_dbInst*) inst_;
0 commit comments