-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDatabaseSetup.java
More file actions
52 lines (43 loc) · 1.67 KB
/
DatabaseSetup.java
File metadata and controls
52 lines (43 loc) · 1.67 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
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
public class DatabaseSetup {
public static void main(String[] args) {
Cluster cluster;
Session session;
cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
session = cluster.connect();
try{
session.execute("CREATE KEYSPACE Dream11 with replication = {'class': 'SimpleStrategy', 'replication_factor': 3};");
session.execute("USE Dream11;");
} catch (Exception e) {
session.execute("USE Dream11;");
}
try{
session.execute(
"CREATE TABLE teams ( " +
"userID int, " +
"teamID int, " +
"matchID int, " +
"playerIDs list<int>, " +
"PRIMARY KEY((userID, matchID), teamID)" +
");"
);
} catch (Exception e) {
session.execute("TRUNCATE TABLE teams;");
}
try{
session.execute(
"CREATE TABLE players ( " +
"matchID int, " +
"playerID int, " +
"playerName text, " +
"score int, " +
"PRIMARY KEY(playerID, matchID)" +
");"
);
} catch (Exception e) {
session.execute("TRUNCATE TABLE players;");
}
System.exit(0);
}
}