@@ -29,37 +29,57 @@ public final class RestoreTableRequest {
29
29
private final String sourceBackupId ;
30
30
private final String sourceClusterId ;
31
31
private final String sourceInstanceId ;
32
+ private final String sourceProjectId ;
32
33
33
34
/**
34
35
* Create a {@link RestoreTableRequest} object. It assumes the source backup locates in the same
35
- * instance as the destination table. To restore a table from a backup in another instance, use
36
- * {@link #of(String, String, String) of} method.
36
+ * instance and project as the destination table. To restore a table from a backup in another
37
+ * instance, use {@link #of(String, String, String) of} method. To restore a table from a backup
38
+ * in another project, use {@link #of(String, String, String, String) of} method.
37
39
*/
38
40
public static RestoreTableRequest of (String sourceClusterId , String sourceBackupId ) {
39
- RestoreTableRequest request = new RestoreTableRequest (null , sourceClusterId , sourceBackupId );
41
+ RestoreTableRequest request =
42
+ new RestoreTableRequest (null , sourceClusterId , sourceBackupId , null );
40
43
return request ;
41
44
}
42
45
43
46
/**
44
- * Create a {@link RestoreTableRequest} object. The source backup could locate in a the same or a
45
- * different instance.
47
+ * Create a {@link RestoreTableRequest} object. The source backup could locate in the same or a
48
+ * different instance but the same project as the destination table. To restore a table from a
49
+ * backup in another project, use {@link #of(String, String, String, String) of} method.
46
50
*/
47
51
public static RestoreTableRequest of (
48
52
String sourceInstanceId , String sourceClusterId , String sourceBackupId ) {
49
53
RestoreTableRequest request =
50
- new RestoreTableRequest (sourceInstanceId , sourceClusterId , sourceBackupId );
54
+ new RestoreTableRequest (sourceInstanceId , sourceClusterId , sourceBackupId , null );
55
+ return request ;
56
+ }
57
+
58
+ /**
59
+ * Create a {@link RestoreTableRequest} object. The source backup could locate in the same or a
60
+ * different instance and/or project.
61
+ */
62
+ public static RestoreTableRequest of (
63
+ String sourceInstanceId ,
64
+ String sourceClusterId ,
65
+ String sourceBackupId ,
66
+ String sourceProjectId ) {
67
+ RestoreTableRequest request =
68
+ new RestoreTableRequest (sourceInstanceId , sourceClusterId , sourceBackupId , sourceProjectId );
51
69
return request ;
52
70
}
53
71
54
72
private RestoreTableRequest (
55
73
@ Nullable String sourceInstanceId ,
56
74
@ Nonnull String sourceClusterId ,
57
- @ Nonnull String sourceBackupId ) {
75
+ @ Nonnull String sourceBackupId ,
76
+ @ Nullable String sourceProjectId ) {
58
77
Preconditions .checkNotNull (sourceClusterId );
59
78
Preconditions .checkNotNull (sourceBackupId );
60
79
this .sourceBackupId = sourceBackupId ;
61
80
this .sourceInstanceId = sourceInstanceId ;
62
81
this .sourceClusterId = sourceClusterId ;
82
+ this .sourceProjectId = sourceProjectId ;
63
83
}
64
84
65
85
public RestoreTableRequest setTableId (String tableId ) {
@@ -80,13 +100,18 @@ public boolean equals(Object o) {
80
100
return Objects .equal (requestBuilder .getTableId (), that .requestBuilder .getTableId ())
81
101
&& Objects .equal (sourceInstanceId , that .sourceInstanceId )
82
102
&& Objects .equal (sourceClusterId , that .sourceClusterId )
83
- && Objects .equal (sourceBackupId , that .sourceBackupId );
103
+ && Objects .equal (sourceBackupId , that .sourceBackupId )
104
+ && Objects .equal (sourceProjectId , that .sourceProjectId );
84
105
}
85
106
86
107
@ Override
87
108
public int hashCode () {
88
109
return Objects .hashCode (
89
- requestBuilder .getTableId (), sourceInstanceId , sourceClusterId , sourceBackupId );
110
+ requestBuilder .getTableId (),
111
+ sourceInstanceId ,
112
+ sourceClusterId ,
113
+ sourceBackupId ,
114
+ sourceProjectId );
90
115
}
91
116
92
117
@ InternalApi
@@ -99,7 +124,7 @@ public com.google.bigtable.admin.v2.RestoreTableRequest toProto(
99
124
.setParent (NameUtil .formatInstanceName (projectId , instanceId ))
100
125
.setBackup (
101
126
NameUtil .formatBackupName (
102
- projectId ,
127
+ sourceProjectId == null ? projectId : sourceProjectId ,
103
128
sourceInstanceId == null ? instanceId : sourceInstanceId ,
104
129
sourceClusterId ,
105
130
sourceBackupId ))
0 commit comments