1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = libgda-GdaClient.html
27  * outPack = gda
28  * outFile = Client
29  * strct   = GdaClient
30  * realStrct=
31  * ctorStrct=
32  * clss    = Client
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = GObject
38  * implements:
39  * prefixes:
40  * 	- gda_client_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- gda_client_open_connection
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- glib.ListG
49  * 	- gda.Connection
50  * 	- gda.ErrorGda
51  * 	- gda.ParameterList
52  * 	- gda.Transaction
53  * structWrap:
54  * 	- GList* -> ListG
55  * 	- GdaConnection* -> Connection
56  * 	- GdaError* -> ErrorGda
57  * 	- GdaParameterList* -> ParameterList
58  * 	- GdaTransaction* -> Transaction
59  * module aliases:
60  * local aliases:
61  * overrides:
62  */
63 
64 module gda.Client;
65 
66 public  import gdac.gdatypes;
67 
68 private import gdac.gda;
69 private import glib.ConstructionException;
70 private import gobject.ObjectG;
71 
72 private import glib.Str;
73 private import glib.ListG;
74 private import gda.Connection;
75 private import gda.ErrorGda;
76 private import gda.ParameterList;
77 private import gda.Transaction;
78 
79 
80 private import gobject.ObjectG;
81 
82 /**
83  *  This class is the main entry point for libgda client applications. It provides
84  *  the way by which client applications open connections. Thus, before using any other
85  *  database-oriented function in libgda, applications must create a GdaClient object
86  *  (via gda_client_new), and, once created, open the connections from it.
87  *
88  *  GdaClient also provides a way to treat several connections as if they were only
89  *  one (a connection pool), which allows applications to, for instance, commit/rollback
90  *  a transaction in all the connections being managed by a unique GdaClient object, or
91  *  obtain the list of all tables in all opened connections.
92  */
93 public class Client : ObjectG
94 {
95 	
96 	/** the main Gtk struct */
97 	protected GdaClient* gdaClient;
98 	
99 	
100 	/** Get the main Gtk struct */
101 	public GdaClient* getClientStruct()
102 	{
103 		return gdaClient;
104 	}
105 	
106 	
107 	/** the main Gtk struct as a void* */
108 	protected override void* getStruct()
109 	{
110 		return cast(void*)gdaClient;
111 	}
112 	
113 	/**
114 	 * Sets our main struct and passes it to the parent class
115 	 */
116 	public this (GdaClient* gdaClient)
117 	{
118 		super(cast(GObject*)gdaClient);
119 		this.gdaClient = gdaClient;
120 	}
121 	
122 	protected override void setStruct(GObject* obj)
123 	{
124 		super.setStruct(obj);
125 		gdaClient = cast(GdaClient*)obj;
126 	}
127 	
128 	/**
129 	 * Establishes a connection to a data source. The connection will be opened
130 	 * if no identical connection is available in the GdaClient connection pool,
131 	 * and re-used if available. If you dont want to share the connection,
132 	 * specify GDA_CONNECTION_OPTIONS_DONT_SHARE as one of the flags in
133 	 * the options parameter.
134 	 * This function is the way of opening database connections with libgda.
135 	 * Params:
136 	 *  dsn = data source name.
137 	 *  username = user name.
138 	 *  password = password for username.
139 	 *  options = options for the connection (see GdaConnectionOptions).
140 	 * Returns :
141 	 *  the opened connection if successful, NULL if there is
142 	 *  an error.
143 	 */
144 	public Connection openConnection(string dsn, string username, string password, GdaConnectionOptions options)
145 	{
146 		// GdaConnection* gda_client_open_connection (GdaClient *client,  const gchar *dsn,  const gchar *username,  const gchar *password,  GdaConnectionOptions options);
147 		GdaConnection* connection = gda_client_open_connection(gdaClient, Str.toStringz(dsn), Str.toStringz(username), Str.toStringz(password), options);
148 		return connection ? new Connection( connection) : null;
149 	}
150 	
151 	/**
152 	 */
153 	
154 	/**
155 	 * Creates a new GdaClient object, which is the entry point for libgda
156 	 * client applications. This object, once created, can be used for
157 	 * opening new database connections and activating other services
158 	 * available to GDA clients.
159 	 * Throws: ConstructionException GTK+ fails to create the object.
160 	 */
161 	public this ()
162 	{
163 		// GdaClient* gda_client_new (void);
164 		auto p = gda_client_new();
165 		if(p is null)
166 		{
167 			throw new ConstructionException("null returned by gda_client_new()");
168 		}
169 		this(cast(GdaClient*) p);
170 	}
171 	
172 	/**
173 	 * Opens a connection given a provider ID and a connection string. This
174 	 * allows applications to open connections without having to create
175 	 * a data source in the configuration. The format of cnc_string is
176 	 * similar to PostgreSQL and MySQL connection strings. It is a ;-separated
177 	 * series of key=value pairs. Do not add extra whitespace after the ;
178 	 * separator. The possible keys depend on the provider, but
179 	 * Params:
180 	 * providerId = provider ID to connect to.
181 	 * cncString = connection string.
182 	 * options = options for the connection (see GdaConnectionOptions).
183 	 * Returns: the opened connection if successful, NULL if there is an error.
184 	 */
185 	public Connection openConnectionFromString(string providerId, string cncString, GdaConnectionOptions options)
186 	{
187 		// GdaConnection* gda_client_open_connection_from_string  (GdaClient *client,  const gchar *provider_id,  const gchar *cnc_string,  GdaConnectionOptions options);
188 		auto p = gda_client_open_connection_from_string(gdaClient, Str.toStringz(providerId), Str.toStringz(cncString), options);
189 		
190 		if(p is null)
191 		{
192 			return null;
193 		}
194 		
195 		return ObjectG.getDObject!(Connection)(cast(GdaConnection*) p);
196 	}
197 	
198 	/**
199 	 * Gets the list of all open connections in the given GdaClient object.
200 	 * The GList returned is an internal pointer, so DON'T TRY TO
201 	 * FREE IT.
202 	 * Returns: a GList of GdaConnection objects.
203 	 */
204 	public ListG getConnectionList()
205 	{
206 		// const GList* gda_client_get_connection_list (GdaClient *client);
207 		auto p = gda_client_get_connection_list(gdaClient);
208 		
209 		if(p is null)
210 		{
211 			return null;
212 		}
213 		
214 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
215 	}
216 	
217 	/**
218 	 * Looks for an open connection given a data source name (per libgda
219 	 * configuration), a username and a password.
220 	 * This function iterates over the list of open connections in the
221 	 * given GdaClient and looks for one that matches the given data source
222 	 * name, username and password.
223 	 * Params:
224 	 * dsn = data source name.
225 	 * username = user name.
226 	 * password = password for username.
227 	 * Returns: a pointer to the found connection, or NULL if it could not be found.
228 	 */
229 	public Connection findConnection(string dsn, string username, string password)
230 	{
231 		// GdaConnection* gda_client_find_connection (GdaClient *client,  const gchar *dsn,  const gchar *username,  const gchar *password);
232 		auto p = gda_client_find_connection(gdaClient, Str.toStringz(dsn), Str.toStringz(username), Str.toStringz(password));
233 		
234 		if(p is null)
235 		{
236 			return null;
237 		}
238 		
239 		return ObjectG.getDObject!(Connection)(cast(GdaConnection*) p);
240 	}
241 	
242 	/**
243 	 * Closes all connections opened by the given GdaClient object.
244 	 */
245 	public void closeAllConnections()
246 	{
247 		// void gda_client_close_all_connections (GdaClient *client);
248 		gda_client_close_all_connections(gdaClient);
249 	}
250 	
251 	/**
252 	 * Notifies an event to the given GdaClient's listeners. The event can be
253 	 * anything (see GdaClientEvent) ranging from a connection opening
254 	 * operation, to changes made to a table in an underlying database.
255 	 * Params:
256 	 * cnc = a GdaConnection object where the event has occurred.
257 	 * event = event ID.
258 	 * params = parameters associated with the event.
259 	 */
260 	public void notifyEvent(Connection cnc, GdaClientEvent event, ParameterList params)
261 	{
262 		// void gda_client_notify_event (GdaClient *client,  GdaConnection *cnc,  GdaClientEvent event,  GdaParameterList *params);
263 		gda_client_notify_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), event, (params is null) ? null : params.getParameterListStruct());
264 	}
265 	
266 	/**
267 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_ERROR event.
268 	 * Params:
269 	 * cnc = a GdaConnection object.
270 	 * error = the error to be notified.
271 	 */
272 	public void notifyErrorEvent(Connection cnc, ErrorGda error)
273 	{
274 		// void gda_client_notify_error_event (GdaClient *client,  GdaConnection *cnc,  GdaError *error);
275 		gda_client_notify_error_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), (error is null) ? null : error.getErrorGdaStruct());
276 	}
277 	
278 	/**
279 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_CONNECTION_OPENED
280 	 * event.
281 	 * Params:
282 	 * cnc = a GdaConnection object.
283 	 */
284 	public void notifyConnectionOpenedEvent(Connection cnc)
285 	{
286 		// void gda_client_notify_connection_opened_event  (GdaClient *client,  GdaConnection *cnc);
287 		gda_client_notify_connection_opened_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct());
288 	}
289 	
290 	/**
291 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_CONNECTION_CLOSED
292 	 * event.
293 	 * Params:
294 	 * cnc = a GdaConnection object.
295 	 */
296 	public void notifyConnectionClosedEvent(Connection cnc)
297 	{
298 		// void gda_client_notify_connection_closed_event  (GdaClient *client,  GdaConnection *cnc);
299 		gda_client_notify_connection_closed_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct());
300 	}
301 	
302 	/**
303 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_TRANSACTION_STARTED
304 	 * event.
305 	 * Params:
306 	 * cnc = a GdaConnection object.
307 	 * xaction = a GdaTransaction object.
308 	 */
309 	public void notifyTransactionStartedEvent(Connection cnc, Transaction xaction)
310 	{
311 		// void gda_client_notify_transaction_started_event  (GdaClient *client,  GdaConnection *cnc,  GdaTransaction *xaction);
312 		gda_client_notify_transaction_started_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), (xaction is null) ? null : xaction.getTransactionStruct());
313 	}
314 	
315 	/**
316 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_TRANSACTION_COMMITTED
317 	 * event.
318 	 * Params:
319 	 * cnc = a GdaConnection object.
320 	 * xaction = a GdaTransaction object.
321 	 */
322 	public void notifyTransactionCommittedEvent(Connection cnc, Transaction xaction)
323 	{
324 		// void gda_client_notify_transaction_committed_event  (GdaClient *client,  GdaConnection *cnc,  GdaTransaction *xaction);
325 		gda_client_notify_transaction_committed_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), (xaction is null) ? null : xaction.getTransactionStruct());
326 	}
327 	
328 	/**
329 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_TRANSACTION_CANCELLED
330 	 * event.
331 	 * Params:
332 	 * cnc = a GdaConnection object.
333 	 * xaction = a GdaTransaction object.
334 	 */
335 	public void notifyTransactionCancelledEvent(Connection cnc, Transaction xaction)
336 	{
337 		// void gda_client_notify_transaction_cancelled_event  (GdaClient *client,  GdaConnection *cnc,  GdaTransaction *xaction);
338 		gda_client_notify_transaction_cancelled_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), (xaction is null) ? null : xaction.getTransactionStruct());
339 	}
340 	
341 	/**
342 	 * Starts a transaction on all connections being managed by the given
343 	 * GdaClient. It is important to note that this operates on all
344 	 * connections opened within a GdaClient, which could not be what
345 	 * you're looking for.
346 	 * To execute a transaction on a unique connection, use
347 	 * gda_connection_begin_transaction, gda_connection_commit_transaction
348 	 * and gda_connection_rollback_transaction.
349 	 * Params:
350 	 * xaction = a GdaTransaction object.
351 	 * Returns: TRUE if all transactions could be started successfully, or FALSE if one of them fails.
352 	 */
353 	public int beginTransaction(Transaction xaction)
354 	{
355 		// gboolean gda_client_begin_transaction (GdaClient *client,  GdaTransaction *xaction);
356 		return gda_client_begin_transaction(gdaClient, (xaction is null) ? null : xaction.getTransactionStruct());
357 	}
358 	
359 	/**
360 	 * Commits a running transaction on all connections being managed by the given
361 	 * GdaClient. It is important to note that this operates on all
362 	 * connections opened within a GdaClient, which could not be what
363 	 * you're looking for.
364 	 * To execute a transaction on a unique connection, use
365 	 * gda_connection_begin_transaction, gda_connection_commit_transaction
366 	 * and gda_connection_rollback_transaction.
367 	 * Params:
368 	 * xaction = a GdaTransaction object.
369 	 * Returns: TRUE if all transactions could be committed successfully, or FALSE if one of them fails.
370 	 */
371 	public int commitTransaction(Transaction xaction)
372 	{
373 		// gboolean gda_client_commit_transaction (GdaClient *client,  GdaTransaction *xaction);
374 		return gda_client_commit_transaction(gdaClient, (xaction is null) ? null : xaction.getTransactionStruct());
375 	}
376 	
377 	/**
378 	 * Cancels a running transaction on all connections being managed by the given
379 	 * GdaClient. It is important to note that this operates on all
380 	 * connections opened within a GdaClient, which could not be what
381 	 * you're looking for.
382 	 * To execute a transaction on a unique connection, use
383 	 * gda_connection_begin_transaction, gda_connection_commit_transaction
384 	 * and gda_connection_rollback_transaction.
385 	 * Params:
386 	 * xaction = a GdaTransaction object.
387 	 * Returns: TRUE if all transactions could be cancelled successfully, or FALSE if one of them fails.
388 	 */
389 	public int rollbackTransaction(Transaction xaction)
390 	{
391 		// gboolean gda_client_rollback_transaction (GdaClient *client,  GdaTransaction *xaction);
392 		return gda_client_rollback_transaction(gdaClient, (xaction is null) ? null : xaction.getTransactionStruct());
393 	}
394 }