///////////////////////////////////////////////////////////////////////////////
//                                                         
// CegoAdmAction.cc  
// ----------------                                                        
// Cego semantic parser adm actions
//
// Design and Implementation by Bjoern Lemke
//     
// (C)opyright 2000-2025 Bjoern Lemke
//
// IMPLEMENTATION MODULE
//
// Class: CegoAdmAction
// 
// Description: Semantic actions for cgadm
//
// Status: CLEAN
//
///////////////////////////////////////////////////////////////////////////////


#include <lfcbase/Tokenizer.h>
#include <lfcbase/Host.h>
#include <lfcbase/Datetime.h>

#include "CegoXMLdef.h"
#include "CegoAdmAction.h"
#include "CegoOutput.h"

#include <stdlib.h>
#include <string.h>

#define DEFTMPSIZE 100
#define DEFSYSSIZE 100
#define DEFAPPSIZE 3000
#define DEFLOGNUM 3
#define DEFLOGSIZE 1000000
#define DEFSORTAREASIZE 10000000
#define DEFTSROOT ""
#define DEFPRIMARY Chain()
#define DEFSECONDARY Chain()
#define DEFTIMEOUT 10
#define DEFMAXCACHEENTRY 200
#define DEFMAXCACHESIZE 500000
#define DEFCACHEHASHRANGE 30
#define MAXHOSTLEN 25

extern char __quoteEscapeFlag;
extern char __caseSensitiveFlag;

CegoAdmAction::CegoAdmAction(CegoAdminHandler *pAH, CegoModule *pModule, CegoAdmAction::ResultMode resultMode, bool rawMode) :  CegoAdm(), SigHandler() 
{
    init();
    
    install(SIGINT);
    install(SIGPIPE);

    _isAborted = false;
	
    _pC = 0;
    _pModule = pModule;
    _pAH = pAH;
    _pit = Chain();
    _lsn = 0;
    _rawMode = rawMode;
    _resultMode = resultMode;
    _keepTicket = false;
    _doCleanup = false;
    _doForceload = false;
    _doCPDump = false;
    _doNoInit = false;
    
    _xportMode = XML_XML_VALUE;
    _correctMode = XML_POST_VALUE;
    
    _timeout = DEFTIMEOUT;
    setDefault();

    // default query cache param values
    _maxEntry = 0;
    _maxSize = 0;
    _threshold = 0;
    _hashRange = 0;
    _cacheFilter = Chain();

    _admSchema.Insert(CegoField(Chain("ADM"), Chain("ADM"), Chain("ROLE"), VARCHAR_TYPE, 10)); 
    _admSchema.Insert(CegoField(Chain("ADM"), Chain("ADM"), Chain("HOSTNAME"), VARCHAR_TYPE, MAXHOSTLEN)); 
    _admSchema.Insert(CegoField(Chain("ADM"), Chain("ADM"), Chain("MSG"), VARCHAR_TYPE, 50));

    _stringBuf = (char*)malloc(MAXSTRINGLEN);
    _stringBufLen = MAXSTRINGLEN;
    
    if ( _stringBuf == 0 ) 
    {
	Chain msg("Malloc system error"); 
	throw Exception(EXLOC, msg);
    }

    _modId = _pModule->getModId("CegoAdmAction");
}

CegoAdmAction::~CegoAdmAction()  
{
}

void CegoAdmAction::statementAction()
{
}

void CegoAdmAction::rawModeOn()
{
    _rawMode = true;
}

void CegoAdmAction::rawModeOff()
{
    _rawMode = false;
}

bool CegoAdmAction::getRawMode()
{
    return _rawMode;
}

void CegoAdmAction::setCommandChain(char *pC)
{
    _pC = pC;
    
    // init some vars
    _buMsg = Chain("NONE");
    _syncCmd = Chain();
    _timeout = DEFTIMEOUT;
    _maxEntry = 0;
    _maxSize = 0;
    _threshold = 0;
    _hashRange = 0;
    _cacheFilter = Chain();
    _correctMode = XML_POST_VALUE;
}

char CegoAdmAction::nextChar() 
{   
    if ( _pC == 0 )
	return 0;

    if ( (int)(*_pC) < 0 )
    {
	Chain msg = Chain("Invalid character <") + Chain((int)(*_pC)) + Chain("> detected"); 
	throw Exception(EXLOC, msg);
    }

    // cout << "Character read : " << *_pC << endl;

    if ( *_pC == '\'' )
    {
	_pC++;
	readChain();
	return 0;
    }
 
    if ( *_pC == 0 )
    {
        return 0; 
    }
    
    char c = *_pC; 
    _pC++;

    if ( __caseSensitiveFlag == 0 )
	return c;
    else
	return (char)tolower((int)c);
} 

void CegoAdmAction::readChain()
{
    setReserved(STRINGVAL); 
    
    unsigned i=0;    

    if ( __quoteEscapeFlag )
    {
	bool moreChar = true; 
	while ( moreChar )
	{	    
	    if ( *_pC == '\'' ) 
	    {
		_pC++;
		if ( *_pC == '\'' )
		{
		    _stringBuf[i] = '\'';
		    i++;
		}
		else
		{
		    moreChar = false;
		}
	    }
	    else
	    {
		_stringBuf[i] = *_pC; 		
		i++;
	    }
	  
	    if ( i == _stringBufLen ) 
	    { 
		reallocateStringBuf();
	    }
	    
	    if ( moreChar )
	    {
		_pC++;
		
		if ( *_pC == 0 )
		{
		    Chain msg("Unterminated string"); 
		    throw Exception(EXLOC, msg);
		}
	    }
	}
    }
    else
    {
	while ( *_pC != '\'' ) 
	{ 
	    // cout << "Storing: " << *_pC << endl; 
	    
	    if ( *_pC == '\\' ) 
	    { 
		_pC++; 
		
		if ( *_pC == 'n' ) 
		{ 
		    _stringBuf[i] = '\n'; 
		} 
		else if ( *_pC == 'r' ) 
		{ 
		    _stringBuf[i] = '\r'; 
		} 
		else if ( *_pC == 't' ) 
		{ 
		    _stringBuf[i] = '\t'; 
		} 
		else if ( *_pC == '\'' ) 
		{ 
		    _stringBuf[i] = '\''; 
		}
		else if ( *_pC == '\\' ) 
		{ 
		    _stringBuf[i] = '\\'; 
		} 
		else 
		{ 
		    Chain msg = Chain("Invalid escape character <") + Chain(*_pC) + Chain(">"); 
		    throw Exception(EXLOC, msg);
		} 
	    } 
	    else
	    { 
		_stringBuf[i] = *_pC; 
	    } 
	    
	    _stringBuf[i] = *_pC; 
	    i++; 
	    
	    if ( i == _stringBufLen ) 
	    {
		reallocateStringBuf();
	    }
	    
	    _pC++;
	    
	    if ( *_pC == 0 )
	    {
		Chain msg("Unterminated string"); 
		throw Exception(EXLOC, msg);
	    }
	}
	_pC++; 
    }

    _stringBuf[i] = 0; 

    return; 
}

void CegoAdmAction::backChar() 
{
    if ( _pC != 0 )
	_pC--;
}

void CegoAdmAction::reallocateStringBuf()
{
    // reallocation required
    _stringBufLen += MAXSTRINGLEN;
    char *newBuf = (char*)malloc( _stringBufLen );
    if ( newBuf == 0 ) 
    {
	Chain msg("Malloc system error"); 
	throw Exception(EXLOC, msg);
    }

    // we just have to copy the previous len
    memcpy(newBuf, _stringBuf, _stringBufLen - MAXSTRINGLEN);
    free(_stringBuf);
    _stringBuf=newBuf;
}

void CegoAdmAction::printTokenList() 
{   
    cout << "TokenList is " << endl;
	
    ListT<Chain> tlist =  getTokenList();
    Chain* pS = tlist.First();
    while (pS)
    {
	cout << *pS << endl;
	pS = tlist.Next();
    }
}

void CegoAdmAction::cleanUp() 
{
    _isAborted = false;
    _tsPerm = Chain();
    _filterPerm = Chain();
    _rightPerm = Chain();
}

void CegoAdmAction::showQueryCacheAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;

    res = _pAH->reqShowQueryCache(tableSet);
    handleResult(res);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    Chain format;
    if ( _pAH->getCacheInfo(oe, info, format) )
    {
	CegoOutput output(oe.getSchema(), format);
	output.setRawMode(_rawMode);
	output.tabOut(info);
    }
    Chain msg;
    _pAH->getMsg(msg);
    
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::listQueryCacheAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;

    res = _pAH->reqListQueryCache(tableSet);
    handleResult(res);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    Chain format;
    if ( _pAH->getCacheList(oe, info, format) )
    {	
	CegoOutput output(oe.getSchema(), format);
	output.setRawMode(_rawMode);
	output.tabOut(info);
    }
    Chain msg;
    _pAH->getMsg(msg);
    
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::cleanQueryCacheAction()
{    
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;

    res = _pAH->reqCleanQueryCache(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setQueryCacheParamAction()
{
    Chain tableSet;
    
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;

    res = _pAH->reqSetQueryCacheParam(tableSet, _maxEntry, _maxSize, _threshold, _hashRange);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;    
}

void CegoAdmAction::setQueryCacheMaxEntry()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_maxEntry = pS->asUnsigned();
    }
}

void CegoAdmAction::setQueryCacheMaxSize()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_maxSize = pS->asUnsigned();
    }
}

void CegoAdmAction::setQueryCacheHashRange()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_hashRange = pS->asUnsigned();
    }
}

void CegoAdmAction::setQueryCacheThreshold()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_threshold = pS->asUnsigned();
    }
}

void CegoAdmAction::showTableCacheAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;

    res = _pAH->reqShowTableCache(tableSet);
    handleResult(res);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    Chain format;
    if ( _pAH->getCacheInfo(oe, info, format) )
    {
	CegoOutput output(oe.getSchema(), format);
	output.setRawMode(_rawMode);
	output.tabOut(info);
    }
    Chain msg;
    _pAH->getMsg(msg);
    
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::listTableCacheAction()
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqListTableCache(tableSet);
    handleResult(res);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    Chain format;
    if ( _pAH->getCacheList(oe, info, format) )
    {	
	CegoOutput output(oe.getSchema(), format);
	output.setRawMode(_rawMode);
	output.tabOut(info);
    }
    Chain msg;
    _pAH->getMsg(msg);
    
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::cleanTableCacheAction()
{
    Chain tableSet;
    
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;

    res = _pAH->reqCleanTableCache(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setTableCacheParamAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;

    res = _pAH->reqSetTableCacheParam(tableSet, _cacheFilter, _maxEntry, _maxSize, _hashRange);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;    
}

void CegoAdmAction::setTableCacheMaxEntry()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_maxEntry = pS->asUnsigned();
    }
}

void CegoAdmAction::setTableCacheMaxSize()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_maxSize = pS->asUnsigned();
    }
}

void CegoAdmAction::setTableCacheHashRange()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_hashRange = pS->asUnsigned();
    }
}

void CegoAdmAction::setTableCacheFilter()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_cacheFilter = Chain(_stringBuf);
    }
}

void CegoAdmAction::setDefault()
{
    _tsRoot = DEFTSROOT;
    _logSize = DEFLOGSIZE;
    _logNum = DEFLOGNUM;
    _sortAreaSize = DEFSORTAREASIZE;
    _branchId = 0;
    _sysSize = DEFSYSSIZE;
    _appSize = DEFAPPSIZE;
    _tmpSize = DEFTMPSIZE;
}

/////////////////////////////////
// cego semantic action methods //
/////////////////////////////////

void CegoAdmAction::lockInfoAction() 
{
    Chain* pS = getTokenList().First();
    pS = getTokenList().Next();
    if ( pS )
    {
	Chain lockCat;
	if ( *pS  == Chain("rec") )
	{
	    lockCat  = Chain(XML_LOCK_REC_VALUE);
	}
	else if ( *pS  == Chain("rbrec") )
	{
	    lockCat = Chain(XML_LOCK_RBREC_VALUE);
	}
	else if ( *pS  == Chain("sysrec") )
	{
	    lockCat = Chain(XML_LOCK_SYSREC_VALUE);
	}
	else if ( *pS  == Chain("tp") )
	{
	    lockCat = Chain(XML_LOCK_THREADPOOL_VALUE);
	}
	else if ( *pS == Chain("sp") )
	{
	    lockCat = Chain(XML_LOCK_SYSPAGE_VALUE);
	}
	else if ( *pS == Chain("dp") )
	{
	    lockCat = Chain(XML_LOCK_DATAPAGE_VALUE);
	}
	else if ( *pS == Chain("ix") )
	{
	    lockCat = Chain(XML_LOCK_IDXPAGE_VALUE);
	}
	else if ( *pS == Chain("rb") )
	{
	    lockCat = Chain(XML_LOCK_RBPAGE_VALUE);
	}
	else if ( *pS == Chain("df") )
	{
	    lockCat = Chain(XML_LOCK_DATAFILE_VALUE);
	}
	else if ( *pS == Chain("bp") )
	{
	    lockCat = Chain(XML_LOCK_BUFFERPOOL_VALUE);
	}
	else if ( *pS == Chain("lm") )
	{
	    lockCat = Chain(XML_LOCK_LOGMNG_VALUE);
	}
	else if ( *pS == Chain("qc") )
	{
	    lockCat = Chain(XML_LOCK_QUERYCACHE_VALUE);
	}
	else if ( *pS == Chain("tc") )
	{
	    lockCat = Chain(XML_LOCK_TABLECACHE_VALUE);
	}
	else
	{
	    throw Exception(EXLOC, "Invalid lock category");
	}

	CegoAdminHandler::ResultType res;
	
	res = _pAH->reqLockInfo(lockCat);

	handleResult(res);
	
	Chain msg;
	_pAH->getMsg(msg);
	
	CegoTableObject oe;
	ListT<ListT<CegoFieldValue> > info;

	_pAH->getLockInfo(oe, info);
	
	CegoOutput output(oe.getSchema());
	output.setRawMode(_rawMode);
	output.tabOut(info);
	if ( _rawMode == false )
	    cout << msg << endl;
    }
}

void CegoAdmAction::lockStatAction() 
{
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqLockStat();    
    handleResult(res);    

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getLockStat(oe, info);
    
    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::verifyLocksAction() 
{
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqVerifyLocks();    
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);

    if ( _rawMode == false )
	cout << msg << endl;
}


void CegoAdmAction::poolInfoAction() 
{       
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqPoolInfo();
    handleResult(res);    

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getPoolInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.headOut();
    ListT<CegoFieldValue> *pFVL = info.First();
    while ( pFVL )
    {
	output.rowOut(*pFVL);	
	pFVL = info.Next();
    }
    output.tailOut();

    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::parameterInfoAction() 
{       
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqParameterInfo();
    handleResult(res); 

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getParameterInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.headOut();
    ListT<CegoFieldValue> *pFVL = info.First();
    while ( pFVL )
    {
	output.rowOut(*pFVL);	
	pFVL = info.Next();
    }

    output.tailOut();

    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::poolEntryListAction() 
{       
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqPoolEntryList();

    while ( res == CegoAdminHandler::ADM_INFO )
    {
	Chain msg;
	_pAH->getMsg(msg);
	
	CegoTableObject oe;
	ListT<ListT<CegoFieldValue> > info;
	
	_pAH->getPoolEntryList(oe, info);

	CegoOutput output(oe.getSchema());
	output.setRawMode(_rawMode);
	output.tabOut(info);
		
	res = _pAH->nextInfo();	
    }
    
    if ( _rawMode == false )
    {
	Chain msg;
	_pAH->getMsg(msg);	
	cout << msg << endl;
    }
}

void CegoAdmAction::listTableSetAction() 
{       
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqGetTableSetList(true);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
        
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getTableSetList(oe, info, true);
    
    CegoOutput output(oe.getSchema(), Chain("lllrrr"));
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::threadInfoAction() 
{       
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqThreadInfo();
    handleResult(res);	

    Chain msg;
    _pAH->getMsg(msg);

    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;

    _pAH->getThreadInfo(oe, info);

    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.tabOut(info);

    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::dbThreadInfoAction() 
{       
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqDbThreadInfo();	
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    Chain format;
    _pAH->getDbThreadInfo(oe, info, format);
    
    CegoOutput output(oe.getSchema(), format);
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::dbThreadQueryHistAction() 
{
    unsigned threadId = 0;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	threadId = pS->asUnsigned();
    }
        
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqDbThreadHistory(threadId);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    Chain format;
    _pAH->getDbThreadHistory(oe, info, format);
    
    CegoOutput output(oe.getSchema(), format);
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::dbQueryHistLastAction()
{
    unsigned numLast = 0;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	numLast = pS->asUnsigned();
    }
    
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqQueryHistoryLast(numLast);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    Chain format;
    _pAH->getDbThreadHistory(oe, info, format);
    
    CegoOutput output(oe.getSchema(), format);
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::dbQueryHistCostAction()
{
    unsigned numLast = 0;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	numLast = pS->asUnsigned();
    }
    
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqQueryHistoryCost(numLast);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    Chain format;
    _pAH->getDbThreadHistory(oe, info, format);
    
    CegoOutput output(oe.getSchema(), format);
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::admThreadInfoAction() 
{       
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqAdmThreadInfo();
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    Chain format;
    _pAH->getAdmThreadInfo(oe, info, format);
    
    CegoOutput output(oe.getSchema(), format);
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}


void CegoAdmAction::buFileInfoAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();

    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqGetDetailedTSInfo(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getBuFileInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::buStatInfoAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();

    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqGetBUStatInfo(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getBUStatInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::buStatResetAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();

    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqResetBUStat(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::abortDbThreadAction() 
{
    unsigned threadId = 0;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	threadId = pS->asUnsigned();
    }
    CegoAdminHandler::ResultType res;
    res = _pAH->reqDbThreadAbort(threadId);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::defineTableSetAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;
    res = _pAH->reqDefineTableSet(tableSet,
				  _tsRoot,
				  _sysSize,
				  _tmpSize,
				  _appSize,
				  _logSize,
				  _logNum, 
				  _sortAreaSize,
				  _branchId);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
    
    setDefault();
}

void CegoAdmAction::startTableSetAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;
    res = _pAH->reqStartTableSet(tableSet, _doCleanup, _doForceload, _doCPDump, _doNoInit);
    _doCleanup=false;
    _doForceload=false;
    _doCPDump=false;
    _doNoInit = false;

    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::stopTableSetAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;    
    res = _pAH->reqStopTableSet(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::startRecoveryAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;
    res = _pAH->reqStartRecovery(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::stopRecoveryAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;    
    res = _pAH->reqStopRecovery(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}


void CegoAdmAction::dropTableSetAction() 
{
    CegoAdminHandler::ResultType res;   
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    res = _pAH->reqDropTableSet(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::removeTableSetAction() 
{
    CegoAdminHandler::ResultType res;   
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    res = _pAH->reqRemoveTableSet(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::createTableSetAction() 
{
    CegoAdminHandler::ResultType res;   
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    res = _pAH->reqCreateTableSet(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::syncTableSetAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSyncTableSet(tableSet, _buMsg, _syncCmd, _timeout);

    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::beginBackupAction()
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;
    res = _pAH->reqBeginBackup(tableSet, _buMsg);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::executeBackupAction()
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;
    res = _pAH->reqExecuteBackup(tableSet, _buMsg);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::endBackupAction()
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;
    res = _pAH->reqEndBackup(tableSet, _buMsg, _keepTicket);
    _keepTicket = false;
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::listBackupAction()
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;
    res = _pAH->reqListBackup(tableSet, _pit);
    handleResult(res);

    // reset pit to 0
    _pit = Chain();

    Chain msg;
    _pAH->getMsg(msg);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getBackupInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::keepTicketAction()
{
    _keepTicket = true;
}

void CegoAdmAction::syncCmdAction()
{
    _syncCmd = Chain(_stringBuf);
}

void CegoAdmAction::timeoutAction()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_timeout = pS->asUnsigned();
    }
}

void CegoAdmAction::msgAction()
{
    _buMsg = Chain(_stringBuf);
}

void CegoAdmAction::cleanupAction()
{
    _doCleanup = true;
}

void CegoAdmAction::forceloadAction()
{
    _doForceload = true;
}

void CegoAdmAction::cpDumpAction()
{
    _doCPDump = true;
}

void CegoAdmAction::noInitAction()
{
    _doNoInit = true;
}

void CegoAdmAction::xmlModeAction()
{
    _xportMode = XML_XML_VALUE;
}

void CegoAdmAction::binModeAction()
{
    _xportMode = XML_BIN_VALUE;
}

void CegoAdmAction::plainModeAction()
{
    _xportMode = XML_PLAIN_VALUE;
}

void CegoAdmAction::restoreTableSetAction()
{
    Chain tableSet;
    Chain backupId(_stringBuf);

    Chain* pS = getTokenList().First();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	tableSet = *pS;
    }
    
    CegoAdminHandler::ResultType res;
    res = _pAH->reqRestore(tableSet, backupId);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::recoverTableSetAction()
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;
    res = _pAH->reqRecover(tableSet, _pit, _lsn);
    handleResult(res);

    // reset pit to 0
    _pit = Chain();
    _lsn = 0;

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setLogMngAction()
{
    Chain progName(_stringBuf);

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetLogMng(progName, _timeout);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;

    _timeout = DEFTIMEOUT;
}

void CegoAdmAction::setBackupMngAction()
{
    Chain progName(_stringBuf);

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetBackupMng(progName);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::showLogMngAction()
{
    CegoAdminHandler::ResultType res;
    res = _pAH->reqShowLogMng();

    if ( res == CegoAdminHandler::ADM_OK )
    {

	CegoTableObject oe;
	ListT<ListT<CegoFieldValue> > info;

	_pAH->getLogMngInfo(oe, info);

	CegoOutput output(oe.getSchema());
	output.setRawMode(_rawMode);
	output.tabOut(info);

	if ( _rawMode == false )
	{
	    Chain msg;
	    _pAH->getMsg(msg);
	    cout << msg << endl;
	}
    }
    else if ( res == CegoAdminHandler::ADM_ERROR )
    {
	Chain msg;
	_pAH->getMsg(msg);
	throw Exception(EXLOC, msg);
    }
}

void CegoAdmAction::showBackupMngAction()
{
    CegoAdminHandler::ResultType res;
    res = _pAH->reqShowBackupMng();

    if ( res == CegoAdminHandler::ADM_OK )
    {

	CegoTableObject oe;
	ListT<ListT<CegoFieldValue> > info;

	_pAH->getBackupMngInfo(oe, info);

	CegoOutput output(oe.getSchema());
	output.setRawMode(_rawMode);
	output.tabOut(info);

	if ( _rawMode == false )
	{
	    Chain msg;
	    _pAH->getMsg(msg);
	    cout << msg << endl;
	}
    }
    else if ( res == CegoAdminHandler::ADM_ERROR )
    {
	Chain msg;
	_pAH->getMsg(msg);
	throw Exception(EXLOC, msg);
    }
}

void CegoAdmAction::setTSInitFileAction()
{
    Chain initFileName(_stringBuf);

    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetTSInitFile(tableSet, initFileName);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setTSRootPathAction()
{
    Chain tsRoot(_stringBuf);

    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetTSRootPath(tableSet, tsRoot);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setTSLogNumAction()
{
    unsigned logNum = 0;
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	logNum = pS->asUnsigned();
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetTSLogNum(tableSet, logNum);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setTSLogSizeAction()
{
    unsigned logSize = 0;
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	logSize = pS->asUnsigned();
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetTSLogSize(tableSet, logSize);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setTSSortAreaSizeAction()
{
    unsigned long long sortAreaSize = 0;
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	sortAreaSize = pS->asUnsignedLongLong();
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetTSSortAreaSize(tableSet, sortAreaSize);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setTSSysSizeAction()
{
    Chain tableSet;
    unsigned sysSize = 0;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	sysSize = pS->asUnsigned();
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetTSSysSize(tableSet, sysSize);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setTSTmpSizeAction()
{
    Chain tableSet;
    unsigned tmpSize = 0;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	tmpSize = pS->asUnsigned();
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetTSTmpSize(tableSet, tmpSize);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setTSAppSizeAction()
{
    Chain tableSet;
    unsigned appSize = 0;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	appSize = pS->asUnsigned();
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetTSAppSize(tableSet, appSize);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setCheckpointAction()
{
    Chain tableSet;
    unsigned interval = 0;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	interval = pS->asUnsigned();
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetCheckpoint(tableSet, interval);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setNumQueryLastAction()
{    
    unsigned numLast = 0;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	numLast = pS->asUnsigned();
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqNumQueryLast(numLast);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setNumQueryCostAction()
{   
    unsigned numCost = 0;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	numCost = pS->asUnsigned();
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqNumQueryCost(numCost);
    handleResult(res);
    
    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}


void CegoAdmAction::verifyTableSetAction()
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqVerifyTableSet(tableSet);

    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);

    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::correctTableSetAction()
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqCorrectTableSet(tableSet);

    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);

    if ( _rawMode == false )
	cout << msg << endl;

}

void CegoAdmAction::tableSetInfoAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqGetDetailedTSInfo(tableSet);
    
    handleResult(res);    

    Chain msg;
    _pAH->getMsg(msg);
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getDetailedTableSetInfo(oe, info);

    CegoOutput output(oe.getSchema(), Chain("rl"));
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::dataFileInfoAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;   
    res = _pAH->reqGetDetailedTSInfo(tableSet);

    handleResult(res);
    
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    Chain msg;
    Chain format;
    _pAH->getMsg(msg);
    _pAH->getDataFileInfo(oe, info, format);
    
    CegoOutput output(oe.getSchema(), format);
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::archLogInfoAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqGetArchLogInfo(tableSet);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);

    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getArchLogInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::logInfoAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqGetDetailedTSInfo(tableSet);

    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
        
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getLogInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::objInfoAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqGetObjectInfo(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
        
    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getObjectInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::transactionInfoAction() 
{
    Chain tableSet;
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqGetTransactionInfo(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);

    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getTransactionInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.tabOut(info);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::exportTableAction()
{
    Chain exportFile(_stringBuf);

    Chain tableSet;
    Chain tableName;

    Chain* pS = getTokenList().First();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	tableName = *pS;
    }

    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqExportTable(tableSet, tableName, exportFile, _xportMode);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);

    if ( _rawMode == false )
	cout << msg << endl;

    // reset to default
    _xportMode = XML_XML_VALUE;
}

void CegoAdmAction::exportTableSetAction()
{
    Chain exportFile(_stringBuf);
    Chain tableSet;
    Chain* pS = getTokenList().First();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;
    res = _pAH->reqExportTableSet(tableSet, false, exportFile, _xportMode);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);

    if ( _rawMode == false )
	cout << msg << endl;

    // reset to default
    _xportMode = XML_XML_VALUE;
}

void CegoAdmAction::exportTableSetStructureAction()
{
    Chain exportFile(_stringBuf);
    Chain tableSet;

    Chain* pS = getTokenList().First();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqExportTableSet(tableSet, true, exportFile, _xportMode);
    handleResult(res);

    _xportMode = XML_XML_VALUE;

    Chain msg;
    _pAH->getMsg(msg);

    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::importTableAction()
{
    Chain importFile(_stringBuf);

    Chain tableSet;
    Chain tableName;

    Chain* pS = getTokenList().First();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	tableName = *pS;
    }
        
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqImportTable(tableSet, tableName, importFile, _xportMode);	
    handleResult(res);

    _xportMode = XML_XML_VALUE;

    Chain msg;
    _pAH->getMsg(msg);

    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::importTableSetAction()
{
    Chain importFile(_stringBuf);
    Chain tableSet;

    Chain* pS = getTokenList().First();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqImportTableSet(tableSet, false, importFile, _xportMode);
    handleResult(res);

    _xportMode = XML_XML_VALUE;

    Chain msg;
    _pAH->getMsg(msg);

    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::importTableSetStructureAction()
{
    Chain importFile(_stringBuf);

    Chain tableSet;

    Chain* pS = getTokenList().First();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqImportTableSet(tableSet, true, importFile, _xportMode);
    handleResult(res);

    _xportMode = XML_XML_VALUE;

    Chain msg;
    _pAH->getMsg(msg);

    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::addDataFileAction()
{
    unsigned numPages = 0;
    Chain tableSet;
    Chain dataFile(_stringBuf);
    Chain fileType;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	numPages = pS->asUnsigned();
    }

    pS = getTokenList().Next();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	if ( *pS == Chain("app" ) )
	{
	    fileType = Chain(XML_APPFILE_VALUE);
	}
	else if ( *pS == Chain("temp" ) )
	{
	    fileType = Chain(XML_TEMPFILE_VALUE);
	}
	else if ( *pS == Chain("sys" ) )
	{
	    fileType = Chain(XML_SYSFILE_VALUE);
	}
	else
	{
	    throw Exception(EXLOC, Chain("Invalid file type"));
	}
    }

    CegoAdminHandler::ResultType res;    
    res = _pAH->reqAddDataFile(tableSet, fileType, dataFile, numPages);

    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::listUserAction()
{
    CegoAdminHandler::ResultType res;
    res = _pAH->reqShowUser();

    handleResult(res);

    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getUserInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.tabOut(info);    
}

void CegoAdmAction::addUserAction()
{
    Chain user;
    Chain password(_stringBuf);

    Chain* pS = getTokenList().First();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	user = *pS;
    }
        
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqAddUser(user, password);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::removeUserAction()
{
    Chain tableSet;
    Chain user;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	user = *pS;
    }
        
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqRemoveUser(user);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::changePwdAction()
{
    Chain user;
    Chain password(_stringBuf);

    Chain* pS = getTokenList().First();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	user = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqChangePwd(user, password);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::assignRoleAction()
{
    Chain user;
    Chain role;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	user = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	role = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqAssignRole(user, role);

    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::removeRoleAction()
{
    Chain user;
    Chain role;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	user = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	role = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqRemoveRole(user, role);

    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::listRoleAction()
{
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqListRole();
    
    handleResult(res);

    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getRoleList(oe, info);
    
    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.tabOut(info);
}

void CegoAdmAction::showRoleAction()
{
    Chain role;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	role = *pS;
    }

    CegoAdminHandler::ResultType res;   
    res = _pAH->reqShowRole(role);
    
    handleResult(res);

    CegoTableObject oe;
    ListT<ListT<CegoFieldValue> > info;
    
    _pAH->getRoleInfo(oe, info);
    
    CegoOutput output(oe.getSchema());
    output.setRawMode(_rawMode);
    output.tabOut(info);
}

void CegoAdmAction::createRoleAction()
{
    Chain role;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	role = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqCreateRole(role);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::dropRoleAction()
{
    Chain role;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	role = *pS;
    }
        
    CegoAdminHandler::ResultType res;
    res = _pAH->reqDropRole(role);

    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setPermAction()
{
    Chain role;
    Chain permid;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	role = *pS;
    }

    pS = getTokenList().Next();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	permid = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqSetPermission(role, permid, _tsPerm, _filterPerm, _rightPerm);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setTableSetPerm()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_tsPerm = *pS;
    }
}

void CegoAdmAction::setFilterPerm()
{
    _filterPerm = Chain(_stringBuf);
}

void CegoAdmAction::setRightPerm()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_rightPerm = *pS;
    }
}

void CegoAdmAction::removePermAction()
{
    Chain role;
    Chain permid;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	role = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	permid = *pS;
    }

    CegoAdminHandler::ResultType res;
    res = _pAH->reqRemovePermission(role, permid);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::traceOnAction()
{
    Chain user;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	user = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqUserTrace(user, true);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::traceOffAction()
{
    Chain user;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	user = *pS;
    }

    CegoAdminHandler::ResultType res;   
    res = _pAH->reqUserTrace(user, false);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::addArchLogAction()
{
    Chain tableSet;
    Chain archId;
    Chain archPath(_stringBuf);

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	archId = *pS;
    }
       
    CegoAdminHandler::ResultType res;    
    res = _pAH->reqAddArchLog(tableSet, archId, archPath);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::removeArchLogAction()
{
    Chain tableSet;
    Chain archId;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
    pS = getTokenList().Next();
    pS = getTokenList().Next();
    if ( pS )
    {
	archId = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqRemoveArchLog(tableSet, archId);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::enableArchLogAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqEnableArchLog(tableSet);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::disableArchLogAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;
    
    res = _pAH->reqDisableArchLog(tableSet);
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::enableAppendModeAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqEnableAppendMode(tableSet);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::disableAppendModeAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqDisableAppendMode(tableSet);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setAutoCorrectAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqSetAutoCorrect(tableSet, _correctMode);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::setAutoCorrectDirect()
{
    _correctMode = XML_DIRECT_VALUE;
}

void CegoAdmAction::setAutoCorrectPost()
{
    _correctMode = XML_POST_VALUE;
}

void CegoAdmAction::setAutoCorrectOff()
{
    _correctMode = XML_OFF_VALUE;
}

void CegoAdmAction::enableTableCacheAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqEnableTableCache(tableSet);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::disableTableCacheAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqDisableTableCache(tableSet);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::enableQueryCacheAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqEnableQueryCache(tableSet);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::disableQueryCacheAction()
{
    Chain tableSet;

    Chain* pS = getTokenList().First();
    if ( pS )
    {
	tableSet = *pS;
    }
        
    CegoAdminHandler::ResultType res;   
    res = _pAH->reqDisableQueryCache(tableSet);
    
    handleResult(res);

    Chain msg;
    _pAH->getMsg(msg);
    if ( _rawMode == false )
	cout << msg << endl;
}

void CegoAdmAction::storeSysSizeAttr()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_sysSize = pS->asUnsigned();
    }
}

void CegoAdmAction::storeTmpSizeAttr()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_tmpSize = pS->asUnsigned();
    }
}

void CegoAdmAction::storeAppSizeAttr()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_appSize = pS->asUnsigned();
    }
}

void CegoAdmAction::storeLogSizeAttr()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_logSize = pS->asUnsigned();
    }
}

void CegoAdmAction::storeLogNumAttr()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_logNum = pS->asUnsigned();
    }
}

void CegoAdmAction::storeSortAreaAttr()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_sortAreaSize = pS->asUnsignedLongLong();
    }
}

void CegoAdmAction::storeTSRootAttr()
{
    _tsRoot = Chain(_stringBuf);
}

void CegoAdmAction::storeBranchAttr()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_branchId = pS->asUnsigned();
    }
}

void CegoAdmAction::storePit()
{
    _pit = Chain(_stringBuf);
}

void CegoAdmAction::storeLsn()
{
    Chain* pS = getTokenList().First();
    if ( pS )
    {
	_lsn = pS->asUnsignedLongLong();
    }
}

void CegoAdmAction::handleResult(CegoAdminHandler::ResultType res)
{
    if ( res == CegoAdminHandler::ADM_ERROR )
    {
	Chain msg;
	_pAH->getMsg(msg);    
	throw Exception(EXLOC, msg);
    }
    
    CegoOutput output(_admSchema, Chain("llm"));
    output.setRawMode(_rawMode);    

    if ( _resultMode == VERBOSE )
	output.headOut();

    while ( res == CegoAdminHandler::ADM_INFO && _isAborted == false )
    {	
	if ( _resultMode == VERBOSE )
	{
	    Chain msg;
	    
	    _pAH->getMsg(msg);

	    ListT<CegoFieldValue> fvl;
	    fvl.Insert(CegoFieldValue(VARCHAR_TYPE, msg));
	    
	    output.rowOut(fvl);
	}
	else if ( _resultMode == NORMAL )
	{
	    Chain msg;
	    _pAH->getMsg(msg);
	    cout << msg;
	    cout.flush();
	}

	res = _pAH->nextInfo();	
    }

    if ( _isAborted && res == CegoAdminHandler::ADM_INFO )
	res = _pAH->abort();
    	
    if ( _resultMode == VERBOSE )
	output.tailOut();
    
    
    if ( res == CegoAdminHandler::ADM_ERROR )
    {
	Chain msg;
	_pAH->getMsg(msg);
	throw Exception(EXLOC, msg);
    }
}

void CegoAdmAction::sigCatch(int sig) 
{    
    try
    {	
	install(SIGINT);
	install(SIGPIPE);

	if ( _abortEnabled )
	{
	    cout << endl << "Aborting admin command .." << endl;
	    _isAborted = true;
	}
	else
	{
	    cout << "Use quit to quit" << endl;
	}
    }
    catch ( Exception e)
    {
	Chain msg;
	e.pop(msg);
	cout << "Error : " << msg << endl;
    }   
}
