Using DMS ( via Java Code )
Please refer this blog http://oracledms.blogspot.in/ for few basic stuff like (publication, publication items etc)
BLOG also has complete information on
1. Installing Server ( Glassfish)
2.Using MOBILE DATABASE WORKBENCH (MDW ) for creating publications and publication items .
3. Adding publication items to publication.
4. Deploying in the server.
5. Packaging the application using (MDW) in packing wizard by Application Name and also path .
6. Once everything is completed publishing the application .
7. In the server you will find the published application .
8. Create users and giving access for application ( including data sub-setting if needed )
9. Using the sync app ( provided by the Oracle) in the Android Phone with server url along with the credentials of the created user .
10. After sync successful database is downloaded in the mobile .
I will be focusing on the creating the entire applications by java code ,
Few basic stuff :
I assume there is Oracle Home folder in some drive , The same folder has the Android Sync sample as well .Use the same folder for finding required for jar .
Make sure you add few environmental variables to compile . ( if you are using cmd to execute java programs)
CLASSPATH
%CLASS_HOME%;%ORACLE_HOME%\Mobile\Sdk\BIN\aes.jar;%ORACLE_HOME%\Mobile\Sdk\BIN\devmgr.jar;%ORACLE_HOME%\Mobile\Sdk\BIN\olite40.jar;%ORACLE_HOME%\Mobile\Sdk\BIN\webtogo.jar;%ORACLE_HOME%\Mobile\CLASSES\phaos.jar;%ORACLE_HOME%\Mobile\CLASSES\consolidator.jar;%ORACLE_HOME%\jdbc\lib\ojdbc14.jar
JAVA_HOME
C:\Program Files\Java\jdk1.7.0_13
MOBILE_HOME
D:\OraHome_1
PATH
%JAVA_HOME%;%Path%
I have used Android SDK to execute the java code , any tool can be used eclipse/net beans etc .
All you need is few jar files which has implementations ,
Please look for jar files mentioned below and import to your project .
D:\OraHome_1\Mobile\Sdk\bin\webtogo.jar
D:\OraHome_1\Mobile\classes\consolidator
D:\OraHome_1\jdbc\lib\.....(few files)
Few of the essential import statements which are needed ,
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.lite.sync.Consolidator;
import oracle.lite.sync.ConsolidatorException;
import oracle.lite.sync.ConsolidatorManager;
import oracle.mobile.admin.MobileResourceManager;
import oracle.mobile.admin.ResourceManager;
Work Flow for Creating Application through Java Code :
1. Create Publication
2. Create Publication Items
3. Add Publication Items to Publication
4. Create Application for the Publication Created .
5. Publish Application
6. Create Users
7. Give a user Access to Application .
8. Associate a Sub-setting for user depending on the application logic .
1. Create Publication
a. Create the ConsolidatorManager object.
b. Connect to the database using the openConnection method. Provide the schema
name, password, and JDBC URL for the database the contains the schema.
c. Create the publication with the createPublication method, which creates an
empty publication. An example of the createPublication method syntax is as
follows:
createPublication(
java.lang.String name,
java.lang.String db_inst,
int client_storage_type,
java.lang.String client_name_template,
java.lang.String enforce_ri,
int dev_types_flg)
The createPublication method can have some of the following input
parameters:
■ name—A character string specifying the new publication name.
■ db_inst—NULL, unless you are using a registered database for application
data. If using a registered database, provide the application database name in
this field.
■ client_storage_type—An integer specifying the client storage type for all
publication items in the new publication. If you are defining a publication
exclusively for a Berkeley DB or SQLite Mobile Client, specify the
Consolidator.BDB_CREATOR_ID or Consolidator.SQLITE_CREATOR_
ID appropriately as the storage type.
Other values are Consolidator.DFLT_CREATOR_ID and
Consolidator.OKPI_CREATOR_ID.
■ client_name_template—A template for publication item instance names on
client devices. This parameter contains the following predefined values:
– %s—Default.
– DATABASE.%s—Causes all publication items to be instantiated inside an
OKAPI database with the name DATABASE.
– SFT-EE_%s—Must be used for Satellite Forms-based applications.
■ enforce_ri—Reserved for future use. Use NULL or an empty string.
■ dev_types_flg—Specifies which device types or platforms the publication
supports. The default flag is set to Consolidator.DEV_FLG_GEN, which
includes all device platforms. If a publication is for more than one platform,
use the sum of the platform flags.
Example Code :
Few Static variables for code :
static String CONS_SCHEMA = "MOBILE";
static String DEFAULT_PASSWORD = "qwerty111";
static String JDBC_URL = "jdbc:oracle:thin:@100.101.0.14:1581:orcl";
static String DEMO_USER = "MOBILEADMIN";
static String DEMO_PASSWORD = "qwerty111";
try {
Connection con = null;
ConsolidatorManager cm = new ConsolidatorManager();
Class.forName("oracle.jdbc.driver.OracleDriver");
try {
con = DriverManager.getConnection(JDBC_URL, DEMO_USER,
DEMO_PASSWORD);
} catch (SQLException sqle) {
sqle.printStackTrace();
}
cm.openConnection(con);
// Creating Publications :
try {
cm.createPublication("T_PUBLICATION",
Consolidator.SQLITE_CREATOR_ID, "spurthi.%s", null);
} catch (Throwable e) {
e.printStackTrace(); //
}
2. Create Publication Items :
Consolidator.PubItemProps taskPIProps = new Consolidator.PubItemProps();
taskPIProps.db_inst = "APP1"; // Remote App database name as registered
taskPIProps.owner = "APPUSER1";
taskPIProps.store = "TASKS";
taskPIProps.refresh_mode = "F";
taskPIProps.select_stmt = "select id, emp_id, cust_id, stat_id, notes
from APPUSER1.TASKS";
taskPIProps.cbk_owner = "MOBILEADMIN";
taskPIProps.cbk_name = "TASKSPI_PKG";
consMgr.createPublicationItem( "PI_1_TASKS", taskPIPProps);
Working Example code :
Consolidator.PubItemProps cp = new Consolidator.PubItemProps();
try {
cp.owner = CONS_SCHEMA;
cp.store = "TBL_MEMBER"; // Table name
cp.refresh_mode = "F";
cp.select_stmt = "SELECT MEMBER_ID, FIRST_NAME, LAST_NAME, MOBILE, EMAIL FROM MOBILE.TBL_MEMBER";
cp.cbk_owner = "MOBILEADMIN";
cp.isLogBased = false;
cm.createPublicationItem("T_PUBLICATIONL_ITEM", cp);
3. Add Publication Items to Publication
cm.addPublicationItem("T_PUBLICATION",
"T_PUBLICATIONL_ITEM", null, null, "S", null, null);
4. Create Application for the Publication Created .
MobileResourceManager mMobileManager = new MobileResourceManager(CONS_SCHEMA,
DEFAULT_PASSWORD, JDBC_URL);
mMobileManager.createApplication("T_APPLICATION","/testpath","T_PUBLICATION",5);
//application name,path,Publication
5. Publish Application
Once the application is successful , we need to publish the application . There are api's to publish application , best way we identified was to import a jar file for eclipse or whatever the tool used with web.xml present ( if not first extract the xml file and name it as web.xml and then import jar ) and use the packaging wizard of MDK and import a signed jar file .
In the server just publish the app by importing the signed jar from MDK , you are done now :)
you can see the Application is published .
6. Create Users
ResourceManager.openConnection(con); // Use the same object of Connection con
boolean test=ResourceManager.createUser("SPURTHI", "test",
"Spurthik", "U"); // username , password,name,access as type (can be "U","A" etc )
7. Give a user Access to Application .
ResourceManager.setUserAccess("/testpath","SPURTHI", true);
// tricky part I spent 2 days to identify
// First paramater is the path of application , second is username
8. Associate a Sub-setting for user depending on the application logic
During the creating of publication Item for the sql statement if you want to dynamically subset the data ,
Creating a Data Subset Example
consolidatorManager.createPublicationItem("CORP_DIR1",
"DIRECTORY1", "ADDRLRL4P", "F" ,
"SELECT LastName, FirstName, company, phone1, phone2, phone3, phone4,
zipcode, country, title, custom1, custom2, custom3, note
FROM directory1.addrlrl4p WHERE company = :COMPANY", NULL, NULL);
Here COMPANY is the Sub setting parameter ,
Example :
// get the initiated instance of ConsolidatorManager
cm.setSubscriptionParameter("T_PUBLICATION", "SPURTHI","COMPANY","'fediclix'");
and thats it :)
All done , Good luck :)