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 
73 private import glib.Str;
74 private import glib.ListG;
75 private import gda.Connection;
76 private import gda.ErrorGda;
77 private import gda.ParameterList;
78 private import gda.Transaction;
79 
80 
81 
82 private import gobject.ObjectG;
83 
84 /**
85  *  This class is the main entry point for libgda client applications. It provides
86  *  the way by which client applications open connections. Thus, before using any other
87  *  database-oriented function in libgda, applications must create a GdaClient object
88  *  (via gda_client_new), and, once created, open the connections from it.
89  *
90  *  GdaClient also provides a way to treat several connections as if they were only
91  *  one (a connection pool), which allows applications to, for instance, commit/rollback
92  *  a transaction in all the connections being managed by a unique GdaClient object, or
93  *  obtain the list of all tables in all opened connections.
94  */
95 public class Client : ObjectG
96 {
97 	
98 	/** the main Gtk struct */
99 	protected GdaClient* gdaClient;
100 	
101 	
102 	public GdaClient* getClientStruct()
103 	{
104 		return gdaClient;
105 	}
106 	
107 	
108 	/** the main Gtk struct as a void* */
109 	protected override void* getStruct()
110 	{
111 		return cast(void*)gdaClient;
112 	}
113 	
114 	/**
115 	 * Sets our main struct and passes it to the parent class
116 	 */
117 	public this (GdaClient* gdaClient)
118 	{
119 		super(cast(GObject*)gdaClient);
120 		this.gdaClient = gdaClient;
121 	}
122 	
123 	protected override void setStruct(GObject* obj)
124 	{
125 		super.setStruct(obj);
126 		gdaClient = cast(GdaClient*)obj;
127 	}
128 	
129 	/**
130 	 * Establishes a connection to a data source. The connection will be opened
131 	 * if no identical connection is available in the GdaClient connection pool,
132 	 * and re-used if available. If you dont want to share the connection,
133 	 * specify GDA_CONNECTION_OPTIONS_DONT_SHARE as one of the flags in
134 	 * the options parameter.
135 	 * This function is the way of opening database connections with libgda.
136 	 * Params:
137 	 *  dsn = data source name.
138 	 *  username = user name.
139 	 *  password = password for username.
140 	 *  options = options for the connection (see GdaConnectionOptions).
141 	 * Returns :
142 	 *  the opened connection if successful, NULL if there is
143 	 *  an error.
144 	 */
145 	public Connection openConnection(string dsn, string username, string password, GdaConnectionOptions options)
146 	{
147 		// GdaConnection* gda_client_open_connection (GdaClient *client,  const gchar *dsn,  const gchar *username,  const gchar *password,  GdaConnectionOptions options);
148 		GdaConnection* connection = gda_client_open_connection(gdaClient, Str.toStringz(dsn), Str.toStringz(username), Str.toStringz(password), options);
149 		return connection ? new Connection( connection) : null;
150 	}
151 	
152 	/**
153 	 */
154 	
155 	/**
156 	 * Creates a new GdaClient object, which is the entry point for libgda
157 	 * client applications. This object, once created, can be used for
158 	 * opening new database connections and activating other services
159 	 * available to GDA clients.
160 	 * Throws: ConstructionException GTK+ fails to create the object.
161 	 */
162 	public this ()
163 	{
164 		// GdaClient* gda_client_new (void);
165 		auto p = gda_client_new();
166 		if(p is null)
167 		{
168 			throw new ConstructionException("null returned by gda_client_new()");
169 		}
170 		this(cast(GdaClient*) p);
171 	}
172 	
173 	/**
174 	 * Opens a connection given a provider ID and a connection string. This
175 	 * allows applications to open connections without having to create
176 	 * a data source in the configuration. The format of cnc_string is
177 	 * similar to PostgreSQL and MySQL connection strings. It is a ;-separated
178 	 * series of key=value pairs. Do not add extra whitespace after the ;
179 	 * separator. The possible keys depend on the provider, but
180 	 * Params:
181 	 * providerId = provider ID to connect to.
182 	 * cncString = connection string.
183 	 * options = options for the connection (see GdaConnectionOptions).
184 	 * Returns: the opened connection if successful, NULL if there is an error.
185 	 */
186 	public Connection openConnectionFromString(string providerId, string cncString, GdaConnectionOptions options)
187 	{
188 		// GdaConnection* gda_client_open_connection_from_string  (GdaClient *client,  const gchar *provider_id,  const gchar *cnc_string,  GdaConnectionOptions options);
189 		auto p = gda_client_open_connection_from_string(gdaClient, Str.toStringz(providerId), Str.toStringz(cncString), options);
190 		
191 		if(p is null)
192 		{
193 			return null;
194 		}
195 		
196 		return ObjectG.getDObject!(Connection)(cast(GdaConnection*) p);
197 	}
198 	
199 	/**
200 	 * Gets the list of all open connections in the given GdaClient object.
201 	 * The GList returned is an internal pointer, so DON'T TRY TO
202 	 * FREE IT.
203 	 * Returns: a GList of GdaConnection objects.
204 	 */
205 	public ListG getConnectionList()
206 	{
207 		// const GList* gda_client_get_connection_list (GdaClient *client);
208 		auto p = gda_client_get_connection_list(gdaClient);
209 		
210 		if(p is null)
211 		{
212 			return null;
213 		}
214 		
215 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
216 	}
217 	
218 	/**
219 	 * Looks for an open connection given a data source name (per libgda
220 	 * configuration), a username and a password.
221 	 * This function iterates over the list of open connections in the
222 	 * given GdaClient and looks for one that matches the given data source
223 	 * name, username and password.
224 	 * Params:
225 	 * dsn = data source name.
226 	 * username = user name.
227 	 * password = password for username.
228 	 * Returns: a pointer to the found connection, or NULL if it could not be found.
229 	 */
230 	public Connection findConnection(string dsn, string username, string password)
231 	{
232 		// GdaConnection* gda_client_find_connection (GdaClient *client,  const gchar *dsn,  const gchar *username,  const gchar *password);
233 		auto p = gda_client_find_connection(gdaClient, Str.toStringz(dsn), Str.toStringz(username), Str.toStringz(password));
234 		
235 		if(p is null)
236 		{
237 			return null;
238 		}
239 		
240 		return ObjectG.getDObject!(Connection)(cast(GdaConnection*) p);
241 	}
242 	
243 	/**
244 	 * Closes all connections opened by the given GdaClient object.
245 	 */
246 	public void closeAllConnections()
247 	{
248 		// void gda_client_close_all_connections (GdaClient *client);
249 		gda_client_close_all_connections(gdaClient);
250 	}
251 	
252 	/**
253 	 * Notifies an event to the given GdaClient's listeners. The event can be
254 	 * anything (see GdaClientEvent) ranging from a connection opening
255 	 * operation, to changes made to a table in an underlying database.
256 	 * Params:
257 	 * cnc = a GdaConnection object where the event has occurred.
258 	 * event = event ID.
259 	 * params = parameters associated with the event.
260 	 */
261 	public void notifyEvent(Connection cnc, GdaClientEvent event, ParameterList params)
262 	{
263 		// void gda_client_notify_event (GdaClient *client,  GdaConnection *cnc,  GdaClientEvent event,  GdaParameterList *params);
264 		gda_client_notify_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), event, (params is null) ? null : params.getParameterListStruct());
265 	}
266 	
267 	/**
268 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_ERROR event.
269 	 * Params:
270 	 * cnc = a GdaConnection object.
271 	 * error = the error to be notified.
272 	 */
273 	public void notifyErrorEvent(Connection cnc, ErrorGda error)
274 	{
275 		// void gda_client_notify_error_event (GdaClient *client,  GdaConnection *cnc,  GdaError *error);
276 		gda_client_notify_error_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), (error is null) ? null : error.getErrorGdaStruct());
277 	}
278 	
279 	/**
280 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_CONNECTION_OPENED
281 	 * event.
282 	 * Params:
283 	 * cnc = a GdaConnection object.
284 	 */
285 	public void notifyConnectionOpenedEvent(Connection cnc)
286 	{
287 		// void gda_client_notify_connection_opened_event  (GdaClient *client,  GdaConnection *cnc);
288 		gda_client_notify_connection_opened_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct());
289 	}
290 	
291 	/**
292 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_CONNECTION_CLOSED
293 	 * event.
294 	 * Params:
295 	 * cnc = a GdaConnection object.
296 	 */
297 	public void notifyConnectionClosedEvent(Connection cnc)
298 	{
299 		// void gda_client_notify_connection_closed_event  (GdaClient *client,  GdaConnection *cnc);
300 		gda_client_notify_connection_closed_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct());
301 	}
302 	
303 	/**
304 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_TRANSACTION_STARTED
305 	 * event.
306 	 * Params:
307 	 * cnc = a GdaConnection object.
308 	 * xaction = a GdaTransaction object.
309 	 */
310 	public void notifyTransactionStartedEvent(Connection cnc, Transaction xaction)
311 	{
312 		// void gda_client_notify_transaction_started_event  (GdaClient *client,  GdaConnection *cnc,  GdaTransaction *xaction);
313 		gda_client_notify_transaction_started_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), (xaction is null) ? null : xaction.getTransactionStruct());
314 	}
315 	
316 	/**
317 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_TRANSACTION_COMMITTED
318 	 * event.
319 	 * Params:
320 	 * cnc = a GdaConnection object.
321 	 * xaction = a GdaTransaction object.
322 	 */
323 	public void notifyTransactionCommittedEvent(Connection cnc, Transaction xaction)
324 	{
325 		// void gda_client_notify_transaction_committed_event  (GdaClient *client,  GdaConnection *cnc,  GdaTransaction *xaction);
326 		gda_client_notify_transaction_committed_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), (xaction is null) ? null : xaction.getTransactionStruct());
327 	}
328 	
329 	/**
330 	 * Notifies the given GdaClient of the GDA_CLIENT_EVENT_TRANSACTION_CANCELLED
331 	 * event.
332 	 * Params:
333 	 * cnc = a GdaConnection object.
334 	 * xaction = a GdaTransaction object.
335 	 */
336 	public void notifyTransactionCancelledEvent(Connection cnc, Transaction xaction)
337 	{
338 		// void gda_client_notify_transaction_cancelled_event  (GdaClient *client,  GdaConnection *cnc,  GdaTransaction *xaction);
339 		gda_client_notify_transaction_cancelled_event(gdaClient, (cnc is null) ? null : cnc.getConnectionStruct(), (xaction is null) ? null : xaction.getTransactionStruct());
340 	}
341 	
342 	/**
343 	 * Starts a transaction on all connections being managed by the given
344 	 * GdaClient. It is important to note that this operates on all
345 	 * connections opened within a GdaClient, which could not be what
346 	 * you're looking for.
347 	 * To execute a transaction on a unique connection, use
348 	 * gda_connection_begin_transaction, gda_connection_commit_transaction
349 	 * and gda_connection_rollback_transaction.
350 	 * Params:
351 	 * xaction = a GdaTransaction object.
352 	 * Returns: TRUE if all transactions could be started successfully, or FALSE if one of them fails.
353 	 */
354 	public int beginTransaction(Transaction xaction)
355 	{
356 		// gboolean gda_client_begin_transaction (GdaClient *client,  GdaTransaction *xaction);
357 		return gda_client_begin_transaction(gdaClient, (xaction is null) ? null : xaction.getTransactionStruct());
358 	}
359 	
360 	/**
361 	 * Commits a running transaction on all connections being managed by the given
362 	 * GdaClient. It is important to note that this operates on all
363 	 * connections opened within a GdaClient, which could not be what
364 	 * you're looking for.
365 	 * To execute a transaction on a unique connection, use
366 	 * gda_connection_begin_transaction, gda_connection_commit_transaction
367 	 * and gda_connection_rollback_transaction.
368 	 * Params:
369 	 * xaction = a GdaTransaction object.
370 	 * Returns: TRUE if all transactions could be committed successfully, or FALSE if one of them fails.
371 	 */
372 	public int commitTransaction(Transaction xaction)
373 	{
374 		// gboolean gda_client_commit_transaction (GdaClient *client,  GdaTransaction *xaction);
375 		return gda_client_commit_transaction(gdaClient, (xaction is null) ? null : xaction.getTransactionStruct());
376 	}
377 	
378 	/**
379 	 * Cancels a running transaction on all connections being managed by the given
380 	 * GdaClient. It is important to note that this operates on all
381 	 * connections opened within a GdaClient, which could not be what
382 	 * you're looking for.
383 	 * To execute a transaction on a unique connection, use
384 	 * gda_connection_begin_transaction, gda_connection_commit_transaction
385 	 * and gda_connection_rollback_transaction.
386 	 * Params:
387 	 * xaction = a GdaTransaction object.
388 	 * Returns: TRUE if all transactions could be cancelled successfully, or FALSE if one of them fails.
389 	 */
390 	public int rollbackTransaction(Transaction xaction)
391 	{
392 		// gboolean gda_client_rollback_transaction (GdaClient *client,  GdaTransaction *xaction);
393 		return gda_client_rollback_transaction(gdaClient, (xaction is null) ? null : xaction.getTransactionStruct());
394 	}
395 }