-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathUpdateExample.java
More file actions
99 lines (86 loc) · 4.97 KB
/
UpdateExample.java
File metadata and controls
99 lines (86 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.example.vault.deprecated;
import com.skyflow.Skyflow;
import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.Env;
import com.skyflow.enums.LogLevel;
import com.skyflow.enums.TokenMode;
import com.skyflow.errors.SkyflowException;
import com.skyflow.vault.data.UpdateRequest;
import com.skyflow.vault.data.UpdateResponse;
import java.util.HashMap;
/**
* @deprecated Pre-v2.1 pattern. Demonstrates two deprecated APIs:
* <ul>
* <li>The {@code "skyflow_id"} key in the data map — use {@code "skyflowId"} instead.</li>
* <li>{@code updateLogLevel()} on the Skyflow client — use {@code setLogLevel()} instead.</li>
* </ul>
* See {@link com.example.vault.UpdateExample} for the current pattern.
*
* Both still work but emit runtime warnings and will be removed in a future release.
*/
@Deprecated
public class UpdateExample {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws SkyflowException {
// Step 1: Set up credentials for the first vault configuration
Credentials credentials = new Credentials();
credentials.setApiKey("<YOUR_API_KEY>"); // Replace with the actual API key
// Step 2: Configure the vault
VaultConfig vaultConfig = new VaultConfig();
vaultConfig.setVaultId("<YOUR_VAULT_ID_1>"); // Replace with the ID of the vault
vaultConfig.setClusterId("<YOUR_CLUSTER_ID_1>"); // Replace with the cluster ID of the vault
vaultConfig.setEnv(Env.PROD); // Set the environment (e.g., DEV, STAGE, PROD)
vaultConfig.setCredentials(credentials); // Associate the credentials with the vault
// Step 3: Set up credentials for the Skyflow client
Credentials skyflowCredentials = new Credentials();
skyflowCredentials.setCredentialsString("<YOUR_CREDENTIALS_STRING>"); // Replace with the actual credentials string
// Step 4: Create a Skyflow client and add vault configurations
// DEPRECATED: use setLogLevel() instead of updateLogLevel()
Skyflow skyflowClient = Skyflow.builder()
.addVaultConfig(vaultConfig)
.addSkyflowCredentials(skyflowCredentials)
.build();
skyflowClient.updateLogLevel(LogLevel.ERROR); // @deprecated — use setLogLevel(LogLevel.ERROR)
// Step 5: Update records with TokenMode enabled
// DEPRECATED: use "skyflowId" key instead of "skyflow_id"
try {
HashMap<String, Object> data1 = new HashMap<>();
data1.put("skyflow_id", "<YOUR_SKYFLOW_ID>"); // @deprecated — use "skyflowId"
data1.put("<COLUMN_NAME_1>", "<COLUMN_VALUE_1>"); // Replace with column name and value to update
data1.put("<COLUMN_NAME_2>", "<COLUMN_VALUE_2>"); // Replace with another column name and value
HashMap<String, Object> tokens = new HashMap<>();
tokens.put("<COLUMN_NAME_2>", "<TOKEN_VALUE_2>"); // Replace with the token for COLUMN_NAME_2
UpdateRequest updateRequest1 = UpdateRequest.builder()
.table("<TABLE_NAME>") // Replace with the table name
.tokenMode(TokenMode.ENABLE) // Enable TokenMode for token validation
.data(data1) // Data to update
.tokens(tokens) // Provide tokens for TokenMode columns
.returnTokens(true) // Return tokens along with the update response
.build();
UpdateResponse updateResponse1 = skyflowClient.vault().update(updateRequest1); // Perform the update
System.out.println("Update Response (TokenMode Enabled): " + updateResponse1);
} catch (SkyflowException e) {
System.out.println("Error during update with TokenMode enabled:");
e.printStackTrace();
}
// Step 6: Update records with TokenMode disabled
// DEPRECATED: use "skyflowId" key instead of "skyflow_id"
try {
HashMap<String, Object> data2 = new HashMap<>();
data2.put("skyflow_id", "<YOUR_SKYFLOW_ID>"); // @deprecated — use "skyflowId"
data2.put("<COLUMN_NAME_1>", "<COLUMN_VALUE_1>"); // Replace with column name and value to update
data2.put("<COLUMN_NAME_2>", "<COLUMN_VALUE_2>"); // Replace with another column name and value
UpdateRequest updateRequest2 = UpdateRequest.builder()
.table("<TABLE_NAME>") // Replace with the table name
.tokenMode(TokenMode.DISABLE) // Disable TokenMode
.data(data2) // Data to update
.returnTokens(false) // Do not return tokens
.build();
UpdateResponse updateResponse2 = skyflowClient.vault().update(updateRequest2); // Perform the update
System.out.println("Update Response (TokenMode Disabled): " + updateResponse2);
} catch (SkyflowException e) {
System.out.println("Error during update with TokenMode disabled:" + e);
}
}
}