|
2.9.2: 2009-01-08 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.basedb.clients.migrate.Manager
net.sf.basedb.clients.migrate.Transfer
abstract class Transfer
Extend this class when transferring data from base 1 to BASE 2.
Setup
connections between base 1 and BASE 2 and then run
start()
.
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 |
---|
protected Connection FROM
protected SessionControl TO
SessionControl sessionControl
protected Connection BASE2
protected int LIMIT
protected int selectOffset
private Map<Integer,Integer> idMap
initIdMap(int)
. The index
corresponds to a base 1 id and the value to a BASE 2 id.
protected List<WrappedItem<BasicItem>> itemList
protected boolean mapIds
mapItemList()
. Set to true by
initIdMap(int)
.
private boolean done
private boolean dependencyFailed
protected Properties properties
protected boolean QUICK_TRANSFER
protected boolean LOCAL_MYSQL_TRANSFER
private static final Logger log
ProgressThread progress
private static final long MB
Constructor Detail |
---|
Transfer()
Method Detail |
---|
abstract void start()
public void setup(Connection from, SessionControl to, SessionControl sessionControl, Connection base2, Properties properties)
from
- Connection
base 1 connectionto
- SessionControl
BASE 2 connectionsessionControl
- An extra SessionControl used to impersonate BASE 2
users when querying the database.base2
- A jdbc connection to BASE 2properties
- Properties from migrate.propertiesprotected void cleanUpMemory()
BasicItem createItem(DbControl b2c, ResultSet rs) throws BaseException, SQLException
run(PreparedStatement)
or
run(PreparedStatement, int, int)
should override this method.
b2c
- DbControl used to during creation.rs
- ResultSet from which we create an item.
BaseException
SQLException
void createItem(ResultSet rs) throws BaseException, SQLException
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.
rs
- ResultSet from which we create an item.
BaseException
SQLException
protected boolean isDone()
protected void done()
protected void dependencyFailure()
public boolean getDependencyStatus()
protected void startProgress(int items, String itemType)
protected void run(PreparedStatement ps, int from, int size)
startProgress(int, String)
before you call
this method
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.Manager.prepareStatementFromFile(String)
protected void run(PreparedStatement ps)
startProgress(int, String)
before you call this method
ps
- PreparedStatement
Manager.prepareStatementFromFile(String)
protected void runUnBatched(PreparedStatement ps, int from, int size)
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 ?,?'.
Manager.prepareStatementFromFile(String)
private void processItemList()
private void mapItemList()
protected void saveItem(DbControl dbc, BasicItem<?> item, int base1Id)
protected DbControl newDbControl()
protected void commit(DbControl dbc)
protected int getInt(String statementId)
protected void initIdMap(int size)
public Integer getBase2Id(int base1Id)
base1Id
- The Base 1 ID
public void mapId(int base1Id, int base2Id)
base1Id
- The old Base 1 IDbase2Id
- The new Base 2 IDpublic int getCount()
public Map<Integer,Integer> getIdMap()
Integer base2Id = map.get(base1Id);
protected String getProperty(String key)
protected int getBatchSize()
protected void writeRestorePointData(ObjectOutputStream out) throws IOException
IOException
protected void readRestorePointData(ObjectInputStream in) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
|
2.9.2: 2009-01-08 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |