JULEA
sql-generic-internal.h
Go to the documentation of this file.
1 /*
2  * JULEA - Flexible storage framework
3  * Copyright (C) 2022 Timm Leon Erxleben
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef JULEA_DB_UTIL_SQL_GENERIC_INTERNAL_H
20 #define JULEA_DB_UTIL_SQL_GENERIC_INTERNAL_H
21 
22 #include <glib.h>
23 
24 #include <db-util/sql-generic.h>
25 #include <db-util/jbson.h>
26 
45 #define BACKEND_ID_TYPE J_DB_TYPE_UINT64
46 
51 {
53  gpointer db_connection;
54 
62  GHashTable* query_cache;
63 
72  GHashTable* schema_cache;
73 };
74 
75 typedef struct JThreadVariables JThreadVariables;
76 
83 struct JSqlBatch
84 {
86  const gchar* namespace;
87 
90 
92  gboolean open;
93 
95  gboolean aborted;
96 };
97 
98 typedef struct JSqlBatch JSqlBatch;
99 
106 {
108  gpointer stmt;
109 
116  GHashTable* out_variables_index;
117 
124  GHashTable* variable_types;
125 };
126 
127 typedef struct JSqlStatement JSqlStatement;
128 
129 // common
130 
132 extern GPrivate thread_variables_global;
133 
135 extern JSQLSpecifics* specs;
136 
138 G_LOCK_EXTERN(sql_backend_lock);
139 
145 void thread_variables_fini(void* ptr);
146 
156 JThreadVariables* thread_variables_get(gpointer backend_data, GError** error);
157 
171 JSqlStatement* j_sql_statement_new(gchar const* query, GArray* types_in, GArray* types_out, GHashTable* out_variables_index, GHashTable* variable_types, GError** error);
172 
179 
190 GString* j_sql_get_full_field_name(const gchar* namespace, const gchar* table, const gchar* field);
191 
192 // DQL
193 
206 gboolean _backend_schema_get(gpointer backend_data, gchar const* namespace, gchar const* name, bson_t* schema, GError** error);
207 
222 GHashTable* get_schema(gpointer backend_data, gchar const* namespace, gchar const* name, GError** error);
223 
237 gboolean build_query_condition_part(gpointer backend_data, JSqlBatch* batch, bson_iter_t* iter, GString* sql, JDBSelectorMode mode, GArray* arr_types_in, GHashTable* schema, GError** error);
238 
249 gboolean bind_selector_query(gpointer backend_data, const gchar* namespace, bson_iter_t* iter, JSqlStatement* statement, GHashTable* schema, GError** error);
250 
266 gboolean _backend_query_ids(gpointer backend_data, gpointer _batch, gchar const* name, bson_t const* selector, GArray** matches, GError** error);
267 
268 // TCL
269 
278 gboolean _backend_batch_start(gpointer backend_data, JSqlBatch* batch, GError** error);
279 
288 gboolean _backend_batch_execute(gpointer backend_data, JSqlBatch* batch, GError** error);
289 
298 gboolean _backend_batch_abort(gpointer backend_data, JSqlBatch* batch, GError** error);
299 
300 #endif
JDBSelectorMode
Definition: jdb-selector.h:35
GPrivate thread_variables_global
Holds a thread-private pointer to JThreadVariables.
Definition: sql-generic-common.c:24
gboolean _backend_batch_abort(gpointer backend_data, JSqlBatch *batch, GError **error)
Abort a batch. Triggers a rollback in the DB backend.
Definition: sql-generic-tcl.c:80
gboolean _backend_batch_start(gpointer backend_data, JSqlBatch *batch, GError **error)
Start a batch. Starts a transaction in the DB backend.
Definition: sql-generic-tcl.c:25
JSqlStatement * j_sql_statement_new(gchar const *query, GArray *types_in, GArray *types_out, GHashTable *out_variables_index, GHashTable *variable_types, GError **error)
Construct a JSqlStatement struct from the necessary information.
Definition: sql-generic-common.c:139
GHashTable * get_schema(gpointer backend_data, gchar const *namespace, gchar const *name, GError **error)
Get the schema as a HashTable for internal usage.
Definition: sql-generic-dql.c:176
gboolean build_query_condition_part(gpointer backend_data, JSqlBatch *batch, bson_iter_t *iter, GString *sql, JDBSelectorMode mode, GArray *arr_types_in, GHashTable *schema, GError **error)
Build the WHERE part of a SELECT statement from a selector.
Definition: sql-generic-dql.c:306
JThreadVariables * thread_variables_get(gpointer backend_data, GError **error)
Retrieve the thread-private JThreadVariables.
Definition: sql-generic-common.c:103
gboolean bind_selector_query(gpointer backend_data, const gchar *namespace, bson_iter_t *iter, JSqlStatement *statement, GHashTable *schema, GError **error)
Bind the variables in the WHERE part of a SELECT statement.
Definition: sql-generic-dql.c:597
JSQLSpecifics * specs
Contains the specific string constants and functions for a DB backend.
Definition: sql-generic-common.c:25
void thread_variables_fini(void *ptr)
Free function for JThreadVariables.
Definition: sql-generic-common.c:73
GString * j_sql_get_full_field_name(const gchar *namespace, const gchar *table, const gchar *field)
Get the full field name from the different parts.
Definition: sql-generic-common.c:215
void j_sql_statement_free(JSqlStatement *ptr)
Destructor for a JSqlStatement.
Definition: sql-generic-common.c:175
gboolean _backend_schema_get(gpointer backend_data, gchar const *namespace, gchar const *name, bson_t *schema, GError **error)
Retrieve the schema as bson document.
Definition: sql-generic-dql.c:26
G_LOCK_EXTERN(sql_backend_lock)
Starting a batch requires locking if the DB backend does not support concurrent accesses.
gboolean _backend_batch_execute(gpointer backend_data, JSqlBatch *batch, GError **error)
Execute a batch. Commits a transaction in the DB backend.
Definition: sql-generic-tcl.c:53
gboolean _backend_query_ids(gpointer backend_data, gpointer _batch, gchar const *name, bson_t const *selector, GArray **matches, GError **error)
Query the IDs of rows that match a selector.
Definition: sql-generic-dql.c:826
Definition: sql-generic.h:31
Definition: jsemantics.c:42
Manages the status of a batch.
Definition: sql-generic-internal.h:84
gboolean open
TRUE if the batch is open.
Definition: sql-generic-internal.h:92
JSemantics * semantics
The namespace of the operations inside the batch.
Definition: sql-generic-internal.h:86
gboolean aborted
TRUE if there was an error and the batch was aborted.
Definition: sql-generic-internal.h:95
The JSqlStatement wraps a DB backend-specific prepared statement.
Definition: sql-generic-internal.h:106
GHashTable * out_variables_index
Indices of the output variables (i.e., columns).
Definition: sql-generic-internal.h:116
gpointer stmt
The prepared statement of a DB backend.
Definition: sql-generic-internal.h:108
GHashTable * variable_types
Types of the variables contained in the query.
Definition: sql-generic-internal.h:124
The JThreadVariables struct bundles the thread-local DB connection, the query cache and the schema ca...
Definition: sql-generic-internal.h:51
GHashTable * schema_cache
Cache for schemas.
Definition: sql-generic-internal.h:72
GHashTable * query_cache
Cache for prepared statements.
Definition: sql-generic-internal.h:62
gpointer db_connection
The backend-specific database connection handle.
Definition: sql-generic-internal.h:53