4 Copyright (C) 1996 Free Software Foundation, Inc.
6 Author: Mircea Oancea <mircea@jupiter.elcom.pub.ro>
9 This file is part of the GNUstep Database Library.
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Library General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Library General Public License for more details.
21 You should have received a copy of the GNU Library General Public
22 License along with this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #ifndef __EODatabaseContext_h__
28 #define __EODatabaseContext_h__
30 #import <Foundation/NSObject.h>
31 #import <GDLAccess/EODatabase.h>
33 @class NSArray, NSMutableArray, NSDictionary, NSMutableDictionary;
34 @class NSString, NSMutableString;
35 @class EOAdaptorContext;
37 @class EOObjectUniquer, EODatabase, EODatabaseContext, EODatabaseChannel;
40 EOUpdateWithOptimisticLocking,
41 EOUpdateWithPessimisticLocking,
42 EOUpdateWithNoLocking,
46 struct _EOTransactionScope;
48 extern NSString *EODatabaseContextWillBeginTransactionName;
49 extern NSString *EODatabaseContextDidBeginTransactionName;
50 extern NSString *EODatabaseContextWillRollbackTransactionName;
51 extern NSString *EODatabaseContextDidRollbackTransactionName;
52 extern NSString *EODatabaseContextWillCommitTransactionName;
53 extern NSString *EODatabaseContextDidCommitTransactionName;
55 struct EODatabaseContextModificationQueue;
57 @interface EODatabaseContext : NSObject < EOObjectRegistry >
58 //EOCooperatingObjectStore < EOObjectRegistry >
60 EOAdaptorContext *adaptorContext;
62 NSMutableArray *channels;
63 EOUpdateStrategy updateStrategy;
65 id delegate; /* non-retained */
67 struct _EOTransactionScope *transactionStackTop;
68 int transactionNestingLevel;
70 // These fields should be in a bitfield but are ivars for debug purposes
71 BOOL isKeepingSnapshots;
72 BOOL isUniquingObjects;
74 /* modified objects */
75 struct EODatabaseContextModificationQueue *ops;
78 unsigned int txBeginCount;
79 unsigned int txCommitCount;
80 unsigned int txRollbackCount;
83 // Initializing instances
84 - (id)initWithDatabase:(EODatabase *)aDatabase;
88 - (void)setDelegate:(id)_delegate;
90 - (EODatabase *)database;
92 // Getting the adaptor context
93 - (EOAdaptorContext*)adaptorContext;
96 - (BOOL)hasBusyChannels;
97 - (BOOL)hasOpenChannels;
98 - (NSArray *)channels;
101 // Controlling transactions
102 - (BOOL)beginTransaction;
103 - (BOOL)commitTransaction;
104 - (BOOL)rollbackTransaction;
106 // Notifying of other transactions
107 - (void)transactionDidBegin;
108 - (void)transactionDidCommit;
109 - (void)transactionDidRollback;
111 // Nesting transactions
112 - (BOOL)canNestTransactions;
113 - (unsigned)transactionNestingLevel;
115 // Setting the update strategy
116 - (void)setUpdateStrategy:(EOUpdateStrategy)aStrategy;
117 - (EOUpdateStrategy)updateStrategy;
118 - (BOOL)keepsSnapshots;
122 - (void)recordLockedObject:(id)anObj;
123 - (BOOL)isObjectLocked:(id)anObj;
124 - (void)recordUpdatedObject:(id)anObj;
125 - (BOOL)isObjectUpdated:(id)anObj;
127 @end /* EODatabaseContext */
129 @interface EODatabaseContext(Statistics)
131 - (unsigned int)transactionBeginCount;
132 - (unsigned int)transactionCommitCount;
133 - (unsigned int)transactionRollbackCount;
138 * Methods used by database classess internally
141 @interface EODatabaseContext(Private)
142 - (void)channelDidInit:(id)aChannel;
143 - (void)channelWillDealloc:(id)aChannel;
144 - (void)privateBeginTransaction;
145 - (void)privateCommitTransaction;
146 - (void)privateRollbackTransaction;
151 @interface EODatabaseContext(NewInEOF2)
153 + (void)setContextClassToRegister:(Class)_cclass;
154 + (Class)contextClassToRegister;
157 + (EODatabaseContext *)registeredDatabaseContextForModel:(EOModel *)_model
158 editingContext:(id)_ec;
163 /* managing channels */
165 - (EODatabaseChannel *)availableChannel;
166 - (NSArray *)registeredChannels;
167 - (void)registerChannel:(EODatabaseChannel *)_channel;
168 - (void)unregisterChannel:(EODatabaseChannel *)_channel;
172 @class EOFetchSpecification;
174 @interface NSObject(EOF2DelegateMethods)
176 - (BOOL)databaseContext:(EODatabaseContext *)_ctx
177 shouldSelectObjectsWithFetchSpecification:(EOFetchSpecification *)_fspec
178 databaseChannel:(EODatabaseChannel *)_channel;
180 - (void)databaseContext:(EODatabaseContext *)_ctx
181 didSelectObjectsWithFetchSpecification:(EOFetchSpecification *)_fspec
182 databaseChannel:(EODatabaseChannel *)_channel;
184 - (BOOL)databaseContext:(EODatabaseContext *)_ctx
185 shouldUsePessimisticLockWithFetchSpecification:(EOFetchSpecification *)_fspec
186 databaseChannel:(EODatabaseChannel *)_channel;
190 #endif /* __EODatabaseContext_h__ */