Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

d_Database.h

Go to the documentation of this file.
00001 
00002 #ifndef d_Database_h
00003 #define d_Database_h 1
00004 //------------------------------------------------------------------------------
00005 
00006 #include "cTypes.h"
00007 #include "oStorage.h"
00008 #include "d_Project.h"
00009 
00010 //------------------------------------------------------------------------------
00011 class _ODLL oObjectManager;
00012 class _ODLL d_String;
00013 class _ODLL d_Ref_Any;
00014 class _ODLL oClass;
00015 
00016 //------------------------------------------------------------------------------
00017 // DEFAULT VALUES
00018 #define dDataStart      5104 // (5Kb - 16bytes of fix segment size)
00019 #define dDataStep       5120
00020 #define dRefStart       1008 // (1Kb - 16bytes of fix segment size)
00021 #define dRefStep        1024
00022 
00023 /**
00024  * Represents a logical database.
00025  *
00026  * A logical database is a container of objects of different classes. A
00027  * database is contained in a project (d_Project class). Classes inside a
00028  * database can refer objects in the same database or into the databases of the
00029  * same Project (federated databases).
00030  *
00031  * MULTI-THREADS:
00032  * d_Database class is not thread-safe, thus multiple threads cannot share the
00033  * same istance of d_Database. Instead define one d_Database object per
00034  * threads. Orient ODBMS will optimize multiple connections to the same database
00035  * with just one.
00036  *
00037  * DATABASE DEFINITION AND CREATION:
00038  * To create a database, see Schema Definition in Orient Main Guide document.
00039  *
00040  * LOCATION:
00041  * d_Database.h
00042  *
00043  * USAGE:
00044  * d_Database   <variable-name>;
00045  *
00046  * WHERE:
00047  * <variable-name>:     is the name of d_Database object
00048  * 
00049  * EXAMPLES:
00050  * d_Database   db;                      * Database object
00051  * db.open( "business" );                * Open the database
00052  * 
00053  * SEE ALSO:
00054  * d_Project
00055  *
00056  * ODMG:
00057  * Compliant 
00058  */
00059 
00060 class _ODLL d_Database 
00061 {
00062   public:
00063 
00064     typedef oUInt1 orDatabase;
00065 
00066     /**
00067      * Default Constructor.
00068      *
00069      * ODMG    :        Compliant 
00070      */
00071     d_Database ();
00072 
00073     /**
00074      * Destructor.
00075      *
00076      * ODMG    :        Compliant 
00077      */
00078     ~d_Database();
00079 
00080     /**
00081      * Opens the database.
00082      *
00083      * Opens the database <iName> with read_write access.
00084      * If a database is already opened throws a d_Error_DatabaseOpen
00085      * exception.
00086      *
00087      * SEE ALSO:  create(), close()
00088      * ODMG    :        Compliant 
00089      */
00090     void open (const char* iName);
00091 
00092     /**
00093      * Creates a new database.
00094      *
00095      * Creates the database <iName> in the project <iProject>.
00096      * If a database already exists, throws a d_Error_DatabaseNotCreated
00097      * exception.
00098      *
00099      * SEE ALSO:  open(), close()
00100      * ODMG    :        Extension
00101      */
00102     void create( d_Project& iProject, const char* iName, const char* iUrl,
00103                  orDsk iDataStart = dDataStart, orDsk iDataStep = dDataStep,
00104                  orDsk iRefStart = dRefStart, orDsk iRefStep = dRefStep );
00105 
00106     /**
00107      * Closes the database open.
00108      *
00109      * Any attempt to access a closed database throws d_ErrorDatabaseClosed
00110      * exception.
00111      *
00112      * SEE ALSO:  open(), create()
00113      * ODMG    :        Compliant
00114      */
00115     void close ();
00116 
00117     /**
00118      * Assign a name to a persistent object.
00119      *
00120      * Estabilishes an association between the <iObj> object and <iName> name
00121      * in the database dictionary. If it's already present an entry with the
00122      * same name throws d_Error_NameNotUnique exception. It's possible to
00123      * associate to an object more names. To remove all entries of an object,
00124      * just call this method passing 0 as second argoument.
00125      * 
00126      * SEE ALSO:  d_Dictionary::bind()
00127      * ODMG    :  Compliant 
00128      */
00129     void set_object_name (const d_Ref_Any &iObj, const char* iName);
00130 
00131     /**
00132      * Rename a named object.
00133      *
00134      * Renames an entry in the database dictionary from <iOldName> to
00135      * <iNewName>. To remove the entry of an object, just call this method
00136      * passing 0 as second argoument.
00137      *
00138      * SEE ALSO:  d_Dictionary::bind()
00139      * ODMG    :  Compliant 
00140      */
00141     void rename_object (const char* iOldName, const char* iNewName);
00142 
00143     /**
00144      * Return the named object searched.
00145      *
00146      * Search into the database dictionary the object associated with <iName>
00147      * name. If founds, returns a reference to found object, otherwise a null
00148      * reference.
00149      *
00150      * SEE ALSO:  d_Dictionary::lookup()
00151      * ODMG    :  Compliant 
00152      */
00153     d_Ref_Any lookup_object (const char* iName);
00154 
00155     /**
00156      * Set the retry values for database open when the database is locked by
00157      * another application.
00158      *
00159      * <iTimes> are the times that Orient will try to open the database, while
00160      * <iDelay> is the time between a test and another.
00161      *
00162      * SEE ALSO:  d_Database::open()
00163      * ODMG    :  Extension
00164      */
00165     void set_retry( int iTimes = 30, int iDelay = 100 );
00166 
00167     /**
00168      * Returns the name of database.
00169      *
00170      * If the database is not yet open or created, then a empty string is
00171      * returned ("").
00172      *
00173      * ODMG    :  Extension
00174      */
00175     d_String getName() const;
00176 
00177     /**
00178      * Returns the url of database.
00179      *
00180      * If the database is not yet open or created, then a empty string is
00181      * returned ("").
00182      *
00183      * ODMG    :  Extension
00184      */
00185     d_String getUrl() const;
00186 
00187     /**
00188      * Returns the schema object (oSysDatabase) of database. This permits to
00189      * inspect the database schema and to change it at run-time.
00190      *
00191      * ODMG    :  Extension
00192      */
00193     d_Ref<oSysDatabase> getSchema() const;
00194 
00195     /**
00196      * Returns true if the database is open, otherwise false.
00197      *
00198      * ODMG    :  Extension
00199      */
00200     bool isOpen() const;
00201 
00202     /**
00203      * Returns the domain of database.
00204      *
00205      * If the database is not yet open or created, then 0 is returned.
00206      *
00207      * ODMG    :  Extension
00208      */
00209     oDomain* getDomain() const;
00210 
00211     // Internal.
00212     d_Object* newObject (const char* iClassName);
00213 
00214     // Internal.
00215     oStorage* getStorage() const;
00216 
00217   private:
00218     // Internal.
00219     oStorage*             storage;
00220 
00221     // Internal.
00222     int retryMax;
00223     int retryDelay;
00224 
00225   // FRIENDSHIPS
00226   friend class oObjectManager;
00227 };
00228 //------------------------------------------------------------------------------
00229 inline oStorage* d_Database::getStorage () const
00230 {
00231   return storage;
00232 }
00233 //------------------------------------------------------------------------------
00234 inline bool d_Database::isOpen() const
00235 {
00236   return storage ? true : false;
00237 }
00238 //------------------------------------------------------------------------------
00239 //------------------------------------------------------------------------------
00240 
00241 #endif
00242 

Generated on Fri Nov 29 17:12:13 2002 for Orient ODBMS Just Edition v. 2.0e by doxygen1.3-rc1