openlsd.appli.autoimport.commonimport
Class LSDCommonFunctions

java.lang.Object
  extended by openlsd.appli.autoimport.commonimport.LSDCommonFunctions
Direct Known Subclasses:
LSDCommonFunctionsExtOp

public class LSDCommonFunctions
extends java.lang.Object

Class for common functions in Import methods

Author:
Frederic Bregier LGPL

Field Summary
protected  java.io.File file
          File to import
protected  boolean isBatch
          Is import in Batch mode
static int nbblock
          Number of documents by block to import (20 is apparently optimal by testing); must be between 1 and 100
 
Constructor Summary
LSDCommonFunctions(java.util.concurrent.ConcurrentLinkedQueue<LSDExtQueueMember> queue, java.util.concurrent.ConcurrentLinkedQueue<LSDExtQueueMember> result, java.io.File file, boolean isBatch)
          Constructor from args
 
Method Summary
protected static void closefile(java.nio.channels.FileChannel filechannelIn)
          Close the filechannelIn
static boolean delDocument(LSDDbAdmin admin, LSDDbLegacy legacy, LSDExtDbDocument document)
          Del the document deleted when OK.
static LSDExtDbDocument getDocument(LSDDbAdmin admin, long lid, LSDBusiness lsdb)
          Get Document from args. lsdb object must contains unique index information.
static LSDExtDbDocument getNewStorageDocumentProcedureCommit(LSDDbAdmin admin, LSDDbLegacy legacy, long filesize, LSDBusiness lsdb, boolean sameLegacy, boolean isMove)
          Get New Storage for New Document.
static LSDExtDbDocument[] getNewStorageDocumentsProcedureCommit(LSDDbAdmin admin, LSDDbLegacy legacy, LSDExtQueueMembers members, boolean sameLegacy, boolean isMove)
          Get New Storage for a set of New Documents.
static boolean setNewStorageDocument(LSDDbAdmin admin, LSDDbLegacy legacy, LSDExtDbDocument document, LSDExtDbDocument documentnew, boolean inserted)
          Set New Storage for New Document if it was inserted, or Set Storage as its previous state and not Set Document
protected  void setOutput(LSDDbAdmin admin, LSDDbLegacy legacy, LSDExtDbDocument document, LSDExtQueueMember member, java.lang.String message, boolean status)
          Set output according to the status (True ok, False wrong)
 void setQueueb(java.util.concurrent.ConcurrentLinkedQueue<LSDExtQueueMember> queue)
          Constructor from args
static boolean testPreviousFile(LSDDbAdmin admin, LSDExtQueueMember member, LSDDbLegacy legacy, LSDExtDbDocument document)
          During import, Test if previous files are really differents or not and remove the DB ref if it is really the same.
 int tryImportOneFile(LSDDbAdmin admin, boolean isLocal, LSDExtQueueMember member, LSDDbLegacy legacy, java.nio.channels.FileChannel filechannelIn, LSDExtDbDocument document)
          Real Import of one file where all necessary info are already OK (directly from Block mode or from tryImportOneNewFile)
 LSDExtDbDocument tryImportOneNewFile(LSDDbAdmin admin, boolean isLocal, LSDExtQueueMember member, LSDDbLegacy legacy, java.nio.channels.FileChannel filechannelIn, long filesize)
          Import 1 file by the simple way (not a set of files) so requests necessary info for this new file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

protected java.io.File file
File to import


isBatch

protected boolean isBatch
Is import in Batch mode


nbblock

public static int nbblock
Number of documents by block to import (20 is apparently optimal by testing); must be between 1 and 100

Constructor Detail

LSDCommonFunctions

public LSDCommonFunctions(java.util.concurrent.ConcurrentLinkedQueue<LSDExtQueueMember> queue,
                          java.util.concurrent.ConcurrentLinkedQueue<LSDExtQueueMember> result,
                          java.io.File file,
                          boolean isBatch)
Constructor from args

Parameters:
queue -
result -
file -
isBatch -
Method Detail

setQueueb

public void setQueueb(java.util.concurrent.ConcurrentLinkedQueue<LSDExtQueueMember> queue)
Constructor from args

Parameters:
queue -

getDocument

public static LSDExtDbDocument getDocument(LSDDbAdmin admin,
                                           long lid,
                                           LSDBusiness lsdb)
Get Document from args. lsdb object must contains unique index information.

Parameters:
admin -
lid -
lsdb -
Returns:
The Document if found, else null

delDocument

public static boolean delDocument(LSDDbAdmin admin,
                                  LSDDbLegacy legacy,
                                  LSDExtDbDocument document)
Del the document deleted when OK. It updates also the associated Storage

Parameters:
admin -
legacy -
document -
Returns:
True if deleted, else False

getNewStorageDocumentProcedureCommit

public static LSDExtDbDocument getNewStorageDocumentProcedureCommit(LSDDbAdmin admin,
                                                                    LSDDbLegacy legacy,
                                                                    long filesize,
                                                                    LSDBusiness lsdb,
                                                                    boolean sameLegacy,
                                                                    boolean isMove)
Get New Storage for New Document. If it already exist, return false. This version uses a stored procedure: insertdoccommit. Commit is done once the storage is updated and document is inserted (must be updated manually after).

Parameters:
admin -
legacy -
filesize -
lsdb -
sameLegacy -
isMove -
Returns:
True if found, else False

getNewStorageDocumentsProcedureCommit

public static LSDExtDbDocument[] getNewStorageDocumentsProcedureCommit(LSDDbAdmin admin,
                                                                       LSDDbLegacy legacy,
                                                                       LSDExtQueueMembers members,
                                                                       boolean sameLegacy,
                                                                       boolean isMove)
Get New Storage for a set of New Documents. If they already exist, return null. This version uses a stored procedure: insertdocscommit. Commit is done once the storage is updated and all documents are inserted at all (must be updated manually after). (only LSDConstants.NBLINEOP members can be handle at a time due to a limitation of VARCHAR2 as out in PL/SQL procedures)

Parameters:
admin -
legacy -
members -
sameLegacy -
isMove -
Returns:
True if found, else False

setNewStorageDocument

public static boolean setNewStorageDocument(LSDDbAdmin admin,
                                            LSDDbLegacy legacy,
                                            LSDExtDbDocument document,
                                            LSDExtDbDocument documentnew,
                                            boolean inserted)
Set New Storage for New Document if it was inserted, or Set Storage as its previous state and not Set Document

Parameters:
admin -
legacy -
document - only in move (previous document)
documentnew - in import
inserted -
Returns:
True if the update is correctly done, else False

testPreviousFile

public static boolean testPreviousFile(LSDDbAdmin admin,
                                       LSDExtQueueMember member,
                                       LSDDbLegacy legacy,
                                       LSDExtDbDocument document)
During import, Test if previous files are really differents or not and remove the DB ref if it is really the same. If so, it try to remove the LSD file (which is in bad status). It does not remove any LSD File that has a valid entry in DB.

Parameters:
admin -
member -
legacy -
document -
Returns:
True if clean is done, else (if not all clean) false

closefile

protected static void closefile(java.nio.channels.FileChannel filechannelIn)
Close the filechannelIn

Parameters:
filechannelIn -

setOutput

protected void setOutput(LSDDbAdmin admin,
                         LSDDbLegacy legacy,
                         LSDExtDbDocument document,
                         LSDExtQueueMember member,
                         java.lang.String message,
                         boolean status)
Set output according to the status (True ok, False wrong)

Parameters:
admin -
legacy -
document -
member -
message -
status -

tryImportOneFile

public int tryImportOneFile(LSDDbAdmin admin,
                            boolean isLocal,
                            LSDExtQueueMember member,
                            LSDDbLegacy legacy,
                            java.nio.channels.FileChannel filechannelIn,
                            LSDExtDbDocument document)
                     throws LSDNoConnexionException,
                            LSDImportNoActionException,
                            LSDImportDbFileDelException,
                            LSDImportDbDelException
Real Import of one file where all necessary info are already OK (directly from Block mode or from tryImportOneNewFile)

Parameters:
admin -
isLocal -
member -
legacy -
filechannelIn -
document -
Returns:
KO : 0 = nothing to do,1=del file+db,2=db,3=MINA no connect or OK : -1
Throws:
LSDNoConnexionException - KO Mina no connect
LSDImportNoActionException - Ko but no Action to do
LSDImportDbFileDelException - KO need to delete Db and File
LSDImportDbDelException - KO need to delete Db

tryImportOneNewFile

public LSDExtDbDocument tryImportOneNewFile(LSDDbAdmin admin,
                                            boolean isLocal,
                                            LSDExtQueueMember member,
                                            LSDDbLegacy legacy,
                                            java.nio.channels.FileChannel filechannelIn,
                                            long filesize)
Import 1 file by the simple way (not a set of files) so requests necessary info for this new file.

Parameters:
admin -
isLocal -
member -
legacy -
filechannelIn -
filesize -
Returns:
The LSDExtDbDocument or Null if an error occurs