1
+ /* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
2
+ This software is dual-licensed to you under the Universal Permissive License
3
+ (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License
4
+ 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
5
+ either license.
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+ https://www.apache.org/licenses/LICENSE-2.0
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ DESCRIPTION
17
+ Main - Runner class calling multiple methods
18
+ */
19
+
20
+ package org .oracle ;
21
+
22
+ import oracle .sql .json .OracleJsonArray ;
23
+ import oracle .sql .json .OracleJsonFactory ;
24
+ import oracle .sql .json .OracleJsonObject ;
25
+
26
+ public class Main {
27
+ private static DatabaseConfig pds ;
28
+
29
+ public static void main (String [] args ) {
30
+
31
+ pds = new DatabaseConfig ();
32
+ OracleJsonFactory f = new OracleJsonFactory ();
33
+
34
+ /*
35
+ * Example 1
36
+ * Get all teams
37
+ */
38
+ System .out .println ("Example 1: Retrieve all teams using team_info_dv" );
39
+ TeamManager .retrieveTeam (pds );
40
+ System .out .println ("\n " );
41
+
42
+ /*
43
+ * Example 2
44
+ * Get specific team
45
+ */
46
+ System .out .println ("Example 2: Retrieve specific teams using team_info_dv" );
47
+ TeamManager .retrieveTeam (pds , 2 );
48
+ System .out .println ("\n " );
49
+ /*
50
+ * Example 3
51
+ * Create new team using INSERT into team_info_dv
52
+ */
53
+ System .out .println ("Example 3: Create a new team using team_info_dv" );
54
+ OracleJsonObject withTeamA = f .createObject ();
55
+ withTeamA .put ("_id" , 3 );
56
+ withTeamA .put ("name" , "Mountain Movers" );
57
+ withTeamA .put ("region" , "South America" );
58
+ withTeamA .put ("color" , "cc2222" );
59
+
60
+ TeamManager .insertNewTeam (pds , withTeamA );
61
+ System .out .println ("\n " );
62
+ /*
63
+ * Example 4
64
+ * Create new Player in Team using an UPDATE into team_info_dv with
65
+ * JSON_TRANSFORM
66
+ */
67
+ System .out .println ("Example 4: Create a new player using JSON_TRANSFORM and team_info_dv" );
68
+ OracleJsonObject withPlayerA = f .createObject ();
69
+ withPlayerA .put ("playerId" , 7 );
70
+ withPlayerA .put ("name" , "PLAYER_GABRIEL" );
71
+ withPlayerA .put ("position" , "Support" );
72
+
73
+ TeamManager .updateTeam (pds , withPlayerA , 3 );
74
+ System .out .println ("\n " );
75
+
76
+ /*
77
+ * Example 5
78
+ * Create new Player in Team using INSERT into player_team_info_dv\
79
+ */
80
+ System .out .println ("Example 5: Create a new player using player_team_info_dv" );
81
+ OracleJsonObject withPlayerB = f .createObject ();
82
+ withPlayerB .put ("_id" , 8 );
83
+ withPlayerB .put ("name" , "PLAYER_HARVEY" );
84
+ withPlayerB .put ("position" , "Offense" );
85
+ withPlayerB .put ("teamId" , 3 );
86
+
87
+ TeamManager .insertNewPlayer (pds , withPlayerB , 3 );
88
+ System .out .println ("\n " );
89
+
90
+ /*
91
+ * Example 5
92
+ * Update Team with new players as a whole JSON document using team_info_dv.
93
+ *
94
+ * This example shows that replacing the players with a new
95
+ * set of players remove the old ones from
96
+ * the PLAYERS table.
97
+ *
98
+ * In this example, an OracleJSONObject is created from
99
+ * a copy of the oldTeam and an update on the object is done
100
+ * to replace the players team
101
+ */
102
+ System .out .println ("Example 6: " );
103
+ OracleJsonObject withPlayerC = f .createObject ();
104
+ withPlayerC .put ("playerId" , 10 );
105
+ withPlayerC .put ("name" , "PLAYER_MARK" );
106
+ withPlayerC .put ("position" , "Offense" );
107
+
108
+ OracleJsonObject withPlayerD = f .createObject ();
109
+ withPlayerD .put ("playerId" , 11 );
110
+ withPlayerD .put ("name" , "PLAYER_NATHAN" );
111
+ withPlayerD .put ("position" , "Offense" );
112
+
113
+ OracleJsonArray newPlayerArr = f .createArray ();
114
+ newPlayerArr .add (withPlayerC );
115
+ newPlayerArr .add (withPlayerD );
116
+
117
+ int teamId = 1 ; // Specify which team
118
+ OracleJsonObject oldTeam = TeamManager .retrieveAndReferenceTeam (pds , teamId );
119
+ if (oldTeam != null ) {
120
+ OracleJsonObject newTeam = f .createObject (oldTeam );
121
+ newTeam .put ("players" , newPlayerArr );
122
+ TeamManager .updateTeamAsAWhole (pds , newTeam , teamId );
123
+ System .out .println ("\n " );
124
+
125
+ }
126
+ }
127
+ }
0 commit comments