2.8.2: 2008-09-18

net.sf.basedb.clients.migrate
Class Transfer

java.lang.Object
  extended by net.sf.basedb.clients.migrate.Manager
      extended by net.sf.basedb.clients.migrate.Transfer
Direct Known Subclasses:
AnnotationTransfer, ArrayBlockTransfer, ArrayTypePlateTransfer, GroupTransfer, NewsTransfer, PlateEventTransfer, PlateEventTypeTransfer, ProtocolTypeTransfer, QuotaTransfer, RawBioAssayDataTransfer, ReporterTransfer, RoleTransfer, SampleTissueTransfer, SharedItemTransfer, UserTransfer, WellTransfer

abstract class Transfer
extends Manager

Extend this class when transferring data from base 1 to BASE 2. Setup connections between base 1 and BASE 2 and then run start().

Version:
2.0
Author:
Gregory
Last modified
$Date: 2008-09-05 17:15:54 +0200 (Fri, 05 Sep 2008) $

Field Summary
protected  Connection BASE2
          BASE 2 direct connection
private  boolean dependencyFailed
          Set to true if one or more dependencies have failed.
private  boolean done
          Set to true if this transfer is done
protected  Connection FROM
          BASE 1
private  Map<Integer,Integer> idMap
          Id map from base 1 to BASE 2 id's.
protected  List<WrappedItem<BasicItem>> itemList
           
protected  int LIMIT
          Limits the number of rows fetched from the database.
protected  boolean LOCAL_MYSQL_TRANSFER
           
private static Logger log
          The logger
protected  boolean mapIds
          If true base1 ids are mapped to base2 ids with mapItemList().
private static long MB
           
(package private)  ProgressThread progress
          The progress thread used for this transfer.
protected  Properties properties
           
protected  boolean QUICK_TRANSFER
           
protected  int selectOffset
          Current offset for data selection from the database
(package private)  SessionControl sessionControl
          BASE 2 connection, used for impersonating users
protected  SessionControl TO
          BASE 2
 
Constructor Summary
Transfer()
           
 
Method Summary
protected  void cleanUpMemory()
          Display free memory.
protected  void commit(DbControl dbc)
          Wrapper for the DbControl.commit().
(package private)  BasicItem createItem(DbControl b2c, ResultSet rs)
          Transfers using run(PreparedStatement) or run(PreparedStatement, int, int) should override this method.
(package private)  void createItem(ResultSet rs)
          Transfers using runUnBatched(PreparedStatement,int,int) must override this method.
protected  void dependencyFailure()
          Sets the dependencyFailed to true.
protected  void done()
          Changes this transfers state to done.
 Integer getBase2Id(int base1Id)
          Get the Base 2 ID when you know the Base 1 ID.
protected  int getBatchSize()
           
 int getCount()
          Get the number of mapped ID:s.
 boolean getDependencyStatus()
           
 Map<Integer,Integer> getIdMap()
          Get the map that contains mapping from Base 1 ID to Base 2 id.
protected  int getInt(String statementId)
          Returns an int of the first row and first column generated by the statementId sql query
protected  String getProperty(String key)
           
protected  void initIdMap(int size)
           
protected  boolean isDone()
          Returns true if this transfer is done.
 void mapId(int base1Id, int base2Id)
          Store the old and new ID of a transfered item
private  void mapItemList()
           
protected  DbControl newDbControl()
          Wrapper for creating a new DbControl.
private  void processItemList()
           
protected  void readRestorePointData(ObjectInputStream in)
          Store ID map and some boolean flags
protected  void run(PreparedStatement ps)
          Run over a SQL query defined by a prepared statement.
protected  void run(PreparedStatement ps, int from, int size)
          Recursive run over a SQL query defined by a prepared statement and LIMIT values from and size.
protected  void runUnBatched(PreparedStatement ps, int from, int size)
          For each row in the prepared statement createItem(ResultSet) is called.
protected  void saveItem(DbControl dbc, BasicItem<?> item, int base1Id)
           
 void setup(Connection from, SessionControl to, SessionControl sessionControl, Connection base2, Properties properties)
          Setup from and to points for this transfer.
(package private) abstract  void start()
          Starts the actual transfer.
protected  void startProgress(int items, String itemType)
          Creates a new progress if needed and starts it.
protected  void writeRestorePointData(ObjectOutputStream out)
          Store ID map and some boolean flags
 
Methods inherited from class net.sf.basedb.clients.migrate.Manager
getPreparedStatements, prepareStatementFromFile, print, printDate, setPreparedStatements, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FROM

protected Connection FROM
BASE 1


TO

protected SessionControl TO
BASE 2


sessionControl

SessionControl sessionControl
BASE 2 connection, used for impersonating users


BASE2

protected Connection BASE2
BASE 2 direct connection


LIMIT

protected int LIMIT
Limits the number of rows fetched from the database.


selectOffset

protected int selectOffset
Current offset for data selection from the database


idMap

private Map<Integer,Integer> idMap
Id map from base 1 to BASE 2 id's. Each transfer can map one set of id's. The id map is initiated with initIdMap(int). The index corresponds to a base 1 id and the value to a BASE 2 id.


itemList

protected List<WrappedItem<BasicItem>> itemList

mapIds

protected boolean mapIds
If true base1 ids are mapped to base2 ids with mapItemList(). Set to true by initIdMap(int).


done

private boolean done
Set to true if this transfer is done


dependencyFailed

private boolean dependencyFailed
Set to true if one or more dependencies have failed.


properties

protected Properties properties

QUICK_TRANSFER

protected boolean QUICK_TRANSFER

LOCAL_MYSQL_TRANSFER

protected boolean LOCAL_MYSQL_TRANSFER

log

private static final Logger log
The logger


progress

ProgressThread progress
The progress thread used for this transfer.


MB

private static final long MB
See Also:
Constant Field Values
Constructor Detail

Transfer

Transfer()
Method Detail

start

abstract void start()
Starts the actual transfer.


setup

public void setup(Connection from,
                  SessionControl to,
                  SessionControl sessionControl,
                  Connection base2,
                  Properties properties)
Setup from and to points for this transfer.

Parameters:
from - Connection base 1 connection
to - SessionControl BASE 2 connection
sessionControl - An extra SessionControl used to impersonate BASE 2 users when querying the database.
base2 - A jdbc connection to BASE 2
properties - Properties from migrate.properties

cleanUpMemory

protected void cleanUpMemory()
Display free memory.


createItem

BasicItem createItem(DbControl b2c,
                     ResultSet rs)
               throws BaseException,
                      SQLException
Transfers using run(PreparedStatement) or run(PreparedStatement, int, int) should override this method.

Parameters:
b2c - DbControl used to during creation.
rs - ResultSet from which we create an item.
Throws:
BaseException
SQLException

createItem

void createItem(ResultSet rs)
          throws BaseException,
                 SQLException
Transfers using runUnBatched(PreparedStatement,int,int) must override this method. For each item this method is responsible to create it's own DbControl and save the item to the database.

Parameters:
rs - ResultSet from which we create an item.
Throws:
BaseException
SQLException

isDone

protected boolean isDone()
Returns true if this transfer is done.


done

protected void done()
Changes this transfers state to done. If a progress is active it's also stopped.


dependencyFailure

protected void dependencyFailure()
Sets the dependencyFailed to true.


getDependencyStatus

public boolean getDependencyStatus()

startProgress

protected void startProgress(int items,
                             String itemType)
Creates a new progress if needed and starts it.


run

protected void run(PreparedStatement ps,
                   int from,
                   int size)
Recursive run over a SQL query defined by a prepared statement and LIMIT values from and size. If this method is called directly from a child transfer, remember to call startProgress(int, String) before you call this method

Parameters:
ps - PreparedStatement which includes a "LIMIT ?,?" at the end.
from - int indicating start position of the ResultSet.
size - int indicating number of rows to include.
See Also:
Manager.prepareStatementFromFile(String)

run

protected void run(PreparedStatement ps)
Run over a SQL query defined by a prepared statement. If this method is called directly from a child transfer, remember to call startProgress(int, String) before you call this method

Parameters:
ps - PreparedStatement
See Also:
Manager.prepareStatementFromFile(String)

runUnBatched

protected void runUnBatched(PreparedStatement ps,
                            int from,
                            int size)
For each row in the prepared statement createItem(ResultSet) is called. If the number of rows equals the size this method is recursivley called with runUnBatched(ps, from + size, size) until the number of rows is smaller than size. The prepared statement must include '.. LIMIT ?,?'.

See Also:
Manager.prepareStatementFromFile(String)

processItemList

private void processItemList()

mapItemList

private void mapItemList()

saveItem

protected void saveItem(DbControl dbc,
                        BasicItem<?> item,
                        int base1Id)

newDbControl

protected DbControl newDbControl()
Wrapper for creating a new DbControl.

Returns:
DbControl

commit

protected void commit(DbControl dbc)
Wrapper for the DbControl.commit().


getInt

protected int getInt(String statementId)
Returns an int of the first row and first column generated by the statementId sql query


initIdMap

protected void initIdMap(int size)

getBase2Id

public Integer getBase2Id(int base1Id)
Get the Base 2 ID when you know the Base 1 ID.

Parameters:
base1Id - The Base 1 ID
Returns:
The Base 2 ID or null if not found

mapId

public void mapId(int base1Id,
                  int base2Id)
Store the old and new ID of a transfered item

Parameters:
base1Id - The old Base 1 ID
base2Id - The new Base 2 ID

getCount

public int getCount()
Get the number of mapped ID:s. This should equal the number of migrated items.


getIdMap

public Map<Integer,Integer> getIdMap()
Get the map that contains mapping from Base 1 ID to Base 2 id.
Integer base2Id = map.get(base1Id);


getProperty

protected String getProperty(String key)

getBatchSize

protected int getBatchSize()

writeRestorePointData

protected void writeRestorePointData(ObjectOutputStream out)
                              throws IOException
Store ID map and some boolean flags

Throws:
IOException

readRestorePointData

protected void readRestorePointData(ObjectInputStream in)
                             throws IOException,
                                    ClassNotFoundException
Store ID map and some boolean flags

Throws:
IOException
ClassNotFoundException

2.8.2: 2008-09-18