Skip to content

Commit

Permalink
Documentation changes for Android and bulk loaders.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwilmer committed Jul 3, 2013
1 parent 2e9dd03 commit 53771a2
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 4 deletions.
1 change: 1 addition & 0 deletions symmetric-assemble/src/docbook/advanced-topics.xml
Expand Up @@ -778,4 +778,5 @@ Enter key password for <sym>
</para>
</section>
<xi:include href="extensions.xml" />
<xi:include href="android.xml"/>
</chapter>
314 changes: 314 additions & 0 deletions symmetric-assemble/src/docbook/android.xml
@@ -0,0 +1,314 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Licensed to JumpMind Inc under one or more contributor license agreements.
See the NOTICE file distributed with this work for additional information
regarding copyright ownership. JumpMind Inc licenses this file to you under
the GNU General Public License, version 3.0 (GPLv3) (the "License"); you
may not use this file except in compliance with the License. You should have
received a copy of the GNU General Public License, version 3.0 (GPLv3) along
with this library; if not, see <http://www.gnu.org/licenses/>. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<section version="5.0" xml:id="android" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns="http://docbook.org/ns/docbook"
xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:html="http://www.w3.org/1999/xhtml">
<title>Synchronization to and from Android Devices </title>

<para>
SymmetricDS now has its web-enabled, fault-tolerant, database
synchronization
software available on the Android mobile computing
platform. The Android client follows all of the same concepts and
brings to Android
all of the same core SymmetricDS features as the
full-featured,
Java-based SymmetricDS client. The Android client is a
little bit different
in that it is not a stand-alone application, but
is designed to
be referenced
as a library to run in-process with an
Android
application
requiring
synchronization for its SQLite database.
</para>
<para>
By using SymmetricDS, mobile application development is
simplified, in that the mobile application developer can now focus
solely on interacting with their local SQLite database. SymmetricDS
takes care of capturing and moving data changes to and from a
centralized database when the network is available
</para>
<para>
One of the main goals of the SymmetricDS 3 release was to support
deployment to Android devices. SymmetricDS's overall footprint was
reduced by eliminating a number of external dependencies in order to
better deploy to Android. Also, the database access layer was
abstracted so that the Android specific database access layer could be
used. This allows SymmetricDS to be efficient in accessing the SQLite
database on the Android device.
</para>
<para>
In order to convey how to use the SymmetricDS Android libraries,
the example below will show how to integrate SymmetricDS into the NotePad
sample application that comes with the Android ADK.
</para>
<para>
The NotePad sample application is a very simple task list
application
that persists “notes” to a SQLite database table called
Notes. The
Notes table will be configured to synchronize to a
centralized version
of the table. The Notes table looks as follows:
</para>
<para>
<table>
<title>Notes Table</title>
<tgroup cols="2">
<thead>
<row>
<entry>Column Name</entry>
<entry>Column Type</entry>
</row>
</thead>
<tbody>
<row>
<entry>_ID(PK)</entry>
<entry>INTEGER</entry>
</row>
<row>
<entry>TITLE</entry>
<entry>TEXT</entry>
</row>
<row>
<entry>NOTES</entry>
<entry>TEXT</entry>
</row>
<row>
<entry>CREATED</entry>
<entry>INTEGER</entry>
</row>
<row>
<entry>MODIFIED</entry>
<entry>INTEGER</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
Next, we will describe how to embed SymmetricDS in the NotePad
application. Eclipse 3.7.2 and Android ADK 20.0.3 were used for this
example.
</para>
<para>
To start,create the NotePad project. You do
this by adding a new Android Sample Project. Select the NotePad
project.
</para>
<para>
<figure id="New Sample NotePad Project">
<title>New Sample NotePad Project</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/sync-android-1.png"
format="PNG" />
</imageobject>
</mediaobject>
</figure>
</para>
<para>
SymmetricDS for Android comes as a zip file of Java archives (jar
files) that are required by the SymmetricDS client at runtime. This
zip file ()symmetric-ds-3.4.7-android.zip) can be downloaded from
the SymmetricDS.org website. 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 and the Eclipse
ADK requires that these jar files be put into a libs directory under
the Android application project.
</para>
<para>
<figure id="Sample NotePad Project">
<title>New Sample NotePad Project</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/sync-android-2.png" width="9.5in" scalefit="1" align="center"
format="PNG" />
</imageobject>
</mediaobject>
</figure>
</para>
<para>
Unzip the symmetric-ds-x.x.x-android.zip file to the NotePad
project directory. Refresh the NotePad project in Eclipse. You should
end up with a libs directory that is automatically added to the Android
Dependencies.
</para>
<para>
<figure id="Jar Files Added to Libs">
<title>Jar Files Added to Libs</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/sync-android-3.png" width="9.5in" scalefit="1" align="center"
format="PNG" />
</imageobject>
</mediaobject>
</figure>
</para>
<para>
The Android version of the SymmetricDS engine is a Java class that can
be
instantiated directly or wired into an application via a provided
Android service. Whether you are using the service or the engine
directly you need to provide a few required startup parameters to the
engine:
<itemizedlist>
<listitem><command>SQLiteOpenHelper</command> – It is best (but not required) if the
SQLiteOpenHelper is shared with the application that will be sharing
the SQLite database. This core Android Java class provides software
synchronization around the access to the database and minimizes
locking errors.
</listitem>
<listitem><command>registrationUrl</command> – This is the URL of where the centralized
SymmetricDS instance is hosted.
</listitem>
<listitem><command>externalId</command> – This is the identifier that can be used by the
centralized SymmetricDS server to identify whether this instance
should get data changes that happen on the server. It could be the
serial number of the device, an account username, or some other
business concept like store number.
</listitem>
<listitem><command>nodeGroupId</command> – This is the group id for the mobile device in
the synchronization configuration. For example, if the nodeGroupId
is 'handheld', then the SymmetricDS configuration might have a group
called 'handheld' and a group called 'corp' where 'handheld' is
configured to push and pull data from 'corp.'
</listitem>
<listitem><command>properties</command> – Optionally tweak the settings for SymmetricDS.
</listitem>
</itemizedlist>
</para>
<para>
In order to integrate SymmetricDS into the NotePad application,
the
Android-specific SymmetricService will be used, and we need to tell
the Android application this by adding the service to the
AndroidManifest.xml file. Add the following snipped to the Manifest as
the last entry under the <![CDATA[<application>]]>
tag.
</para>
<para>
<programlisting>
<![CDATA[<service android:name="org.jumpmind.symmetric.android.SymmetricService" android:enabled="true" >
<intent-filter>
<action android:name="org.jumpmind.symmetric.android.SymmetricService" />
</intent-filter>
</service>]]>
</programlisting>
</para>

<para>
The other change required in the Manifest is to give the application
permission to use the Internet. Add this as the first entry in the
AndroidManifest.xml right before the
<![CDATA[<application> tag]]>.
</para>

<para>
<programlisting>
<![CDATA[<uses-permission android:name="android.permission.INTERNET"></uses-permission> ]]>
</programlisting>
</para>

<para>
The only additional change needed is the call to start the service in the
application. The service needs to be started manually because we need
to give the application a chance to provide configuration information
to the service.
</para>

<para>
In NotePadProvider.java add the following code snippet in the onCreate
method.
</para>

<para>
<figure id="NotePadProvider.java">
<title>NotePadProvider.java</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/sync-android-4.png" width="9.5in" scalefit="1" align="center"
format="PNG" />
</imageobject>
</mediaobject>
</figure>
</para>

<para>
<programlisting>
<![CDATA[
final String HELPER_KEY = "NotePadHelperKey";
// Register the database helper, so it can be shared with the
SymmetricService
SQLiteOpenHelperRegistry.register(HELPER_KEY, mOpenHelper);
Intent intent = new Intent(getContext(), SymmetricService.class);
// Notify the service of the database helper key
intent.putExtra(SymmetricService.INTENTKEY_SQLITEOPENHELPER_REGISTRY_KEY,
HELPER_KEY);
intent.putExtra(SymmetricService.INTENTKEY_REGISTRATION_URL,
"http://10.0.2.2:31415/sync/server");
intent.putExtra(SymmetricService.INTENTKEY_EXTERNAL_ID,
"android-simulator");
intent.putExtra(SymmetricService.INTENTKEY_NODE_GROUP_ID, "client");
intent.putExtra(SymmetricService.INTENTKEY_START_IN_BACKGROUND,
true);
Properties properties = new Properties();
// initial load existing notes from the Client to the Server
properties.setProperty(ParameterConstants.AUTO_RELOAD_REVERSE_ENABLED,
"true");
intent.putExtra(SymmetricService.INTENTKEY_PROPERTIES, properties);
getContext().startService(intent);
]]>
</programlisting>
</para>

<para>
This code snippet shows how the SQLiteOpenHelper is shared. The
application's SQLiteOpenHelper is registered in a static registry
provided by the SymmetricDS Android library. When the service is
started, the key used to store the helper is passed to the service so
that the service may pull the helper back out of the registry.
</para>

<para>
The various parameters needed by SymmetricDS are being set in the Intent
which will be used by the SymmetricService to start the engine.
</para>

<para>
Most of the parameters will be familiar to SymmetricDS users. In this case
a property is being set which will force an initial load of the
existing Notes from the client to the server. This allows the user of
the application to enter Notes for the first time offline or while the
SymmetricDS engine is unregistered and still have them arrive at the
centralized server once the SymmetricDS engine does get registered.
</para>

<para>
That's all you have to do to integrate SymmetricDS with your Android
application. Users who are adventurous or are already familiar with
SymmetricDS can probably figure out how to setup the central
SymmetricDS server and configuration synchronization for the Notes
table. The second part of this article will describe exactly that. A
few transformation goodies will be thrown in as well.
</para>
</section>
20 changes: 17 additions & 3 deletions symmetric-assemble/src/docbook/databases.xml
Expand Up @@ -244,6 +244,10 @@
</para>
<section id="ap02-oracle">
<title>Oracle</title>
<para>SymmetricDS has bulk loading capability available for Oracle. SymmetricDS specifies data loader types on
a channel by channel basis. To utilize Oracle Bulk loading versus straight JDBC insert, specify the Oracle Bulk
Loader ("oracle_bulk") in the data_loader_type column of sym_channel.
</para>
<para>
While BLOBs are supported on Oracle, the LONG data type is not. LONG columns cannot be accessed from triggers.
</para>
Expand Down Expand Up @@ -311,7 +315,7 @@ CREATE UNIQUE INDEX IDX_D_CHANNEL_ID ON SYM_DATA (DATA_ID, CHANNEL_ID) LOCAL
and resync the triggers. The error can happen when the captured data in a row exceeds 4k and lob columns do not exist
in the table. By enabling <code>use_capture_lobs</code> the concatanated varchar string is cast to a clob which
allows a length of more than 4k.
</para>
</para>
</section>
<section id="ap02-mysql">
<title>MySQL</title>
Expand Down Expand Up @@ -355,6 +359,10 @@ CREATE UNIQUE INDEX IDX_D_CHANNEL_ID ON SYM_DATA (DATA_ID, CHANNEL_ID) LOCAL
</section>
<section id="ap02-postgresql">
<title>PostgreSQL</title>
<para>SymmetricDS has bulk loading capability available for Postgres. SymmetricDS specifies data loader types on
a channel by channel basis. To utilize Postgres Bulk loading versus straight JDBC insert, specify the Postgres Bulk
Loader ("postgres_bulk") in the data_loader_type column of sym_channel.
</para>
<para>
Starting with PostgreSQL 8.3, SymmetricDS supports the transaction identifier.
Binary Large Object (BLOB) replication is supported for both byte array (BYTEA)
Expand Down Expand Up @@ -399,13 +407,19 @@ CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql
GRANT CREATE ON SCHEMA {schema name} TO {user name};
]]></programlisting>
</para>

</section>
<section id="ap02-greenplum">
<title>Greenplum</title>
<para>
Greenplum is a data warehouse based on PostgreSQL. It is supported as a target platform in SymmetricDS. For the best performance,
the SymmetricDS Pro PostgreSQL bulk loader should be used.
Greenplum is a data warehouse based on PostgreSQL. It is supported as a target platform in SymmetricDS.
</para>

<para>SymmetricDS has bulk loading capability available for Greenplum. SymmetricDS specifies data loader types on
a channel by channel basis. To utilize Greenplum Bulk loading versus straight JDBC insert, specify the Postgres Bulk
Loader ("postgres_bulk") in the data_loader_type column of sym_channel.
</para>

</section>
<section id="ap02-sql-server">
<title>MS SQL Server</title>
Expand Down
7 changes: 6 additions & 1 deletion symmetric-assemble/src/docbook/extensions.xml
Expand Up @@ -165,7 +165,12 @@
be activated for a <xref linkend="table_channel" xrefstyle="table"/> by indicating the data loader name in the <code>data_loader_type</code> column.
</para>
<para>
One possible use of this extension point is to route data to a NOSQL data sink.
SymmetricDS has two out of the box extensions of IDataLoaderFactory already implemented in its PostgresBulkDataLoaderFactory
and OracleBulkDataLoaderFactory classes. These extension points implement bulk data loading capabilities for Oracle,
Postgres and Greenplum dialects. See Appendix C. Database Notes for details.
</para>
<para>
Another possible use of this extension point is to route data to a NOSQL data sink.
</para>
</section>
<section id="extensions-acknowledge-event-listener">
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 53771a2

Please sign in to comment.