Skip to content

Commit 1eae09d

Browse files
authored
Add files via upload
1 parent 933e0bc commit 1eae09d

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

DBSynchronizerService.java

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright 2017 Arvind Sasikumar.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
import java.io.FileNotFoundException;
25+
import sync.db.mysql.*;
26+
import java.util.Scanner;
27+
28+
/**
29+
* Console version.
30+
* @author Arvind Sasikumar
31+
*/
32+
public class DBSynchronizerService {
33+
34+
public static void main(String[] args){
35+
36+
Scanner scanner = new Scanner(System.in);
37+
38+
System.out.println("Enter server database address: ");
39+
String serverDatabaseAddress = scanner.next();
40+
System.out.println("Enter server database name: ");
41+
String serverDatabaseName = scanner.next();
42+
System.out.println("Enter server database username: ");
43+
String serverDatabaseUsername = scanner.next();
44+
System.out.println("Enter server database password: ");
45+
String serverDatabasePassword = scanner.next();
46+
System.out.println("Enter server database port: ");
47+
int serverDatabasePort = scanner.nextInt();
48+
System.out.println("Enter server database connection options: ");
49+
String serverDatabaseConnectionOptions = scanner.next();
50+
51+
System.out.println("Enter client database address: ");
52+
String clientDatabaseAddress = scanner.next();
53+
System.out.println("Enter client database name: ");
54+
String clientDatabaseName = scanner.next();
55+
System.out.println("Enter client database username: ");
56+
String clientDatabaseUsername = scanner.next();
57+
System.out.println("Enter client database password: ");
58+
String clientDatabasePassword = scanner.next();
59+
System.out.println("Enter client database port: ");
60+
int clientDatabasePort = scanner.nextInt();
61+
System.out.println("Enter client database connection options: ");
62+
String clientDatabaseConnectionOptions = scanner.next();
63+
scanner.nextLine();
64+
System.out.println("Enter full path to the dmml file to create the database map: ");
65+
String dmmlFilePath = scanner.nextLine();
66+
67+
DBMap dbMap = new DBMap();
68+
try{
69+
70+
dbMap = DBMap.getDBMapFromFile(dmmlFilePath);
71+
}
72+
catch(FileNotFoundException e){
73+
74+
System.out.println("DMML File not found!");
75+
System.exit(0);
76+
}
77+
catch(InvalidDBMapFileException e){
78+
79+
System.out.println("Invalid DBMap File!");
80+
System.exit(0);
81+
}
82+
catch(Exception e){
83+
84+
e.printStackTrace();
85+
System.exit(0);
86+
}
87+
88+
DBSyncAgent dbSyncAgent = new DBSyncAgent.Builder()
89+
.setServerDatabaseAddress(serverDatabaseAddress)
90+
.setServerDatabaseName(serverDatabaseName)
91+
.setServerDatabaseUsername(serverDatabaseUsername)
92+
.setServerDatabasePassword(serverDatabasePassword)
93+
.setServerDatabasePort(serverDatabasePort)
94+
.setServerDatabaseConnectionOptions(serverDatabaseConnectionOptions)
95+
.setClientDatabaseAddress(clientDatabaseAddress)
96+
.setClientDatabaseName(clientDatabaseName)
97+
.setClientDatabaseUsername(clientDatabaseUsername)
98+
.setClientDatabasePassword(clientDatabasePassword)
99+
.setClientDatabasePort(clientDatabasePort)
100+
.setClientDatabaseConnectionOptions(clientDatabaseConnectionOptions)
101+
.setDBMap(dbMap)
102+
.build();
103+
104+
dbSyncAgent.setSyncInterval(30);
105+
106+
dbSyncAgent.connect();
107+
dbSyncAgent.sync();
108+
dbSyncAgent.hold();
109+
dbSyncAgent.liveSync();
110+
111+
String s;
112+
s = scanner.next();
113+
114+
dbSyncAgent.stopSync();
115+
dbSyncAgent.disconnect();
116+
}
117+
}

0 commit comments

Comments
 (0)