#include <TableImpl.h>
Inheritance diagram for TableImpl:
Public Member Functions | |
TableImpl () | |
~TableImpl () | |
void | setDB (Database *db) |
void | setSystemDB (Database *db) |
void | setLockManager (LockManager *lmgr) |
void | setTrans (Transaction **t) |
DataType | getFieldType (const char *name) |
int | getFieldOffset (const char *name) |
size_t | getFieldLength (const char *name) |
DbRetVal | getFieldInfo (const char *fieldName, FieldInfo *&info) |
List | getFieldNameList () |
void | setCondition (Condition *p) |
sets condition for the select, update and delete operations | |
DbRetVal | bindFld (const char *name, void *val) |
binds application buffer to the specified field of the table. | |
void | markFldNull (const char *name) |
marks the specified field to insert null when insert method is called. | |
void | markFldNull (int colpos) |
marks the specified field to insert null when insert method is called. | |
bool | isFldNull (const char *name) |
checks whether the field value is null. | |
bool | isFldNull (int colpos) |
checks whether the field value is null for the specified field position. | |
void | clearFldNull (const char *name) |
clears the null mark which is set before. | |
void | clearFldNull (int colpos) |
clears the null mark which is set before. | |
DbRetVal | insertTuple () |
insert the tuple into the table. | |
DbRetVal | updateTuple () |
update values in the current tuple of the table. | |
DbRetVal | deleteTuple () |
deletes the current tuple of the table. | |
int | deleteWhere () |
deletes all the records which satisfies the condition set. | |
int | truncate () |
deletes the all the records in the table. | |
DbRetVal | execute () |
executes the select statement. | |
void * | fetch () |
fetches the next tuple in the table which satisfies the condition specified. | |
void * | fetch (DbRetVal &rv) |
void * | fetchNoBind () |
fetches the next tuple in the table which satisfies the condition specified. | |
void * | fetchNoBind (DbRetVal &rv) |
DbRetVal | close () |
closes the scan. | |
long | spaceUsed () |
Retrieves the total space used for this table in bytes. | |
long | numTuples () |
Retrieves the total number of tuples present in this table. | |
int | pagesUsed () |
void | printInfo () |
DbRetVal | lock (bool shared) |
takes lock on the table if bool shared flag is set, it will take shared lock, or else exclusive lock | |
DbRetVal | unlock () |
releases the lock acquired on the table | |
DbRetVal | setUndoLogging (bool flag) |
sets the undo log flag. | |
void | printSQLIndexString () |
char * | getName () |
void | setTableInfo (char *name, int tblid, size_t length, int numFld, int numIdx, void *chunk) |
Data Fields | |
FieldList | fldList_ |
int | numIndexes_ |
char ** | indexPtr_ |
IndexInfo ** | idxInfo |
int | useIndex_ |
bool | isPlanCreated |
Database * | db_ |
Database * | sysDB_ |
bool | isIntUsedForNULL |
int | iNullInfo |
char * | cNullInfo |
int | iNotNullInfo |
char * | cNotNullInfo |
Friends | |
class | DatabaseManagerImpl |
Definition at line 65 of file TableImpl.h.
TableImpl::TableImpl | ( | ) | [inline] |
Definition at line 130 of file TableImpl.h.
References cNotNullInfo, cNullInfo, db_, idxInfo, indexPtr_, iNotNullInfo, iNullInfo, isIntUsedForNULL, isPlanCreated, unknownScan, and useIndex_.
00130 { db_ = NULL; chunkPtr_ = NULL; iter = NULL; 00131 idxInfo = NULL; indexPtr_ = NULL; scanType_ = unknownScan; 00132 pred_ = NULL; useIndex_ = -1; numFlds_ = 0; 00133 iNullInfo = 0; cNullInfo = NULL; isIntUsedForNULL = true; 00134 iNotNullInfo = 0; cNotNullInfo = NULL; 00135 isPlanCreated = false; undoFlag = true;}
TableImpl::~TableImpl | ( | ) |
Definition at line 781 of file TableImpl.cxx.
References cNullInfo, fldList_, idxInfo, indexPtr_, and FieldList::removeAll().
00782 { 00783 if (NULL != iter ) { delete iter; iter = NULL; } 00784 if (NULL != indexPtr_) { delete[] indexPtr_; indexPtr_ = NULL; } 00785 if (NULL != idxInfo) 00786 { 00787 for (int i = 0; i < numIndexes_; i++) delete idxInfo[i]; 00788 delete[] idxInfo; 00789 idxInfo = NULL; 00790 } 00791 if (numFlds_ > 31 && cNullInfo != NULL) { free(cNullInfo); cNullInfo = NULL; } 00792 00793 fldList_.removeAll(); 00794 00795 }
Here is the call graph for this function:
DbRetVal TableImpl::bindFld | ( | const char * | name, | |
void * | val | |||
) | [virtual] |
binds application buffer to the specified field of the table.
Before doing any DML operations required fields are binded first. Below are the candidates for this:
1.All the fields in the projection list of select statement.
2.Field list in the insert statement.
3.Fields in the assignment list of update statement.
name | field name in the table | |
val | address of the application buffer. Memory should be allocated by the application before binding the buffer. |
Implements Table.
Definition at line 27 of file TableImpl.cxx.
References ErrNotExists, fldList_, OK, printError, and FieldList::updateBindVal().
00028 { 00029 //set it in the field list 00030 DbRetVal rv = fldList_.updateBindVal(name, val); 00031 if (OK != rv) { 00032 printError(ErrNotExists, "Field %s does not exist", name); 00033 return rv; 00034 } 00035 return OK; 00036 }
Here is the call graph for this function:
void TableImpl::clearFldNull | ( | int | colpos | ) | [virtual] |
clears the null mark which is set before.
colpos | field position |
Implements Table.
Definition at line 98 of file TableImpl.cxx.
References CLEARBIT, cNullInfo, iNullInfo, and isIntUsedForNULL.
00099 { 00100 if (colpos <1 || colpos > numFlds_) return; 00101 if (isIntUsedForNULL) { 00102 CLEARBIT(iNullInfo, colpos); 00103 } 00104 else 00105 cNullInfo[colpos-1] = 0; 00106 return; 00107 }
void TableImpl::clearFldNull | ( | const char * | name | ) | [virtual] |
clears the null mark which is set before.
name | field name |
Implements Table.
Definition at line 86 of file TableImpl.cxx.
References ErrNotExists, fldList_, FieldList::getFieldPosition(), and printError.
00087 { 00088 int colpos = fldList_.getFieldPosition(name); 00089 if (-1 == colpos) 00090 { 00091 printError(ErrNotExists, "Field %s does not exist", name); 00092 return; 00093 } 00094 00095 clearFldNull(colpos); 00096 }
Here is the call graph for this function:
DbRetVal TableImpl::close | ( | ) | [virtual] |
closes the scan.
Needs to be called before calling execute again on the same table handle. It releases the resources acquired during the scan.
Implements Table.
Definition at line 733 of file TableImpl.cxx.
References TupleIterator::close(), ErrNotOpen, OK, and printError.
Referenced by deleteWhere().
00734 { 00735 if (NULL == iter) 00736 { 00737 printError(ErrNotOpen,"Scan not open"); 00738 return ErrNotOpen; 00739 } 00740 iter->close(); 00741 delete iter; 00742 iter = NULL; 00743 return OK; 00744 }
Here is the call graph for this function:
Here is the caller graph for this function:
DbRetVal TableImpl::deleteTuple | ( | ) | [virtual] |
deletes the current tuple of the table.
It works only on top of select. using fetch first go to the tuple to be deleted, then call this method to delete.
To delete all the tuples, do not set any condition and call fetch followed by delete in a loop till fetch exhausts.
Implements Table.
Definition at line 398 of file TableImpl.cxx.
References db_, DeleteOperation, ErrLockTimeOut, ErrNotOpen, LockManager::getExclusiveLock(), idxInfo, indexPtr_, OK, printError, LockManager::releaseLock(), and sysDB_.
Referenced by deleteWhere().
00399 { 00400 if (NULL == curTuple_) 00401 { 00402 printError(ErrNotOpen, "Scan not open: No Current tuple"); 00403 return ErrNotOpen; 00404 } 00405 DbRetVal ret = lMgr_->getExclusiveLock(curTuple_, trans); 00406 if (OK != ret) 00407 { 00408 printError(ret, "Could not get lock for the delete tuple %x", curTuple_); 00409 return ErrLockTimeOut; 00410 } 00411 00412 if (NULL != indexPtr_) 00413 { 00414 int i; 00415 //it has index 00416 for (i = 0; i < numIndexes_ ; i++) 00417 { 00418 ret = deleteIndexNode(*trans, indexPtr_[i], idxInfo[i], curTuple_); 00419 if (ret != OK) break; 00420 } 00421 if (i != numIndexes_ ) 00422 { 00423 for (int j = 0; j < i ; j++) 00424 insertIndexNode(*trans, indexPtr_[j], idxInfo[j], curTuple_); 00425 lMgr_->releaseLock(curTuple_); 00426 (*trans)->removeFromHasList(db_, curTuple_); 00427 printError(ret, "Unable to insert index node for tuple %x", curTuple_); 00428 return ret; 00429 } 00430 } 00431 ((Chunk*)chunkPtr_)->free(db_, curTuple_); 00432 if (undoFlag) 00433 ret = (*trans)->appendUndoLog(sysDB_, DeleteOperation, curTuple_, length_); 00434 return ret; 00435 }
Here is the call graph for this function:
Here is the caller graph for this function:
int TableImpl::deleteWhere | ( | ) | [virtual] |
deletes all the records which satisfies the condition set.
Implements Table.
Definition at line 437 of file TableImpl.cxx.
References close(), deleteTuple(), execute(), fetchNoBind(), OK, and printError.
Referenced by truncate().
00438 { 00439 int tuplesDeleted = 0; 00440 DbRetVal rv = OK; 00441 rv = execute(); 00442 if (rv !=OK) return (int) rv; 00443 while(true){ 00444 fetchNoBind( rv); 00445 if (rv != OK) { tuplesDeleted = (int)rv; break; } 00446 if (NULL == curTuple_) break; 00447 rv = deleteTuple(); 00448 if (rv != OK) { 00449 printError(rv, "Error: Could only delete %d tuples", tuplesDeleted); 00450 close(); 00451 return (int) rv; 00452 } 00453 tuplesDeleted++; 00454 } 00455 close(); 00456 return tuplesDeleted; 00457 }
Here is the call graph for this function:
Here is the caller graph for this function:
DbRetVal TableImpl::execute | ( | ) | [virtual] |
executes the select statement.
Based on the predicate(condition), respective index is chosen for the select. Application should call execute before they start fetching the values from the table.This starts scan on the table.
Implements Table.
Definition at line 110 of file TableImpl.cxx.
References ErrAlready, ErrSysFatal, ErrSysInternal, fullTableScan, idxInfo, OK, TupleIterator::open(), printError, Database::procSlot, PredicateImpl::setTable(), sysDB_, and useIndex_.
Referenced by deleteWhere().
00111 { 00112 if (NULL != iter) 00113 { 00114 printError(ErrAlready,"Scan already open:Close and re execute"); 00115 return ErrAlready; 00116 } 00117 //table ptr is set in predicate because it needs to access the 00118 //type and length to evaluate 00119 if( NULL != pred_) 00120 { 00121 PredicateImpl *pred = (PredicateImpl*) pred_; 00122 pred->setTable(this); 00123 } 00124 DbRetVal ret = OK; 00125 00126 ret = createPlan(); 00127 if (OK != ret) 00128 { 00129 printError(ErrSysInternal,"Unable to create the plan"); 00130 return ErrSysInternal; 00131 } 00132 if (useIndex_ >= 0) 00133 iter = new TupleIterator(pred_, scanType_, idxInfo[useIndex_], chunkPtr_, sysDB_->procSlot); 00134 else if (scanType_ == fullTableScan) 00135 iter = new TupleIterator(pred_, scanType_, NULL, chunkPtr_, sysDB_->procSlot); 00136 else 00137 { 00138 printError(ErrSysFatal,"Unable to create tuple iterator");//should never happen 00139 return ErrSysFatal; 00140 } 00141 ret = iter->open(); 00142 if (OK != ret) 00143 { 00144 printError(ret,"Unable to open the iterator"); 00145 return ret; 00146 } 00147 return OK; 00148 }
Here is the call graph for this function:
Here is the caller graph for this function:
void * TableImpl::fetch | ( | DbRetVal & | rv | ) | [virtual] |
Implements Table.
Definition at line 200 of file TableImpl.cxx.
References fetchNoBind().
00201 { 00202 fetchNoBind(rv); 00203 if (NULL == curTuple_) return curTuple_; 00204 copyValuesToBindBuffer(curTuple_); 00205 return curTuple_; 00206 }
Here is the call graph for this function:
void * TableImpl::fetch | ( | ) | [virtual] |
fetches the next tuple in the table which satisfies the condition specified.
execute should be called before calling this method. Application buffer should be binded to get the tuple values.
Implements Table.
Definition at line 193 of file TableImpl.cxx.
References fetchNoBind().
00194 { 00195 fetchNoBind(); 00196 if (NULL == curTuple_) return curTuple_; 00197 copyValuesToBindBuffer(curTuple_); 00198 return curTuple_; 00199 }
Here is the call graph for this function:
void * TableImpl::fetchNoBind | ( | DbRetVal & | rv | ) | [virtual] |
Implements Table.
Definition at line 266 of file TableImpl.cxx.
References Conf::config, ErrLockTimeOut, ErrNotOpen, Config::getMutexSecs(), Config::getMutexUSecs(), LockManager::getSharedLock(), LockManager::isExclusiveLocked(), TupleIterator::next(), OK, printError, READ_COMMITTED, READ_REPEATABLE, and os::select().
00267 { 00268 rv = OK; 00269 if (NULL == iter) 00270 { 00271 printError(ErrNotOpen,"Scan not open or Scan is closed\n"); 00272 rv = ErrNotOpen; 00273 return NULL; 00274 } 00275 void *prevTuple = curTuple_; 00276 curTuple_ = iter->next(); 00277 if (NULL == curTuple_) 00278 { 00279 return NULL; 00280 } 00281 DbRetVal lockRet = OK; 00282 if ((*trans)->isoLevel_ == READ_REPEATABLE) { 00283 lockRet = lMgr_->getSharedLock(curTuple_, trans); 00284 if (OK != lockRet) 00285 { 00286 printError(lockRet, "Unable to get the lock for the tuple %x", curTuple_); 00287 rv = ErrLockTimeOut; 00288 curTuple_ = prevTuple; 00289 return NULL; 00290 } 00291 00292 } 00293 else if ((*trans)->isoLevel_ == READ_COMMITTED) 00294 { 00295 //if iso level is read committed, operation duration lock is sufficent 00296 //so release it here itself. 00297 int tries = 5; 00298 struct timeval timeout; 00299 timeout.tv_sec = Conf::config.getMutexSecs(); 00300 timeout.tv_usec = Conf::config.getMutexUSecs(); 00301 00302 bool status = false; 00303 while(true) { 00304 lockRet = lMgr_->isExclusiveLocked( curTuple_, trans, status); 00305 if (OK != lockRet) 00306 { 00307 printError(lockRet, "Unable to get the lock for the tuple %x", curTuple_); 00308 curTuple_ = prevTuple; 00309 rv = ErrLockTimeOut; 00310 return NULL; 00311 } 00312 if (!status) break; 00313 tries--; 00314 if (tries == 0) break; 00315 os::select(0, 0, 0, 0, &timeout); 00316 00317 } 00318 if (tries == 0) 00319 { 00320 printError(lockRet, "Unable to get the lock for the tuple %x", curTuple_); 00321 curTuple_ = prevTuple; 00322 rv = ErrLockTimeOut; 00323 return NULL; 00324 } 00325 } 00326 return curTuple_; 00327 }
Here is the call graph for this function:
void * TableImpl::fetchNoBind | ( | ) | [virtual] |
fetches the next tuple in the table which satisfies the condition specified.
execute should be called before calling this method. Application buffer need not be binded to call this method.
Implements Table.
Definition at line 208 of file TableImpl.cxx.
References Conf::config, ErrNotOpen, Config::getMutexSecs(), Config::getMutexUSecs(), LockManager::getSharedLock(), LockManager::isExclusiveLocked(), TupleIterator::next(), OK, printError, READ_COMMITTED, READ_REPEATABLE, and os::select().
Referenced by deleteWhere(), and fetch().
00209 { 00210 if (NULL == iter) 00211 { 00212 printError(ErrNotOpen,"Scan not open or Scan is closed\n"); 00213 return NULL; 00214 } 00215 void *prevTuple = curTuple_; 00216 curTuple_ = iter->next(); 00217 if (NULL == curTuple_) 00218 { 00219 return NULL; 00220 } 00221 DbRetVal lockRet = OK; 00222 if ((*trans)->isoLevel_ == READ_REPEATABLE) { 00223 lockRet = lMgr_->getSharedLock(curTuple_, trans); 00224 if (OK != lockRet) 00225 { 00226 printError(lockRet, "Unable to get the lock for the tuple %x", curTuple_); 00227 curTuple_ = prevTuple; 00228 return NULL; 00229 } 00230 00231 } 00232 else if ((*trans)->isoLevel_ == READ_COMMITTED) 00233 { 00234 //if iso level is read committed, operation duration lock is sufficent 00235 //so release it here itself. 00236 int tries = 5; 00237 struct timeval timeout; 00238 timeout.tv_sec = Conf::config.getMutexSecs(); 00239 timeout.tv_usec = Conf::config.getMutexUSecs(); 00240 00241 bool status = false; 00242 while(true) { 00243 lockRet = lMgr_->isExclusiveLocked( curTuple_, trans, status); 00244 if (OK != lockRet) 00245 { 00246 printError(lockRet, "Unable to get the lock for the tuple %x", curTuple_); 00247 curTuple_ = prevTuple; 00248 return NULL; 00249 } 00250 if (!status) break; 00251 tries--; 00252 if (tries == 0) break; 00253 os::select(0, 0, 0, 0, &timeout); 00254 00255 } 00256 if (tries == 0) 00257 { 00258 printError(lockRet, "Unable to get the lock for the tuple %x", curTuple_); 00259 curTuple_ = prevTuple; 00260 return NULL; 00261 } 00262 } 00263 return curTuple_; 00264 }
Here is the call graph for this function:
Here is the caller graph for this function:
Implements Table.
Definition at line 150 of file TableImpl.h.
References fldList_, and FieldList::getFieldInfo().
00151 { return fldList_.getFieldInfo(fieldName, info); }
Here is the call graph for this function:
size_t TableImpl::getFieldLength | ( | const char * | name | ) | [inline] |
Definition at line 147 of file TableImpl.h.
References fldList_, and FieldList::getFieldLength().
Referenced by PredicateImpl::evaluate().
00148 { return fldList_.getFieldLength(name); }
Here is the call graph for this function:
Here is the caller graph for this function:
List TableImpl::getFieldNameList | ( | ) | [virtual] |
Implements Table.
Definition at line 720 of file TableImpl.cxx.
References List::append(), fldList_, FieldList::getIterator(), FieldIterator::hasElement(), Identifier::name, and FieldIterator::nextElement().
00721 { 00722 List fldNameList; 00723 FieldIterator fIter = fldList_.getIterator(); 00724 while (fIter.hasElement()) 00725 { 00726 FieldDef def = fIter.nextElement(); 00727 Identifier *elem = new Identifier(); 00728 strcpy(elem->name, def.fldName_); 00729 fldNameList.append(elem); 00730 } 00731 return fldNameList; 00732 }
Here is the call graph for this function:
int TableImpl::getFieldOffset | ( | const char * | name | ) | [inline] |
Definition at line 145 of file TableImpl.h.
References fldList_, and FieldList::getFieldOffset().
Referenced by PredicateImpl::evaluate().
00146 { return fldList_.getFieldOffset(name); }
Here is the call graph for this function:
Here is the caller graph for this function:
DataType TableImpl::getFieldType | ( | const char * | name | ) | [inline] |
Definition at line 143 of file TableImpl.h.
References fldList_, and FieldList::getFieldType().
Referenced by PredicateImpl::evaluate().
00144 { return fldList_.getFieldType(name); }
Here is the call graph for this function:
Here is the caller graph for this function:
char* TableImpl::getName | ( | ) | [inline, virtual] |
Implements Table.
Definition at line 200 of file TableImpl.h.
Referenced by printSQLIndexString().
Here is the caller graph for this function:
DbRetVal TableImpl::insertTuple | ( | ) | [virtual] |
insert the tuple into the table.
Prior to this, the binded buffer should be updated Values present in the binded buffers of all the fields are taken and stored in the table.
Implements Table.
Definition at line 329 of file TableImpl.cxx.
References os::align(), cNullInfo, db_, ErrLockTimeOut, ErrWarning, LockManager::getExclusiveLock(), idxInfo, indexPtr_, InsertOperation, iNullInfo, os::memcpy(), OK, printError, LockManager::releaseLock(), and sysDB_.
00330 { 00331 DbRetVal ret =OK; 00332 void *tptr = ((Chunk*)chunkPtr_)->allocate(db_, &ret); 00333 if (NULL == tptr) 00334 { 00335 printError(ret, "Unable to allocate record from chunk"); 00336 return ret; 00337 } 00338 ret = lMgr_->getExclusiveLock(tptr, trans); 00339 if (OK != ret) 00340 { 00341 ((Chunk*)chunkPtr_)->free(db_, tptr); 00342 printError(ret, "Could not get lock for the insert tuple %x", tptr); 00343 return ErrLockTimeOut; 00344 } 00345 00346 00347 ret = copyValuesFromBindBuffer(tptr); 00348 if (ret != OK) 00349 { 00350 printError(ret, "Unable to copy values from bind buffer"); 00351 (*trans)->removeFromHasList(db_, tptr); 00352 lMgr_->releaseLock(tptr); 00353 ((Chunk*)chunkPtr_)->free(db_, tptr); 00354 return ret; 00355 } 00356 00357 int addSize = 0; 00358 if (numFlds_ < 31) 00359 { 00360 addSize = 4; 00361 *(int*)((char*)(tptr) + (length_-addSize)) = iNullInfo; 00362 } 00363 else 00364 { 00365 addSize = os::align(numFlds_); 00366 os::memcpy(((char*)(tptr) + (length_-addSize)), cNullInfo, addSize); 00367 00368 } 00369 //int tupleSize = length_ + addSize; 00370 if (NULL != indexPtr_) 00371 { 00372 int i; 00373 //it has index 00374 for (i = 0; i < numIndexes_ ; i++) 00375 { 00376 ret = insertIndexNode(*trans, indexPtr_[i], idxInfo[i], tptr); 00377 if (ret != OK) { printError(ret, "Error in inserting to index"); break;} 00378 } 00379 if (i != numIndexes_ ) 00380 { 00381 for (int j = 0; j < i ; j++) { 00382 printError(ErrWarning, "Deleting index node"); 00383 deleteIndexNode(*trans, indexPtr_[j], idxInfo[j], tptr); 00384 } 00385 lMgr_->releaseLock(tptr); 00386 (*trans)->removeFromHasList(db_, tptr); 00387 ((Chunk*)chunkPtr_)->free(db_, tptr); 00388 //TMP::remove int derefernce 00389 printError(ret, "PRABA:::Unable to insert index node for tuple %x %d", tptr, *(int*)tptr); 00390 return ret; 00391 } 00392 } 00393 if (undoFlag) 00394 ret = (*trans)->appendUndoLog(sysDB_, InsertOperation, tptr, length_); 00395 return ret; 00396 }
Here is the call graph for this function:
bool TableImpl::isFldNull | ( | int | colpos | ) | [virtual] |
checks whether the field value is null for the specified field position.
colpos | field position |
Implements Table.
Definition at line 49 of file TableImpl.cxx.
References os::align(), BITSET, and isIntUsedForNULL.
00050 { 00051 if (!curTuple_) return false; 00052 if (colpos <1 || colpos > numFlds_) return false; 00053 char *nullOffset = (char*)curTuple_ - 4; 00054 if (isIntUsedForNULL) { 00055 int nullVal = *(int*)((char*)curTuple_ + (length_ - 4)); 00056 if (BITSET(nullVal, colpos)) return true; 00057 } 00058 else { 00059 char *nullOffset = (char*)curTuple_ - os::align(numFlds_); 00060 if (nullOffset[colpos-1]) return true; 00061 } 00062 return false; 00063 }
Here is the call graph for this function:
bool TableImpl::isFldNull | ( | const char * | name | ) | [virtual] |
checks whether the field value is null.
name | field name |
Implements Table.
Definition at line 38 of file TableImpl.cxx.
References ErrNotExists, fldList_, FieldList::getFieldPosition(), and printError.
00038 { 00039 int colpos = fldList_.getFieldPosition(name); 00040 if (-1 == colpos) 00041 { 00042 printError(ErrNotExists, "Field %s does not exist", name); 00043 return false; 00044 } 00045 00046 return isFldNull(colpos); 00047 }
Here is the call graph for this function:
DbRetVal TableImpl::lock | ( | bool | shared | ) | [virtual] |
takes lock on the table if bool shared flag is set, it will take shared lock, or else exclusive lock
Implements Table.
Definition at line 745 of file TableImpl.cxx.
References OK.
00746 { 00747 00748 DbRetVal ret = OK; 00749 /* 00750 if (shared) 00751 ret = lMgr_->getSharedLock(chunkPtr_, NULL); 00752 else 00753 ret = lMgr_->getExclusiveLock(chunkPtr_, NULL); 00754 if (OK != ret) 00755 { 00756 printError(ret, "Could not exclusive lock on the table %x", chunkPtr_); 00757 }else { 00758 //do not append for S to X upgrade 00759 if (!ProcessManager::hasLockList.exists(chunkPtr_)) 00760 ProcessManager::hasLockList.append(chunkPtr_); 00761 } 00762 */ 00763 return ret; 00764 }
void TableImpl::markFldNull | ( | int | colpos | ) | [virtual] |
marks the specified field to insert null when insert method is called.
colpos | field position |
Implements Table.
Definition at line 75 of file TableImpl.cxx.
References BITSET, cNullInfo, iNotNullInfo, iNullInfo, isIntUsedForNULL, and SETBIT.
00076 { 00077 if (fldpos <1 || fldpos > numFlds_) return; 00078 if (isIntUsedForNULL) { 00079 if (!BITSET(iNotNullInfo, fldpos)) SETBIT(iNullInfo, fldpos); 00080 } 00081 else 00082 if (!BITSET(iNotNullInfo, fldpos)) cNullInfo[fldpos-1] = 1; 00083 return; 00084 }
void TableImpl::markFldNull | ( | const char * | name | ) | [virtual] |
marks the specified field to insert null when insert method is called.
name | field name in the table |
Implements Table.
Definition at line 64 of file TableImpl.cxx.
References ErrNotExists, fldList_, FieldList::getFieldPosition(), and printError.
00065 { 00066 int colpos = fldList_.getFieldPosition(name); 00067 if (-1 == colpos) 00068 { 00069 printError(ErrNotExists, "Field %s does not exist", name); 00070 return; 00071 } 00072 markFldNull(colpos); 00073 }
Here is the call graph for this function:
long TableImpl::numTuples | ( | ) | [virtual] |
Retrieves the total number of tuples present in this table.
Implements Table.
Definition at line 715 of file TableImpl.cxx.
Referenced by printInfo().
00716 { 00717 return ((Chunk*)chunkPtr_)->getTotalDataNodes(); 00718 }
Here is the caller graph for this function:
int TableImpl::pagesUsed | ( | ) |
Definition at line 709 of file TableImpl.cxx.
References Chunk::totalPages().
Referenced by printInfo().
00710 { 00711 Chunk *chk = (Chunk*)chunkPtr_; 00712 return chk->totalPages(); 00713 }
Here is the call graph for this function:
Here is the caller graph for this function:
void TableImpl::printInfo | ( | ) |
Definition at line 536 of file TableImpl.cxx.
References CatalogTableINDEX::getName(), indexPtr_, numTuples(), pagesUsed(), and spaceUsed().
Referenced by main().
00537 { 00538 printf(" <TableName> %s </TableName>\n", tblName_); 00539 printf(" <TupleCount> %d </TupleCount>\n", numTuples()); 00540 printf(" <PagesUsed> %d </PagesUsed>\n", pagesUsed()); 00541 printf(" <SpaceUsed> %d </SpaceUsed>\n", spaceUsed()); 00542 printf(" <Indexes> %d <Indexes>\n", numIndexes_); 00543 printf(" <TupleLength> %d </TupleLength>\n", length_); 00544 printf(" <Fields> %d </Fields>\n", numFlds_); 00545 printf(" <Indexes>\n"); 00546 for (int i =0; i<numIndexes_; i++) 00547 printf("<IndexName> %s </IndexName>\n", CatalogTableINDEX::getName(indexPtr_[i])); 00548 printf(" </Indexes>\n"); 00549 00550 }
Here is the call graph for this function:
Here is the caller graph for this function:
void TableImpl::printSQLIndexString | ( | ) | [virtual] |
Implements Table.
Definition at line 660 of file TableImpl.cxx.
References CatalogTableINDEXFIELD::getFieldNameAndType(), getName(), IDENTIFIER_LENGTH, idxInfo, indexPtr_, and sysDB_.
00661 { 00662 CatalogTableINDEXFIELD cIndexField(sysDB_); 00663 char fName[IDENTIFIER_LENGTH]; 00664 char *fldName = fName; 00665 DataType type; 00666 for (int i = 0; i < numIndexes_ ; i++) 00667 { 00668 INDEX *iptr = (INDEX*) indexPtr_[i]; 00669 cIndexField.getFieldNameAndType((void*)iptr, fldName, type); 00670 printf("CREATE INDEX %s on %s ( %s ) ", iptr->indName_, getName(), fldName); 00671 if (((SingleFieldHashIndexInfo*) idxInfo[i])->isUnique) printf(" UNIQUE;\n"); else printf(";\n"); 00672 } 00673 }
Here is the call graph for this function:
void TableImpl::setCondition | ( | Condition * | p | ) | [inline, virtual] |
sets condition for the select, update and delete operations
c | condition |
Implements Table.
Definition at line 156 of file TableImpl.h.
References Condition::getPredicate(), and isPlanCreated.
00157 { isPlanCreated = false; if (p) pred_ = p->getPredicate(); else pred_ = NULL;}
Here is the call graph for this function:
void TableImpl::setDB | ( | Database * | db | ) | [inline] |
Definition at line 138 of file TableImpl.h.
References db_.
Referenced by DatabaseManagerImpl::openTable().
00138 { db_ = db; }
Here is the caller graph for this function:
void TableImpl::setLockManager | ( | LockManager * | lmgr | ) | [inline] |
Definition at line 140 of file TableImpl.h.
Referenced by DatabaseManagerImpl::openTable().
Here is the caller graph for this function:
void TableImpl::setSystemDB | ( | Database * | db | ) | [inline] |
Definition at line 139 of file TableImpl.h.
References sysDB_.
Referenced by DatabaseManagerImpl::openTable().
00139 { sysDB_ = db; }
Here is the caller graph for this function:
void TableImpl::setTableInfo | ( | char * | name, | |
int | tblid, | |||
size_t | length, | |||
int | numFld, | |||
int | numIdx, | |||
void * | chunk | |||
) |
Definition at line 690 of file TableImpl.cxx.
Referenced by DatabaseManagerImpl::openTable().
00692 { 00693 strcpy(tblName_, name); 00694 tblID_ = tblid; 00695 length_ = length; 00696 numFlds_ = numFld; 00697 numIndexes_ = numIdx; 00698 chunkPtr_ = chunk; 00699 }
Here is the caller graph for this function:
void TableImpl::setTrans | ( | Transaction ** | t | ) | [inline] |
Definition at line 141 of file TableImpl.h.
Referenced by DatabaseManagerImpl::openTable().
Here is the caller graph for this function:
DbRetVal TableImpl::setUndoLogging | ( | bool | flag | ) | [inline, virtual] |
sets the undo log flag.
If this flag is unset then undo logs will not be generated
Implements Table.
Definition at line 197 of file TableImpl.h.
long TableImpl::spaceUsed | ( | ) | [virtual] |
Retrieves the total space used for this table in bytes.
Implements Table.
Definition at line 701 of file TableImpl.cxx.
References Chunk::getSize(), Chunk::getTotalDataNodes(), and Chunk::totalPages().
Referenced by printInfo().
00702 { 00703 Chunk *chk = (Chunk*)chunkPtr_; 00704 long totSize = chk->getTotalDataNodes() * chk->getSize(); 00705 totSize = totSize + (chk->totalPages() * sizeof (PageInfo)); 00706 return totSize; 00707 }
Here is the call graph for this function:
Here is the caller graph for this function:
int TableImpl::truncate | ( | ) | [virtual] |
deletes the all the records in the table.
No transaction required to call this. It takes table level lock.
Implements Table.
Definition at line 459 of file TableImpl.cxx.
References deleteWhere(), isPlanCreated, and OK.
00460 { 00461 //take exclusive lock on the table 00462 //get the chunk ptr of the table 00463 //traverse the tablechunks and free all the pages except the first one 00464 //get the chunk ptr of all its indexes 00465 //traverse the indexchunks and free all the pages except the first one 00466 //release table lock 00467 00468 //TEMPORARY FIX 00469 DbRetVal rv = OK; 00470 Predicate* tmpPred = pred_; 00471 pred_ = NULL; 00472 isPlanCreated = false; 00473 int tuplesDeleted = deleteWhere(); 00474 isPlanCreated = false; 00475 pred_ = tmpPred; 00476 return tuplesDeleted; 00477 }
Here is the call graph for this function:
DbRetVal TableImpl::unlock | ( | ) | [virtual] |
releases the lock acquired on the table
Implements Table.
Definition at line 765 of file TableImpl.cxx.
References OK.
00766 { 00767 /* 00768 if (!ProcessManager::hasLockList.exists(chunkPtr_)) return OK; 00769 DbRetVal ret = lMgr_->releaseLock(chunkPtr_); 00770 if (OK != ret) 00771 { 00772 printError(ret, "Could not release exclusive lock on the table %x", chunkPtr_); 00773 }else 00774 { 00775 ProcessManager::hasLockList.remove(chunkPtr_); 00776 } 00777 */ 00778 return OK; 00779 }
DbRetVal TableImpl::updateTuple | ( | ) | [virtual] |
update values in the current tuple of the table.
It works only on top of select using fetch go to the tuple to be updated, then update the binded buffer value and then call this method to updates the field values in the tuple.
Implements Table.
Definition at line 479 of file TableImpl.cxx.
References os::align(), db_, ErrLockTimeOut, ErrNotOpen, LockManager::getExclusiveLock(), idxInfo, indexPtr_, iNullInfo, OK, printError, LockManager::releaseLock(), sysDB_, and UpdateOperation.
00480 { 00481 if (NULL == curTuple_) 00482 { 00483 printError(ErrNotOpen, "Scan not open: No Current tuple"); 00484 return ErrNotOpen; 00485 } 00486 DbRetVal ret = lMgr_->getExclusiveLock(curTuple_, trans); 00487 if (OK != ret) 00488 { 00489 printError(ret, "Could not get lock for the update tuple %x", curTuple_); 00490 return ErrLockTimeOut; 00491 } 00492 if (NULL != indexPtr_) 00493 { 00494 //it has index 00495 //TODO::If it fails while updating index node, we have to undo all the updates 00496 //on other indexes on the table.Currently it will leave the database in an 00497 //inconsistent state. 00498 for (int i = 0; i < numIndexes_ ; i++) 00499 { 00500 ret = updateIndexNode(*trans, indexPtr_[i], idxInfo[i], curTuple_); 00501 if (ret != OK) 00502 { 00503 lMgr_->releaseLock(curTuple_); 00504 (*trans)->removeFromHasList(db_, curTuple_); 00505 printError(ret, "Unable to update index node for tuple %x", curTuple_); 00506 return ret; 00507 } 00508 } 00509 } 00510 if (undoFlag) 00511 ret = (*trans)->appendUndoLog(sysDB_, UpdateOperation, curTuple_, length_); 00512 if (ret != OK) return ret; 00513 int addSize = 0; 00514 if (numFlds_ < 31) 00515 { 00516 addSize = 4; 00517 *(int*)((char*)(curTuple_) + (length_-addSize)) |= iNullInfo; 00518 } 00519 else 00520 { 00521 addSize = os::align(numFlds_); 00522 //TODO::Do not do blind memcpy. It should OR each and every char 00523 //os::memcpy(((char*)(curTuple_) + (length_-addSize)), cNullInfo, addSize); 00524 00525 } 00526 00527 DbRetVal rv = copyValuesFromBindBuffer(curTuple_, false); 00528 if (rv != OK) { 00529 lMgr_->releaseLock(curTuple_); 00530 (*trans)->removeFromHasList(db_, curTuple_); 00531 return rv; 00532 } 00533 return OK; 00534 }
Here is the call graph for this function:
friend class DatabaseManagerImpl [friend] |
Definition at line 203 of file TableImpl.h.
char* TableImpl::cNotNullInfo |
Definition at line 110 of file TableImpl.h.
Referenced by DatabaseManagerImpl::openTable(), and TableImpl().
char* TableImpl::cNullInfo |
Definition at line 108 of file TableImpl.h.
Referenced by clearFldNull(), insertTuple(), markFldNull(), DatabaseManagerImpl::openTable(), TableImpl(), and ~TableImpl().
Definition at line 101 of file TableImpl.h.
Referenced by deleteTuple(), HashIndex::insert(), insertTuple(), HashIndex::remove(), setDB(), TableImpl(), HashIndex::update(), and updateTuple().
Definition at line 94 of file TableImpl.h.
Referenced by bindFld(), clearFldNull(), getFieldInfo(), getFieldLength(), getFieldNameList(), getFieldOffset(), getFieldType(), isFldNull(), markFldNull(), DatabaseManagerImpl::openTable(), HashIndex::update(), and ~TableImpl().
Definition at line 97 of file TableImpl.h.
Referenced by deleteTuple(), execute(), insertTuple(), DatabaseManagerImpl::openTable(), printSQLIndexString(), TableImpl(), updateTuple(), and ~TableImpl().
char** TableImpl::indexPtr_ |
Definition at line 96 of file TableImpl.h.
Referenced by deleteTuple(), insertTuple(), DatabaseManagerImpl::openTable(), printInfo(), printSQLIndexString(), TableImpl(), updateTuple(), and ~TableImpl().
Definition at line 109 of file TableImpl.h.
Referenced by markFldNull(), DatabaseManagerImpl::openTable(), and TableImpl().
Definition at line 107 of file TableImpl.h.
Referenced by clearFldNull(), insertTuple(), markFldNull(), DatabaseManagerImpl::openTable(), TableImpl(), and updateTuple().
Definition at line 106 of file TableImpl.h.
Referenced by clearFldNull(), isFldNull(), markFldNull(), DatabaseManagerImpl::openTable(), and TableImpl().
Definition at line 99 of file TableImpl.h.
Referenced by setCondition(), TableImpl(), and truncate().
Definition at line 102 of file TableImpl.h.
Referenced by deleteTuple(), execute(), HashIndex::insert(), insertTuple(), printSQLIndexString(), HashIndex::remove(), setSystemDB(), HashIndex::update(), and updateTuple().