Commit 303b366b authored by lw's avatar lw

Adding wb_vrepdb::copy() and changed semantics of wb_vrepdb::create()

parent d90f3734
...@@ -19,6 +19,53 @@ ...@@ -19,6 +19,53 @@
#if 1 #if 1
int main( int argc, char *argv[]) int main( int argc, char *argv[])
{
//pwr_tStatus sts;
//dbs_sEnv env;
//dbs_sEnv *ep;
wb_erep *erep = new wb_erep();
if (argc <= 2) exit(0);
// ep = dbs_Map(&sts, &env, argv[1]);
wb_vrepdbs *vdbs = new wb_vrepdbs(erep, argv[1]);
vdbs->load();
wb_dbs dbs(vdbs);
dbs.setFileName("lasse.dbs");
dbs.importVolume(*vdbs);
//wb_orepdbs *op = (wb_orepdbs *)vdbs->object(&sts);
wb_db db(pwr_cNVid);
db.copy(*vdbs, argv[2]);
//db.importVolume(*vdbs);
db.close();
wb_vrepdb vdb(erep, argv[2]);
wb_dbs adbs(vdbs);
adbs.setFileName("alasse.dbs");
adbs.importVolume(vdb);
}
#elif 0
int main( int argc, char *argv[])
{
//pwr_tStatus sts;
//dbs_sEnv env;
//dbs_sEnv *ep;
wb_erep *erep = new wb_erep();
if (argc <= 2) exit(0);
//wb_vrepdb vdb(erep, argv[2]);
wb_vrepdb vdb(erep, 1000, pwr_eClass_RootVolume, "Lasse", argv[2]);
}
#elif 0
int main( int argc, char *argv[])
{ {
pwr_tStatus sts; pwr_tStatus sts;
//dbs_sEnv env; //dbs_sEnv env;
...@@ -34,7 +81,7 @@ int main( int argc, char *argv[]) ...@@ -34,7 +81,7 @@ int main( int argc, char *argv[])
dbs.setFileName("lasse.dbs"); dbs.setFileName("lasse.dbs");
dbs.importVolume(*vdbs); dbs.importVolume(*vdbs);
wb_orepdbs *op = (wb_orepdbs *)vdbs->object(&sts); //wb_orepdbs *op = (wb_orepdbs *)vdbs->object(&sts);
wb_db db(vdbs->vid()); wb_db db(vdbs->vid());
db.create(vdbs->vid(), vdbs->cid(), vdbs->name(), argv[2]); db.create(vdbs->vid(), vdbs->cid(), vdbs->name(), argv[2]);
......
...@@ -692,7 +692,8 @@ void wb_db_dbody::iter(wb_import &i) ...@@ -692,7 +692,8 @@ void wb_db_dbody::iter(wb_import &i)
m_dbc->close(); m_dbc->close();
} }
wb_db::wb_db() wb_db::wb_db() :
m_vid(pwr_cNVid)
{ {
} }
...@@ -720,15 +721,101 @@ void wb_db::close() ...@@ -720,15 +721,101 @@ void wb_db::close()
m_env->close(0); m_env->close(0);
} }
void wb_db::copy(wb_export &e, const char *fileName)
{
dcli_translate_filename(m_fileName, fileName);
//int rc = m_env->txn_begin(0, (DbTxn **)&m_txn, 0);
openDb(false);
importVolume(e);
close();
openDb(true);
try {
m_env->txn_begin(0, (DbTxn **)&m_txn, 0);
wb_db_info i(this);
i.get(m_txn);
m_vid = i.vid();
m_cid = i.cid();
strcpy(m_volumeName, i.name());
}
catch (DbException &e) {
//txn->abort();
printf("exeption: %s\n", e.what());
}
}
void wb_db::create(pwr_tVid vid, pwr_tCid cid, const char *volumeName, const char *fileName) void wb_db::create(pwr_tVid vid, pwr_tCid cid, const char *volumeName, const char *fileName)
{ {
m_vid = vid; m_vid = vid;
m_cid = cid; m_cid = cid;
pwr_tStatus sts;
strcpy(m_volumeName, volumeName); strcpy(m_volumeName, volumeName);
dcli_translate_filename(m_fileName, fileName); dcli_translate_filename(m_fileName, fileName);
//int rc = m_env->txn_begin(0, (DbTxn **)&m_txn, 0); //int rc = m_env->txn_begin(0, (DbTxn **)&m_txn, 0);
size_t rbSize = 0;
pwr_uVolume volume;
pwr_tTime time;
pwr_tOid oid;
openDb(false);
openDb(true);
memset(&volume, 0, sizeof(volume));
switch (cid) {
case pwr_eClass_RootVolume:
rbSize = sizeof(pwr_sRootVolume);
break;
case pwr_eClass_SubVolume:
rbSize = sizeof(pwr_sSubVolume);
break;
case pwr_eClass_SystemVolume:
rbSize = sizeof(pwr_sSystemVolume);
break;
case pwr_eClass_ClassVolume:
rbSize = sizeof(pwr_sClassVolume);
break;
case pwr_eClass_WorkBenchVolume:
rbSize = sizeof(pwr_sWorkBenchVolume);
break;
case pwr_eClass_DirectoryVolume:
rbSize = sizeof(pwr_sDirectoryVolume);
break;
case pwr_eClass_SharedVolume:
case pwr_eClass_CreateVolume:
case pwr_eClass_MountVolume:
case pwr_eClass_MountObject:
case pwr_eClass_VolatileVolume:
case pwr_eClass_DynamicVolume:
default:
break;
}
oid.vid = vid;
oid.oix = pwr_cNOix;
wb_name n(volumeName);
pwr_mClassDef flags;
try {
m_env->txn_begin(0, (DbTxn **)&m_txn, 0);
importHead(oid, cid, pwr_cNOid, pwr_cNOid, pwr_cNOid, pwr_cNOid, pwr_cNOid, n.name(), n.normName(), flags, time, time, time, rbSize, 0);
wb_db_info i(this);
i.get(m_txn);
m_vid = i.vid();
m_cid = i.cid();
strcpy(m_volumeName, i.name());
commit(&sts);
}
catch (DbException &e) {
//txn->abort();
printf("exeption: %s\n", e.what());
}
} }
wb_db_txn *wb_db::begin(wb_db_txn *txn) wb_db_txn *wb_db::begin(wb_db_txn *txn)
......
...@@ -65,6 +65,7 @@ public: ...@@ -65,6 +65,7 @@ public:
void open(const char *fileName); void open(const char *fileName);
void openDb(bool useTxn); void openDb(bool useTxn);
void copy(wb_export &e, const char *fileName);
void create(pwr_tVid vid, pwr_tCid cid, const char *volumeName, const char *fileName); void create(pwr_tVid vid, pwr_tCid cid, const char *volumeName, const char *fileName);
int del_family(wb_db_txn *txn, Dbc *cp, pwr_tOid poid); int del_family(wb_db_txn *txn, Dbc *cp, pwr_tOid poid);
......
...@@ -27,5 +27,3 @@ public: ...@@ -27,5 +27,3 @@ public:
}; };
#endif #endif
...@@ -37,6 +37,21 @@ wb_vrepdb::wb_vrepdb(wb_erep *erep, const char *fileName) : ...@@ -37,6 +37,21 @@ wb_vrepdb::wb_vrepdb(wb_erep *erep, const char *fileName) :
m_merep = m_erep->merep(); m_merep = m_erep->merep();
} }
wb_vrepdb::wb_vrepdb(wb_erep *erep, pwr_tVid vid, pwr_tCid cid, const char *volumeName, const char *fileName) :
m_erep(erep), m_nRef(0), m_ohead()
{
strcpy(m_fileName, fileName);
m_db = new wb_db();
m_db->create(vid, cid, volumeName, fileName);
m_ohead.setDb(m_db);
strcpy(m_name, m_db->volumeName());
m_vid = m_db->vid();
m_cid = m_db->cid();
m_merep = m_erep->merep();
}
wb_erep *wb_vrepdb::erep() wb_erep *wb_vrepdb::erep()
{ {
return m_erep; return m_erep;
......
...@@ -25,6 +25,7 @@ public: ...@@ -25,6 +25,7 @@ public:
wb_db_ohead m_ohead; wb_db_ohead m_ohead;
wb_vrepdb(wb_erep *erep, const char *fileName); wb_vrepdb(wb_erep *erep, const char *fileName);
wb_vrepdb(wb_erep *erep, pwr_tVid, pwr_tCid, const char *volumeName, const char *fileName);
virtual void unref(); virtual void unref();
virtual wb_vrep *ref(); virtual wb_vrep *ref();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment