/* Copyright (c) 2000, 2007, Oracle. All rights reserved. */ /* NAME occiObjects.h - header file for OCCI object classes DESCRIPTION Class definitions for Ref, RefAny, AnyData RELATED DOCUMENTS EXPORT FUNCTION(S) INTERNAL FUNCTION(S) EXAMPLES NOTES */ #ifndef _olint /* disable olint check */ #ifndef OCCIOBJECTS_ORACLE # define OCCIOBJECTS_ORACLE #ifndef OCCICOMMON_ORACLE #include #endif namespace oracle { namespace occi { struct AnyDataCtx { ConnectionImpl *occiSession; OCIAnyData *anyData; void *objHeader; ub4 errNum; }; typedef struct AnyDataCtx AnyDataCtx; class PObject { public: enum LockOption {OCCI_LOCK_WAIT, OCCI_LOCK_NOWAIT}; enum UnpinOption {OCCI_PINCOUNT_DECR, OCCI_PINCOUNT_RESET}; static void destroy(void *); static void refresh(void *); PObject(); PObject(const void *ctx); PObject(const PObject& obj); virtual ~PObject(); PObject& operator=(const PObject& obj); void *operator new(size_t size); void *operator new(size_t size, const Connection *x, const OCCI_STD_NAMESPACE::string& tablename, const char *typeName); void *operator new(size_t size, const Connection *sess, const OCCI_STD_NAMESPACE::string& tablename, const OCCI_STD_NAMESPACE::string& typName , const OCCI_STD_NAMESPACE::string& schTabName="", const OCCI_STD_NAMESPACE::string& schTypName = ""); void *operator new(size_t size, const Connection *sess, const UString& tablename, const UString &typName, const UString& schTabName, const UString& schTypName); void *operator new(size_t size, void *adctx); void operator delete(void *obj, size_t size); RefAny getRef() const; bool isLocked() const; void unpin(UnpinOption mode=OCCI_PINCOUNT_DECR); void pin(); void lock(PObject::LockOption lock_option); void unmark(); void flush(); void markDelete(); void markModified(); bool isNull() const; void setNull(); const Connection *getConnection() const; virtual OCCI_STD_NAMESPACE::string getSQLTypeName() const = 0; virtual void getSQLTypeName(Environment *env, void **schName, unsigned int &schNameLen, void **typeName, unsigned int &typeNameLen) const = 0; void getSQLTypeName(Environment *env, void *(*rSQL)(void *), void **schname, unsigned int &schnamelen, void **typname, unsigned int &typnamelen) const; virtual void writeSQL(AnyData& stream) = 0; virtual void readSQL(AnyData& stream) = 0; private: static void initialise( void * obj, const Connection * sess, void *schTabName, unsigned int schTabLen, void *tableName, unsigned int tabLen, void *schTypName, unsigned int schTypLen, void *typeName, unsigned int typLen); ConnectionImpl *occiSession_; void *objHeader_; ub2 customNewed_; enum {CUSTOM_NEWED = 0x5cde}; ub2 flags_; enum {NULL_INFO = 0x0001, GARBAGE_COLLECTED = 0x0002, REFRESH_OBJECT = 0x0004, CACHED_OBJECT = 0xBAF8}; //check PObject implementation for CACHED_OBJECT flag // for future use void *pobjectExt; friend class RefImpl; }; class AnyData { public: ~AnyData(); AnyData(void *any) ; AnyData(const Connection *sessp); AnyData(const Connection *sessp, OCIAnyData *any, bool freeImg = true) ; AnyData(const AnyData &src); AnyData& operator = (const AnyData &src); OCIAnyData* getOCIAnyData() const; const Connection* getConnection() const; bool isNull() const ; void setNull() ; OCCI_STD_NAMESPACE::string getString() const ; UString getUString() const ; Blob getBlob() const ; Clob getClob() const ; Bfile getBfile() const ; BFloat getBFloat() const ; BDouble getBDouble() const ; Number getNumber() const ; Bytes getBytes() const ; Date getDate() const ; Timestamp getTimestamp() const ; IntervalYM getIntervalYM() const ; IntervalDS getIntervalDS() const ; PObject *getObject(void *(*rSQL)(void *)) const ; RefAny getRef() const ; void setString(const OCCI_STD_NAMESPACE::string &str) ; void setUString(const UString &str) ; void setBlob(const Blob &blob) ; void setClob(const Clob &clob) ; void setBfile(const Bfile &bfile) ; void setBFloat(const BFloat &n) ; void setBDouble(const BDouble &n) ; void setNumber(const Number &n) ; void setBytes(const Bytes &bytes) ; void setDate(const Date &date) ; void setTimestamp(const Timestamp ×tamp) ; void setIntervalYM(const IntervalYM &intervalym) ; void setIntervalDS(const IntervalDS &intervalds) ; void setObject(const PObject *objptr) ; void setRef(const RefAny &ref) ; void setFromString(const OCCI_STD_NAMESPACE::string &str) ; void setFromBfile(const Bfile &bfile) ; void setFromBFloat(const BFloat &n) ; void setFromBDouble(const BDouble &n) ; void setFromNumber(const Number &n) ; void setFromBytes(const Bytes &bytes) ; void setFromDate(const Date &date) ; void setFromTimestamp(const Timestamp ×tamp) ; void setFromIntervalYM(const IntervalYM &intervalym) ; void setFromIntervalDS(const IntervalDS &intervalds) ; void setFromObject(const PObject *objptr) ; void setFromRef(const RefAny &ref, const OCCI_STD_NAMESPACE::string &typname, const OCCI_STD_NAMESPACE::string &schname) ; OCCI_STD_NAMESPACE::string getAsString() const ; Bfile getAsBfile() const ; BFloat getAsBFloat() const ; BDouble getAsBDouble() const ; Number getAsNumber() const ; Bytes getAsBytes() const ; Date getAsDate() const ; Timestamp getAsTimestamp() const ; IntervalYM getAsIntervalYM() const ; IntervalDS getAsIntervalDS() const ; PObject *getAsObject() const ; RefAny getAsRef() const ; TypeCode getType() const; private: // private data members Ptr anyDataImplPtr; }; template class Ref { public: Ref(); Ref(const T *obj) ; Ref(const RefAny &refAny) ; Ref(const Ref &src) ; Ref(const Connection *sessp, OCIRef *tref, bool copy=TRUE) ; ~Ref(); Ref& operator=(const Ref &src) ; Ref& operator=(const T *obj) ; Ref& operator=(const RefAny &src); T * operator->() ; T * ptr() ; T & operator *() ; const T * operator->() const; const T * ptr() const; const T & operator *() const ; void markDelete() ; void unmarkDelete() ; void setNull(); bool isNull() const; void clear() ; bool isClear() const; void setPrefetch(const OCCI_STD_NAMESPACE::string &typeName, unsigned int depth); void setPrefetch(const OCCI_STD_NAMESPACE::string &schName, const OCCI_STD_NAMESPACE::string &typeName, unsigned int depth); void setPrefetch(const UString &schName, const UString &typeName, unsigned int depth); void setPrefetch(unsigned int depth) ; void setLock(LockOptions ); operator RefAny() const; OCIRef *getRef() const; const Connection *getConnection() const; bool operator == (const Ref &ref) const; bool operator != (const Ref &ref) const; bool operator == (const RefAny &refAnyR) const ; bool operator != (const RefAny &refAnyR) const ; OCIComplexObject *getCor() const; void setPinnedObject(PObject *objPtr); private: RefImpl *rimplPtr; }; class RefImpl { public: RefImpl(); RefImpl(PObject *obj) ; RefImpl(const RefAny &refAny) ; RefImpl(const RefImpl &src) ; RefImpl(const Connection *sessp, OCIRef *tref, bool copy=TRUE) ; ~RefImpl(); bool isNull() const ; void setNull() ; void markDelete() ; void unmarkDelete() ; void clear() ; bool isClear() const ; void setPrefetch(const OCCI_STD_NAMESPACE::string &typeName, unsigned int depth) ; void setPrefetch(const OCCI_STD_NAMESPACE::string &schName, const OCCI_STD_NAMESPACE::string &typeName, unsigned int depth); void setPrefetch(const UString &schName, const UString &typeName, unsigned int depth); void setPrefetch(unsigned int depth) ; void setLock(LockOptions lckOption) ; PObject *pin() ; void unpin(PObject *obj) ; void setRefFromObjPtr(const PObject *obj) ; OCIRef* getRef() const; void setRefImpl(RefImpl *rptr); const Connection * getConnection() const; bool operator == (const RefImpl &refI) const ; bool operator == (const RefAny &refAnyR) const ; void assignObj(PObject *newObjPtr) ; void assignRefAny(const RefAny &src) ; // added following methods bool isEqual(PObject *obj); void operator = ( const RefImpl &src); OCIComplexObject *getCor() const; void setPinnedObject( PObject *objPtr); private: OCIRef *ref; const ConnectionImpl *sessp; OCIComplexObject *corhp; OCCI_STD_NAMESPACE::list descriptorList; LockOptions lockOption; // added data member for object header void *objHeader; //common implementation function for setPrefetch void do_setPrefetch(void *schName, unsigned int schNameLen, void *typeName, unsigned int typeNameLen, unsigned int depth); }; class RefAny { public: RefAny(); RefAny (const Connection *sessptr, const OCIRef *ref); RefAny (const Connection *sessptr, const OCIRef *ref, bool isowner); ~RefAny() ; RefAny(const RefAny& src) ; RefAny& operator=(const RefAny& src) ; void markDelete() ; void unmarkDelete() ; void clear() ; bool isNull() const; OCIRef * getRef() const; const Connection * getConnection() const; bool operator == (const RefAny &refAnyR) const; bool operator != (const RefAny &refAnyR) const; bool isOwner() const; private: OCIRef *ref; const ConnectionImpl *sessp; // for future use void *refanyExt; bool owner; friend RefAny MetaData::getRef(MetaData::AttrId) const; friend RefAny PObject::getRef() const; friend class AnyDataImpl; friend class ResultSetImpl; friend class StatementImpl; friend void getVector(const ResultSet *rs, unsigned int colIndex, OCCI_STD_NAMESPACE::vector &vect) ; friend void getVector(const Statement *stmt, unsigned int colIndex, OCCI_STD_NAMESPACE::vector &vect) ; }; template Ref::Ref() { rimplPtr = new RefImpl(); } template Ref::Ref(const T *obj) { rimplPtr = new RefImpl((PObject *)obj); } template Ref::Ref(const RefAny &refAny) { rimplPtr = new RefImpl(refAny); } template Ref::Ref(const Ref& src) { rimplPtr = new RefImpl(*(src.rimplPtr)); } template Ref::Ref(const Connection *sessp, OCIRef *tref, bool copy) { rimplPtr = new RefImpl(sessp, tref, copy); } template Ref::~Ref() { delete rimplPtr; } template Ref& Ref::operator=(const Ref &src) { if (&src == this) return *this; *rimplPtr = *(src.rimplPtr); return *this; } template Ref& Ref::operator=(const T *obj) { if (rimplPtr->isEqual((PObject *)obj)) return *this; rimplPtr->assignObj((PObject *)obj); return *this; } template Ref& Ref::operator=(const RefAny &src) { rimplPtr->assignRefAny(src); return *this; } template T* Ref::operator->() { return ((T *)rimplPtr->pin()); } template T* Ref::ptr() { return ((T *)rimplPtr->pin()); } template T& Ref::operator * () { return ((T &)(*(rimplPtr->pin()))); } template const T* Ref::operator->() const { return ((const T *)rimplPtr->pin()); } template const T* Ref::ptr() const { return ((const T *)rimplPtr->pin()); } template const T& Ref::operator * () const { return ((const T &)(*(rimplPtr->pin()))); } template void Ref::markDelete () { rimplPtr->markDelete(); } template void Ref::unmarkDelete () { rimplPtr->unmarkDelete(); } template void Ref::setNull() { rimplPtr->setNull(); } template bool Ref::isNull() const { return rimplPtr->isNull(); } template void Ref::clear () { rimplPtr->clear(); } template bool Ref::isClear() const { return rimplPtr->isClear(); } template void Ref::setPrefetch (const OCCI_STD_NAMESPACE::string &typeName, unsigned int depth) { rimplPtr->setPrefetch(typeName,depth); } template void Ref::setPrefetch (const OCCI_STD_NAMESPACE::string &schemaName, const OCCI_STD_NAMESPACE::string &typeName, unsigned int depth) { rimplPtr->setPrefetch(schemaName,typeName,depth); } template void Ref::setPrefetch (const UString &schemaName, const UString &typeName, unsigned int depth) { rimplPtr->setPrefetch(schemaName,typeName,depth); } template void Ref::setPrefetch (unsigned int depth) { rimplPtr->setPrefetch(depth); } template void Ref::setLock (LockOptions lckOption) { rimplPtr->setLock(lckOption); } template OCIRef* Ref::getRef() const { return (rimplPtr->getRef()); } template const Connection* Ref::getConnection () const { return (rimplPtr->getConnection()); } template Ref::operator RefAny () const { if (isNull()) return RefAny(); return (RefAny(rimplPtr->getConnection(), rimplPtr->getRef())); } template bool Ref::operator ==(const Ref &ref) const { return ( (*rimplPtr) == (*(ref.rimplPtr)) ); } template bool Ref::operator !=(const Ref &ref) const { return ( !((*rimplPtr) == (*(ref.rimplPtr))) ); } template bool Ref::operator == (const RefAny & refAnyR) const { return ( (*rimplPtr) == refAnyR ); } template bool Ref::operator != (const RefAny & refAnyR) const { return ( !((*rimplPtr) == refAnyR )); } template OCIComplexObject * Ref::getCor() const { return (rimplPtr->getCor()); } template < class T> void Ref::setPinnedObject( PObject *objPtr) { rimplPtr->setPinnedObject(objPtr); } /*--------------------------------------------------------------------------- PROTOTYPES USED BY FUNCTION TEMPLATES ---------------------------------------------------------------------------*/ void getVectorOfOCIRefs( const AnyData &any, OCCI_STD_NAMESPACE::vector &vect); void getVectorOfPObjects( const AnyData &any, OCCI_STD_NAMESPACE::vector< PObject* > &vect, void *(*rSQL)(void *)) ; void setVectorOfOCIRefs( AnyData &any, const OCCI_STD_NAMESPACE::vector &vect, const OCCI_STD_NAMESPACE::vector< OCIInd> &vec_ind) ; void setVectorOfPObjects( AnyData &any, const OCCI_STD_NAMESPACE::vector< PObject* > &vect) ; /*--------------------------------------------------------------------------- EXPORT FUNCTIONS ---------------------------------------------------------------------------*/ /*------------------- getVector for POBject----------------------------*/ /* NAME getVector - overloaded function. Retrieves the attribute in the current position as a vector of PObject PARAMETERS any - AnyData vect- reference to vector of PObject (OUT parameter). DESCRIPTION Retrieves the attribute in the current position as a vector of PObject The attribute at the current position should be a collection type (varray or nested table). The SQL type of the elements in the collection should be compatible with PObject RETURNS nothing NOTES compatible SQL types : user defined types (SQLT_NTY) etc. */ #if defined(WIN32COMMON) || defined(__MVS__) // and other platforms that do not support // partial function template specialization template void getVector(const AnyData &any, OCCI_STD_NAMESPACE::vector &vect, void *(*rSQL)(void *)) { OCCI_STD_NAMESPACE::vector< PObject *> vec_pobj; getVectorOfPObjects( any, vec_pobj, rSQL); vect.clear(); unsigned int size= vec_pobj.size(); vect.reserve( size ); for( unsigned int i=0; i< size; i++) vect.push_back( (T)vec_pobj[i] ); } #else template void getVector(const AnyData &any, OCCI_STD_NAMESPACE::vector &vect, void *(*rSQL)(void *)) { OCCI_STD_NAMESPACE::vector< PObject *> vec_pobj; getVectorOfPObjects( any, vec_pobj, rSQL); vect.clear(); unsigned int size= vec_pobj.size(); vect.reserve( size ); for( unsigned int i=0; i< size; i++) vect.push_back( (T*)vec_pobj[i] ); } #endif /* end of #ifdef WIN32COMMON */ /*------------------- getVector for Ref----------------------------*/ /* NAME getVector - overloaded function. Retrieves the attribute in the current position as a vector of PObject PARAMETERS any - AnyData vect- reference to vector of PObject (OUT parameter). DESCRIPTION Retrieves the attribute in the current position as a vector of PObject The attribute at the current position should be a collection type (varray or nested table). The SQL type of the elements in the collection should be compatible with PObject RETURNS nothing NOTES compatible SQL types : user defined types (SQLT_NTY) etc. */ #if !defined(WIN32COMMON) && !defined(__MVS__) template void getVector(const AnyData &any,OCCI_STD_NAMESPACE::vector< Ref > &vect) { OCCI_STD_NAMESPACE::vector< void *> vec_ref; getVectorOfOCIRefs( any, vec_ref); vect.clear(); unsigned int size = vec_ref.size(); vect.reserve( size ); const Connection *sess = any.getConnection(); for (unsigned int i=0; i< size; i++) { if (vec_ref[i] == (OCIRef *)0) vect.push_back(Ref()); // pushing a default-constructed Ref else vect.push_back(Ref(sess, (OCIRef *)vec_ref[i], FALSE)); } } #endif /* end of #ifndef WIN32COMMON */ /*-----------------------setVector for PObject--------------------------*/ /* NAME setVector - overloaded function. sets the attribute in the current position of anydata with the vector elements. PARAMETERS none. DESCRIPTION sets the attribute in the current position in anydata with the vector elements. The attribute in the current position of anydata should be a collection type. If the collection type is a varray, the input vector size should be equal to the size of the varray. Also the SQL type of the collection's elements should be compatible with PObject. RETURNS nothing. NOTES compatible SQL types : SQLT_NTY (user defined types). */ #if defined(WIN32COMMON) || defined(__MVS__) // and other platforms that do not support // partial function template specialization template void setVector(AnyData &any, const OCCI_STD_NAMESPACE::vector &vect) { OCCI_STD_NAMESPACE::vector< PObject *> vec_pobj; unsigned int size= vect.size(); vec_pobj.reserve( size ); for( unsigned int i=0; i< size; i++) vec_pobj.push_back( vect[i] ); setVectorOfPObjects( any, vec_pobj); } #else template void setVector(AnyData &any, const OCCI_STD_NAMESPACE::vector &vect) { OCCI_STD_NAMESPACE::vector< PObject *> vec_pobj; unsigned int size= vect.size(); vec_pobj.reserve( size ); for( unsigned int i=0; i< size; i++) vec_pobj.push_back( vect[i] ); setVectorOfPObjects( any, vec_pobj); } #endif /* end of #ifdef WIN32COMMON */ /*-----------------------setVector for Ref--------------------------*/ /* NAME setVector - overloaded function. sets the attribute in the current position of anydata with the vector elements. PARAMETERS none. DESCRIPTION sets the attribute in the current position in anydata with the vector elements. The attribute in the current position of anydata should be a collection type. If the collection type is a varray, the input vector size should be equal to the size of the varray. Also the SQL type of the collection's elements should be compatible with PObject. RETURNS nothing. NOTES compatible SQL types : SQLT_NTY (user defined types). */ #if !defined(WIN32COMMON) && !defined(__MVS__) template void setVector(AnyData &any, const OCCI_STD_NAMESPACE::vector< Ref > &vect) { OCCI_STD_NAMESPACE::vector< void *> vec_ref; OCCI_STD_NAMESPACE::vector vec_ind; unsigned int size= vect.size(); vec_ref.reserve( size ); vec_ind.reserve( size ); for( unsigned int i=0; i< size; i++) { vec_ref.push_back( vect[i].getRef() ); vec_ind.push_back(vect[i].isNull() ? OCI_IND_NULL : OCI_IND_NOTNULL); } setVectorOfOCIRefs( any, vec_ref, vec_ind); } #endif /* end of #ifndef WIN32COMMON */ // Platform independent get/setVectorOfRefs method added // get(set)Vector of Ref and get(set)VectorOfRefs are identical // in functionality. /*------------------- getVectorOfRefs for Ref----------------------------*/ /* NAME getVectorOfRefs - overloaded function. Retrieves the attribute in the current position as a vector of PObject PARAMETERS any - AnyData vect- reference to vector of PObject (OUT parameter). DESCRIPTION Retrieves the attribute in the current position as a vector of PObject The attribute at the current position should be a collection type (varray or nested table). The SQL type of the elements in the collection should be compatible with PObject RETURNS nothing NOTES compatible SQL types : user defined types (SQLT_NTY) etc. */ template void getVectorOfRefs(const AnyData &any, OCCI_STD_NAMESPACE::vector< Ref > &vect) { OCCI_STD_NAMESPACE::vector< void *> vec_ref; getVectorOfOCIRefs( any, vec_ref); vect.clear(); unsigned int size = vec_ref.size(); vect.reserve( size ); const Connection *sess = any.getConnection(); for (unsigned int i=0; i< size; i++) { if (vec_ref[i] == (OCIRef *)0) vect.push_back(Ref()); // pushing a default-constructed Ref else vect.push_back(Ref(sess, (OCIRef *)vec_ref[i], FALSE)); } } /*-----------------------setVectorOfRefs for Ref--------------------------*/ /* NAME setVectorOfRefs - overloaded function. sets the attribute in the current position of anydata with the vector elements. PARAMETERS none. DESCRIPTION sets the attribute in the current position in anydata with the vector elements. The attribute in the current position of anydata should be a collection type. If the collection type is a varray, the input vector size should be equal to the size of the varray. Also the SQL type of the collection's elements should be compatible with PObject. RETURNS nothing. NOTES compatible SQL types : SQLT_NTY (user defined types). */ template void setVectorOfRefs(AnyData &any, const OCCI_STD_NAMESPACE::vector< Ref > &vect) { OCCI_STD_NAMESPACE::vector< void *> vec_ref; OCCI_STD_NAMESPACE::vector vec_ind; unsigned int size= vect.size(); vec_ref.reserve( size ); vec_ind.reserve( size ); for( unsigned int i=0; i< size; i++) { vec_ref.push_back( vect[i].getRef() ); vec_ind.push_back(vect[i].isNull() ? OCI_IND_NULL : OCI_IND_NOTNULL); } setVectorOfOCIRefs( any, vec_ref, vec_ind); } /*--------------------------------------------------------------------------- INTERNAL FUNCTIONS ---------------------------------------------------------------------------*/ } /* end of namespace occi */ } /* end of namespace oracle */ #endif /* OCCIOBJECTS_ORACLE */ #endif /* _olint */