Connection provides the interface for all threads interacting with a Database object.
public class Connection implements java.io.Closeable
{
/* Constructors */
public Connection(Database db)
{
this.db = db;
id = connect(db.name, null);
}
public Connection(Database db, byte[] context)
{
this.db = db;
id = connect(db.name, context);
}
protected Connection(Connection con) {
db = con.db;
id = con.id;
}
/* Close - disconnect methods */
public void disconnect()
{
if (id != 0)
{
disconnect(id);
id = 0;
}
}
public void close()
{
disconnect();
}
/* Transaction methods */
public void startTransaction(Database.TransactionType type)
{
startTransaction(type, Database.TransactionPriority.Foreground,
Database.IsolationLevel.Default);
}
public void startTransaction(Database.TransactionType type,
Database.TransactionPriority pri,
Database.IsolationLevel level)
{
startTransaction(id, type.ordinal(), pri.ordinal(), level.ordinal());
}
public boolean commitTransaction()
{
return commitTransaction(id);
}
public boolean commitTransaction(int phase)
{
if (phase != 1 && phase != 2)
{
throw new IllegalArgumentException("Invalid phase: " + phase);
}
return commitTransactionPhase(id, phase);
}
public void setCommitPolicy(Database.CommitPolicy policy)
{
setCommitPolicy(id, policy.ordinal());
}
public void diskFlush()
{
diskFlush(id);
}
public void rollbackTransaction()
{
rollbackTransaction(id);
}
public boolean checkpointTransaction()
{
return checkpointTransaction(id);
}
/* Database operation methods */
public long insert(Object obj)
{
...
}
public long count(Class cls)
{
return count(id, db.getClassDescriptor(cls).classNo);
}
public void removeAll(Class cls)
{
removeAll(id, db.getClassDescriptor(cls).classNo);
}
public boolean saveSnapshot(String databaseSnapshotFilePath)
{
return save(id, databaseSnapshotFilePath);
}
public boolean saveMetadata(String databaseMetadataFilePath, boolean saveDefaults)
{
return saveMetadata(id, databaseMetadataFilePath, saveDefaults);
}
public boolean saveDictionary(String databaseDictionaryFilePath)
{
return saveDictionary(id, databaseDictionaryFilePath);
}
public boolean saveClass(String filePath, Class cls)
{
return saveClass(id, filePath, db.getClassDescriptor(cls).classNo);
}
public boolean loadClass(String filePath, Class cls, boolean doMerge)
{
return loadClass(id, filePath, (cls != null) ? db.getClassDescriptor(cls).classNo : 0, doMerge);
}
public boolean loadClass(String filePath)
{
return loadClass(id, filePath, 0, false);
}
/* Event methods */
public void waitEvent(String name)
{
waitEvent(id, db.findEvent(name));
}
public void releaseEvent(String name)
{
releaseEvent(id, db.findEvent(name));
}
public void releaseAllEvents()
{
releaseAllEvents(id);
}
/* Statistics methods */
public int getFreePages()
{
return getFreePages(id);
}
public int getTotalPages()
{
return getTotalPages(id);
}
public short getDbPageSize()
{
return getDbPageSize(id);
}
public Statistic.ClassStat getClassStat(int classCode)
{
return getClassStat(id, classCode);
}
public short getIndexStatCount()
{
return getIndexStatCount(id);
}
public Statistic.IndexStat getIndexStat(short index)
{
...
}
public Statistic.DiskInfo getDiskInfo()
{
return getDiskInfo(id);
}
/* Incremental Backup methods */
public void createBackup(String fileName, String label, Database.BackupType type)
{
createBackup(id, fileName, label, type.ordinal(), 0, null);
}
public void createBackup(String fileName, String label, Database.BackupType type,
int compressionLevel, String cipher)
{
createBackup(id, fileName, label, type.ordinal(), compressionLevel, cipher);
}
public void restoreBackup(String fileName, String label)
{
restoreBackup(id, fileName, label, null);
}
public void restoreBackup(String fileName, String label, String cipher)
{
restoreBackup(id, fileName, label, cipher);
}
public Database.BackupInfo [] listBackup(String fileName)
{
return listBackup(id, fileName);
}
}
public Connection(Database db)
Constructor.
db
Returns: a Connection instance.
Constructor.
db
context
Returns: a Connection instance.
Constructor.
con
Returns: a Connection instance.
public void disconnect()
public void close()
disconnect()).Start a database transaction.
type
(Note that nested transactions are supported.)
Start a database transaction.
type
pri
level
(Note that nested transactions are supported.)
Commit phase 1 or 2 of a two-phase database transaction.
phase
1 or 2.Returns: false in case of an MVCC error; otherwise true.
public void diskFlush()
MCO_COMMIT_BUFFERED transaction policy is used.)Checkpoint the current transaction: insert all objects updated by the current transaction in indexes.
Returns: false in case of an MVCC error; otherwise true.
public long insert(Object obj)
Insert a new object into the database.
obj
Returns: the AUTOID of the created object if the autoid attribute is set in the
Persistent annotation for this class, or 0 if the class has no associated
AUTOID index.
public long count(Class cls)
Return the number of instances of this class stored in the database.
cls
Remove all instances of the specified class. (Note that class inheritance is not considered.)
cls
Save a database snapshot to the specified file. (This snapshot can later be loaded by the
Database method open() if the corresponding file path is specified in
Database.Parameters.databaseSnapshotFilePath.)
databaseSnapshotFilePath
Returns: true if the snapshot file was successfully saved; false if the
specified file cannot be opened.
Save database metadata to the specified file. (This metadata can later be loaded as an xSQL configuration file.)
databaseMetadataFilePath
saveDefaults
true, save default values.Returns: true if the metadata file was successfully saved; false if the
specified file cannot be opened.
Save a database dictionary to the specified file.
databaseDictionaryFilePath
Returns: true if the dictionary file was successfully saved; false if the
specified file cannot be opened.
Save table content to the specified file. This snapshot can later be loaded by the Databaseopen() or Connection loadClass().
filePath
cls
Returns: true if the file was successfully saved; false if the specified
file cannot be opened.
Load the table contents from the file previously created by ConnectionsaveClass() or saveSnapshot().
filePath
cls
doMerge
false, the content of the table is cleared before loading from the image file;
if true, the loaded objects are "added" to the table.Returns: true if the file was successfully loaded; false if the specified
file cannot be opened.
Load the table contents from the file previously created by ConnectionsaveClass() or saveSnapshot() using the class id of 0 and
doMerge of false.
filePath
Returns: true if the file was successfully loaded; false if the specified
file cannot be opened.
Wait for signaling of the specified asynchronous event.
name
Release the specified asynchronous event.
name
public void releaseAllEvents()
public int getFreePages()
public int getTotalPages()
public short getDbPageSize()
Collects database statistics at runtime.
classCode
Returns: statistics data for the class.
getIndexStat() to obtain index statistics
at runtime.)Obtains index statistics at runtime.
index
getIndexStatCount().)Returns: index statistics data.
Create a backup record of the database.
fileName
label
type
mco_backup_create()
for details).Create a backup record of the database using compression and/or encryption.
fileName
label
type
mco_backup_create()
for details).compressionLevel
cipher
Restore backup records starting from the latest snapshot record in the specified file up to the specified label.
fileName
label
Restore backup records starting from the latest snapshot record in the specified file up to the specified label using compression and/or encryption.
fileName
label
cipher
List the contents of a backup file.
fileName
Export the database to an XML file.
filePath
Returns: true if the database was successfully exported; false if the
specified file cannot be opened.
Import data from an XML file into the database.
filePath
transactionSize
Returns: true if the data was successfully imported; false if the specified
file cannot be opened.
Import data from an XML file into the database.
filePath
Returns: true if the data was successfully imported; false if the specified
file cannot be opened.