1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.graph;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.io.Reader;
30 import java.math.BigDecimal;
31 import java.net.URI;
32 import java.util.ArrayList;
33 import java.util.Calendar;
34 import java.util.Collection;
35 import java.util.Collections;
36 import java.util.Date;
37 import java.util.HashMap;
38 import java.util.Iterator;
39 import java.util.LinkedList;
40 import java.util.List;
41 import java.util.Map;
42 import java.util.Set;
43 import java.util.UUID;
44 import java.util.concurrent.TimeUnit;
45 import net.jcip.annotations.Immutable;
46 import net.jcip.annotations.NotThreadSafe;
47 import org.modeshape.common.collection.EmptyIterator;
48 import org.modeshape.common.collection.Problems;
49 import org.modeshape.common.i18n.I18n;
50 import org.modeshape.common.util.CheckArg;
51 import org.modeshape.graph.cache.CachePolicy;
52 import org.modeshape.graph.connector.RepositoryConnection;
53 import org.modeshape.graph.connector.RepositoryConnectionFactory;
54 import org.modeshape.graph.connector.RepositorySource;
55 import org.modeshape.graph.connector.RepositorySourceException;
56 import org.modeshape.graph.io.GraphImporter;
57 import org.modeshape.graph.property.Binary;
58 import org.modeshape.graph.property.DateTime;
59 import org.modeshape.graph.property.Name;
60 import org.modeshape.graph.property.NameFactory;
61 import org.modeshape.graph.property.Path;
62 import org.modeshape.graph.property.PathNotFoundException;
63 import org.modeshape.graph.property.Property;
64 import org.modeshape.graph.property.PropertyFactory;
65 import org.modeshape.graph.property.Reference;
66 import org.modeshape.graph.property.ValueFactory;
67 import org.modeshape.graph.property.ValueFormatException;
68 import org.modeshape.graph.property.Path.Segment;
69 import org.modeshape.graph.query.QueryContext;
70 import org.modeshape.graph.query.QueryEngine;
71 import org.modeshape.graph.query.QueryResults;
72 import org.modeshape.graph.query.QueryResults.Columns;
73 import org.modeshape.graph.query.model.QueryCommand;
74 import org.modeshape.graph.query.model.TypeSystem;
75 import org.modeshape.graph.query.optimize.Optimizer;
76 import org.modeshape.graph.query.optimize.RuleBasedOptimizer;
77 import org.modeshape.graph.query.plan.CanonicalPlanner;
78 import org.modeshape.graph.query.plan.PlanHints;
79 import org.modeshape.graph.query.plan.PlanNode;
80 import org.modeshape.graph.query.plan.Planner;
81 import org.modeshape.graph.query.process.AbstractAccessComponent;
82 import org.modeshape.graph.query.process.ProcessingComponent;
83 import org.modeshape.graph.query.process.Processor;
84 import org.modeshape.graph.query.process.QueryProcessor;
85 import org.modeshape.graph.query.process.SelectComponent.Analyzer;
86 import org.modeshape.graph.query.validate.Schemata;
87 import org.modeshape.graph.request.AccessQueryRequest;
88 import org.modeshape.graph.request.BatchRequestBuilder;
89 import org.modeshape.graph.request.CacheableRequest;
90 import org.modeshape.graph.request.CloneWorkspaceRequest;
91 import org.modeshape.graph.request.CompositeRequest;
92 import org.modeshape.graph.request.CreateNodeRequest;
93 import org.modeshape.graph.request.CreateWorkspaceRequest;
94 import org.modeshape.graph.request.FullTextSearchRequest;
95 import org.modeshape.graph.request.InvalidRequestException;
96 import org.modeshape.graph.request.InvalidWorkspaceException;
97 import org.modeshape.graph.request.ReadAllChildrenRequest;
98 import org.modeshape.graph.request.ReadAllPropertiesRequest;
99 import org.modeshape.graph.request.ReadBranchRequest;
100 import org.modeshape.graph.request.ReadNodeRequest;
101 import org.modeshape.graph.request.ReadPropertyRequest;
102 import org.modeshape.graph.request.Request;
103 import org.modeshape.graph.request.RequestBuilder;
104 import org.modeshape.graph.request.RequestType;
105 import org.modeshape.graph.request.UnsupportedRequestException;
106 import org.modeshape.graph.request.VerifyWorkspaceRequest;
107 import org.modeshape.graph.request.CloneWorkspaceRequest.CloneConflictBehavior;
108 import org.modeshape.graph.request.CreateWorkspaceRequest.CreateConflictBehavior;
109 import org.xml.sax.SAXException;
110
111
112
113
114
115
116
117 @NotThreadSafe
118 public class Graph {
119
120 protected static final Iterator<Property> EMPTY_PROPERTIES = new EmptyIterator<Property>();
121 protected static final Iterable<Property> NO_PROPERTIES = new Iterable<Property>() {
122 public final Iterator<Property> iterator() {
123 return EMPTY_PROPERTIES;
124 }
125 };
126
127
128
129
130
131
132
133
134
135
136
137 public static Graph create( String sourceName,
138 RepositoryConnectionFactory connectionFactory,
139 ExecutionContext context ) {
140 return new Graph(sourceName, connectionFactory, context);
141 }
142
143
144
145
146
147
148
149
150
151 public static Graph create( final RepositoryConnection connection,
152 ExecutionContext context ) {
153 CheckArg.isNotNull(connection, "connection");
154 final String connectorSourceName = connection.getSourceName();
155 RepositoryConnectionFactory connectionFactory = new RepositoryConnectionFactory() {
156 public RepositoryConnection createConnection( String sourceName ) throws RepositorySourceException {
157 if (connectorSourceName.equals(sourceName)) return connection;
158 return null;
159 }
160 };
161 return new Graph(connectorSourceName, connectionFactory, context);
162 }
163
164
165
166
167
168
169
170
171
172 public static Graph create( final RepositorySource source,
173 ExecutionContext context ) {
174 CheckArg.isNotNull(source, "source");
175 final String connectorSourceName = source.getName();
176 RepositoryConnectionFactory connectionFactory = new RepositoryConnectionFactory() {
177 public RepositoryConnection createConnection( String sourceName ) throws RepositorySourceException {
178 if (connectorSourceName.equals(sourceName)) return source.getConnection();
179 return null;
180 }
181 };
182 return new Graph(connectorSourceName, connectionFactory, context);
183 }
184
185 private final String sourceName;
186 private final RepositoryConnectionFactory connectionFactory;
187 protected final ExecutionContext context;
188 protected final RequestBuilder requests;
189 protected final Conjunction<Graph> nextGraph;
190 private Workspace currentWorkspace;
191 private QueryEngine queryEngine;
192
193 protected Graph( String sourceName,
194 RepositoryConnectionFactory connectionFactory,
195 ExecutionContext context ) {
196 CheckArg.isNotNull(sourceName, "sourceName");
197 CheckArg.isNotNull(connectionFactory, "connectionFactory");
198 CheckArg.isNotNull(context, "context");
199 this.sourceName = sourceName;
200 this.connectionFactory = connectionFactory;
201 this.context = context;
202 this.nextGraph = new Conjunction<Graph>() {
203 public Graph and() {
204 return Graph.this;
205 }
206 };
207 this.requests = new RequestBuilder() {
208 @Override
209 protected <T extends Request> T process( T request ) {
210 Graph.this.execute(request);
211 return request;
212 }
213 };
214 }
215
216
217
218
219
220
221 public RepositoryConnectionFactory getConnectionFactory() {
222 return connectionFactory;
223 }
224
225
226
227
228
229
230
231
232 public String getSourceName() {
233 return sourceName;
234 }
235
236
237
238
239
240
241 public ExecutionContext getContext() {
242 return context;
243 }
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261 protected void execute( Request request ) {
262 RepositoryConnection connection = Graph.this.getConnectionFactory().createConnection(getSourceName());
263 if (connection == null) {
264 throw new RepositorySourceException(GraphI18n.unableToFindRepositorySourceWithName.text(getSourceName()));
265 }
266 try {
267 connection.execute(Graph.this.getContext(), request);
268 } finally {
269 connection.close();
270 }
271 if (request.hasError()) {
272 Throwable error = request.getError();
273 if (error instanceof RuntimeException) throw (RuntimeException)error;
274 throw new RepositorySourceException(getSourceName(), error);
275 }
276 }
277
278
279
280
281
282
283
284
285 public CachePolicy getDefaultCachePolicy() {
286 RepositoryConnection connection = this.connectionFactory.createConnection(getSourceName());
287 if (connection == null) {
288 throw new RepositorySourceException(GraphI18n.unableToFindRepositorySourceWithName.text(getSourceName()));
289 }
290 try {
291 return connection.getDefaultCachePolicy();
292 } finally {
293 connection.close();
294 }
295 }
296
297
298
299
300
301
302
303
304 protected Workspace setWorkspace( String workspaceName,
305 Location actualRootLocation ) {
306 assert workspaceName != null;
307 assert actualRootLocation != null;
308 this.currentWorkspace = new GraphWorkspace(workspaceName, actualRootLocation);
309 return this.currentWorkspace;
310 }
311
312
313
314
315
316
317
318
319
320 public String getCurrentWorkspaceName() {
321 return getCurrentWorkspace().getName();
322 }
323
324
325
326
327
328
329
330
331
332
333
334 public Workspace getCurrentWorkspace() {
335 if (this.currentWorkspace == null) {
336 useWorkspace(null);
337 }
338 assert this.currentWorkspace != null;
339 return this.currentWorkspace;
340 }
341
342
343
344
345
346
347 public Set<String> getWorkspaces() {
348 return requests.getWorkspaces().getAvailableWorkspaceNames();
349 }
350
351
352
353
354
355
356
357
358
359
360 public Workspace useWorkspace( String workspaceName ) {
361 VerifyWorkspaceRequest request = requests.verifyWorkspace(workspaceName);
362 return setWorkspace(request.getActualWorkspaceName(), request.getActualLocationOfRoot());
363 }
364
365
366
367
368
369
370
371
372 public CreateWorkspace createWorkspace() {
373 return new CreateWorkspace() {
374
375
376
377
378
379 public Workspace named( String workspaceName ) {
380 CreateWorkspaceRequest request = requests.createWorkspace(workspaceName, CreateConflictBehavior.DO_NOT_CREATE);
381 return setWorkspace(request.getActualWorkspaceName(), request.getActualLocationOfRoot());
382 }
383
384
385
386
387
388
389 public Workspace namedSomethingLike( String workspaceName ) {
390 CreateWorkspaceRequest request = requests.createWorkspace(workspaceName,
391 CreateConflictBehavior.CREATE_WITH_ADJUSTED_NAME);
392 return setWorkspace(request.getActualWorkspaceName(), request.getActualLocationOfRoot());
393 }
394
395
396
397
398
399
400 public NameWorkspace clonedFrom( final String nameOfWorkspaceToClone ) {
401 return new NameWorkspace() {
402
403
404
405
406
407 public Workspace named( String nameOfWorkspaceToCreate ) {
408 CloneWorkspaceRequest request = requests.cloneWorkspace(nameOfWorkspaceToClone,
409 nameOfWorkspaceToCreate,
410 CreateConflictBehavior.DO_NOT_CREATE,
411 CloneConflictBehavior.DO_NOT_CLONE);
412 return setWorkspace(request.getActualWorkspaceName(), request.getActualLocationOfRoot());
413 }
414
415
416
417
418
419
420 public Workspace namedSomethingLike( String nameOfWorkspaceToCreate ) {
421 CloneWorkspaceRequest request = requests.cloneWorkspace(nameOfWorkspaceToClone,
422 nameOfWorkspaceToCreate,
423 CreateConflictBehavior.CREATE_WITH_ADJUSTED_NAME,
424 CloneConflictBehavior.DO_NOT_CLONE);
425 return setWorkspace(request.getActualWorkspaceName(), request.getActualLocationOfRoot());
426 }
427 };
428 }
429 };
430 }
431
432
433
434
435
436
437
438 public LockScope<LockTimeout<Conjunction<Graph>>> lock( Node at ) {
439 return lock(at.getLocation());
440 }
441
442
443
444
445
446
447
448 public LockScope<LockTimeout<Conjunction<Graph>>> lock( String atPath ) {
449 return lock(Location.create(createPath(atPath)));
450 }
451
452
453
454
455
456
457
458 public LockScope<LockTimeout<Conjunction<Graph>>> lock( Path at ) {
459 return lock(Location.create(at));
460 }
461
462
463
464
465
466
467
468 public LockScope<LockTimeout<Conjunction<Graph>>> lock( UUID at ) {
469 return lock(Location.create(at));
470 }
471
472
473
474
475
476
477
478
479 public LockScope<LockTimeout<Conjunction<Graph>>> lock( Property idProperty ) {
480 return lock(Location.create(idProperty));
481 }
482
483
484
485
486
487
488
489
490
491 public LockScope<LockTimeout<Conjunction<Graph>>> lock( Property firstIdProperty,
492 Property... additionalIdProperties ) {
493 return lock(Location.create(firstIdProperty, additionalIdProperties));
494 }
495
496
497
498
499
500
501
502 public LockScope<LockTimeout<Conjunction<Graph>>> lock( Location at ) {
503 return new LockAction<Conjunction<Graph>>(this.nextGraph, at) {
504 @Override
505 protected Conjunction<Graph> submit( Location target,
506 org.modeshape.graph.request.LockBranchRequest.LockScope lockScope,
507 long lockTimeoutInMillis ) {
508 String workspaceName = getCurrentWorkspaceName();
509 requests.lockBranch(workspaceName, target, lockScope, lockTimeoutInMillis);
510 return and();
511 }
512 };
513 }
514
515
516
517
518
519
520
521 public Conjunction<Graph> unlock( Node at ) {
522 return unlock(at.getLocation());
523 }
524
525
526
527
528
529
530
531 public Conjunction<Graph> unlock( String atPath ) {
532 return unlock(Location.create(createPath(atPath)));
533 }
534
535
536
537
538
539
540
541 public Conjunction<Graph> unlock( Path at ) {
542 return unlock(Location.create(at));
543 }
544
545
546
547
548
549
550
551 public Conjunction<Graph> unlock( UUID at ) {
552 return unlock(Location.create(at));
553 }
554
555
556
557
558
559
560
561
562 public Conjunction<Graph> unlock( Property idProperty ) {
563 return unlock(Location.create(idProperty));
564 }
565
566
567
568
569
570
571
572
573
574 public Conjunction<Graph> unlock( Property firstIdProperty,
575 Property... additionalIdProperties ) {
576 return unlock(Location.create(firstIdProperty, additionalIdProperties));
577 }
578
579
580
581
582
583
584
585 public Conjunction<Graph> unlock( Location at ) {
586 String workspaceName = getCurrentWorkspaceName();
587 requests.unlockBranch(workspaceName, at);
588 return this.nextGraph;
589 }
590
591
592
593
594
595
596
597
598
599
600
601
602
603 public Move<Conjunction<Graph>> move( Node from ) {
604 return move(from.getLocation());
605 }
606
607
608
609
610
611
612
613
614
615
616
617
618
619 public Move<Conjunction<Graph>> move( Location from ) {
620 return new MoveAction<Conjunction<Graph>>(this.nextGraph, from) {
621 @Override
622 protected Conjunction<Graph> submit( Locations from,
623 Location into,
624 Location before,
625 Name newName ) {
626 String workspaceName = getCurrentWorkspaceName();
627 do {
628 requests.moveBranch(from.getLocation(), into, before, workspaceName, newName);
629 } while ((from = from.next()) != null);
630 return and();
631 }
632 };
633 }
634
635
636
637
638
639
640
641
642
643
644
645
646
647 public Move<Conjunction<Graph>> move( String fromPath ) {
648 return move(Location.create(createPath(fromPath)));
649 }
650
651
652
653
654
655
656
657
658
659
660
661
662
663 public Move<Conjunction<Graph>> move( Path from ) {
664 return move(Location.create(from));
665 }
666
667
668
669
670
671
672
673
674
675
676
677
678
679 public Move<Conjunction<Graph>> move( UUID from ) {
680 return move(Location.create(from));
681 }
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696 public Move<Conjunction<Graph>> move( Property idProperty ) {
697 return move(Location.create(idProperty));
698 }
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714 public Move<Conjunction<Graph>> move( Property firstIdProperty,
715 Property... additionalIdProperties ) {
716 return move(Location.create(firstIdProperty, additionalIdProperties));
717 }
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735 public Clone<Graph> clone( Location from ) {
736 return new CloneAction<Graph>(this, from) {
737 @Override
738 protected Graph submit( String fromWorkspaceName,
739 Location from,
740 String intoWorkspaceName,
741 Location into,
742 Name desiredName,
743 Segment desiredSegment,
744 boolean removeExisting ) {
745 requests.cloneBranch(from,
746 fromWorkspaceName,
747 into,
748 intoWorkspaceName,
749 desiredName,
750 desiredSegment,
751 removeExisting);
752 return and();
753 }
754 };
755 }
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774 public Clone<Graph> clone( Node from ) {
775 return clone(from.getLocation());
776 }
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795 public Clone<Graph> clone( String fromPath ) {
796 return clone(Location.create(createPath(fromPath)));
797 }
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816 public Clone<Graph> clone( Path from ) {
817 return clone(Location.create(from));
818 }
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837 public Clone<Graph> clone( UUID from ) {
838 return clone(Location.create(from));
839 }
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859 public Clone<Graph> clone( Property idProperty ) {
860 return clone(Location.create(idProperty));
861 }
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882 public Clone<Graph> clone( Property firstIdProperty,
883 Property... additionalIdProperties ) {
884 return clone(Location.create(firstIdProperty, additionalIdProperties));
885 }
886
887
888
889
890
891
892
893
894
895
896
897
898
899 public Copy<Graph> copy( Node from ) {
900 return copy(from.getLocation());
901 }
902
903
904
905
906
907
908
909
910
911
912
913
914
915 public Copy<Graph> copy( Location from ) {
916 return new CopyAction<Graph>(this, from) {
917 @Override
918 protected Graph submit( String fromWorkspaceName,
919 Locations from,
920 Location into,
921 Name childName ) {
922 String workspaceName = fromWorkspaceName != null ? fromWorkspaceName : getCurrentWorkspaceName();
923 do {
924 requests.copyBranch(from.getLocation(),
925 workspaceName,
926 into,
927 getCurrentWorkspaceName(),
928 childName,
929 NodeConflictBehavior.APPEND);
930 } while ((from = from.next()) != null);
931 return and();
932 }
933 };
934 }
935
936
937
938
939
940
941
942
943
944
945
946
947
948 public Copy<Graph> copy( String fromPath ) {
949 return copy(Location.create(createPath(fromPath)));
950 }
951
952
953
954
955
956
957
958
959
960
961
962
963
964 public Copy<Graph> copy( Path from ) {
965 return copy(Location.create(from));
966 }
967
968
969
970
971
972
973
974
975
976
977
978
979
980 public Copy<Graph> copy( UUID from ) {
981 return copy(Location.create(from));
982 }
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997 public Copy<Graph> copy( Property idProperty ) {
998 return copy(Location.create(idProperty));
999 }
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015 public Copy<Graph> copy( Property firstIdProperty,
1016 Property... additionalIdProperties ) {
1017 return copy(Location.create(firstIdProperty, additionalIdProperties));
1018 }
1019
1020
1021
1022
1023
1024
1025
1026 public Conjunction<Graph> delete( Node at ) {
1027 requests.deleteBranch(at.getLocation(), getCurrentWorkspaceName());
1028 return nextGraph;
1029 }
1030
1031
1032
1033
1034
1035
1036
1037 public Conjunction<Graph> delete( Location at ) {
1038 requests.deleteBranch(at, getCurrentWorkspaceName());
1039 return nextGraph;
1040 }
1041
1042
1043
1044
1045
1046
1047
1048 public Conjunction<Graph> delete( String atPath ) {
1049 return delete(Location.create(createPath(atPath)));
1050 }
1051
1052
1053
1054
1055
1056
1057
1058 public Conjunction<Graph> delete( Path at ) {
1059 return delete(Location.create(at));
1060 }
1061
1062
1063
1064
1065
1066
1067
1068 public Conjunction<Graph> delete( UUID at ) {
1069 return delete(Location.create(at));
1070 }
1071
1072
1073
1074
1075
1076
1077
1078
1079 public Conjunction<Graph> delete( Property idProperty ) {
1080 return delete(Location.create(idProperty));
1081 }
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091 public Conjunction<Graph> delete( Property firstIdProperty,
1092 Property... additionalIdProperties ) {
1093 return delete(Location.create(firstIdProperty, additionalIdProperties));
1094 }
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108 public CreateAt<Graph> createAt( String atPath ) {
1109 return createAt(createPath(atPath));
1110 }
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124 public CreateAt<Graph> createAt( final Path at ) {
1125 CheckArg.isNotNull(at, "at");
1126 final Path parent = at.getParent();
1127 final Name childName = at.getLastSegment().getName();
1128 final String workspaceName = getCurrentWorkspaceName();
1129 return new CreateAt<Graph>() {
1130 private final List<Property> properties = new LinkedList<Property>();
1131
1132 public CreateAt<Graph> and( UUID uuid ) {
1133 PropertyFactory factory = getContext().getPropertyFactory();
1134 properties.add(factory.create(ModeShapeLexicon.UUID, uuid));
1135 return this;
1136 }
1137
1138 public CreateAt<Graph> and( Property property ) {
1139 properties.add(property);
1140 return this;
1141 }
1142
1143 public CreateAt<Graph> and( Iterable<Property> properties ) {
1144 for (Property property : properties) {
1145 this.properties.add(property);
1146 }
1147 return this;
1148 }
1149
1150 public CreateAt<Graph> and( String name,
1151 Object... values ) {
1152 ExecutionContext context = getContext();
1153 PropertyFactory factory = context.getPropertyFactory();
1154 NameFactory nameFactory = context.getValueFactories().getNameFactory();
1155 properties.add(factory.create(nameFactory.create(name), values));
1156 return this;
1157 }
1158
1159 public CreateAt<Graph> and( Name name,
1160 Object... values ) {
1161 ExecutionContext context = getContext();
1162 PropertyFactory factory = context.getPropertyFactory();
1163 properties.add(factory.create(name, values));
1164 return this;
1165 }
1166
1167 public CreateAt<Graph> and( Property property,
1168 Property... additionalProperties ) {
1169 properties.add(property);
1170 for (Property additionalProperty : additionalProperties) {
1171 properties.add(additionalProperty);
1172 }
1173 return this;
1174 }
1175
1176 public CreateAt<Graph> with( UUID uuid ) {
1177 return and(uuid);
1178 }
1179
1180 public CreateAt<Graph> with( Property property ) {
1181 return and(property);
1182 }
1183
1184 public CreateAt<Graph> with( Iterable<Property> properties ) {
1185 return and(properties);
1186 }
1187
1188 public CreateAt<Graph> with( Property property,
1189 Property... additionalProperties ) {
1190 return and(property, additionalProperties);
1191 }
1192
1193 public CreateAt<Graph> with( String name,
1194 Object... values ) {
1195 return and(name, values);
1196 }
1197
1198 public CreateAt<Graph> with( Name name,
1199 Object... values ) {
1200 return and(name, values);
1201 }
1202
1203 public Location getLocation() {
1204 Location parentLoc = Location.create(parent);
1205 CreateNodeRequest request = requests.createNode(parentLoc, workspaceName, childName, this.properties.iterator());
1206 return request.getActualLocationOfNode();
1207 }
1208
1209 public Node getNode() {
1210 Location parentLoc = Location.create(parent);
1211 CreateNodeRequest request = requests.createNode(parentLoc, workspaceName, childName, this.properties.iterator());
1212 return getNodeAt(request.getActualLocationOfNode());
1213 }
1214
1215 public Graph and() {
1216 requests.createNode(Location.create(parent), workspaceName, childName, this.properties.iterator());
1217 return Graph.this;
1218 }
1219 };
1220 }
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233 public Create<Graph> create( String atPath ) {
1234 return create(createPath(atPath));
1235 }
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249 public Create<Graph> create( String atPath,
1250 Property property ) {
1251 return create(createPath(atPath)).with(property);
1252 }
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267 public Create<Graph> create( String atPath,
1268 Property firstProperty,
1269 Property... additionalProperties ) {
1270 return create(createPath(atPath)).with(firstProperty, additionalProperties);
1271 }
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284 public final Create<Graph> create( Path at ) {
1285 CheckArg.isNotNull(at, "at");
1286 Path parent = at.getParent();
1287 Name name = at.getLastSegment().getName();
1288 return create(Location.create(parent), name);
1289 }
1290
1291 protected final CreateAction<Graph> create( Location parent,
1292 Name child ) {
1293 return new CreateAction<Graph>(this, parent, getCurrentWorkspaceName(), child) {
1294 @Override
1295 protected Graph submit( Location parent,
1296 String workspaceName,
1297 Name childName,
1298 Collection<Property> properties,
1299 NodeConflictBehavior behavior ) {
1300 requests.createNode(parent, workspaceName, childName, properties.iterator(), behavior);
1301 return Graph.this;
1302 }
1303
1304 };
1305 }
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319 public Create<Graph> create( Path at,
1320 Iterable<Property> properties ) {
1321 Create<Graph> action = create(at);
1322 for (Property property : properties) {
1323 action.and(property);
1324 }
1325 return action;
1326 }
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340 public Create<Graph> create( Path at,
1341 Property property ) {
1342 return create(at).with(property);
1343 }
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358 public Create<Graph> create( Path at,
1359 Property firstProperty,
1360 Property... additionalProperties ) {
1361 return create(at).with(firstProperty, additionalProperties);
1362 }
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375 public CreateNode<Conjunction<Graph>> createUnder( final Location parent ) {
1376 final NameFactory nameFactory = getContext().getValueFactories().getNameFactory();
1377 CheckArg.isNotNull(parent, "parent");
1378 return new CreateNode<Conjunction<Graph>>() {
1379 public Conjunction<Graph> node( String name,
1380 Property... properties ) {
1381 Name child = nameFactory.create(name);
1382 requests.createNode(parent, getCurrentWorkspaceName(), child, properties);
1383 return nextGraph;
1384 }
1385
1386 public Conjunction<Graph> node( String name,
1387 Iterator<Property> properties ) {
1388 Name child = nameFactory.create(name);
1389 requests.createNode(parent, getCurrentWorkspaceName(), child, properties);
1390 return nextGraph;
1391 }
1392
1393 public Conjunction<Graph> node( String name,
1394 Iterable<Property> properties ) {
1395 Name child = nameFactory.create(name);
1396 requests.createNode(parent, getCurrentWorkspaceName(), child, properties.iterator());
1397 return nextGraph;
1398 }
1399 };
1400 }
1401
1402 public AddValue<Graph> addValue( Object value ) {
1403 return new AddValueAction<Graph>(this, this.getCurrentWorkspaceName(), value) {
1404
1405 @Override
1406 protected Graph submit( String workspaceName,
1407 Location on,
1408 Name property,
1409 List<Object> values ) {
1410 requests.addValues(workspaceName, on, property, values);
1411 return nextGraph.and();
1412 }
1413 };
1414 }
1415
1416 public RemoveValue<Graph> removeValue( Object value ) {
1417 return new RemoveValueAction<Graph>(this, this.getCurrentWorkspaceName(), value) {
1418
1419 @Override
1420 protected Graph submit( String workspaceName,
1421 Location on,
1422 Name property,
1423 List<Object> values ) {
1424 requests.removeValues(workspaceName, on, property, values);
1425 return nextGraph.and();
1426 }
1427 };
1428 }
1429
1430
1431
1432
1433
1434
1435
1436 public On<Conjunction<Graph>> set( final Property... properties ) {
1437 return new On<Conjunction<Graph>>() {
1438 public Conjunction<Graph> on( Location location ) {
1439 requests.setProperties(location, getCurrentWorkspaceName(), properties);
1440 return nextGraph;
1441 }
1442
1443 public Conjunction<Graph> on( String path ) {
1444 return on(Location.create(createPath(path)));
1445 }
1446
1447 public Conjunction<Graph> on( Path path ) {
1448 return on(Location.create(path));
1449 }
1450
1451 public Conjunction<Graph> on( Property idProperty ) {
1452 return on(Location.create(idProperty));
1453 }
1454
1455 public Conjunction<Graph> on( Property firstIdProperty,
1456 Property... additionalIdProperties ) {
1457 return on(Location.create(firstIdProperty, additionalIdProperties));
1458 }
1459
1460 public Conjunction<Graph> on( Iterable<Property> idProperties ) {
1461 return on(Location.create(idProperties));
1462 }
1463
1464 public Conjunction<Graph> on( UUID uuid ) {
1465 return on(Location.create(uuid));
1466 }
1467 };
1468 }
1469
1470
1471
1472
1473
1474
1475
1476
1477 public SetValues<Conjunction<Graph>> set( String propertyName ) {
1478 Name name = getContext().getValueFactories().getNameFactory().create(propertyName);
1479 return set(name);
1480 }
1481
1482
1483
1484
1485
1486
1487
1488
1489 public SetValues<Conjunction<Graph>> set( final Name propertyName ) {
1490 return new SetValues<Conjunction<Graph>>() {
1491 public SetValuesTo<Conjunction<Graph>> on( final Location location ) {
1492 return new SetValuesTo<Conjunction<Graph>>() {
1493 public Conjunction<Graph> to( Node value ) {
1494 Reference ref = (Reference)convertReferenceValue(value);
1495 Property property = getContext().getPropertyFactory().create(propertyName, ref);
1496 requests.setProperty(location, getCurrentWorkspaceName(), property);
1497 return nextGraph;
1498 }
1499
1500 public Conjunction<Graph> to( Location value ) {
1501 Reference ref = (Reference)convertReferenceValue(value);
1502 Property property = getContext().getPropertyFactory().create(propertyName, ref);
1503 requests.setProperty(location, getCurrentWorkspaceName(), property);
1504 return nextGraph;
1505 }
1506
1507 protected Conjunction<Graph> toValue( Object value ) {
1508 Property property = getContext().getPropertyFactory().create(propertyName, value);
1509 requests.setProperty(location, getCurrentWorkspaceName(), property);
1510 return nextGraph;
1511 }
1512
1513 public Conjunction<Graph> to( String value ) {
1514 return toValue(value);
1515 }
1516
1517 public Conjunction<Graph> to( int value ) {
1518 return toValue(Integer.valueOf(value));
1519 }
1520
1521 public Conjunction<Graph> to( long value ) {
1522 return toValue(Long.valueOf(value));
1523 }
1524
1525 public Conjunction<Graph> to( boolean value ) {
1526 return toValue(Boolean.valueOf(value));
1527 }
1528
1529 public Conjunction<Graph> to( float value ) {
1530 return toValue(Float.valueOf(value));
1531 }
1532
1533 public Conjunction<Graph> to( double value ) {
1534 return toValue(Double.valueOf(value));
1535 }
1536
1537 public Conjunction<Graph> to( BigDecimal value ) {
1538 return toValue(value);
1539 }
1540
1541 public Conjunction<Graph> to( Calendar value ) {
1542 return toValue(value);
1543 }
1544
1545 public Conjunction<Graph> to( Date value ) {
1546 return toValue(value);
1547 }
1548
1549 public Conjunction<Graph> to( DateTime value ) {
1550 return toValue(value);
1551 }
1552
1553 public Conjunction<Graph> to( Name value ) {
1554 return toValue(value);
1555 }
1556
1557 public Conjunction<Graph> to( Path value ) {
1558 return toValue(value);
1559 }
1560
1561 public Conjunction<Graph> to( Reference value ) {
1562 return toValue(value);
1563 }
1564
1565 public Conjunction<Graph> to( URI value ) {
1566 return toValue(value);
1567 }
1568
1569 public Conjunction<Graph> to( UUID value ) {
1570 return toValue(value);
1571 }
1572
1573 public Conjunction<Graph> to( Binary value ) {
1574 return toValue(value);
1575 }
1576
1577 public Conjunction<Graph> to( byte[] value ) {
1578 return toValue(value);
1579 }
1580
1581 public Conjunction<Graph> to( InputStream stream,
1582 long approximateLength ) {
1583 Binary value = getContext().getValueFactories().getBinaryFactory().create(stream, approximateLength);
1584 return toValue(value);
1585 }
1586
1587 public Conjunction<Graph> to( Reader reader,
1588 long approximateLength ) {
1589 Binary value = getContext().getValueFactories().getBinaryFactory().create(reader, approximateLength);
1590 return toValue(value);
1591 }
1592
1593 public Conjunction<Graph> to( Object value ) {
1594 value = convertReferenceValue(value);
1595 Property property = getContext().getPropertyFactory().create(propertyName, value);
1596 requests.setProperty(location, getCurrentWorkspaceName(), property);
1597 return nextGraph;
1598 }
1599
1600 public Conjunction<Graph> to( Object firstValue,
1601 Object... otherValues ) {
1602 firstValue = convertReferenceValue(firstValue);
1603 for (int i = 0, len = otherValues.length; i != len; ++i) {
1604 otherValues[i] = convertReferenceValue(otherValues[i]);
1605 }
1606 Property property = getContext().getPropertyFactory().create(propertyName, firstValue, otherValues);
1607 requests.setProperty(location, getCurrentWorkspaceName(), property);
1608 return nextGraph;
1609 }
1610
1611 public Conjunction<Graph> to( Object[] values ) {
1612 for (int i = 0, len = values.length; i != len; ++i) {
1613 values[i] = convertReferenceValue(values[i]);
1614 }
1615 Property property = getContext().getPropertyFactory().create(propertyName, values);
1616 requests.setProperty(location, getCurrentWorkspaceName(), property);
1617 return nextGraph;
1618 }
1619
1620 public Conjunction<Graph> to( Iterable<?> values ) {
1621 List<Object> valueList = new LinkedList<Object>();
1622 for (Object value : values) {
1623 value = convertReferenceValue(value);
1624 valueList.add(value);
1625 }
1626 Property property = getContext().getPropertyFactory().create(propertyName, valueList);
1627 requests.setProperty(location, getCurrentWorkspaceName(), property);
1628 return nextGraph;
1629 }
1630
1631 public Conjunction<Graph> to( Iterator<?> values ) {
1632 List<Object> valueList = new LinkedList<Object>();
1633 while (values.hasNext()) {
1634 Object value = values.next();
1635 valueList.add(value);
1636 }
1637 Property property = getContext().getPropertyFactory().create(propertyName, valueList);
1638 requests.setProperty(location, getCurrentWorkspaceName(), property);
1639 return nextGraph;
1640 }
1641 };
1642 }
1643
1644 public SetValuesTo<Conjunction<Graph>> on( String path ) {
1645 return on(Location.create(createPath(path)));
1646 }
1647
1648 public SetValuesTo<Conjunction<Graph>> on( Path path ) {
1649 return on(Location.create(path));
1650 }
1651
1652 public SetValuesTo<Conjunction<Graph>> on( Property idProperty ) {
1653 return on(Location.create(idProperty));
1654 }
1655
1656 public SetValuesTo<Conjunction<Graph>> on( Property firstIdProperty,
1657 Property... additionalIdProperties ) {
1658 return on(Location.create(firstIdProperty, additionalIdProperties));
1659 }
1660
1661 public SetValuesTo<Conjunction<Graph>> on( Iterable<Property> idProperties ) {
1662 return on(Location.create(idProperties));
1663 }
1664
1665 public SetValuesTo<Conjunction<Graph>> on( UUID uuid ) {
1666 return on(Location.create(uuid));
1667 }
1668
1669 public On<Conjunction<Graph>> to( Node node ) {
1670 Reference value = (Reference)convertReferenceValue(node);
1671 return set(getContext().getPropertyFactory().create(propertyName, value));
1672 }
1673
1674 public On<Conjunction<Graph>> to( Location location ) {
1675 Reference value = (Reference)convertReferenceValue(location);
1676 return set(getContext().getPropertyFactory().create(propertyName, value));
1677 }
1678
1679 protected On<Conjunction<Graph>> toValue( Object value ) {
1680 return set(getContext().getPropertyFactory().create(propertyName, value));
1681 }
1682
1683 public On<Conjunction<Graph>> to( String value ) {
1684 return toValue(value);
1685 }
1686
1687 public On<Conjunction<Graph>> to( int value ) {
1688 return toValue(Integer.valueOf(value));
1689 }
1690
1691 public On<Conjunction<Graph>> to( long value ) {
1692 return toValue(Long.valueOf(value));
1693 }
1694
1695 public On<Conjunction<Graph>> to( boolean value ) {
1696 return toValue(Boolean.valueOf(value));
1697 }
1698
1699 public On<Conjunction<Graph>> to( float value ) {
1700 return toValue(Float.valueOf(value));
1701 }
1702
1703 public On<Conjunction<Graph>> to( double value ) {
1704 return toValue(Double.valueOf(value));
1705 }
1706
1707 public On<Conjunction<Graph>> to( BigDecimal value ) {
1708 return toValue(value);
1709 }
1710
1711 public On<Conjunction<Graph>> to( Calendar value ) {
1712 return toValue(value);
1713 }
1714
1715 public On<Conjunction<Graph>> to( Date value ) {
1716 return toValue(value);
1717 }
1718
1719 public On<Conjunction<Graph>> to( DateTime value ) {
1720 return toValue(value);
1721 }
1722
1723 public On<Conjunction<Graph>> to( Name value ) {
1724 return toValue(value);
1725 }
1726
1727 public On<Conjunction<Graph>> to( Path value ) {
1728 return toValue(value);
1729 }
1730
1731 public On<Conjunction<Graph>> to( Reference value ) {
1732 return toValue(value);
1733 }
1734
1735 public On<Conjunction<Graph>> to( URI value ) {
1736 return toValue(value);
1737 }
1738
1739 public On<Conjunction<Graph>> to( UUID value ) {
1740 return toValue(value);
1741 }
1742
1743 public On<Conjunction<Graph>> to( Binary value ) {
1744 return toValue(value);
1745 }
1746
1747 public On<Conjunction<Graph>> to( byte[] value ) {
1748 return toValue(value);
1749 }
1750
1751 public On<Conjunction<Graph>> to( InputStream stream,
1752 long approximateLength ) {
1753 Binary value = getContext().getValueFactories().getBinaryFactory().create(stream, approximateLength);
1754 return toValue(value);
1755 }
1756
1757 public On<Conjunction<Graph>> to( Reader reader,
1758 long approximateLength ) {
1759 Binary value = getContext().getValueFactories().getBinaryFactory().create(reader, approximateLength);
1760 return toValue(value);
1761 }
1762
1763 public On<Conjunction<Graph>> to( Object value ) {
1764 value = convertReferenceValue(value);
1765 return set(getContext().getPropertyFactory().create(propertyName, value));
1766 }
1767
1768 public On<Conjunction<Graph>> to( Object firstValue,
1769 Object... otherValues ) {
1770 firstValue = convertReferenceValue(firstValue);
1771 for (int i = 0, len = otherValues.length; i != len; ++i) {
1772 otherValues[i] = convertReferenceValue(otherValues[i]);
1773 }
1774 return set(getContext().getPropertyFactory().create(propertyName, firstValue, otherValues));
1775 }
1776
1777 public On<Conjunction<Graph>> to( Object[] values ) {
1778 for (int i = 0, len = values.length; i != len; ++i) {
1779 values[i] = convertReferenceValue(values[i]);
1780 }
1781 return set(getContext().getPropertyFactory().create(propertyName, values));
1782 }
1783
1784 public On<Conjunction<Graph>> to( Iterable<?> values ) {
1785 List<Object> valueList = new LinkedList<Object>();
1786 for (Object value : values) {
1787 value = convertReferenceValue(value);
1788 valueList.add(value);
1789 }
1790 return set(getContext().getPropertyFactory().create(propertyName, valueList));
1791 }
1792
1793 public On<Conjunction<Graph>> to( Iterator<?> values ) {
1794 List<Object> valueList = new LinkedList<Object>();
1795 while (values.hasNext()) {
1796 Object value = values.next();
1797 valueList.add(value);
1798 }
1799 return set(getContext().getPropertyFactory().create(propertyName, valueList));
1800 }
1801 };
1802 }
1803
1804
1805
1806
1807
1808
1809
1810 public On<Conjunction<Graph>> remove( final Name... propertyNames ) {
1811 return new On<Conjunction<Graph>>() {
1812 public Conjunction<Graph> on( Location location ) {
1813 requests.removeProperties(location, getCurrentWorkspaceName(), propertyNames);
1814 return nextGraph;
1815 }
1816
1817 public Conjunction<Graph> on( String path ) {
1818 return on(Location.create(createPath(path)));
1819 }
1820
1821 public Conjunction<Graph> on( Path path ) {
1822 return on(Location.create(path));
1823 }
1824
1825 public Conjunction<Graph> on( Property idProperty ) {
1826 return on(Location.create(idProperty));
1827 }
1828
1829 public Conjunction<Graph> on( Property firstIdProperty,
1830 Property... additionalIdProperties ) {
1831 return on(Location.create(firstIdProperty, additionalIdProperties));
1832 }
1833
1834 public Conjunction<Graph> on( Iterable<Property> idProperties ) {
1835 return on(Location.create(idProperties));
1836 }
1837
1838 public Conjunction<Graph> on( UUID uuid ) {
1839 return on(Location.create(uuid));
1840 }
1841 };
1842 }
1843
1844
1845
1846
1847
1848
1849
1850 public On<Conjunction<Graph>> remove( final String... propertyNames ) {
1851 NameFactory nameFactory = getContext().getValueFactories().getNameFactory();
1852 int number = propertyNames.length;
1853 final Name[] names = new Name[number];
1854 for (int i = 0; i != number; ++i) {
1855 names[i] = nameFactory.create(propertyNames[i]);
1856 }
1857 return new On<Conjunction<Graph>>() {
1858 public Conjunction<Graph> on( Location location ) {
1859 requests.removeProperties(location, getCurrentWorkspaceName(), names);
1860 return nextGraph;
1861 }
1862
1863 public Conjunction<Graph> on( String path ) {
1864 return on(Location.create(createPath(path)));
1865 }
1866
1867 public Conjunction<Graph> on( Path path ) {
1868 return on(Location.create(path));
1869 }
1870
1871 public Conjunction<Graph> on( Property idProperty ) {
1872 return on(Location.create(idProperty));
1873 }
1874
1875 public Conjunction<Graph> on( Property firstIdProperty,
1876 Property... additionalIdProperties ) {
1877 return on(Location.create(firstIdProperty, additionalIdProperties));
1878 }
1879
1880 public Conjunction<Graph> on( Iterable<Property> idProperties ) {
1881 return on(Location.create(idProperties));
1882 }
1883
1884 public Conjunction<Graph> on( UUID uuid ) {
1885 return on(Location.create(uuid));
1886 }
1887 };
1888 }
1889
1890
1891
1892
1893
1894
1895
1896 public On<Collection<Property>> getProperties() {
1897 return new On<Collection<Property>>() {
1898 public Collection<Property> on( Location location ) {
1899 return requests.readAllProperties(location, getCurrentWorkspaceName()).getProperties();
1900 }
1901
1902 public Collection<Property> on( String path ) {
1903 return on(Location.create(createPath(path)));
1904 }
1905
1906 public Collection<Property> on( Path path ) {
1907 return on(Location.create(path));
1908 }
1909
1910 public Collection<Property> on( Property idProperty ) {
1911 return on(Location.create(idProperty));
1912 }
1913
1914 public Collection<Property> on( Property firstIdProperty,
1915 Property... additionalIdProperties ) {
1916 return on(Location.create(firstIdProperty, additionalIdProperties));
1917 }
1918
1919 public Collection<Property> on( Iterable<Property> idProperties ) {
1920 return on(Location.create(idProperties));
1921 }
1922
1923 public Collection<Property> on( UUID uuid ) {
1924 return on(Location.create(uuid));
1925 }
1926 };
1927 }
1928
1929
1930
1931
1932
1933
1934
1935
1936 public On<Map<Name, Property>> getPropertiesByName() {
1937 return new On<Map<Name, Property>>() {
1938 public Map<Name, Property> on( Location location ) {
1939 return requests.readAllProperties(location, getCurrentWorkspaceName()).getPropertiesByName();
1940 }
1941
1942 public Map<Name, Property> on( String path ) {
1943 return on(Location.create(createPath(path)));
1944 }
1945
1946 public Map<Name, Property> on( Path path ) {
1947 return on(Location.create(path));
1948 }
1949
1950 public Map<Name, Property> on( Property idProperty ) {
1951 return on(Location.create(idProperty));
1952 }
1953
1954 public Map<Name, Property> on( Property firstIdProperty,
1955 Property... additionalIdProperties ) {
1956 return on(Location.create(firstIdProperty, additionalIdProperties));
1957 }
1958
1959 public Map<Name, Property> on( Iterable<Property> idProperties ) {
1960 return on(Location.create(idProperties));
1961 }
1962
1963 public Map<Name, Property> on( UUID uuid ) {
1964 return on(Location.create(uuid));
1965 }
1966 };
1967 }
1968
1969
1970
1971
1972
1973
1974
1975
1976 public Children<List<Location>> getChildren() {
1977 return new Children<List<Location>>() {
1978 public List<Location> of( String path ) {
1979 return of(Location.create(createPath(path)));
1980 }
1981
1982 public List<Location> of( Path path ) {
1983 return of(Location.create(path));
1984 }
1985
1986 public List<Location> of( Property idProperty ) {
1987 return of(Location.create(idProperty));
1988 }
1989
1990 public List<Location> of( Property firstIdProperty,
1991 Property... additionalIdProperties ) {
1992 return of(Location.create(firstIdProperty, additionalIdProperties));
1993 }
1994
1995 public List<Location> of( Iterable<Property> idProperties ) {
1996 return of(Location.create(idProperties));
1997 }
1998
1999 public List<Location> of( UUID uuid ) {
2000 return of(Location.create(uuid));
2001 }
2002
2003 public List<Location> of( Location at ) {
2004 return requests.readAllChildren(at, getCurrentWorkspaceName()).getChildren();
2005 }
2006
2007 public BlockOfChildren<List<Location>> inBlockOf( final int blockSize ) {
2008 return new BlockOfChildren<List<Location>>() {
2009 public Under<List<Location>> startingAt( final int startingIndex ) {
2010 return new Under<List<Location>>() {
2011 public List<Location> under( String path ) {
2012 return under(Location.create(createPath(path)));
2013 }
2014
2015 public List<Location> under( Path path ) {
2016 return under(Location.create(path));
2017 }
2018
2019 public List<Location> under( Property idProperty ) {
2020 return under(Location.create(idProperty));
2021 }
2022
2023 public List<Location> under( Property firstIdProperty,
2024 Property... additionalIdProperties ) {
2025 return under(Location.create(firstIdProperty, additionalIdProperties));
2026 }
2027
2028 public List<Location> under( UUID uuid ) {
2029 return under(Location.create(uuid));
2030 }
2031
2032 public List<Location> under( Location at ) {
2033 return requests.readBlockOfChildren(at, getCurrentWorkspaceName(), startingIndex, blockSize)
2034 .getChildren();
2035 }
2036 };
2037 }
2038
2039 public List<Location> startingAfter( final Location previousSibling ) {
2040 return requests.readNextBlockOfChildren(previousSibling, getCurrentWorkspaceName(), blockSize)
2041 .getChildren();
2042 }
2043
2044 public List<Location> startingAfter( String pathOfPreviousSibling ) {
2045 return startingAfter(Location.create(createPath(pathOfPreviousSibling)));
2046 }
2047
2048 public List<Location> startingAfter( Path pathOfPreviousSibling ) {
2049 return startingAfter(Location.create(pathOfPreviousSibling));
2050 }
2051
2052 public List<Location> startingAfter( UUID uuidOfPreviousSibling ) {
2053 return startingAfter(Location.create(uuidOfPreviousSibling));
2054 }
2055
2056 public List<Location> startingAfter( Property idPropertyOfPreviousSibling ) {
2057 return startingAfter(Location.create(idPropertyOfPreviousSibling));
2058 }
2059
2060 public List<Location> startingAfter( Property firstIdProperyOfPreviousSibling,
2061 Property... additionalIdPropertiesOfPreviousSibling ) {
2062 return startingAfter(Location.create(firstIdProperyOfPreviousSibling,
2063 additionalIdPropertiesOfPreviousSibling));
2064 }
2065 };
2066 }
2067 };
2068 }
2069
2070
2071
2072
2073
2074
2075
2076
2077 public On<Property> getProperty( final String name ) {
2078 Name nameObj = context.getValueFactories().getNameFactory().create(name);
2079 return getProperty(nameObj);
2080 }
2081
2082
2083
2084
2085
2086
2087
2088
2089 public OnMultiple<Property> getProperty( final Name name ) {
2090 CheckArg.isNotNull(name, "name");
2091 return new OnMultiple<Property>() {
2092 public Property on( String path ) {
2093 return on(Location.create(createPath(path)));
2094 }
2095
2096 public Property on( Path path ) {
2097 return on(Location.create(path));
2098 }
2099
2100 public Property on( Property idProperty ) {
2101 return on(Location.create(idProperty));
2102 }
2103
2104 public Property on( Property firstIdProperty,
2105 Property... additionalIdProperties ) {
2106 return on(Location.create(firstIdProperty, additionalIdProperties));
2107 }
2108
2109 public Property on( Iterable<Property> idProperties ) {
2110 return on(Location.create(idProperties));
2111 }
2112
2113 public Property on( UUID uuid ) {
2114 return on(Location.create(uuid));
2115 }
2116
2117 public Property on( Location at ) {
2118 return requests.readProperty(at, getCurrentWorkspaceName(), name).getProperty();
2119 }
2120
2121 public Map<Location, Property> on( Collection<Location> locations ) {
2122 CheckArg.isNotNull(locations, "locations");
2123 final List<ReadPropertyRequest> requests = new LinkedList<ReadPropertyRequest>();
2124 String workspace = getCurrentWorkspaceName();
2125 for (Location location : locations) {
2126 requests.add(new ReadPropertyRequest(location, workspace, name));
2127 }
2128 return execute(requests);
2129 }
2130
2131 public Map<Location, Property> on( Location first,
2132 Location... additional ) {
2133 CheckArg.isNotNull(first, "first");
2134 final List<ReadPropertyRequest> requests = new LinkedList<ReadPropertyRequest>();
2135 String workspace = getCurrentWorkspaceName();
2136 requests.add(new ReadPropertyRequest(first, workspace, name));
2137 for (Location location : additional) {
2138 requests.add(new ReadPropertyRequest(location, workspace, name));
2139 }
2140 return execute(requests);
2141 }
2142
2143 public Map<Location, Property> on( String first,
2144 String... additional ) {
2145 CheckArg.isNotNull(first, "first");
2146 final List<ReadPropertyRequest> requests = new LinkedList<ReadPropertyRequest>();
2147 String workspace = getCurrentWorkspaceName();
2148 requests.add(new ReadPropertyRequest(Location.create(createPath(first)), workspace, name));
2149 for (String path : additional) {
2150 requests.add(new ReadPropertyRequest(Location.create(createPath(path)), workspace, name));
2151 }
2152 return execute(requests);
2153 }
2154
2155 public Map<Location, Property> on( Path first,
2156 Path... additional ) {
2157 CheckArg.isNotNull(first, "first");
2158 final List<ReadPropertyRequest> requests = new LinkedList<ReadPropertyRequest>();
2159 String workspace = getCurrentWorkspaceName();
2160 requests.add(new ReadPropertyRequest(Location.create(first), workspace, name));
2161 for (Path path : additional) {
2162 requests.add(new ReadPropertyRequest(Location.create(path), workspace, name));
2163 }
2164 return execute(requests);
2165 }
2166
2167 public Map<Location, Property> on( UUID first,
2168 UUID... additional ) {
2169 CheckArg.isNotNull(first, "first");
2170 final List<ReadPropertyRequest> requests = new LinkedList<ReadPropertyRequest>();
2171 String workspace = getCurrentWorkspaceName();
2172 requests.add(new ReadPropertyRequest(Location.create(first), workspace, name));
2173 for (UUID uuid : additional) {
2174 requests.add(new ReadPropertyRequest(Location.create(uuid), workspace, name));
2175 }
2176 return execute(requests);
2177 }
2178
2179 protected Map<Location, Property> execute( List<ReadPropertyRequest> requests ) {
2180
2181 Request composite = CompositeRequest.with(requests);
2182 Graph.this.execute(composite);
2183 Map<Location, Property> results = new HashMap<Location, Property>();
2184 for (ReadPropertyRequest request : requests) {
2185 Property property = request.getProperty();
2186 Location location = request.getActualLocationOfNode();
2187 results.put(location, property);
2188 }
2189 return results;
2190 }
2191 };
2192 }
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202 public OnMultiple<Map<Name, Property>> getProperties( final Name... names ) {
2203 return new OnMultiple<Map<Name, Property>>() {
2204 public Map<Name, Property> on( String path ) {
2205 return on(Location.create(createPath(path)));
2206 }
2207
2208 public Map<Name, Property> on( Path path ) {
2209 return on(Location.create(path));
2210 }
2211
2212 public Map<Name, Property> on( Property idProperty ) {
2213 return on(Location.create(idProperty));
2214 }
2215
2216 public Map<Name, Property> on( Property firstIdProperty,
2217 Property... additionalIdProperties ) {
2218 return on(Location.create(firstIdProperty, additionalIdProperties));
2219 }
2220
2221 public Map<Name, Property> on( Iterable<Property> idProperties ) {
2222 return on(Location.create(idProperties));
2223 }
2224
2225 public Map<Name, Property> on( UUID uuid ) {
2226 return on(Location.create(uuid));
2227 }
2228
2229 public Map<Name, Property> on( Location at ) {
2230 final List<ReadPropertyRequest> requests = new LinkedList<ReadPropertyRequest>();
2231 String workspace = getCurrentWorkspaceName();
2232 for (Name propertyName : names) {
2233 requests.add(new ReadPropertyRequest(at, workspace, propertyName));
2234 }
2235
2236 Request composite = CompositeRequest.with(requests);
2237 Graph.this.execute(composite);
2238 Map<Name, Property> results = new HashMap<Name, Property>();
2239 for (ReadPropertyRequest request : requests) {
2240 Property property = request.getProperty();
2241 results.put(property.getName(), property);
2242 }
2243 return results;
2244 }
2245
2246 public Map<Location, Map<Name, Property>> on( Collection<Location> locations ) {
2247 CheckArg.isNotNull(locations, "locations");
2248 final List<ReadPropertyRequest> requests = new LinkedList<ReadPropertyRequest>();
2249 String workspace = getCurrentWorkspaceName();
2250 for (Location location : locations) {
2251 if (location == null) continue;
2252 for (Name propertyName : names) {
2253 if (propertyName == null) continue;
2254 requests.add(new ReadPropertyRequest(location, workspace, propertyName));
2255 }
2256 }
2257 return execute(requests);
2258 }
2259
2260
2261
2262
2263
2264
2265 public Map<Location, Map<Name, Property>> on( Location first,
2266 Location... additional ) {
2267 CheckArg.isNotNull(first, "first");
2268 final List<ReadPropertyRequest> requests = new LinkedList<ReadPropertyRequest>();
2269 String workspace = getCurrentWorkspaceName();
2270 for (Location location : additional) {
2271 if (location == null) continue;
2272 for (Name propertyName : names) {
2273 if (propertyName == null) continue;
2274 requests.add(new ReadPropertyRequest(first, workspace, propertyName));
2275 requests.add(new ReadPropertyRequest(location, workspace, propertyName));
2276 }
2277 }
2278 return execute(requests);
2279 }
2280
2281
2282
2283
2284
2285
2286
2287 public Map<Location, Map<Name, Property>> on( Path first,
2288 Path... additional ) {
2289 CheckArg.isNotNull(first, "first");
2290 List<Location> locations = new LinkedList<Location>();
2291 locations.add(Location.create(first));
2292 for (Path path : additional) {
2293 if (path != null) locations.add(Location.create(path));
2294 }
2295 return on(locations);
2296 }
2297
2298
2299
2300
2301
2302
2303 public Map<Location, Map<Name, Property>> on( String first,
2304 String... additional ) {
2305 CheckArg.isNotNull(first, "first");
2306 List<Location> locations = new LinkedList<Location>();
2307 locations.add(Location.create(createPath(first)));
2308 for (String path : additional) {
2309 if (path != null) locations.add(Location.create(createPath(path)));
2310 }
2311 return on(locations);
2312 }
2313
2314
2315
2316
2317
2318
2319 public Map<Location, Map<Name, Property>> on( UUID first,
2320 UUID... additional ) {
2321 CheckArg.isNotNull(first, "first");
2322 List<Location> locations = new LinkedList<Location>();
2323 locations.add(Location.create(first));
2324 for (UUID uuid : additional) {
2325 if (uuid != null) locations.add(Location.create(uuid));
2326 }
2327 return on(locations);
2328 }
2329
2330 protected Map<Location, Map<Name, Property>> execute( List<ReadPropertyRequest> requests ) {
2331
2332 Request composite = CompositeRequest.with(requests);
2333 Graph.this.execute(composite);
2334 Map<Location, Map<Name, Property>> results = new HashMap<Location, Map<Name, Property>>();
2335 for (ReadPropertyRequest request : requests) {
2336 Property property = request.getProperty();
2337
2338
2339 if (property == null) continue;
2340
2341 Location location = request.getActualLocationOfNode();
2342 Map<Name, Property> properties = results.get(location);
2343 if (properties == null) {
2344 properties = new HashMap<Name, Property>();
2345 results.put(location, properties);
2346 }
2347 properties.put(property.getName(), property);
2348 }
2349 return results;
2350 }
2351 };
2352 }
2353
2354
2355
2356
2357
2358
2359
2360 public Node getNodeAt( UUID uuid ) {
2361 return getNodeAt(Location.create(uuid));
2362 }
2363
2364
2365
2366
2367
2368
2369
2370 public Node getNodeAt( Location location ) {
2371 return new GraphNode(requests.readNode(location, getCurrentWorkspaceName()));
2372 }
2373
2374
2375
2376
2377
2378
2379
2380 public Node getNodeAt( String path ) {
2381 return getNodeAt(Location.create(createPath(path)));
2382 }
2383
2384
2385
2386
2387
2388
2389
2390 public Node getNodeAt( Path path ) {
2391 return getNodeAt(Location.create(path));
2392 }
2393
2394
2395
2396
2397
2398
2399
2400 public Node getNodeAt( Property idProperty ) {
2401 return getNodeAt(Location.create(idProperty));
2402 }
2403
2404
2405
2406
2407
2408
2409
2410
2411 public Node getNodeAt( Property firstIdProperty,
2412 Property... additionalIdProperties ) {
2413 return getNodeAt(Location.create(firstIdProperty, additionalIdProperties));
2414 }
2415
2416
2417
2418
2419
2420
2421
2422 public Node getNodeAt( Iterable<Property> idProperties ) {
2423 return getNodeAt(Location.create(idProperties));
2424 }
2425
2426
2427
2428
2429
2430
2431
2432
2433 public Node resolve( Reference reference ) {
2434 CheckArg.isNotNull(reference, "reference");
2435 UUID uuid = context.getValueFactories().getUuidFactory().create(reference);
2436 return getNodeAt(uuid);
2437 }
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448 public At<Subgraph> getSubgraphOfDepth( final int depth ) {
2449 return new At<Subgraph>() {
2450 public Subgraph at( Location location ) {
2451 return new SubgraphResults(requests.readBranch(location, getCurrentWorkspaceName(), depth));
2452 }
2453
2454 public Subgraph at( String path ) {
2455 return at(Location.create(createPath(path)));
2456 }
2457
2458 public Subgraph at( Path path ) {
2459 return at(Location.create(path));
2460 }
2461
2462 public Subgraph at( UUID uuid ) {
2463 return at(Location.create(uuid));
2464 }
2465
2466 public Subgraph at( Property idProperty ) {
2467 return at(Location.create(idProperty));
2468 }
2469
2470 public Subgraph at( Property firstIdProperty,
2471 Property... additionalIdProperties ) {
2472 return at(Location.create(firstIdProperty, additionalIdProperties));
2473 }
2474
2475 public Subgraph at( Iterable<Property> idProperties ) {
2476 return at(Location.create(idProperties));
2477 }
2478 };
2479 }
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490 public QueryResults search( final String fullTextSearchExpression,
2491 int maxResults,
2492 int offset ) {
2493 FullTextSearchRequest request = requests.search(getCurrentWorkspaceName(), fullTextSearchExpression, maxResults, offset);
2494 QueryResults results = new org.modeshape.graph.query.process.QueryResults(request.getResultColumns(),
2495 request.getStatistics(), request.getTuples());
2496 return results;
2497 }
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507 public BuildQuery query( final QueryCommand query,
2508 final Schemata schemata ) {
2509 CheckArg.isNotNull(query, "query");
2510 CheckArg.isNotNull(schemata, "schemata");
2511 return new BuildQuery() {
2512 private PlanHints hints;
2513 private Problems problems;
2514 private Map<String, Object> variables;
2515
2516
2517
2518
2519
2520
2521 public BuildQuery using( Map<String, Object> variables ) {
2522 CheckArg.isNotNull(variables, "variables");
2523 if (this.variables == null) this.variables = new HashMap<String, Object>();
2524 this.variables.putAll(variables);
2525 return this;
2526 }
2527
2528
2529
2530
2531
2532
2533 public BuildQuery using( String variableName,
2534 Object variableValue ) {
2535 CheckArg.isNotNull(variableName, "variableName");
2536 if (this.variables == null) this.variables = new HashMap<String, Object>();
2537 this.variables.put(variableName, variableValue);
2538 return this;
2539 }
2540
2541
2542
2543
2544
2545
2546 public BuildQuery using( PlanHints hints ) {
2547 this.hints = hints;
2548 return this;
2549 }
2550
2551
2552
2553
2554
2555
2556 public QueryResults execute() {
2557 Batch batch = batch();
2558 TypeSystem typeSystem = getContext().getValueFactories().getTypeSystem();
2559 QueryContext context = new GraphQueryContext(schemata, typeSystem, hints, problems, variables, batch);
2560 QueryEngine engine = getQueryEngine();
2561 return engine.execute(context, query);
2562 }
2563 };
2564 }
2565
2566 protected QueryEngine getQueryEngine() {
2567 if (queryEngine == null) {
2568 queryEngine = getQueryEngine(new RuleBasedOptimizer());
2569 }
2570 return queryEngine;
2571 }
2572
2573 protected QueryEngine getQueryEngine( Optimizer optimizer ) {
2574 Planner planner = new CanonicalPlanner();
2575 Processor processor = new QueryProcessor() {
2576
2577
2578
2579
2580
2581
2582
2583 @Override
2584 protected ProcessingComponent createAccessComponent( QueryCommand originalQuery,
2585 QueryContext context,
2586 PlanNode accessNode,
2587 Columns resultColumns,
2588 Analyzer analyzer ) {
2589 return new AccessQueryProcessor(getSourceName(), getCurrentWorkspaceName(), context, resultColumns, accessNode);
2590 }
2591
2592
2593
2594
2595
2596
2597 @Override
2598 protected void preExecute( QueryContext context ) {
2599
2600
2601 ((GraphQueryContext)context).getBatch().execute();
2602 }
2603 };
2604 return new QueryEngine(planner, optimizer, processor);
2605 }
2606
2607 protected class GraphQueryContext extends QueryContext {
2608 private final Batch batch;
2609
2610 protected GraphQueryContext( Schemata schemata,
2611 TypeSystem typeSystem,
2612 PlanHints hints,
2613 Problems problems,
2614 Map<String, Object> variables,
2615 Batch batch ) {
2616 super(schemata, typeSystem, hints, problems, variables);
2617 this.batch = batch;
2618 assert this.batch != null;
2619 }
2620
2621
2622
2623
2624
2625
2626 public Batch getBatch() {
2627 return batch;
2628 }
2629 }
2630
2631 protected static class AccessQueryProcessor extends AbstractAccessComponent {
2632 private final AccessQueryRequest accessRequest;
2633 private final String graphSourceName;
2634
2635 protected AccessQueryProcessor( String graphSourceName,
2636 String workspaceName,
2637 QueryContext context,
2638 Columns columns,
2639 PlanNode accessNode ) {
2640 super(context, columns, accessNode);
2641 this.graphSourceName = graphSourceName;
2642 accessRequest = new AccessQueryRequest(workspaceName, sourceName, getColumns(), andedConstraints, limit,
2643 context.getSchemata(), context.getVariables());
2644 ((GraphQueryContext)context).getBatch().requestQueue.submit(accessRequest);
2645 }
2646
2647
2648
2649
2650
2651
2652 public AccessQueryRequest getAccessRequest() {
2653 return accessRequest;
2654 }
2655
2656
2657
2658
2659
2660
2661 @Override
2662 public List<Object[]> execute() {
2663 if (accessRequest.getError() != null) {
2664 I18n msg = GraphI18n.errorWhilePerformingQuery;
2665 getContext().getProblems().addError(accessRequest.getError(),
2666 msg,
2667 accessNode.getString(),
2668 accessRequest.workspace(),
2669 graphSourceName,
2670 accessRequest.getError().getLocalizedMessage());
2671 return emptyTuples();
2672 }
2673 return accessRequest.getTuples();
2674 }
2675
2676 }
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686 public ImportInto<Conjunction<Graph>> importXmlFrom( final InputStream stream ) {
2687 CheckArg.isNotNull(stream, "stream");
2688
2689 return new ImportInto<Conjunction<Graph>>() {
2690 private boolean skipRootElement = false;
2691
2692 public ImportInto<Conjunction<Graph>> skippingRootElement( boolean skipRootElement ) {
2693 this.skipRootElement = skipRootElement;
2694 return this;
2695 }
2696
2697 public Conjunction<Graph> into( String path ) throws IOException, SAXException {
2698 return into(Location.create(createPath(path)));
2699 }
2700
2701 public Conjunction<Graph> into( Path path ) throws IOException, SAXException {
2702 return into(Location.create(path));
2703 }
2704
2705 public Conjunction<Graph> into( Property idProperty ) throws IOException, SAXException {
2706 return into(Location.create(idProperty));
2707 }
2708
2709 public Conjunction<Graph> into( Property firstIdProperty,
2710 Property... additionalIdProperties ) throws IOException, SAXException {
2711 return into(Location.create(firstIdProperty, additionalIdProperties));
2712 }
2713
2714 public Conjunction<Graph> into( Iterable<Property> idProperties ) throws IOException, SAXException {
2715 return into(Location.create(idProperties));
2716 }
2717
2718 public Conjunction<Graph> into( UUID uuid ) throws IOException, SAXException {
2719 return into(Location.create(uuid));
2720 }
2721
2722 public Conjunction<Graph> into( Location at ) throws IOException, SAXException {
2723 GraphImporter importer = new GraphImporter(Graph.this);
2724 importer.importXml(stream, at, skipRootElement).execute();
2725 return Graph.this.nextGraph;
2726 }
2727 };
2728 }
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738 public ImportInto<Conjunction<Graph>> importXmlFrom( final URI uri ) {
2739 return new ImportInto<Conjunction<Graph>>() {
2740 private boolean skipRootElement = false;
2741
2742 public ImportInto<Conjunction<Graph>> skippingRootElement( boolean skipRootElement ) {
2743 this.skipRootElement = skipRootElement;
2744 return this;
2745 }
2746
2747 public Conjunction<Graph> into( String path ) throws IOException, SAXException {
2748 return into(Location.create(createPath(path)));
2749 }
2750
2751 public Conjunction<Graph> into( Path path ) throws IOException, SAXException {
2752 return into(Location.create(path));
2753 }
2754
2755 public Conjunction<Graph> into( Property idProperty ) throws IOException, SAXException {
2756 return into(Location.create(idProperty));
2757 }
2758
2759 public Conjunction<Graph> into( Property firstIdProperty,
2760 Property... additionalIdProperties ) throws IOException, SAXException {
2761 return into(Location.create(firstIdProperty, additionalIdProperties));
2762 }
2763
2764 public Conjunction<Graph> into( Iterable<Property> idProperties ) throws IOException, SAXException {
2765 return into(Location.create(idProperties));
2766 }
2767
2768 public Conjunction<Graph> into( UUID uuid ) throws IOException, SAXException {
2769 return into(Location.create(uuid));
2770 }
2771
2772 public Conjunction<Graph> into( Location at ) throws IOException, SAXException {
2773 GraphImporter importer = new GraphImporter(Graph.this);
2774 importer.importXml(uri, at, skipRootElement).execute();
2775 return Graph.this.nextGraph;
2776 }
2777 };
2778 }
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788 public ImportInto<Conjunction<Graph>> importXmlFrom( String pathToFile ) {
2789 CheckArg.isNotNull(pathToFile, "pathToFile");
2790 return importXmlFrom(new File(pathToFile).toURI());
2791 }
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801 public ImportInto<Conjunction<Graph>> importXmlFrom( File file ) {
2802 CheckArg.isNotNull(file, "file");
2803 return importXmlFrom(file.toURI());
2804 }
2805
2806 protected Path createPath( String path ) {
2807 return getContext().getValueFactories().getPathFactory().create(path);
2808 }
2809
2810 protected List<Segment> getSegments( List<Location> locations ) {
2811 List<Segment> segments = new ArrayList<Segment>(locations.size());
2812 for (Location location : locations) {
2813 segments.add(location.getPath().getLastSegment());
2814 }
2815 return segments;
2816 }
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827 public Batch batch() {
2828 return new Batch(new BatchRequestBuilder());
2829 }
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842 public Batch batch( BatchRequestBuilder builder ) {
2843 CheckArg.isNotNull(builder, "builder");
2844 return new Batch(builder);
2845 }
2846
2847
2848
2849
2850
2851
2852 @Immutable
2853 public final class Batch implements Executable<Node> {
2854 protected final BatchRequestBuilder requestQueue;
2855 protected final BatchConjunction nextRequests;
2856 protected final String workspaceName;
2857 protected boolean executed = false;
2858
2859
2860 assert builder != null;
2861 this.requestQueue = builder;
2862 this.workspaceName = Graph.this.getCurrentWorkspaceName();
2863 this.nextRequests = new BatchConjunction() {
2864 public Batch and() {
2865 return Batch.this;
2866 }
2867
2868 public Results execute() {
2869 return Batch.this.execute();
2870 }
2871 };
2872 }
2873
2874
2875
2876
2877
2878
2879 public boolean hasExecuted() {
2880 return executed;
2881 }
2882
2883
2884
2885
2886
2887
2888 public boolean isExecuteRequired() {
2889 return !executed && requestQueue.hasRequests();
2890 }
2891
2892
2893
2894
2895
2896
2897 public Graph getGraph() {
2898 return Graph.this;
2899 }
2900
2901
2902
2903
2904
2905
2906 public String getCurrentWorkspaceName() {
2907 return this.workspaceName;
2908 }
2909
2910 protected final void assertNotExecuted() {
2911 if (executed) {
2912 throw new IllegalStateException(GraphI18n.unableToAddMoreRequestsToAlreadyExecutedBatch.text());
2913 }
2914 }
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928 public Move<BatchConjunction> move( Node from ) {
2929 return move(from.getLocation());
2930 }
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944 public final Move<BatchConjunction> move( Location from ) {
2945 assertNotExecuted();
2946 return new MoveAction<BatchConjunction>(this.nextRequests, from) {
2947 @Override
2948 protected BatchConjunction submit( Locations from,
2949 Location into,
2950 Location before,
2951 Name newName ) {
2952 String workspaceName = getCurrentWorkspaceName();
2953 do {
2954 requestQueue.moveBranch(from.getLocation(), into, before, workspaceName, newName);
2955 } while ((from = from.next()) != null);
2956 return and();
2957 }
2958 };
2959 }
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973 public Move<BatchConjunction> move( String fromPath ) {
2974 return move(Location.create(createPath(fromPath)));
2975 }
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989 public Move<BatchConjunction> move( Path from ) {
2990 return move(Location.create(from));
2991 }
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005 public Move<BatchConjunction> move( UUID from ) {
3006 return move(Location.create(from));
3007 }
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022 public Move<BatchConjunction> move( Property idProperty ) {
3023 return move(Location.create(idProperty));
3024 }
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040 public Move<BatchConjunction> move( Property firstIdProperty,
3041 Property... additionalIdProperties ) {
3042 return move(Location.create(firstIdProperty, additionalIdProperties));
3043 }
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058 public Move<BatchConjunction> move( Iterable<Property> idProperties ) {
3059 return move(Location.create(idProperties));
3060 }
3061
3062
3063
3064
3065
3066
3067
3068 public LockScope<LockTimeout<BatchConjunction>> lock( Node at ) {
3069 return lock(at.getLocation());
3070 }
3071
3072
3073
3074
3075
3076
3077
3078 public LockScope<LockTimeout<BatchConjunction>> lock( String atPath ) {
3079 return lock(Location.create(createPath(atPath)));
3080 }
3081
3082
3083
3084
3085
3086
3087
3088 public LockScope<LockTimeout<BatchConjunction>> lock( Path at ) {
3089 return lock(Location.create(at));
3090 }
3091
3092
3093
3094
3095
3096
3097
3098 public LockScope<LockTimeout<BatchConjunction>> lock( UUID at ) {
3099 return lock(Location.create(at));
3100 }
3101
3102
3103
3104
3105
3106
3107
3108
3109 public LockScope<LockTimeout<BatchConjunction>> lock( Property idProperty ) {
3110 return lock(Location.create(idProperty));
3111 }
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121 public LockScope<LockTimeout<BatchConjunction>> lock( Property firstIdProperty,
3122 Property... additionalIdProperties ) {
3123 return lock(Location.create(firstIdProperty, additionalIdProperties));
3124 }
3125
3126
3127
3128
3129
3130
3131
3132 public LockScope<LockTimeout<BatchConjunction>> lock( Location at ) {
3133 return new LockAction<BatchConjunction>(this.nextRequests, at) {
3134 @Override
3135 protected BatchConjunction submit( Location target,
3136 org.modeshape.graph.request.LockBranchRequest.LockScope lockScope,
3137 long lockTimeoutInMillis ) {
3138 String workspaceName = getCurrentWorkspaceName();
3139 requests.lockBranch(workspaceName, target, lockScope, lockTimeoutInMillis);
3140 return and();
3141 }
3142 };
3143 }
3144
3145
3146
3147
3148
3149
3150
3151 public BatchConjunction unlock( Node at ) {
3152 return unlock(at.getLocation());
3153 }
3154
3155
3156
3157
3158
3159
3160
3161 public BatchConjunction unlock( String atPath ) {
3162 return unlock(Location.create(createPath(atPath)));
3163 }
3164
3165
3166
3167
3168
3169
3170
3171 public BatchConjunction unlock( Path at ) {
3172 return unlock(Location.create(at));
3173 }
3174
3175
3176
3177
3178
3179
3180
3181 public BatchConjunction unlock( UUID at ) {
3182 return unlock(Location.create(at));
3183 }
3184
3185
3186
3187
3188
3189
3190
3191
3192 public BatchConjunction unlock( Property idProperty ) {
3193 return unlock(Location.create(idProperty));
3194 }
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204 public BatchConjunction unlock( Property firstIdProperty,
3205 Property... additionalIdProperties ) {
3206 return unlock(Location.create(firstIdProperty, additionalIdProperties));
3207 }
3208
3209
3210
3211
3212
3213
3214
3215 public BatchConjunction unlock( Location at ) {
3216 requests.unlockBranch(workspaceName, at);
3217 return this.nextRequests;
3218 }
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232 public Clone<BatchConjunction> clone( Node from ) {
3233 return clone(from.getLocation());
3234 }
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248 public Clone<BatchConjunction> clone( Location from ) {
3249 assertNotExecuted();
3250 return new CloneAction<BatchConjunction>(this.nextRequests, from) {
3251 @Override
3252 protected BatchConjunction submit( String fromWorkspaceName,
3253 Location from,
3254 String intoWorkspaceName,
3255 Location into,
3256 Name desiredName,
3257 Segment desiredSegment,
3258 boolean removeExisting ) {
3259 requestQueue.cloneBranch(from,
3260 fromWorkspaceName,
3261 into,
3262 intoWorkspaceName,
3263 desiredName,
3264 desiredSegment,
3265 removeExisting);
3266 return and();
3267 }
3268 };
3269 }
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283 public Clone<BatchConjunction> clone( String fromPath ) {
3284 return clone(Location.create(createPath(fromPath)));
3285 }
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299 public Clone<BatchConjunction> clone( Path from ) {
3300 return clone(Location.create(from));
3301 }
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315 public Clone<BatchConjunction> clone( UUID from ) {
3316 return clone(Location.create(from));
3317 }
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332 public Clone<BatchConjunction> clone( Property idProperty ) {
3333 return clone(Location.create(idProperty));
3334 }
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350 public Clone<BatchConjunction> clone( Property firstIdProperty,
3351 Property... additionalIdProperties ) {
3352 return clone(Location.create(firstIdProperty, additionalIdProperties));
3353 }
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368 public Clone<BatchConjunction> clone( Iterable<Property> idProperties ) {
3369 return clone(Location.create(idProperties));
3370 }
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384 public Copy<BatchConjunction> copy( Node from ) {
3385 return copy(from.getLocation());
3386 }
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400 public Copy<BatchConjunction> copy( Location from ) {
3401 assertNotExecuted();
3402 return new CopyAction<BatchConjunction>(this.nextRequests, from) {
3403 @Override
3404 protected BatchConjunction submit( String fromWorkspaceName,
3405 Locations from,
3406 Location into,
3407 Name copyName ) {
3408
3409 String intoWorkspaceName = getCurrentWorkspaceName();
3410 if (fromWorkspaceName == null) fromWorkspaceName = intoWorkspaceName;
3411 do {
3412 requestQueue.copyBranch(from.getLocation(), fromWorkspaceName, into, intoWorkspaceName, copyName, null);
3413 } while ((from = from.next()) != null);
3414 return and();
3415 }
3416 };
3417 }
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431 public Copy<BatchConjunction> copy( String fromPath ) {
3432 return copy(Location.create(createPath(fromPath)));
3433 }
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447 public Copy<BatchConjunction> copy( Path from ) {
3448 return copy(Location.create(from));
3449 }
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463 public Copy<BatchConjunction> copy( UUID from ) {
3464 return copy(Location.create(from));
3465 }
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480 public Copy<BatchConjunction> copy( Property idProperty ) {
3481 return copy(Location.create(idProperty));
3482 }
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498 public Copy<BatchConjunction> copy( Property firstIdProperty,
3499 Property... additionalIdProperties ) {
3500 return copy(Location.create(firstIdProperty, additionalIdProperties));
3501 }
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516 public Copy<BatchConjunction> copy( Iterable<Property> idProperties ) {
3517 return copy(Location.create(idProperties));
3518 }
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530 public BatchConjunction delete( Node at ) {
3531 return delete(at.getLocation());
3532 }
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544 public BatchConjunction delete( Location at ) {
3545 assertNotExecuted();
3546 this.requestQueue.deleteBranch(at, getCurrentWorkspaceName());
3547 return nextRequests;
3548 }
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560 public BatchConjunction delete( String atPath ) {
3561 return delete(Location.create(createPath(atPath)));
3562 }
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574 public BatchConjunction delete( Path at ) {
3575 return delete(Location.create(at));
3576 }
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588 public BatchConjunction delete( UUID at ) {
3589 return delete(Location.create(at));
3590 }
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602 public BatchConjunction delete( Property idProperty ) {
3603 return delete(Location.create(idProperty));
3604 }
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618 public BatchConjunction delete( Property firstIdProperty,
3619 Property... additionalIdProperties ) {
3620 return delete(Location.create(firstIdProperty, additionalIdProperties));
3621 }
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634 public BatchConjunction delete( Iterable<Property> idProperties ) {
3635 return delete(Location.create(idProperties));
3636 }
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649 public Create<Batch> create( String atPath ) {
3650 return create(createPath(atPath));
3651 }
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665 public Create<Batch> create( String atPath,
3666 Property property ) {
3667 return create(createPath(atPath)).with(property);
3668 }
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683 public Create<Batch> create( String atPath,
3684 Property firstProperty,
3685 Property... additionalProperties ) {
3686 return create(createPath(atPath)).with(firstProperty, additionalProperties);
3687 }
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700 public final Create<Batch> create( Path at ) {
3701 assertNotExecuted();
3702 CheckArg.isNotNull(at, "at");
3703 Path parent = at.getParent();
3704 Name name = at.getLastSegment().getName();
3705 return create(Location.create(parent), name);
3706 }
3707
3708 protected final CreateAction<Batch> create( Location parent,
3709 Name child ) {
3710 return new CreateAction<Batch>(this, parent, getCurrentWorkspaceName(), child) {
3711 @Override
3712 protected Batch submit( Location parent,
3713 String workspaceName,
3714 Name childName,
3715 Collection<Property> properties,
3716 NodeConflictBehavior behavior ) {
3717 requestQueue.createNode(parent, workspaceName, childName, properties.iterator(), behavior);
3718 return Batch.this;
3719 }
3720 };
3721 }
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735 public Create<Batch> create( Path at,
3736 Iterable<Property> properties ) {
3737 Create<Batch> action = create(at);
3738 for (Property property : properties) {
3739 action.and(property);
3740 }
3741 return action;
3742 }
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756 public Create<Batch> create( Path at,
3757 Property property ) {
3758 return create(at).with(property);
3759 }
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774 public Create<Batch> create( Path at,
3775 Property firstProperty,
3776 Property... additionalProperties ) {
3777 return create(at).with(firstProperty, additionalProperties);
3778 }
3779
3780
3781
3782
3783
3784
3785
3786
3787 public CreateNodeNamed<Batch> createUnder( Location parent ) {
3788 CheckArg.isNotNull(parent, "parent");
3789 return new CreateNodeNamedAction<Batch>(this, parent) {
3790 @Override
3791 protected CreateAction<Batch> createWith( Batch batch,
3792 Location parent,
3793 Name childName ) {
3794 return Batch.this.create(parent, childName);
3795 }
3796 };
3797 }
3798
3799 public AddValue<Batch> addValue( Object value ) {
3800 return new AddValueAction<Batch>(this, this.getCurrentWorkspaceName(), value) {
3801
3802 @Override
3803 protected Batch submit( String workspaceName,
3804 Location on,
3805 Name property,
3806 List<Object> values ) {
3807 requests.addValues(workspaceName, on, property, values);
3808 return nextRequests.and();
3809 }
3810 };
3811 }
3812
3813 public RemoveValue<Batch> removeValue( Object value ) {
3814 return new RemoveValueAction<Batch>(this, this.getCurrentWorkspaceName(), value) {
3815
3816 @Override
3817 protected Batch submit( String workspaceName,
3818 Location on,
3819 Name property,
3820 List<Object> values ) {
3821 requests.removeValues(workspaceName, on, property, values);
3822 return nextRequests.and();
3823 }
3824 };
3825 }
3826
3827
3828
3829
3830
3831
3832
3833 public On<BatchConjunction> set( final Property... properties ) {
3834 return new On<BatchConjunction>() {
3835 public BatchConjunction on( Location location ) {
3836 requestQueue.setProperties(location, getCurrentWorkspaceName(), properties);
3837 return nextRequests;
3838 }
3839
3840 public BatchConjunction on( String path ) {
3841 return on(Location.create(createPath(path)));
3842 }
3843
3844 public BatchConjunction on( Path path ) {
3845 return on(Location.create(path));
3846 }
3847
3848 public BatchConjunction on( Property idProperty ) {
3849 return on(Location.create(idProperty));
3850 }
3851
3852 public BatchConjunction on( Property firstIdProperty,
3853 Property... additionalIdProperties ) {
3854 return on(Location.create(firstIdProperty, additionalIdProperties));
3855 }
3856
3857 public BatchConjunction on( Iterable<Property> idProperties ) {
3858 return on(Location.create(idProperties));
3859 }
3860
3861 public BatchConjunction on( UUID uuid ) {
3862 return on(Location.create(uuid));
3863 }
3864 };
3865 }
3866
3867
3868
3869
3870
3871
3872
3873
3874 public SetValues<BatchConjunction> set( String propertyName ) {
3875 Name name = getContext().getValueFactories().getNameFactory().create(propertyName);
3876 return set(name);
3877 }
3878
3879
3880
3881
3882
3883
3884
3885
3886 public SetValues<BatchConjunction> set( final Name propertyName ) {
3887 return new SetValues<BatchConjunction>() {
3888 public SetValuesTo<BatchConjunction> on( final Location location ) {
3889 return new SetValuesTo<BatchConjunction>() {
3890 public BatchConjunction to( Node value ) {
3891 return to(value.getLocation());
3892 }
3893
3894 public BatchConjunction to( Location value ) {
3895 Reference ref = (Reference)convertReferenceValue(value);
3896 Property property = getContext().getPropertyFactory().create(propertyName, ref);
3897 requestQueue.setProperty(location, getCurrentWorkspaceName(), property);
3898 return nextRequests;
3899 }
3900
3901 protected BatchConjunction toValue( Object value ) {
3902 Property property = getContext().getPropertyFactory().create(propertyName, value);
3903 requestQueue.setProperty(location, getCurrentWorkspaceName(), property);
3904 return nextRequests;
3905 }
3906
3907 public BatchConjunction to( String value ) {
3908 return toValue(value);
3909 }
3910
3911 public BatchConjunction to( int value ) {
3912 return toValue(Integer.valueOf(value));
3913 }
3914
3915 public BatchConjunction to( long value ) {
3916 return toValue(Long.valueOf(value));
3917 }
3918
3919 public BatchConjunction to( boolean value ) {
3920 return toValue(Boolean.valueOf(value));
3921 }
3922
3923 public BatchConjunction to( float value ) {
3924 return toValue(Float.valueOf(value));
3925 }
3926
3927 public BatchConjunction to( double value ) {
3928 return toValue(Double.valueOf(value));
3929 }
3930
3931 public BatchConjunction to( BigDecimal value ) {
3932 return toValue(value);
3933 }
3934
3935 public BatchConjunction to( Calendar value ) {
3936 return toValue(value);
3937 }
3938
3939 public BatchConjunction to( Date value ) {
3940 return toValue(value);
3941 }
3942
3943 public BatchConjunction to( DateTime value ) {
3944 return toValue(value);
3945 }
3946
3947 public BatchConjunction to( Name value ) {
3948 return toValue(value);
3949 }
3950
3951 public BatchConjunction to( Path value ) {
3952 return toValue(value);
3953 }
3954
3955 public BatchConjunction to( Reference value ) {
3956 return toValue(value);
3957 }
3958
3959 public BatchConjunction to( URI value ) {
3960 return toValue(value);
3961 }
3962
3963 public BatchConjunction to( UUID value ) {
3964 return toValue(value);
3965 }
3966
3967 public BatchConjunction to( Binary value ) {
3968 return toValue(value);
3969 }
3970
3971 public BatchConjunction to( byte[] value ) {
3972 return toValue(value);
3973 }
3974
3975 public BatchConjunction to( InputStream stream,
3976 long approximateLength ) {
3977 Binary value = getContext().getValueFactories().getBinaryFactory().create(stream, approximateLength);
3978 return toValue(value);
3979 }
3980
3981 public BatchConjunction to( Reader reader,
3982 long approximateLength ) {
3983 Binary value = getContext().getValueFactories().getBinaryFactory().create(reader, approximateLength);
3984 return toValue(value);
3985 }
3986
3987 public BatchConjunction to( Object value ) {
3988 value = convertReferenceValue(value);
3989 Property property = getContext().getPropertyFactory().create(propertyName, value);
3990 requestQueue.setProperty(location, getCurrentWorkspaceName(), property);
3991 return nextRequests;
3992 }
3993
3994 public BatchConjunction to( Object firstValue,
3995 Object... otherValues ) {
3996 firstValue = convertReferenceValue(firstValue);
3997 for (int i = 0, len = otherValues.length; i != len; ++i) {
3998 otherValues[i] = convertReferenceValue(otherValues[i]);
3999 }
4000 Property property = getContext().getPropertyFactory().create(propertyName, firstValue, otherValues);
4001 requestQueue.setProperty(location, getCurrentWorkspaceName(), property);
4002 return nextRequests;
4003 }
4004
4005 public BatchConjunction to( Object[] values ) {
4006 for (int i = 0; i != values.length; ++i) {
4007 values[i] = convertReferenceValue(values[i]);
4008 }
4009 Property property = getContext().getPropertyFactory().create(propertyName, values);
4010 requestQueue.setProperty(location, getCurrentWorkspaceName(), property);
4011 return nextRequests;
4012 }
4013
4014 public BatchConjunction to( Iterable<?> values ) {
4015 List<Object> valueList = new LinkedList<Object>();
4016 for (Object value : values) {
4017 value = convertReferenceValue(value);
4018 valueList.add(value);
4019 }
4020 Property property = getContext().getPropertyFactory().create(propertyName, valueList);
4021 requestQueue.setProperty(location, getCurrentWorkspaceName(), property);
4022 return nextRequests;
4023 }
4024
4025 public BatchConjunction to( Iterator<?> values ) {
4026 List<Object> valueList = new LinkedList<Object>();
4027 while (values.hasNext()) {
4028 Object value = values.next();
4029 valueList.add(value);
4030 }
4031 Property property = getContext().getPropertyFactory().create(propertyName, valueList);
4032 requestQueue.setProperty(location, getCurrentWorkspaceName(), property);
4033 return nextRequests;
4034 }
4035
4036 };
4037 }
4038
4039 public SetValuesTo<BatchConjunction> on( String path ) {
4040 return on(Location.create(createPath(path)));
4041 }
4042
4043 public SetValuesTo<BatchConjunction> on( Path path ) {
4044 return on(Location.create(path));
4045 }
4046
4047 public SetValuesTo<BatchConjunction> on( Property idProperty ) {
4048 return on(Location.create(idProperty));
4049 }
4050
4051 public SetValuesTo<BatchConjunction> on( Property firstIdProperty,
4052 Property... additionalIdProperties ) {
4053 return on(Location.create(firstIdProperty, additionalIdProperties));
4054 }
4055
4056 public SetValuesTo<BatchConjunction> on( Iterable<Property> idProperties ) {
4057 return on(Location.create(idProperties));
4058 }
4059
4060 public SetValuesTo<BatchConjunction> on( UUID uuid ) {
4061 return on(Location.create(uuid));
4062 }
4063
4064 public On<BatchConjunction> to( Node value ) {
4065 Object reference = convertReferenceValue(value);
4066 return set(getContext().getPropertyFactory().create(propertyName, reference));
4067 }
4068
4069 public On<BatchConjunction> to( Location value ) {
4070 Object reference = convertReferenceValue(value);
4071 return set(getContext().getPropertyFactory().create(propertyName, reference));
4072 }
4073
4074 protected On<BatchConjunction> toValue( Object value ) {
4075 return set(getContext().getPropertyFactory().create(propertyName, value));
4076 }
4077
4078 public On<BatchConjunction> to( String value ) {
4079 return toValue(value);
4080 }
4081
4082 public On<BatchConjunction> to( int value ) {
4083 return toValue(Integer.valueOf(value));
4084 }
4085
4086 public On<BatchConjunction> to( long value ) {
4087 return toValue(Long.valueOf(value));
4088 }
4089
4090 public On<BatchConjunction> to( boolean value ) {
4091 return toValue(Boolean.valueOf(value));
4092 }
4093
4094 public On<BatchConjunction> to( float value ) {
4095 return toValue(Float.valueOf(value));
4096 }
4097
4098 public On<BatchConjunction> to( double value ) {
4099 return toValue(Double.valueOf(value));
4100 }
4101
4102 public On<BatchConjunction> to( BigDecimal value ) {
4103 return toValue(value);
4104 }
4105
4106 public On<BatchConjunction> to( Calendar value ) {
4107 return toValue(value);
4108 }
4109
4110 public On<BatchConjunction> to( Date value ) {
4111 return toValue(value);
4112 }
4113
4114 public On<BatchConjunction> to( DateTime value ) {
4115 return toValue(value);
4116 }
4117
4118 public On<BatchConjunction> to( Name value ) {
4119 return toValue(value);
4120 }
4121
4122 public On<BatchConjunction> to( Path value ) {
4123 return toValue(value);
4124 }
4125
4126 public On<BatchConjunction> to( Reference value ) {
4127 return toValue(value);
4128 }
4129
4130 public On<BatchConjunction> to( URI value ) {
4131 return toValue(value);
4132 }
4133
4134 public On<BatchConjunction> to( UUID value ) {
4135 return toValue(value);
4136 }
4137
4138 public On<BatchConjunction> to( Binary value ) {
4139 return toValue(value);
4140 }
4141
4142 public On<BatchConjunction> to( byte[] value ) {
4143 return toValue(value);
4144 }
4145
4146 public On<BatchConjunction> to( InputStream stream,
4147 long approximateLength ) {
4148 Binary value = getContext().getValueFactories().getBinaryFactory().create(stream, approximateLength);
4149 return toValue(value);
4150 }
4151
4152 public On<BatchConjunction> to( Reader reader,
4153 long approximateLength ) {
4154 Binary value = getContext().getValueFactories().getBinaryFactory().create(reader, approximateLength);
4155 return toValue(value);
4156 }
4157
4158 public On<BatchConjunction> to( Object value ) {
4159 value = convertReferenceValue(value);
4160 return set(getContext().getPropertyFactory().create(propertyName, value));
4161 }
4162
4163 public On<BatchConjunction> to( Object firstValue,
4164 Object... otherValues ) {
4165 Object[] values = new Object[otherValues.length + 1];
4166 values[0] = convertReferenceValue(firstValue);
4167 for (int i = 0, len = otherValues.length; i != len; ++i) {
4168 values[i + 1] = convertReferenceValue(otherValues[i]);
4169 }
4170 return set(getContext().getPropertyFactory().create(propertyName, values));
4171 }
4172
4173 public On<BatchConjunction> to( Object[] values ) {
4174 for (int i = 0, len = values.length; i != len; ++i) {
4175 values[i] = convertReferenceValue(values[i]);
4176 }
4177 return set(getContext().getPropertyFactory().create(propertyName, values));
4178 }
4179
4180 public On<BatchConjunction> to( Iterable<?> values ) {
4181 List<Object> valueList = new LinkedList<Object>();
4182 for (Object value : values) {
4183 value = convertReferenceValue(value);
4184 valueList.add(value);
4185 }
4186 return set(getContext().getPropertyFactory().create(propertyName, valueList));
4187 }
4188
4189 public On<BatchConjunction> to( Iterator<?> values ) {
4190 List<Object> valueList = new LinkedList<Object>();
4191 while (values.hasNext()) {
4192 Object value = values.next();
4193 valueList.add(value);
4194 }
4195 return set(getContext().getPropertyFactory().create(propertyName, valueList));
4196 }
4197 };
4198 }
4199
4200
4201
4202
4203
4204
4205
4206 public On<BatchConjunction> remove( final Name... propertyNames ) {
4207 return new On<BatchConjunction>() {
4208 public BatchConjunction on( Location location ) {
4209 requestQueue.removeProperties(location, getCurrentWorkspaceName(), propertyNames);
4210 return nextRequests;
4211 }
4212
4213 public BatchConjunction on( String path ) {
4214 return on(Location.create(createPath(path)));
4215 }
4216
4217 public BatchConjunction on( Path path ) {
4218 return on(Location.create(path));
4219 }
4220
4221 public BatchConjunction on( Property idProperty ) {
4222 return on(Location.create(idProperty));
4223 }
4224
4225 public BatchConjunction on( Property firstIdProperty,
4226 Property... additionalIdProperties ) {
4227 return on(Location.create(firstIdProperty, additionalIdProperties));
4228 }
4229
4230 public BatchConjunction on( Iterable<Property> idProperties ) {
4231 return on(Location.create(idProperties));
4232 }
4233
4234 public BatchConjunction on( UUID uuid ) {
4235 return on(Location.create(uuid));
4236 }
4237 };
4238 }
4239
4240
4241
4242
4243
4244
4245
4246 public On<BatchConjunction> remove( String... propertyNames ) {
4247 NameFactory nameFactory = getContext().getValueFactories().getNameFactory();
4248 int number = propertyNames.length;
4249 final Name[] names = new Name[number];
4250 for (int i = 0; i != number; ++i) {
4251 names[i] = nameFactory.create(propertyNames[i]);
4252 }
4253 return new On<BatchConjunction>() {
4254 public BatchConjunction on( Location location ) {
4255 requestQueue.removeProperties(location, getCurrentWorkspaceName(), names);
4256 return nextRequests;
4257 }
4258
4259 public BatchConjunction on( String path ) {
4260 return on(Location.create(createPath(path)));
4261 }
4262
4263 public BatchConjunction on( Path path ) {
4264 return on(Location.create(path));
4265 }
4266
4267 public BatchConjunction on( Property idProperty ) {
4268 return on(Location.create(idProperty));
4269 }
4270
4271 public BatchConjunction on( Property firstIdProperty,
4272 Property... additionalIdProperties ) {
4273 return on(Location.create(firstIdProperty, additionalIdProperties));
4274 }
4275
4276 public BatchConjunction on( Iterable<Property> idProperties ) {
4277 return on(Location.create(idProperties));
4278 }
4279
4280 public BatchConjunction on( UUID uuid ) {
4281 return on(Location.create(uuid));
4282 }
4283 };
4284 }
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296 public BatchConjunction read( UUID uuid ) {
4297 return read(Location.create(uuid));
4298 }
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310 public BatchConjunction read( Location location ) {
4311 assertNotExecuted();
4312 requestQueue.readNode(location, getCurrentWorkspaceName());
4313 return nextRequests;
4314 }
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326 public BatchConjunction read( String path ) {
4327 return read(Location.create(createPath(path)));
4328 }
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340 public BatchConjunction read( Path path ) {
4341 return read(Location.create(path));
4342 }
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354 public BatchConjunction read( Property idProperty ) {
4355 return read(Location.create(idProperty));
4356 }
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370 public BatchConjunction read( Property firstIdProperty,
4371 Property... additionalIdProperties ) {
4372 return read(Location.create(firstIdProperty, additionalIdProperties));
4373 }
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385 public BatchConjunction read( Iterable<Property> idProperties ) {
4386 return read(Location.create(idProperties));
4387 }
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400 public On<BatchConjunction> readProperty( String propertyName ) {
4401 assertNotExecuted();
4402 Name name = Graph.this.getContext().getValueFactories().getNameFactory().create(propertyName);
4403 return readProperty(name);
4404 }
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417 public On<BatchConjunction> readProperty( final Name name ) {
4418 assertNotExecuted();
4419 return new On<BatchConjunction>() {
4420 public BatchConjunction on( String path ) {
4421 return on(Location.create(createPath(path)));
4422 }
4423
4424 public BatchConjunction on( Path path ) {
4425 return on(Location.create(path));
4426 }
4427
4428 public BatchConjunction on( Property idProperty ) {
4429 return on(Location.create(idProperty));
4430 }
4431
4432 public BatchConjunction on( Property firstIdProperty,
4433 Property... additionalIdProperties ) {
4434 return on(Location.create(firstIdProperty, additionalIdProperties));
4435 }
4436
4437 public BatchConjunction on( Iterable<Property> idProperties ) {
4438 return on(Location.create(idProperties));
4439 }
4440
4441 public BatchConjunction on( UUID uuid ) {
4442 return on(Location.create(uuid));
4443 }
4444
4445 public BatchConjunction on( Location at ) {
4446 requestQueue.readProperty(at, getCurrentWorkspaceName(), name);
4447 return Batch.this.nextRequests;
4448 }
4449 };
4450 }
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462 public On<BatchConjunction> readProperties() {
4463 assertNotExecuted();
4464 return new On<BatchConjunction>() {
4465 public BatchConjunction on( Location location ) {
4466 requestQueue.readAllProperties(location, getCurrentWorkspaceName());
4467 return Batch.this.nextRequests;
4468 }
4469
4470 public BatchConjunction on( String path ) {
4471 return on(Location.create(createPath(path)));
4472 }
4473
4474 public BatchConjunction on( Path path ) {
4475 return on(Location.create(path));
4476 }
4477
4478 public BatchConjunction on( Property idProperty ) {
4479 return on(Location.create(idProperty));
4480 }
4481
4482 public BatchConjunction on( Property firstIdProperty,
4483 Property... additionalIdProperties ) {
4484 return on(Location.create(firstIdProperty, additionalIdProperties));
4485 }
4486
4487 public BatchConjunction on( Iterable<Property> idProperties ) {
4488 return on(Location.create(idProperties));
4489 }
4490
4491 public BatchConjunction on( UUID uuid ) {
4492 return on(Location.create(uuid));
4493 }
4494 };
4495 }
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507 public Of<BatchConjunction> readChildren() {
4508 assertNotExecuted();
4509 return new Of<BatchConjunction>() {
4510 public BatchConjunction of( String path ) {
4511 return of(Location.create(createPath(path)));
4512 }
4513
4514 public BatchConjunction of( Path path ) {
4515 return of(Location.create(path));
4516 }
4517
4518 public BatchConjunction of( Property idProperty ) {
4519 return of(Location.create(idProperty));
4520 }
4521
4522 public BatchConjunction of( Property firstIdProperty,
4523 Property... additionalIdProperties ) {
4524 return of(Location.create(firstIdProperty, additionalIdProperties));
4525 }
4526
4527 public BatchConjunction of( Iterable<Property> idProperties ) {
4528 return of(Location.create(idProperties));
4529 }
4530
4531 public BatchConjunction of( UUID uuid ) {
4532 return of(Location.create(uuid));
4533 }
4534
4535 public BatchConjunction of( Location at ) {
4536 requestQueue.readAllChildren(at, getCurrentWorkspaceName());
4537 return Batch.this.nextRequests;
4538 }
4539 };
4540 }
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553 public At<BatchConjunction> readSubgraphOfDepth( final int depth ) {
4554 assertNotExecuted();
4555 return new At<BatchConjunction>() {
4556 public BatchConjunction at( Location location ) {
4557 requestQueue.readBranch(location, getCurrentWorkspaceName(), depth);
4558 return Batch.this.nextRequests;
4559 }
4560
4561 public BatchConjunction at( String path ) {
4562 return at(Location.create(createPath(path)));
4563 }
4564
4565 public BatchConjunction at( Path path ) {
4566 return at(Location.create(path));
4567 }
4568
4569 public BatchConjunction at( UUID uuid ) {
4570 return at(Location.create(uuid));
4571 }
4572
4573 public BatchConjunction at( Property idProperty ) {
4574 return at(Location.create(idProperty));
4575 }
4576
4577 public BatchConjunction at( Property firstIdProperty,
4578 Property... additionalIdProperties ) {
4579 return at(Location.create(firstIdProperty, additionalIdProperties));
4580 }
4581
4582 public BatchConjunction at( Iterable<Property> idProperties ) {
4583 return at(Location.create(idProperties));
4584 }
4585 };
4586 }
4587
4588
4589
4590
4591
4592
4593 public Results execute() {
4594 executed = true;
4595 Request request = requestQueue.pop();
4596 if (request == null) {
4597 return new BatchResults();
4598 }
4599 Graph.this.execute(request);
4600 if (RequestType.COMPOSITE == request.getType()) {
4601 CompositeRequest composite = (CompositeRequest)request;
4602 return new BatchResults(composite.getRequests());
4603 }
4604 return new BatchResults(request);
4605 }
4606
4607
4608
4609
4610
4611
4612 @Override
4613 public String toString() {
4614 StringBuilder sb = new StringBuilder();
4615 sb.append("Pending requests:\n");
4616 sb.append(requestQueue.toString());
4617 return sb.toString();
4618 }
4619 }
4620
4621
4622
4623
4624
4625
4626
4627
4628 protected Object convertReferenceValue( Object value ) {
4629 if (value instanceof Node) {
4630 Node node = (Node)value;
4631 UUID uuid = node.getLocation().getUuid();
4632 if (uuid == null) {
4633
4634 Property uuidProperty = node.getProperty(ModeShapeLexicon.UUID);
4635 if (uuidProperty != null) {
4636 uuid = context.getValueFactories().getUuidFactory().create(uuidProperty.getFirstValue());
4637 } else {
4638 uuidProperty = node.getProperty(JcrLexicon.UUID);
4639 if (uuidProperty != null) {
4640 uuid = context.getValueFactories().getUuidFactory().create(uuidProperty.getFirstValue());
4641 }
4642 }
4643 }
4644 if (uuid == null) {
4645 String nodeString = node.getLocation().getString(getContext().getNamespaceRegistry());
4646 String msg = GraphI18n.unableToCreateReferenceToNodeWithoutUuid.text(nodeString);
4647 throw new IllegalArgumentException(msg);
4648 }
4649 return getContext().getValueFactories().getReferenceFactory().create(uuid);
4650 }
4651 if (value instanceof Location) {
4652 Location location = (Location)value;
4653 UUID uuid = location.getUuid();
4654 if (uuid == null) {
4655 String nodeString = location.getString(getContext().getNamespaceRegistry());
4656 String msg = GraphI18n.unableToCreateReferenceToNodeWithoutUuid.text(nodeString);
4657 throw new IllegalArgumentException(msg);
4658 }
4659 return getContext().getValueFactories().getReferenceFactory().create(uuid);
4660 }
4661 return value;
4662 }
4663
4664 protected static DateTime computeExpirationTime( CacheableRequest request ) {
4665 CachePolicy policy = request.getCachePolicy();
4666 return policy == null ? null : request.getTimeLoaded().plus(policy.getTimeToLive(), TimeUnit.MILLISECONDS);
4667 }
4668
4669
4670
4671
4672 public interface BuildQuery {
4673
4674
4675
4676
4677
4678
4679
4680 BuildQuery using( PlanHints hints );
4681
4682
4683
4684
4685
4686
4687
4688
4689 BuildQuery using( Map<String, Object> variables );
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699 BuildQuery using( String variableName,
4700 Object value );
4701
4702
4703
4704
4705
4706
4707 QueryResults execute();
4708 }
4709
4710
4711
4712
4713 public interface NameWorkspace {
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723 Workspace named( String workspaceName );
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733 Workspace namedSomethingLike( String workspaceName );
4734 }
4735
4736
4737
4738
4739 public interface CreateWorkspace extends NameWorkspace {
4740
4741
4742
4743
4744
4745
4746
4747
4748 NameWorkspace clonedFrom( String originalWorkspaceName );
4749 }
4750
4751
4752
4753
4754
4755
4756 public interface Executable<NodeType extends Node> {
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768 Results execute();
4769 }
4770
4771
4772
4773
4774
4775
4776 public interface Conjunction<Next> {
4777
4778
4779
4780
4781
4782 Next and();
4783 }
4784
4785
4786
4787
4788
4789
4790 public interface Into<Next> {
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801 Next into( Location parentLocation );
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813 Next into( String parentPath );
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825 Next into( Path parentPath );
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835 Next into( UUID parentUuid );
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845 Next into( Property parentIdProperty );
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858 Next into( Property firstParentIdProperty,
4859 Property... additionalParentIdProperties );
4860 }
4861
4862
4863
4864
4865
4866
4867
4868
4869 public interface Before<Next> {
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880 Next before( Location parentLocation );
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892 Next before( String parentPath );
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904 Next before( Path parentPath );
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914 Next before( UUID parentUuid );
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924 Next before( Property parentIdProperty );
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937 Next before( Property firstParentIdProperty,
4938 Property... additionalParentIdProperties );
4939 }
4940
4941
4942
4943
4944
4945
4946 public interface ToName<Next> {
4947
4948 public Next to( String name );
4949
4950 public Next to( Name name );
4951
4952 }
4953
4954
4955
4956
4957
4958
4959 public interface FromName<Next> {
4960
4961 public Next from( String name );
4962
4963 public Next from( Name name );
4964
4965 }
4966
4967
4968
4969
4970
4971
4972 public interface To<Next> {
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982 Next to( Location desiredLocation );
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993 Next to( String desiredPath );
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004 Next to( Path desiredPath );
5005 }
5006
5007
5008
5009
5010
5011
5012 public interface AsChild<Next> {
5013
5014
5015
5016
5017
5018
5019
5020 Next as( Path.Segment newSegment );
5021
5022
5023
5024
5025
5026
5027
5028
5029 Next as( Name newName );
5030
5031
5032
5033
5034
5035
5036
5037
5038 Next as( String newName );
5039 }
5040
5041
5042
5043
5044
5045
5046 public interface AsName<Next> {
5047
5048
5049
5050
5051
5052
5053 Next as( String newName );
5054
5055
5056
5057
5058
5059
5060
5061 Next as( Name newName );
5062 }
5063
5064
5065
5066
5067
5068
5069 public interface And<Next> {
5070
5071
5072
5073
5074
5075
5076 Next and( Location from );
5077
5078
5079
5080
5081
5082
5083
5084 Next and( String fromPath );
5085
5086
5087
5088
5089
5090
5091
5092 Next and( Path from );
5093
5094
5095
5096
5097
5098
5099
5100 Next and( UUID from );
5101
5102
5103
5104
5105
5106
5107
5108 Next and( Property idProperty );
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119 Next and( Property firstIdProperty,
5120 Property... additionalIdProperties );
5121
5122
5123
5124
5125
5126
5127
5128 Next and( Iterable<Property> idProperties );
5129 }
5130
5131
5132
5133
5134
5135
5136 public interface Move<Next> extends AsName<Into<Next>>, Into<Next>, Before<Next>, And<Move<Next>> {
5137 }
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147 public interface Copy<Next> extends FromWorkspace<CopyTarget<Next>>, CopyTarget<Next>, And<Copy<Next>> {
5148 }
5149
5150 public interface CopyTarget<Next> extends To<Next>, Into<Next> {
5151 }
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168 public interface Clone<Next> extends FromWorkspace<AsChild<Into<WithUuids<Next>>>> {
5169
5170 }
5171
5172
5173
5174
5175
5176
5177 public interface FromWorkspace<Next> {
5178 Next fromWorkspace( String workspaceName );
5179 }
5180
5181
5182
5183
5184
5185
5186 public interface WithUuids<Next> {
5187 Next failingIfAnyUuidsMatch();
5188
5189 Next replacingExistingNodesWithSameUuids();
5190 }
5191
5192
5193
5194
5195
5196
5197 public interface LockScope<Next> {
5198 Next andItsDescendants();
5199
5200 Next only();
5201 }
5202
5203
5204
5205
5206
5207
5208 public interface LockTimeout<Next> {
5209 Next withDefaultTimeout();
5210
5211 Next withTimeoutOf( long milliseconds );
5212 }
5213
5214 @NotThreadSafe
5215 protected abstract class LockAction<T> extends AbstractAction<T> implements LockScope<LockTimeout<T>> {
5216 private final Location target;
5217
5218
5219 Location target ) {
5220 super(afterConjunction);
5221 this.target = target;
5222 }
5223
5224 protected abstract T submit( Location lock,
5225 org.modeshape.graph.request.LockBranchRequest.LockScope lockScope,
5226 long lockTimeoutInMillis );
5227
5228 @SuppressWarnings( "synthetic-access" )
5229 public LockTimeout<T> andItsDescendants() {
5230 return new LockTimeout<T>() {
5231
5232 public T withDefaultTimeout() {
5233 return submit(target, org.modeshape.graph.request.LockBranchRequest.LockScope.SELF_AND_DESCENDANTS, 0);
5234 }
5235
5236 public T withTimeoutOf( long milliseconds ) {
5237 return submit(target,
5238 org.modeshape.graph.request.LockBranchRequest.LockScope.SELF_AND_DESCENDANTS,
5239 milliseconds);
5240 }
5241
5242 };
5243 }
5244
5245 @SuppressWarnings( "synthetic-access" )
5246 public LockTimeout<T> only() {
5247 return new LockTimeout<T>() {
5248
5249 public T withDefaultTimeout() {
5250 return submit(target, org.modeshape.graph.request.LockBranchRequest.LockScope.SELF_ONLY, 0);
5251 }
5252
5253 public T withTimeoutOf( long milliseconds ) {
5254 return submit(target, org.modeshape.graph.request.LockBranchRequest.LockScope.SELF_ONLY, milliseconds);
5255 }
5256
5257 };
5258 }
5259
5260 }
5261
5262
5263
5264
5265
5266
5267 public interface Create<Next> extends Conjunction<Next> {
5268
5269
5270
5271
5272
5273
5274 Create<Next> ifAbsent();
5275
5276
5277
5278
5279
5280
5281
5282 Create<Next> orUpdate();
5283
5284
5285
5286
5287
5288
5289
5290 Create<Next> orReplace();
5291
5292
5293
5294
5295
5296
5297
5298 Create<Next> byAppending();
5299
5300
5301
5302
5303
5304
5305
5306 Create<Next> with( UUID uuid );
5307
5308
5309
5310
5311
5312
5313
5314 Create<Next> with( Property property );
5315
5316
5317
5318
5319
5320
5321
5322 Create<Next> with( Iterable<Property> properties );
5323
5324
5325
5326
5327
5328
5329
5330
5331 Create<Next> with( String propertyName,
5332 Object... values );
5333
5334
5335
5336
5337
5338
5339
5340
5341 Create<Next> with( Name propertyName,
5342 Object... values );
5343
5344
5345
5346
5347
5348
5349
5350
5351 Create<Next> with( Property firstProperty,
5352 Property... additionalProperties );
5353
5354
5355
5356
5357
5358
5359
5360 Create<Next> and( UUID uuid );
5361
5362
5363
5364
5365
5366
5367
5368 Create<Next> and( Property property );
5369
5370
5371
5372
5373
5374
5375
5376
5377 Create<Next> and( Iterable<Property> properties );
5378
5379
5380
5381
5382
5383
5384
5385
5386 Create<Next> and( String propertyName,
5387 Object... values );
5388
5389
5390
5391
5392
5393
5394
5395
5396 Create<Next> and( Name propertyName,
5397 Object... values );
5398
5399
5400
5401
5402
5403
5404
5405
5406 Create<Next> and( Property firstProperty,
5407 Property... additionalProperties );
5408 }
5409
5410
5411
5412
5413
5414
5415 public interface CreateAt<Next> extends Conjunction<Next> {
5416
5417
5418
5419
5420
5421
5422 CreateAt<Next> with( UUID uuid );
5423
5424
5425
5426
5427
5428
5429
5430 CreateAt<Next> with( Property property );
5431
5432
5433
5434
5435
5436
5437
5438 CreateAt<Next> with( Iterable<Property> properties );
5439
5440
5441
5442
5443
5444
5445
5446
5447 CreateAt<Next> with( String propertyName,
5448 Object... values );
5449
5450
5451
5452
5453
5454
5455
5456
5457 CreateAt<Next> with( Name propertyName,
5458 Object... values );
5459
5460
5461
5462
5463
5464
5465
5466
5467 CreateAt<Next> with( Property firstProperty,
5468 Property... additionalProperties );
5469
5470
5471
5472
5473
5474
5475
5476 CreateAt<Next> and( UUID uuid );
5477
5478
5479
5480
5481
5482
5483
5484 CreateAt<Next> and( Property property );
5485
5486
5487
5488
5489
5490
5491
5492
5493 CreateAt<Next> and( Iterable<Property> properties );
5494
5495
5496
5497
5498
5499
5500
5501
5502 CreateAt<Next> and( String propertyName,
5503 Object... values );
5504
5505
5506
5507
5508
5509
5510
5511
5512 CreateAt<Next> and( Name propertyName,
5513 Object... values );
5514
5515
5516
5517
5518
5519
5520
5521
5522 CreateAt<Next> and( Property firstProperty,
5523 Property... additionalProperties );
5524
5525
5526
5527
5528
5529
5530 Location getLocation();
5531
5532
5533
5534
5535
5536
5537 Node getNode();
5538 }
5539
5540
5541
5542
5543
5544
5545 public interface On<Next> {
5546
5547
5548
5549
5550
5551
5552 Next on( Location to );
5553
5554
5555
5556
5557
5558
5559
5560 Next on( String toPath );
5561
5562
5563
5564
5565
5566
5567
5568 Next on( Path to );
5569
5570
5571
5572
5573
5574
5575
5576 Next on( UUID to );
5577
5578
5579
5580
5581
5582
5583
5584 Next on( Property idProperty );
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595 Next on( Property firstIdProperty,
5596 Property... additionalIdProperties );
5597
5598
5599
5600
5601
5602
5603
5604 Next on( Iterable<Property> idProperties );
5605 }
5606
5607
5608
5609
5610
5611
5612 public interface OnMultiple<Next> extends On<Next> {
5613
5614
5615
5616
5617
5618
5619 Map<Location, Next> on( Collection<Location> to );
5620
5621
5622
5623
5624
5625
5626
5627
5628 Map<Location, Next> on( Location firstTo,
5629 Location... additional );
5630
5631
5632
5633
5634
5635
5636
5637
5638 Map<Location, Next> on( String firstPath,
5639 String... additional );
5640
5641
5642
5643
5644
5645
5646
5647
5648 Map<Location, Next> on( Path firstPath,
5649 Path... additional );
5650
5651
5652
5653
5654
5655
5656
5657
5658 Map<Location, Next> on( UUID firstPath,
5659 UUID... additional );
5660 }
5661
5662
5663
5664
5665
5666
5667 public interface Of<Next> {
5668
5669
5670
5671
5672
5673
5674 Next of( Location to );
5675
5676
5677
5678
5679
5680
5681
5682 Next of( String toPath );
5683
5684
5685
5686
5687
5688
5689
5690 Next of( Path to );
5691
5692
5693
5694
5695
5696
5697
5698 Next of( UUID to );
5699
5700
5701
5702
5703
5704
5705
5706 Next of( Property idProperty );
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717 Next of( Property firstIdProperty,
5718 Property... additionalIdProperties );
5719
5720
5721
5722
5723
5724
5725
5726 Next of( Iterable<Property> idProperties );
5727 }
5728
5729
5730
5731
5732
5733
5734 public interface At<Next> {
5735
5736
5737
5738
5739
5740
5741 Next at( Location to );
5742
5743
5744
5745
5746
5747
5748
5749 Next at( String toPath );
5750
5751
5752
5753
5754
5755
5756
5757 Next at( Path to );
5758
5759
5760
5761
5762
5763
5764
5765 Next at( UUID to );
5766
5767
5768
5769
5770
5771
5772
5773 Next at( Property idProperty );
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784 Next at( Property firstIdProperty,
5785 Property... additionalIdProperties );
5786
5787
5788
5789
5790
5791
5792
5793 Next at( Iterable<Property> idProperties );
5794 }
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804 public interface Children<Next> extends Of<Next> {
5805
5806
5807
5808
5809
5810
5811 BlockOfChildren<Next> inBlockOf( int blockSize );
5812 }
5813
5814
5815
5816
5817
5818
5819
5820 public interface BlockOfChildren<Next> {
5821
5822
5823
5824
5825
5826
5827 Under<Next> startingAt( int startingIndex );
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837 Next startingAfter( Location previousSibling );
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847 Next startingAfter( String pathToPreviousSiblingName );
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857 Next startingAfter( Path previousSibling );
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867 Next startingAfter( UUID previousSiblingUuid );
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877 Next startingAfter( Property idPropertyOfPreviousSibling );
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890 Next startingAfter( Property firstIdPropertyOfPreviousSibling,
5891 Property... additionalIdPropertiesOfPreviousSibling );
5892 }
5893
5894
5895
5896
5897
5898
5899 public interface Under<Next> {
5900
5901
5902
5903
5904
5905
5906 Next under( Location to );
5907
5908
5909
5910
5911
5912
5913
5914 Next under( String toPath );
5915
5916
5917
5918
5919
5920
5921
5922 Next under( Path to );
5923
5924
5925
5926
5927
5928
5929
5930 Next under( UUID to );
5931
5932
5933
5934
5935
5936
5937
5938 Next under( Property idProperty );
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949 Next under( Property firstIdProperty,
5950 Property... additionalIdProperties );
5951 }
5952
5953
5954
5955
5956
5957
5958
5959 public interface AddValue<Next> extends ToName<On<Next>> {
5960
5961
5962
5963
5964
5965
5966 AddValue<Next> andValue( Object value );
5967
5968 }
5969
5970
5971
5972
5973
5974
5975
5976 public interface RemoveValue<Next> extends FromName<On<Next>> {
5977
5978
5979
5980
5981
5982
5983
5984 RemoveValue<Next> andValue( Object value );
5985
5986 }
5987
5988 public abstract class AddValueAction<T> extends AbstractAction<T> implements AddValue<T> {
5989
5990 protected final String workspaceName;
5991 protected final List<Object> values = new LinkedList<Object>();
5992
5993 protected AddValueAction( T afterConjunction,
5994 String workspaceName,
5995 Object firstValue ) {
5996 super(afterConjunction);
5997
5998 this.workspaceName = workspaceName;
5999 this.values.add(firstValue);
6000 }
6001
6002 public AddValue<T> andValue( Object nextValue ) {
6003 this.values.add(nextValue);
6004 return this;
6005 }
6006
6007 public On<T> to( String name ) {
6008 return to(createName(name));
6009 }
6010
6011 public On<T> to( final Name name ) {
6012 return new On<T>() {
6013
6014 public T on( Iterable<Property> idProperties ) {
6015 return on(Location.create(idProperties));
6016 }
6017
6018 public T on( Location to ) {
6019 return submit(workspaceName, to, name, values);
6020 }
6021
6022 public T on( Path to ) {
6023 return on(Location.create(to));
6024 }
6025
6026 public T on( Property firstIdProperty,
6027 Property... additionalIdProperties ) {
6028 return on(Location.create(firstIdProperty, additionalIdProperties));
6029 }
6030
6031 public T on( Property idProperty ) {
6032 return on(Location.create(idProperty));
6033 }
6034
6035 public T on( String toPath ) {
6036 return on(Location.create(createPath(toPath)));
6037 }
6038
6039 public T on( UUID to ) {
6040 return on(Location.create(to));
6041 }
6042 };
6043 }
6044
6045 protected abstract T submit( String workspaceName,
6046 Location on,
6047 Name property,
6048 List<Object> values );
6049
6050 }
6051
6052 public abstract class RemoveValueAction<T> extends AbstractAction<T> implements RemoveValue<T> {
6053
6054 protected final String workspaceName;
6055 protected final List<Object> values = new LinkedList<Object>();
6056
6057 protected RemoveValueAction( T afterConjunction,
6058 String workspaceName,
6059 Object firstValue ) {
6060 super(afterConjunction);
6061
6062 this.workspaceName = workspaceName;
6063 this.values.add(firstValue);
6064 }
6065
6066 public RemoveValue<T> andValue( Object nextValue ) {
6067 this.values.add(nextValue);
6068 return this;
6069 }
6070
6071 public On<T> from( String name ) {
6072 return from(createName(name));
6073 }
6074
6075 public On<T> from( final Name name ) {
6076 return new On<T>() {
6077
6078 public T on( Iterable<Property> idProperties ) {
6079 return on(Location.create(idProperties));
6080 }
6081
6082 public T on( Location to ) {
6083 return submit(workspaceName, to, name, values);
6084 }
6085
6086 public T on( Path to ) {
6087 return on(Location.create(to));
6088 }
6089
6090 public T on( Property firstIdProperty,
6091 Property... additionalIdProperties ) {
6092 return on(Location.create(firstIdProperty, additionalIdProperties));
6093 }
6094
6095 public T on( Property idProperty ) {
6096 return on(Location.create(idProperty));
6097 }
6098
6099 public T on( String toPath ) {
6100 return on(Location.create(createPath(toPath)));
6101 }
6102
6103 public T on( UUID to ) {
6104 return on(Location.create(to));
6105 }
6106 };
6107 }
6108
6109 protected abstract T submit( String workspaceName,
6110 Location on,
6111 Name property,
6112 List<Object> values );
6113
6114 }
6115
6116
6117
6118
6119
6120
6121 public interface SetValues<Next> extends On<SetValuesTo<Next>>, SetValuesTo<On<Next>> {
6122 }
6123
6124
6125
6126
6127
6128
6129 public interface SetValuesTo<Next> {
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139 Next to( Node node );
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149 Next to( Location location );
6150
6151
6152
6153
6154
6155
6156
6157 Next to( String value );
6158
6159
6160
6161
6162
6163
6164
6165 Next to( int value );
6166
6167
6168
6169
6170
6171
6172
6173 Next to( long value );
6174
6175
6176
6177
6178
6179
6180
6181 Next to( boolean value );
6182
6183
6184
6185
6186
6187
6188
6189 Next to( float value );
6190
6191
6192
6193
6194
6195
6196
6197 Next to( double value );
6198
6199
6200
6201
6202
6203
6204
6205 Next to( BigDecimal value );
6206
6207
6208
6209
6210
6211
6212
6213 Next to( Calendar value );
6214
6215
6216
6217
6218
6219
6220
6221 Next to( Date value );
6222
6223
6224
6225
6226
6227
6228
6229 Next to( DateTime value );
6230
6231
6232
6233
6234
6235
6236
6237 Next to( Name value );
6238
6239
6240
6241
6242
6243
6244
6245 Next to( Path value );
6246
6247
6248
6249
6250
6251
6252
6253 Next to( Reference value );
6254
6255
6256
6257
6258
6259
6260
6261 Next to( URI value );
6262
6263
6264
6265
6266
6267
6268
6269 Next to( UUID value );
6270
6271
6272
6273
6274
6275
6276
6277 Next to( Binary value );
6278
6279
6280
6281
6282
6283
6284
6285 Next to( byte[] value );
6286
6287
6288
6289
6290
6291
6292
6293
6294 Next to( InputStream stream,
6295 long approximateLength );
6296
6297
6298
6299
6300
6301
6302
6303
6304 Next to( Reader reader,
6305 long approximateLength );
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316 Next to( Object value );
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328 Next to( Object[] values );
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341 Next to( Object firstValue,
6342 Object... otherValues );
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354 Next to( Iterable<?> values );
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366 Next to( Iterator<?> values );
6367 }
6368
6369
6370
6371
6372
6373
6374 public interface CreateNode<Next> {
6375
6376
6377
6378
6379
6380
6381
6382 Next node( String nodeName,
6383 Property... properties );
6384
6385
6386
6387
6388
6389
6390
6391
6392 Next node( String nodeName,
6393 Iterator<Property> properties );
6394
6395
6396
6397
6398
6399
6400
6401
6402 Next node( String nodeName,
6403 Iterable<Property> properties );
6404 }
6405
6406
6407
6408
6409
6410
6411 public interface CreateNodeNamed<Next> {
6412
6413
6414
6415
6416
6417
6418 Create<Next> nodeNamed( String nodeName );
6419
6420
6421
6422
6423
6424
6425
6426 Create<Next> nodeNamed( Name nodeName );
6427 }
6428
6429
6430
6431
6432
6433
6434 public interface ImportInto<Next> {
6435
6436
6437
6438
6439
6440
6441
6442 ImportInto<Next> skippingRootElement( boolean skip );
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452 Next into( Location to ) throws IOException, SAXException;
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462 Next into( String toPath ) throws IOException, SAXException;
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472 Next into( Path to ) throws IOException, SAXException;
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482 Next into( UUID to ) throws IOException, SAXException;
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492 Next into( Property idProperty ) throws IOException, SAXException;
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505 Next into( Property firstIdProperty,
6506 Property... additionalIdProperties ) throws IOException, SAXException;
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516 Next into( Iterable<Property> idProperties ) throws IOException, SAXException;
6517 }
6518
6519 public interface BatchConjunction extends Conjunction<Batch>, Executable<Node> {
6520 }
6521
6522 public interface GetNodeConjunction<Next> extends Conjunction<Next> {
6523 Node andReturn();
6524 }
6525
6526
6527
6528
6529 @Immutable
6530 protected class GraphNode implements Node {
6531 private final ReadNodeRequest request;
6532
6533
6534 this.request = request;
6535 }
6536
6537 public Location getLocation() {
6538 return request.getActualLocationOfNode();
6539 }
6540
6541 public DateTime getExpirationTime() {
6542 CachePolicy policy = request.getCachePolicy();
6543 return policy == null ? null : request.getTimeLoaded().plus(policy.getTimeToLive(), TimeUnit.MILLISECONDS);
6544 }
6545
6546 public Graph getGraph() {
6547 return Graph.this;
6548 }
6549
6550 public Collection<Property> getProperties() {
6551 return request.getProperties();
6552 }
6553
6554 public Property getProperty( Name name ) {
6555 return getPropertiesByName().get(name);
6556 }
6557
6558 public Property getProperty( String nameStr ) {
6559 Name name = getContext().getValueFactories().getNameFactory().create(nameStr);
6560 return getPropertiesByName().get(name);
6561 }
6562
6563 public Map<Name, Property> getPropertiesByName() {
6564 return request.getPropertiesByName();
6565 }
6566
6567 public List<Location> getChildren() {
6568 return request.getChildren();
6569 }
6570
6571 public boolean hasChildren() {
6572 return request.getChildren().size() > 0;
6573 }
6574
6575 public List<Segment> getChildrenSegments() {
6576 return getSegments(getChildren());
6577 }
6578
6579 public Iterator<Location> iterator() {
6580 return request.getChildren().iterator();
6581 }
6582
6583 @Override
6584 public int hashCode() {
6585 return getLocation().hashCode();
6586 }
6587
6588 @Override
6589 public boolean equals( Object obj ) {
6590 if (obj instanceof Node) {
6591 Node that = (Node)obj;
6592 return this.getLocation().isSame(that.getLocation());
6593 }
6594 return false;
6595 }
6596
6597 @Override
6598 public String toString() {
6599 return "Node " + getLocation().toString();
6600 }
6601 }
6602
6603
6604
6605
6606 @Immutable
6607 class BatchResults implements Results {
6608 private final Map<Path, BatchResultsNode> nodes = new HashMap<Path, BatchResultsNode>();
6609 private final List<Request> requests;
6610
6611
6612 this.requests = Collections.unmodifiableList(requests);
6613
6614 for (Request request : requests) {
6615 DateTime expires;
6616 BatchResultsNode node;
6617
6618 switch (request.getType()) {
6619 case READ_ALL_PROPERTIES:
6620 ReadAllPropertiesRequest readAll = (ReadAllPropertiesRequest)request;
6621 expires = computeExpirationTime(readAll);
6622 getOrCreateNode(readAll.getActualLocationOfNode(), expires).setProperties(readAll.getPropertiesByName());
6623 break;
6624 case READ_PROPERTY:
6625 ReadPropertyRequest read = (ReadPropertyRequest)request;
6626 expires = computeExpirationTime(read);
6627 getOrCreateNode(read.getActualLocationOfNode(), expires).addProperty(read.getProperty());
6628 break;
6629 case READ_NODE:
6630 ReadNodeRequest readNode = (ReadNodeRequest)request;
6631 expires = computeExpirationTime(readNode);
6632 node = getOrCreateNode(readNode.getActualLocationOfNode(), expires);
6633 node.setProperties(readNode.getPropertiesByName());
6634 node.setChildren(readNode.getChildren());
6635 break;
6636 case READ_BLOCK_OF_CHILDREN:
6637 throw new IllegalStateException();
6638 case READ_ALL_CHILDREN:
6639 ReadAllChildrenRequest readAllChildren = (ReadAllChildrenRequest)request;
6640 expires = computeExpirationTime(readAllChildren);
6641 getOrCreateNode(readAllChildren.getActualLocationOfNode(), expires).setChildren(readAllChildren.getChildren());
6642 break;
6643 case READ_BRANCH:
6644 ReadBranchRequest readBranch = (ReadBranchRequest)request;
6645 expires = computeExpirationTime(readBranch);
6646 for (Location location : readBranch) {
6647 node = getOrCreateNode(location, expires);
6648 node.setProperties(readBranch.getPropertiesFor(location));
6649 node.setChildren(readBranch.getChildren(location));
6650 }
6651 break;
6652 default:
6653
6654 break;
6655 }
6656 }
6657 for (Map.Entry<Path, BatchResultsNode> entry : nodes.entrySet()) {
6658 entry.getValue().freeze();
6659 }
6660 }
6661
6662
6663 this.requests = Collections.singletonList(request);
6664
6665 DateTime expires;
6666 BatchResultsNode node;
6667
6668 switch (request.getType()) {
6669 case READ_ALL_PROPERTIES:
6670 ReadAllPropertiesRequest readAll = (ReadAllPropertiesRequest)request;
6671 expires = computeExpirationTime(readAll);
6672 getOrCreateNode(readAll.getActualLocationOfNode(), expires).setProperties(readAll.getPropertiesByName());
6673 break;
6674 case READ_PROPERTY:
6675 ReadPropertyRequest read = (ReadPropertyRequest)request;
6676 expires = computeExpirationTime(read);
6677 getOrCreateNode(read.getActualLocationOfNode(), expires).addProperty(read.getProperty());
6678 break;
6679 case READ_NODE:
6680 ReadNodeRequest readNode = (ReadNodeRequest)request;
6681 expires = computeExpirationTime(readNode);
6682 node = getOrCreateNode(readNode.getActualLocationOfNode(), expires);
6683 node.setProperties(readNode.getPropertiesByName());
6684 node.setChildren(readNode.getChildren());
6685 break;
6686 case READ_BLOCK_OF_CHILDREN:
6687 throw new IllegalStateException();
6688 case READ_ALL_CHILDREN:
6689 ReadAllChildrenRequest readAllChildren = (ReadAllChildrenRequest)request;
6690 expires = computeExpirationTime(readAllChildren);
6691 getOrCreateNode(readAllChildren.getActualLocationOfNode(), expires).setChildren(readAllChildren.getChildren());
6692 break;
6693 case READ_BRANCH:
6694 ReadBranchRequest readBranch = (ReadBranchRequest)request;
6695 expires = computeExpirationTime(readBranch);
6696 for (Location location : readBranch) {
6697 node = getOrCreateNode(location, expires);
6698 node.setProperties(readBranch.getPropertiesFor(location));
6699 node.setChildren(readBranch.getChildren(location));
6700 }
6701 break;
6702 default:
6703
6704 break;
6705 }
6706 for (Map.Entry<Path, BatchResultsNode> entry : nodes.entrySet()) {
6707 entry.getValue().freeze();
6708 }
6709 }
6710
6711 BatchResults() {
6712 this.requests = Collections.emptyList();
6713 }
6714
6715
6716
6717
6718
6719
6720 public List<Request> getRequests() {
6721 return requests;
6722 }
6723
6724 private BatchResultsNode getOrCreateNode( Location location,
6725 DateTime expirationTime ) {
6726 BatchResultsNode node = nodes.get(location);
6727 if (node == null) {
6728 node = new BatchResultsNode(location, expirationTime);
6729 assert location != null;
6730 assert location.getPath() != null;
6731 nodes.put(location.getPath(), node);
6732 }
6733 return node;
6734 }
6735
6736 public Graph getGraph() {
6737 return Graph.this;
6738 }
6739
6740 protected void checkIsAbsolute( Path path ) {
6741 if (!path.isAbsolute()) {
6742 throw new IllegalArgumentException(GraphI18n.pathIsNotAbsolute.text(path));
6743 }
6744 }
6745
6746 public Node getNode( String pathStr ) {
6747 Path path = createPath(pathStr);
6748 checkIsAbsolute(path);
6749 return nodes.get(path);
6750 }
6751
6752 public Node getNode( Path path ) {
6753 CheckArg.isNotNull(path, "path");
6754 checkIsAbsolute(path);
6755 return nodes.get(path);
6756 }
6757
6758 public Node getNode( Location location ) {
6759 CheckArg.isNotNull(location, "location");
6760 CheckArg.isNotNull(location.getPath(), "location.getPath()");
6761 return nodes.get(location.getPath());
6762 }
6763
6764 public boolean includes( String path ) {
6765 return getNode(path) != null;
6766 }
6767
6768 public boolean includes( Path path ) {
6769 return getNode(path) != null;
6770 }
6771
6772 public boolean includes( Location location ) {
6773 return getNode(location) != null;
6774 }
6775
6776 public Iterator<Node> iterator() {
6777 List<Path> paths = new ArrayList<Path>(nodes.keySet());
6778 Collections.sort(paths);
6779 final Iterator<Path> pathIter = paths.iterator();
6780 return new Iterator<Node>() {
6781 public boolean hasNext() {
6782 return pathIter.hasNext();
6783 }
6784
6785 public Node next() {
6786 Path nextPath = pathIter.next();
6787 return getNode(nextPath);
6788 }
6789
6790 public void remove() {
6791 throw new UnsupportedOperationException();
6792 }
6793 };
6794 }
6795 }
6796
6797 @Immutable
6798 class BatchResultsNode implements Node {
6799 private final Location location;
6800 private final DateTime expirationTime;
6801 private Map<Name, Property> properties;
6802 private List<Location> children;
6803
6804 BatchResultsNode( Location location,
6805 DateTime expirationTime ) {
6806 this.location = location;
6807 this.expirationTime = expirationTime;
6808 }
6809
6810 public DateTime getExpirationTime() {
6811 return expirationTime;
6812 }
6813
6814 void addProperty( Property property ) {
6815 if (this.properties == null) this.properties = new HashMap<Name, Property>();
6816 this.properties.put(property.getName(), property);
6817 }
6818
6819 void setProperties( Map<Name, Property> properties ) {
6820 this.properties = properties;
6821 }
6822
6823 void setChildren( List<Location> children ) {
6824 this.children = children;
6825 }
6826
6827 void freeze() {
6828 if (properties != null) properties = Collections.unmodifiableMap(properties);
6829 else properties = Collections.emptyMap();
6830 if (children != null) children = Collections.unmodifiableList(children);
6831 else children = Collections.emptyList();
6832 }
6833
6834 public List<Segment> getChildrenSegments() {
6835 return getSegments(getChildren());
6836 }
6837
6838 public Graph getGraph() {
6839 return Graph.this;
6840 }
6841
6842 public Location getLocation() {
6843 return location;
6844 }
6845
6846 public Collection<Property> getProperties() {
6847 return properties.values();
6848 }
6849
6850 public Map<Name, Property> getPropertiesByName() {
6851 return properties;
6852 }
6853
6854 public Property getProperty( Name name ) {
6855 return properties.get(name);
6856 }
6857
6858 public Property getProperty( String nameStr ) {
6859 Name name = getContext().getValueFactories().getNameFactory().create(nameStr);
6860 return properties.get(name);
6861 }
6862
6863 public List<Location> getChildren() {
6864 return children;
6865 }
6866
6867 public boolean hasChildren() {
6868 return children.size() != 0;
6869 }
6870
6871 public Iterator<Location> iterator() {
6872 return children.iterator();
6873 }
6874
6875 @Override
6876 public int hashCode() {
6877 return location.hashCode();
6878 }
6879
6880 @Override
6881 public boolean equals( Object obj ) {
6882 if (obj instanceof Node) {
6883 Node that = (Node)obj;
6884 return this.location.isSame(that.getLocation());
6885 }
6886 return false;
6887 }
6888
6889 @Override
6890 public String toString() {
6891 return "Node " + getLocation().toString();
6892 }
6893
6894 }
6895
6896
6897
6898
6899 @Immutable
6900 class SubgraphResults implements Subgraph {
6901 private final ReadBranchRequest request;
6902
6903 SubgraphResults( ReadBranchRequest request ) {
6904 this.request = request;
6905 }
6906
6907 public Graph getGraph() {
6908 return Graph.this;
6909 }
6910
6911 public Location getLocation() {
6912 return request.getActualLocationOfNode();
6913 }
6914
6915 public SubgraphNode getRoot() {
6916 return getNode(getLocation());
6917 }
6918
6919 public int getMaximumDepth() {
6920 return request.maximumDepth();
6921 }
6922
6923 public Iterator<SubgraphNode> iterator() {
6924 final Iterator<Location> iter = request.iterator();
6925 return new Iterator<SubgraphNode>() {
6926 public boolean hasNext() {
6927 return iter.hasNext();
6928 }
6929
6930 public SubgraphNode next() {
6931 return getNode(iter.next());
6932 }
6933
6934 public void remove() {
6935 throw new UnsupportedOperationException();
6936 }
6937 };
6938 }
6939
6940 public boolean includes( Path path ) {
6941 CheckArg.isNotNull(path, "path");
6942 path = getAbsolutePath(path);
6943 return request.includes(path);
6944 }
6945
6946 public boolean includes( Location location ) {
6947 CheckArg.isNotNull(location, "location");
6948 return request.includes(location);
6949 }
6950
6951 public boolean includes( String pathStr ) {
6952 Path path = createPath(pathStr);
6953 path = getAbsolutePath(path);
6954 return includes(path);
6955 }
6956
6957 public SubgraphNode getNode( Location location ) {
6958 if (!location.hasPath()) return null;
6959 Location actualLocation = request.getLocationFor(location.getPath());
6960 if (actualLocation == null) return null;
6961 return new SubgraphNodeImpl(actualLocation, request);
6962 }
6963
6964 public SubgraphNode getNode( Path path ) {
6965 path = getAbsolutePath(path);
6966 if (!includes(path)) return null;
6967 Location location = request.getLocationFor(path);
6968 if (location == null) return null;
6969 return new SubgraphNodeImpl(location, request);
6970 }
6971
6972 public SubgraphNode getNode( String pathStr ) {
6973 CheckArg.isNotEmpty(pathStr, "path");
6974 Path path = createPath(pathStr);
6975 path = getAbsolutePath(path);
6976 return getNode(path);
6977 }
6978
6979 public SubgraphNode getNode( Name relativePath ) {
6980 Path path = getGraph().getContext()
6981 .getValueFactories()
6982 .getPathFactory()
6983 .create(getLocation().getPath(), relativePath);
6984 path = path.getNormalizedPath();
6985 return getNode(path);
6986 }
6987
6988 protected Path getAbsolutePath( Path absoluteOrRelative ) {
6989 Path result = absoluteOrRelative;
6990 if (!result.isAbsolute()) {
6991 result = getGraph().getContext().getValueFactories().getPathFactory().create(getLocation().getPath(), result);
6992 result = result.getNormalizedPath();
6993 }
6994 return result;
6995 }
6996
6997 @Override
6998 public int hashCode() {
6999 return getLocation().hashCode();
7000 }
7001
7002 @Override
7003 public String toString() {
7004 return "Subgraph\n" + getToString(context);
7005 }
7006
7007
7008
7009
7010
7011
7012
7013 public String getToString( ExecutionContext context ) {
7014 StringBuilder sb = new StringBuilder();
7015 getRecursiveString(context, getRoot(), sb, 0);
7016 return sb.toString();
7017 }
7018
7019 private void getRecursiveString( ExecutionContext context,
7020 SubgraphNode node,
7021 StringBuilder str,
7022 int indentLevel ) {
7023 for (int i = 0; i < indentLevel; ++i) {
7024 str.append(" ");
7025 }
7026 str.append(node.toString());
7027
7028
7029 for (Location nextLoc : node.getChildren()) {
7030 SubgraphNode childNode = getNode(nextLoc);
7031
7032
7033
7034 if (childNode != null) {
7035 getRecursiveString(context, childNode, str, indentLevel + 1);
7036 }
7037 }
7038 }
7039
7040 }
7041
7042 protected static final List<Location> NO_CHILDREN = Collections.emptyList();
7043
7044 @Immutable
7045 class SubgraphNodeImpl implements SubgraphNode {
7046 private final Location location;
7047 private final ReadBranchRequest request;
7048
7049 SubgraphNodeImpl( Location location,
7050 ReadBranchRequest request ) {
7051 this.location = location;
7052 this.request = request;
7053 }
7054
7055 public DateTime getExpirationTime() {
7056 return computeExpirationTime(request);
7057 }
7058
7059 public List<Location> getChildren() {
7060 List<Location> children = request.getChildren(location);
7061 if (children == null) children = NO_CHILDREN;
7062 return children;
7063 }
7064
7065 public Graph getGraph() {
7066 return Graph.this;
7067 }
7068
7069 public Location getLocation() {
7070 return location;
7071 }
7072
7073 public Collection<Property> getProperties() {
7074 return getPropertiesByName().values();
7075 }
7076
7077 public Map<Name, Property> getPropertiesByName() {
7078 return request.getPropertiesFor(location);
7079 }
7080
7081 public Property getProperty( Name name ) {
7082 return getPropertiesByName().get(name);
7083 }
7084
7085 public Property getProperty( String nameStr ) {
7086 Name name = getContext().getValueFactories().getNameFactory().create(nameStr);
7087 return getPropertiesByName().get(name);
7088 }
7089
7090 public boolean hasChildren() {
7091 return getChildren().size() != 0;
7092 }
7093
7094 public List<Segment> getChildrenSegments() {
7095 return getSegments(getChildren());
7096 }
7097
7098 public Iterator<Location> iterator() {
7099 return getChildren().iterator();
7100 }
7101
7102 public SubgraphNode getNode( Name childName ) {
7103 Path path = getContext().getValueFactories().getPathFactory().create(location.getPath(), childName);
7104 Location location = request.getLocationFor(path);
7105 if (location == null) return null;
7106 return new SubgraphNodeImpl(location, request);
7107 }
7108
7109 public SubgraphNode getNode( Path relativePath ) {
7110 Path path = getContext().getValueFactories().getPathFactory().create(location.getPath(), relativePath);
7111 path = path.getNormalizedPath();
7112 Location location = request.getLocationFor(path);
7113 if (location == null) return null;
7114 return new SubgraphNodeImpl(location, request);
7115 }
7116
7117 @Override
7118 public int hashCode() {
7119 return location.hashCode();
7120 }
7121
7122 @Override
7123 public boolean equals( Object obj ) {
7124 if (obj instanceof Node) {
7125 Node that = (Node)obj;
7126 return this.location.isSame(that.getLocation());
7127 }
7128 return false;
7129 }
7130
7131 @Override
7132 public String toString() {
7133 return getNodeString(context, location);
7134 }
7135
7136 private String getNodeString( ExecutionContext context,
7137 Location location ) {
7138 StringBuilder sb = new StringBuilder();
7139 sb.append('<');
7140 ValueFactory<String> strings = context.getValueFactories().getStringFactory();
7141
7142 String name = "";
7143 if (location.getPath().getLastSegment() != null) {
7144 name = strings.create(location.getPath().getLastSegment());
7145 } else {
7146 name = strings.create(location.getPath());
7147 }
7148
7149 if (name.startsWith("{")) {
7150
7151 int end = name.indexOf('}');
7152 name = name.substring(end + 1, name.length());
7153 }
7154
7155
7156 sb.append("name = ").append('\"').append(name).append('\"').append(" ");
7157 boolean first = true;
7158 if (getProperties() != null) {
7159 for (Property entry : getProperties()) {
7160
7161 if (first) {
7162 first = false;
7163 } else sb.append(" ");
7164 sb.append(getPropertyString(entry));
7165 }
7166 }
7167 sb.append(">\n");
7168
7169 return sb.toString();
7170 }
7171
7172 private String getPropertyString( Property property ) {
7173
7174
7175
7176
7177 StringBuilder sb = new StringBuilder();
7178 sb.append(property.getName().getLocalName());
7179 sb.append(" = ");
7180 if (property.isEmpty()) {
7181 sb.append("null");
7182 } else if (property.isSingle()) {
7183 String valueStr = getContext().getValueFactories().getStringFactory().create(property.getValues().next());
7184 sb.append('\"').append(valueStr).append('\"');
7185 } else {
7186 sb.append('[');
7187 boolean first = true;
7188 for (Object value : property.getValuesAsArray()) {
7189 if (first) first = false;
7190 else sb.append(",");
7191 String valueStr = getContext().getValueFactories().getStringFactory().create(value);
7192 sb.append('\"').append(valueStr).append('\"');
7193 }
7194 if (property.isMultiple()) sb.append(']');
7195 }
7196 return sb.toString();
7197 }
7198 }
7199
7200
7201
7202
7203 @Immutable
7204 protected abstract class AbstractAction<T> implements Conjunction<T> {
7205 private final T afterConjunction;
7206
7207
7208 this.afterConjunction = afterConjunction;
7209 }
7210
7211
7212 return this.afterConjunction;
7213 }
7214
7215 public T and() {
7216 return this.afterConjunction;
7217 }
7218
7219
7220 return Graph.this.getContext().getValueFactories().getPathFactory().create(path);
7221 }
7222
7223
7224 return Graph.this.getContext().getValueFactories().getNameFactory().create(name);
7225 }
7226 }
7227
7228 @NotThreadSafe
7229 protected abstract class MoveAction<T> extends AbstractAction<T> implements Move<T> {
7230 private final Locations from;
7231 private Name newName;
7232
7233
7234 Location from ) {
7235 super(afterConjunction);
7236 this.from = new Locations(from);
7237 }
7238
7239 public Move<T> and( Location from ) {
7240 this.from.add(from);
7241 return this;
7242 }
7243
7244 public Move<T> and( String from ) {
7245 this.from.add(Location.create(createPath(from)));
7246 return this;
7247 }
7248
7249 public Move<T> and( Path from ) {
7250 this.from.add(Location.create(from));
7251 return this;
7252 }
7253
7254 public Move<T> and( Property firstFrom,
7255 Property... additionalFroms ) {
7256 this.from.add(Location.create(firstFrom, additionalFroms));
7257 return this;
7258 }
7259
7260 public Move<T> and( Iterable<Property> idPropertiesFrom ) {
7261 this.from.add(Location.create(idPropertiesFrom));
7262 return this;
7263 }
7264
7265 public Move<T> and( Property from ) {
7266 this.from.add(Location.create(from));
7267 return this;
7268 }
7269
7270 public Move<T> and( UUID from ) {
7271 this.from.add(Location.create(from));
7272 return this;
7273 }
7274
7275 public Into<T> as( Name newName ) {
7276 this.newName = newName;
7277 return this;
7278 }
7279
7280
7281
7282
7283
7284
7285 public Into<T> as( String newName ) {
7286 return as(createName(newName));
7287 }
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298 protected abstract T submit( Locations from,
7299 Location into,
7300 Location before,
7301 Name newName );
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311 protected T submit( Locations from,
7312 Location into,
7313 Name newName ) {
7314 return submit(from, into, null, newName);
7315 }
7316
7317 public T into( Location into ) {
7318 return submit(from, into, null, newName);
7319 }
7320
7321 public T into( Path into ) {
7322 return submit(from, Location.create(into), newName);
7323 }
7324
7325 public T into( UUID into ) {
7326 return submit(from, Location.create(into), newName);
7327 }
7328
7329 public T into( Property firstIdProperty,
7330 Property... additionalIdProperties ) {
7331 return submit(from, Location.create(firstIdProperty, additionalIdProperties), newName);
7332 }
7333
7334 public T into( Property into ) {
7335 return submit(from, Location.create(into), newName);
7336 }
7337
7338 public T into( String into ) {
7339 return submit(from, Location.create(createPath(into)), newName);
7340 }
7341
7342 public T before( Location before ) {
7343 return submit(from, null, before, newName);
7344 }
7345
7346 public T before( Path before ) {
7347 return submit(from, null, Location.create(before), newName);
7348 }
7349
7350 public T before( UUID before ) {
7351 return submit(from, null, Location.create(before), newName);
7352 }
7353
7354 public T before( Property firstIdProperty,
7355 Property... additionalIdProperties ) {
7356 return submit(from, null, Location.create(firstIdProperty, additionalIdProperties), newName);
7357 }
7358
7359 public T before( Property before ) {
7360 return submit(from, null, Location.create(before), newName);
7361 }
7362
7363 public T before( String before ) {
7364 return submit(from, null, Location.create(createPath(before)), newName);
7365 }
7366 }
7367
7368 @NotThreadSafe
7369 protected abstract class CopyAction<T> extends AbstractAction<T> implements Copy<T> {
7370 protected Locations from;
7371 protected String fromWorkspaceName;
7372
7373
7374 Location from ) {
7375 super(afterConjunction);
7376 this.from = new Locations(from);
7377 this.fromWorkspaceName = Graph.this.getCurrentWorkspaceName();
7378 }
7379
7380 public Copy<T> and( Location from ) {
7381 this.from.add(from);
7382 return this;
7383 }
7384
7385 public Copy<T> and( String from ) {
7386 this.from.add(Location.create(createPath(from)));
7387 return this;
7388 }
7389
7390 public Copy<T> and( Path from ) {
7391 this.from.add(Location.create(from));
7392 return this;
7393 }
7394
7395 public Copy<T> and( Property firstFrom,
7396 Property... additionalFroms ) {
7397 this.from.add(Location.create(firstFrom, additionalFroms));
7398 return this;
7399 }
7400
7401 public Copy<T> and( Iterable<Property> idProperties ) {
7402 this.from.add(Location.create(idProperties));
7403 return this;
7404 }
7405
7406 public Copy<T> and( Property from ) {
7407 this.from.add(Location.create(from));
7408 return this;
7409 }
7410
7411 public Copy<T> and( UUID from ) {
7412 this.from.add(Location.create(from));
7413 return this;
7414 }
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425 protected abstract T submit( String fromWorkspaceName,
7426 Locations from,
7427 Location into,
7428 Name nameForCopy );
7429
7430 public CopyTarget<T> fromWorkspace( String workspaceName ) {
7431 this.fromWorkspaceName = workspaceName;
7432
7433 return this;
7434 }
7435
7436 public T into( Location into ) {
7437 return submit(this.fromWorkspaceName, this.from, into, null);
7438 }
7439
7440 public T into( Path into ) {
7441 return submit(this.fromWorkspaceName, this.from, Location.create(into), null);
7442 }
7443
7444 public T into( UUID into ) {
7445 return submit(this.fromWorkspaceName, this.from, Location.create(into), null);
7446 }
7447
7448 public T into( Property firstIdProperty,
7449 Property... additionalIdProperties ) {
7450 return submit(this.fromWorkspaceName, this.from, Location.create(firstIdProperty, additionalIdProperties), null);
7451 }
7452
7453 public T into( Property into ) {
7454 return submit(this.fromWorkspaceName, this.from, Location.create(into), null);
7455 }
7456
7457 public T into( String into ) {
7458 return submit(this.fromWorkspaceName, this.from, Location.create(createPath(into)), null);
7459 }
7460
7461 public T to( Location desiredLocation ) {
7462 if (!desiredLocation.hasPath()) {
7463 throw new IllegalArgumentException(GraphI18n.unableToCopyToLocationWithoutAPath.text(this.from, desiredLocation));
7464 }
7465 Path desiredPath = desiredLocation.getPath();
7466 if (desiredPath.isRoot()) {
7467 throw new IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from, desiredLocation));
7468 }
7469 Path parent = desiredPath.getParent();
7470 return submit(this.fromWorkspaceName, this.from, Location.create(parent), desiredPath.getLastSegment().getName());
7471 }
7472
7473 public T to( Path desiredPath ) {
7474 if (desiredPath.isRoot()) {
7475 throw new IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from, desiredPath));
7476 }
7477 Path parent = desiredPath.getParent();
7478 return submit(this.fromWorkspaceName, this.from, Location.create(parent), desiredPath.getLastSegment().getName());
7479 }
7480
7481 public T to( String desiredPath ) {
7482 return to(createPath(desiredPath));
7483 }
7484 }
7485
7486 @NotThreadSafe
7487 public abstract class CloneAction<T> extends AbstractAction<T> implements Clone<T> {
7488 protected final Location from;
7489
7490
7491 Location from ) {
7492 super(afterConjunction);
7493 this.from = from;
7494 }
7495
7496 protected abstract T submit( String fromWorkspaceName,
7497 Location from,
7498 String intoWorkspaceName,
7499 Location into,
7500 Name desiredName,
7501 Segment desiredSegment,
7502 boolean removeExisting );
7503
7504 public AsChild<Into<WithUuids<T>>> fromWorkspace( final String workspaceName ) {
7505 final CloneAction<T> source = this;
7506 return new AsChild<Into<WithUuids<T>>>() {
7507 public Into<WithUuids<T>> as( final Name name ) {
7508 return new CloneTargetAction<T>(afterConjunction(), source) {
7509 @Override
7510 protected T submit( Location into,
7511 boolean removeExisting ) {
7512 String intoWorkspaceName = getCurrentWorkspaceName();
7513 return source.submit(workspaceName, from, intoWorkspaceName, into, name, null, removeExisting);
7514 }
7515 };
7516
7517 }
7518
7519 public Into<WithUuids<T>> as( final String name ) {
7520 return as(context.getValueFactories().getNameFactory().create(name));
7521 }
7522
7523 public Into<WithUuids<T>> as( final Segment segment ) {
7524 return new CloneTargetAction<T>(afterConjunction(), source) {
7525 @Override
7526 protected T submit( Location into,
7527 boolean removeExisting ) {
7528 String intoWorkspaceName = getCurrentWorkspaceName();
7529 return source.submit(workspaceName, from, intoWorkspaceName, into, null, segment, removeExisting);
7530 }
7531 };
7532 }
7533
7534 };
7535 }
7536 }
7537
7538 @NotThreadSafe
7539 public abstract class CloneTargetAction<T> extends AbstractAction<T> implements Into<WithUuids<T>> {
7540 protected final CloneAction<T> source;
7541
7542
7543 CloneAction<T> source ) {
7544 super(afterConjunction);
7545 this.source = source;
7546 }
7547
7548 protected abstract T submit( Location into,
7549 boolean removeExisting );
7550
7551 public WithUuids<T> into( final Location into ) {
7552 return new WithUuids<T>() {
7553 public T failingIfAnyUuidsMatch() {
7554 submit(into, false);
7555 return and();
7556 }
7557
7558 public T replacingExistingNodesWithSameUuids() {
7559 submit(into, true);
7560 return and();
7561
7562 }
7563 };
7564 }
7565
7566 public WithUuids<T> into( Path into ) {
7567 return into(Location.create(into));
7568 }
7569
7570 public WithUuids<T> into( UUID into ) {
7571 return into(Location.create(into));
7572 }
7573
7574 public WithUuids<T> into( Property firstIdProperty,
7575 Property... additionalIdProperties ) {
7576 return into(Location.create(firstIdProperty, additionalIdProperties));
7577 }
7578
7579 public WithUuids<T> into( Property into ) {
7580 return into(Location.create(into));
7581 }
7582
7583 public WithUuids<T> into( String into ) {
7584 return into(Location.create(createPath(into)));
7585 }
7586 }
7587
7588 @NotThreadSafe
7589 protected abstract class CreateAction<T> extends AbstractAction<T> implements Create<T> {
7590 private final String workspaceName;
7591 private final Location parent;
7592 private final Name childName;
7593 private final Map<Name, Property> properties = new HashMap<Name, Property>();
7594 private boolean submitted = false;
7595 private NodeConflictBehavior conflictBehavior = NodeConflictBehavior.APPEND;
7596
7597
7598 Location parent,
7599 String workspaceName,
7600 Name childName ) {
7601 super(afterConjunction);
7602 this.parent = parent;
7603 this.workspaceName = workspaceName;
7604 this.childName = childName;
7605 }
7606
7607
7608
7609
7610
7611
7612 public CreateAction<T> ifAbsent() {
7613 conflictBehavior = NodeConflictBehavior.DO_NOT_REPLACE;
7614 return this;
7615 }
7616
7617
7618
7619
7620
7621
7622 public CreateAction<T> orReplace() {
7623 conflictBehavior = NodeConflictBehavior.REPLACE;
7624 return this;
7625 }
7626
7627
7628
7629
7630
7631
7632 public CreateAction<T> orUpdate() {
7633 conflictBehavior = NodeConflictBehavior.UPDATE;
7634 return this;
7635 }
7636
7637
7638
7639
7640
7641
7642 public CreateAction<T> byAppending() {
7643 conflictBehavior = NodeConflictBehavior.APPEND;
7644 return this;
7645 }
7646
7647 public Create<T> and( UUID uuid ) {
7648 PropertyFactory factory = getContext().getPropertyFactory();
7649 properties.put(ModeShapeLexicon.UUID, factory.create(ModeShapeLexicon.UUID, uuid));
7650 return this;
7651 }
7652
7653 public Create<T> and( Property property ) {
7654 properties.put(property.getName(), property);
7655 return this;
7656 }
7657
7658 public Create<T> and( Iterable<Property> properties ) {
7659 for (Property property : properties) {
7660 this.properties.put(property.getName(), property);
7661 }
7662 return this;
7663 }
7664
7665 public Create<T> and( String name,
7666 Object... values ) {
7667 ExecutionContext context = getContext();
7668 PropertyFactory factory = context.getPropertyFactory();
7669 NameFactory nameFactory = context.getValueFactories().getNameFactory();
7670 Name propertyName = nameFactory.create(name);
7671 properties.put(propertyName, factory.create(propertyName, values));
7672 return this;
7673 }
7674
7675 public Create<T> and( Name name,
7676 Object... values ) {
7677 PropertyFactory factory = getContext().getPropertyFactory();
7678 properties.put(name, factory.create(name, values));
7679 return this;
7680 }
7681
7682 public Create<T> and( Property property,
7683 Property... additionalProperties ) {
7684 properties.put(property.getName(), property);
7685 for (Property additionalProperty : additionalProperties) {
7686 properties.put(additionalProperty.getName(), additionalProperty);
7687 }
7688 return this;
7689 }
7690
7691 public Create<T> with( UUID uuid ) {
7692 return and(uuid);
7693 }
7694
7695 public Create<T> with( Property property ) {
7696 return and(property);
7697 }
7698
7699 public Create<T> with( Iterable<Property> properties ) {
7700 return and(properties);
7701 }
7702
7703 public Create<T> with( Property property,
7704 Property... additionalProperties ) {
7705 return and(property, additionalProperties);
7706 }
7707
7708 public Create<T> with( String name,
7709 Object... values ) {
7710 return and(name, values);
7711 }
7712
7713 public Create<T> with( Name name,
7714 Object... values ) {
7715 return and(name, values);
7716 }
7717
7718 protected abstract T submit( Location parent,
7719 String workspaceName,
7720 Name childName,
7721 Collection<Property> properties,
7722 NodeConflictBehavior conflictBehavior );
7723
7724 @Override
7725 public T and() {
7726 if (!submitted) {
7727 submit(parent, workspaceName, childName, this.properties.values(), this.conflictBehavior);
7728 submitted = true;
7729 }
7730 return super.and();
7731 }
7732 }
7733
7734 @NotThreadSafe
7735 protected abstract class CreateNodeNamedAction<T> extends AbstractAction<T> implements CreateNodeNamed<T> {
7736 private final Location parent;
7737
7738 protected CreateNodeNamedAction( T afterConjunction,
7739 Location parent ) {
7740 super(afterConjunction);
7741 this.parent = parent;
7742 }
7743
7744 public CreateAction<T> nodeNamed( String name ) {
7745 NameFactory factory = getContext().getValueFactories().getNameFactory();
7746 Name nameObj = factory.create(name);
7747 return createWith(afterConjunction(), parent, nameObj);
7748 }
7749
7750 public CreateAction<T> nodeNamed( Name name ) {
7751 return createWith(afterConjunction(), parent, name);
7752 }
7753
7754 protected abstract CreateAction<T> createWith( T afterConjunction,
7755 Location parent,
7756 Name nodeName );
7757 }
7758
7759 @Immutable
7760 protected static final class GraphWorkspace implements Workspace {
7761 private final String name;
7762 private final Location root;
7763
7764 GraphWorkspace( String name,
7765 Location root ) {
7766 assert name != null;
7767 assert root != null;
7768 this.name = name;
7769 this.root = root;
7770 }
7771
7772
7773
7774
7775
7776
7777 public String getName() {
7778 return name;
7779 }
7780
7781
7782
7783
7784
7785
7786 public Location getRoot() {
7787 return root;
7788 }
7789
7790
7791
7792
7793
7794
7795 @Override
7796 public int hashCode() {
7797 return this.name.hashCode();
7798 }
7799
7800
7801
7802
7803
7804
7805 @Override
7806 public boolean equals( Object obj ) {
7807 if (obj == this) return true;
7808 if (obj instanceof GraphWorkspace) {
7809 GraphWorkspace that = (GraphWorkspace)obj;
7810 if (!this.getName().equals(that.getName())) return false;
7811
7812 return true;
7813 }
7814 return false;
7815 }
7816
7817
7818
7819
7820
7821
7822 @Override
7823 public String toString() {
7824 return "Workspace \"" + this.name + "\" (root = " + this.root + " )";
7825 }
7826 }
7827
7828
7829
7830
7831
7832
7833
7834 @Immutable
7835 public interface BaseResults<NodeType extends Node> extends Iterable<NodeType> {
7836
7837
7838
7839
7840
7841
7842 Graph getGraph();
7843
7844
7845
7846
7847
7848
7849
7850 NodeType getNode( String path );
7851
7852
7853
7854
7855
7856
7857
7858 NodeType getNode( Path path );
7859
7860
7861
7862
7863
7864
7865
7866 NodeType getNode( Location location );
7867
7868
7869
7870
7871
7872
7873
7874 boolean includes( String path );
7875
7876
7877
7878
7879
7880
7881
7882 boolean includes( Path path );
7883
7884
7885
7886
7887
7888
7889
7890 boolean includes( Location location );
7891
7892 }
7893 }