public class OSESession extends java.lang.Object implements OSEExceptionConstants
Example:
String user = "JOHN"; String pwd = "john"; OSESession sess = null; try { sess = new OSESession(user, pwd.toCharArray()) sess.setURL("localhost:88"); sess.sync(); } finally { if (sess != null) sess.close(); }
Modifier and Type | Field and Description |
---|---|
static int |
DIR_RECEIVE
Sync direction RECEIVE
Data is only received, but not sent
|
static int |
DIR_SEND
Sync direction SEND
Data is only sent, but not received
|
static int |
DIR_SENDRECEIVE
Sync direction SENDRECEIVE
Bidirectional sync, this is the default
|
static int |
ENC_AES
Encryption type AES, this is the default
|
static int |
ENC_NONE
No encryption
|
static int |
ENC_SSL
Encryption type SSL
Uses HTTPS protocol, so the data will go through secure sockets
|
static int |
PRIO_DEFAULT
Normal data priority
|
static int |
PRIO_HIGH
High data priority
|
static int |
PRIO_LOWEST |
static int |
TR_HTTP
Transport type HTTP, this is the default
|
static int |
TR_USER
Transport type USER
Data is transfered by custom transport provided by application
|
CONFIG_LOAD_ERROR, CONFIG_SAVE_ERROR, CONNECTION_TO_SRV_FAILED, DATABASE_NOT_FOUND, EMPTY_PASSWORD, EMPTY_USER, ENCRYPTION_ID_MISMATCH, ERR_CREDENTIALS, ERROR_RESUME_RECEIVE, ERROR_RESUME_SEND, HTTP_RESPONSE, HTTP_TRANSPORT_ERROR, INTERNAL_ERROR, INVALID_BUFFER, INVALID_DML_TYPE, INVALID_ENCR_VER, INVALID_ENCRYPTION_TYPE, INVALID_HANDLE, INVALID_HTTP_URL, INVALID_INT_OPT, INVALID_OPCODE, INVALID_PLUGIN_FLAGS, INVALID_PRIORITY, INVALID_SESS, INVALID_STR_OPT, INVALID_STRING_LENGTH, INVALID_SYNC_DIRECTION, INVALID_TRANSPORT_TYPE, MISSING_DEFAULT_DATABASE, MISSING_PLUGIN_API, NOT_SUPPORTED, OPCODE_LENGTH_OVERRUN, OPCODE_LENGTH_UNDERRUN, OPCODE_OUT_OF_SEQUENCE, PASSWORD_NOT_SPECIFIED, PLUGIN_CLASS_INIT_FAILED, PLUGIN_CLASS_NOT_FOUND, PLUGIN_EXCEPTION, PLUGIN_ID_NOT_FOUND, PUBLICATION_ID_MISMATCH, PUBLICATION_ID_NOT_FOUND, PUBLICATION_NOT_FOUND, SERVER_ERROR, SNAP_NAME_NOT_FOUND, SNAPSHOT_ID_EXISTS, SNAPSHOT_ID_NOT_FOUND, SYNC_CANCELED, SYNC_UNAVAILABLE, TRANS_NOT_FOUND, UNCOMPRESSED_DATA, UNEXP_TERM_OPCODE, UNEXPECTED_BLOB_DATA, UNEXPECTED_OPCODE, UNINIT_USER_TRANSPORT, UNRECOGNIZED_DATA, USER_NOT_SPECIFIED, USER_TRANSPORT_ERROR
Constructor and Description |
---|
OSESession()
Empty constructor.
|
OSESession(java.lang.String user)
Sync session constructor for a user.
|
OSESession(java.lang.String user,
char[] pwd)
Sync session constructor for a user.
|
Modifier and Type | Method and Description |
---|---|
void |
addProgressListener(OSEProgressListener pl)
Add progress listener
|
void |
cancelSync()
Attempts to cancel the sync from another thread.
|
void |
close()
Closes the session and releases its resources
It's expected that before application exists, it calls this function.
|
java.lang.String |
getAppRoot()
Gets current root location
|
boolean |
getBackground()
Gets a flag which indicates whether sync should be background
The default is false, indicating foreground sync.
|
boolean |
getEncryptDatabases()
Gets the current value of encrypt databases flag
|
int |
getEncryptionType()
Gets current encryption type.
|
boolean |
getForceRefresh()
Gets current value set by
setForceRefresh(boolean) |
java.lang.String |
getProxy()
Returns current http proxy.
|
boolean |
getSavePassword()
Gets the boolean flag set by
setSavePassword(boolean)
The default is false. |
boolean |
getSyncApps()
Gets a flag that indicates whether sync should download a list of
application/client updates so they can later be installed.
|
int |
getSyncDirection()
Gets the current sync direction set by
setSyncDirection(int)
The default is DIR_SENDRECEIVE. |
boolean |
getSyncNewPub()
Gets current value set by
setSyncNewPub(boolean) |
int |
getSyncPriority()
Gets sync priority
The default is PRIO_DEFAULT.
|
int |
getTransportType()
Gets current sync transport type
|
java.lang.String |
getURL()
Returns current mobile server URL.
|
boolean |
getUseFiles()
Gets the current UseFiles value
setUseFiles(boolean) |
java.lang.String |
getUser()
Gets current sync user name
|
boolean |
getUseResume()
Gets the current UseResume value
setUseResume(boolean) |
static void |
logError(java.lang.Exception e) |
void |
removeProgressListener(OSEProgressListener pl)
Remove progress listener
|
void |
saveUser()
Saves user information in OSE meta files.
|
void |
selectPub(java.lang.String name)
Adds publication to the list of publications to be synchronized
selectively
|
void |
setAppRoot(java.lang.String appRoot)
Allows specification of the root directory for various internal sync
files as well as database files
|
void |
setBackground(boolean on)
Sets a flag which indicates whether sync should be background
|
static void |
setDBFactory(oracle.opensync.db.DBFactory f) |
void |
setEncryptDatabases(boolean on)
Enables database encryption for new databases created during sync.
|
void |
setEncryptionType(int type)
Sets sync encryption type to one of: ENC_AES, ENC_SSL or ENC_NONE
|
void |
setForceRefresh(boolean on)
To wipe out all of client's data and replace it with server's data,
set this to true.
|
void |
setNewPassword(char[] pwd)
Allows clients to modify their password.
|
void |
setPassword(char[] pwd)
Sets sync user password
|
void |
setProgress(OSEProgressListener p)
Set sync progress listener
|
void |
setProxy(java.lang.String proxy)
Sets current http proxy.
|
void |
setSavePassword(boolean on)
Sets the flag for persistently saving user password.
|
void |
setStartSyncAgent(boolean on)
Sets a flag which indicates whether to start the Sync Agent
upon sync completion
|
void |
setSyncApps(boolean on)
Sets a flag that indicates whether application/client updates
should be downloaded during sync
|
void |
setSyncDirection(int dir)
Sets the sync direction.
|
void |
setSyncNewPub(boolean on)
Sets flag for enabling synchronization of new publications.
|
void |
setSyncPriority(int prio)
Sets sync priority.
|
void |
setTransportType(int type)
Sets current transport type.
|
void |
setURL(java.lang.String url)
Sets HTTP URL of the mobile server
|
void |
setUseFiles(boolean on)
Enables switching between streaming and using files to transport
synchronization data.
|
void |
setUseResume(boolean on)
Enables using resume functionality, which will attempt to resume
sending or receiving data during sync in light of network failure.
|
void |
setUserTransport(OSETransport t)
Sets custom user-defined transport for sync
|
void |
shareConnection(java.lang.String dbName,
java.lang.Object connObj)
Provides database connection handle from the application to
use in OSE engine, instead of engine opening its own database
connection, which is default.
|
void |
sync()
Performs sync.
|
public static final int DIR_RECEIVE
public static final int DIR_SEND
public static final int DIR_SENDRECEIVE
public static final int ENC_AES
public static final int ENC_NONE
public static final int ENC_SSL
public static final int PRIO_DEFAULT
public static final int PRIO_HIGH
public static final int PRIO_LOWEST
public static final int TR_HTTP
public static final int TR_USER
public OSESession() throws OSEException
OSEException
- if last user was not saved or error
occurred loading user infopublic OSESession(java.lang.String user) throws OSEException
setPassword(char [])
user
- sync user nameOSEException
- if error occurred loading user infopublic OSESession(java.lang.String user, char[] pwd) throws OSEException
user
- sync user namepwd
- sync user passwordOSEException
- if error occured loading user infopublic void addProgressListener(OSEProgressListener pl)
pl
- progress listenerOSEProgressListener
public void cancelSync() throws OSEException
OSEException
- if IO error has occurredpublic void close() throws OSEException
OSEException
- if error occurred closing database connectionspublic java.lang.String getAppRoot()
setAppRoot(String)
public boolean getBackground()
public boolean getEncryptDatabases()
setEncryptDatabases(boolean)
public int getEncryptionType()
setEncryptionType(int)
The default is ENC_AES.public boolean getForceRefresh()
setForceRefresh(boolean)
public java.lang.String getProxy()
setProxy(String)
public boolean getSavePassword()
setSavePassword(boolean)
The default is false.setSavePassword(boolean)
setSavePassword(boolean)
public boolean getSyncApps()
public int getSyncDirection()
setSyncDirection(int)
The default is DIR_SENDRECEIVE.setSyncDirection(int)
public boolean getSyncNewPub()
setSyncNewPub(boolean)
public int getSyncPriority()
public int getTransportType()
setTransportType(int)
public java.lang.String getURL()
setURL(String)
public boolean getUseFiles()
setUseFiles(boolean)
public java.lang.String getUser()
public boolean getUseResume()
setUseResume(boolean)
public static void logError(java.lang.Exception e)
public void removeProgressListener(OSEProgressListener pl)
pl
- progress listenerOSEProgressListener
public void saveUser() throws OSEException
OSEException
- if failed to save user infopublic void selectPub(java.lang.String name) throws OSEException
name
- publication name, pass null to unselect all publications
and revert to normal (non-selective) syncOSEException
- if publication with provided name was not foundpublic void setAppRoot(java.lang.String appRoot)
appRoot
- directory stringpublic void setBackground(boolean on)
on
- true if background, false if foregroundgetBackground()
public static void setDBFactory(oracle.opensync.db.DBFactory f)
public void setEncryptDatabases(boolean on)
on
- boolean true to enable encryption, false to disablepublic void setEncryptionType(int type) throws OSEException
type
- encryption typeOSEException
- if invalid encryption type was providedgetEncryptionType()
public void setForceRefresh(boolean on)
on
- if true, upon sync completion, the client's data will be
wiped out and replaced with server's datapublic void setNewPassword(char[] pwd) throws OSEException
pwd
- new passwordOSEException
- if provided new password is blankpublic void setPassword(char[] pwd) throws OSEException
pwd
- sync passwordOSEException
- if provided password is blankpublic void setProgress(OSEProgressListener p)
p
- OSEProgressListenerOSEProgressListener
public void setProxy(java.lang.String proxy)
proxy
- http proxy or null if proxy is not usedpublic void setSavePassword(boolean on)
on
- boolean set to true, if the password needs to be saved.getSavePassword()
public void setStartSyncAgent(boolean on)
on
- true if Sync Agent should be started, false if notpublic void setSyncApps(boolean on)
on
- true or falsegetSyncApps()
public void setSyncDirection(int dir) throws OSEException
dir
- sync directionOSEException
- if invalid sync direction providedgetSyncDirection()
public void setSyncNewPub(boolean on)
on
- boolean if true, any subscribed new publications
on the server will be downloaded to the client.
The default is true.public void setSyncPriority(int prio) throws OSEException
prio
- PRIO_DEFAULT or PRIO_HIGHOSEException
- if invalid priority providedgetSyncPriority()
public void setTransportType(int type) throws OSEException
type
- int
TR_HTTP | default transport |
TR_USER | custom transport |
OSEException
- if invalid transport type providedgetTransportType()
public void setURL(java.lang.String url)
url
- mobile server URL
for example: http://localhost:99 or https://localhost or localhost:99
or localhost (the protocol will default to http).public void setUseFiles(boolean on)
Note: streaming requires that the underlying client transport stack implements HTTP 1.1
on
- boolean if true, sync will use files to store uploaded and
downloaded data, otherwise, data will be streamed.public void setUseResume(boolean on)
setUseFiles(boolean)
),
UseResume provides much more reliable transport for synchronizing
data at the expense of very light performance overhead.
The default is false.on
- boolean if true, resume functionality is enabled.public void setUserTransport(OSETransport t)
t
- user-defined transport instance, must implement
OSETransport
interfaceOSETransport
public void shareConnection(java.lang.String dbName, java.lang.Object connObj)
dbName
- database nameconnObj
- connection object , has to be a valid connection object for
particular type of database as used in OSE plugin.
For native sync client, it must be an instance of java.lang.Integer or
java.lang.Long encapsulating corresponding native connection handle
(for example, for sqlite and BDB plugins it would be of type
"sqlite3 *")
For pure java sync client, it must be an instance of corresponding
platform-specific database connection class:
net.rim.device.api.database.Database for Blackberry client
android.database.sqlite.SQLiteDatabase for Android client
java.sql.Connection for SE clientOSEException
- if plugin error has occuredpublic void sync() throws OSEException
OSEException
- if sync has failed