17
17
package io .objectbox .sync ;
18
18
19
19
import java .util .Arrays ;
20
+ import java .util .Collections ;
21
+ import java .util .List ;
20
22
21
23
import javax .annotation .Nullable ;
22
24
23
25
import io .objectbox .BoxStore ;
24
26
import io .objectbox .annotation .apihint .Internal ;
27
+ import io .objectbox .exception .FeatureNotAvailableException ;
25
28
import io .objectbox .sync .internal .Platform ;
26
29
import io .objectbox .sync .listener .SyncChangeListener ;
27
30
import io .objectbox .sync .listener .SyncCompletedListener ;
@@ -40,7 +43,7 @@ public final class SyncBuilder {
40
43
final Platform platform ;
41
44
final BoxStore boxStore ;
42
45
String url ;
43
- final SyncCredentials credentials ;
46
+ final List < SyncCredentials > credentials ;
44
47
45
48
@ Nullable SyncLoginListener loginListener ;
46
49
@ Nullable SyncCompletedListener completedListener ;
@@ -83,18 +86,35 @@ public enum RequestUpdatesMode {
83
86
AUTO_NO_PUSHES
84
87
}
85
88
89
+ private static void checkSyncFeatureAvailable () {
90
+ if (!BoxStore .isSyncAvailable ()) {
91
+ throw new FeatureNotAvailableException (
92
+ "This library does not include ObjectBox Sync. " +
93
+ "Please visit https://objectbox.io/sync/ for options." );
94
+ }
95
+ }
96
+
97
+
86
98
@ Internal
87
99
public SyncBuilder (BoxStore boxStore , SyncCredentials credentials ) {
88
100
checkNotNull (boxStore , "BoxStore is required." );
89
101
checkNotNull (credentials , "Sync credentials are required." );
90
- if (!BoxStore .isSyncAvailable ()) {
91
- throw new IllegalStateException (
92
- "This library does not include ObjectBox Sync. " +
93
- "Please visit https://objectbox.io/sync/ for options." );
102
+ checkSyncFeatureAvailable ();
103
+ this .platform = Platform .findPlatform ();
104
+ this .boxStore = boxStore ;
105
+ this .credentials = Collections .singletonList (credentials );
106
+ }
107
+
108
+ @ Internal
109
+ public SyncBuilder (BoxStore boxStore , SyncCredentials [] multipleCredentials ) {
110
+ checkNotNull (boxStore , "BoxStore is required." );
111
+ if (multipleCredentials .length == 0 ) {
112
+ throw new IllegalArgumentException ("At least one Sync credential is required." );
94
113
}
114
+ checkSyncFeatureAvailable ();
95
115
this .platform = Platform .findPlatform ();
96
116
this .boxStore = boxStore ;
97
- this .credentials = credentials ;
117
+ this .credentials = Arrays . asList ( multipleCredentials ) ;
98
118
}
99
119
100
120
@ Internal
@@ -104,6 +124,13 @@ public SyncBuilder(BoxStore boxStore, String url, SyncCredentials credentials) {
104
124
this .url = url ;
105
125
}
106
126
127
+ @ Internal
128
+ public SyncBuilder (BoxStore boxStore , String url , SyncCredentials [] multipleCredentials ) {
129
+ this (boxStore , multipleCredentials );
130
+ checkNotNull (url , "Sync server URL is required." );
131
+ this .url = url ;
132
+ }
133
+
107
134
/**
108
135
* Allows internal code to set the Sync server URL after creating this builder.
109
136
*/
0 commit comments