/*

Test 07: create two new tuples with one shared float component, save both to file.

*/
void SecondoTestFrame::Test07(const TupleAttributes *attributes, 
		SmiRecordFile *recFile, SmiRecordFile *lobFile) {
	Tuple* myTuple;
	Tuple* myTuple2;
	float realv;
	int intv;
	int intv2;
	char boolv;
	char boolv2;
	bool bboolv;
	bool bboolv2;
	int numberOfPoints;	
	int *X;
	int *Y;
	int i;
	CcReal *real1;
	CcInt *int1;
	CcInt *int2;
	CcBool *bool1;
	CcBool *bool2;
	CcBool *bool2a;
	Polygon* polygon1;
	Polygon* polygon2;
	SmiRecordId recId;

	myTuple = new Tuple(attributes);
	myTuple2 = new Tuple(attributes);
	
	cout << "\ta float value for both tuples, please: "; cin >> realv;						
	cout << "\tan int value for the first tuple, please: "; cin >> intv;
	cout << "\tt = true, f = false" << endl;
	cout << "\ta boolean value for the first tuple, please: "; cin >> boolv;
						
	cout << "\tan int value for the second tuple, please: "; cin >> intv2;
	cout << "\tt = true, f = false" << endl;
	cout << "\ta boolean value for the second tuple, please: "; cin >> boolv2;
	bboolv = ((boolv == 't') ? true : false);
	bboolv2 = ((boolv2 == 't') ? true : false);
	
	cout << "\thow many points, please: "; cin >> numberOfPoints;
	X = new int[numberOfPoints];
	Y = new int[numberOfPoints];
						
	for (i = 0; i < numberOfPoints; i++) {
		cout << "\t" << (i+1) << ". Point:" << endl;
		cout << "\t\tX: "; cin >> X[i];
		cout << "\t\tY: "; cin >> Y[i];
	}

	real1 = new CcReal(true, realv);
    int1 = new CcInt(true, intv);
	bool1 = new CcBool(true, bboolv);
	int2 = new CcInt(true, intv2);
	bool2 = new CcBool(true, bboolv2);
	bool2a = new CcBool(true, bboolv2);
	
	polygon1 = new Polygon(lobFile, numberOfPoints, X, Y);
	polygon2 = new Polygon(lobFile, numberOfPoints, X, Y);
	
	myTuple->DelPut(0, int1);
	myTuple->DelPut(1, bool1);
	myTuple->DelPut(2, real1);
	myTuple->Put(3, polygon1);

	myTuple2->DelPut(0, int2);
	myTuple2->DelPut(1, bool2);
	myTuple2->AttrPut(1, myTuple, 1);
	myTuple2->AttrPut(2, myTuple, 2);
	myTuple2->Put(3, polygon2);
					
	cout << "\ttest tuple values" << endl;
	cout << "\t" << *myTuple << endl;
	cout << "\tSize: " << myTuple->GetSize() << endl;
	cout << "\tAttributes: " << myTuple->GetAttrNum() << endl;
	cout << endl;
	cout << "\ttest tuple values" << endl;
	cout << "\t" << *myTuple2 << endl;
	cout << "\tSize: " << myTuple2->GetSize() << endl;
	cout << "\tAttributes: " << myTuple2->GetAttrNum() << endl;

	cout << "\tSave tuple into recFile. Persistent id = ";

	myTuple->SaveTo(recFile, lobFile);
	recId = myTuple->GetPersistentId();
	cout << recId;
	
	myTuple2->SaveTo(recFile, lobFile);
	recId = myTuple2->GetPersistentId();
	cout << ", Persistent id = " << recId << endl;
	
	cout << "****************" << endl;
	delete myTuple2;
	cout << "(I)" << *myTuple << endl;
	delete myTuple;
	cout << "****************" << endl;
	
	
        polygon1->Close();	
	delete polygon1;
	delete polygon2;

	delete[] X;
	delete[] Y;
	
	//delete myTuple2;
	//delete myTuple;
}
/*

Test 08: create new tuple with lots of points and save to file

*/
void SecondoTestFrame::Test08(const TupleAttributes *attributes, 
		SmiRecordFile *recFile, SmiRecordFile *lobFile) {
	Tuple* myTuple;	
	float realv;
	int intv;
	char boolv;
	bool bboolv;
	int numberOfPoints;	
	int *X;
	int *Y;
	int i;
	CcReal *real1;
	CcInt *int1;
	CcBool *bool1;
	Polygon* polygon1;
	SmiRecordId recId;

	myTuple = new Tuple(attributes);
	cout << "\ta float value, please: "; cin >> realv;
	cout << "\tan int value, please: "; cin >> intv;
	cout << "\tt = true, f = false" << endl;
	cout << "\ta boolean value, please: "; cin >> boolv;
	bboolv = ((boolv == 't') ? true : false);
	cout << "\thow many points, please: "; cin >> numberOfPoints;
	X = new int[numberOfPoints];
	Y = new int[numberOfPoints];
						
	for (i = 0; i < numberOfPoints; i++) {
		X[i] = i;
		Y[i] = i * i;
	}
						
	real1 = new CcReal(true, realv);
    int1 = new CcInt(true, intv);
	bool1 = new CcBool(true, bboolv);
					
	polygon1 = new Polygon(lobFile, numberOfPoints, X, Y);
	myTuple->Put(0, int1);
	myTuple->Put(1, bool1);
	myTuple->Put(2, real1);
	myTuple->Put(3, polygon1);
					
	cout << "\ttest tuple values" << endl;
	cout << "\t" << *myTuple << endl;
	cout << "\tSize: " << myTuple->GetSize() << endl;
	cout << "\tAttributes: " << myTuple->GetAttrNum() << endl;
	cout << "\tSave tuple into recFile. Persistent id = ";

	myTuple->SaveTo(recFile, lobFile);
	recId = myTuple->GetPersistentId();
	cout << recId << endl;

        polygon1->Close();	
	delete polygon1;
	delete real1;
	delete int1;
	delete bool1;
	delete[] X;
	delete[] Y;
	delete myTuple;
}
/*

Test 04: create lots of tuples and save to file.
			The number of tuples which can created
			and inserted during a single transaction
			is limited by Berkeley DB. Therefore for
			each 1000th tuple the transaction will 
			be closed and reopened.

*/
void SecondoTestFrame::Test04(const TupleAttributes *attributes, 
		SmiRecordFile *recFile, SmiRecordFile *lobFile) {
	Tuple* myTuple;	
	float realv;
	int intv;
	char boolv;
	bool bboolv;
	int numberOfPoints;
	int numberOfTuples;
	int *X;
	int *Y;
	int i;
	int j;
	CcReal *real1;
	CcInt *int1;
	CcBool *bool1;
	Polygon* polygon1;
	SmiRecordId recId;
	
	cout << "\tnumber of tuples, please: "; cin >> numberOfTuples;
	
	cout << "\ta start float value, please: "; cin >> realv;
	cout << "\tan start int value, please: "; cin >> intv;
	cout << "\tt = true, f = false" << endl;
	cout << "\ta boolean value, please: "; cin >> boolv;
	bboolv = ((boolv == 't') ? true : false);
	cout << "\thow many points, please: "; cin >> numberOfPoints;

	X = new int[numberOfPoints];
	Y = new int[numberOfPoints];
		
	for (i = 0; i < numberOfPoints; i++) {
		cout << "\t" << (i+1) << ". Point." << endl;
		cout << "\t\tX: "; cin >> X[i];
		cout << "\t\tY: "; cin >> Y[i];
	}
	
	cout << "creating ";
	for (j = 0; j < numberOfTuples; j++) {
		myTuple = new Tuple(attributes);					
		real1 = new CcReal(true, realv + j);
    	int1 = new CcInt(true, intv + j);
		bool1 = new CcBool(true, bboolv);				
		
		polygon1 = new Polygon(lobFile, numberOfPoints, X, Y);
		myTuple->Put(0, int1);
		myTuple->Put(1, bool1);
		myTuple->Put(2, real1);
		myTuple->Put(3, polygon1);
					
		//cout << *myTuple << ", ";

		myTuple->SaveTo(recFile, lobFile);
		recId = myTuple->GetPersistentId();
		//cout << recId;
		
		if (j % 100 == 0) cout << "created: " << j << endl;
		
		delete real1;
		delete int1;
		delete bool1;
                polygon1->Close();
		delete polygon1;
		delete myTuple;
		
		if ((j > 0) && (j % 1000 == 0)) {
			cout << "\t\t\tCommit Transaction..." << endl;
			SecondoSystem::GetInstance()->CommitTransaction();
			cout << "\t\t\tBegin Transaction..." << endl;
			SecondoSystem::GetInstance()->BeginTransaction();
		}
	}
	
	cout << endl;
	
	delete[] X;
	delete[] Y;
}