/* test-insert-or-replace.c generated by valac 0.12.0, the Vala compiler
 * generated from test-insert-or-replace.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <libtracker-sparql/tracker-sparql.h>

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_timer_destroy0(var) ((var == NULL) ? NULL : (var = (g_timer_destroy (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))



#define insert_query_replace "\n" \
"DELETE { ?r nao:hasProperty ?property . }\n" \
"WHERE { \n" \
"	?r a nco:PhoneNumber;\n" \
"	   nco:phoneNumber \"02141730585%d\";\n" \
"	   nao:hasProperty ?property .\n" \
"}\n" \
"\n" \
"DELETE {\n" \
"	?r a nco:CarPhoneNumber, nco:BbsNumber, nco:PagerNumber,\n" \
"	     nco:VideoTelephoneNumber, nco:MessagingNumber, nco:VoicePhoneNum" \
"ber,\n" \
"	     nco:CellPhoneNumber, nco:FaxNumber, nco:ModemNumber .\n" \
"} WHERE {\n" \
"	?r a nco:PhoneNumber;\n" \
"	   nco:phoneNumber \"02141730585%d\" .\n" \
"}\n" \
"\n" \
"INSERT {\n" \
"	_:tel a nco:PhoneNumber ;\n" \
"	      nco:phoneNumber \"02141730585%d\" .\n" \
"} WHERE {\n" \
"	OPTIONAL {\n" \
"		?r a nco:PhoneNumber;\n" \
"		   nco:phoneNumber \"02141730585%d\" .\n" \
"	}\n" \
"	FILTER(!bound(?r)) .\n" \
"}\n" \
"\n" \
"INSERT OR REPLACE { <mailto:rhome0@example.com%d> a nco:EmailAddress ;" \
"\n" \
"		nco:emailAddress \"rhome0@example.com%d\" . }\n" \
"\n" \
"DELETE { <contact:r:%d> nco:hasAffiliation ?e . ?e a rdfs:Resource }\n" \
"WHERE { <contact:r:%d> a nco:PersonContact ; nco:hasAffiliation ?e }\n" \
"\n" \
"INSERT OR REPLACE {\n" \
"	_:af1 a nco:Affiliation ;\n" \
"	      rdfs:label \"Work\" ;\n" \
"	      nco:hasEmailAddress <mailto:rhome0@example.com%d> .\n" \
"\n" \
"	_:af2 a nco:Affiliation ;\n" \
"	      rdfs:label \"Other\" ;\n" \
"	      nco:hasPhoneNumber ?tel .\n" \
"\n" \
"	<contact:r:%d> a nco:PersonContact ;\n" \
"	               nco:nameGiven \"First %d\" ;\n" \
"	               nco:nameFamily \"Last %d\" ;\n" \
"	               nco:hasAffiliation _:af1 ;\n" \
"	               nco:hasAffiliation _:af2 ;\n" \
"	               nie:contentCreated \"2011-03-14T13:47:25\" ;\n" \
"	               nco:contactUID \"c1f1b12d-bc75-4d45-9a1f-b1efe934409f\"" \
" .\n" \
"} WHERE {\n" \
"	?tel nco:phoneNumber \"02141730585%d\"\n" \
"}"
#define insert_query_original "\n" \
"DELETE { ?r nao:hasProperty ?property . }\n" \
"WHERE { \n" \
"	?r a nco:PhoneNumber; nco:phoneNumber \"2141730585%d\";\n" \
"	   nao:hasProperty ?property .\n" \
"}\n" \
"\n" \
"DELETE {\n" \
"	?r a nco:CarPhoneNumber, nco:BbsNumber, nco:PagerNumber,\n" \
"	     nco:VideoTelephoneNumber, nco:MessagingNumber, nco:VoicePhoneNum" \
"ber,\n" \
"	     nco:CellPhoneNumber, nco:FaxNumber, nco:ModemNumber .\n" \
"} WHERE {\n" \
"	?r a nco:PhoneNumber;\n" \
"	   nco:phoneNumber \"2141730585%d\" .\n" \
"}\n" \
"\n" \
"INSERT {\n" \
"	_:tel a nco:PhoneNumber ;\n" \
"	      nco:phoneNumber \"2141730585%d\" .\n" \
"} WHERE {\n" \
"	OPTIONAL {\n" \
"		?r a nco:PhoneNumber;\n" \
"		   nco:phoneNumber \"2141730585%d\" .\n" \
"	}\n" \
"	FILTER(!bound(?r)) .\n" \
"}\n" \
"\n" \
"INSERT { <mailto:home0@example.com%d> a nco:EmailAddress ;\n" \
"			nco:emailAddress \"home0@example.com%d\" . }\n" \
"\n" \
"DELETE { <contact:o:%d> nco:hasAffiliation ?e . ?e a rdfs:Resource }\n" \
"WHERE { <contact:o:%d> a nco:PersonContact ; nco:hasAffiliation ?e }\n" \
"\n" \
"DELETE { GRAPH <urn:uuid:08070f5c-a334-4d19-a8b0-12a3071bfab9> {\n" \
"    <contact:o:%d> ?predicate ?object .\n" \
"} } WHERE { GRAPH <urn:uuid:08070f5c-a334-4d19-a8b0-12a3071bfab9> {\n" \
"    <contact:o:%d> ?predicate ?object .\n" \
"    FILTER(?predicate NOT IN (nco:contactLocalUID,nco:contactUID,rdf:t" \
"ype)) .\n" \
"} }\n" \
"\n" \
"INSERT { GRAPH <urn:uuid:08070f5c-a334-4d19-a8b0-12a3071bfab9> {\n" \
"	_:af1 a nco:Affiliation ;\n" \
"	      rdfs:label \"Work\" ;\n" \
"	      nco:hasEmailAddress <mailto:home0@example.com%d> .\n" \
"\n" \
"	_:af2 a nco:Affiliation ;\n" \
"	      rdfs:label \"Other\" ;\n" \
"	      nco:hasPhoneNumber ?tel .\n" \
"\n" \
"	<contact:o:%d> a nco:PersonContact ;\n" \
"	               nco:nameGiven \"First %d\" ;\n" \
"	               nco:nameFamily \"Last %d\" ;\n" \
"	               nco:hasAffiliation _:af1 ;\n" \
"	               nco:hasAffiliation _:af2 ;\n" \
"	               nie:contentCreated \"2011-03-14T13:47:25\" ;\n" \
"	               nco:contactUID \"c1f1b12d-bc75-4d45-9a1f-b1efe934409f\"" \
" .\n" \
"} } WHERE {\n" \
"	?tel nco:phoneNumber \"2141730585%d\"\n" \
"}"
gint _vala_main (gchar** args, int args_length1);


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	guint i = 0U;
	guint y;
	GTimer* _tmp0_ = NULL;
	GTimer* timer;
	TrackerSparqlConnection* c = NULL;
	TrackerSparqlConnection* _tmp1_ = NULL;
	TrackerSparqlConnection* _tmp2_;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp9_ = FALSE;
	GError * _inner_error_ = NULL;
	y = (guint) 100;
	_tmp0_ = g_timer_new ();
	timer = _tmp0_;
	_tmp1_ = tracker_sparql_connection_get (NULL, &_inner_error_);
	_tmp2_ = _tmp1_;
	if (_inner_error_ != NULL) {
		_g_object_unref0 (c);
		_g_timer_destroy0 (timer);
		goto __catch0_g_error;
	}
	_g_object_unref0 (c);
	c = _tmp2_;
	if (args_length1 == 3) {
		gint _tmp3_;
		_tmp3_ = atoi (args[2]);
		y = (guint) _tmp3_;
	}
	if (args_length1 == 1) {
		_tmp4_ = TRUE;
	} else {
		_tmp4_ = g_strcmp0 (args[1], "replace") == 0;
	}
	if (_tmp4_) {
		gdouble _tmp8_;
		g_timer_start (timer);
		{
			gboolean _tmp5_;
			i = (guint) 0;
			_tmp5_ = TRUE;
			while (TRUE) {
				gchar* _tmp6_ = NULL;
				gchar* _tmp7_;
				if (!_tmp5_) {
					i++;
				}
				_tmp5_ = FALSE;
				if (!(i < y)) {
					break;
				}
				_tmp6_ = g_strdup_printf (insert_query_replace, i, i, i, i, i, i, i, i, i, i, i, i, i);
				_tmp7_ = _tmp6_;
				tracker_sparql_connection_update (c, _tmp7_, G_PRIORITY_DEFAULT, NULL, &_inner_error_);
				_g_free0 (_tmp7_);
				if (_inner_error_ != NULL) {
					_g_object_unref0 (c);
					_g_timer_destroy0 (timer);
					goto __catch0_g_error;
				}
			}
		}
		g_timer_stop (timer);
		_tmp8_ = g_timer_elapsed (timer, NULL);
		g_print ("REPLACE  : %u contacts: %f\n", y, _tmp8_);
	}
	if (args_length1 == 1) {
		_tmp9_ = TRUE;
	} else {
		_tmp9_ = g_strcmp0 (args[1], "original") == 0;
	}
	if (_tmp9_) {
		gdouble _tmp13_;
		g_timer_start (timer);
		{
			gboolean _tmp10_;
			i = (guint) 0;
			_tmp10_ = TRUE;
			while (TRUE) {
				gchar* _tmp11_ = NULL;
				gchar* _tmp12_;
				if (!_tmp10_) {
					i++;
				}
				_tmp10_ = FALSE;
				if (!(i < y)) {
					break;
				}
				_tmp11_ = g_strdup_printf (insert_query_original, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i);
				_tmp12_ = _tmp11_;
				tracker_sparql_connection_update (c, _tmp12_, G_PRIORITY_DEFAULT, NULL, &_inner_error_);
				_g_free0 (_tmp12_);
				if (_inner_error_ != NULL) {
					_g_object_unref0 (c);
					_g_timer_destroy0 (timer);
					goto __catch0_g_error;
				}
			}
		}
		g_timer_stop (timer);
		_tmp13_ = g_timer_elapsed (timer, NULL);
		g_print ("ORIGINAL : %u contacts: %f\n", y, _tmp13_);
	}
	_g_object_unref0 (c);
	_g_timer_destroy0 (timer);
	goto __finally0;
	__catch0_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_critical ("test-insert-or-replace.vala:152: %s", e->message);
		_g_error_free0 (e);
	}
	__finally0:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	result = 0;
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _vala_main (argv, argc);
}



