/[dgee]/dgee/dbstore/dbObject.h
ViewVC logotype

Diff of /dgee/dbstore/dbObject.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by csmith, Thu May 22 19:34:41 2003 UTC revision 1.2 by csmith, Sun Sep 21 10:48:16 2003 UTC
# Line 0  Line 1 
1    /*
2     * DotGNU Execution Environment Core
3     * (c)2003 netFluid Technology Ltd - http://www.nfluid.com
4     *
5     * Database Object Encapsulation
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20     *
21     * $Revision$  $Date$
22     *
23     * --------------------------------------------------------------------------
24     */
25    #ifndef DG_DBOBJ_H
26    #define DG_DBOBJ_H
27    
28    #include <stddef.h>
29    #include "dgDbError.h"
30    
31    typedef enum {
32            DBF_CHAR = 1,
33            DBF_INT  = 2,
34            DBF_LONG = 3,
35    } fieldType;
36    
37    typedef struct {
38      const char *property;
39      off_t       offset;
40      fieldType   type;
41      size_t      size;
42    } dbProperty;
43    
44    typedef struct {
45      int newobj;
46      int dirty;
47      int          delInd;      /* Set when object is effectively deleted */
48    
49      size_t       keyOffset;
50      size_t       keySize;
51      size_t       dataOffset;
52      size_t       dataSize;
53      size_t       objSize;
54      dbProperty  *keyProperties;
55      dbProperty  *dataProperties;
56      char        *tableName;
57      int          uniqueKey;
58      char       **dbh;
59    
60    } dbObjPrivate;
61    
62    struct _dbobj;
63    
64    typedef struct {
65      int (*Load)( struct _dbobj *this );
66      int (*Save)( struct _dbobj *this );
67      int (*Set)( struct _dbobj *this, char *p, char *d );
68      char * (*Get)( struct _dbobj *this, char *p );
69      int (*Delete)( struct _dbobj *this );
70      int (*Compare)( struct _dbobj *this, struct _dbobj *that );
71      int (*CompareKey)( struct _dbobj *this, struct _dbobj *that );
72      int (*CopyFrom)( struct _dbobj *this, struct _dbobj *that );
73    
74      void (*Destroy)( struct _dbobj **this ); /* Release an object */
75    
76      int (*connect)();
77    } dbObjMethods;
78    
79    typedef struct _dbobj {
80      dbObjMethods method;
81      dbObjPrivate private;
82    } dbObject;
83    
84    #define KEY_IS_UNIQUE     1
85    #define KEY_IS_NOT_UNIQUE 0
86    
87    /* This structure describes the object for dbengine.
88     * Info is pulled out of here and held in dbObjMehtods and dbObjPrivate
89     */
90    typedef struct {
91            size_t keySize;
92            size_t dataSize;
93            size_t objSize;
94            char   *tableName;
95            int      keyIsUnique;
96            char   **dbh;
97            dbProperty *keyProperties;
98            dbProperty *dataProperties;
99    } dbObjDesc;
100    
101    dbObject * db_newObject( dbObjDesc *def );
102    void db_destroy( dbObject **this_p );
103    int db_setProperty( dbObject *this, char *property, char *data );
104    void db_configure( char *dbroot );
105    
106    /* Helper methods */
107    #define setProperty(a,b,c) (a)->method.Set( (dbObject*)(a), b, c )
108    #define getProperty(a,b)   (a)->method.Get( (dbObject*)(a), b )
109    
110    #define loadObject(a) (a)->method.Load( (dbObject*)(a) )
111    #define saveObject(a) (a)->method.Save( (dbObject*)(a) )
112    #define deleteObject(a)  (a)->method.Delete( (dbObject*)(a) )
113    #define destroyObject(a) (a)->method.Destroy( (dbObject**)&(a) )
114    #define compareObjectKey(a,b) (a)->method.CompareKey( (dbObject*)(a), (dbObject*)(b) )
115    
116    /* ------------------------------------------------------------------------- */
117    #endif

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26