de.folt.models.datamodel.sql
Class OpenTMSQLDataSource

java.lang.Object
  extended by de.folt.models.datamodel.BasicDataSource
      extended by de.folt.models.datamodel.sql.OpenTMSQLDataSource
All Implemented Interfaces:
DataSource, java.util.Observer

public class OpenTMSQLDataSource
extends BasicDataSource

This class represents a SQl data source. It is realized using Hibernate.

Author:
klemens

Nested Class Summary
 
Nested classes/interfaces inherited from class de.folt.models.datamodel.BasicDataSource
BasicDataSource.BasicDataSourceObserver
 
Constructor Summary
OpenTMSQLDataSource(DataSourceProperties dataModelProperties)
          The constructor created and associates a data sources for a given set of parameters.
 
Method Summary
 boolean addMonoLingualObject(MonoLingualObject monoLingualObject, boolean mergeObjects)
          addMultiLingualObject adds a MonoLingualObject to the given MultiLingualObject to the data source
 boolean addMultiLingualObject(MultiLingualObject multiLingualObject, boolean mergeObjects)
          addMultiLingualObject adds a MultiLingualObject to the data source
 void cleanDataSource()
          cleanDataSource method is used to allow some clean operations e.g. after an instance has been loaded.
 boolean clearDataSource()
          clearDataSource removes the content in a data source.
static boolean createDatabase(java.lang.String dbname, java.lang.String hibernateConfigFile)
          createDatabase creates a new SQL database
 boolean createDataSource(DataSourceProperties dataModelProperties)
          createDataSource creates a new Data source; this is esp. intended for creating a new database, e.g. in MySQL or Ms SQL Server.
static boolean deleteDatabase(java.lang.String dbname, java.lang.String hibernateConfigFile)
          deleteDatabase creates a new SQL database
 boolean deleteDataSource(DataSourceProperties dataModelProperties)
          deleteDataSource deletes an existing Data source; this is esp. intended for deleting a database, e.g. in MySQL or Ms SQL Server.
static int exportTmx(java.lang.String tmxFile, java.lang.String hibernateConfigFile)
          exportTmx
 int exportTmxFile(java.lang.String tmxFile)
          exportTmxFile exports the data source into an tmx file
static int exportToMOL(java.lang.String hibernateConfigFile)
          exportToMOL
 java.lang.String getDataSourceType()
          getDataSourceType get the type of the database
 MonoLingualPartitionedFuzzyNodeTree getFuzzyTree()
           
 int getLastErrorCode()
          getLastErrorCode Method returns the last error code for an operation done by the data source
 ObservableHashtable<java.lang.String,MultiLingualObject> getMultiLingualObjectCache()
          multiLingualObjectCache is a cache object which can be used by the data sources to store read MultiLingual Objects.
 int hashCode()
           
 int importTmxFile(java.lang.String tmxFile)
          importTmxFile import a TMX file into the data source
static int importTmxFile(java.lang.String tmxFile, java.lang.String hibernateConfigFile)
          importTmxFile
 int importXliffFile(java.lang.String xliffFile)
          importXliffFile imports an xliff file into the data source; it imports the approved source / target's of the trans-units
static int importXliffFile(java.lang.String tmxFile, java.lang.String hibernateConfigFile)
           
 boolean isBLoadAttributesLazy()
          This method determines if the attributes of MultiLingualObjects or MonoLingualObjects should be loaded at the time when the data source is created (false) or when they are actually needed (true).
static void main(java.lang.String[] args)
          main
 void removeDataSource()
          removeDataSource method called when the DataSource should be removed
 boolean removeMonoLingualObject(MonoLingualObject monoLingualObject)
          removeMonoLingualObject adds a MultiLingualObject to the data source
 boolean removeMultiLingualObject(MultiLingualObject multiLingualObject)
          removeMultiLingualObject adds a MultiLingualObject to the data source
 java.util.Vector<MonoLingualObject> search(MonoLingualObject searchMonoLingualObject)
          search search for a MonoLingualObject; if no language is given in the searchMonoLingualObject the search is done indepenent of the language
 void setBLoadAttributesLazy(boolean loadAttributesLazy)
          This method sets loading of the the attributes of MultiLingualObjects or MonoLingualObjects; false = they should be loaded at the time when the data source is created or true = when they are actually needed.
 void setDataSourceType()
          setDataSourceType sets the type of the data source
 void setFuzzyTree(MonoLingualPartitionedFuzzyNodeTree fuzzyTree)
           
 void setLastErrorCode(int lastErrorCode)
          setLastErrorCode sets the error code of the currently running method of the data source
 void setMultiLingualObjectCache(ObservableHashtable<java.lang.String,MultiLingualObject> multiLingualObjectCache)
          multiLingualObjectCache is a cache object which can be used by the data sources to store read MultiLingual Objects.
 java.lang.String toString()
           
 org.jdom.Element translate(org.jdom.Element transUnit, XmlDocument xliffDocument, java.lang.String sourceLanguage, java.lang.String targetLanguage, int matchSimilarity, java.util.Hashtable<java.lang.String,java.lang.String> translationParameters)
          translate translates a trans-unit given the source language, target Language and match similarity
static int translate(java.lang.String xliffFile, java.lang.String sourceLanguage, java.lang.String targetLanguage, java.lang.String similarity, java.lang.String hibernateConfigFile)
          translate translates an xliff file based on an SQL data source
 void update(java.util.Observable arg0, java.lang.Object arg1)
           
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OpenTMSQLDataSource

public OpenTMSQLDataSource(DataSourceProperties dataModelProperties)
The constructor created and associates a data sources for a given set of parameters. The parameters are supplied in the dataModelProperties. The following key- value pairs are supported: hibernateConfiguration - hibernate configuration file hibernate.hbm2ddl.auto - the mode how the database is started (create creates the baisc tables) any other hibernate paramters can be supplied if hibernateConfiguration is not specified. In this case the key classes de.folt.models.datamodel.sql.SQLMultiLingualObject, de.folt.models.datamodel.sql.SQLMonoLingualObject, de.folt.models.datamodel.sql.SQLTmxProp are added as addAnnotatedClass(es) annotationOnly - true ( false - if true no session is created (mainly used for creating new databases) with createDataSource

Parameters:
dataModelProperties - the properties of the model.
Method Detail

createDatabase

public static boolean createDatabase(java.lang.String dbname,
                                     java.lang.String hibernateConfigFile)
createDatabase creates a new SQL database

Parameters:
dbname - the database name
hibernateConfigFile - hibernate configuraion file for the new database
Returns:
true in case of success otherwise false

deleteDatabase

public static boolean deleteDatabase(java.lang.String dbname,
                                     java.lang.String hibernateConfigFile)
deleteDatabase creates a new SQL database

Parameters:
dbname - the database name
hibernateConfigFile - hibernate configuraion file for the new database
Returns:
true in case of success, otherwise false

exportTmx

public static int exportTmx(java.lang.String tmxFile,
                            java.lang.String hibernateConfigFile)
exportTmx

Parameters:
tmxFile -
hibernateConfigFile -
Returns:

exportToMOL

public static int exportToMOL(java.lang.String hibernateConfigFile)
exportToMOL

Parameters:
hibernateConfigFile -
Returns:

importTmxFile

public static int importTmxFile(java.lang.String tmxFile,
                                java.lang.String hibernateConfigFile)
importTmxFile

Parameters:
tmxFile -
hibernateConfigFile -
Returns:

importXliffFile

public static int importXliffFile(java.lang.String tmxFile,
                                  java.lang.String hibernateConfigFile)

main

public static void main(java.lang.String[] args)
main

Parameters:
args -

translate

public static int translate(java.lang.String xliffFile,
                            java.lang.String sourceLanguage,
                            java.lang.String targetLanguage,
                            java.lang.String similarity,
                            java.lang.String hibernateConfigFile)
translate translates an xliff file based on an SQL data source

Parameters:
xliffFile - the xliff file to translate
sourceLanguage - the source language to translate
targetLanguage - the target language to translate
similarity - the similarity to use (integer number)
hibernateConfigFile - the sql data source configuartion file
Returns:

addMonoLingualObject

public boolean addMonoLingualObject(MonoLingualObject monoLingualObject,
                                    boolean mergeObjects)
Description copied from interface: DataSource
addMultiLingualObject adds a MonoLingualObject to the given MultiLingualObject to the data source

Specified by:
addMonoLingualObject in interface DataSource
Overrides:
addMonoLingualObject in class BasicDataSource
Parameters:
monoLingualObject - the MOL object to add
mergeObjects - if true first a search is done if the containing MonoLingualObjects exist in the data source (based on the segment text); if they exist they are merged; if false the MUL is added as new entry
Returns:
true if added; false if the MultiLingualObject does not exist

addMultiLingualObject

public boolean addMultiLingualObject(MultiLingualObject multiLingualObject,
                                     boolean mergeObjects)
Description copied from interface: DataSource
addMultiLingualObject adds a MultiLingualObject to the data source

Specified by:
addMultiLingualObject in interface DataSource
Overrides:
addMultiLingualObject in class BasicDataSource
Parameters:
multiLingualObject - the object to add
mergeObjects - if true first a search is done if the containing MonoLingualObjects exist in the data source (based on the segment text); if they exist they are merged; if false the MUL is added as new entry
Returns:
true if added; false if not

cleanDataSource

public void cleanDataSource()
Description copied from interface: DataSource
cleanDataSource method is used to allow some clean operations e.g. after an instance has been loaded.
An example is disposing a tmx document after having read all the entries.

Specified by:
cleanDataSource in interface DataSource
Overrides:
cleanDataSource in class BasicDataSource

clearDataSource

public boolean clearDataSource()
                        throws OpenTMSException
Description copied from interface: DataSource
clearDataSource removes the content in a data source. In addition it can be used to delete a TMX data source.

Specified by:
clearDataSource in interface DataSource
Overrides:
clearDataSource in class BasicDataSource
Returns:
true if success
Throws:
OpenTMSException

createDataSource

public boolean createDataSource(DataSourceProperties dataModelProperties)
                         throws OpenTMSException
Description copied from interface: DataSource
createDataSource creates a new Data source; this is esp. intended for creating a new database, e.g. in MySQL or Ms SQL Server. In addition it can be used to create a new empty TMX data source.

Specified by:
createDataSource in interface DataSource
Overrides:
createDataSource in class BasicDataSource
Parameters:
dataModelProperties - the parameters of the data source
Returns:
true if success
Throws:
OpenTMSException

deleteDataSource

public boolean deleteDataSource(DataSourceProperties dataModelProperties)
                         throws OpenTMSException
Description copied from interface: DataSource
deleteDataSource deletes an existing Data source; this is esp. intended for deleting a database, e.g. in MySQL or Ms SQL Server. In addition it can be used to delete a TMX data source.

Specified by:
deleteDataSource in interface DataSource
Overrides:
deleteDataSource in class BasicDataSource
Parameters:
dataModelProperties - the parameters of the data source
Returns:
true if success
Throws:
OpenTMSException

exportTmxFile

public int exportTmxFile(java.lang.String tmxFile)
Description copied from interface: DataSource
exportTmxFile exports the data source into an tmx file

Specified by:
exportTmxFile in interface DataSource
Overrides:
exportTmxFile in class BasicDataSource
Parameters:
tmxFile - the tmx file to export to
Returns:
the number of entries exported

getDataSourceType

public java.lang.String getDataSourceType()
Description copied from interface: DataSource
getDataSourceType get the type of the database

Specified by:
getDataSourceType in interface DataSource
Overrides:
getDataSourceType in class BasicDataSource
Returns:
the data source type

getFuzzyTree

public MonoLingualPartitionedFuzzyNodeTree getFuzzyTree()
Returns:
the fuzzyTree

getLastErrorCode

public int getLastErrorCode()
Description copied from class: BasicDataSource
getLastErrorCode Method returns the last error code for an operation done by the data source

Specified by:
getLastErrorCode in interface DataSource
Overrides:
getLastErrorCode in class BasicDataSource
Returns:
an OpenTMS Error code describing the error which occurred for the last operation

getMultiLingualObjectCache

public ObservableHashtable<java.lang.String,MultiLingualObject> getMultiLingualObjectCache()
Description copied from class: BasicDataSource
multiLingualObjectCache is a cache object which can be used by the data sources to store read MultiLingual Objects. The key used is the unique id of the object.

Overrides:
getMultiLingualObjectCache in class BasicDataSource
Returns:
the multiLingualObjectCache

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

importTmxFile

public int importTmxFile(java.lang.String tmxFile)
importTmxFile import a TMX file into the data source

Specified by:
importTmxFile in interface DataSource
Overrides:
importTmxFile in class BasicDataSource
Parameters:
tmxFile - the tmx file to import
Returns:
number of entries read

importXliffFile

public int importXliffFile(java.lang.String xliffFile)
Description copied from interface: DataSource
importXliffFile imports an xliff file into the data source; it imports the approved source / target's of the trans-units

Specified by:
importXliffFile in interface DataSource
Overrides:
importXliffFile in class BasicDataSource
Parameters:
xliffFile - the xliff file to import
Returns:
the number of entries imported

isBLoadAttributesLazy

public boolean isBLoadAttributesLazy()
Description copied from interface: DataSource
This method determines if the attributes of MultiLingualObjects or MonoLingualObjects should be loaded at the time when the data source is created (false) or when they are actually needed (true).

Specified by:
isBLoadAttributesLazy in interface DataSource
Overrides:
isBLoadAttributesLazy in class BasicDataSource
Returns:
the bLoadAttributesLazy true if the should be loaded when need / false when they should be loaded at creation time of the data source.

removeDataSource

public void removeDataSource()
Description copied from interface: DataSource
removeDataSource method called when the DataSource should be removed

Specified by:
removeDataSource in interface DataSource
Overrides:
removeDataSource in class BasicDataSource

removeMonoLingualObject

public boolean removeMonoLingualObject(MonoLingualObject monoLingualObject)
Description copied from interface: DataSource
removeMonoLingualObject adds a MultiLingualObject to the data source

Specified by:
removeMonoLingualObject in interface DataSource
Overrides:
removeMonoLingualObject in class BasicDataSource
Parameters:
monoLingualObject - the object to remove
Returns:
true if removed; false if not

removeMultiLingualObject

public boolean removeMultiLingualObject(MultiLingualObject multiLingualObject)
Description copied from interface: DataSource
removeMultiLingualObject adds a MultiLingualObject to the data source

Specified by:
removeMultiLingualObject in interface DataSource
Overrides:
removeMultiLingualObject in class BasicDataSource
Parameters:
multiLingualObject - the object to remove
Returns:
true if removed; false if not

search

public java.util.Vector<MonoLingualObject> search(MonoLingualObject searchMonoLingualObject)
Description copied from interface: DataSource
search search for a MonoLingualObject; if no language is given in the searchMonoLingualObject the search is done indepenent of the language

Specified by:
search in interface DataSource
Overrides:
search in class BasicDataSource
Parameters:
searchMonoLingualObject - the MonoLingualObject to search for
Returns:
a vector of MOL which contain segment of the given monoLingualObject

setBLoadAttributesLazy

public void setBLoadAttributesLazy(boolean loadAttributesLazy)
Description copied from interface: DataSource
This method sets loading of the the attributes of MultiLingualObjects or MonoLingualObjects; false = they should be loaded at the time when the data source is created or true = when they are actually needed.

Specified by:
setBLoadAttributesLazy in interface DataSource
Overrides:
setBLoadAttributesLazy in class BasicDataSource
Parameters:
loadAttributesLazy - the bLoadAttributesLazy to set; false = load at creation time; true load at time when needed

setDataSourceType

public void setDataSourceType()
Description copied from interface: DataSource
setDataSourceType sets the type of the data source

Specified by:
setDataSourceType in interface DataSource
Overrides:
setDataSourceType in class BasicDataSource

setFuzzyTree

public void setFuzzyTree(MonoLingualPartitionedFuzzyNodeTree fuzzyTree)
Parameters:
fuzzyTree - the fuzzyTree to set

setLastErrorCode

public void setLastErrorCode(int lastErrorCode)
Description copied from interface: DataSource
setLastErrorCode sets the error code of the currently running method of the data source

Specified by:
setLastErrorCode in interface DataSource
Overrides:
setLastErrorCode in class BasicDataSource
Parameters:
lastErrorCode - the lastErrorCode to set

setMultiLingualObjectCache

public void setMultiLingualObjectCache(ObservableHashtable<java.lang.String,MultiLingualObject> multiLingualObjectCache)
Description copied from class: BasicDataSource
multiLingualObjectCache is a cache object which can be used by the data sources to store read MultiLingual Objects. The key used is the unique id of the object.

Overrides:
setMultiLingualObjectCache in class BasicDataSource
Parameters:
multiLingualObjectCache - the multiLingualObjectCache to set

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

translate

public org.jdom.Element translate(org.jdom.Element transUnit,
                                  XmlDocument xliffDocument,
                                  java.lang.String sourceLanguage,
                                  java.lang.String targetLanguage,
                                  int matchSimilarity,
                                  java.util.Hashtable<java.lang.String,java.lang.String> translationParameters)
                           throws OpenTMSException
Description copied from interface: DataSource
translate translates a trans-unit given the source language, target Language and match similarity

Specified by:
translate in interface DataSource
Overrides:
translate in class BasicDataSource
Parameters:
transUnit - the trans unit to translate to use
xliffDocument - the basic xliff document
sourceLanguage - the source language to use
targetLanguage - the target language to use
matchSimilarity - the similarity (fuzzy) match quality (0 - 100) to use
translationParameters - the hash table contains parameters which control some parameters, e.g. should header/source/target properties be written to alt-trans
Returns:
the modified trans-unit with new translatione
Throws:
OpenTMSException

update

public void update(java.util.Observable arg0,
                   java.lang.Object arg1)
Specified by:
update in interface java.util.Observer
Overrides:
update in class BasicDataSource