Skip to content

Commit

Permalink
Merge branch '3.9' of https://github.com/JumpMind/symmetric-ds into 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
klementinastojanovska committed Jan 26, 2018
2 parents 0d71c71 + f433ee3 commit a17e0de
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
40 changes: 36 additions & 4 deletions symmetric-assemble/src/asciidoc/developer.ad
Expand Up @@ -182,20 +182,52 @@ symmetric-assemble directory:

The first step to using SymmetricDS in an Android application is to unzip the jar files into a location where the project will recognize them.
The latest Android SDK requires that these jar files be put into a libs directory under the app directory of the Android application project.

+

[IMPORTANT]
In order to sync properly, the Sync URL of the corp-000 node must be updated to use the IP address of host rather than localhost.
Then, update the String REGISTRATION_URL in the DbProvider class of the Android project to the new Sync URL of the corp-000 node.
+

Next, set up an Android Emulator. This can be done by opening the Android Virtual Device Manager. Click New and follow the steps. The higher
Next, set up an Android Emulator or connect and Android device. This can be done by opening the Android Virtual Device Manager. Click New and follow the steps. The higher
the Emulator's API, the better.

Run your Android Application by pressing the Run button in Android Studio. When prompted, select the emulator you just created. Monitor the
Console in Android Studio. Let the apk install on the emulator. Now watch the LogCat and wait as it attempts to register with your SymmetricDS
Master Node.

The core functionality of SymmetricDS on Android is implemented by starting the SymmetricService class as an Android service. This requires
building the SymmetricDS Android libraries using the steps mentioned above and adding them to your Android project�s dependencies.�

The SymmetricService Intent is defined in the AndroidManifest.xml using the following XML snippet:

[source, xml]
----
<service android:name="org.jumpmind.symmetric.android.SymmetricService" android:enabled="true" >
<intent-filter>
<action android:name="org.jumpmind.symmetric.android.SymmetricService" />
</intent-filter>
</service>
----

The SymmetricService Intent is started using the following java code:

[source, java]
----
Intent intent = new Intent(getContext(), SymmetricService.class);

// Replace extras with desired node configuration
intent.putExtra(SymmetricService.INTENTKEY_SQLITEOPENHELPER_REGISTRY_KEY, DATABASE_NAME);
intent.putExtra(SymmetricService.INTENTKEY_REGISTRATION_URL, REGISTRATION_URL);
intent.putExtra(SymmetricService.INTENTKEY_EXTERNAL_ID, NODE_ID);
intent.putExtra(SymmetricService.INTENTKEY_NODE_GROUP_ID, NODE_GROUP);
intent.putExtra(SymmetricService.INTENTKEY_START_IN_BACKGROUND, true);

Properties properties = new Properties();
// Put any additional SymmetricDS parameters into properties
intent.putExtra(SymmetricService.INTENTKEY_PROPERTIES, properties);

getContext().startService(intent);
----

=== Embedding in C/C++
A minimal implementation of the SymmetricDS client is written in C, which includes a shared library named "libsymclient" and a command line executable
named "sym" for synchronizing a database. It currently only supports the SQLite database. The SymmetricDS C library and client are built
Expand Down
Expand Up @@ -27,7 +27,7 @@ Before a node is allowed to register, it must have an open registration. If the

You can open registration from the command line with the following command:

`bin/symadmin --engine <engine name> <node group> <external id>`
`bin/symadmin open-registration --engine <engine name> <node group> <external id>`

The <node group> and <external id> should match the `group.id` and `external.id` in the registering node's <<Node Properties File>>.

Expand Down
Expand Up @@ -56,4 +56,11 @@ protected void appendColumnEquals(StringBuilder sql, Column column) {
}
}

@Override
protected String escapeText(String value) {
value = super.escapeText(value);
value = value.replace("\\", "\\\\");
value = value.replace("$", "\\$");
return value;
}
}
17 changes: 11 additions & 6 deletions symmetric-db/src/main/java/org/jumpmind/db/sql/DmlStatement.java
Expand Up @@ -28,6 +28,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
Expand Down Expand Up @@ -73,6 +74,8 @@ public enum DmlType {

protected String textColumnExpression;

protected static final String QUESTION_MARK = "<!QUESTION_MARK!>";

public DmlStatement(DmlType type, String catalogName, String schemaName, String tableName,
Column[] keysColumns, Column[] columns, boolean[] nullKeyValues,
DatabaseInfo databaseInfo, boolean useQuotedIdentifiers, String textColumnExpression) {
Expand Down Expand Up @@ -453,7 +456,6 @@ public Object[] getValueArray(Map<String, Object> params) {

public String buildDynamicSql(BinaryEncoding encoding, Row row,
boolean useVariableDates, boolean useJdbcTimestampFormat, Column[] columns) {
final String QUESTION_MARK = "<!QUESTION_MARK!>";
String newSql = sql;
String quote = databaseInfo.getValueQuoteToken();
String binaryQuoteStart = databaseInfo.getBinaryQuoteStart();
Expand All @@ -472,11 +474,8 @@ public String buildDynamicSql(BinaryEncoding encoding, Row row,
if (column.isOfTextType()) {
try {
String value = row.getString(name);
value = value.replace("\\", "\\\\");
value = value.replace("$", "\\$");
value = value.replace("'", "''");
value = value.replace("?", QUESTION_MARK);
newSql = newSql.replaceFirst(regex, quote + value + quote);
value = escapeText(value);
newSql = newSql.replaceFirst(regex, quote + Matcher.quoteReplacement(value) + quote);
} catch (RuntimeException ex) {
log.error("Failed to replace ? in {" + sql + "} with " + name + "="
+ row.getString(name));
Expand Down Expand Up @@ -553,5 +552,11 @@ public String[] getLookupKeyData(Map<String, String> lookupDataMap) {
}
return null;
}

protected String escapeText(String value) {
value = value.replace("?", QUESTION_MARK);
value = value.replace("'", "''");
return value;
}

}

0 comments on commit a17e0de

Please sign in to comment.