00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "OracleDatastore.h"
00018 #include <iostream>
00019 #include <fstream>
00020 #include <string.h>
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <bool.h>
00024
00025 #include <MovableObject.h>
00026 #include <FEM_ObjectBroker.h>
00027 #include <Domain.h>
00028 #include <ID.h>
00029 #include <Vector.h>
00030 #include <Matrix.h>
00031
00032 #define IsCreateTable 0
00033
00034 extern "C" void connectToDB(char *theUser, char* thePass);
00035 extern "C" void commitDatabase();
00036 extern "C" void createIDTable(char *tableName);
00037 extern "C" void createVectorTable(char *tableName);
00038 extern "C" void createMatrixTable(char *tableName);
00039 extern "C" void cleanTables();
00040
00041 extern "C" void changeProjTag(int projectID);
00042
00043
00044 extern "C" int queryProjTag();
00045
00046 extern "C" int queryTagOnName(char *projName);
00047
00048 extern "C" void insertIDTable(int idSize, int *tempProjTag, int *tempDataTag,
00049 int *tempCommitTag, int *tempPos, int *tempID);
00050
00051 extern "C" void queryIDTable(int idSize, int projTag, int dataTag,
00052 int commitTag, int *tempID);
00053
00054 extern "C" void insertVectorTable(int vectSize, int *tempProjTag, int *tempDataTag,
00055 int *tempCommitTag, int *tempPos, double *tempVect);
00056 extern "C" void queryVectorTable(int vectSize, int projTag, int dataTag,
00057 int commitTag, double *tempVect);
00058
00059 extern "C" void insertMatrixTable(int matrixSize, int *tempProjTag, int *tempDataTag,
00060 int *tempCommitTag, int *row, int *col, double *tempMatrix);
00061 extern "C" void queryMatrixTable(int rowSize, int colSize, int projTag, int dataTag,
00062 int commitTag, double *tempMatrix);
00063
00064
00065
00066 OracleDatastore::OracleDatastore(char *dataBaseName,
00067 Domain &theDomain,
00068 FEM_ObjectBroker &theObjBroker)
00069 :FE_Datastore(theDomain, theObjBroker), dbTag(0)
00070 {
00071 connectToDB("junpeng", "g3iscool");
00072
00073 projTag = this->searchProjTag(dataBaseName);
00074
00075 if (IsCreateTable) {
00076 createIDTable("ID");
00077 createVectorTable("VECTOR");
00078 createMatrixTable("MATRIX");
00079 }
00080
00081
00082 }
00083
00084
00085 OracleDatastore::~OracleDatastore()
00086 {
00087 commitDatabase();
00088 }
00089
00090
00091 int
00092 OracleDatastore::getProjTag(void)
00093 {
00094 return projTag;
00095 }
00096
00097
00098
00099
00100 void
00101 OracleDatastore::setProjTag(int projectID)
00102 {
00103 projTag = projectID;
00104 }
00105
00106
00107
00108
00109 int
00110 OracleDatastore::searchProjTag(char* projName)
00111 {
00112 int projTag = queryTagOnName(projName);
00113
00114 return projTag;
00115 }
00116
00117
00118
00119
00120
00121 char *
00122 OracleDatastore::addToProgram(void)
00123 {
00124 return 0;
00125 }
00126
00127 int
00128 OracleDatastore::setUpShadow(void)
00129 {
00130 return 0;
00131 }
00132
00133 int
00134 OracleDatastore::setUpActor(void)
00135 {
00136 return 0;
00137 }
00138
00139 int
00140 OracleDatastore::setNextAddress(const ChannelAddress &otherChannelAddress)
00141 {
00142 return 0;
00143 }
00144
00145
00146 ChannelAddress *
00147 OracleDatastore::getLastSendersAddress(void)
00148 {
00149 return 0;
00150 }
00151
00152
00153
00154
00155
00156
00157 int
00158 OracleDatastore::commitState(int commitTag)
00159 {
00160 int result = FE_Datastore::commitState(commitTag);
00161
00162 return result;
00163 }
00164
00165 int
00166 OracleDatastore::sendObj(int commitTag,
00167 MovableObject &theObject,
00168 ChannelAddress *theAddress)
00169 {
00170 return theObject.sendSelf(commitTag, *this);
00171 }
00172
00173 int
00174 OracleDatastore::recvObj(int commitTag,
00175 MovableObject &theObject,
00176 FEM_ObjectBroker &theNewBroker,
00177 ChannelAddress *theAddress)
00178 {
00179 return theObject.recvSelf(commitTag, *this, theNewBroker);
00180 }
00181
00182
00183 int
00184 OracleDatastore::sendMsg(int dataTag, int commitTag,
00185 const Message &,
00186 ChannelAddress *theAddress)
00187 {
00188 opserr << "OracleDatastore::sendMsg() - not yet implemented\n";
00189 return -1;
00190 }
00191
00192 int
00193 OracleDatastore::recvMsg(int dataTag, int commitTag,
00194 Message &,
00195 ChannelAddress *theAddress)
00196 {
00197 opserr << "OracleDatastore::recvMsg() - not yet implemented\n";
00198 return -1;
00199 }
00200
00201
00202 int
00203 OracleDatastore::sendMatrix(int dataTag, int commitTag,
00204 const Matrix &theMatrix,
00205 ChannelAddress *theAddress)
00206 {
00207 int numRows = theMatrix.noRows();
00208 int numCols = theMatrix.noCols();
00209 int matrixSize = numRows * numCols;
00210 int pt;
00211
00212 int *tempProjTag = new int[matrixSize];
00213 int *tempDataTag = new int[matrixSize];
00214 int *tempCommitTag = new int[matrixSize];
00215 int *row = new int[matrixSize];
00216 int *col = new int[matrixSize];
00217 double *tempMatrix = new double[matrixSize];
00218
00219 for (int i = 0; i < numRows; i++) {
00220 for (int j = 0; j < numCols; j++) {
00221 pt = i *numCols + j;
00222 tempProjTag[pt] = projTag;
00223 tempDataTag[pt] = dataTag;
00224 tempCommitTag[pt] = commitTag;
00225 row[pt] = i;
00226 col[pt] = j;
00227 tempMatrix[pt] = theMatrix(i, j);
00228 }
00229 }
00230
00231 insertMatrixTable(matrixSize, tempProjTag, tempDataTag, tempCommitTag, row, col, tempMatrix);
00232
00233 delete [] tempDataTag;
00234 delete [] tempCommitTag;
00235 delete [] row;
00236 delete [] col;
00237 delete [] tempMatrix;
00238
00239 return 0;
00240 }
00241
00242
00243 int
00244 OracleDatastore::recvMatrix(int dataTag, int commitTag,
00245 Matrix &theMatrix,
00246 ChannelAddress *theAddress)
00247 {
00248 int numRows = theMatrix.noRows();
00249 int numCols = theMatrix.noCols();
00250 int matrixSize = numRows * numCols;
00251
00252 double *tempMatrix = new double[matrixSize];
00253
00254 queryMatrixTable(numRows, numCols, projTag, dataTag, commitTag, tempMatrix);
00255
00256 for (int i = 0; i < numRows; i++) {
00257 for (int j = 0; j < numCols; j++) {
00258 theMatrix(i, j) = tempMatrix[i*numCols + j];
00259 }
00260 }
00261
00262 delete [] tempMatrix;
00263
00264 return 0;
00265 }
00266
00267
00268 int
00269 OracleDatastore::sendVector(int dataTag, int commitTag,
00270 const Vector &theVector,
00271 ChannelAddress *theAddress)
00272 {
00273 int vectSize = theVector.Size();
00274 int *tempProjTag = new int[vectSize];
00275 int *tempDataTag = new int[vectSize];
00276 int *tempCommitTag = new int[vectSize];
00277 int *tempPos = new int[vectSize];
00278 double *tempVect = new double[vectSize];
00279
00280 for (int i=0; i<vectSize; i++) {
00281 tempProjTag[i] = projTag;
00282 tempDataTag[i] = dataTag;
00283 tempCommitTag[i] = commitTag;
00284 tempPos[i] = i;
00285 tempVect[i] = theVector(i);
00286 }
00287
00288 insertVectorTable(vectSize, tempProjTag, tempDataTag, tempCommitTag, tempPos, tempVect);
00289
00290 delete [] tempProjTag;
00291 delete [] tempDataTag;
00292 delete [] tempCommitTag;
00293 delete [] tempPos;
00294 delete [] tempVect;
00295
00296 return 0;
00297 }
00298
00299 int
00300 OracleDatastore::recvVector(int dataTag, int commitTag,
00301 Vector &theVector,
00302 ChannelAddress *theAddress)
00303 {
00304 int vectSize = theVector.Size();
00305 double *tempVect = new double[vectSize];
00306
00307 queryVectorTable(vectSize, projTag, dataTag, commitTag, tempVect);
00308
00309 for (int i=0; i<vectSize; i++) {
00310 theVector(i) = tempVect[i];
00311 }
00312
00313 delete [] tempVect;
00314
00315 return 0;
00316 }
00317
00318
00319
00320 int
00321 OracleDatastore::sendID(int dataTag, int commitTag,
00322 const ID &theID,
00323 ChannelAddress *theAddress)
00324 {
00325 int idSize = theID.Size();
00326 int *tempProjTag = new int[idSize];
00327 int *tempDataTag = new int[idSize];
00328 int *tempCommitTag = new int[idSize];
00329 int *tempPos = new int[idSize];
00330 int *tempID = new int[idSize];
00331
00332 for (int i=0; i<idSize; i++) {
00333 tempProjTag[i] = projTag;
00334 tempDataTag[i] = dataTag;
00335 tempCommitTag[i] = commitTag;
00336 tempPos[i] = i;
00337 tempID[i] = theID(i);
00338 }
00339
00340 insertIDTable(idSize, tempProjTag, tempDataTag, tempCommitTag, tempPos, tempID);
00341
00342 delete [] tempDataTag;
00343 delete [] tempCommitTag;
00344 delete [] tempPos;
00345 delete [] tempID;
00346
00347 return 0;
00348 }
00349
00350
00351 int
00352 OracleDatastore::recvID(int dataTag, int commitTag,
00353 ID &theID,
00354 ChannelAddress *theAddress)
00355 {
00356 int idSize = theID.Size();
00357 int *tempID = new int[idSize];
00358
00359 queryIDTable(idSize, projTag, dataTag, commitTag, tempID);
00360
00361 for (int i=0; i<idSize; i++) {
00362 theID(i) = tempID[i];
00363 }
00364
00365 delete [] tempID;
00366 return 0;
00367 }
00368