You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/11/05 03:31:05 UTC
svn commit: r471336 [2/2] - in
/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis:
service/protocol/ service/protocol/codec/ service/protocol/message/ store/
store/derby/ util/
Modified: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStore.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStore.java?view=diff&rev=471336&r1=471335&r2=471336
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStore.java (original)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStore.java Sat Nov 4 18:31:02 2006
@@ -19,6 +19,7 @@
*/
package org.apache.directory.mitosis.store.derby;
+
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -49,13 +50,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
public class DerbyReplicationStore implements ReplicationStore
{
private static final Logger log = LoggerFactory.getLogger( DerbyReplicationStore.class );
private static final String DEFAULT_TABLE_PREFIX = "REPLICATION_";
private static final String KEY_REPLICA_ID = "replicaId";
-
+
private static final String DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver";
private static final String DB_URI_PREFIX = "jdbc:derby:";
@@ -70,34 +72,37 @@
private final Object knownReplicaIdsLock = new Object();
private final OperationCodec operationCodec = new OperationCodec();
-
+
public String getTablePrefix()
{
return tablePrefix;
}
+
public void setTablePrefix( String tablePrefix )
{
- if( tablePrefix == null )
+ if ( tablePrefix == null )
{
tablePrefix = DEFAULT_TABLE_PREFIX;
}
-
+
tablePrefix = tablePrefix.trim();
- if( tablePrefix.length() == 0 )
+ if ( tablePrefix.length() == 0 )
{
tablePrefix = DEFAULT_TABLE_PREFIX;
}
-
+
this.tablePrefix = tablePrefix;
}
+
public void open( DirectoryServiceConfiguration serviceCfg, ReplicationConfiguration cfg )
{
replicaId = cfg.getReplicaId();
-
+
// Calculate DB URI
- dbURI = DB_URI_PREFIX + serviceCfg.getStartupConfiguration().getWorkingDirectory().getPath() + File.separator + "replication";
+ dbURI = DB_URI_PREFIX + serviceCfg.getStartupConfiguration().getWorkingDirectory().getPath() + File.separator
+ + "replication";
// Create database if not exists.
try
@@ -106,7 +111,7 @@
Connection con = DriverManager.getConnection( dbURI + ";create=true" );
con.close();
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new ReplicationStoreException( "Failed to initialize Derby database.", e );
}
@@ -118,16 +123,17 @@
dataSource.setUsername( "sa" );
dataSource.setPassword( "" );
this.dataSource = dataSource;
-
+
// Pre-calculate table names
metadataTableName = tablePrefix + "METADATA";
uuidTableName = tablePrefix + "UUID";
logTableName = tablePrefix + "LOG";
-
+
initSchema();
loadMetadata();
}
-
+
+
private void initSchema()
{
Connection con = null;
@@ -147,48 +153,39 @@
rs.close();
rs = null;
}
- catch( SQLException e )
+ catch ( SQLException e )
{
- stmt.executeUpdate( "CREATE TABLE " + metadataTableName + " (" +
- " M_KEY VARCHAR(30) NOT NULL PRIMARY KEY," +
- " M_VALUE VARCHAR(100) NOT NULL )" );
+ stmt.executeUpdate( "CREATE TABLE " + metadataTableName + " ("
+ + " M_KEY VARCHAR(30) NOT NULL PRIMARY KEY," + " M_VALUE VARCHAR(100) NOT NULL )" );
}
-
+
try
{
rs = stmt.executeQuery( "SELECT UUID FROM " + uuidTableName + " WHERE UUID IS NULL" );
rs.close();
rs = null;
}
- catch( SQLException e )
+ catch ( SQLException e )
{
- stmt.executeUpdate( "CREATE TABLE " + uuidTableName + " (" +
- " UUID CHAR(32) NOT NULL PRIMARY KEY," +
- " DN CLOB NOT NULL" +
- ")" );
+ stmt.executeUpdate( "CREATE TABLE " + uuidTableName + " (" + " UUID CHAR(32) NOT NULL PRIMARY KEY,"
+ + " DN CLOB NOT NULL" + ")" );
}
-
+
try
{
rs = stmt.executeQuery( "SELECT CSN_REPLICA_ID FROM " + logTableName + " WHERE CSN_REPLICA_ID IS NULL" );
rs.close();
rs = null;
}
- catch( SQLException e )
+ catch ( SQLException e )
{
- stmt.executeUpdate( "CREATE TABLE " + logTableName + " (" +
- " CSN_REPLICA_ID VARCHAR(16) NOT NULL," +
- " CSN_TIMESTAMP BIGINT NOT NULL," +
- " CSN_OP_SEQ INTEGER NOT NULL," +
- " OPERATION BLOB NOT NULL," +
- "CONSTRAINT " + logTableName + "_PK PRIMARY KEY (" +
- " CSN_REPLICA_ID," +
- " CSN_TIMESTAMP," +
- " CSN_OP_SEQ)" +
- ")");
+ stmt.executeUpdate( "CREATE TABLE " + logTableName + " (" + " CSN_REPLICA_ID VARCHAR(16) NOT NULL,"
+ + " CSN_TIMESTAMP BIGINT NOT NULL," + " CSN_OP_SEQ INTEGER NOT NULL,"
+ + " OPERATION BLOB NOT NULL," + "CONSTRAINT " + logTableName + "_PK PRIMARY KEY ("
+ + " CSN_REPLICA_ID," + " CSN_TIMESTAMP," + " CSN_OP_SEQ)" + ")" );
}
}
- catch( SQLException e )
+ catch ( SQLException e )
{
throw new ReplicationStoreException( "Failed to initialize DB schema.", e );
}
@@ -197,33 +194,33 @@
SQLUtil.cleanup( con, stmt, rs );
}
}
-
+
+
private void loadMetadata()
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
-
+
try
{
con = dataSource.getConnection();
con.setAutoCommit( true );
con.setTransactionIsolation( Connection.TRANSACTION_REPEATABLE_READ );
con.setReadOnly( true );
-
+
// Check if replicaId is already registered
ps = con.prepareStatement( "SELECT M_VALUE FROM " + metadataTableName + " WHERE M_KEY=?" );
ps.setString( 1, KEY_REPLICA_ID );
rs = ps.executeQuery();
- if( rs.next() )
+ if ( rs.next() )
{
// If already registered, match it with what user specified.
String actualReplicaId = rs.getString( 1 );
- if( !replicaId.getId().equalsIgnoreCase( actualReplicaId ) )
+ if ( !replicaId.getId().equalsIgnoreCase( actualReplicaId ) )
{
- throw new ReplicationStoreException(
- "Replica ID mismatches: " + actualReplicaId +
- " (expected: " + replicaId + ")" );
+ throw new ReplicationStoreException( "Replica ID mismatches: " + actualReplicaId + " (expected: "
+ + replicaId + ")" );
}
}
else
@@ -232,7 +229,7 @@
rs = null;
ps.close();
ps = null;
-
+
con.setReadOnly( false );
// If not registered yet, register with what user specified.
ps = con.prepareStatement( "INSERT INTO " + metadataTableName + " (M_KEY, M_VALUE) VALUES (?,?)" );
@@ -240,27 +237,27 @@
ps.setString( 2, replicaId.getId() );
ps.executeUpdate();
}
-
- if( rs != null )
+
+ if ( rs != null )
{
rs.close();
rs = null;
}
ps.close();
ps = null;
-
+
// Get known replica IDs.
ps = con.prepareStatement( "SELECT DISTINCT CSN_REPLICA_ID FROM " + logTableName );
rs = ps.executeQuery();
knownReplicaIds = new HashSet();
- while( rs.next() )
+ while ( rs.next() )
{
knownReplicaIds.add( new ReplicaId( rs.getString( 1 ) ) );
}
}
- catch( Exception e )
+ catch ( Exception e )
{
- if( e instanceof ReplicationStoreException )
+ if ( e instanceof ReplicationStoreException )
{
throw ( ReplicationStoreException ) e;
}
@@ -272,13 +269,14 @@
}
}
+
public void close()
{
try
{
dataSource.close();
}
- catch( SQLException e )
+ catch ( SQLException e )
{
log.warn( "Failed to close the dataSource.", e );
}
@@ -289,28 +287,31 @@
{
DriverManager.getConnection( dbURI + ";shutdown=true" );
}
- catch( Exception e )
+ catch ( Exception e )
{
// An exception is thrown always.
}
}
+
public ReplicaId getReplicaId()
{
return replicaId;
}
-
+
+
public Set getKnownReplicaIds()
{
return new HashSet( knownReplicaIds );
}
+
public Name getDN( UUID uuid )
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
-
+
try
{
con = dataSource.getConnection();
@@ -319,7 +320,7 @@
ps = con.prepareStatement( "SELECT DN FROM " + uuidTableName + " WHERE UUID=?" );
ps.setString( 1, uuid.toOctetString() );
rs = ps.executeQuery();
- if( rs.next() )
+ if ( rs.next() )
{
return new LdapName( rs.getString( 1 ) );
}
@@ -328,7 +329,7 @@
return null;
}
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new ReplicationStoreException( e );
}
@@ -338,48 +339,51 @@
}
}
+
public boolean putUUID( UUID uuid, Name dn )
{
String uuidString = uuid.toOctetString();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
-
+
try
{
con = dataSource.getConnection();
con.setAutoCommit( false );
con.setTransactionIsolation( Connection.TRANSACTION_REPEATABLE_READ );
con.setReadOnly( true );
-
+
// Check if the specified uuid already exists
ps = con.prepareStatement( "SELECT UUID FROM " + uuidTableName + " WHERE UUID=?" );
ps.setString( 1, uuidString );
rs = ps.executeQuery();
- if( rs.next() )
+ if ( rs.next() )
{
return false;
}
-
+
rs.close();
rs = null;
-
+
// insert
con.setReadOnly( false );
ps = con.prepareStatement( "INSERT INTO " + uuidTableName + " (UUID, DN) VALUES(?,?)" );
ps.setString( 1, uuidString );
ps.setString( 2, dn.toString() );
-
+
int updateCnt = ps.executeUpdate();
con.commit();
return updateCnt == 1;
}
- catch( Exception e )
+ catch ( Exception e )
{
try
{
con.rollback();
- } catch (SQLException e1) {
+ }
+ catch ( SQLException e1 )
+ {
}
throw new ReplicationStoreException( e );
@@ -390,25 +394,26 @@
}
}
+
public boolean removeUUID( UUID uuid )
{
String uuidString = uuid.toOctetString();
Connection con = null;
PreparedStatement ps = null;
-
+
try
{
con = dataSource.getConnection();
con.setAutoCommit( true );
con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED );
con.setReadOnly( false );
-
+
// Check if the specified uuid already exists
ps = con.prepareStatement( "DELETE FROM " + uuidTableName + " WHERE UUID=?" );
ps.setString( 1, uuidString );
return ps.executeUpdate() == 1;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new ReplicationStoreException( e );
}
@@ -418,48 +423,50 @@
}
}
+
public void putLog( Operation op )
{
CSN csn = op.getCSN();
byte[] encodedOp = operationCodec.encode( op );
Connection con = null;
PreparedStatement ps = null;
-
+
try
{
con = dataSource.getConnection();
con.setAutoCommit( true );
con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED );
con.setReadOnly( false );
-
+
// Check if the specified uuid already exists
- ps = con.prepareStatement( "INSERT INTO " + logTableName + " (CSN_REPLICA_ID, CSN_TIMESTAMP, CSN_OP_SEQ, OPERATION) VALUES(?,?,?,?)" );
+ ps = con.prepareStatement( "INSERT INTO " + logTableName
+ + " (CSN_REPLICA_ID, CSN_TIMESTAMP, CSN_OP_SEQ, OPERATION) VALUES(?,?,?,?)" );
ps.setString( 1, csn.getReplicaId().getId() );
ps.setLong( 2, csn.getTimestamp() );
ps.setInt( 3, csn.getOperationSequence() );
ps.setBytes( 4, encodedOp );
- if( ps.executeUpdate() != 1 )
+ if ( ps.executeUpdate() != 1 )
{
throw new ReplicationStoreException( "Failed to insert a row." );
}
}
- catch( Exception e )
+ catch ( Exception e )
{
- if( e instanceof ReplicationStoreException )
+ if ( e instanceof ReplicationStoreException )
{
throw ( ReplicationStoreException ) e;
}
-
+
throw new ReplicationStoreException( e );
}
finally
{
SQLUtil.cleanup( con, ps, null );
}
-
- if( !knownReplicaIds.contains( csn.getReplicaId() ) )
+
+ if ( !knownReplicaIds.contains( csn.getReplicaId() ) )
{
- synchronized( knownReplicaIdsLock )
+ synchronized ( knownReplicaIdsLock )
{
Set newKnownReplicaIds = new HashSet( knownReplicaIds );
newKnownReplicaIds.add( csn.getReplicaId() );
@@ -468,26 +475,27 @@
}
}
+
public ReplicationLogIterator getLogs( CSNVector updateVector, boolean inclusive )
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
-
+
updateVector = getNormalizedUpdateVector( updateVector );
-
- StringBuffer buf = new StringBuffer(
- "SELECT CSN_REPLICA_ID, CSN_TIMESTAMP, CSN_OP_SEQ, OPERATION FROM " +
- logTableName + " " );
-
- if( updateVector.size() > 0 )
+
+ StringBuffer buf = new StringBuffer( "SELECT CSN_REPLICA_ID, CSN_TIMESTAMP, CSN_OP_SEQ, OPERATION FROM "
+ + logTableName + " " );
+
+ if ( updateVector.size() > 0 )
{
buf.append( "WHERE " );
- for( int i = updateVector.size();; )
+ for ( int i = updateVector.size();; )
{
- buf.append( "( CSN_REPLICA_ID = ? AND (CSN_TIMESTAMP = ? AND CSN_OP_SEQ >" + (inclusive? "=" : "" ) + " ? OR CSN_TIMESTAMP > ?) ) " );
- i --;
- if( i == 0 )
+ buf.append( "( CSN_REPLICA_ID = ? AND (CSN_TIMESTAMP = ? AND CSN_OP_SEQ >" + ( inclusive ? "=" : "" )
+ + " ? OR CSN_TIMESTAMP > ?) ) " );
+ i--;
+ if ( i == 0 )
{
break;
}
@@ -495,26 +503,26 @@
{
buf.append( "OR " );
}
-
+
}
}
buf.append( "ORDER BY CSN_TIMESTAMP ASC, CSN_OP_SEQ ASC" );
-
+
String query = buf.toString();
-
+
try
{
con = dataSource.getConnection();
con.setAutoCommit( true );
con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED );
con.setReadOnly( true );
-
+
// Check if the specified uuid already exists
ps = con.prepareStatement( query );
-
+
Iterator i = updateVector.getReplicaIds().iterator();
int paramIdx = 1;
- while( i.hasNext() )
+ while ( i.hasNext() )
{
ReplicaId replicaId = ( ReplicaId ) i.next();
CSN csn = updateVector.getCSN( replicaId );
@@ -524,84 +532,90 @@
ps.setLong( paramIdx++, csn.getTimestamp() );
}
rs = ps.executeQuery();
-
+
return new DerbyReplicationLogIterator( operationCodec, con, ps, rs );
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new ReplicationStoreException( e );
}
}
+
private CSNVector getNormalizedUpdateVector( CSNVector updateVector )
{
CSNVector newUV = new CSNVector();
- synchronized( knownReplicaIds )
+ synchronized ( knownReplicaIds )
{
Iterator i = knownReplicaIds.iterator();
- while( i.hasNext() )
+ while ( i.hasNext() )
{
- newUV.setCSN( new SimpleCSN( 0, ( ReplicaId ) i.next(), 0 ) );
+ newUV.setCSN( new SimpleCSN( 0, ( ReplicaId ) i.next(), 0 ) );
}
}
-
+
newUV.setAllCSN( updateVector );
return newUV;
}
+
public ReplicationLogIterator getLogs( CSN fromCSN, boolean inclusive )
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
-
+
try
{
con = dataSource.getConnection();
con.setAutoCommit( true );
con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED );
con.setReadOnly( true );
-
+
// Check if the specified uuid already exists
- ps = con.prepareStatement( "SELECT CSN_REPLICA_ID, CSN_TIMESTAMP, CSN_OP_SEQ, OPERATION FROM " + logTableName + " " +
- "WHERE CSN_REPLICA_ID = ? AND (CSN_TIMESTAMP = ? AND CSN_OP_SEQ >" + (inclusive? "=" : "" ) + " ? OR CSN_TIMESTAMP > ?) " +
- "ORDER BY CSN_TIMESTAMP ASC, CSN_OP_SEQ ASC");
+ ps = con
+ .prepareStatement( "SELECT CSN_REPLICA_ID, CSN_TIMESTAMP, CSN_OP_SEQ, OPERATION FROM " + logTableName
+ + " " + "WHERE CSN_REPLICA_ID = ? AND (CSN_TIMESTAMP = ? AND CSN_OP_SEQ >"
+ + ( inclusive ? "=" : "" ) + " ? OR CSN_TIMESTAMP > ?) "
+ + "ORDER BY CSN_TIMESTAMP ASC, CSN_OP_SEQ ASC" );
ps.setString( 1, fromCSN.getReplicaId().getId() );
ps.setLong( 2, fromCSN.getTimestamp() );
ps.setInt( 3, fromCSN.getOperationSequence() );
ps.setLong( 4, fromCSN.getTimestamp() );
rs = ps.executeQuery();
-
+
return new DerbyReplicationLogIterator( operationCodec, con, ps, rs );
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new ReplicationStoreException( e );
}
}
-
+
+
public int removeLogs( CSN toCSN, boolean inclusive )
{
Connection con = null;
PreparedStatement ps = null;
-
+
try
{
con = dataSource.getConnection();
con.setAutoCommit( true );
con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED );
con.setReadOnly( false );
-
+
// Check if the specified uuid already exists
- ps = con.prepareStatement( "DELETE FROM " + logTableName + " WHERE " +
- "CSN_REPLICA_ID = ? AND (CSN_TIMESTAMP = ? AND CSN_OP_SEQ <" + (inclusive? "=" : "" ) + " ? OR CSN_TIMESTAMP < ?)" );
+ ps = con.prepareStatement( "DELETE FROM " + logTableName + " WHERE "
+ + "CSN_REPLICA_ID = ? AND (CSN_TIMESTAMP = ? AND CSN_OP_SEQ <" + ( inclusive ? "=" : "" )
+ + " ? OR CSN_TIMESTAMP < ?)" );
ps.setString( 1, toCSN.getReplicaId().getId() );
ps.setLong( 2, toCSN.getTimestamp() );
ps.setInt( 3, toCSN.getOperationSequence() );
ps.setLong( 4, toCSN.getTimestamp() );
return ps.executeUpdate();
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new ReplicationStoreException( e );
}
@@ -610,13 +624,14 @@
SQLUtil.cleanup( con, ps, null );
}
}
-
+
+
public int getLogSize()
{
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
-
+
try
{
con = dataSource.getConnection();
@@ -627,7 +642,7 @@
rs.next();
return rs.getInt( 1 );
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new ReplicationStoreException( e );
}
@@ -637,24 +652,25 @@
}
}
+
public int getLogSize( ReplicaId replicaId )
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
-
+
try
{
con = dataSource.getConnection();
con.setTransactionIsolation( Connection.TRANSACTION_READ_COMMITTED );
con.setReadOnly( true );
- ps = con.prepareStatement( "SELECT COUNT(*) FROM " + logTableName + " WHERE CSN_REPLICA_ID=?");
+ ps = con.prepareStatement( "SELECT COUNT(*) FROM " + logTableName + " WHERE CSN_REPLICA_ID=?" );
ps.setString( 1, replicaId.getId() );
rs = ps.executeQuery();
rs.next();
return rs.getInt( 1 );
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new ReplicationStoreException( e );
}
@@ -664,39 +680,43 @@
}
}
+
public CSNVector getUpdateVector()
{
return getVector( false );
}
+
public CSNVector getPurgeVector()
{
return getVector( true );
}
-
+
+
private CSNVector getVector( boolean min )
{
final String ORDER = min ? "ASC" : "DESC";
-
+
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
CSNVector result = new CSNVector();
-
+
try
{
con = dataSource.getConnection();
con.setTransactionIsolation( Connection.TRANSACTION_READ_COMMITTED );
con.setReadOnly( true );
- ps = con.prepareStatement( "SELECT CSN_TIMESTAMP, CSN_OP_SEQ FROM " + logTableName + " WHERE CSN_REPLICA_ID=? ORDER BY CSN_TIMESTAMP " + ORDER + ", CSN_OP_SEQ " + ORDER );
-
+ ps = con.prepareStatement( "SELECT CSN_TIMESTAMP, CSN_OP_SEQ FROM " + logTableName
+ + " WHERE CSN_REPLICA_ID=? ORDER BY CSN_TIMESTAMP " + ORDER + ", CSN_OP_SEQ " + ORDER );
+
Iterator it = knownReplicaIds.iterator();
- while( it.hasNext() )
+ while ( it.hasNext() )
{
ReplicaId replicaId = ( ReplicaId ) it.next();
ps.setString( 1, replicaId.getId() );
rs = ps.executeQuery();
- if( rs.next() )
+ if ( rs.next() )
{
result.setCSN( new SimpleCSN( rs.getLong( 1 ), replicaId, rs.getInt( 2 ) ) );
}
@@ -704,10 +724,10 @@
rs = null;
ps.clearParameters();
}
-
+
return result;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new ReplicationStoreException( e );
}
Modified: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/SQLUtil.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/SQLUtil.java?view=diff&rev=471336&r1=471335&r2=471336
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/SQLUtil.java (original)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/SQLUtil.java Sat Nov 4 18:31:02 2006
@@ -19,42 +19,45 @@
*/
package org.apache.directory.mitosis.store.derby;
+
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-class SQLUtil {
+
+class SQLUtil
+{
static void cleanup( Connection con, Statement stmt, ResultSet rs )
{
- if( rs != null )
+ if ( rs != null )
{
try
{
rs.close();
}
- catch( SQLException e )
+ catch ( SQLException e )
{
}
}
- if( stmt != null )
+ if ( stmt != null )
{
try
{
stmt.close();
}
- catch( SQLException e )
+ catch ( SQLException e )
{
}
}
- if( con != null )
+ if ( con != null )
{
try
{
con.close();
}
- catch( SQLException e )
+ catch ( SQLException e )
{
}
}
Modified: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/util/OctetString.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/util/OctetString.java?view=diff&rev=471336&r1=471335&r2=471336
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/util/OctetString.java (original)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/util/OctetString.java Sat Nov 4 18:31:02 2006
@@ -19,6 +19,7 @@
*/
package org.apache.directory.mitosis.util;
+
/**
* A utuility class that generates octet strings from numbers.
*
@@ -29,118 +30,126 @@
{
private static final char[] highDigits;
private static final char[] lowDigits;
-
+
static
{
final char[] digits =
- { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+ { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
int i;
char[] high = new char[256];
char[] low = new char[256];
-
- for( i = 0; i < 256; i++ )
+
+ for ( i = 0; i < 256; i++ )
{
- high[i] = digits[ i >>> 4 ];
- low[i] = digits[ i & 0x0F ];
+ high[i] = digits[i >>> 4];
+ low[i] = digits[i & 0x0F];
}
-
+
highDigits = high;
lowDigits = low;
}
+
public static void append( StringBuffer dst, long value )
{
int v;
- v = (int) ( value >>> 56 );
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
-
- v = (int) ( value >>> 48 ) & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
-
- v = (int) ( value >>> 40 ) & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
-
- v = (int) ( value >>> 32 ) & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
-
- v = (int) ( value >>> 24 ) & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
-
- v = (int) ( value >>> 16 ) & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
-
- v = (int) ( value >>> 8 ) & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
-
- v = (int) value & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
+ v = ( int ) ( value >>> 56 );
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
+
+ v = ( int ) ( value >>> 48 ) & 0xff;
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
+
+ v = ( int ) ( value >>> 40 ) & 0xff;
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
+
+ v = ( int ) ( value >>> 32 ) & 0xff;
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
+
+ v = ( int ) ( value >>> 24 ) & 0xff;
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
+
+ v = ( int ) ( value >>> 16 ) & 0xff;
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
+
+ v = ( int ) ( value >>> 8 ) & 0xff;
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
+
+ v = ( int ) value & 0xff;
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
}
-
+
+
public static void append( StringBuffer dst, int value )
{
int v;
v = ( value >>> 24 ) & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
-
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
+
v = ( value >>> 16 ) & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
-
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
+
v = ( value >>> 8 ) & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
-
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
+
v = value & 0xff;
- dst.append( highDigits[ v ] );
- dst.append( lowDigits[ v ] );
+ dst.append( highDigits[v] );
+ dst.append( lowDigits[v] );
}
-
+
+
public static String toString( byte[] src )
{
final int end = src.length;
StringBuffer dst = new StringBuffer( src.length << 1 );
- for( int i = 0; i < end; i++ )
+ for ( int i = 0; i < end; i++ )
{
- dst.append( highDigits[ src[ i ] & 0xff ] );
- dst.append( lowDigits[ src[ i ] & 0xff ] );
+ dst.append( highDigits[src[i] & 0xff] );
+ dst.append( lowDigits[src[i] & 0xff] );
}
-
+
return dst.toString();
}
-
+
+
public static String toString( long value )
{
StringBuffer dst = new StringBuffer( 16 );
append( dst, value );
return dst.toString();
}
-
+
+
public static String toString( int value )
{
StringBuffer dst = new StringBuffer( 8 );
append( dst, value );
return dst.toString();
}
-
+
+
public static int parseInt( String value )
{
return Integer.parseInt( value, 16 );
}
-
+
+
public static long parseLong( String value )
{
return Long.parseLong( value, 16 );
}
+
private OctetString()
{