org.ov4j.db4oImpl
Class Container<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>

java.lang.Object
  extended by org.ov4j.db4oImpl.Container<T,C>
All Implemented Interfaces:
IContainer<T,C>

public class Container<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
extends java.lang.Object
implements IContainer<T,C>

IContainer implementation using DB4O database for adta and DB4O extended memory database for mapping IDs.

Author:
smolloy

Field Summary
protected  com.db4o.ext.ExtObjectContainer db
          Database storing data.
protected  com.db4o.ext.ExtObjectContainer mapDB
          Database storing map of IDs.
protected  com.db4o.ext.ExtObjectContainer unmapDB
          Database storing map of deleted IDs.
 
Constructor Summary
Container(java.lang.String dbName, long delay, long saveInterval, long defragDelay, long defragInterval)
          Constructor.
 
Method Summary
protected  void backup()
          Backup the data and ID map databases.
 void batchDelete(Item<T,C>[] items, boolean keepTrack)
          Delete an array of items all at once, items which are not found will simply be ignored.
 void batchMerge(C[] ids)
          Merge an array of items all at once, items which are not found will simply be ignored.
 void batchSave(Item<T,C>[] items, boolean abortOnDuplicate)
          Save array of items all at once.
 void clear()
          Clear the database, will not clear the backups.
 void clearDeletedIDs()
           
 void close()
          Close the container.
 void close(boolean removeHook)
          Close the container, possibly removing shutdown hook.
 void commit()
          Commit all changes.
protected  void configure()
          Configure database, subclasses should overload this method, but still call super.configure() so that everything is configured correctly.
 void defragment()
          Taken from Db4o's Defragment tool, see Db4o licenses for usage.
 void delete(Item<T,C> it, boolean keepTrack)
          Delete the item.
 C[] deletedIds()
          Retrieve list of IDs that have been deleted.
 C[] deletedIdsSince(long timestamp)
          Retrieve a list of IDs that have been deleted since the given timestamp.
 void duplicate(IContainer<T,C> cont)
          Converts the given IContainer into an hessian implementation.
static int getBlockSize()
           
 boolean inUse(C id)
          Determine if the given id is in use.
 boolean isClosed()
          Determine if the container has already been closed.
 C[] listModifiedSince(long timestamp)
          List all items modified since the given timestamp.
 Item<T,C>[] load(C[] ids, boolean allVersions)
          Load multiple items at once, using the specified ids.
 Item<T,C> load(C id, boolean allVersions)
          Load an item using its id.
 Item<T,C>[] modifiedSince(long timestamp, boolean allVersions)
          Load all items modified since the given timestamp.
 void release(java.lang.Object obj)
          Release the object so it can be garbage collected immediately.
 void rollback()
          Rollback and discard all changes since last commit.
 void save(Item<T,C> it)
          Save the item.
static void setBlockSize(int blockSize)
           
 java.lang.String toString()
          Returns a string representation of this Container.
 void waitForPendingSaves()
          Wait for all saves and deletes pending tasks to finish.
 void waitForPendingTasks()
          Wait for all tasks pending tasks to finish.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

db

protected com.db4o.ext.ExtObjectContainer db
Database storing data.


mapDB

protected com.db4o.ext.ExtObjectContainer mapDB
Database storing map of IDs.


unmapDB

protected com.db4o.ext.ExtObjectContainer unmapDB
Database storing map of deleted IDs.

Constructor Detail

Container

public Container(java.lang.String dbName,
                 long delay,
                 long saveInterval,
                 long defragDelay,
                 long defragInterval)
Constructor.

Parameters:
dbName - Name of the database.
delay - Delay before the first save.
saveInterval - Interval (in ms) between periodic replication to backup database.
Method Detail

getBlockSize

public static int getBlockSize()
Returns:
the blockSize

setBlockSize

public static void setBlockSize(int blockSize)
Parameters:
blockSize - the blockSize to set

backup

protected void backup()
Backup the data and ID map databases.


batchDelete

public void batchDelete(Item<T,C>[] items,
                        boolean keepTrack)
Description copied from interface: IContainer
Delete an array of items all at once, items which are not found will simply be ignored.

Specified by:
batchDelete in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
items - Items to be deleted.
keepTrack - Whether or not the ID should be kept in history.
See Also:
org.ov4j.IContainer#batchDelete(org.ov4j.data.Item[])

batchMerge

public void batchMerge(C[] ids)
                throws java.io.IOException
Description copied from interface: IContainer
Merge an array of items all at once, items which are not found will simply be ignored.

Specified by:
batchMerge in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
ids - IDs to be merged.
Throws:
java.io.IOException
See Also:
IContainer.batchMerge(java.lang.Comparable[])

batchSave

public void batchSave(Item<T,C>[] items,
                      boolean abortOnDuplicate)
               throws java.io.IOException
Description copied from interface: IContainer
Save array of items all at once. If abortOnDuplicate is set to true, data will not be saved if 1 or more item ids are in use.

Specified by:
batchSave in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
items - Array of items to be saved.
abortOnDuplicate - Whether or not saving should abort when an item has an ID already in use.
Throws:
java.io.IOException
See Also:
org.ov4j.IContainer#batchSave(org.ov4j.data.Item[], boolean)

clear

public void clear()
Clear the database, will not clear the backups. WARNING: THIS OPERATION CAN BE VERY HARMFUL AS ALL DATA IN THE DB WILL BE LOST!!!

Specified by:
clear in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
See Also:
IContainer.clear()

clearDeletedIDs

public void clearDeletedIDs()
See Also:
org.ov4j.IContainer#clearDeletedIDs()

close

public void close()
Description copied from interface: IContainer
Close the container.

Specified by:
close in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
See Also:
IContainer.close()

close

public void close(boolean removeHook)
Close the container, possibly removing shutdown hook.

Parameters:
removeHook - Whether or not the shutdown hook should be removed first.

commit

public void commit()
Description copied from interface: IContainer
Commit all changes.

Specified by:
commit in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
See Also:
IContainer.commit()

configure

protected void configure()
Configure database, subclasses should overload this method, but still call super.configure() so that everything is configured correctly. This method will be called before any databases are opened or created.


defragment

public void defragment()
Taken from Db4o's Defragment tool, see Db4o licenses for usage. Defragment the container.

Throws:
java.lang.ClassNotFoundException

delete

public void delete(Item<T,C> it,
                   boolean keepTrack)
Description copied from interface: IContainer
Delete the item.

Specified by:
delete in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
it - Item to be deleted.
keepTrack - Whether or not the ID should be kept in history.
See Also:
org.ov4j.IContainer#delete(org.ov4j.data.Item)

deletedIds

public C[] deletedIds()
Description copied from interface: IContainer
Retrieve list of IDs that have been deleted.

Specified by:
deletedIds in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Returns:
All IDs deleted.
See Also:
IContainer.deletedIds()

deletedIdsSince

public C[] deletedIdsSince(long timestamp)
Description copied from interface: IContainer
Retrieve a list of IDs that have been deleted since the given timestamp.

Specified by:
deletedIdsSince in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
timestamp - Timestamp to use.
Returns:
All IDS deleted since the given timestamp.
See Also:
IContainer.deletedIdsSince(long)

duplicate

public void duplicate(IContainer<T,C> cont)
               throws java.io.IOException
Converts the given IContainer into an hessian implementation.

Specified by:
duplicate in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
cont - IContainer to convert.
Throws:
java.io.IOException

inUse

public boolean inUse(C id)
Description copied from interface: IContainer
Determine if the given id is in use.

Specified by:
inUse in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
id - ID to check.
Returns:
True if the ID is already used in the system.
See Also:
IContainer.inUse(java.lang.Comparable)

isClosed

public boolean isClosed()
Description copied from interface: IContainer
Determine if the container has already been closed.

Specified by:
isClosed in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Returns:
True if the container has been closed.
See Also:
IContainer.isClosed()

listModifiedSince

public C[] listModifiedSince(long timestamp)
                                                              throws java.io.IOException
Description copied from interface: IContainer
List all items modified since the given timestamp.

Specified by:
listModifiedSince in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
timestamp - Timestamp to use.
Returns:
An array of IDs for items modified since specified timestamp.
Throws:
java.io.IOException
See Also:
IContainer.listModifiedSince(long)

load

public Item<T,C> load(C id,
                      boolean allVersions)
                                                                                                                                          throws java.io.IOException
Description copied from interface: IContainer
Load an item using its id.

Specified by:
load in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
id - ID to look for.
allVersions - Whether or not all versions should be loaded.
Returns:
The item with specified ID.
Throws:
java.io.IOException
See Also:
IContainer.load(java.lang.Comparable, boolean)

load

public Item<T,C>[] load(C[] ids,
                        boolean allVersions)
                                                                                                                                            throws java.io.IOException
Description copied from interface: IContainer
Load multiple items at once, using the specified ids.

Specified by:
load in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
ids - Array of IDs to look for.
allVersions - Whether or not all versions should be loaded.
Returns:
An array of items with specified IDs, not necessarily in the same order.
Throws:
java.io.IOException
See Also:
IContainer.load(java.lang.Comparable, boolean)

modifiedSince

public Item<T,C>[] modifiedSince(long timestamp,
                                 boolean allVersions)
                                                                                                                                                     throws java.io.IOException
Description copied from interface: IContainer
Load all items modified since the given timestamp.

Specified by:
modifiedSince in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
timestamp - Timestamp to use.
allVersions - Whether or not all versions should be loaded.
Returns:
An array of items modified since specified timestamp.
Throws:
java.io.IOException
See Also:
IContainer.modifiedSince(long, boolean)

release

public void release(java.lang.Object obj)
Description copied from interface: IContainer
Release the object so it can be garbage collected immediately.

Specified by:
release in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
obj - Object to release.
See Also:
IContainer.release(java.lang.Object)

rollback

public void rollback()
Description copied from interface: IContainer
Rollback and discard all changes since last commit.

Specified by:
rollback in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
See Also:
IContainer.rollback()

save

public void save(Item<T,C> it)
          throws java.io.IOException
Description copied from interface: IContainer
Save the item.

Specified by:
save in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Parameters:
it - Item to be saved.
Throws:
java.io.IOException
See Also:
IContainer.save(org.ov4j.data.Item)

toString

public java.lang.String toString()
Returns a string representation of this Container.

Overrides:
toString in class java.lang.Object
Returns:
String representation of the Container.

waitForPendingSaves

public void waitForPendingSaves()
Description copied from interface: IContainer
Wait for all saves and deletes pending tasks to finish.

Specified by:
waitForPendingSaves in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>

waitForPendingTasks

public void waitForPendingTasks()
Description copied from interface: IContainer
Wait for all tasks pending tasks to finish.

Specified by:
waitForPendingTasks in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>


Copyright © 2004-2007 Steve Molloy. All Rights Reserved.