Tang Cheng | 31b9525 | 2014-10-23 09:22:35 +0800 | [diff] [blame^] | 1 | /* Copyright (c) 2000, 2007, Oracle. All rights reserved. */ |
| 2 | |
| 3 | /* |
| 4 | NAME |
| 5 | occiObjects.h - header file for OCCI object classes |
| 6 | |
| 7 | DESCRIPTION |
| 8 | Class definitions for Ref, RefAny, AnyData |
| 9 | |
| 10 | RELATED DOCUMENTS |
| 11 | <note any documents related to this facility> |
| 12 | |
| 13 | EXPORT FUNCTION(S) |
| 14 | <external functions declared for use outside package - one-line |
| 15 | descriptions> |
| 16 | |
| 17 | INTERNAL FUNCTION(S) |
| 18 | <other external functions declared - one-line descriptions> |
| 19 | |
| 20 | EXAMPLES |
| 21 | |
| 22 | NOTES |
| 23 | <other useful comments, qualifications, etc.> |
| 24 | |
| 25 | |
| 26 | */ |
| 27 | |
| 28 | #ifndef _olint /* disable olint check */ |
| 29 | |
| 30 | #ifndef OCCIOBJECTS_ORACLE |
| 31 | # define OCCIOBJECTS_ORACLE |
| 32 | |
| 33 | #ifndef OCCICOMMON_ORACLE |
| 34 | #include <occiCommon.h> |
| 35 | #endif |
| 36 | |
| 37 | namespace oracle { |
| 38 | namespace occi { |
| 39 | struct AnyDataCtx { |
| 40 | ConnectionImpl *occiSession; |
| 41 | OCIAnyData *anyData; |
| 42 | void *objHeader; |
| 43 | ub4 errNum; |
| 44 | }; |
| 45 | typedef struct AnyDataCtx AnyDataCtx; |
| 46 | |
| 47 | class PObject |
| 48 | { |
| 49 | public: |
| 50 | enum LockOption {OCCI_LOCK_WAIT, OCCI_LOCK_NOWAIT}; |
| 51 | enum UnpinOption {OCCI_PINCOUNT_DECR, OCCI_PINCOUNT_RESET}; |
| 52 | static void destroy(void *); |
| 53 | static void refresh(void *); |
| 54 | PObject(); |
| 55 | PObject(const void *ctx); |
| 56 | PObject(const PObject& obj); |
| 57 | virtual ~PObject(); |
| 58 | PObject& operator=(const PObject& obj); |
| 59 | void *operator new(size_t size); |
| 60 | void *operator new(size_t size, const Connection *x, |
| 61 | const OCCI_STD_NAMESPACE::string& tablename, |
| 62 | const char *typeName); |
| 63 | void *operator new(size_t size, const Connection *sess, |
| 64 | const OCCI_STD_NAMESPACE::string& tablename, |
| 65 | const OCCI_STD_NAMESPACE::string& typName , |
| 66 | const OCCI_STD_NAMESPACE::string& schTabName="", |
| 67 | const OCCI_STD_NAMESPACE::string& schTypName = ""); |
| 68 | void *operator new(size_t size, const Connection *sess, |
| 69 | const UString& tablename, const UString &typName, |
| 70 | const UString& schTabName, const UString& schTypName); |
| 71 | void *operator new(size_t size, void *adctx); |
| 72 | void operator delete(void *obj, size_t size); |
| 73 | RefAny getRef() const; |
| 74 | bool isLocked() const; |
| 75 | void unpin(UnpinOption mode=OCCI_PINCOUNT_DECR); |
| 76 | void pin(); |
| 77 | void lock(PObject::LockOption lock_option); |
| 78 | void unmark(); |
| 79 | void flush(); |
| 80 | void markDelete(); |
| 81 | void markModified(); |
| 82 | bool isNull() const; |
| 83 | void setNull(); |
| 84 | const Connection *getConnection() const; |
| 85 | virtual OCCI_STD_NAMESPACE::string getSQLTypeName() const = 0; |
| 86 | virtual void getSQLTypeName(Environment *env, void **schName, |
| 87 | unsigned int &schNameLen, void **typeName, |
| 88 | unsigned int &typeNameLen) const = 0; |
| 89 | void getSQLTypeName(Environment *env, void *(*rSQL)(void *), |
| 90 | void **schname, unsigned int &schnamelen, |
| 91 | void **typname, unsigned int &typnamelen) const; |
| 92 | virtual void writeSQL(AnyData& stream) = 0; |
| 93 | virtual void readSQL(AnyData& stream) = 0; |
| 94 | private: |
| 95 | static void initialise( void * obj, const Connection * sess, |
| 96 | void *schTabName, unsigned int schTabLen, |
| 97 | void *tableName, unsigned int tabLen, |
| 98 | void *schTypName, unsigned int schTypLen, |
| 99 | void *typeName, unsigned int typLen); |
| 100 | |
| 101 | ConnectionImpl *occiSession_; |
| 102 | void *objHeader_; |
| 103 | ub2 customNewed_; |
| 104 | enum {CUSTOM_NEWED = 0x5cde}; |
| 105 | ub2 flags_; |
| 106 | enum {NULL_INFO = 0x0001, GARBAGE_COLLECTED = 0x0002, |
| 107 | REFRESH_OBJECT = 0x0004, |
| 108 | CACHED_OBJECT = 0xBAF8}; |
| 109 | //check PObject implementation for CACHED_OBJECT flag |
| 110 | // for future use |
| 111 | void *pobjectExt; |
| 112 | friend class RefImpl; |
| 113 | }; |
| 114 | |
| 115 | class AnyData |
| 116 | { |
| 117 | public: |
| 118 | ~AnyData(); |
| 119 | AnyData(void *any) ; |
| 120 | AnyData(const Connection *sessp); |
| 121 | AnyData(const Connection *sessp, OCIAnyData *any, bool freeImg = true) ; |
| 122 | |
| 123 | AnyData(const AnyData &src); |
| 124 | AnyData& operator = (const AnyData &src); |
| 125 | |
| 126 | OCIAnyData* getOCIAnyData() const; |
| 127 | const Connection* getConnection() const; |
| 128 | |
| 129 | |
| 130 | bool isNull() const ; |
| 131 | void setNull() ; |
| 132 | OCCI_STD_NAMESPACE::string getString() const ; |
| 133 | UString getUString() const ; |
| 134 | Blob getBlob() const ; |
| 135 | Clob getClob() const ; |
| 136 | Bfile getBfile() const ; |
| 137 | BFloat getBFloat() const ; |
| 138 | BDouble getBDouble() const ; |
| 139 | Number getNumber() const ; |
| 140 | Bytes getBytes() const ; |
| 141 | Date getDate() const ; |
| 142 | Timestamp getTimestamp() const ; |
| 143 | IntervalYM getIntervalYM() const ; |
| 144 | IntervalDS getIntervalDS() const ; |
| 145 | PObject *getObject(void *(*rSQL)(void *)) const ; |
| 146 | RefAny getRef() const ; |
| 147 | |
| 148 | void setString(const OCCI_STD_NAMESPACE::string &str) ; |
| 149 | void setUString(const UString &str) ; |
| 150 | void setBlob(const Blob &blob) ; |
| 151 | void setClob(const Clob &clob) ; |
| 152 | void setBfile(const Bfile &bfile) ; |
| 153 | void setBFloat(const BFloat &n) ; |
| 154 | void setBDouble(const BDouble &n) ; |
| 155 | void setNumber(const Number &n) ; |
| 156 | void setBytes(const Bytes &bytes) ; |
| 157 | void setDate(const Date &date) ; |
| 158 | void setTimestamp(const Timestamp ×tamp) ; |
| 159 | void setIntervalYM(const IntervalYM &intervalym) ; |
| 160 | void setIntervalDS(const IntervalDS &intervalds) ; |
| 161 | void setObject(const PObject *objptr) ; |
| 162 | void setRef(const RefAny &ref) ; |
| 163 | |
| 164 | void setFromString(const OCCI_STD_NAMESPACE::string &str) ; |
| 165 | void setFromBfile(const Bfile &bfile) ; |
| 166 | void setFromBFloat(const BFloat &n) ; |
| 167 | void setFromBDouble(const BDouble &n) ; |
| 168 | void setFromNumber(const Number &n) ; |
| 169 | void setFromBytes(const Bytes &bytes) ; |
| 170 | void setFromDate(const Date &date) ; |
| 171 | void setFromTimestamp(const Timestamp ×tamp) ; |
| 172 | void setFromIntervalYM(const IntervalYM &intervalym) ; |
| 173 | void setFromIntervalDS(const IntervalDS &intervalds) ; |
| 174 | void setFromObject(const PObject *objptr) ; |
| 175 | void setFromRef(const RefAny &ref, |
| 176 | const OCCI_STD_NAMESPACE::string &typname, |
| 177 | const OCCI_STD_NAMESPACE::string &schname) ; |
| 178 | |
| 179 | OCCI_STD_NAMESPACE::string getAsString() const ; |
| 180 | Bfile getAsBfile() const ; |
| 181 | BFloat getAsBFloat() const ; |
| 182 | BDouble getAsBDouble() const ; |
| 183 | Number getAsNumber() const ; |
| 184 | Bytes getAsBytes() const ; |
| 185 | Date getAsDate() const ; |
| 186 | Timestamp getAsTimestamp() const ; |
| 187 | IntervalYM getAsIntervalYM() const ; |
| 188 | IntervalDS getAsIntervalDS() const ; |
| 189 | PObject *getAsObject() const ; |
| 190 | RefAny getAsRef() const ; |
| 191 | |
| 192 | TypeCode getType() const; |
| 193 | |
| 194 | private: |
| 195 | |
| 196 | |
| 197 | // private data members |
| 198 | Ptr<AnyDataImpl> anyDataImplPtr; |
| 199 | |
| 200 | |
| 201 | }; |
| 202 | |
| 203 | template <class T> |
| 204 | class Ref |
| 205 | { |
| 206 | public: |
| 207 | |
| 208 | Ref(); |
| 209 | Ref(const T *obj) ; |
| 210 | Ref(const RefAny &refAny) ; |
| 211 | Ref(const Ref<T> &src) ; |
| 212 | Ref(const Connection *sessp, OCIRef *tref, bool copy=TRUE) |
| 213 | ; |
| 214 | ~Ref(); |
| 215 | Ref<T>& operator=(const Ref<T> &src) |
| 216 | ; |
| 217 | Ref<T>& operator=(const T *obj) ; |
| 218 | Ref<T>& operator=(const RefAny &src); |
| 219 | T * operator->() ; |
| 220 | T * ptr() ; |
| 221 | T & operator *() ; |
| 222 | const T * operator->() const; |
| 223 | const T * ptr() const; |
| 224 | const T & operator *() const ; |
| 225 | void markDelete() ; |
| 226 | void unmarkDelete() ; |
| 227 | void setNull(); |
| 228 | bool isNull() const; |
| 229 | void clear() ; |
| 230 | bool isClear() const; |
| 231 | void setPrefetch(const OCCI_STD_NAMESPACE::string &typeName, |
| 232 | unsigned int depth); |
| 233 | void setPrefetch(const OCCI_STD_NAMESPACE::string &schName, |
| 234 | const OCCI_STD_NAMESPACE::string &typeName, |
| 235 | unsigned int depth); |
| 236 | void setPrefetch(const UString &schName, |
| 237 | const UString &typeName, |
| 238 | unsigned int depth); |
| 239 | void setPrefetch(unsigned int depth) ; |
| 240 | void setLock(LockOptions ); |
| 241 | operator RefAny() const; |
| 242 | OCIRef *getRef() const; |
| 243 | const Connection *getConnection() const; |
| 244 | bool operator == (const Ref<T> &ref) const; |
| 245 | bool operator != (const Ref<T> &ref) const; |
| 246 | bool operator == (const RefAny &refAnyR) const ; |
| 247 | bool operator != (const RefAny &refAnyR) const ; |
| 248 | OCIComplexObject *getCor() const; |
| 249 | void setPinnedObject(PObject *objPtr); |
| 250 | private: |
| 251 | |
| 252 | RefImpl *rimplPtr; |
| 253 | }; |
| 254 | |
| 255 | |
| 256 | class RefImpl |
| 257 | { |
| 258 | public: |
| 259 | |
| 260 | RefImpl(); |
| 261 | RefImpl(PObject *obj) ; |
| 262 | RefImpl(const RefAny &refAny) ; |
| 263 | RefImpl(const RefImpl &src) ; |
| 264 | RefImpl(const Connection *sessp, OCIRef *tref, |
| 265 | bool copy=TRUE) ; |
| 266 | ~RefImpl(); |
| 267 | bool isNull() const ; |
| 268 | void setNull() ; |
| 269 | void markDelete() ; |
| 270 | void unmarkDelete() ; |
| 271 | void clear() ; |
| 272 | bool isClear() const ; |
| 273 | void setPrefetch(const OCCI_STD_NAMESPACE::string &typeName, |
| 274 | unsigned int depth) ; |
| 275 | void setPrefetch(const OCCI_STD_NAMESPACE::string &schName, |
| 276 | const OCCI_STD_NAMESPACE::string &typeName, |
| 277 | unsigned int depth); |
| 278 | void setPrefetch(const UString &schName, |
| 279 | const UString &typeName, |
| 280 | unsigned int depth); |
| 281 | void setPrefetch(unsigned int depth) ; |
| 282 | void setLock(LockOptions lckOption) ; |
| 283 | PObject *pin() ; |
| 284 | void unpin(PObject *obj) ; |
| 285 | void setRefFromObjPtr(const PObject *obj) ; |
| 286 | OCIRef* getRef() const; |
| 287 | void setRefImpl(RefImpl *rptr); |
| 288 | const Connection * getConnection() const; |
| 289 | bool operator == (const RefImpl &refI) const ; |
| 290 | bool operator == (const RefAny &refAnyR) const ; |
| 291 | void assignObj(PObject *newObjPtr) ; |
| 292 | void assignRefAny(const RefAny &src) ; |
| 293 | // added following methods |
| 294 | bool isEqual(PObject *obj); |
| 295 | void operator = ( const RefImpl &src); |
| 296 | OCIComplexObject *getCor() const; |
| 297 | void setPinnedObject( PObject *objPtr); |
| 298 | private: |
| 299 | |
| 300 | OCIRef *ref; |
| 301 | const ConnectionImpl *sessp; |
| 302 | OCIComplexObject *corhp; |
| 303 | OCCI_STD_NAMESPACE::list<void *> descriptorList; |
| 304 | LockOptions lockOption; |
| 305 | // added data member for object header |
| 306 | void *objHeader; |
| 307 | //common implementation function for setPrefetch |
| 308 | void do_setPrefetch(void *schName, unsigned int schNameLen, |
| 309 | void *typeName, unsigned int typeNameLen, |
| 310 | unsigned int depth); |
| 311 | }; |
| 312 | |
| 313 | |
| 314 | class RefAny |
| 315 | { |
| 316 | public: |
| 317 | |
| 318 | RefAny(); |
| 319 | RefAny (const Connection *sessptr, const OCIRef *ref); |
| 320 | RefAny (const Connection *sessptr, const OCIRef *ref, bool isowner); |
| 321 | ~RefAny() ; |
| 322 | RefAny(const RefAny& src) ; |
| 323 | RefAny& operator=(const RefAny& src) ; |
| 324 | void markDelete() ; |
| 325 | void unmarkDelete() ; |
| 326 | void clear() ; |
| 327 | bool isNull() const; |
| 328 | OCIRef * getRef() const; |
| 329 | const Connection * getConnection() const; |
| 330 | bool operator == (const RefAny &refAnyR) const; |
| 331 | bool operator != (const RefAny &refAnyR) const; |
| 332 | bool isOwner() const; |
| 333 | |
| 334 | private: |
| 335 | |
| 336 | OCIRef *ref; |
| 337 | const ConnectionImpl *sessp; |
| 338 | // for future use |
| 339 | void *refanyExt; |
| 340 | bool owner; |
| 341 | |
| 342 | friend RefAny MetaData::getRef(MetaData::AttrId) const; |
| 343 | friend RefAny PObject::getRef() const; |
| 344 | friend class AnyDataImpl; |
| 345 | friend class ResultSetImpl; |
| 346 | friend class StatementImpl; |
| 347 | friend void getVector(const ResultSet *rs, |
| 348 | unsigned int colIndex, |
| 349 | OCCI_STD_NAMESPACE::vector<RefAny> &vect) ; |
| 350 | friend void getVector(const Statement *stmt, |
| 351 | unsigned int colIndex, |
| 352 | OCCI_STD_NAMESPACE::vector<RefAny> &vect) ; |
| 353 | }; |
| 354 | |
| 355 | template <class T> |
| 356 | Ref<T>::Ref() |
| 357 | { |
| 358 | rimplPtr = new RefImpl(); |
| 359 | } |
| 360 | |
| 361 | template <class T> |
| 362 | Ref<T>::Ref(const T *obj) |
| 363 | { |
| 364 | rimplPtr = new RefImpl((PObject *)obj); |
| 365 | } |
| 366 | |
| 367 | template <class T> |
| 368 | Ref<T>::Ref(const RefAny &refAny) |
| 369 | |
| 370 | { |
| 371 | rimplPtr = new RefImpl(refAny); |
| 372 | } |
| 373 | |
| 374 | template <class T> |
| 375 | Ref<T>::Ref(const Ref<T>& src) |
| 376 | |
| 377 | { |
| 378 | rimplPtr = new RefImpl(*(src.rimplPtr)); |
| 379 | } |
| 380 | |
| 381 | template <class T> |
| 382 | Ref<T>::Ref(const Connection *sessp, OCIRef *tref, bool copy) |
| 383 | |
| 384 | { |
| 385 | rimplPtr = new RefImpl(sessp, tref, copy); |
| 386 | } |
| 387 | |
| 388 | template <class T> |
| 389 | Ref<T>::~Ref() |
| 390 | { |
| 391 | delete rimplPtr; |
| 392 | } |
| 393 | |
| 394 | |
| 395 | template <class T> |
| 396 | Ref<T>& Ref<T>::operator=(const Ref<T> &src) |
| 397 | { |
| 398 | if (&src == this) |
| 399 | return *this; |
| 400 | *rimplPtr = *(src.rimplPtr); |
| 401 | return *this; |
| 402 | } |
| 403 | |
| 404 | template <class T> |
| 405 | Ref<T>& Ref<T>::operator=(const T *obj) |
| 406 | { |
| 407 | if (rimplPtr->isEqual((PObject *)obj)) |
| 408 | return *this; |
| 409 | rimplPtr->assignObj((PObject *)obj); |
| 410 | return *this; |
| 411 | } |
| 412 | |
| 413 | template <class T> |
| 414 | Ref<T>& Ref<T>::operator=(const RefAny &src) |
| 415 | { |
| 416 | rimplPtr->assignRefAny(src); |
| 417 | return *this; |
| 418 | } |
| 419 | |
| 420 | template <class T> |
| 421 | T* Ref<T>::operator->() |
| 422 | { |
| 423 | return ((T *)rimplPtr->pin()); |
| 424 | } |
| 425 | |
| 426 | template <class T> |
| 427 | T* Ref<T>::ptr() |
| 428 | { |
| 429 | return ((T *)rimplPtr->pin()); |
| 430 | } |
| 431 | |
| 432 | template <class T> |
| 433 | T& Ref<T>::operator * () |
| 434 | { |
| 435 | return ((T &)(*(rimplPtr->pin()))); |
| 436 | } |
| 437 | |
| 438 | template <class T> |
| 439 | const T* Ref<T>::operator->() const |
| 440 | { |
| 441 | return ((const T *)rimplPtr->pin()); |
| 442 | } |
| 443 | |
| 444 | template <class T> |
| 445 | const T* Ref<T>::ptr() const |
| 446 | { |
| 447 | return ((const T *)rimplPtr->pin()); |
| 448 | } |
| 449 | |
| 450 | template <class T> |
| 451 | const T& Ref<T>::operator * () const |
| 452 | { |
| 453 | return ((const T &)(*(rimplPtr->pin()))); |
| 454 | } |
| 455 | |
| 456 | template <class T> |
| 457 | void Ref<T>::markDelete () |
| 458 | { |
| 459 | rimplPtr->markDelete(); |
| 460 | } |
| 461 | |
| 462 | template <class T> |
| 463 | void Ref<T>::unmarkDelete () |
| 464 | { |
| 465 | rimplPtr->unmarkDelete(); |
| 466 | } |
| 467 | |
| 468 | template <class T> |
| 469 | void Ref<T>::setNull() |
| 470 | { |
| 471 | rimplPtr->setNull(); |
| 472 | } |
| 473 | |
| 474 | template <class T> |
| 475 | bool Ref<T>::isNull() const |
| 476 | { |
| 477 | return rimplPtr->isNull(); |
| 478 | } |
| 479 | |
| 480 | template <class T> |
| 481 | void Ref<T>::clear () |
| 482 | { |
| 483 | rimplPtr->clear(); |
| 484 | } |
| 485 | |
| 486 | template <class T> |
| 487 | bool Ref<T>::isClear() const |
| 488 | { |
| 489 | return rimplPtr->isClear(); |
| 490 | } |
| 491 | |
| 492 | template <class T> |
| 493 | void Ref<T>::setPrefetch (const OCCI_STD_NAMESPACE::string &typeName, |
| 494 | unsigned int depth) |
| 495 | |
| 496 | { |
| 497 | rimplPtr->setPrefetch(typeName,depth); |
| 498 | } |
| 499 | |
| 500 | template <class T> |
| 501 | void Ref<T>::setPrefetch (const OCCI_STD_NAMESPACE::string &schemaName, |
| 502 | const OCCI_STD_NAMESPACE::string &typeName, |
| 503 | unsigned int depth) |
| 504 | |
| 505 | { |
| 506 | rimplPtr->setPrefetch(schemaName,typeName,depth); |
| 507 | } |
| 508 | |
| 509 | template <class T> |
| 510 | void Ref<T>::setPrefetch (const UString &schemaName, |
| 511 | const UString &typeName, |
| 512 | unsigned int depth) |
| 513 | |
| 514 | { |
| 515 | rimplPtr->setPrefetch(schemaName,typeName,depth); |
| 516 | } |
| 517 | |
| 518 | template <class T> |
| 519 | void Ref<T>::setPrefetch (unsigned int depth) |
| 520 | |
| 521 | { |
| 522 | rimplPtr->setPrefetch(depth); |
| 523 | } |
| 524 | |
| 525 | template <class T> |
| 526 | void Ref<T>::setLock (LockOptions lckOption) |
| 527 | { |
| 528 | rimplPtr->setLock(lckOption); |
| 529 | } |
| 530 | |
| 531 | template <class T> |
| 532 | OCIRef* Ref<T>::getRef() const |
| 533 | { |
| 534 | return (rimplPtr->getRef()); |
| 535 | } |
| 536 | |
| 537 | template<class T> |
| 538 | const Connection* Ref<T>::getConnection () const |
| 539 | { |
| 540 | return (rimplPtr->getConnection()); |
| 541 | } |
| 542 | |
| 543 | template <class T> |
| 544 | Ref<T>::operator RefAny () const |
| 545 | { |
| 546 | if (isNull()) |
| 547 | return RefAny(); |
| 548 | return (RefAny(rimplPtr->getConnection(), rimplPtr->getRef())); |
| 549 | } |
| 550 | |
| 551 | template <class T> |
| 552 | bool Ref<T>::operator ==(const Ref<T> &ref) const |
| 553 | |
| 554 | { |
| 555 | return ( (*rimplPtr) == (*(ref.rimplPtr)) ); |
| 556 | } |
| 557 | |
| 558 | template <class T> |
| 559 | bool Ref<T>::operator !=(const Ref<T> &ref) const |
| 560 | |
| 561 | { |
| 562 | return ( !((*rimplPtr) == (*(ref.rimplPtr))) ); |
| 563 | } |
| 564 | |
| 565 | template <class T> |
| 566 | bool Ref<T>::operator == (const RefAny & refAnyR) const |
| 567 | |
| 568 | { |
| 569 | return ( (*rimplPtr) == refAnyR ); |
| 570 | } |
| 571 | |
| 572 | template <class T> |
| 573 | bool Ref<T>::operator != (const RefAny & refAnyR) const |
| 574 | |
| 575 | { |
| 576 | return ( !((*rimplPtr) == refAnyR )); |
| 577 | } |
| 578 | |
| 579 | template <class T> |
| 580 | OCIComplexObject * Ref<T>::getCor() const |
| 581 | { |
| 582 | return (rimplPtr->getCor()); |
| 583 | } |
| 584 | |
| 585 | template < class T> |
| 586 | void Ref<T>::setPinnedObject( PObject *objPtr) |
| 587 | { |
| 588 | rimplPtr->setPinnedObject(objPtr); |
| 589 | } |
| 590 | |
| 591 | /*--------------------------------------------------------------------------- |
| 592 | PROTOTYPES USED BY FUNCTION TEMPLATES |
| 593 | ---------------------------------------------------------------------------*/ |
| 594 | void getVectorOfOCIRefs( const AnyData &any, |
| 595 | OCCI_STD_NAMESPACE::vector<void *> &vect); |
| 596 | void getVectorOfPObjects( const AnyData &any, |
| 597 | OCCI_STD_NAMESPACE::vector< PObject* > &vect, |
| 598 | void *(*rSQL)(void *)) ; |
| 599 | void setVectorOfOCIRefs( AnyData &any, |
| 600 | const OCCI_STD_NAMESPACE::vector<void *> &vect, |
| 601 | const OCCI_STD_NAMESPACE::vector< OCIInd> &vec_ind) ; |
| 602 | void setVectorOfPObjects( AnyData &any, |
| 603 | const OCCI_STD_NAMESPACE::vector< PObject* > &vect) ; |
| 604 | |
| 605 | /*--------------------------------------------------------------------------- |
| 606 | EXPORT FUNCTIONS |
| 607 | ---------------------------------------------------------------------------*/ |
| 608 | |
| 609 | /*------------------- getVector for POBject----------------------------*/ |
| 610 | /* |
| 611 | NAME |
| 612 | getVector - overloaded function. Retrieves the attribute in the |
| 613 | current position as a vector of PObject |
| 614 | |
| 615 | PARAMETERS |
| 616 | any - AnyData |
| 617 | vect- reference to vector of PObject (OUT parameter). |
| 618 | |
| 619 | DESCRIPTION |
| 620 | Retrieves the attribute in the current position as a vector |
| 621 | of PObject |
| 622 | The attribute at the current position should be a collection |
| 623 | type (varray or nested table). The SQL type of the elements in |
| 624 | the collection should be compatible with PObject |
| 625 | |
| 626 | RETURNS |
| 627 | nothing |
| 628 | |
| 629 | NOTES |
| 630 | compatible SQL types : user defined types (SQLT_NTY) etc. |
| 631 | */ |
| 632 | |
| 633 | #if defined(WIN32COMMON) || defined(__MVS__) |
| 634 | // and other platforms that do not support |
| 635 | // partial function template specialization |
| 636 | template <class T> |
| 637 | void getVector(const AnyData &any, OCCI_STD_NAMESPACE::vector<T> &vect, |
| 638 | void *(*rSQL)(void *)) |
| 639 | { |
| 640 | OCCI_STD_NAMESPACE::vector< PObject *> vec_pobj; |
| 641 | getVectorOfPObjects( any, vec_pobj, rSQL); |
| 642 | |
| 643 | vect.clear(); |
| 644 | unsigned int size= vec_pobj.size(); |
| 645 | vect.reserve( size ); |
| 646 | for( unsigned int i=0; i< size; i++) |
| 647 | vect.push_back( (T)vec_pobj[i] ); |
| 648 | } |
| 649 | #else |
| 650 | template <class T> |
| 651 | void getVector(const AnyData &any, OCCI_STD_NAMESPACE::vector<T*> &vect, |
| 652 | void *(*rSQL)(void *)) |
| 653 | { |
| 654 | OCCI_STD_NAMESPACE::vector< PObject *> vec_pobj; |
| 655 | getVectorOfPObjects( any, vec_pobj, rSQL); |
| 656 | |
| 657 | vect.clear(); |
| 658 | unsigned int size= vec_pobj.size(); |
| 659 | vect.reserve( size ); |
| 660 | for( unsigned int i=0; i< size; i++) |
| 661 | vect.push_back( (T*)vec_pobj[i] ); |
| 662 | } |
| 663 | #endif /* end of #ifdef WIN32COMMON */ |
| 664 | |
| 665 | /*------------------- getVector for Ref<T>----------------------------*/ |
| 666 | /* |
| 667 | NAME |
| 668 | getVector - overloaded function. Retrieves the attribute in the |
| 669 | current position as a vector of PObject |
| 670 | |
| 671 | PARAMETERS |
| 672 | any - AnyData |
| 673 | vect- reference to vector of PObject (OUT parameter). |
| 674 | |
| 675 | DESCRIPTION |
| 676 | Retrieves the attribute in the current position as a vector |
| 677 | of PObject |
| 678 | The attribute at the current position should be a collection |
| 679 | type (varray or nested table). The SQL type of the elements in |
| 680 | the collection should be compatible with PObject |
| 681 | |
| 682 | RETURNS |
| 683 | nothing |
| 684 | |
| 685 | NOTES |
| 686 | compatible SQL types : user defined types (SQLT_NTY) etc. |
| 687 | */ |
| 688 | #if !defined(WIN32COMMON) && !defined(__MVS__) |
| 689 | template <class T> |
| 690 | void getVector(const AnyData &any,OCCI_STD_NAMESPACE::vector< Ref<T> > &vect) |
| 691 | { |
| 692 | OCCI_STD_NAMESPACE::vector< void *> vec_ref; |
| 693 | getVectorOfOCIRefs( any, vec_ref); |
| 694 | |
| 695 | vect.clear(); |
| 696 | unsigned int size = vec_ref.size(); |
| 697 | vect.reserve( size ); |
| 698 | const Connection *sess = any.getConnection(); |
| 699 | |
| 700 | for (unsigned int i=0; i< size; i++) |
| 701 | { |
| 702 | if (vec_ref[i] == (OCIRef *)0) |
| 703 | vect.push_back(Ref<T>()); // pushing a default-constructed Ref |
| 704 | else |
| 705 | vect.push_back(Ref<T>(sess, (OCIRef *)vec_ref[i], FALSE)); |
| 706 | } |
| 707 | } |
| 708 | #endif /* end of #ifndef WIN32COMMON */ |
| 709 | |
| 710 | /*-----------------------setVector for PObject--------------------------*/ |
| 711 | /* |
| 712 | NAME |
| 713 | setVector - overloaded function. sets the attribute in the current |
| 714 | position of anydata with the vector elements. |
| 715 | |
| 716 | PARAMETERS |
| 717 | none. |
| 718 | |
| 719 | DESCRIPTION |
| 720 | sets the attribute in the current position in anydata with the |
| 721 | vector elements. |
| 722 | The attribute in the current position of anydata should be a |
| 723 | collection type. If the collection type is a varray, the input vector |
| 724 | size should be equal to the size of the varray. Also the SQL type of |
| 725 | the collection's elements should be compatible with PObject. |
| 726 | |
| 727 | RETURNS |
| 728 | nothing. |
| 729 | |
| 730 | NOTES |
| 731 | compatible SQL types : SQLT_NTY (user defined types). |
| 732 | */ |
| 733 | #if defined(WIN32COMMON) || defined(__MVS__) |
| 734 | // and other platforms that do not support |
| 735 | // partial function template specialization |
| 736 | |
| 737 | template <class T> |
| 738 | void setVector(AnyData &any, const OCCI_STD_NAMESPACE::vector<T> &vect) |
| 739 | { |
| 740 | OCCI_STD_NAMESPACE::vector< PObject *> vec_pobj; |
| 741 | unsigned int size= vect.size(); |
| 742 | vec_pobj.reserve( size ); |
| 743 | for( unsigned int i=0; i< size; i++) |
| 744 | vec_pobj.push_back( vect[i] ); |
| 745 | setVectorOfPObjects( any, vec_pobj); |
| 746 | |
| 747 | } |
| 748 | |
| 749 | #else |
| 750 | |
| 751 | template <class T> |
| 752 | void setVector(AnyData &any, const OCCI_STD_NAMESPACE::vector<T*> &vect) |
| 753 | { |
| 754 | OCCI_STD_NAMESPACE::vector< PObject *> vec_pobj; |
| 755 | unsigned int size= vect.size(); |
| 756 | vec_pobj.reserve( size ); |
| 757 | for( unsigned int i=0; i< size; i++) |
| 758 | vec_pobj.push_back( vect[i] ); |
| 759 | setVectorOfPObjects( any, vec_pobj); |
| 760 | |
| 761 | } |
| 762 | #endif /* end of #ifdef WIN32COMMON */ |
| 763 | |
| 764 | /*-----------------------setVector for Ref<T>--------------------------*/ |
| 765 | /* |
| 766 | NAME |
| 767 | setVector - overloaded function. sets the attribute in the current |
| 768 | position of anydata with the vector elements. |
| 769 | |
| 770 | PARAMETERS |
| 771 | none. |
| 772 | |
| 773 | DESCRIPTION |
| 774 | sets the attribute in the current position in anydata with the |
| 775 | vector elements. |
| 776 | The attribute in the current position of anydata should be a |
| 777 | collection type. If the collection type is a varray, the input vector |
| 778 | size should be equal to the size of the varray. Also the SQL type of |
| 779 | the collection's elements should be compatible with PObject. |
| 780 | |
| 781 | RETURNS |
| 782 | nothing. |
| 783 | |
| 784 | NOTES |
| 785 | compatible SQL types : SQLT_NTY (user defined types). |
| 786 | */ |
| 787 | #if !defined(WIN32COMMON) && !defined(__MVS__) |
| 788 | template <class T> |
| 789 | void setVector(AnyData &any, const OCCI_STD_NAMESPACE::vector< Ref<T> > &vect) |
| 790 | { |
| 791 | OCCI_STD_NAMESPACE::vector< void *> vec_ref; |
| 792 | OCCI_STD_NAMESPACE::vector<OCIInd> vec_ind; |
| 793 | |
| 794 | unsigned int size= vect.size(); |
| 795 | vec_ref.reserve( size ); |
| 796 | vec_ind.reserve( size ); |
| 797 | for( unsigned int i=0; i< size; i++) |
| 798 | { |
| 799 | vec_ref.push_back( vect[i].getRef() ); |
| 800 | vec_ind.push_back(vect[i].isNull() ? OCI_IND_NULL : OCI_IND_NOTNULL); |
| 801 | } |
| 802 | setVectorOfOCIRefs( any, vec_ref, vec_ind); |
| 803 | |
| 804 | } |
| 805 | #endif /* end of #ifndef WIN32COMMON */ |
| 806 | |
| 807 | // Platform independent get/setVectorOfRefs method added |
| 808 | // get(set)Vector of Ref<T> and get(set)VectorOfRefs are identical |
| 809 | // in functionality. |
| 810 | |
| 811 | /*------------------- getVectorOfRefs for Ref<T>----------------------------*/ |
| 812 | /* |
| 813 | NAME |
| 814 | getVectorOfRefs - overloaded function. Retrieves the attribute in the |
| 815 | current position as a vector of PObject |
| 816 | |
| 817 | PARAMETERS |
| 818 | any - AnyData |
| 819 | vect- reference to vector of PObject (OUT parameter). |
| 820 | |
| 821 | DESCRIPTION |
| 822 | Retrieves the attribute in the current position as a vector |
| 823 | of PObject |
| 824 | The attribute at the current position should be a collection |
| 825 | type (varray or nested table). The SQL type of the elements in |
| 826 | the collection should be compatible with PObject |
| 827 | |
| 828 | RETURNS |
| 829 | nothing |
| 830 | |
| 831 | NOTES |
| 832 | compatible SQL types : user defined types (SQLT_NTY) etc. |
| 833 | */ |
| 834 | |
| 835 | template <class T> |
| 836 | void getVectorOfRefs(const AnyData &any, |
| 837 | OCCI_STD_NAMESPACE::vector< Ref<T> > &vect) |
| 838 | { |
| 839 | OCCI_STD_NAMESPACE::vector< void *> vec_ref; |
| 840 | getVectorOfOCIRefs( any, vec_ref); |
| 841 | |
| 842 | vect.clear(); |
| 843 | unsigned int size = vec_ref.size(); |
| 844 | vect.reserve( size ); |
| 845 | const Connection *sess = any.getConnection(); |
| 846 | |
| 847 | for (unsigned int i=0; i< size; i++) |
| 848 | { |
| 849 | if (vec_ref[i] == (OCIRef *)0) |
| 850 | vect.push_back(Ref<T>()); // pushing a default-constructed Ref |
| 851 | else |
| 852 | vect.push_back(Ref<T>(sess, (OCIRef *)vec_ref[i], FALSE)); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | /*-----------------------setVectorOfRefs for Ref<T>--------------------------*/ |
| 857 | /* |
| 858 | NAME |
| 859 | setVectorOfRefs - overloaded function. sets the attribute in the current |
| 860 | position of anydata with the vector elements. |
| 861 | |
| 862 | PARAMETERS |
| 863 | none. |
| 864 | |
| 865 | DESCRIPTION |
| 866 | sets the attribute in the current position in anydata with the |
| 867 | vector elements. |
| 868 | The attribute in the current position of anydata should be a |
| 869 | collection type. If the collection type is a varray, the input vector |
| 870 | size should be equal to the size of the varray. Also the SQL type of |
| 871 | the collection's elements should be compatible with PObject. |
| 872 | |
| 873 | RETURNS |
| 874 | nothing. |
| 875 | |
| 876 | NOTES |
| 877 | compatible SQL types : SQLT_NTY (user defined types). |
| 878 | */ |
| 879 | |
| 880 | template <class T> |
| 881 | void setVectorOfRefs(AnyData &any, |
| 882 | const OCCI_STD_NAMESPACE::vector< Ref<T> > &vect) |
| 883 | |
| 884 | { |
| 885 | OCCI_STD_NAMESPACE::vector< void *> vec_ref; |
| 886 | OCCI_STD_NAMESPACE::vector<OCIInd> vec_ind; |
| 887 | |
| 888 | unsigned int size= vect.size(); |
| 889 | vec_ref.reserve( size ); |
| 890 | vec_ind.reserve( size ); |
| 891 | for( unsigned int i=0; i< size; i++) |
| 892 | { |
| 893 | vec_ref.push_back( vect[i].getRef() ); |
| 894 | vec_ind.push_back(vect[i].isNull() ? OCI_IND_NULL : OCI_IND_NOTNULL); |
| 895 | } |
| 896 | setVectorOfOCIRefs( any, vec_ref, vec_ind); |
| 897 | |
| 898 | } |
| 899 | |
| 900 | |
| 901 | /*--------------------------------------------------------------------------- |
| 902 | INTERNAL FUNCTIONS |
| 903 | ---------------------------------------------------------------------------*/ |
| 904 | |
| 905 | |
| 906 | } /* end of namespace occi */ |
| 907 | } /* end of namespace oracle */ |
| 908 | #endif /* OCCIOBJECTS_ORACLE */ |
| 909 | |
| 910 | #endif /* _olint */ |