summaryrefslogtreecommitdiff
path: root/tests/functional-tests/ipc/test-insert-or-replace.vala
blob: ce64eecbe389ed275b6357846e1f1a18f4d6e441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using GLib;
using Tracker;
using Tracker.Sparql;

const string insert_query_replace = "
DELETE { ?r nao:hasTag ?tag . }
WHERE { 
	?r a nco:PhoneNumber;
	   nco:phoneNumber \"02141730585%d\";
	   nao:hasTag ?tag .
}

DELETE {
	?r a nco:CarPhoneNumber, nco:BbsNumber, nco:PagerNumber,
	     nco:VideoTelephoneNumber, nco:MessagingNumber, nco:VoicePhoneNumber,
	     nco:CellPhoneNumber, nco:FaxNumber, nco:ModemNumber .
} WHERE {
	?r a nco:PhoneNumber;
	   nco:phoneNumber \"02141730585%d\" .
}

INSERT {
	_:tel a nco:PhoneNumber ;
	      nco:phoneNumber \"02141730585%d\" .
} WHERE {
	OPTIONAL {
		?r a nco:PhoneNumber;
		   nco:phoneNumber \"02141730585%d\" .
	}
	FILTER(!bound(?r)) .
}

INSERT OR REPLACE { <mailto:rhome0@example.com%d> a nco:EmailAddress ;
		nco:emailAddress \"rhome0@example.com%d\" . }

DELETE { <contact:r:%d> nco:hasAffiliation ?e . ?e a rdfs:Resource }
WHERE { <contact:r:%d> a nco:PersonContact ; nco:hasAffiliation ?e }

INSERT OR REPLACE {
	_:af1 a nco:Affiliation ;
	      rdfs:label \"Work\" ;
	      nco:hasEmailAddress <mailto:rhome0@example.com%d> .

	_:af2 a nco:Affiliation ;
	      rdfs:label \"Other\" ;
	      nco:hasPhoneNumber ?tel .

	<contact:r:%d> a nco:PersonContact ;
	               nco:nameGiven \"First %d\" ;
	               nco:nameFamily \"Last %d\" ;
	               nco:hasAffiliation _:af1 ;
	               nco:hasAffiliation _:af2 ;
	               nie:contentCreated \"2011-03-14T13:47:25\" ;
	               nco:contactUID \"c1f1b12d-bc75-4d45-9a1f-b1efe934409f\" .
} WHERE {
	?tel nco:phoneNumber \"02141730585%d\"
}";

const string insert_query_original = "
DELETE { ?r nao:tag ?tag . }
WHERE { 
	?r a nco:PhoneNumber; nco:phoneNumber \"2141730585%d\";
	   nao:hasTag ?tag .
}

DELETE {
	?r a nco:CarPhoneNumber, nco:BbsNumber, nco:PagerNumber,
	     nco:VideoTelephoneNumber, nco:MessagingNumber, nco:VoicePhoneNumber,
	     nco:CellPhoneNumber, nco:FaxNumber, nco:ModemNumber .
} WHERE {
	?r a nco:PhoneNumber;
	   nco:phoneNumber \"2141730585%d\" .
}

INSERT {
	_:tel a nco:PhoneNumber ;
	      nco:phoneNumber \"2141730585%d\" .
} WHERE {
	OPTIONAL {
		?r a nco:PhoneNumber;
		   nco:phoneNumber \"2141730585%d\" .
	}
	FILTER(!bound(?r)) .
}

INSERT { <mailto:home0@example.com%d> a nco:EmailAddress ;
			nco:emailAddress \"home0@example.com%d\" . }

DELETE { <contact:o:%d> nco:hasAffiliation ?e . ?e a rdfs:Resource }
WHERE { <contact:o:%d> a nco:PersonContact ; nco:hasAffiliation ?e }

DELETE { GRAPH <urn:uuid:08070f5c-a334-4d19-a8b0-12a3071bfab9> {
    <contact:o:%d> ?predicate ?object .
} } WHERE { GRAPH <urn:uuid:08070f5c-a334-4d19-a8b0-12a3071bfab9> {
    <contact:o:%d> ?predicate ?object .
    FILTER(?predicate NOT IN (nco:contactLocalUID,nco:contactUID,rdf:type)) .
} }

INSERT { GRAPH <urn:uuid:08070f5c-a334-4d19-a8b0-12a3071bfab9> {
	_:af1 a nco:Affiliation ;
	      rdfs:label \"Work\" ;
	      nco:hasEmailAddress <mailto:home0@example.com%d> .

	_:af2 a nco:Affiliation ;
	      rdfs:label \"Other\" ;
	      nco:hasPhoneNumber ?tel .

	<contact:o:%d> a nco:PersonContact ;
	               nco:nameGiven \"First %d\" ;
	               nco:nameFamily \"Last %d\" ;
	               nco:hasAffiliation _:af1 ;
	               nco:hasAffiliation _:af2 ;
	               nie:contentCreated \"2011-03-14T13:47:25\" ;
	               nco:contactUID \"c1f1b12d-bc75-4d45-9a1f-b1efe934409f\" .
} } WHERE {
	?tel nco:phoneNumber \"2141730585%d\"
}";


int main (string[] args) {
	try {
		uint i, y = 100;
		Timer timer = new Timer ();
		Connection c;
		c = Connection.get ();

		if (args.length == 3) {
			y = int.parse (args[2]);
		}

		if (args.length == 1 || args[1] == "replace") {
			timer.start ();
			for (i = 0; i < y; i++) {
				c.update (insert_query_replace.printf (i,i,i,i,i,i,i,i,i,i,i,i,i));
			}
			timer.stop ();

			print ("REPLACE  : %u contacts: %f\n", y, timer.elapsed());
		}


		if (args.length == 1 || args[1] == "original") {
			timer.start ();
			for (i = 0; i < y; i++) {
				c.update (insert_query_original.printf (i,i,i,i,i,i,i,i,i,i,i,i,i,i,i));
			}
			timer.stop ();

			print ("ORIGINAL : %u contacts: %f\n", y, timer.elapsed());
		}
	} catch (GLib.Error e) {
		critical ("%s", e.message);
	}

	return 0;
}