alternative to assert
[gtkD.git] / gtkD / srcgda / gda / Client.d
blobb8a9547e2bfff4fdb90344c31dc01c3f53aa8de5
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = libgda-GdaClient.html
26 * outPack = gda
27 * outFile = Client
28 * strct = GdaClient
29 * realStrct=
30 * ctorStrct=
31 * clss = Client
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gda_client_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * - gda_client_open_connection
44 * imports:
45 * - gda.Connection
46 * structWrap:
47 * - GdaConnection* -> Connection
48 * module aliases:
49 * local aliases:
52 module gda.Client;
54 version(noAssert)
56 version(Tango)
58 import tango.io.Stdout; // use the tango loging?
62 private import gdac.gdatypes;
64 private import gdac.gda;
67 private import gda.Connection;
72 /**
73 * Description
74 * This class is the main entry point for libgda client applications. It provides
75 * the way by which client applications open connections. Thus, before using any other
76 * database-oriented function in libgda, applications must create a GdaClient object
77 * (via gda_client_new), and, once created, open the connections from it.
78 * GdaClient also provides a way to treat several connections as if they were only
79 * one (a connection pool), which allows applications to, for instance, commit/rollback
80 * a transaction in all the connections being managed by a unique GdaClient object, or
81 * obtain the list of all tables in all opened connections.
83 public class Client
86 /** the main Gtk struct */
87 protected GdaClient* gdaClient;
90 public GdaClient* getClientStruct()
92 return gdaClient;
96 /** the main Gtk struct as a void* */
97 protected void* getStruct()
99 return cast(void*)gdaClient;
103 * Sets our main struct and passes it to the parent class
105 public this (GdaClient* gdaClient)
107 version(noAssert)
109 if ( gdaClient is null )
111 int zero = 0;
112 version(Tango)
114 Stdout("struct gdaClient is null on constructor").newline;
116 else
118 printf("struct gdaClient is null on constructor");
120 zero = zero / zero;
123 else
125 assert(gdaClient !is null, "struct gdaClient is null on constructor");
127 this.gdaClient = gdaClient;
131 * Establishes a connection to a data source. The connection will be opened
132 * if no identical connection is available in the GdaClient connection pool,
133 * and re-used if available. If you dont want to share the connection,
134 * specify GDA_CONNECTION_OPTIONS_DONT_SHARE as one of the flags in
135 * the options parameter.
136 * This function is the way of opening database connections with libgda.
137 * client :
138 * a GdaClient object.
139 * dsn :
140 * data source name.
141 * username :
142 * user name.
143 * password :
144 * password for username.
145 * options :
146 * options for the connection (see GdaConnectionOptions).
147 * Returns :
148 * the opened connection if successful, NULL if there is
149 * an error.
151 public Connection openConnection(char[] dsn, char[] username, char[] password, GdaConnectionOptions options)
153 // GdaConnection* gda_client_open_connection (GdaClient *client, const gchar *dsn, const gchar *username, const gchar *password, GdaConnectionOptions options);
154 GdaConnection* connection = gda_client_open_connection(gdaClient, Str.toStringz(dsn), Str.toStringz(username), Str.toStringz(password), options);
155 return connection ? new Connection( connection) : null;
164 * Creates a new GdaClient object, which is the entry point for libgda
165 * client applications. This object, once created, can be used for
166 * opening new database connections and activating other services
167 * available to GDA clients.
168 * Returns :
169 * the newly created object.
171 public this ()
173 // GdaClient* gda_client_new (void);
174 this(cast(GdaClient*)gda_client_new() );
179 * Opens a connection given a provider ID and a connection string. This
180 * allows applications to open connections without having to create
181 * a data source in the configuration. The format of cnc_string is
182 * similar to PostgreSQL and MySQL connection strings. It is a ;-separated
183 * series of key=value pairs. Do not add extra whitespace after the ;
184 * separator. The possible keys depend on the provider, but
185 * these keys should work with all providers:
186 * USER, PASSWORD, HOST, DATABASE, PORT
187 * client :
188 * a GdaClient object.
189 * provider_id :
190 * provider ID to connect to.
191 * cnc_string :
192 * connection string.
193 * options :
194 * options for the connection (see GdaConnectionOptions).
195 * Returns :
196 * the opened connection if successful, NULL if there is
197 * an error.
199 public Connection openConnectionFromString(char[] providerId, char[] cncString, GdaConnectionOptions options)
201 // GdaConnection* gda_client_open_connection_from_string (GdaClient *client, const gchar *provider_id, const gchar *cnc_string, GdaConnectionOptions options);
202 return new Connection( gda_client_open_connection_from_string(gdaClient, Str.toStringz(providerId), Str.toStringz(cncString), options) );
206 * Gets the list of all open connections in the given GdaClient object.
207 * The GList returned is an internal pointer, so DON'T TRY TO
208 * FREE IT.
209 * client :
210 * a GdaClient object.
211 * Returns :
212 * a GList of GdaConnection objects.
214 public GList* getConnectionList()
216 // const GList* gda_client_get_connection_list (GdaClient *client);
217 return gda_client_get_connection_list(gdaClient);
221 * Looks for an open connection given a data source name (per libgda
222 * configuration), a username and a password.
223 * This function iterates over the list of open connections in the
224 * given GdaClient and looks for one that matches the given data source
225 * name, username and password.
226 * client :
227 * a GdaClient object.
228 * dsn :
229 * data source name.
230 * username :
231 * user name.
232 * password :
233 * password for username.
234 * Returns :
235 * a pointer to the found connection, or NULL if it could not
236 * be found.
238 public Connection findConnection(char[] dsn, char[] username, char[] password)
240 // GdaConnection* gda_client_find_connection (GdaClient *client, const gchar *dsn, const gchar *username, const gchar *password);
241 return new Connection( gda_client_find_connection(gdaClient, Str.toStringz(dsn), Str.toStringz(username), Str.toStringz(password)) );
245 * Closes all connections opened by the given GdaClient object.
246 * client :
247 * a GdaClient object.
249 public void closeAllConnections()
251 // void gda_client_close_all_connections (GdaClient *client);
252 gda_client_close_all_connections(gdaClient);
256 * Notifies an event to the given GdaClient's listeners. The event can be
257 * anything (see GdaClientEvent) ranging from a connection opening
258 * operation, to changes made to a table in an underlying database.
259 * client :
260 * a GdaClient object.
261 * cnc :
262 * a GdaConnection object where the event has occurred.
263 * event :
264 * event ID.
265 * params :
266 * parameters associated with the event.
268 public void notifyEvent(Connection cnc, GdaClientEvent event, GdaParameterList* params)
270 // void gda_client_notify_event (GdaClient *client, GdaConnection *cnc, GdaClientEvent event, GdaParameterList *params);
271 gda_client_notify_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), event, params);
275 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_ERROR event.
276 * client :
277 * a GdaClient object.
278 * cnc :
279 * a GdaConnection object.
280 * error :
281 * the error to be notified.
283 public void notifyErrorEvent(Connection cnc, GdaError* error)
285 // void gda_client_notify_error_event (GdaClient *client, GdaConnection *cnc, GdaError *error);
286 gda_client_notify_error_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), error);
290 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_CONNECTION_OPENED
291 * event.
292 * client :
293 * a GdaClient object.
294 * cnc :
295 * a GdaConnection object.
297 public void notifyConnectionOpenedEvent(Connection cnc)
299 // void gda_client_notify_connection_opened_event (GdaClient *client, GdaConnection *cnc);
300 gda_client_notify_connection_opened_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct());
304 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_CONNECTION_CLOSED
305 * event.
306 * client :
307 * a GdaClient object.
308 * cnc :
309 * a GdaConnection object.
311 public void notifyConnectionClosedEvent(Connection cnc)
313 // void gda_client_notify_connection_closed_event (GdaClient *client, GdaConnection *cnc);
314 gda_client_notify_connection_closed_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct());
318 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_TRANSACTION_STARTED
319 * event.
320 * client :
321 * a GdaClient object.
322 * cnc :
323 * a GdaConnection object.
324 * xaction :
325 * a GdaTransaction object.
327 public void notifyTransactionStartedEvent(Connection cnc, GdaTransaction* xaction)
329 // void gda_client_notify_transaction_started_event (GdaClient *client, GdaConnection *cnc, GdaTransaction *xaction);
330 gda_client_notify_transaction_started_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), xaction);
334 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_TRANSACTION_COMMITTED
335 * event.
336 * client :
337 * a GdaClient object.
338 * cnc :
339 * a GdaConnection object.
340 * xaction :
341 * a GdaTransaction object.
343 public void notifyTransactionCommittedEvent(Connection cnc, GdaTransaction* xaction)
345 // void gda_client_notify_transaction_committed_event (GdaClient *client, GdaConnection *cnc, GdaTransaction *xaction);
346 gda_client_notify_transaction_committed_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), xaction);
350 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_TRANSACTION_CANCELLED
351 * event.
352 * client :
353 * a GdaClient object.
354 * cnc :
355 * a GdaConnection object.
356 * xaction :
357 * a GdaTransaction object.
359 public void notifyTransactionCancelledEvent(Connection cnc, GdaTransaction* xaction)
361 // void gda_client_notify_transaction_cancelled_event (GdaClient *client, GdaConnection *cnc, GdaTransaction *xaction);
362 gda_client_notify_transaction_cancelled_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), xaction);
366 * Starts a transaction on all connections being managed by the given
367 * GdaClient. It is important to note that this operates on all
368 * connections opened within a GdaClient, which could not be what
369 * you're looking for.
370 * To execute a transaction on a unique connection, use
371 * gda_connection_begin_transaction, gda_connection_commit_transaction
372 * and gda_connection_rollback_transaction.
373 * client :
374 * a GdaClient object.
375 * xaction :
376 * a GdaTransaction object.
377 * Returns :
378 * TRUE if all transactions could be started successfully,
379 * or FALSE if one of them fails.
381 public int beginTransaction(GdaTransaction* xaction)
383 // gboolean gda_client_begin_transaction (GdaClient *client, GdaTransaction *xaction);
384 return gda_client_begin_transaction(gdaClient, xaction);
388 * Commits a running transaction on all connections being managed by the given
389 * GdaClient. It is important to note that this operates on all
390 * connections opened within a GdaClient, which could not be what
391 * you're looking for.
392 * To execute a transaction on a unique connection, use
393 * gda_connection_begin_transaction, gda_connection_commit_transaction
394 * and gda_connection_rollback_transaction.
395 * client :
396 * a GdaClient object.
397 * xaction :
398 * a GdaTransaction object.
399 * Returns :
400 * TRUE if all transactions could be committed successfully,
401 * or FALSE if one of them fails.
403 public int commitTransaction(GdaTransaction* xaction)
405 // gboolean gda_client_commit_transaction (GdaClient *client, GdaTransaction *xaction);
406 return gda_client_commit_transaction(gdaClient, xaction);
410 * Cancels a running transaction on all connections being managed by the given
411 * GdaClient. It is important to note that this operates on all
412 * connections opened within a GdaClient, which could not be what
413 * you're looking for.
414 * To execute a transaction on a unique connection, use
415 * gda_connection_begin_transaction, gda_connection_commit_transaction
416 * and gda_connection_rollback_transaction.
417 * client :
418 * a GdaClient object.
419 * xaction :
420 * a GdaTransaction object.
421 * Returns :
422 * TRUE if all transactions could be cancelled successfully,
423 * or FALSE if one of them fails.
424 * See Also
425 * GdaConnection.
427 public int rollbackTransaction(GdaTransaction* xaction)
429 // gboolean gda_client_rollback_transaction (GdaClient *client, GdaTransaction *xaction);
430 return gda_client_rollback_transaction(gdaClient, xaction);