diff options
Diffstat (limited to 'reladminif/test')
-rw-r--r-- | reladminif/test/Makefile | 90 | ||||
-rw-r--r-- | reladminif/test/admintest.C | 92 | ||||
-rw-r--r-- | reladminif/test/check.cc | 301 | ||||
-rw-r--r-- | reladminif/test/dbnamedobjtest.C | 88 | ||||
-rw-r--r-- | reladminif/test/dbreftest.C | 70 | ||||
-rw-r--r-- | reladminif/test/demobld.sql | 125 | ||||
-rw-r--r-- | reladminif/test/demodrop.sql | 42 | ||||
-rw-r--r-- | reladminif/test/eoidtest.C | 128 | ||||
-rw-r--r-- | reladminif/test/indextest.cc | 227 | ||||
-rw-r--r-- | reladminif/test/perstest.C | 1155 | ||||
-rw-r--r-- | reladminif/test/test_databaseif.cc | 203 | ||||
-rw-r--r-- | reladminif/test/testcenter.h | 47 | ||||
-rw-r--r-- | reladminif/test/testconnect.c | 395 | ||||
-rw-r--r-- | reladminif/test/testta.pgc | 281 |
14 files changed, 3244 insertions, 0 deletions
diff --git a/reladminif/test/Makefile b/reladminif/test/Makefile new file mode 100644 index 0000000..40097a2 --- /dev/null +++ b/reladminif/test/Makefile @@ -0,0 +1,90 @@ +# -*-Makefile-*- +# +# This file is part of rasdaman community. +# +# Rasdaman community is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Rasdaman community is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +# +# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +# rasdaman GmbH. +# +# For more information please see <http://www.rasdaman.org> +# or contact Peter Baumann via <baumann@rasdaman.com>. # Top Level makefile. This points to the various modules that have to be build +# and/or deployed +# +# MAKEFILE FOR: +# reladminif tests. +# +# COMMENTS: +# - List environment dependencies, known bugs, specialities etc. +# +################################################################## +######################### Definitions ############################ + +# all test programs +ALLTESTS = test_databaseif dbreftest admintest perstest eoidtest dbnamedobjtest testindex testconnect test_databaseif + +# Needed rasdaman libraries for linking. To be completed. +NEEDEDLIBS = $(CACHETAMGR) $(QLPARSER) $(INDEXMGR) $(RELADMINIF) $(RELMDDIF) $(RELBLOBIF) $(RELINDEXIF) $(CACHETAMGR) $(RELCATALOGIF) $(RASLIB) $(RELADMINIF) $(RELMDDIF) + +# insert names of source files which need STL<TOOLKIT> +# also insert names of source files which include .hh files which need stl +NEEDSTL := dbreftest.C eoidtest.C admintest.C perstest.C dbnamedobjtest.C testindex.c + +# insert any files that are not object, bind or generated .c/.C files +# e.g.: libs +MISCCLEAN := client.bm client.dbg client.log ir.out core + +# insert object files here. makes only sense if oracle and db2 files are the same +OBJS := dbreftest.o admintest.o perstest.o eoidtest.o dbnamedobjtest.o testindex.o testconnect.o test_databaseif.o + +# add to compile flag set +CXXFLAGS += $(I_SYM)$(RMANBASE)/raslib + +########################### Targets ############################## + +# make all tests +.PHONY: test +test: $(ALLTESTS) + +indextest.o: indextest.cc + $(CXX) -c $(BASEDBCXXFLAGS) $(STLCXXFLAGS) $(CXXFLAGS) $< + +######################## Dependencies ############################ + +admintest: admintest.o $(NEEDEDLIBS) +admintest.o: admintest.C + +dbreftest: dbreftest.o +dbreftest.o: dbreftest.C + +eoidtest: eoidtest.o +eoidtest.o: eoidtest.C + +dbnamedobjtest: dbnamedobjtest.o +dbnamedobjtest.o: dbnamedobjtest.C + +perstest: perstest.o +perstest.o: perstest.C + +dbcheck.o: dbcheck.c +dbcheck.c: dbcheck.pc +dbcheck: dbcheck.o + $(PURIFY) $(CXX) $(LDFLAGS) -o $@ $^ -L/home/proj/rasdaman/3rdParty/linux/lib -L$(RMANHOME)/lib -Xlinker -Bstatic $(LIBAKINSIDE) -lmddmgr -ltilemgr -lindexmgr -lcatalogmgr -lstoragemgr -lreladminif -lrelmddif -lrelstorageif -lrelindexif -lrelcatalogif -lrelblobif -lcompression -lconversion -lraslib $(RMANHOME)/mymalloc/mymalloc_svc.o -lpng -ltiff -ljpeg -lmfhdf -ldf -lz $(REL_STATIC_LIBS) + +check: check.o + $(PURIFY) $(CXX) $(LDFLAGS) -o $@ $^ -L$(RMANHOME)/lib -Xlinker -Bstatic $(LIBAKINSIDE) -lmddmgr -ltilemgr -lindexmgr -lcatalogmgr -lstoragemgr -lreladminif -lrelmddif -lrelstorageif -lrelindexif -lrelcatalogif -lrelblobif -lcompression -lconversion -lraslib $(RMANHOME)/mymalloc/mymalloc_svc.o -lpng -ltiff -ljpeg -lmfhdf -ldf -lz $(REL_STATIC_LIBS) + +test_databaseif: test_databaseif.o ../databaseif.o + $(PURIFY) $(CXX) $(LDFLAGS) -o $@ $^ $(RMANBASE)/mymalloc/mymalloc_svc.o ../sqlerror.o ../oidif.o ../adminif.o -L$(RMANBASE)/lib -lraslib -lrasodmg $(BASEDBLDFLAGS) + diff --git a/reladminif/test/admintest.C b/reladminif/test/admintest.C new file mode 100644 index 0000000..adf0d94 --- /dev/null +++ b/reladminif/test/admintest.C @@ -0,0 +1,92 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +#include "raslib/rmdebug.hh" +#include <iostream.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" +#include "raslib/rmdebug.hh" +#include "externs.h" + +RMINITGLOBALS('C') + + +int +main(int argc, char *argv[]) + { + int RManDebug2 = 5; + int RManModule = 1; + DatabaseIf database; + TransactionIf ta; + char* name = 0; + + if (argc == 2) + name = argv[1]; + else + name = "RASBASE"; + + cout << "OPENING DATABASEIF" << endl; + if (database.open(name)) + { + cout << "ERROR OPENING DATABASE" << endl; + return -1; + } + cout << "OPENED DATABASEIF" << endl; + + if (!database.databaseExists()) + { + cout << "DATABASE EXISTS NOT" << endl; + cout << "CREATEING DATABASE" << endl; + database.create(name, 0, 0); + cout << "DATABASE CREATED" << endl; + } + else { + cout << "DATABASE EXISTS" << endl; + cout << "BEGINNING TRANSACTIONIF" << endl; + ta.begin(&database); + cout << "TRANSACTIONIF BEGUN" << endl; + cout << "DESTROYING DATABASE" << endl; + database.destroyDB(&ta, name); + cout << "DATABASE DESTROYED" << endl; + } + cout << "CLOSING DATABASEIF" << endl; + database.close(); + cout << "CLOSED DATABASEIF" << endl; + + cout << "OPENING DATABASEIF" << endl; + if (database.open(name)) + { + cout << "ERROR OPENING DATABASE" << endl; + return -1; + } + cout << "OPENED DATABASEIF" << endl; + if (database.databaseExists()) + cout << "DATABASE EXISTS" << endl; + else + cout << "DATABASE EXISTS NOT" << endl; + database.close(); + cout << "CLOSED DATABASEIF" << endl; + } diff --git a/reladminif/test/check.cc b/reladminif/test/check.cc new file mode 100644 index 0000000..44e5892 --- /dev/null +++ b/reladminif/test/check.cc @@ -0,0 +1,301 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/* +get mddoid, iterate domain, dataformat + +select mdd +get domain + { + begin ta + iterate over domain + retrieve tiles + alter tiles + commit ta + } +*/ + +#ifdef EARLY_TEMPLATE +#define __EXECUTABLE__ +#include "server/template_inst.hh" +#endif + +#include "reladminif/adminif.hh" +#include "reladminif/databaseif.hh" +#include "reladminif/transactionif.hh" +#include "reladminif/oidif.hh" +#include "mddmgr/mddobj.hh" +#include "tilemgr/tile.hh" +#include "cmlparser.hh" +#include "raslib/mitera.hh" + +#define ALLDONE 0 +#define ERRORPARSINGCOMMANDLINE 1 +#define DOMAINMISSING 2 +#define OIDMISSING 3 +#define OIDINVALID 4 +#define DOMAINMISMATCH 5 +#define FAILED 6 +#define DOMAININVALID 7 +#define UNKNOWNDATAFORMAT 8 + +char globalConnectId[256]; + +RMINITGLOBALS('S') + +r_Minterval domain; +OId oid; + +int +main(int argc, char** argv) + { + RMInit::logOut.rdbuf(cout.rdbuf()); + RMInit::dbgOut.rdbuf(cout.rdbuf()); + int retval = 0; + CommandLineParser &cmlInter = CommandLineParser::getInstance(); + CommandLineParameter &clp_help = cmlInter.addFlagParameter('h', "help", "show command line switches"); + CommandLineParameter &clp_connect = cmlInter.addStringParameter(CommandLineParser::noShortName, "connect", "database connect string", "/"); + CommandLineParameter &clp_mdddomain = cmlInter.addStringParameter(CommandLineParser::noShortName, "mdddomain", "the domain to do the changes in."); + CommandLineParameter &clp_domain = cmlInter.addStringParameter(CommandLineParser::noShortName, "domain", "the extent to be used when selecting data from the mdd."); + CommandLineParameter &clp_oid = cmlInter.addStringParameter(CommandLineParser::noShortName, "oid", "the oid of the mdd to operate on"); + CommandLineParameter &clp_comptype = cmlInter.addStringParameter(CommandLineParser::noShortName, "storageformat", "name of storage format", "Array"); + CommandLineParameter &clp_readonly = cmlInter.addFlagParameter('r', "readonly", "read only check"); + try { + cmlInter.processCommandLine(argc, argv); + } + catch(CmlException& err) + { + cmlInter.printHelp(); + cout << "Error parsing command line:" << endl; + cout << err.what() << endl; + return ERRORPARSINGCOMMANDLINE; + } + if (cmlInter.isPresent('h')) + { + cmlInter.printHelp(); + return ALLDONE; + } + r_Data_Format storageFormat = r_Array; + if (cmlInter.isPresent("storageformat")) + { + storageFormat = get_data_format_from_name(cmlInter.getValueAsString("storageformat")); + if (storageFormat == r_Data_Format_NUMBER) + { + cout << "unknown data format " << cmlInter.getValueAsString("storageformat") << endl; + return UNKNOWNDATAFORMAT; + } + } + if (!cmlInter.isPresent("domain")) + { + cout << "domain is missing" << endl; + return DOMAINMISSING; + } + if (!cmlInter.isPresent("oid")) + { + cout << "oid is missing" << endl; + return OIDMISSING; + } + strcpy((char*)globalConnectId, cmlInter.getValueAsString("connect")); + cout << "connect " << globalConnectId << endl; + try { + domain = r_Minterval(cmlInter.getValueAsString("domain")); + } + catch (const r_Error& e) + { + cout << "domain is not valid: " << e.what() << " " << e.get_errorno() << endl; + return DOMAININVALID; + } + oid = OId(atol(cmlInter.getValueAsString("oid"))); + if (oid.getType() != OId::MDDOID) + { + cout << "oid is not a mdd oid" << endl; + return OIDINVALID; + } + bool readonly = cmlInter.isPresent("readonly"); + if (readonly) + { + cout << "performing read only check" << std::endl; + } + else { + cout << "performing recompression" << std::endl; + } + cout << "set up done" << endl; + AdminIf::instance(); + DatabaseIf d; + TransactionIf t; + MDDObj* mdd = NULL; + r_Minterval completeDomain; + r_MiterArea* miter = NULL; + try { + d.open("RASBASE"); + t.begin(&d, true); + mdd = new MDDObj(oid); + if (mdd->getCurrentDomain().dimension() == domain.dimension()) + { + completeDomain = mdd->getCurrentDomain(); + if (cmlInter.isPresent("mdddomain")) + { + try { + r_Minterval temp(cmlInter.getValueAsString("mdddomain")); + if (temp.dimension() == completeDomain.dimension()) + { + cout << "Not using complete mdd domain (" << completeDomain << ") but " << temp << endl; + completeDomain = temp; + } + else { + cout << "Domains do not have same number of dimensions" << endl; + delete mdd; + mdd = NULL; + t.commit(); + d.close(); + return DOMAINMISMATCH; + } + } + catch (const r_Error& e2) + { + cout << "mdddomain parameter is not correct: " << e2.get_errorno() << " " << e2.what() << endl; + delete mdd; + mdd = NULL; + t.commit(); + d.close(); + return DOMAININVALID; + } + } + miter = new r_MiterArea(&domain, &completeDomain); + } + else { + t.commit(); + d.close(); + return DOMAINMISMATCH; + } + delete mdd; + mdd = NULL; + t.commit(); + d.close(); + } + catch (const r_Error& e) + { + delete miter; + miter = NULL; + cout << "Caught exception " << e.get_errorno() << " " << e.what() << endl; + try { + t.abort(); + } + catch (const r_Error& ee) + { + cout << "Caugh exception while aborting " << ee.get_errorno() << " " << ee.what() << endl; + try { + t.abort(); + } + catch (const r_Error& eee) + { + cout << "Caugh exception while 2nd aborting " << eee.get_errorno() << " " << eee.what() << endl; + } + } + try { + d.close(); + } + catch (const r_Error& eeee) + { + cout << "Caugh exception while closing " << eeee.get_errorno() << " " << eeee.what() << endl; + } + return FAILED; + } + std::vector<Tile*>* tiles = NULL; + std::vector<Tile*>::iterator here; + std::vector<Tile*>::iterator end; + r_Minterval currentDomain; + while (!miter->isDone()) + { + currentDomain = miter->nextArea(); + try { + d.open("RASBASE"); + t.begin(&d, readonly); + mdd = new MDDObj(oid); + tiles = mdd->intersect(currentDomain); + end = tiles->end(); + if (tiles) + { + cout << "working on " << currentDomain << " with " << tiles->size() << " tiles" << endl; + for (here = tiles->begin(); here < end; here++) + { + cout << " tile " << (*here)->getDomain() << " " << (*here)->getDBTile()->getOId() << " " << (*here)->getDataFormat() << " " << (*here)->getCompressedSize(); + if (!(*here)->decompress()) + { + cout << " decompress failed"; + } + if (((*here)->getDataFormat() != storageFormat) && (!readonly)) + { + cout << " changing storage format"; + (*here)->setCompressionFormat(storageFormat); + cout << " compressed size " << (*here)->getCompressedSize(); + } + cout << endl; + } + } + else { + cout << currentDomain << " no tiles" << endl; + } + delete mdd; + mdd = NULL; + delete tiles; + tiles = NULL; + t.commit(); + d.close(); + } + catch (const r_Error& e) + { + delete miter; + miter = NULL; + delete tiles; + tiles = NULL; + cout << "Caught exception " << e.get_errorno() << " " << e.what() << endl; + try { + t.abort(); + } + catch (const r_Error& ee) + { + cout << "Caugh exception while aborting " << ee.get_errorno() << " " << ee.what() << endl; + try { + t.abort(); + } + catch (const r_Error& eee) + { + cout << "Caugh exception while 2nd aborting " << eee.get_errorno() << " " << eee.what() << endl; + } + } + try { + d.close(); + } + catch (const r_Error& eeee) + { + cout << "Caugh exception while closing " << eeee.get_errorno() << " " << eeee.what() << endl; + } + return FAILED; + } + } + delete tiles; + tiles = NULL; + delete miter; + miter = NULL; + return retval; + } diff --git a/reladminif/test/dbnamedobjtest.C b/reladminif/test/dbnamedobjtest.C new file mode 100644 index 0000000..e0c47f4 --- /dev/null +++ b/reladminif/test/dbnamedobjtest.C @@ -0,0 +1,88 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +#include "mymalloc/mymalloc.h" +#include "raslib/rmdebug.hh" +#include <iostream.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "dbnamedobject.hh" + +RMINITGLOBALS('C') + +int RManDebug2 = 6; +int RManModule = 4; + +int +main(int argc, char *argv[]) + { + if (argc == 1) + { + cout << "Usage:" << endl; + cout << "\t1\t: " << endl << "\t\t" << endl; + } + else { + cout << "arg 1: " << argv[0] << " arg 2: " << argv[1] << " arg 3: " << argv[2] << endl; + OId* id = 0; + DBNamedObject* obj = 0; + char* text = (char*)mymalloc(sizeof(char) * 300); + struct { + short length; + char data[200]; + } VARCHAR; + + cout << "DATADUMP\t:" << VARCHAR.data << endl; + strcpy(VARCHAR.data, "aslkjfdhaskldjfjsd\0askdjfhdkjsladf\0laksjddf\0"); + cout << "DATADUMP\t:" << VARCHAR.data << endl; + switch (atoi(argv[1])) + { + case 1: + strcpy(text, "maxidaxi\0waxitaxi"); +// id = new OId(1,1); + DBNamedObject::MAXNAMELENGTH = atoi(argv[2]); + cout << "Name: " << text << endl; + obj = new DBNamedObject(text);//*id, text); + cout << "Get Name: " << obj->getName() << endl; + break; + case 2: + DBNamedObject::MAXNAMELENGTH = atoi(argv[2]); + obj = new DBNamedObject(text);//*id, text); + cout << "Get Name: " << obj->getName() << endl; + VARCHAR.length = atoi(argv[3]); + obj->setName(VARCHAR.length, (char*)VARCHAR.data); + cout << "Get Name: " << obj->getName() << endl; + break; + case 3: + DBNamedObject::MAXNAMELENGTH = atoi(argv[2]); + obj = new DBNamedObject(); + cout << "Get Name: " << obj->getName() << endl; + VARCHAR.length = atoi(argv[3]); + obj->setName(VARCHAR.length, (char*)VARCHAR.data); + cout << "Get Name: " << obj->getName() << endl; + break; + default: + cout << "DONT KNOW WHAT TO DO" << endl; + break; + } + } + } diff --git a/reladminif/test/dbreftest.C b/reladminif/test/dbreftest.C new file mode 100644 index 0000000..5c62b64 --- /dev/null +++ b/reladminif/test/dbreftest.C @@ -0,0 +1,70 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +#include "raslib/rmdebug.hh" +#include <iostream.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "dbnamedobject.hh" +#include "dbref.hh" +#include "dbobject.hh" +#include "oidif.hh" +#include "adminif.hh" +#include "databaseif.hh" +#include "oidif.hh" +#include "transactionif.hh" + +#include "alltypes.hh" +#include "typefactory.hh" + +#include "dbmddcoll.hh" +#include "dbmddcolloidentry.hh" +#include "dbmddobj.hh" + +#include "raslib/rmdebug.hh" + +RMINITGLOBALS('C') + +int RManDebug2 = 8; +int RManModule = 3; + +int +main(int argc, char *argv[]) + { + OId t(10, OId::BASETYPEOID); + + AdminIf* myAdmin; + DatabaseIf database; + TransactionIf ta; + RManDebug = 6; + + myAdmin = AdminIf::instance(); + database.open("RMAN"); + ta.begin(&database); + + DbRef<BaseType> p(t); + cout << "Type " << p->getName() << endl; + + ta.abort(); + database.close(); + } diff --git a/reladminif/test/demobld.sql b/reladminif/test/demobld.sql new file mode 100644 index 0000000..0895e87 --- /dev/null +++ b/reladminif/test/demobld.sql @@ -0,0 +1,125 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +-- +-- $Header: /home/rasdev/CVS-repository/rasdaman/reladminif/test/demobld.sql,v 1.3 2003/12/27 23:11:46 rasdev Exp $ +-- Copyright (c) Oracle Corporation 1988, 1993. All Rights Reserved. +-- +-- +-- This script creates the SQL*Plus demonstration tables. +-- +-- It should be STARTed by each user wishing to access the tables. +-- + +set termout on +prompt Building demonstration tables. Please wait. +set termout off +set feedback off + +ALTER SESSION SET NLS_LANGUAGE = AMERICAN; +ALTER SESSION SET NLS_TERRITORY = AMERICA; + +DROP TABLE EMP; +DROP TABLE DEPT; +DROP TABLE BONUS; +DROP TABLE SALGRADE; +DROP TABLE DUMMY; + +CREATE TABLE EMP + (EMPNO NUMBER(4) NOT NULL, + ENAME VARCHAR2(10), + JOB VARCHAR2(9), + MGR NUMBER(4), + HIREDATE DATE, + SAL NUMBER(7,2), + COMM NUMBER(7,2), + DEPTNO NUMBER(2)); + +INSERT INTO EMP VALUES + (7369,'SMITH','CLERK',7902,'17-DEC-80',800,NULL,20); +INSERT INTO EMP VALUES + (7499,'ALLEN','SALESMAN',7698,'20-FEB-81',1600,300,30); +INSERT INTO EMP VALUES + (7521,'WARD','SALESMAN',7698,'22-FEB-81',1250,500,30); +INSERT INTO EMP VALUES + (7566,'JONES','MANAGER',7839,'2-APR-81',2975,NULL,20); +INSERT INTO EMP VALUES + (7654,'MARTIN','SALESMAN',7698,'28-SEP-81',1250,1400,30); +INSERT INTO EMP VALUES + (7698,'BLAKE','MANAGER',7839,'1-MAY-81',2850,NULL,30); +INSERT INTO EMP VALUES + (7782,'CLARK','MANAGER',7839,'9-JUN-81',2450,NULL,10); +INSERT INTO EMP VALUES + (7788,'SCOTT','ANALYST',7566,'09-DEC-82',3000,NULL,20); +INSERT INTO EMP VALUES + (7839,'KING','PRESIDENT',NULL,'17-NOV-81',5000,NULL,10); +INSERT INTO EMP VALUES + (7844,'TURNER','SALESMAN',7698,'8-SEP-81',1500,0,30); +INSERT INTO EMP VALUES + (7876,'ADAMS','CLERK',7788,'12-JAN-83',1100,NULL,20); +INSERT INTO EMP VALUES + (7900,'JAMES','CLERK',7698,'3-DEC-81',950,NULL,30); +INSERT INTO EMP VALUES + (7902,'FORD','ANALYST',7566,'3-DEC-81',3000,NULL,20); +INSERT INTO EMP VALUES + (7934,'MILLER','CLERK',7782,'23-JAN-82',1300,NULL,10); + +CREATE TABLE DEPT + (DEPTNO NUMBER(2), + DNAME VARCHAR2(14), + LOC VARCHAR2(13) ); + +INSERT INTO DEPT VALUES + (10,'ACCOUNTING','NEW YORK'); +INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS'); +INSERT INTO DEPT VALUES + (30,'SALES','CHICAGO'); +INSERT INTO DEPT VALUES + (40,'OPERATIONS','BOSTON'); + +CREATE TABLE BONUS + ( + ENAME VARCHAR2(10), + JOB VARCHAR2(9), + SAL NUMBER, + COMM NUMBER + ); + +CREATE TABLE SALGRADE + ( GRADE NUMBER, + LOSAL NUMBER, + HISAL NUMBER ); + +INSERT INTO SALGRADE VALUES (1,700,1200); +INSERT INTO SALGRADE VALUES (2,1201,1400); +INSERT INTO SALGRADE VALUES (3,1401,2000); +INSERT INTO SALGRADE VALUES (4,2001,3000); +INSERT INTO SALGRADE VALUES (5,3001,9999); + +CREATE TABLE DUMMY + ( DUMMY NUMBER ); + +INSERT INTO DUMMY VALUES (0); + +COMMIT; + +EXIT; diff --git a/reladminif/test/demodrop.sql b/reladminif/test/demodrop.sql new file mode 100644 index 0000000..282bf6d --- /dev/null +++ b/reladminif/test/demodrop.sql @@ -0,0 +1,42 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +-- +-- $Header: /home/rasdev/CVS-repository/rasdaman/reladminif/test/demodrop.sql,v 1.3 2003/12/27 23:11:46 rasdev Exp $ +-- Copyright (c) Oracle Corporation 1988, 1993. All Rights Reserved. +-- +-- +-- This script drops the SQL*Plus demonstration tables. +-- +-- It should be STARTed by each owner of the tables. + +set termout on +prompt Dropping demonstration tables. Please wait. +set termout off + +DROP TABLE EMP; +DROP TABLE DEPT; +DROP TABLE BONUS; +DROP TABLE SALGRADE; +DROP TABLE DUMMY; + +EXIT; diff --git a/reladminif/test/eoidtest.C b/reladminif/test/eoidtest.C new file mode 100644 index 0000000..66aa0ee --- /dev/null +++ b/reladminif/test/eoidtest.C @@ -0,0 +1,128 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +#include "raslib/rmdebug.hh" +#include <iostream.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "dbnamedobject.hh" +#include "dbref.hh" +#include "dbobject.hh" +#include "oidif.hh" +#include "adminif.hh" +#include "databaseif.hh" +#include "oidif.hh" +#include "eoid.hh" +#include "transactionif.hh" + +#include "alltypes.hh" +#include "typefactory.hh" + +#include "dbmddcoll.hh" +#include "dbmddcolloidentry.hh" +#include "dbmddobj.hh" + +#include "raslib/rmdebug.hh" + +RMINITGLOBALS('C') + +int RManDebug2 = 8; +int RManModule = 3; + +int +main(int argc, char *argv[]) + { + typedef map< EOId, string, less<EOId> > ap; + typedef pair< EOId, string > air; + ap* myMap = new ap(); + AdminIf* myAdmin; + DatabaseIf database; + myAdmin = AdminIf::instance(); + database.open("RMAN"); + TransactionIf ta; + ta.begin(&database); + + cout << "DBName " << database.getName() << endl; + cout << " or " << AdminIf::getCurrentDatabaseIf()->getName() << endl;; + + OId* o = new OId(1, OId::BASETYPEOID); + EOId* e = new EOId("asys", "abase", 0L, 3); + string* s = new string("aa0"); + myMap->insert(air(*e, *s)); + + e = new EOId("asys", "abase", 5L, 3); + s = new string("aa5"); + myMap->insert(air(*e, *s)); + + e = new EOId("asys", "abase", 10L, 3); + s = new string("aa10"); + myMap->insert(air(*e, *s)); + + e = new EOId("bsys", "abase", 0L, 3); + s = new string("ba0"); + myMap->insert(air(*e, *s)); + + e = new EOId("bsys", "abase", 5L, 3); + s = new string("ba5"); + myMap->insert(air(*e, *s)); + + e = new EOId("bsys", "abase", 10L, 3); + s = new string("ba10"); + myMap->insert(air(*e, *s)); + + e = new EOId("asys", "bbase", 0L, 3); + s = new string("ab0"); + myMap->insert(air(*e, *s)); + + e = new EOId("asys", "bbase", 5L, 3); + s = new string("ab5"); + myMap->insert(air(*e, *s)); + + e = new EOId("asys", "bbase", 10L, 3); + s = new string("ab10"); + myMap->insert(air(*e, *s)); + + e = new EOId("bsys", "bbase", 0L, 3); + s = new string("bb0"); + myMap->insert(air(*e, *s)); + + e = new EOId("bsys", "bbase", 10L, 3); + s = new string("bb10"); + myMap->insert(air(*e, *s)); + + e = new EOId("bsys", "bbase", 15L, 3); + s = new string("bb15"); + myMap->insert(air(*e, *s)); + + e = new EOId("asys", "abase", 5L, 3); + s = new string("fuenf b"); + myMap->insert(air(*e, *s)); + + int i = 0; + ap::iterator iter = myMap->begin(); + for (; iter != myMap->end(); iter++) + { + i++; + cout << "Nummer " << i << " key " << (*iter).first << " value " << (*iter).second.c_str() << endl; + } + } diff --git a/reladminif/test/indextest.cc b/reladminif/test/indextest.cc new file mode 100644 index 0000000..fdcdfa9 --- /dev/null +++ b/reladminif/test/indextest.cc @@ -0,0 +1,227 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +#include "mymalloc/mymalloc.h" +#include <stdlib.h> +#include <iostream> + +#include "chartype.hh" +#include "cachetamgr/persmddcoll.hh" +#include "cachetamgr/persmddobj.hh" +#include "cachetamgr/perstile.hh" +#include "cachetamgr/persmddcolliter.hh" + +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" +#include "oidif.hh" + +#include "raslib/rminit.hh" +#include "typefactory.hh" + +#include "dbmddobj.hh" +#include "dbmddcoll.hh" + +#include "mddbasetype.hh" +#include "mdddimensiontype.hh" +#include "settype.hh" + +#ifndef BASEDB_O2 +#include "externs.h" +#endif + +RMINITGLOBALS('C') +#ifndef BASEDB_O2 +char* O2DBName = "RASBASE"; +#else +char* O2DBName = "NorbertBase"; +#endif +char *collName = "testColl"; +char defaultCollName[]= "ObjsContainer"; + +#ifdef BASEDB_O2 +extern char* myExecArgv0 = ""; +#endif + +int +main( int argc, char** argv) + { +#ifdef BASEDB_O2 + myExecArgv0 = argv[0]; +#endif + RManDebug = 3; +#ifndef BASEDB_O2 + RManModule = 0; +#endif + RMInit::logOut = cout.rdbuf(); + RMInit::dbgOut = cout.rdbuf(); + RMInit::tileSize = 12; + MDDStorage::DefaultIxType = MDDStorage::RPlusTreeNode; + + // variables representing O2 database, ta and session + DatabaseIf db; + + // don't forget to initialize before using AdminIf! + AdminIf* myAdmin = AdminIf::instance(); + TransactionIf ta; + // connect to the database + cout << "Connecting to database " << O2DBName << "..." << endl; + int errorDBOpen; + try { + errorDBOpen = db.open(O2DBName); + } + catch(...) + { + cout << "Caught Exception " << endl; + exit(-1); + } + ta.begin(&db); + int i = PersMDDColl::destroyRoot(collName, &db); + ta.commit(); + ta.begin(&db); + const CollectionType* greyset = TypeFactory::mapSetType("GreySet"); + MDDDimensionType* mddtype = (MDDDimensionType*)TypeFactory::mapMDDType("GreyCube"); + if (!mddtype || !greyset) + { + cout << "didnt find types" << endl; + exit(-1); + } + OId oColl; + if (OId::allocateMDDCollOId(&oColl) == 0) + { + } + else + cout <<"Error allocating OId for collection " << endl; + PersMDDColl* col; + try { + // CollectionType* ct = TypeFactory::mapSetType("ObjsContainerType"); + col = PersMDDColl::createRoot(collName, oColl, greyset, &db); + } + catch (...) + { + cout << "Error creating PersMDDColl" << endl; + exit(-1); + } + + greyset = TypeFactory::mapSetType("GreySet3"); + mddtype = (MDDDimensionType*)TypeFactory::mapMDDType("GreyCube"); + + OId oid1; + if (OId::allocateMDDOId(&oid1) == 0) + { + + } + else + { + cout << "Error by allocation of OId" <<endl; + exit(1); + } + + // read root object + + PersMDDColl objsSet(collName); + + + // create MDD Object 1 + + r_Sinterval limits1Obj1(0l,100l); + r_Sinterval limits2Obj1(0l,100l); + r_Sinterval limits3Obj1(0l,100l); + r_Minterval dom(3); + dom << limits1Obj1 << limits2Obj1 << limits3Obj1; + + PersMDDObj* MDDObj1 = new PersMDDObj(mddtype, dom, O2DBName, oid1); + cout << "created new persmddobj" << endl; + + char* test = (char*)mymalloc((dom.cell_count() + 1) * mddtype->getBaseType()->getSize()); + for (i = 0; i < 1000; i++) + test[i] = i%255; + + dom[0].set_interval(0l,1l); + dom[1].set_interval(0l,1l); + dom[2].set_interval(0l,1l); + PersTile* tile1Obj1 = new PersTile(dom, mddtype->getBaseType(), test); + MDDObj1->insertTile(tile1Obj1); + cout << "1--------------" << endl; + + dom[0].set_interval(2l,3l); + dom[1].set_interval(0l,1l); + dom[2].set_interval(0l,1l); + tile1Obj1 = new PersTile(dom, mddtype->getBaseType(), test); + MDDObj1->insertTile(tile1Obj1); + cout << "2--------------" << endl; + + dom[0].set_interval(4l,5l); + dom[1].set_interval(0l,1l); + dom[2].set_interval(0l,1l); + tile1Obj1 = new PersTile(dom, mddtype->getBaseType(), test); + MDDObj1->insertTile(tile1Obj1); + cout << "3--------------" << endl; + + dom[1].set_interval(0l,1l); + dom[0].set_interval(20l,21l); + dom[2].set_interval(0l,1l); + tile1Obj1 = new PersTile(dom, mddtype->getBaseType(), test); + MDDObj1->insertTile(tile1Obj1); + cout << "4--------------" << endl; + + dom[1].set_interval(0l,1l); + dom[0].set_interval(22l,23l); + dom[2].set_interval(0l,1l); + tile1Obj1 = new PersTile(dom, mddtype->getBaseType(), test); + MDDObj1->insertTile(tile1Obj1); + cout << "5--------------" << endl; + + dom[1].set_interval(0l,1l); + dom[0].set_interval(24l,25l); + dom[2].set_interval(0l,1l); + tile1Obj1 = new PersTile(dom, mddtype->getBaseType(), test); + MDDObj1->insertTile(tile1Obj1); + cout << "6--------------" << endl; + + dom[1].set_interval(0l,1l); + dom[0].set_interval(10l,11l); + dom[2].set_interval(0l,1l); + tile1Obj1 = new PersTile(dom, mddtype->getBaseType(), test); + MDDObj1->insertTile(tile1Obj1); + cout << "7--------------" << endl; + + dom[1].set_interval(0l,1l); + dom[0].set_interval(26l,27l); + dom[2].set_interval(0l,1l); + tile1Obj1 = new PersTile(dom, mddtype->getBaseType(), test); + MDDObj1->insertTile(tile1Obj1); + cout << "8--------------" << endl; + + objsSet.insert(MDDObj1); + + r_Point po("[10,0,1]"); + char* utest = MDDObj1->pointQuery(po); + if (utest) + cout << "works" << endl; + else + cout << "failure" << endl; + ta.commit(); + db.close(); + } + + diff --git a/reladminif/test/perstest.C b/reladminif/test/perstest.C new file mode 100644 index 0000000..118fcf4 --- /dev/null +++ b/reladminif/test/perstest.C @@ -0,0 +1,1155 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +#include "mymalloc/mymalloc.h" +#define TEST_PROTECTED +#define TEST_PRIVATE + +#include <stdlib.h> +#include <iostream.h> + +#include "ulongtype.hh" +#include "cachetamgr/persmddcoll.hh" +#include "cachetamgr/persmddobj.hh" +#include "cachetamgr/perstile.hh" +#include "cachetamgr/persmddcolliter.hh" + +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" +#include "oidif.hh" + +#include "raslib/rminit.hh" +#include "typefactory.hh" + +#include "dbmddobj.hh" +#include "dbmddcoll.hh" + +#include "mddbasetype.hh" +#include "mdddomaintype.hh" +#include "settype.hh" + +#include "externs.h" + + + +/* + Global Variables +*/ + +RMINITGLOBALS('C') + +static char* O2DBName; +char *collName; +char defaultCollName[]= "ObjsContainer"; +OId globalOId1, globalOId2; +OId globalCollOId; +EOId globalEOId[4]; +int numObjsCreated; +TransactionIf ta; +int ExitNo; + +/* + Functions +*/ + +int +getOption( ) +{ + unsigned int result; + cout << endl; + cout << "Choose Option : " << endl; + cout << "-----------------------------------------------------------------"<<endl; + cout << " 1 - Create MDD collection with name .. " << collName << endl; + cout << " 2 - Populate collection with MDD objects (testConstructors) " << endl; + cout << " 3 - Access MDD collection given name (testAccessing) " << endl; + cout << " 4 - Access MDD collection given OId (testAccessing)" << endl; + cout << " 5 - Access MDD object given OId (testAccessingMDDObj) " << endl; + cout << " 6 - Remove MDD object from the collection given OId (testRemove) "<<endl; + cout << " 7 - Test PersMDDObj::intersect( ) (testSearch) " <<endl; + cout << " 8 - Test PersMDDColl::getCardinality( ) "<<endl; + cout << " 9 - Test PersMDDObj get functions "<< endl; + cout << " 10 - Remove MDD Collection given OId " << endl; + cout << " 11 - Insert MDD given OId in a second collection "<< endl; + cout << " 12 - Insert tile in MDD given OId "<< globalOId1 <<endl; + cout << " 13 - Test removeTile from MDD "<< globalOId1 << endl; + ExitNo = 14; + cout << " " << ExitNo << " - Exit " << endl; + cout << "------------------------------------------------------------------"<<endl; + cout << "Enter option: "; + cin >> result; + switch (result) + { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + return result; + break; + default: + return getOption(); + } +} + +// 1 - Create MDD collection +static int createMDDColl( const char* collName, DatabaseIf* db ); + +// 2 - Populate collection with MDD objects +static void testConstructors( char* cn ); + +// 3 - Retrieves an MDD collection with name cn and prints contents: +static void testAccessing( char* cn ); + +// 4 - Retrieves an MDD collection with OId o and prints contents: +static void testAccessing( OId o ); + +// 5 - Retrieves an MDD object with OId o and prints contents: +static void testAccessingMDDObj( OId o ); + +// Removes one of the MDD objects in the collection +static void testRemove( ); + +// 6 - Removes MDD object with OId o in the collection +static void testRemove( OId o ); + +// 7 - Test PersMDDObj::intersect( ) objects of the collection +static void testSearch( ); + +// 8 - Test PersMDDColl::getCardinality( ) +static void testGetCardinality( char* cn); + +// 9 - Scans collection and tests PersMDDObj get functions +static void testGetFunctions( ); + +//10 - Remove MDD collection given OId + +//11 - Insert MDD given OId in a second collection +static void testInsertMDDObjColl( OId o, char* cn ); + +//12 - Test later insertion of tile in PersMDDObj +static void testLaterInsert( OId o ); + +//13 - Test removeTile from an MDD obj +static void testRemoveTile( OId o ); + +// Tries accessing several OIds, including ilegal ones, to test +// several error conditions. +static void testAccessingOId( ); + + +/************************************************************* + * Function name.: int main( int argc, char** argv) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * Return value..: exit status + * Description...: none + ************************************************************/ +int +main( int argc, char** argv) +{ +RManDebug = 10; +RManModule = 0; +RMInit::logOut = cout.rdbuf(); +RMInit::dbgOut = cout.rdbuf(); +RMInit::tileSize = 12; +MDDStorage::DefaultIxType = MDDStorage::RPlusTreeNode; + + // variables representing O2 database, ta and session + DatabaseIf database; + + if( argc < 2 ) { + cout << "Usage: test_persmddcoll <database> [collName]" << endl; + return -1; + } + O2DBName = strdup( argv[1] ); + if ( argc == 3 ) collName = strdup( argv[2] ); + else + collName = defaultCollName; + + // don't forget to initialize before using AdminIf! + AdminIf* myAdmin = AdminIf::instance(); + + + // connect to the database + cout << "Connecting to database " << O2DBName + << "..." << endl; + int errorDBOpen; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch( ...) + { + cout << "Caught Exception " << endl; + errorDBOpen = -6; + } + if ( errorDBOpen < 0 ) + { + cout << "Database doesn't exist. Create it new ... " << endl; + cout << "Creating new database " << O2DBName + << "..." << endl; + database.create( O2DBName, "TestSMSchema" ); + cout << "Connecting to database " << O2DBName + << "..." << endl; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch(...) + { + errorDBOpen = -6; + } + } + if ( errorDBOpen < 0 ) + { + cout << "Failed at opening newly created database " << errorDBOpen << endl; + cout << "Exiting " << endl; + return errorDBOpen; + } + + ta.begin( &database ); + cout << endl << "Deleting root object from the database ..." <<endl; + int i = PersMDDColl::destroyRoot( collName, &database ); + cout << " i == " << i << endl; + // cout << " &database = " << long( &database) << endl; + ta.commit( ); + + char c; + int error; + + for( unsigned opt = getOption( ); opt != ExitNo ; opt = getOption( ) ) + { + cout <<"Transaction begin ... " << endl; + ta.begin( &database ); + switch ( opt ) + { + case 1: // 1 - Create MDD collection with name + // create root collection + cout << endl << "Creating mdd types and root collection..." << endl; + if ( createMDDColl( collName, &database ) != 0 ) + { + cout <<"Error caught ................."<< endl; + cout << endl << "Ending O2 session..." << endl; + ta.commit( ); + database.close( ); + delete myAdmin; + exit( 1 ); + } + break; + + case 2: // 2 - Populate collection with MDD objects (testConstructors) + // create objects and put them in the collection + cout << endl << "Populate collection ..." << endl; + testConstructors( collName ); + break; + + case 3: // 3 - Access MDD collection given name (testAccessing) + // read coll and print contents + cout << endl << "Read collection " << collName << " and print contents..." << endl; + testAccessing( collName ); + break; + + case 4: // 4 - Access MDD collection given OId (testAccessing) + cout << endl << "Read collection " << globalCollOId << " and print contents..." << endl; + testAccessing( globalCollOId ); + break; + + case 5: // 5 - Access MDD object given OId (testAccessingMDDObj) + cout << endl << "Test Accessing MDD with OId " << globalOId1 << " ... " << endl; + testAccessingMDDObj( globalOId1 ); + break; + + case 6: // 6 - Remove MDD object from the collection given OId (testRemove) + cout<< endl << "Remove MDD with OId " << globalOId1 << " ..." << endl; + testRemove( globalOId1 ); + break; + + case 7: // 7 - Test PersMDDObj::intersect( ) (testSearch) + cout << endl << "Test region search ..." << endl; + testSearch( ); + break; + + case 8: // 8 - Test PersMDDColl::getCardinality( ) + cout << endl << "Get cardinality of collection" << collName <<" ..." << endl; + testGetCardinality( collName ); + break; + + case 9: // 9 - Test PersMDDObj get functions + cout << endl <<"Test PersMDDObj get functions " << endl; + testGetFunctions( ); + break; + + case 10: // 10 - Remove MDD Collection given OId + cout << endl << "Remove MDD collection with OId "; + cout << globalCollOId << " ..." << endl; + error = PersMDDColl::destroyRoot( globalCollOId, &database ); + if (error ) + cout << " Error destroying root " << endl; + break; + + case 11: // 11 - Insert MDD given OId in a second collection + cout << endl << "Insert Object with OId " << globalOId1; + cout << " in collection Coleccao1 " << endl; + cout << "First, create collection" << endl; + if ( createMDDColl( "Coleccao1", &database ) != 0 ) + { + cout <<"Error caught ................."<< endl; + cout << endl << "Ending O2 session..." << endl; + ta.commit( ); + database.close( ); + delete myAdmin; + exit( 1 ); + } + cout << "Then insert object with OId "<< globalOId1 << endl; + testInsertMDDObjColl( globalOId1 , "Coleccao1"); + cout << endl; + break; + + case 12: // 12 - Insert new tiles in the MDD object + cout << endl << "Insert Tile in object with OId " << globalOId1; + testLaterInsert( globalOId1 ); + cout << endl; + break; + + case 13: // 13 - Remove a tile from the MDD object + cout << endl << "Remove Tile from object with OId " << globalOId1; + testRemoveTile( globalOId1 ); + cout << endl; + break; + + default: + break; + } + cout <<"Transaction abort (A/a) or commit (default)? "; + cin >> c; + if ( c == 'A' || c == 'a' ) + { + ta.abort( ); + cout <<"End of Transaction Abort..."<<endl; + } + else + { + ta.commit( ); + cout <<"End of Transaction Commit..."<<endl; + } + if ( opt == 6 ) + { + cout<<"Garbage ? ( y /n ) "; + cin >> c; + if (c =='y' || c == 'Y' ) + { + cout <<"Garbaging ..."<< endl; + ta.begin( &database ); + database.garbage( ); + ta.commit( ); + } + } + cout <<"End of transaction commit... "<<endl; + } // for opt + + + cout << endl << "Ending O2 session..." << endl; + database.close( ); + delete myAdmin; + + free( O2DBName ); + if ( collName != defaultCollName ) free( collName ); + return 0; + +} + +/************************************************************* + * Functions......: + * + * static void + * testInsertMDDObjColl( OId o, char* cn ) + * + * static void + * testConstructors( char* collName ) + * + ************************************************************/ +static void +testInsertMDDObjColl( OId o, char* cn ) +{ + cout << "....testInsertMDDObjColl "<< o <<","<< cn << endl; + PersMDDObj* obj = new PersMDDObj( O2DBName,o ); + PersMDDColl objsSet( cn ); + objsSet.insert( obj ); + delete obj; + +} + +static void testConstructors( char* collName ) +{ + + const BaseType* ulongTypeObj = TypeFactory::mapType("ULong"); + const BaseType* boolTypeObj = TypeFactory::mapType("Bool"); + const MDDBaseType* mType1 = (const MDDBaseType* ) TypeFactory::mapMDDType("TestSMDomainType2D"); + const MDDBaseType* mType2 = (const MDDBaseType* ) TypeFactory::mapMDDType("TestSMDomainType3D"); + + cout << "....testConstructors"<< endl; + + OId oid1; + if ( OId::allocateMDDOId( &oid1 ) == 0) + cout << "Successfull allocation of OId " << oid1 <<endl; + else + { + cout << "Error by allocation of OId" <<endl; + exit(1); + } + OId oid2; + if ( OId::allocateMDDOId( &oid2 ) == 0) + cout << "Successfull allocation of OId " << oid2 <<endl; + else + { + cout << "Error by allocation of OId" <<endl; + exit(1); + } + + globalOId1 = oid1; + globalOId2 = oid2; + + // read root object + + PersMDDColl objsSet(collName); + + + // create MDD Object 1 + + cout << "Creating mddObj1" << endl; + cout << "tile 1 = nil, 10-12, 20-24 "<< endl; + r_Sinterval limits1Obj1(10l,12l); + r_Sinterval limits2Obj1(20l,24l); + r_Minterval dom(2); + dom << limits1Obj1 << limits2Obj1; + + r_Minterval tmpInt = *( ( MDDDomainType* ) mType1 )->getDomain( ); + PersMDDObj* MDDObj1 = new PersMDDObj( mType1, tmpInt, O2DBName, oid1 ); + + char* test = (char*)mymalloc((dom.cell_count() + 1) * 4); + memset(test, 0, (dom.cell_count() + 1) * 4); + cout << "created new persmddobj" << endl; + PersTile* tile1Obj1 = new PersTile( dom, ulongTypeObj, test ); + cout << "created new perstile" << endl; + MDDObj1->insertTile(tile1Obj1); + cout << "inserted tile" << endl; + + cout << "tile 2 = nil, 0-400, 22-24 "<< endl; + dom[0].set_interval(0l,400l); + dom[1].set_interval(22l,24l); + test = (char*)mymalloc((dom.cell_count() + 1) * 4); + memset(test, 0, (dom.cell_count() + 1) * 4); + cout << "created new perstile" << endl; + PersTile* tile2Obj1 = new PersTile( dom, ulongTypeObj, test ); + cout << "insert tile" << endl; + MDDObj1->insertTile(tile2Obj1); + cout << "inserted tile" << endl; + + cout << "tile 3 = nil, 0-600, 10-1000 "<< endl; + dom[0].set_interval(0l,600l); + dom[1].set_interval(10l,1000l); + test = (char*)mymalloc((dom.cell_count() + 1) * 4); + memset(test, 0, (dom.cell_count() + 1) * 4); + cout << "created new perstile" << endl; + PersTile* tile3Obj1 = new PersTile( dom, ulongTypeObj, test ); + cout << "insert tile" << endl; + MDDObj1->insertTile(tile3Obj1); + cout << "inserted tile" << endl; + + cout << "MDDObj1 == isPersistent:" << MDDObj1->isPersistent( )<< ";" <<endl; + MDDObj1->printStatus( ); + cout << endl; + + objsSet.insert(MDDObj1); + + // create MDD Object + cout << "Creating mddObj2 "<< endl; + cout << "tile 1 = nil, 0-19, 20-59, 30-59 "<< endl; + r_Sinterval limits1Obj2(0l,19l); + r_Sinterval limits2Obj2(20l,59l); + r_Sinterval limits3Obj2(30l,59l); + r_Minterval dom2(3); + dom2 << limits1Obj2 << limits2Obj2 << limits3Obj2; + + tmpInt = *( ( MDDDomainType* ) mType2 )->getDomain( ); + PersMDDObj* MDDObj2 = new PersMDDObj( mType2, tmpInt, O2DBName, oid2 ); + + test = (char*)mymalloc((dom.cell_count() + 1) * 1); + memset(test, 0, (dom.cell_count() + 1) * 1); + PersTile* tile1Obj2 = new PersTile( dom2, boolTypeObj, test); + MDDObj2->insertTile( tile1Obj2 ); + + cout << "tile 2 = nil, 20-39, 60-79, 60-89 "<< endl; + dom2[0].set_interval(20l,39l); + dom2[1].set_interval(60l,79l); + dom2[2].set_interval(60l,89l); + test = (char*)mymalloc((dom.cell_count() + 1) * 1); + memset(test, 0, (dom.cell_count() + 1) * 1); + PersTile* tile2Obj2 = new PersTile( dom2, boolTypeObj, test); + + MDDObj2->insertTile(tile2Obj2); + + + cout << "MDDObj2 == isPersistent:" << MDDObj2->isPersistent( )<< ";" <<endl; + MDDObj2->printStatus( ); + cout << endl; + +/* + // This program doesn't work if the TA is aborted when OIds are + // allocated, even if all allocated OIds are binded. Question: is it + // because of dangling handles? This little test was done to + // check that. + // This without oids works with ta.abort + // conclusion: the problem with abort is not due to the handles + Handle hd; + d_Ref<DBMDDObj> refObj = MDDObj2->getDBMDDObjId(); + hd = refObj.o2_get_handle(); +*/ + + + objsSet.insert(MDDObj2); + numObjsCreated = 2; + + cout << "Release all " << endl; + + //( ( PersMDDColl ) objsSet ).releaseAll( ); + + cout << "Release all END" << endl; +} + + +/************************************************************* + * Function......: testAccessing( char* cn ) + * testAccessing( OId o ) + ************************************************************/ + +static void testAccessing( char* cn ) +{ + PersMDDObj* accessedObj; + + cout << "....testAccessing collection "<< cn << endl; + + try{ + PersMDDColl objsSet( cn ); + + // To test PersMDDColl::printStatus( ) + // objsSet.printStatus( ); + + // To test PersMDDObj::printStatus( ), MDDCollIter::createIterator( ) and + // MDDCollIter methods : + + cout << "Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + cout << i<<". MDD object in set:" << endl; + accessedObj = (PersMDDObj*) objsIt->getElement(); + accessedObj->printStatus(); + EOId eoid; + if ( accessedObj->getEOId( &eoid ) ==0 ) + cout <<"EOId: " << eoid; + // old version cout <<"EOId: " << eoid.getSystemName( ) << eoid.getBaseName( ) << eoid.getOId( ); + cout << endl << endl; + accessedObj->getEOId( &globalEOId[i-1] ); + } + delete objsIt; + objsSet.releaseAll( ); + } + catch ( r_Error& errObj) + { + cout <<"Error caught ................."<< endl; + } +} + +static void testAccessing( OId o ) +{ + PersMDDObj* accessedObj; + + cout << "....testAccessing collection "<< o << endl; + + try { + PersMDDColl objsSet( o, O2DBName ); + + OId o; + if ( objsSet.getOId( &o ) == 0 ) + cout <<"getOId " << o << endl; + else + cout <<"Error getOId " << endl; + + EOId eo; + if ( objsSet.getEOId( &eo ) == 0 ) + cout << "getEOId " << eo <<endl; + // cout << "getEOId " << eo.getSystemName( ) <<":"<<eo.getBaseName( )<<":"<<eo.getOId( ) << endl; + else + cout <<"Error getEOId " << endl; + + // To test PersMDDColl::printStatus( ) + objsSet.printStatus( ); + + // To test PersMDDObj::printStatus( ), MDDCollIter::createIterator( ) and + // MDDCollIter methods : + + cout << "Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + cout << i<<". MDD object in set:" << endl; + accessedObj = (PersMDDObj*) objsIt->getElement(); + accessedObj->printStatus(); + EOId eoid; + if ( accessedObj->getEOId( &eoid ) ==0 ) + cout <<"EOId: " << eoid ; + // cout <<"EOId: " << eoid.getSystemName( ) << eoid.getBaseName() << eoid.getOId( ); + cout << endl << endl; + accessedObj->getEOId( &globalEOId[i-1] ); + } + delete objsIt; + objsSet.releaseAll( ); + } + catch ( r_Error& errObj) + { + cout <<"Error caught ................."<< endl; + } + +} + +/************************************************************* + * Function......: testAccessingMDDObj(OId o ) + * testAccessingOId( ) + * + ************************************************************/ +static void testAccessingMDDObj(OId o) +{ + PersMDDObj *mObj; + + cout << "....testAccessingMDDObj"<<endl; + + try{ + mObj = new PersMDDObj( O2DBName, o); + mObj->printStatus( ); + delete mObj; + } + catch (...) + { + cout <<" Object not found..." << endl; + + } +} + +static void testAccessingOId() +{ + PersMDDObj *mObj1, *mObj2, *mObj; + int result; + OId o(70000); + OId o1(5010); + OId o2(0); + OId o3(5); + + cout << "....testAccessingOId"<<endl; + + + cout << "Test OIdIf::getType( )..."<<endl; + cout << "1.st MDDObj " << endl; + cout << "getType " << globalOId1.getType( O2DBName ) << endl; + + cout << "2.nd MDDObj " << endl; + cout << "getType " << globalOId2.getType( O2DBName ) << endl; + + // This crashes + // cout << "OId == 0 " << endl; + // cout << "getType " << o2.getType( O2DBName ) << endl; + + cout << "OId == 5 " << endl; + cout << "getType " << o3.getType( O2DBName ) << endl; + + cout << "MDDCollection " << endl; + cout << "getType " << globalCollOId.getType( O2DBName ) << endl; + // mObj2 = new PersMDDObj( O2DBName, globalOId2); + // mObj2->printStatus( ); + + cout << "Not used OId " << endl; + cout << "getType " << o1.getType( O2DBName ) << endl; + + cout << "Nonexistent OId " << endl; + cout << "getType " << o.getType( O2DBName ) << endl; + // mObj2 = new PersMDDObj( O2DBName, globalOId2); + // mObj2->printStatus( ); + + cout <<"Loading PersMDDObjs from OIds " << endl; + mObj1 = new PersMDDObj( O2DBName, globalOId1); + mObj1->printStatus( ); + mObj2 = new PersMDDObj( O2DBName, globalOId2); + mObj2->printStatus( ); + + delete mObj1; + delete mObj2; + + + for ( int i = 0; i < numObjsCreated; i++ ) + { + cout << "Reading with " << i+1<< ".th EOId " ; + cout << globalEOId[i]; + // cout << globalEOId[i].getSystemName( ); + // cout << " ; "<< globalEOId[i].getBaseName( ) << ";" << globalEOId[i].getOId( ); + cout << endl; + + + // result = o2_externalNameGetObject( &globalEOId[i], &hdObj ); +/* + result = globalEOId[i].getObject( &hdObj ); + if ( result == 0 ) + { + DBMDDObjId obj1(hdObj); + mObj = new PersMDDObj(obj1); + mObj->printStatus( ); + } + else + cout << "No such object!!" << endl; + // o2_unref_handle( ); + delete mObj; +*/ + } + +} + +/************************************************************* + * Function......: testLaterInsert() + * + ************************************************************/ + +static void testLaterInsert( OId o ) +{ + PersMDDObj* accessedObj; + + cout << "....testLaterInsert"<<endl; + + try{ + accessedObj = new PersMDDObj( O2DBName, o); + } + catch (...) + { + cout <<" Object not found..." << endl; + return; + } + + cout << "Current status of MDD object : " << endl; + accessedObj->printStatus( ); + cout << endl << "Inserting new Tile ..."<< endl; + + PersTile *t, *t2, *t3; + switch( accessedObj->getDimension( ) ) + { + case 2 : + t2 = new PersTile( r_Minterval("[40:60,80:1200]"), + accessedObj->getCellType( ) ); + t = t2; + break; + case 3 : + t3 = new PersTile(r_Minterval("[40:60,80:100,0:20]"), + accessedObj->getCellType( ) ); + t = t3; + break; + default: + cout << "Error Dimensionality not expected" << endl; + break; + } + accessedObj->insertTile(t); + cout << " New status after insertion:" << endl; + accessedObj->printStatus(); + cout << endl << endl; + + delete accessedObj; +} + + +/************************************************************* + * Function......: testSearch() + * + ************************************************************/ +static void testSearch() +{ + + MDDObj* accessedObj; + + cout << "....testSearch"<<endl; + + PersMDDColl objsSet(collName); + + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + accessedObj = objsIt->getElement(); + + cout << "Accessed Object " << endl; + accessedObj->printStatus( ); + cout << endl; + + if (i == 1 || i == 2) + { + r_Minterval searchInt1(2); + r_Minterval searchInt2(3); + vector< Tile* >* entriesList; + + cout << " -- " << i << ". MDD object in list. Search for:"; + switch (i) { + case 1: searchInt1[0].set_interval(10l,20l); + searchInt1[1].set_interval(10l,30l); + cout << " 10-20, 10-30" << endl; + entriesList = accessedObj->intersect(searchInt1); + break; + case 2: searchInt2[0].set_interval(10l,20l); + searchInt2[1].set_interval(10l,30l); + searchInt2[2].set_interval(40l,50l); + cout << " 10-20, 10-30, 40-50" <<endl; + entriesList = accessedObj->intersect(searchInt2); + break; + default: break; + } + cout << " -- Search result: " << endl; + vector<Tile*>::iterator entryIt = entriesList->begin(); + + while (entryIt != entriesList->end()) + { + // (*entryIt)->printStatus(); + r_Minterval tileInterval = (*entryIt)->getDomain(); + int dimensionality = tileInterval.dimension(); + + cout << " PersTile printStatus"; + cout << " domain == " << dimensionality << ": "; + for (int i = 0; i <dimensionality; i++) + cout << tileInterval[i].low() << "-" + << tileInterval[i].high() <<", "; + cout << endl; + + entryIt++; + } + delete entriesList; + } + } + delete objsIt; + // objsSet.releaseAll( ); +} + +/************************************************************* + * Function......: testRemoveTile(OId o ) + * + ************************************************************/ +static void testRemoveTile(OId o) +{ + PersMDDObj *mObj; + + cout << "....testRemoveTile from MDD Obj "<< o << endl; + + try{ + mObj = new PersMDDObj( O2DBName, o); + mObj->printStatus( ); + } + catch (...) + { + cout <<" Object not found..." << endl; + return; + } + + vector<Tile*>* tiles = mObj->getTiles( ); + + if ( tiles->size( ) == 0 ) + { + cout <<"MDD object has no tiles !! "<< endl; + return; + } + else + { + int ix = tiles->size( )/2; + + cout << "Removing "<< ix <<". tile from MDD Obj "<< endl; + cout << "Tile Description: " << (*tiles)[ix]->getDomain( ) << endl; + + PersTile* t = (PersTile*) (*tiles)[ix]; + + mObj->removeTile( (*tiles)[ix] ); + + delete tiles; + delete mObj; + } +} + +/************************************************************* + * Function......: testGetCardinality( const char* cn ) + * testGetFunctions() + * + ************************************************************/ +static void testGetCardinality( char* cn ) +{ + cout << "....testGetCardinality( "<< cn << " )" << endl; + + try{ + PersMDDColl objsSet( cn ); + cout<< "Cardinality of collection " << objsSet.getCardinality( ) <<endl; + } + catch( r_Error& errObj) + { + cout <<"Error caught ................."<< endl; + } +} + +static void testGetFunctions() +{ + PersMDDObj* accessedObj; + + cout << "....testGetFunctions"<<endl; + + PersMDDColl objsSet(collName); + + MDDCollIter* objsIt = objsSet.createIterator( ); + + vector< Tile* >* entriesList; + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + r_Minterval currDom; + r_Minterval defDom; + + cout << " " << i << ". Object" << endl; + accessedObj = (PersMDDObj*) objsIt->getElement(); + + + defDom = accessedObj->getDefinitionDomain( ); + cout << " GetDefinitionDomain result: "; + defDom.print_status( ); + cout << endl; + + currDom = accessedObj->getCurrentDomain( ); + cout << " GetCurrentDomain result: "; + currDom.print_status( ); + cout << endl; + + entriesList = accessedObj->getTiles( ); + cout << " -- GetTiles result: " << endl; + vector<Tile*>::iterator entryIt = entriesList->begin(); + + while (entryIt != entriesList->end()) + { + // (*entryIt)->printStatus(); + r_Minterval tileInterval = (*entryIt)->getDomain(); + int dimensionality = tileInterval.dimension(); + + cout << " PersTile "; + cout << " domain == " << dimensionality << ": "; + for (int i = 0; i <dimensionality; i++) + cout << tileInterval[i].low() << "-" << tileInterval[i].high() <<", "; + cout << endl; + entryIt++; + } + delete entriesList; + } + delete objsIt; + objsSet.releaseAll( ); +} + +/************************************************************* + * Function......: testRemove() + * testRemove( OId o ) + * + ************************************************************/ + +static void testRemove() +{ + PersMDDObj* accessedObj; + + cout << "....testRemove"<<endl; + + PersMDDColl objsSet(collName); + // PersMDDColl objsSet("Qualquercoisa"); + // To test PersMDDColl::printStatus and PersMDDColl::remove + + + MDDCollIter* objsIt = objsSet.createIterator( ); + + cout << "-- Remove second element from collection " << endl; + + for( int i = 1 ; objsIt->notDone( ) && i < 2; i++, objsIt->advance( )) + { + accessedObj = (PersMDDObj*) objsIt->getElement(); + } + cout << "Delete of objsIt:" << endl; + delete objsIt; + cout << "Finished Delete of objsIt." << endl; + cout << "Remove accessedObj:" << endl; + objsSet.remove( accessedObj ); + cout << "Finished Remove accessedObj." << endl; +} + +static void testRemove( OId o ) +{ + + cout << "....testRemove( OId == " << o <<" ) "<< endl; + + PersMDDColl objsSet(collName); + objsSet.remove( o, O2DBName ); +} + + +/************************************************************* + * Function......: createMDDColl( ) + ************************************************************/ +static int +createMDDColl( const char* collName, DatabaseIf* db ) +{ +cout << "createMDDColl(" << collName << ", " << db->getName() << ")" << endl; + MDDDomainType* mType1 = 0; + MDDDomainType* mType2 = 0; + MDDType* mt = 0; + CollectionType* collType1 = 0; + + const BaseType* ulongTypeObj = TypeFactory::mapType("ULong"); + + const MDDDomainType* cmType1 = + ( MDDDomainType* ) TypeFactory::mapMDDType( "TestSMDomainType2D" ); + if (cmType1) + cout << "cmType1 " << cmType1->getName() << endl; + const MDDDomainType* cmType2 = + ( MDDDomainType* ) TypeFactory::mapMDDType( "TestSMDomainType3D" ); + if (cmType2) + cout << "cmType1 " << cmType2->getName() << endl; + + const CollectionType* collType = + (CollectionType*)TypeFactory::mapSetType( "ObjsContainerType" ); + if (collType) + cout << "collType " << collType->getName() << endl; + + + if( !cmType1 || !cmType2 || !collType ) + { + cout << "types not found!" << endl; + char name1[] = "TestSMDomainType2D"; + char name2[] = "TestSMDomainType3D"; + + r_Sinterval limits1Obj1(0l,1000l); + r_Sinterval limits2Obj1(0l,800l); + r_Minterval dom1(2); + dom1 << limits1Obj1 << limits2Obj1; + cout << "MDD Type 1 , domain "<< dom1 << endl; + + cout << " tile 1 = nil, 0-19, 20-59, 30-59 "<< endl; + r_Sinterval limits1Obj2(0l,19l); + r_Sinterval limits2Obj2(20l,59l); + r_Sinterval limits3Obj2(30l,59l); + r_Minterval dom2(3); + dom2 << limits1Obj2 << limits2Obj2 << limits3Obj2; + cout << "MDD Type 2 , domain "<< dom2 << endl; + + // MDDDomainType* mType1 = + mType1 = + new MDDDomainType((char*) name1, ( BaseType* ) ulongTypeObj, dom1 ); + // MDDDomainType* mType2 = + mType2 = + new MDDDomainType((char*) name2, ( BaseType* ) ulongTypeObj, dom2 ); + + cout << "MDD Type1 == "; + mType1->print_status( cout ); + cout << endl; + cout << "MDD Type2 == "; + mType2->print_status( cout ); + cout << endl; + + TypeFactory::addMDDType( mType1 ); + TypeFactory::addMDDType( mType2 ); + + if ( !collType ) + { + cout << "Collection type newly created " << endl; + // MDDType* mt = new MDDType( ); + mt = new MDDType( ); + cout << "MDDtype created "<< endl; + collType1 = new SetType( "ObjsContainerType", mType1 ); + cout << "Set Type created ... "; + collType = collType1; + TypeFactory::addSetType( (SetType*) collType ); + cout <<" and added "<< endl; + + } + + } + else + cout << "types were found!" << endl; + //ta.commit( ); + + //ta.begin( ); + + cout << "Creating root collection" << endl; + + // cout << " &database = " << long( db ) << endl; + + OId oColl; + if( OId::allocateMDDCollOId( &oColl ) == 0 ) + cout <<"Successfully allocated OId for collection " << oColl << endl; + else + cout <<"Error allocating OId for collection " << endl; + globalCollOId = oColl; + + PersMDDColl* col; + try { + // CollectionType* ct = TypeFactory::mapSetType( "ObjsContainerType" ); + col = PersMDDColl::createRoot( collName, oColl, collType, db ); + } + catch (...) + { + cout <<"Error caught ................."<< endl; + return -1; + } + + cout << "Committing TA ..."<< endl; + ta.commit( ); + + /* + + cout <<"Freeing types ... "<< endl; + + // if ( mType1 ) delete mType1; + cout << "Type 1 freed . "<< endl; + // if ( mType2 ) delete mType2; + cout << "Type 2 freed . "<< endl; + // if ( mt ) delete mt; + cout << "Type mt freed . "<< endl; + // if ( collType1 ) delete collType1; + cout << "Types collType1 freed . "<< endl; + */ + if ( col ) delete col; + cout << "Col freed . "<< endl; + + + ta.begin( db ); + return 0; +} diff --git a/reladminif/test/test_databaseif.cc b/reladminif/test/test_databaseif.cc new file mode 100644 index 0000000..46caa5f --- /dev/null +++ b/reladminif/test/test_databaseif.cc @@ -0,0 +1,203 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/************************************************************************* + * + * + * PURPOSE: + * test class DatabaseIf. + * + * + * PREREQUISITES: + * - needs COMPDATE (compilation date) defined, eg. cc -DCOMPDATE=\"`date`\" + * + * COMMENTS: + * + ***********************************************************************/ + +static const char rcsid[] = "@(#)reladminif,DatabaseIf: $Id: databaseif.ec,v 1.9 2003/12/27 23:11:43 rasdev Exp $"; + +using namespace std; + +#include <iostream.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "error.hh" +#include "adminif.hh" +#include "databaseif.hh" +#include "externs.h" + +#include "raslib/rmdebug.hh" +#define DEBUG_MAIN +#include "debug.hh" + + +RMINITGLOBALS('C') + + +// test environment: +#include "testcenter.h" + +#define ELLIPSIS "..." +/// test macro for checking error condition, printing result, and aborting on error +#define CHECK(p) { cout << "CHECKING " << "p"; \ + if (!(p)) \ + { cout << TEST_ERROR << endl; \ + return false; \ + } \ + else \ + { \ + cout << TEST_OK << endl; \ + } \ + } + +/// ObjectBroker: dummy class to satisfy linker; real ObjectBroker functionality never used here. +class ObjectBroker +{ + public: + void init(); + void deinit(); + bool freeMemory(); +}; + +void ObjectBroker::init() +{ +} +void ObjectBroker::deinit() +{ +} +bool ObjectBroker::freeMemory() +{ + return true; +} + +/// from server/rasserver_main.cc: +char globalConnectId[256]; + +/// doTest(): run the test cases +/// preconditions: +/// database does NOT yet exist +/// @params: +/// dbname name of database +/// @returns: +/// true if all tests succeeded +/// false if some test failed + +bool doTest( const char *dbname ) +{ + bool result = false; // overall test result + DatabaseIf *db = NULL; // our test candidate + + try // capture eny eventual exception for reporting + { + // --- (1) good scenario + + cout << "DatabaseIf constructor" << ELLIPSIS << flush; + db = new DatabaseIf(); + cout << "new state is: " << *db; + CHECK( db != NULL ); + + cout << "create" << ELLIPSIS << endl; + db->createDB( dbname, NULL, NULL ); + CHECK( db->isConnected() ); + CHECK( db->isOpen() ); + + cout << "db open" << ELLIPSIS << endl; + db->open( dbname ); + CHECK( db->isConnected() ); + CHECK( db->isOpen() ); + + cout << "db close" << ELLIPSIS << endl; + db->close(); + CHECK( db->isConnected() ); + CHECK( db->isOpen() ); + + cout << "db destroy" << ELLIPSIS << endl; + db->destroyDB( dbname ); + CHECK( db->isConnected() ); + CHECK( db->isOpen() ); + + result = true; + } + // FIXME: what else should be caught explicitly? + catch(r_Error& myErr) + { + cout << "caught r_Error exception #" << myErr.get_errorno() << ": " << myErr.what() << endl; + result = false; + } + catch(bad_alloc) + { + cout << "caught bad_alloc exception" << endl; + result = false; + } + catch(...) + { + cout << "caught unknown exception" << endl; + result = false; + } + + return result; +} + +int +main(int argc, char *argv[]) +{ + const char *progName = argv[0]; // name of this test program + + int RManDebug2 = 5; // debug trace settings + int RManModule = 1; // dito + + char* dbName = "RASBASE"; // default database name + int result = RC_ERROR; // overall test exit code + char *resultText = NULL; // overall test status string + + // --- parameter evaluation, launch msg + if (argc == 2) + dbName = argv[1]; + else if (argc > 2) + { + cout << "usage: " << progName << " [dbname]" << endl; + return( RC_USAGE ); + } + cout << progName << ", generated on " << COMPDATE << " for rasdaman version " << RMANVERSION << " and base DBMS " << BASEDBSTRING << "; using database '" << dbName << "'" << endl; + + // --- all is fine, let's do the test + bool allFine = doTest( dbName ); + + if (allFine) + { + resultText = TEST_OK; + result = RC_OK; + } + else + { + resultText = TEST_ERROR; + result = RC_ERROR; + } + + // --- done, epilogue + cout << progName << ": overall test result is " << resultText << endl; + + return( result ); +} + diff --git a/reladminif/test/testcenter.h b/reladminif/test/testcenter.h new file mode 100644 index 0000000..c17d94f --- /dev/null +++ b/reladminif/test/testcenter.h @@ -0,0 +1,47 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/************************************************************************* + * + * + * PURPOSE: + * provide global settings for running system tests. + * + * + * COMMENTS: + * + ***********************************************************************/ + +#ifndef _TESTCENTER_H_ + +/// program exit codes +#define RC_OK 0 +#define RC_USAGE 2 +#define RC_ERROR -1 + +/// protocol output, must be canonical for automatic & regression testing +#define TEST_OK "OK" +#define TEST_ERROR "ERROR" + +#define _TESTCENTER_H_ +#endif _TESTCENTER_H_ + diff --git a/reladminif/test/testconnect.c b/reladminif/test/testconnect.c new file mode 100644 index 0000000..70215b7 --- /dev/null +++ b/reladminif/test/testconnect.c @@ -0,0 +1,395 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +#include <sqlhdr.h> +#include <sqliapi.h> +#line 1 "testconnect.ec" +/* testconnect.ec +test connection to Informix database +*/ + +#include <iostream> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <minmax.h> + +/* + * EXEC SQL INCLUDE SQLCA; + */ +#line 11 "testconnect.ec" + +#line 11 "testconnect.ec" +#line 1 "/opt/informix/incl/esql/sqlca.h" +/**************************************************************************** + * + * IBM INC. + * + * PROPRIETARY DATA + * + * Licensed Material - Property Of IBM + * + * "Restricted Materails of IBM" + * + * IBM Informix Client SDK + * + * (c) Copyright IBM Corporation 2002. All rights reserved. + * + * + * Title: sqlca.h + * Sccsid: @(#)sqlca.h 9.4 1/18/93 11:09:48 + * Description: + * SQL Control Area + * + *************************************************************************** + */ + +#ifndef SQLCA_INCL +#define SQLCA_INCL + +#include "ifxtypes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct sqlca_s + { + int4 sqlcode; + char sqlerrm[72]; /* error message parameters */ + char sqlerrp[8]; + int4 sqlerrd[6]; + /* 0 - estimated number of rows returned */ + /* 1 - serial value after insert or ISAM error code */ + /* 2 - number of rows processed */ + /* 3 - estimated cost */ + /* 4 - offset of the error into the SQL statement */ + /* 5 - rowid after insert */ +#ifdef _FGL_ + char sqlawarn[8]; +#else + struct sqlcaw_s + { + char sqlwarn0; /* = W if any of sqlwarn[1-7] = W */ + char sqlwarn1; /* = W if any truncation occurred or + database has transactions or + no privileges revoked */ + char sqlwarn2; /* = W if a null value returned or + ANSI database */ + char sqlwarn3; /* = W if no. in select list != no. in into list or + turbo backend or no privileges granted */ + char sqlwarn4; /* = W if no where clause on prepared update, delete or + incompatible float format */ + char sqlwarn5; /* = W if non-ANSI statement */ + char sqlwarn6; /* = W if server is in data replication secondary mode */ + char sqlwarn7; /* = W if database locale is different from proc_locale + */ + } sqlwarn; +#endif + } ifx_sqlca_t; + +/* NOTE: 4gl assumes that the sqlwarn structure can be defined as + * sqlawarn -- an 8 character string, because single-char + * variables are not recognized in 4gl. + * + * If this structure should change, the code generated by 4gl compiler + * must also change + */ + +#ifdef VMS +noshare +#endif /* VMS */ + +#define SQLNOTFOUND 100 + +#ifndef IFX_THREAD +extern struct sqlca_s sqlca; + +extern int4 SQLCODE; + +extern char SQLSTATE[]; +#else /* IFX_THREAD */ +extern int4 * ifx_sqlcode(); +extern struct sqlca_s * ifx_sqlca(); +#define SQLCODE (*(ifx_sqlcode())) +#define SQLSTATE ((char *)(ifx_sqlstate())) +#define sqlca (*(ifx_sqlca())) +#endif /* IFX_THREAD */ + +#ifdef __cplusplus +} +#endif + +#endif /* SQLCA_INCL */ + +#line 101 "/opt/informix/incl/esql/sqlca.h" +/* + * EXEC SQL define SUCCESS 0; + */ +#line 12 "testconnect.ec" + +/* + * EXEC SQL define WARNING 1; + */ +#line 13 "testconnect.ec" + +/* + * EXEC SQL define NODATA 100; + */ +#line 14 "testconnect.ec" + +/* + * EXEC SQL define RTERROR -1; + */ +#line 15 "testconnect.ec" + +#line 16 "testconnect.ec" + +/* + * The sqlstate_err() function checks the SQLSTATE status variable to see + * if an error or warning has occurred following an SQL statement. + */ +int4 sqlstate_err() +{ + int4 err_code = -1; + + if(SQLSTATE[0] == '0') /* trap '00', '01', '02' */ + { + switch(SQLSTATE[1]) + { + case '0': /* success - return 0 */ + err_code = 0; + break; + case '1': /* warning - return 1 */ + err_code = 1; + break; + case '2': /* end of data - return 100 */ + err_code = 100; + break; + default: /* error - return SQLCODE */ + break; + } + } + return(err_code); +} + +/* + * The disp_sqlstate_err() function executes the GET DIAGNOSTICS + * statement and prints the detail for each exception that is returned. + */ +void disp_sqlstate_err() +{ + mint j; + +/* + * EXEC SQL BEGIN DECLARE SECTION; + */ +#line 53 "testconnect.ec" +#line 54 "testconnect.ec" +#line 54 "testconnect.ec" +mint exception_count; +#line 55 "testconnect.ec" + char overflow[2]; +#line 56 "testconnect.ec" +mint exception_num = 1; +#line 57 "testconnect.ec" + char class_id[255]; +#line 58 "testconnect.ec" + char subclass_id[255]; +#line 59 "testconnect.ec" + char message[255]; +#line 60 "testconnect.ec" +mint messlen; +#line 61 "testconnect.ec" + char sqlstate_code[6]; +#line 62 "testconnect.ec" +mint i; +/* + * EXEC SQL END DECLARE SECTION; + */ +#line 63 "testconnect.ec" + + + printf("SQLSTATE: %s\n",SQLSTATE); + printf("SQLCODE: %d\n", SQLCODE); + +/* + * EXEC SQL get diagnostics :exception_count = NUMBER, :overflow = MORE; + */ +#line 68 "testconnect.ec" + { +#line 68 "testconnect.ec" + static ifx_hostvar_t _SQhtab[] = + { + { 0, 1, 102, sizeof(exception_count), 0, 0, 0, 0 }, + { 0, 2, 100, 2, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0 } +#line 68 "testconnect.ec" + }; + _SQhtab[0].hostaddr = (char *)&exception_count; + _SQhtab[1].hostaddr = (overflow); +#line 68 "testconnect.ec" + sqli_diag_get(ESQLINTVERSION, _SQhtab, -1); +#line 68 "testconnect.ec" + } + + printf("EXCEPTIONS: Number=%d\t", exception_count); + printf("More? %s\n", overflow); + + for (i = 1; i <= exception_count; i++) + { +/* + * EXEC SQL get diagnostics exception :i + * :sqlstate_code = RETURNED_SQLSTATE, + * :class_id = CLASS_ORIGIN, :subclass_id = SUBCLASS_ORIGIN, + * :message = MESSAGE_TEXT, :messlen = MESSAGE_LENGTH; + */ +#line 75 "testconnect.ec" + { +#line 78 "testconnect.ec" + static ifx_hostvar_t _SQhtab[] = + { + { 0, 3, 100, 6, 0, 0, 0, 0 }, + { 0, 4, 100, 255, 0, 0, 0, 0 }, + { 0, 5, 100, 255, 0, 0, 0, 0 }, + { 0, 6, 100, 255, 0, 0, 0, 0 }, + { 0, 7, 102, sizeof(messlen), 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0 } +#line 78 "testconnect.ec" + }; + _SQhtab[0].hostaddr = (sqlstate_code); + _SQhtab[1].hostaddr = (class_id); + _SQhtab[2].hostaddr = (subclass_id); + _SQhtab[3].hostaddr = (message); + _SQhtab[4].hostaddr = (char *)&messlen; +#line 78 "testconnect.ec" + sqli_diag_get(ESQLINTVERSION, _SQhtab, i); +#line 78 "testconnect.ec" + } + + printf("EXCEPTION %d: SQLSTATE=%s\n", i, sqlstate_code); + message[messlen-1] = '\0'; + printf("MESSAGE TEXT: %s\n", message); + j = byleng(class_id, stleng(class_id)); + class_id[j] = '\0'; + printf("CLASS ORIGIN: %s\n",class_id); + j = byleng(subclass_id, stleng(subclass_id)); + subclass_id[j] = '\0'; + printf("SUBCLASS ORIGIN: %s\n",subclass_id); + } +} + +void disp_error(char* stmt) +{ +} + +void disp_exception(char* stmt, int4 sqlerr_code, mint warn_flg) +{ + switch (sqlerr_code) + { + case 0: + case 100: + break; + case 1: + if(warn_flg) + { + printf("Warning encountered in %s\n", stmt); + disp_sqlstate_err(); + } + break; + case -1: + printf("Error encountered in %s\n", stmt); + disp_sqlstate_err(); + break; + default: + printf("INVALID EXCEPTION STATE for %s\n", stmt); + break; + } +} + +int +check() +{ + mint warn_flg = 1; + int4 sqlerr_code = 0; + + sqlerr_code = sqlstate_err(); + disp_exception((char*)"error", sqlerr_code, warn_flg); + + return SQLCODE; +} + + +int +main(int argc, char** argv) +{ + cout << argv[0] << " Informix database access test" << endl; + if (argc != 2) + { + cout << "Usage: " << argv[0] << " connectstring" << endl; + return 2; + } + +/* + * EXEC SQL BEGIN DECLARE SECTION; + */ +#line 143 "testconnect.ec" +#line 144 "testconnect.ec" +#line 144 "testconnect.ec" + char id[256]; +/* + * EXEC SQL END DECLARE SECTION; + */ +#line 145 "testconnect.ec" + + + strcpy( id, argv[1] ); + cout << "using connect string: " << id << endl; + +/* + * EXEC SQL CONNECT TO :id; + */ +#line 150 "testconnect.ec" + { +#line 150 "testconnect.ec" + sqli_connect_open(ESQLINTVERSION, 0, id, (char *) 0, (ifx_conn_t *) 0, 0); +#line 150 "testconnect.ec" + } + check(); + +/* + * EXEC SQL DISCONNECT CURRENT; + */ +#line 153 "testconnect.ec" + { +#line 153 "testconnect.ec" + sqli_connect_close(3, (char *) 0, 0, 0); +#line 153 "testconnect.ec" + } + check(); + + cout << argv[0] << ": done." << endl; + return 0; +} + + +#line 159 "testconnect.ec" diff --git a/reladminif/test/testta.pgc b/reladminif/test/testta.pgc new file mode 100644 index 0000000..38a994c --- /dev/null +++ b/reladminif/test/testta.pgc @@ -0,0 +1,281 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/************************************************************************* + * + * + * PURPOSE: + * test class TransactionIF. + * + * + * COMMENTS: + * none + * + * PRECONDITIONS: + * - database exists and is accessible (PG & rasdaman server running) + * - reladminif/DatabaseIF works + * + ***********************************************************************/ + +static const char rcsid[] = "@(#)reladminif,TransactionIf: $Id: testta.pgc,v 1.6 2003/12/27 23:11:43 rasdev Exp $"; + +#define DEBUG_MAIN +#include "debug.hh" + +// constants: +#define DATABASE "RASBASE" + +// pointers representing O2, database, ta and session +AdminIf* admin = NULL; +DatabaseIf* db = NULL; +TransactionIf* ta = NULL; + +int main() +{ + const char *prog = argv[0]; // this program's name + + cout << prog << ": test for transactionif, generated on " << COMPDATE << endl; + + // --- outmost exception catcher ------------------------ + try + { + + // --- (1) preparation: open connection + admin = AdminIf::instance(); + if( !admin ) + { + cout << prog << ": cannot create adminIf instance" << endl; + throw r_Error(); + } + // connect to the database + db = new DatabaseIf(); + if( !admin ) + { + cout << prog << ": cannot create DatabaseIf instance" << endl; + throw r_Error(); + } + db->open( DATABASE ); + + ta = new TransactionIf(); + if( !admin ) + { + cout << prog << ": cannot create TransactionIf instance" << endl; + throw r_Error(); + } + ta->begin( db ); + ta->abort( db ); + ta->commit( db ); + + db->close(); + } + catch(...) + { + cout << prog << ": error abort." << endl; + } + + cout << prog << ": test for transactionif done." << endl; +} + + +void +TransactionIf::begin( bool readOnly ) throw ( r_Error ) +{ + RMDBGENTER(2, RMDebug::module_adminif, "TransactionIf", "begin(" << readOnly << ")"); + ENTER( "TransactionIf::begin, readOnly=" << readOnly ); + + isReadOnly = readOnly; + AdminIf::setAborted(false); + AdminIf::setReadOnlyTA(readOnly); + + TALK( "EXEC SQL BEGIN WORK" ); + EXEC SQL BEGIN WORK; + if (sqlca.sqlwarn[2] == 'W') // real error, not just a warning + { + SQLCODE = 0; // FIXME: bad hack, as PG can't reset error state and SQLCODE is queried in many places -- PB 2005-jan-09 + } + else + { + RMDBGMIDDLE(4, RMDebug::module_adminif, "TransactionIf", "error occured while issuing BEGIN"); + LEAVE( "TransactionIf::begin(): error during BEGIN: " << SQLCODE ); + generateException(); + } + + if (readOnly) + { + TALK( "EXEC SQL SET TRANSACTION READ ONLY" ); + EXEC SQL SET TRANSACTION READ ONLY; + // no error check, as this doesn't inhibit work + } + + // prelim.:have additional libpq TA -- PB 2005-jan-09 + TALK( "PQexec( pgConn, BEGIN )" ); + PGresult *pgResult = PQexec( pgConn, "BEGIN" ); + if (PQresultStatus(pgResult) != PGRES_COMMAND_OK) + { + LEAVE( "TransactionIf::begin() Error: cannot open libpq TA: " << PQerrorMessage(pgConn) ); + generateException(); + } + +#ifdef RMANBENCHMARK + DBObject::readTimer.start(); + DBObject::readTimer.pause(); + + DBObject::updateTimer.start(); + DBObject::updateTimer.pause(); + + DBObject::deleteTimer.start(); + DBObject::deleteTimer.pause(); + + DBObject::insertTimer.start(); + DBObject::insertTimer.pause(); + + OId::oidAlloc.start(); + OId::oidAlloc.pause(); + + OId::oidResolve.start(); + OId::oidResolve.pause(); +#endif + + OId::initialize(); + TypeFactory::initialize(); + + LEAVE( "TransactionIf::begin, SQLCODE=" << SQLCODE ); + RMDBGEXIT(2, RMDebug::module_adminif, "TransactionIf", "begin(" << readOnly << ") "); +} + +void +TransactionIf::commit() throw ( r_Error ) +{ + RMDBGENTER(2, RMDebug::module_adminif, "TransactionIf", "commit()"); + ENTER( "TransactionIf::commit" ); + + if (isReadOnly) + { + RMDBGMIDDLE(9, RMDebug::module_adminif, "TransactionIf", "read only: aborting"); + TALK( "TA is readonly: aborting" ); + abort(); + } + else + { + AdminIf::setAborted(false); + RMDBGMIDDLE(9, RMDebug::module_adminif, "TransactionIf", "set aborted false"); + TypeFactory::freeTempTypes(); + RMDBGMIDDLE(9, RMDebug::module_adminif, "TransactionIf", "freed temp types"); + ObjectBroker::clearBroker(); + RMDBGMIDDLE(9, RMDebug::module_adminif, "TransactionIf", "cleared broker"); + OId::deinitialize(); + RMDBGMIDDLE(9, RMDebug::module_adminif, "TransactionIf", "wrote oid counters"); + AdminIf::setReadOnlyTA(false); + RMDBGMIDDLE(9, RMDebug::module_adminif, "TransactionIf", "committing"); + + TALK( "EXEC SQL COMMIT WORK" ); + EXEC SQL COMMIT WORK; + if (check("TransactionIf::begin() COMMIT\0")) + { + RMDBGMIDDLE(4, RMDebug::module_adminif, "TransactionIf", "error occured while issuing COMMIT"); + LEAVE( "TransactionIf::commit(): error during COMMIT:" << SQLCODE ); + generateException(); + } + + // prelim.:have additional libpq TA -- PB 2005-jan-09 + TALK( "PQexec( pgConn, END )" ); + PGresult *pgResult = PQexec( pgConn, "END" ); + if (PQresultStatus(pgResult) != PGRES_COMMAND_OK) + { + LEAVE( "TransactionIf::commit() Error: cannot commit libpq TA: " << PQerrorMessage(pgConn) ); + generateException(); + } + + if (lastBase) + { + RMDBGMIDDLE(9, RMDebug::module_adminif, "TransactionIf", "closing dbms"); + lastBase->baseDBMSClose(); + } + } + +#ifdef RMANBENCHMARK + DBObject::readTimer.stop(); + + DBObject::updateTimer.stop(); + + DBObject::deleteTimer.stop(); + + DBObject::insertTimer.stop(); + + OId::oidAlloc.stop(); + + OId::oidResolve.stop(); +#endif + + LEAVE( "TransactionIf::commit" ); + RMDBGEXIT(2, RMDebug::module_adminif, "TransactionIf", "commit() " << endl << endl); +} + +void +TransactionIf::abort() +{ + RMDBGENTER(2, RMDebug::module_adminif, "TransactionIf", "abort()"); + ENTER( "TransactionIf::abort" ); + + // prelim.:have additional libpq TA -- PB 2005-jan-09 + TALK( "PQexec( pgConn, ABORT )" ); + PGresult *pgResult = PQexec( pgConn, "ABORT" ); + if (PQresultStatus(pgResult) != PGRES_COMMAND_OK) + { + LEAVE( "TransactionIf::abort() Error: cannot abort libpq TA: " << PQerrorMessage(pgConn) ); + generateException(); + } + + AdminIf::setAborted(true); + TypeFactory::freeTempTypes(); + ObjectBroker::clearBroker(); + OId::deinitialize(); + AdminIf::setReadOnlyTA(false); + + TALK( "EXEC SQL ROLLBACK WORK" ); + EXEC SQL ROLLBACK WORK; + if (check("TransactionIf::abort() ROLLBACK\0")) + { + RMDBGMIDDLE(4, RMDebug::module_adminif, "TransactionIf", "error occured while issuing ROLLBACK"); + TALK( "TransactionIf::abort(): error during ROLLBACK, still continuing: " << SQLCODE ); + } + if(lastBase) + lastBase->baseDBMSClose(); + +#ifdef RMANBENCHMARK + DBObject::readTimer.stop(); + + DBObject::updateTimer.stop(); + + DBObject::deleteTimer.stop(); + + DBObject::insertTimer.stop(); + + OId::oidAlloc.stop(); + + OId::oidResolve.stop(); +#endif + + LEAVE( "TransactionIf::abort, SQLCODE=" << SQLCODE ); + RMDBGEXIT(2, RMDebug::module_adminif, "TransactionIf", "abort() " << endl << endl); +} + |