Commit e85e61a8 authored by lw's avatar lw

Size of bodies, and modification times are updated in object header

parent 8f8045fd
/*
* Proview $Id: wb_convert_volume.h,v 1.1 2006-05-21 22:36:22 lw Exp $
* Proview $Id: wb_convert_volume.h,v 1.2 2006-05-26 11:57:28 lw Exp $
* Copyright (C) 2005 SSAB Oxelösund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -36,8 +36,8 @@ public:
virtual ~wb_convert_volume() {}
void setUpdate(bool update) { m_update = update;}
virtual void updateObject(pwr_tOid oid, pwr_tCid cid) = 0;
virtual void checkObject(pwr_tOid oid, pwr_tCid cid) = 0;
virtual pwr_tStatus updateObject(pwr_tOid oid, pwr_tCid cid) = 0;
virtual pwr_tStatus checkObject(pwr_tOid oid, pwr_tCid cid) = 0;
};
#endif
/*
* Proview $Id: wb_db.cpp,v 1.34 2006-05-21 22:30:50 lw Exp $
* Proview $Id: wb_db.cpp,v 1.35 2006-05-26 11:57:28 lw Exp $
* Copyright (C) 2005 SSAB Oxelösund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -406,7 +406,6 @@ wb_db_ohead &wb_db_ohead::get(wb_db_txn *txn)
rc = m_db->m_t_ohead->get(txn, &m_key, &m_data, 0);
if (rc)
// printf("wb_db_ohead::get(txn), get, rc %d\n", rc);
throw DbException( rc);
return *this;
}
......@@ -463,7 +462,6 @@ void wb_db_ohead::clear()
void wb_db_ohead::iter(void (*print)(pwr_tOid oid, db_sObject *op))
{
int rc = 0;
//Dbc *cp;
rc = m_db->m_t_ohead->cursor(m_db->m_txn, &m_dbc, 0);
......@@ -481,7 +479,6 @@ void wb_db_ohead::iter(void (*print)(pwr_tOid oid, db_sObject *op))
/* Walk through the database and print out the key/data pairs. */
//int rc = m_dbc->get(&m_key, &m_data, DB_FIRST);
while ((rc = m_dbc->get(&m_key, &m_data, DB_NEXT)) == 0) {
print(m_oid, &m_o);
......@@ -493,7 +490,6 @@ void wb_db_ohead::iter(void (*print)(pwr_tOid oid, db_sObject *op))
void wb_db_ohead::iter(wb_import &i)
{
int rc = 0;
//Dbc *cp;
rc = m_db->m_t_ohead->cursor(m_db->m_txn, &m_dbc, 0);
......@@ -567,7 +563,6 @@ int wb_db_rbody::del(wb_db_txn *txn)
void wb_db_rbody::iter(void (*print)(pwr_tOid oid))
{
int rc = 0;
//static char b[1];
m_db->m_t_rbody->cursor(m_db->m_txn, &m_dbc, 0);
......@@ -576,18 +571,10 @@ void wb_db_rbody::iter(void (*print)(pwr_tOid oid))
memset(&m_oid, 0, sizeof(m_oid));
m_key.set_data(&m_oid);
m_key.set_ulen(sizeof(m_oid));
//m_key.set_dlen(sizeof(m_oid));
//m_key.set_size(sizeof(m_oid));
m_key.set_flags(DB_DBT_USERMEM);
//m_data.set_data(b);
//m_data.set_ulen(0);
//m_data.set_dlen(sizeof(b));
//m_data.set_size(sizeof(b));
//m_data.set_doff(0);
m_data.set_flags(DB_DBT_USERMEM|DB_DBT_PARTIAL);
/* Walk through the database and print out the key/data pairs. */
//int rc = m_dbc->get(&m_key, &m_data, DB_FIRST);
while (1) {
try {
......@@ -689,7 +676,6 @@ int wb_db_dbody::del(wb_db_txn *txn)
void wb_db_dbody::iter(void (*print)(pwr_tOid oid))
{
int rc = 0;
//static char b[65000];
m_db->m_t_dbody->cursor(m_db->m_txn, &m_dbc, 0);
......@@ -698,16 +684,10 @@ void wb_db_dbody::iter(void (*print)(pwr_tOid oid))
m_key.set_data(&m_oid);
m_key.set_ulen(sizeof(m_oid));
m_key.set_flags(DB_DBT_USERMEM);
//m_data.set_data(b);
//m_data.set_ulen(sizeof(b));
//m_data.set_dlen(sizeof(b));
//m_data.set_size(sizeof(b));
m_data.set_flags(DB_DBT_USERMEM|DB_DBT_PARTIAL);
//m_data.set_flags(DB_DBT_USERMEM);
/* Walk through the database and print out the key/data pairs. */
//int rc = m_dbc->get(&m_key, &m_data, DB_FIRST);
while (1) {
......@@ -730,7 +710,6 @@ void wb_db_dbody::iter(void (*print)(pwr_tOid oid))
void wb_db_dbody::iter(wb_import &i)
{
int rc = 0;
//static char b[65000];
m_db->m_t_dbody->cursor(m_db->m_txn, &m_dbc, 0);
......@@ -739,16 +718,10 @@ void wb_db_dbody::iter(wb_import &i)
m_key.set_data(&m_oid);
m_key.set_ulen(sizeof(m_oid));
m_key.set_flags(DB_DBT_USERMEM);
//m_data.set_data(b);
//m_data.set_ulen(sizeof(b));
//m_data.set_dlen(sizeof(b));
//m_data.set_size(sizeof(b));
m_data.set_flags(DB_DBT_MALLOC);
//m_data.set_flags(DB_DBT_USERMEM);
/* Walk through the database and print out the key/data pairs. */
//int rc = m_dbc->get(&m_key, &m_data, DB_FIRST);
while (1) {
......@@ -802,7 +775,6 @@ void wb_db::copy(wb_export &e, const char *fileName)
{
pwr_tStatus sts;
dcli_translate_filename(m_fileName, fileName);
//int rc = m_env->txn_begin(0, (DbTxn **)&m_txn, 0);
openDb(false);
importVolume(e);
......@@ -833,7 +805,6 @@ void wb_db::create(pwr_tVid vid, pwr_tCid cid, const char *volumeName, const cha
pwr_tStatus sts;
strcpy(m_volumeName, volumeName);
dcli_translate_filename(m_fileName, fileName);
//int rc = m_env->txn_begin(0, (DbTxn **)&m_txn, 0);
size_t rbSize = 0;
pwr_uVolume volume;
pwr_tTime time;
......@@ -922,9 +893,6 @@ void wb_db::open(const char *fileName)
openDb(true);
//m_env->txn_begin(0, (DbTxn **)&m_txn, 0);
//m_txn = 0;
try {
m_env->txn_begin(0, (DbTxn **)&m_txn, 0);
......@@ -1070,7 +1038,6 @@ void wb_db::openDb(bool useTxn)
m_t_info = new Db(m_env, 0);
rc = m_t_class->set_bt_compare(wb_db_class_bt_compare);
// printf("m_t_class->set_bt_compare %d\n", rc);
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR > 0
u_int32_t flags;
......@@ -1079,7 +1046,6 @@ void wb_db::openDb(bool useTxn)
m_t_ohead->open(NULL, "ohead", NULL, DB_BTREE, flags, 0 /* S_IRUSR | S_IWUSR */);
m_t_rbody->open(NULL, "rbody", NULL, DB_BTREE, flags, 0 /* S_IRUSR | S_IWUSR */);
m_t_dbody->open(NULL, "dbody", NULL, DB_BTREE, flags, 0 /* S_IRUSR | S_IWUSR */);
// m_t_dbody->open(NULL, "dbody", NULL, DB_BTREE, DB_CREATE | DB_AUTO_COMMIT, 0 /* S_IRUSR | S_IWUSR */);
m_t_class->open(NULL, "class", NULL, DB_BTREE, flags, 0 /* S_IRUSR | S_IWUSR */);
m_t_name->open(NULL, "name", NULL, DB_BTREE, flags, 0 /* S_IRUSR | S_IWUSR */);
m_t_info->open(NULL, "info", NULL, DB_BTREE, flags, 0 /* S_IRUSR | S_IWUSR */);
......@@ -1087,7 +1053,6 @@ void wb_db::openDb(bool useTxn)
m_t_ohead->open("ohead", NULL, DB_BTREE, DB_CREATE, 0 /* S_IRUSR | S_IWUSR */);
m_t_rbody->open("rbody", NULL, DB_BTREE, DB_CREATE, 0 /* S_IRUSR | S_IWUSR */);
m_t_dbody->open("dbody", NULL, DB_BTREE, DB_CREATE, 0 /* S_IRUSR | S_IWUSR */);
// m_t_dbody->open(NULL, "dbody", NULL, DB_BTREE, DB_CREATE | DB_AUTO_COMMIT, 0 /* S_IRUSR | S_IWUSR */);
m_t_class->open("class", NULL, DB_BTREE, DB_CREATE, 0 /* S_IRUSR | S_IWUSR */);
m_t_name->open("name", NULL, DB_BTREE, DB_CREATE, 0 /* S_IRUSR | S_IWUSR */);
m_t_info->open("info", NULL, DB_BTREE, DB_CREATE, 0 /* S_IRUSR | S_IWUSR */);
......@@ -1124,7 +1089,6 @@ pwr_tOid wb_db::new_oid(wb_db_txn *txn, pwr_tOid oid)
try {
wb_db_ohead o(this, txn, woid);
} catch (DbException &e) {
// cout << e.what() << " old oid not found, keep\n";
return woid;
}
cout << " Old oix found, force new " << woid.oix << " !\n";
......@@ -1286,16 +1250,13 @@ bool wb_db::importHead(pwr_tOid oid, pwr_tCid cid, pwr_tOid poid,
{
wb_db_ohead o(this, oid, cid, poid, boid, aoid, foid, loid, name, normname, flags, ohTime, rbTime, dbTime, rbSize, dbSize);
o.put(m_txn);
//printf("head put: %d.%d %s\n", oid.vid, oid.oix, name);
wb_db_name n(this, oid, poid, normname);
int rc = n.put(m_txn);
if (rc) {
//printf("importHead: n.put: %d, %d.%d %s\n", rc, poid.vid, poid.oix, name);
char newName[50];
sprintf(newName, "O%u_%s", oid.oix, name);
newName[31] = '\0';
wb_name nn(newName);
// wb_name nn(name);
o.name(nn);
o.put(m_txn);
n.name(nn);
......@@ -1318,17 +1279,27 @@ bool wb_db::importHead(pwr_tOid oid, pwr_tCid cid, pwr_tOid poid,
bool wb_db::importRbody(pwr_tOid oid, size_t size, void *body)
{
wb_db_rbody rb(this, oid, size, body);
//printf("rbody size: %d.%d %d\n", oid.vid, oid.oix, size);
rb.put(m_txn);
wb_db_rbody b(this, oid, size, body);
wb_db_ohead oh(this, oid);
pwr_tTime time;
clock_gettime(CLOCK_REALTIME, &time);
oh.get(m_txn);
oh.rbTime(time);
oh.put(m_txn);
b.put(m_txn);
return true;
}
bool wb_db::importDbody(pwr_tOid oid, size_t size, void *body)
{
wb_db_dbody db(this, oid, size, body);
//printf("dbody size: %d.%d %d\n", oid.vid, oid.oix, size);
db.put(m_txn);
wb_db_dbody b(this, oid, size, body);
wb_db_ohead oh(this, oid);
pwr_tTime time;
clock_gettime(CLOCK_REALTIME, &time);
oh.get(m_txn);
oh.dbTime(time);
oh.put(m_txn);
b.put(m_txn);
return true;
}
......
/*
* Proview $Id: wb_vrepdb.cpp,v 1.44 2006-05-23 10:19:51 claes Exp $
* Proview $Id: wb_vrepdb.cpp,v 1.45 2006-05-26 11:57:28 lw Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -642,6 +642,8 @@ bool wb_vrepdb::writeAttribute(pwr_tStatus *sts, wb_orep *orp, pwr_eBix bix, siz
int rc = 0;
m_ohead.get(m_db->m_txn, orp->oid());
*sts = LDH__SUCCESS;
pwr_tTime time;
clock_gettime(CLOCK_REALTIME, &time);
switch (bix) {
case pwr_eBix_rt:
......@@ -649,6 +651,8 @@ bool wb_vrepdb::writeAttribute(pwr_tStatus *sts, wb_orep *orp, pwr_eBix bix, siz
wb_db_rbody rb(m_db, m_ohead.oid());
rc = rb.put(m_db->m_txn, offset, size, p);
m_ohead.rbTime(time);
m_ohead.put(m_db->m_txn);
if (rc)
printf("wb_vrepdb::writeAttribute rb.put rc %d\n", rc);
break;
......@@ -658,6 +662,8 @@ bool wb_vrepdb::writeAttribute(pwr_tStatus *sts, wb_orep *orp, pwr_eBix bix, siz
wb_db_dbody db(m_db, m_ohead.oid());
rc = db.put(m_db->m_txn, offset, size, p);
m_ohead.dbTime(time);
m_ohead.put(m_db->m_txn);
if (rc)
printf("wb_vrepdb::writeAttribute db.put rc %d\n", rc);
break;
......@@ -747,6 +753,8 @@ bool wb_vrepdb::writeBody(pwr_tStatus *sts, wb_orep *o, pwr_eBix bix, void *p)
int rc = 0;
m_ohead.get(m_db->m_txn, o->oid());
*sts = LDH__SUCCESS;
pwr_tTime time;
clock_gettime(CLOCK_REALTIME, &time);
switch (bix) {
case pwr_eBix_rt:
......@@ -756,6 +764,8 @@ bool wb_vrepdb::writeBody(pwr_tStatus *sts, wb_orep *o, pwr_eBix bix, void *p)
rc = rb.put(m_db->m_txn, 0, m_ohead.rbSize(), p);
if (rc)
printf("wb_vrepdb::writeBody rb.put rc %d\n", rc);
m_ohead.rbTime(time);
m_ohead.put(m_db->m_txn);
break;
}
case pwr_eBix_dev:
......@@ -765,6 +775,8 @@ bool wb_vrepdb::writeBody(pwr_tStatus *sts, wb_orep *o, pwr_eBix bix, void *p)
rc = db.put(m_db->m_txn, 0, m_ohead.dbSize(), p);
if (rc)
printf("wb_vrepdb::writeBody db.put rc %d\n", rc);
m_ohead.dbTime(time);
m_ohead.put(m_db->m_txn);
break;
}
default:
......@@ -1567,7 +1579,7 @@ bool wb_vrepdb::importPaste()
}
void wb_vrepdb::checkMeta()
pwr_tStatus wb_vrepdb::checkMeta()
{
wb_db_class c(m_db);
......@@ -1581,15 +1593,17 @@ void wb_vrepdb::checkMeta()
c.iter(this);
if (m_classCount == 0)
return;
return LDH__SUCCESS;
char buff[256];
sprintf(buff, "A total of %d object instances of %d classes can to be updated", m_totalInstanceCount, m_classCount);
MsgWindow::message('W', buff);
return LDH__SUCCESS;
}
void wb_vrepdb::updateMeta()
pwr_tStatus wb_vrepdb::updateMeta()
{
wb_db_class c(m_db);
......@@ -1604,10 +1618,10 @@ void wb_vrepdb::updateMeta()
c.iter(this);
} catch (DbException &e) {
printf("vrepdb: %s\n", e.what());
return;
return LDH__DBERROR;
} catch (wb_error &e) {
printf("vrepdb: %s\n", e.what().c_str());
return;
return LDH__DBERROR;
}
if (m_classCount != 0) {
......@@ -1623,15 +1637,17 @@ void wb_vrepdb::updateMeta()
if (sts) {
MsgWindow::message(co_error(sts), "Could not save class updates to database");
return;
return LDH__DBERROR;
}
}
m_merep->copyFiles(m_fileName, m_erep->merep());
delete m_merep;
m_merep = new wb_merep(m_fileName, m_erep, this);
return LDH__SUCCESS;
}
void wb_vrepdb::checkObject(pwr_tOid oid, pwr_tCid cid)
pwr_tStatus wb_vrepdb::checkObject(pwr_tOid oid, pwr_tCid cid)
{
static wb_cdrep *o_crep = 0;
static wb_cdrep *n_crep = 0;
......@@ -1693,18 +1709,18 @@ void wb_vrepdb::checkObject(pwr_tOid oid, pwr_tCid cid)
}
if (skip)
return;
return LDH__SUCCESS;
m_instanceCount++;
return LDH__SUCCESS;
}
void wb_vrepdb::updateObject(pwr_tOid oid, pwr_tCid cid)
pwr_tStatus wb_vrepdb::updateObject(pwr_tOid oid, pwr_tCid cid)
{
static wb_cdrep *o_crep = 0;
static wb_cdrep *n_crep = 0;
static bool skip = false;
pwr_tTime o_time = {0, 0};
pwr_tTime n_time = {0, 0};
......@@ -1760,7 +1776,7 @@ void wb_vrepdb::updateObject(pwr_tOid oid, pwr_tCid cid)
}
if (skip) {
return;
return LDH__SUCCESS;
}
m_instanceCount++;
......@@ -1768,7 +1784,7 @@ void wb_vrepdb::updateObject(pwr_tOid oid, pwr_tCid cid)
m_ohead.get(m_db->m_txn, oid);
if (time_Acomp(&o_time, &n_time) == 0)
return;
return LDH__SUCCESS;
wb_db_rbody rb(m_db, m_ohead.oid());
void *rp = calloc(1, m_ohead.rbSize());
......@@ -1793,18 +1809,30 @@ void wb_vrepdb::updateObject(pwr_tOid oid, pwr_tCid cid)
free(rp);
free(dp);
pwr_tTime time;
clock_gettime(CLOCK_REALTIME, &time);
if (rbody) {
rc = rb.put(m_db->m_txn, 0, m_ohead.rbSize(), rbody);
rc = rb.put(m_db->m_txn, 0, rsize, rbody);
if (rc)
printf("wb_vrepdb::writeBody rb.put rc %d\n", rc);
rc = 0;
free(rbody);
m_ohead.rbSize(rsize);
m_ohead.rbTime(time);
}
if (dbody) {
rc = db.put(m_db->m_txn, 0, m_ohead.dbSize(), dbody);
rc = db.put(m_db->m_txn, 0, dsize, dbody);
if (rc)
printf("wb_vrepdb::writeBody db.put rc %d\n", rc);
free(dbody);
m_ohead.dbSize(dsize);
m_ohead.dbTime(time);
}
}
m_ohead.ohTime(time);
m_ohead.put(m_db->m_txn);
return LDH__SUCCESS;
}
/*
* Proview $Id: wb_vrepdb.h,v 1.30 2006-05-21 22:30:50 lw Exp $
* Proview $Id: wb_vrepdb.h,v 1.31 2006-05-26 11:57:28 lw Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -182,8 +182,8 @@ public:
void load();
void checkMeta();
void updateMeta();
pwr_tStatus checkMeta();
pwr_tStatus updateMeta();
virtual bool exportVolume(wb_import &e);
......@@ -227,8 +227,8 @@ public:
// virtual void checkClassList(pwr_tOid oid, pwr_tCid cid, bool update);
virtual void updateObject(pwr_tOid oid, pwr_tCid cid);
virtual void checkObject(pwr_tOid oid, pwr_tCid cid);
virtual pwr_tStatus updateObject(pwr_tOid oid, pwr_tCid cid);
virtual pwr_tStatus checkObject(pwr_tOid oid, pwr_tCid cid);
};
#endif
/*
* Proview $Id: wb_vrepdbs.h,v 1.35 2006-05-22 09:40:39 claes Exp $
* Proview $Id: wb_vrepdbs.h,v 1.36 2006-05-26 11:57:28 lw Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -159,7 +159,7 @@ public:
virtual bool exportDocBlock(wb_import &e);
virtual bool exportMeta(wb_import &e);
virtual bool exportTree(wb_treeimport &i, pwr_tOid oid);
bool wb_vrepdbs::exportTreeObject(wb_treeimport &i, dbs_sObject *op, bool isRoot);
bool exportTreeObject(wb_treeimport &i, dbs_sObject *op, bool isRoot);
virtual bool importTree(bool keepref) { return false;}
virtual bool importTreeObject(wb_merep *merep, pwr_tOid oid, pwr_tCid cid, pwr_tOid poid,
pwr_tOid boid, const char *name, pwr_mClassDef flags,
......
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