Cleanups.

This commit is contained in:
JoelKatz
2013-01-29 14:28:05 -08:00
parent 1a6eac274f
commit 6b4141f583
5 changed files with 33 additions and 27 deletions

View File

@@ -214,6 +214,16 @@ std::string SerializedTransaction::getSQLInsertHeader()
return "INSERT INTO Transactions " + getSQLValueHeader() + " VALUES ";
}
std::string SerializedTransaction::getSQLInsertIgnoreHeader()
{
return "INSERT OR IGNORE INTO Transactions " + getSQLValueHeader() + " VALUES ";
}
std::string SerializedTransaction::getSQLInsertReplaceHeader()
{
return "INSERT OR REPLACE INTO Transactions " + getSQLValueHeader() + " VALUES ";
}
std::string SerializedTransaction::getMetaSQLInsertHeader()
{
return "INSERT INTO Transactions " + getMetaSQLValueHeader() + " VALUES ";

View File

@@ -73,6 +73,8 @@ public:
// SQL Functions
static std::string getSQLValueHeader();
static std::string getSQLInsertHeader();
static std::string getSQLInsertIgnoreHeader();
static std::string getSQLInsertReplaceHeader();
std::string getSQL(std::string& sql, uint32 inLedger, char status) const;
std::string getSQL(uint32 inLedger, char status) const;
std::string getSQL(Serializer rawTxn, uint32 inLedger, char status) const;

View File

@@ -126,35 +126,25 @@ void Transaction::setStatus(TransStatus ts, uint32 lseq)
mInLedger = lseq;
}
void Transaction::saveTransaction(const Transaction::pointer& txn)
void Transaction::save()
{
txn->save();
}
bool Transaction::save()
{
if ((mStatus == INVALID) || (mStatus == REMOVED)) return false;
if ((mStatus == INVALID) || (mStatus == REMOVED))
return;
char status;
switch (mStatus)
{
case NEW: status = TXN_SQL_NEW; break;
case INCLUDED: status = TXN_SQL_INCLUDED; break;
case CONFLICTED: status = TXN_SQL_CONFLICT; break;
case COMMITTED: status = TXN_SQL_VALIDATED; break;
case HELD: status = TXN_SQL_HELD; break;
default: status = TXN_SQL_UNKNOWN;
case NEW: status = TXN_SQL_NEW; break;
case INCLUDED: status = TXN_SQL_INCLUDED; break;
case CONFLICTED: status = TXN_SQL_CONFLICT; break;
case COMMITTED: status = TXN_SQL_VALIDATED; break;
case HELD: status = TXN_SQL_HELD; break;
default: status = TXN_SQL_UNKNOWN;
}
static boost::format selStat("SELECT Status FROM Transactions WHERE TransID = '%s';");
std::string exists = boost::str(selStat % mTransaction->getTransactionID().GetHex());
Database *db = theApp->getTxnDB()->getDB();
ScopedLock dbLock(theApp->getTxnDB()->getDBLock());
if (SQL_EXISTS(db, exists))
return false;
return
db->executeSQL(mTransaction->getSQLInsertHeader() + mTransaction->getSQL(getLedger(), status) + ";");
db->executeSQL(mTransaction->getSQLInsertReplaceHeader() + mTransaction->getSQL(getLedger(), status) + ";");
}
Transaction::pointer Transaction::transactionFromSQL(Database* db, bool bValidate)

View File

@@ -97,8 +97,7 @@ public:
void setLedger(uint32 ledger) { mInLedger = ledger; }
// database functions
static void saveTransaction(Transaction::ref);
bool save();
void save();
static Transaction::pointer load(const uint256& id);
static Transaction::pointer findFrom(const RippleAddress& fromID, uint32 seq);

View File

@@ -66,18 +66,23 @@ SerializedTransaction::pointer TransactionMaster::fetch(SHAMapItem::ref item, SH
return txn;
}
static void saveTransactionHelper(Transaction::pointer txn, LoadEvent::pointer)
static void saveHelper(Transaction::pointer txn, LoadEvent::pointer l)
{
Transaction::saveTransaction(txn);
txn->save();
l.reset();
}
bool TransactionMaster::canonicalize(Transaction::pointer& txn, bool may_be_new)
{
uint256 tid = txn->getID();
if (!tid) return false;
if (mCache.canonicalize(tid, txn)) return true;
if (!tid)
return false;
if (mCache.canonicalize(tid, txn))
return true;
if (may_be_new)
theApp->getAuxService().post(boost::bind(&saveTransactionHelper, txn,
theApp->getAuxService().post(boost::bind(saveHelper, txn,
theApp->getJobQueue().getLoadEvent(jtDISK)));
return false;
}