Skip to content

Commit a294bcf

Browse files
authored
Update README.md
1 parent dfc1646 commit a294bcf

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,46 @@ public class Test{
1515
public static void main(String args[]){
1616

1717
DBMap dbMap = new DBMap(); //Creates a new DBMap object. The DBMap objects lets you create a mapping between source and destination MySQL Server table names and attribute names of these tables.
18-
TableMap tableMap = new TableMap(); //Creates a new TableMap object. The TableMap objects lets you create a mapping between table names and attribute names withing these tables. This will become a part of the DBMap object we created earlier.
18+
TableMap tableMap = new TableMap("info","new_info","servertime","servertime"); //Creates a new TableMap object. The TableMap objects lets you create a mapping between table names and attribute names withing these tables. This will become a part of the DBMap object we created earlier. The first parameter specifies the table name of the source table while the second parameter specifies the corresponding table name of the destination table. The third parameter specifies the name of the timestamp attribute of the source table which the synchronization will be based on and the last parameters specifies the corresponding timestamp attribute's name.
1919
tableMap.addAttributeMap(new AttributeMap("name","fullname",AttributeType.STRING)); //Creates a new AttributeMap object that maps an attribute name between these tables. Here, the source table has an attribute called 'name', which is mapped to the attribute called 'fullname' in the destination table. The third parameter, AttributeType.STRING tells what type of attribute is being mapped; for e.g. varchar, char, timestamp, etc. are of type AttributeType.STRING whereas float, int, double etc. are of type AttributeType.NUMERICAL.
20-
tableMap.addAttributeMap(new AttributeMap("servertime","servertime",AttributeType.STRING));
20+
tableMap.addAttributeMap(new AttributeMap("servertime","servertime",AttributeType.STRING)); //The synchronizing timestamp attribute of the source and destination tables as specified in the TableMap object creation above is important and need to be separately mapped.
21+
dbMap.addTableMap(tableMap); //Add this newly created table map into the DBMap object.
22+
23+
tableMap = new TableMap("orders","orders","servertime","clienttime"); //Resuse the same TableMap object created above to create a fresh TableMap object and add AttributeMaps to it. Finally, add this table map to the initially created DBMap.
24+
tableMap.addAttributeMap("details","details",AttributeType.STRING);
25+
tableMap.addAttributeMap("id","orderid",AttributeType.NUMERICAL);
26+
tableMap.addAttributeMap("servertime","clienttime",AttributeType.STRING);
27+
dbMap.addTableMap(tableMap); //We are now donw with the mapping procedure.
28+
29+
//Before we can start the synchronization, we need to establish a connection between the server and the client MySQL databases. This, and the actual syncronization is handled by the class DBSyncAgent. An object of this class is built using a standard Builder Pattern.
30+
31+
DBSyncAgent dbSyncAgent = new DBSyncAgent.Builder()
32+
.setServerDatabaseAddress("56.23.53.87") //Set the MySQL server database address here. This can also be a domain name, e.g. xyz.com where the server database is hosted. Also, this value can be localhost.
33+
.setServerDatabaseName("test1") //Set the MySQL server database name from which to synchronize the client database.
34+
.setServerDatabaseUsername("user123") //Set the MySQL server database username for connection.
35+
.setServerDatabasePassword("1234") //Set the MySQL server's corresponding password.
36+
.setServerDatabasePort(3306) //Set the port on which the server database listens, usually 3306.
37+
.setServerDatabaseConnectionOptions("?useSSL=false") //All additional connection options to be passed here. If none, set this string to "".
38+
.set.setClientDatabaseAddress("localhost") //Now do the same for the MySQL client database.
39+
.setClientDatabaseName("test2")
40+
.setClientDatabaseUsername("user567")
41+
.setClientDatabasePassword("9878")
42+
.setClientDatabasePort(3306)
43+
.setClientDatabaseConnectionOptions("?useSSL=false")
44+
.setDBMap(dbMap) //Pass the DBMap object created earlier
45+
.setSyncInterval(20) //Specifies the time interval in which successive synchronization takes places, in seconds. This parameter is the only one that is not necessary to be set here. Also, this is useful only for live synchronization and otherwise can be omitted for one-off synchronization.
46+
.build(); //Builds a new dbSyncAgent using the properties provided using the Builder Pattern.
47+
48+
dbSyncAgent.connect(); //Establish connection to server and client databases.
49+
dbSyncAgent.sync(); //Call this when synchronizing for first time, even if live synchronization is required. If the latter is the case, call the method for live synchronization immediately after this.
50+
dbSyncAgent.liveSync(); //Activates live sync. Make sure syncInterval() method has been used or the sync interval property was set while building the DBSyncObject. So not use this method if the client server has been idle for a while or is starting for the first time, especially if the server receives a lot of entires within this period. In this case, call the sync() function method, followed by this method.
51+
System.out.println("Enter a command:");
52+
Scanner scanner = new Scanner(System.in);
53+
String s = scanner.next(); //The synchronization happens in a new Thread. This main thread is free to receive commands. Use your standard input to enter the command 'end' to end the synchronization. This will end all synchronization activities safely.
54+
if(s.equals("end"){
55+
dbAgent.stopSync(); //Call this method to stop the synchronization safely.
56+
dbAgent.disconnect(); //Call this method after the stopSync() method has been called. Do not call this method without calling the stopSync() method.
57+
}
2158
}
2259
}
2360
```

0 commit comments

Comments
 (0)