Author: akarasulu
Date: Wed Feb 24 23:27:29 2010
New Revision: 916036
URL: http://svn.apache.org/viewvc?rev=916036&view=rev
Log:
more formatting
Modified:
directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/CachePolicy.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/CachePolicyListener.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/DefaultSerializer.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java
directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/CacheRecordManager.java
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/CachePolicy.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/CachePolicy.java?rev=916036&r1=916035&r2=916036&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/CachePolicy.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/CachePolicy.java Wed Feb 24 23:27:29
2010
@@ -44,11 +44,12 @@
*
* $Id: CachePolicy.java,v 1.5 2003/11/01 13:25:02 dranatunga Exp $
*/
-
package jdbm.helper;
+
import java.util.Enumeration;
+
/**
* CachePolicity is an abstraction for different cache policies.
* (ie. MRU, time-based, soft-refs, ...)
@@ -57,9 +58,8 @@
* @author <a href="mailto:dranatunga@users.sourceforge.net">Dilum Ranatunga</a>
* @version $Id: CachePolicy.java,v 1.5 2003/11/01 13:25:02 dranatunga Exp $
*/
-public interface CachePolicy
+public interface CachePolicy<K,V>
{
-
/**
* Place an object in the cache. If the cache does not currently contain
* an object for the key specified, this mapping is added. If an object
@@ -82,8 +82,7 @@
* to make room for new object, an eviction listener encountered
* this problem.
*/
- public void put( Object key, Object value )
- throws CacheEvictionException;
+ public void put( K key, V value ) throws CacheEvictionException;
/**
@@ -92,7 +91,7 @@
* @param key key the object was cached under
* @return the object if it is still in the cache, null otherwise.
*/
- public Object get( Object key );
+ public V get( K key );
/**
@@ -103,7 +102,7 @@
*
* @param key key the object was stored in the cache under.
*/
- public void remove( Object key );
+ public void remove( K key );
/**
@@ -116,7 +115,7 @@
/**
* Enumerate through the objects currently in the cache.
*/
- public Enumeration elements();
+ public Enumeration<V> elements();
/**
@@ -128,8 +127,7 @@
* @param listener the (non-null) listener to add to this policy
* @throws IllegalArgumentException if listener is null.
*/
- public void addListener( CachePolicyListener listener )
- throws IllegalArgumentException;
+ public void addListener( CachePolicyListener<V> listener ) throws IllegalArgumentException;
/**
@@ -138,6 +136,5 @@
*
* @param listener the listener to remove from this policy
*/
- public void removeListener( CachePolicyListener listener );
-
+ public void removeListener( CachePolicyListener<V> listener );
}
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/CachePolicyListener.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/CachePolicyListener.java?rev=916036&r1=916035&r2=916036&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/CachePolicyListener.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/CachePolicyListener.java Wed Feb
24 23:27:29 2010
@@ -60,18 +60,17 @@
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: CachePolicyListener.java,v 1.3 2003/11/01 13:25:41 dranatunga Exp $
*/
-public interface CachePolicyListener {
-
+public interface CachePolicyListener<T>
+{
/**
* Notification that the cache this listener is attached to is evicting
* the object indicated.
*
- * @param obj object being evited from cache
+ * @param obj object being evicted from cache
* @throws CacheEvictionException if this listener encountered problems
* while preparing for the specified object's eviction. For example,
* a listener may try to persist the object to disk, and encounter
* an <code>IOException</code>.
*/
- public void cacheObjectEvicted(Object obj) throws CacheEvictionException;
-
+ public void cacheObjectEvicted( T obj ) throws CacheEvictionException;
}
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/DefaultSerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/DefaultSerializer.java?rev=916036&r1=916035&r2=916036&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/DefaultSerializer.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/DefaultSerializer.java Wed Feb
24 23:27:29 2010
@@ -43,22 +43,22 @@
* Contributions are Copyright (C) 2001 by their associated contributors.
*
*/
-
package jdbm.helper;
+
import java.io.IOException;
+
/**
* Default java serializer.
*
* @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
* @version $Id: DefaultSerializer.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
*/
-public class DefaultSerializer
- implements Serializer
+public class DefaultSerializer implements Serializer
{
+ private static final long serialVersionUID = -3818545055661017388L;
-
public static final DefaultSerializer INSTANCE = new DefaultSerializer();
@@ -77,27 +77,27 @@
* @param obj Object to serialize
* @return a byte array representing the object's state
*/
- public byte[] serialize( Object obj )
- throws IOException
+ public byte[] serialize( Object obj ) throws IOException
{
return Serialization.serialize( obj );
}
/**
- * Deserialize the content of an object from a byte array.
+ * De-serialize the content of an object from a byte array.
*
* @param serialized Byte array representation of the object
- * @return deserialized object
+ * @return de-serialized object
*/
- public Object deserialize( byte[] serialized )
- throws IOException
+ public Object deserialize( byte[] serialized ) throws IOException
{
- try {
+ try
+ {
return Serialization.deserialize( serialized );
- } catch ( ClassNotFoundException except ) {
+ }
+ catch ( ClassNotFoundException except )
+ {
throw new WrappedRuntimeException( except );
}
}
-
}
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java?rev=916036&r1=916035&r2=916036&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java Wed Feb
24 23:27:29 2010
@@ -86,82 +86,62 @@
implements RecordManager
{
- /**
- * Underlying record file.
- */
- private RecordFile _file;
+ /** Underlying record file. */
+ private RecordFile recordFile;
+ /** Physical row identifier manager. */
+ private PhysicalRowIdManager physMgr;
- /**
- * Physical row identifier manager.
- */
- private PhysicalRowIdManager _physMgr;
+ /** Logical to Physical row identifier manager. */
+ private LogicalRowIdManager logMgr;
+ /** Page manager. */
+ private PageManager pageMgr;
- /**
- * Logigal to Physical row identifier manager.
- */
- private LogicalRowIdManager _logMgr;
-
-
- /**
- * Page manager.
- */
- private PageManager _pageman;
-
-
- /**
- * Reserved slot for name directory.
- */
+ /** Reserved slot for name directory. */
public static final int NAME_DIRECTORY_ROOT = 0;
-
- /**
- * Static debugging flag
- */
+ /** Static debugging flag */
public static final boolean DEBUG = false;
-
/**
* Directory of named JDBMHashtables. This directory is a persistent
- * directory, stored as a Hashtable. It can be retrived by using
+ * directory, stored as a Hashtable. It can be retrieved by using
* the NAME_DIRECTORY_ROOT.
*/
- private Map _nameDirectory;
+ private Map<String,Long> nameDirectory;
/**
- * Creates a record manager for the indicated file
+ * Creates a record manager for the indicated file
*
- * @throws IOException when the file cannot be opened or is not
- * a valid file content-wise.
+ * @throws IOException when the file cannot be opened or is not
+ * a valid file content-wise.
*/
- public BaseRecordManager( String filename )
- throws IOException
+ public BaseRecordManager( String filename ) throws IOException
{
- _file = new RecordFile( filename );
- _pageman = new PageManager( _file );
- _physMgr = new PhysicalRowIdManager( _file, _pageman );
- _logMgr = new LogicalRowIdManager( _file, _pageman );
+ recordFile = new RecordFile( filename );
+ pageMgr = new PageManager( recordFile );
+ physMgr = new PhysicalRowIdManager( recordFile, pageMgr );
+ logMgr = new LogicalRowIdManager( recordFile, pageMgr );
}
/**
- * Get the underlying Transaction Manager
+ * Get the underlying Transaction Manager
*/
public synchronized TransactionManager getTransactionManager()
{
checkIfClosed();
-
- return _file.txnMgr;
+ return recordFile.txnMgr;
}
/**
- * Switches off transactioning for the record manager. This means
- * that a) a transaction log is not kept, and b) writes aren't
- * synch'ed after every update. This is useful when batch inserting
- * into a new database.
+ * Switches off transactions for the record manager. This means
+ * that a) a transaction log is not kept, and b) writes aren't
+ * synch'ed after every update. This is useful when batch inserting
+ * into a new database.
* <p>
* Only call this method directly after opening the file, otherwise
* the results will be undefined.
@@ -169,53 +149,49 @@
public synchronized void disableTransactions()
{
checkIfClosed();
-
- _file.disableTransactions();
+ recordFile.disableTransactions();
}
/**
- * Closes the record manager.
+ * Closes the record manager.
*
- * @throws IOException when one of the underlying I/O operations fails.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public synchronized void close()
- throws IOException
+ public synchronized void close() throws IOException
{
checkIfClosed();
- _pageman.close();
- _pageman = null;
+ pageMgr.close();
+ pageMgr = null;
- _file.close();
- _file = null;
+ recordFile.close();
+ recordFile = null;
}
/**
- * Inserts a new record using standard java object serialization.
+ * Inserts a new record using standard java object serialization.
*
- * @param obj the object for the new record.
- * @return the rowid for the new record.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param obj the object for the new record.
+ * @return the rowid for the new record.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public long insert( Object obj )
- throws IOException
+ public long insert( Object obj ) throws IOException
{
return insert( obj, DefaultSerializer.INSTANCE );
}
/**
- * Inserts a new record using a custom serializer.
+ * Inserts a new record using a custom serializer.
*
- * @param obj the object for the new record.
- * @param serializer a custom serializer
- * @return the rowid for the new record.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param obj the object for the new record.
+ * @param serializer a custom serializer
+ * @return the rowid for the new record.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public synchronized long insert( Object obj, Serializer serializer )
- throws IOException
+ public synchronized long insert( Object obj, Serializer serializer ) throws IOException
{
byte[] data;
long recid;
@@ -224,105 +200,114 @@
checkIfClosed();
data = serializer.serialize( obj );
- physRowId = _physMgr.insert( data, 0, data.length );
- recid = _logMgr.insert( physRowId ).toLong();
- if ( DEBUG ) {
+ physRowId = physMgr.insert( data, 0, data.length );
+ recid = logMgr.insert( physRowId ).toLong();
+
+ if ( DEBUG )
+ {
System.out.println( "BaseRecordManager.insert() recid " + recid + " length "
+ data.length ) ;
}
+
return recid;
}
+
/**
- * Deletes a record.
+ * Deletes a record.
*
- * @param recid the rowid for the record that should be deleted.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param recid the rowid for the record that should be deleted.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public synchronized void delete( long recid )
- throws IOException
+ public synchronized void delete( long recid ) throws IOException
{
checkIfClosed();
- if ( recid <= 0 ) {
+
+ if ( recid <= 0 )
+ {
throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) );
}
- if ( DEBUG ) {
+ if ( DEBUG )
+ {
System.out.println( "BaseRecordManager.delete() recid " + recid ) ;
}
Location logRowId = new Location( recid );
- Location physRowId = _logMgr.fetch( logRowId );
- _physMgr.delete( physRowId );
- _logMgr.delete( logRowId );
+ Location physRowId = logMgr.fetch( logRowId );
+ physMgr.delete( physRowId );
+ logMgr.delete( logRowId );
}
/**
- * Updates a record using standard java object serialization.
+ * Updates a record using standard java object serialization.
*
- * @param recid the recid for the record that is to be updated.
- * @param obj the new object for the record.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param recid the recid for the record that is to be updated.
+ * @param obj the new object for the record.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public void update( long recid, Object obj )
- throws IOException
+ public void update( long recid, Object obj ) throws IOException
{
update( recid, obj, DefaultSerializer.INSTANCE );
}
/**
- * Updates a record using a custom serializer.
+ * Updates a record using a custom serializer.
*
- * @param recid the recid for the record that is to be updated.
- * @param obj the new object for the record.
- * @param serializer a custom serializer
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param recid the recid for the record that is to be updated.
+ * @param obj the new object for the record.
+ * @param serializer a custom serializer
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public synchronized void update( long recid, Object obj, Serializer serializer )
- throws IOException
+ public synchronized void update( long recid, Object obj, Serializer serializer ) throws
IOException
{
checkIfClosed();
- if ( recid <= 0 ) {
+
+ if ( recid <= 0 )
+ {
throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) );
}
Location logRecid = new Location( recid );
- Location physRecid = _logMgr.fetch( logRecid );
+ Location physRecid = logMgr.fetch( logRecid );
byte[] data = serializer.serialize( obj );
- if ( DEBUG ) {
+
+ if ( DEBUG )
+ {
System.out.println( "BaseRecordManager.update() recid " + recid + " length "
+ data.length ) ;
}
- Location newRecid = _physMgr.update( physRecid, data, 0, data.length );
- if ( ! newRecid.equals( physRecid ) ) {
- _logMgr.update( logRecid, newRecid );
+ Location newRecid = physMgr.update( physRecid, data, 0, data.length );
+
+ if ( ! newRecid.equals( physRecid ) )
+ {
+ logMgr.update( logRecid, newRecid );
}
}
/**
- * Fetches a record using standard java object serialization.
+ * Fetches a record using standard java object serialization.
*
- * @param recid the recid for the record that must be fetched.
- * @return the object contained in the record.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param recid the recid for the record that must be fetched.
+ * @return the object contained in the record.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public Object fetch( long recid )
- throws IOException
+ public Object fetch( long recid ) throws IOException
{
return fetch( recid, DefaultSerializer.INSTANCE );
}
/**
- * Fetches a record using a custom serializer.
+ * Fetches a record using a custom serializer.
*
- * @param recid the recid for the record that must be fetched.
- * @param serializer a custom serializer
- * @return the object contained in the record.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param recid the recid for the record that must be fetched.
+ * @param serializer a custom serializer
+ * @return the object contained in the record.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
public synchronized Object fetch( long recid, Serializer serializer )
throws IOException
@@ -330,11 +315,16 @@
byte[] data;
checkIfClosed();
- if ( recid <= 0 ) {
+
+ if ( recid <= 0 )
+ {
throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) );
}
- data = _physMgr.fetch( _logMgr.fetch( new Location( recid ) ) );
- if ( DEBUG ) {
+
+ data = physMgr.fetch( logMgr.fetch( new Location( recid ) ) );
+
+ if ( DEBUG )
+ {
System.out.println( "BaseRecordManager.fetch() recid " + recid + " length " +
data.length ) ;
}
return serializer.deserialize( data );
@@ -342,27 +332,27 @@
/**
- * Returns the number of slots available for "root" rowids. These slots
- * can be used to store special rowids, like rowids that point to
- * other rowids. Root rowids are useful for bootstrapping access to
- * a set of data.
+ * Returns the number of slots available for "root" rowids. These slots
+ * can be used to store special rowids, like rowids that point to
+ * other rowids. Root rowids are useful for bootstrapping access to
+ * a set of data.
*/
public int getRootCount()
{
return FileHeader.NROOTS;
}
+
/**
* Returns the indicated root rowid.
*
* @see #getRootCount
*/
- public synchronized long getRoot( int id )
- throws IOException
+ public synchronized long getRoot( int id ) throws IOException
{
checkIfClosed();
- return _pageman.getFileHeader().getRoot( id );
+ return pageMgr.getFileHeader().getRoot( id );
}
@@ -371,12 +361,11 @@
*
* @see #getRootCount
*/
- public synchronized void setRoot( int id, long rowid )
- throws IOException
+ public synchronized void setRoot( int id, long rowid ) throws IOException
{
checkIfClosed();
- _pageman.getFileHeader().setRoot( id, rowid );
+ pageMgr.getFileHeader().setRoot( id, rowid );
}
@@ -384,33 +373,38 @@
* Obtain the record id of a named object. Returns 0 if named object
* doesn't exist.
*/
- public long getNamedObject( String name )
- throws IOException
+ public long getNamedObject( String name ) throws IOException
{
checkIfClosed();
- Map nameDirectory = getNameDirectory();
- Long recid = (Long) nameDirectory.get( name );
- if ( recid == null ) {
+ Map<String,Long> nameDirectory = getNameDirectory();
+ Long recid = nameDirectory.get( name );
+
+ if ( recid == null )
+ {
return 0;
}
- return recid.longValue();
+
+ return recid;
}
+
/**
* Set the record id of a named object.
*/
- public void setNamedObject( String name, long recid )
- throws IOException
+ public void setNamedObject( String name, long recid ) throws IOException
{
checkIfClosed();
- Map nameDirectory = getNameDirectory();
- if ( recid == 0 ) {
+ Map<String,Long> nameDirectory = getNameDirectory();
+ if ( recid == 0 )
+ {
// remove from hashtable
nameDirectory.remove( name );
- } else {
- nameDirectory.put( name, new Long( recid ) );
+ }
+ else
+ {
+ nameDirectory.put( name, recid );
}
saveNameDirectory( nameDirectory );
}
@@ -424,60 +418,65 @@
{
checkIfClosed();
- _pageman.commit();
+ pageMgr.commit();
}
/**
* Rollback (cancel) all changes since beginning of transaction.
*/
- public synchronized void rollback()
- throws IOException
+ public synchronized void rollback() throws IOException
{
checkIfClosed();
- _pageman.rollback();
+ pageMgr.rollback();
}
/**
* Load name directory
*/
- private Map getNameDirectory()
- throws IOException
+ @SuppressWarnings("unchecked")
+ private Map<String,Long> getNameDirectory() throws IOException
{
// retrieve directory of named hashtable
long nameDirectory_recid = getRoot( NAME_DIRECTORY_ROOT );
- if ( nameDirectory_recid == 0 ) {
- _nameDirectory = new HashMap();
- nameDirectory_recid = insert( _nameDirectory );
+
+ if ( nameDirectory_recid == 0 )
+ {
+ nameDirectory = new HashMap<String, Long>();
+ nameDirectory_recid = insert( nameDirectory );
setRoot( NAME_DIRECTORY_ROOT, nameDirectory_recid );
- } else {
- _nameDirectory = (Map) fetch( nameDirectory_recid );
+ }
+ else
+ {
+ nameDirectory = ( Map<String, Long> ) fetch( nameDirectory_recid );
}
- return _nameDirectory;
+
+ return nameDirectory;
}
- private void saveNameDirectory( Map directory )
- throws IOException
+ private void saveNameDirectory( Map<String,Long> directory ) throws IOException
{
long recid = getRoot( NAME_DIRECTORY_ROOT );
- if ( recid == 0 ) {
+
+ if ( recid == 0 )
+ {
throw new IOException( I18n.err( I18n.ERR_537 ) );
}
- update( recid, _nameDirectory );
+
+ update( recid, nameDirectory );
}
/**
- * Check if RecordManager has been closed. If so, throw an
- * IllegalStateException.
+ * Check if RecordManager has been closed. If so, throw an IllegalStateException.
*/
- private void checkIfClosed()
- throws IllegalStateException
+ private void checkIfClosed() throws IllegalStateException
{
- if ( _file == null ) {
+ if ( recordFile == null )
+ {
throw new IllegalStateException( I18n.err( I18n.ERR_538 ) );
}
}
Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/CacheRecordManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/CacheRecordManager.java?rev=916036&r1=916035&r2=916036&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/CacheRecordManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/CacheRecordManager.java Wed Feb
24 23:27:29 2010
@@ -45,9 +45,9 @@
*
* $Id: CacheRecordManager.java,v 1.9 2005/06/25 23:12:32 doomdark Exp $
*/
-
package jdbm.recman;
+
import jdbm.RecordManager;
import jdbm.helper.CacheEvictionException;
import jdbm.helper.CachePolicy;
@@ -61,6 +61,7 @@
import org.apache.directory.server.i18n.I18n;
+
/**
* A RecordManager wrapping and caching another RecordManager.
*
@@ -68,41 +69,38 @@
* @author <a href="cg@cdegroot.com">Cees de Groot</a>
* @version $Id: CacheRecordManager.java,v 1.9 2005/06/25 23:12:32 doomdark Exp $
*/
-public class CacheRecordManager
- implements RecordManager
+public class CacheRecordManager implements RecordManager
{
+ /** Wrapped RecordManager */
+ protected RecordManager recMgr;
- /**
- * Wrapped RecordManager
- */
- protected RecordManager _recman;
-
-
- /**
- * Cache for underlying RecordManager
- */
- protected CachePolicy _cache;
+ /** Cache for underlying RecordManager */
+ protected CachePolicy<Long,CacheEntry> cache;
/**
* Construct a CacheRecordManager wrapping another RecordManager and
* using a given cache policy.
*
- * @param recman Wrapped RecordManager
+ * @param recMgr Wrapped RecordManager
* @param cache Cache policy
*/
- public CacheRecordManager( RecordManager recman, CachePolicy cache )
+ public CacheRecordManager( RecordManager recMgr, CachePolicy<Long,CacheEntry> cache
)
{
- if ( recman == null ) {
+ if ( recMgr == null )
+ {
throw new IllegalArgumentException( I18n.err( I18n.ERR_517 ) );
}
- if ( cache == null ) {
+
+ if ( cache == null )
+ {
throw new IllegalArgumentException( I18n.err( I18n.ERR_542 ) );
}
- _recman = recman;
- _cache = cache;
+
+ this.recMgr = recMgr;
+ this.cache = cache;
- _cache.addListener( new CacheListener() );
+ this.cache.addListener( new CacheListener() );
}
@@ -114,7 +112,7 @@
*/
public RecordManager getRecordManager()
{
- return _recman;
+ return recMgr;
}
@@ -124,43 +122,44 @@
* @return underlying CachePolicy or null if CacheRecordManager has
* been closed.
*/
- public CachePolicy getCachePolicy()
+ public CachePolicy<Long,CacheEntry> getCachePolicy()
{
- return _cache;
+ return cache;
}
/**
- * Inserts a new record using a custom serializer.
+ * Inserts a new record using a custom serializer.
*
- * @param obj the object for the new record.
- * @return the rowid for the new record.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param obj the object for the new record.
+ * @return the rowid for the new record.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public long insert( Object obj )
- throws IOException
+ public long insert( Object obj ) throws IOException
{
return insert( obj, DefaultSerializer.INSTANCE );
}
/**
- * Inserts a new record using a custom serializer.
+ * Inserts a new record using a custom serializer.
*
- * @param obj the object for the new record.
- * @param serializer a custom serializer
- * @return the rowid for the new record.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param obj the object for the new record.
+ * @param serializer a custom serializer
+ * @return the rowid for the new record.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public synchronized long insert( Object obj, Serializer serializer )
- throws IOException
+ public synchronized long insert( Object obj, Serializer serializer ) throws IOException
{
checkIfClosed();
- long recid = _recman.insert( obj, serializer );
- try {
- _cache.put( new Long( recid ), new CacheEntry( recid, obj, serializer, false
) );
- } catch ( CacheEvictionException except ) {
+ long recid = recMgr.insert( obj, serializer );
+ try
+ {
+ cache.put( recid, new CacheEntry( recid, obj, serializer, false ) );
+ }
+ catch ( CacheEvictionException except )
+ {
throw new WrappedRuntimeException( except );
}
return recid;
@@ -168,203 +167,199 @@
/**
- * Deletes a record.
+ * Deletes a record.
*
- * @param recid the rowid for the record that should be deleted.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param recid the rowid for the record that should be deleted.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public synchronized void delete( long recid )
- throws IOException
+ public synchronized void delete( long recid ) throws IOException
{
checkIfClosed();
- _recman.delete( recid );
- _cache.remove( new Long( recid ) );
+ recMgr.delete( recid );
+ cache.remove( recid );
}
/**
- * Updates a record using standard Java serialization.
+ * Updates a record using standard Java serialization.
*
- * @param recid the recid for the record that is to be updated.
- * @param obj the new object for the record.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param recid the recid for the record that is to be updated.
+ * @param obj the new object for the record.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public void update( long recid, Object obj )
- throws IOException
+ public void update( long recid, Object obj ) throws IOException
{
update( recid, obj, DefaultSerializer.INSTANCE );
}
/**
- * Updates a record using a custom serializer.
+ * Updates a record using a custom serializer.
*
- * @param recid the recid for the record that is to be updated.
- * @param obj the new object for the record.
- * @param serializer a custom serializer
- * @throws IOException when one of the underlying I/O operations fails.
- */
- public synchronized void update( long recid, Object obj,
- Serializer serializer )
- throws IOException
+ * @param recid the recid for the record that is to be updated.
+ * @param obj the new object for the record.
+ * @param serializer a custom serializer
+ * @throws IOException when one of the underlying I/O operations fails.
+ */
+ public synchronized void update( long recid, Object obj, Serializer serializer ) throws
IOException
{
CacheEntry entry;
- Long id;
checkIfClosed();
- id = new Long( recid );
try {
- entry = (CacheEntry) _cache.get( id );
- if ( entry != null ) {
+ entry = cache.get( recid );
+
+ if ( entry != null )
+ {
// reuse existing cache entry
- entry._obj = obj;
- entry._serializer = serializer;
- entry._isDirty = true;
- } else {
- _cache.put( id, new CacheEntry( recid, obj, serializer, true ) );
+ entry.obj = obj;
+ entry.serializer = serializer;
+ entry.isDirty = true;
+ }
+ else
+ {
+ cache.put( recid, new CacheEntry( recid, obj, serializer, true ) );
}
- } catch ( CacheEvictionException except ) {
+ }
+ catch ( CacheEvictionException except )
+ {
throw new IOException( except.getLocalizedMessage() );
}
}
/**
- * Fetches a record using standard Java serialization.
+ * Fetches a record using standard Java serialization.
*
- * @param recid the recid for the record that must be fetched.
- * @return the object contained in the record.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param recid the recid for the record that must be fetched.
+ * @return the object contained in the record.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public Object fetch( long recid )
- throws IOException
+ public Object fetch( long recid ) throws IOException
{
return fetch( recid, DefaultSerializer.INSTANCE );
}
/**
- * Fetches a record using a custom serializer.
+ * Fetches a record using a custom serializer.
*
- * @param recid the recid for the record that must be fetched.
- * @param serializer a custom serializer
- * @return the object contained in the record.
- * @throws IOException when one of the underlying I/O operations fails.
+ * @param recid the recid for the record that must be fetched.
+ * @param serializer a custom serializer
+ * @return the object contained in the record.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public synchronized Object fetch( long recid, Serializer serializer )
- throws IOException
+ public synchronized Object fetch( long recid, Serializer serializer ) throws IOException
{
checkIfClosed();
- Long id = new Long( recid );
- CacheEntry entry = (CacheEntry) _cache.get( id );
- if ( entry == null ) {
+ CacheEntry entry = cache.get( recid );
+ if ( entry == null )
+ {
entry = new CacheEntry( recid, null, serializer, false );
- entry._obj = _recman.fetch( recid, serializer );
- try {
- _cache.put( id, entry );
- } catch ( CacheEvictionException except ) {
+ entry.obj = recMgr.fetch( recid, serializer );
+ try
+ {
+ cache.put( recid, entry );
+ }
+ catch ( CacheEvictionException except )
+ {
throw new WrappedRuntimeException( except );
}
}
- if ( entry._obj instanceof byte[] )
+ if ( entry.obj instanceof byte[] )
{
- byte[] copy = new byte[((byte[])entry._obj).length];
- System.arraycopy( entry._obj, 0, copy, 0, ((byte[])entry._obj).length );
+ byte[] copy = new byte[ ( ( byte[] ) entry.obj ).length ];
+ System.arraycopy( entry.obj, 0, copy, 0, ( ( byte[] ) entry.obj ).length );
return copy;
}
- return entry._obj;
+ return entry.obj;
}
/**
- * Closes the record manager.
+ * Closes the record manager.
*
- * @throws IOException when one of the underlying I/O operations fails.
+ * @throws IOException when one of the underlying I/O operations fails.
*/
- public synchronized void close()
- throws IOException
+ public synchronized void close() throws IOException
{
checkIfClosed();
updateCacheEntries();
- _recman.close();
- _recman = null;
- _cache = null;
+ recMgr.close();
+ recMgr = null;
+ cache = null;
}
/**
- * Returns the number of slots available for "root" rowids. These slots
- * can be used to store special rowids, like rowids that point to
- * other rowids. Root rowids are useful for bootstrapping access to
- * a set of data.
+ * Returns the number of slots available for "root" rowids. These slots
+ * can be used to store special rowids, like rowids that point to
+ * other rowids. Root rowids are useful for bootstrapping access to
+ * a set of data.
*/
public synchronized int getRootCount()
{
checkIfClosed();
- return _recman.getRootCount();
+ return recMgr.getRootCount();
}
/**
- * Returns the indicated root rowid.
+ * Returns the indicated root rowid.
*
- * @see #getRootCount
+ * @see #getRootCount
*/
- public synchronized long getRoot( int id )
- throws IOException
+ public synchronized long getRoot( int id ) throws IOException
{
checkIfClosed();
- return _recman.getRoot( id );
+ return recMgr.getRoot( id );
}
/**
- * Sets the indicated root rowid.
+ * Sets the indicated root rowid.
*
- * @see #getRootCount
+ * @see #getRootCount
*/
- public synchronized void setRoot( int id, long rowid )
- throws IOException
+ public synchronized void setRoot( int id, long rowid ) throws IOException
{
checkIfClosed();
- _recman.setRoot( id, rowid );
+ recMgr.setRoot( id, rowid );
}
/**
* Commit (make persistent) all changes since beginning of transaction.
*/
- public synchronized void commit()
- throws IOException
+ public synchronized void commit() throws IOException
{
checkIfClosed();
updateCacheEntries();
- _recman.commit();
+ recMgr.commit();
}
/**
* Rollback (cancel) all changes since beginning of transaction.
*/
- public synchronized void rollback()
- throws IOException
+ public synchronized void rollback() throws IOException
{
checkIfClosed();
- _recman.rollback();
+ recMgr.rollback();
// discard all cache entries since we don't know which entries
// where part of the transaction
- _cache.removeAll();
+ cache.removeAll();
}
@@ -372,35 +367,32 @@
* Obtain the record id of a named object. Returns 0 if named object
* doesn't exist.
*/
- public synchronized long getNamedObject( String name )
- throws IOException
+ public synchronized long getNamedObject( String name ) throws IOException
{
checkIfClosed();
- return _recman.getNamedObject( name );
+ return recMgr.getNamedObject( name );
}
/**
* Set the record id of a named object.
*/
- public synchronized void setNamedObject( String name, long recid )
- throws IOException
+ public synchronized void setNamedObject( String name, long recid ) throws IOException
{
checkIfClosed();
- _recman.setNamedObject( name, recid );
+ recMgr.setNamedObject( name, recid );
}
/**
- * Check if RecordManager has been closed. If so, throw an
- * IllegalStateException
+ * Check if RecordManager has been closed. If so, throw an IllegalStateException
*/
- private void checkIfClosed()
- throws IllegalStateException
+ private void checkIfClosed() throws IllegalStateException
{
- if ( _recman == null ) {
+ if ( recMgr == null )
+ {
throw new IllegalStateException( I18n.err( I18n.ERR_538 ) );
}
}
@@ -409,15 +401,16 @@
/**
* Update all dirty cache objects to the underlying RecordManager.
*/
- protected void updateCacheEntries()
- throws IOException
+ protected void updateCacheEntries() throws IOException
{
- Enumeration enume = _cache.elements();
- while ( enume.hasMoreElements() ) {
- CacheEntry entry = (CacheEntry) enume.nextElement();
- if ( entry._isDirty ) {
- _recman.update( entry._recid, entry._obj, entry._serializer );
- entry._isDirty = false;
+ Enumeration<CacheEntry> enume = cache.elements();
+ while ( enume.hasMoreElements() )
+ {
+ CacheEntry entry = enume.nextElement();
+ if ( entry.isDirty )
+ {
+ recMgr.update( entry.recid, entry.obj, entry.serializer );
+ entry.isDirty = false;
}
}
}
@@ -425,43 +418,44 @@
private class CacheEntry
{
-
- long _recid;
- Object _obj;
- Serializer _serializer;
- boolean _isDirty;
+ long recid;
+ Object obj;
+ Serializer serializer;
+ boolean isDirty;
CacheEntry( long recid, Object obj, Serializer serializer, boolean isDirty )
{
- _recid = recid;
- _obj = obj;
- _serializer = serializer;
- _isDirty = isDirty;
+ this.recid = recid;
+ this.obj = obj;
+ this.serializer = serializer;
+ this.isDirty = isDirty;
}
} // class CacheEntry
- private class CacheListener
- implements CachePolicyListener
+
+ private class CacheListener implements CachePolicyListener<CacheEntry>
{
- /** Notification that cache is evicting an object
- *
- * @arg obj object evited from cache
+ /**
+ * Notification that cache is evicting an object
*
+ * @param obj object evicted from cache
*/
- public void cacheObjectEvicted( Object obj )
- throws CacheEvictionException
+ public void cacheObjectEvicted( CacheEntry obj ) throws CacheEvictionException
{
- CacheEntry entry = (CacheEntry) obj;
- if ( entry._isDirty ) {
- try {
- _recman.update( entry._recid, entry._obj, entry._serializer );
- } catch ( IOException except ) {
+ CacheEntry entry = obj;
+ if ( entry.isDirty )
+ {
+ try
+ {
+ recMgr.update( entry.recid, entry.obj, entry.serializer );
+ }
+ catch ( IOException except )
+ {
throw new CacheEvictionException( except );
}
}
}
-
}
}
|