diff --git a/src/java/org/thdl/lex/util/ConvertDataToNewMapping.java b/src/java/org/thdl/lex/util/ConvertDataToNewMapping.java new file mode 100644 index 0000000..05de170 --- /dev/null +++ b/src/java/org/thdl/lex/util/ConvertDataToNewMapping.java @@ -0,0 +1,92 @@ +package org.thdl.lex.util; + +import junit.framework.*; +import org.thdl.lex.*; +import org.thdl.lex.component.*; +import org.apache.commons.dbcp.BasicDataSourceFactory; +import java.util.*; +import javax.naming.InitialContext; +import javax.naming.Name; +import net.sf.hibernate.*; +import java.io.File; + +/** + * Description of the Class + * + * @author travis + * @created February 16, 2004 + */ +public class ConvertDataToNewMapping +{ + public static File file = null; + + public static void convertLexComponents() + { try + { + + if ( file.exists() ) + { + System.out.println( "Config File exists!" ); + } + else + { + System.out.println( "Config File DOES NOT exist!" ); + } + + HibernateSessionDataTransfer.setConfig( file ); + HibernateSessionDataTransfer.setConfigResource( args[0] ); + + Iterator it; + ILexComponent lc; + + LexComponentRepository.beginTransaction(); + + String queryString = " FROM org.thdl.lex.component.LexComponent comp where metaId"; + Query query = LexComponentRepository.getSession().createQuery( queryString ); + it = query.iterate(); + while ( it.hasNext() ) + { + lc = (ILexComponent) it.next(); + + System.out.println( "Saving: " + lc.toString() ); + + try + { + LexComponentRepositoryDataTransfer.beginTransaction(); + LexComponentRepositoryDataTransfer.getSession().save( lc ); + LexComponentRepositoryDataTransfer.endTransaction( true ); + LexComponentRepositoryDataTransfer.getSession().evict( lc ); + LexComponentRepository.getSession().evict( lc ); + } + catch ( HibernateException he ) + { + LexComponentRepositoryDataTransfer.endTransaction( false ); + throw he; + } + + } + + LexComponentRepository.endTransaction( false ); + + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + + + /** + * The main program for the ConvertDataToNewMapping class + * + * @param args The command line arguments + */ + public static void main( String[] args ) + { + file = new java.io.File( args[0] ); + //ConvertDataToNewMapping.convertLexComponents(); + //ConvertDataToNewMapping.convertTerms(); + ConvertDataToNewMapping.writeCredits(); + } +} + diff --git a/src/java/org/thdl/lex/util/DictionaryImporter.java b/src/java/org/thdl/lex/util/DictionaryImporter.java index a5fe347..f843274 100644 --- a/src/java/org/thdl/lex/util/DictionaryImporter.java +++ b/src/java/org/thdl/lex/util/DictionaryImporter.java @@ -10,6 +10,13 @@ import java.sql.*; public class DictionaryImporter { + private static final String INSERT_META = "INSERT INTO meta (createdby, modifiedby, createdbyprojsub, modifiedbyprojsub, createdon," + + "modifiedon, source, language, dialect, script, note) VALUES ( ?, ? , ?, ?, NOW(), NOW(), 0, 0, 0, 1, ?)"; + private static final String SELECT_META = "SELECT metaid FROM terms WHERE term = ?"; + private static final String INSERT_TERM = "INSERT INTO terms (metaid, term) VALUES (?,?)"; + private static final String UPDATE_TRANS = "UPDATE transitionaldata SET transitionaldatatext = ? WHERE metaid = ?"; + private static final String INSERT_TRANS = "INSERT INTO transitionaldata (metaid, parentid, precedence, transitionaldatalabel, forpublicconsumption, " + +"transitionaldatatext) VALUES (?, ?, ?, ?, ?, ? )"; private static PrintWriter out; private static BufferedReader in; private static String delimiter; @@ -21,7 +28,12 @@ public class DictionaryImporter private static Integer label; private static Statement sqlStatement; private static Connection conn; - + private static PreparedStatement insertMetaStmt; + private static PreparedStatement selectMetaStmt; + private static PreparedStatement insertTermStmt; + private static PreparedStatement updateTransStmt; + private static PreparedStatement insertTransStmt; + public final static int delimiterGeneric=0; public final static int delimiterAcip=1; public final static int delimiterDash=2; @@ -93,8 +105,15 @@ public class DictionaryImporter Boolean result; ResultSet set; int metaID, metaIDTrans, prec; - String currentDef, insertMeta = "INSERT INTO meta (createdby, modifiedby, createdbyprojsub, modifiedbyprojsub, createdon, modifiedon, source, language, dialect, script, note) VALUES (" + creator.toString() + ", " + creator.toString() + ", " + proj.toString() + ", " + proj.toString() + ", NOW(), NOW(), 0, 0, 0, 1, \"" + note + "\")"; + String currentDef; + insertMetaStmt.setString( 1, creator.toString() ); + insertMetaStmt.setString( 2, creator.toString() ); + insertMetaStmt.setString( 3, proj.toString() ); + insertMetaStmt.setString( 4, proj.toString() ); + insertMetaStmt.setString( 5, note ); + + definition = Manipulate.replace(definition, "\\", "@@@@"); definition = Manipulate.replace(definition, "@@@@", "\\\\"); @@ -105,18 +124,21 @@ public class DictionaryImporter // System.out.println(term); // Check to see if term is already there - sqlStatement.execute("SELECT metaid FROM terms WHERE term = \"" + term + "\""); - set = sqlStatement.getResultSet(); + selectMetaStmt.setString( 1 , term ); + set = selectMetaStmt.getResultSet(); // if it is get its metaID, else add it if (!set.first()) { - sqlStatement.execute(insertMeta); + insertMetaStmt.execute(); sqlStatement.execute("SELECT MAX(metaid) FROM META"); set = sqlStatement.getResultSet(); set.first(); metaID = set.getInt(1); - sqlStatement.execute("INSERT INTO terms (metaid, term) VALUES (" + metaID + ", \"" + term + "\")"); + + insertTermStmt.setInt( 1, metaID ); + insertTermStmt.setString(2, term ); + insertTermStmt.execute(); } else metaID = set.getInt(1); @@ -139,7 +161,9 @@ public class DictionaryImporter { if (!currentDef.equals("")) definition = currentDef + ". " + definition; metaIDTrans = set.getInt(2); - sqlStatement.execute("UPDATE transitionaldata SET transitionaldatatext = \"" + definition + "\" WHERE metaid = " + metaIDTrans); + updateTransStmt.setString( 1, currentDef ); + updateTransStmt.setInt( 1, metaIDTrans ); + updateTransStmt.execute(); } } else @@ -153,7 +177,14 @@ public class DictionaryImporter set = sqlStatement.getResultSet(); if (set.first()) prec = set.getInt(1)+1; else prec = 0; - sqlStatement.execute("INSERT INTO transitionaldata (metaid, parentid, precedence, transitionaldatalabel, forpublicconsumption, transitionaldatatext) VALUES ("+ metaIDTrans +", " + metaID +", " + prec + ", " + label + ", \"" + publicCons + "\", \"" + definition + "\")"); + + insertTransStmt.setInt( 1, metaIDTrans ); + insertTransStmt.setInt( 2, metaID ); + insertTransStmt.setInt( 3, prec ); + insertTransStmt.setInt( 4, label ); + insertTransStmt.setInt( 5, publicCons ); + insertTransStmt.setString( 6, definition ); + insertTransStmt.execute(); } } @@ -292,16 +323,12 @@ public class DictionaryImporter } /** Used only if the database is being accessed manually instead of through Hibernate */ - private static Statement getStatement() + private static void initConnections() { ResourceBundle rb = ResourceBundle.getBundle("dictionary-importer"); - Statement s = null; // Loading driver try { - // The newInstance() call is a work around for some - // broken Java implementations - Class.forName(rb.getString("dictionaryimporter.driverclassname")).newInstance(); } catch (Exception ex) { System.out.println("Mysql driver couldn't be loaded!"); @@ -311,19 +338,35 @@ public class DictionaryImporter // Connecting to database try { conn = DriverManager.getConnection(rb.getString("dictionaryimporter.url")); - s = conn.createStatement(); - - // Do something with the Connection - + conn2 = DriverManager.getConnection(rb.getString("dictionaryimporter.url")); + conn3 = DriverManager.getConnection(rb.getString("dictionaryimporter.url")); + conn4 = DriverManager.getConnection(rb.getString("dictionaryimporter.url")); + conn5 = DriverManager.getConnection(rb.getString("dictionaryimporter.url")); } catch (Exception ex) { // handle any errors System.out.println("Could not connect to database!"); + ex.printStackTrace(); System.exit(0); } - - return s; } + private static void initStatements() + { + try { + sqlStatement = conn.createStatement(); + insertMetaStmt = conn.prepareStatement( INSERT_META ); + selectMetaStmt = conn.prepareStatement( SELECT_META ); + insertTermStmt = conn.prepareStatement( INSERT_TERM ); + updateTransStmt = conn.prepareStatement( UPDATE_TRANS ); + insertTransStmt = conn.prepareStatement( INSERT_TRANS ); + } catch (Exception ex) { + // handle any errors + System.out.println("Could not create statement!"); + ex.printStackTrace(); + System.exit(0); + } + } + public DictionaryImporter() { } @@ -363,7 +406,8 @@ public class DictionaryImporter currentArg++; if (option.equals("manual")) { - sqlStatement = getStatement(); + initConnections(); + initStatements(); } else if (option.equals("format")) { if (argNum<=currentArg) diff --git a/src/java/org/thdl/lex/util/HibernateSessionDataTransfer.java b/src/java/org/thdl/lex/util/HibernateSessionDataTransfer.java new file mode 100644 index 0000000..aac05b5 --- /dev/null +++ b/src/java/org/thdl/lex/util/HibernateSessionDataTransfer.java @@ -0,0 +1,107 @@ +package org.thdl.lex.util; + +import net.sf.hibernate.*; +import net.sf.hibernate.cfg.*; +import java.io.File; + +/** + * Description of the Class + * + * @author Hibernate WIKI + * @created October 1, 2003 + */ +public class HibernateSessionTEMP +{ + + private static SessionFactory sessionFactory; + /** + * Description of the Field + */ + public final static ThreadLocal session = new ThreadLocal(); + + /** + * Description of the Field + */ + public static File config; + public static String configResource; +public static void setConfigResource(String configResource) { + HibernateSessionTEMP.configResource = configResource; +} +public static String getConfigResource() { + return configResource; +} + + + /** + * Sets the config attribute of the HibernateSessionTEMP object + * + * @param config The new config value + */ + public static void setConfig( File config ) + { + HibernateSessionTEMP.config = config; + } + + + /** + * Gets the config attribute of the HibernateSessionTEMP object + * + * @return The config value + */ + public static File getConfig() + { + return config; + } + + + /** + * Description of the Method + * + * @return Description of the Returned Value + * @exception HibernateException Description of Exception + * @since + */ + public static Session currentSession() + throws HibernateException + { + + Session s = (Session) session.get(); + if ( s == null ) + { + + // Don't get from JNDI, use a static SessionFactory + if ( sessionFactory == null ) + { + + // Use default hibernate.cfg.xml + sessionFactory = new Configuration().configure( getConfig() ).buildSessionFactory(); + + } + + s = sessionFactory.openSession(); + session.set( s ); + } + return s; + } + + + /** + * Description of the Method + * + * @exception HibernateException Description of Exception + * @since + */ + public static void closeSession() + throws HibernateException + { + + Session s = (Session) session.get(); + session.set( null ); + if ( s != null ) + { + s.close(); + } + } + +} + diff --git a/src/java/org/thdl/lex/util/HibernateTransactionDataTransfer.java b/src/java/org/thdl/lex/util/HibernateTransactionDataTransfer.java new file mode 100644 index 0000000..2c0fd42 --- /dev/null +++ b/src/java/org/thdl/lex/util/HibernateTransactionDataTransfer.java @@ -0,0 +1,65 @@ +package org.thdl.lex.util; + +import net.sf.hibernate.*; +import net.sf.hibernate.cfg.*; + + +/** + * Description of the Class + * + * @author Hibernate WIKI + * @created October 1, 2003 + */ +public class HibernateTransactionTEMP +{ + + /** + * Description of the Field + */ + public final static ThreadLocal transaction = new ThreadLocal(); + + + /** + * Description of the Method + * + * @exception HibernateException Description of Exception + * @since + */ + public static void beginTransaction() throws HibernateException + { + + Transaction t = (Transaction) transaction.get(); + if ( t == null ) + { + t = HibernateSessionTEMP.currentSession().beginTransaction(); + transaction.set( t ); + } + } + + + /** + * Description of the Method + * + * @param commit Description of the Parameter + * @exception HibernateException Description of Exception + * @since + */ + public static void endTransaction( boolean commit ) throws HibernateException + { + Transaction t = (Transaction) transaction.get(); + transaction.set( null ); + if ( t != null ) + { + if ( commit ) + { + t.commit(); + } + else + { + t.rollback(); + } + } + } + +} + diff --git a/src/java/org/thdl/lex/util/LexComponentDataTransfer.hbm.xml b/src/java/org/thdl/lex/util/LexComponentDataTransfer.hbm.xml new file mode 100644 index 0000000..4e7e620 --- /dev/null +++ b/src/java/org/thdl/lex/util/LexComponentDataTransfer.hbm.xml @@ -0,0 +1,471 @@ + + + + + + + + org.thdl.lex.component.BaseLexComponent + + + + + + + + + + + + + + + + + + + org.thdl.lex.component.BaseMeta + + + + + + + + + + + + + + + org.thdl.lex.component.BaseAnalyticalNote + + + + + + + + + + + + + org.thdl.lex.component.BaseTerm + org.thdl.lex.component.LexComponentNode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.thdl.lex.component.BaseDefinition + org.thdl.lex.component.Translatable, org.thdl.lex.component.LexComponentNode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.thdl.lex.component.BaseSubdefinition + org.thdl.lex.component.Translatable, org.thdl.lex.component.LexComponentNode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.thdl.lex.component.BasePronunciation + + + + + + + + + + + + + + org.thdl.lex.component.BaseEtymology + org.thdl.lex.component.Translatable + + + + + + + + + + + + + + + + + + + + + + org.thdl.lex.component.BaseSpelling + + + + + + + + + + + + + + org.thdl.lex.component.BaseGrammaticalFunction + + + + + + + + + + + + + org.thdl.lex.component.BaseEncyclopediaArticle + + + + + + + + + + + + + + org.thdl.lex.component.BaseGloss + + + + + + + + + + + + + + org.thdl.lex.component.BaseKeyword + + + + + + + + + + + + + org.thdl.lex.component.BaseModelSentence + org.thdl.lex.component.Translatable + + + + + + + + + + + + + + + + + + + org.thdl.lex.component.BaseTranslationEquivalent + + + + + + + + + + + + + org.thdl.lex.component.BaseRelatedTerm + + + + + + + + + + + + + + org.thdl.lex.component.BasePassage + org.thdl.lex.component.Translatable + + + + + + + + + + + + + + + + + + + + + + org.thdl.lex.component.BaseSpeechRegister + + + + + + + + + + + + + org.thdl.lex.component.BaseTransitionalData + + + + + + + + + + + + + + + + + diff --git a/src/java/org/thdl/lex/util/LexComponentRepositoryDataTransfer.java b/src/java/org/thdl/lex/util/LexComponentRepositoryDataTransfer.java new file mode 100644 index 0000000..61a0f0c --- /dev/null +++ b/src/java/org/thdl/lex/util/LexComponentRepositoryDataTransfer.java @@ -0,0 +1,898 @@ +package org.thdl.lex; +import java.sql.*; +import java.util.*; + +import net.sf.hibernate.*; +import org.apache.log4j.*; + +import org.thdl.lex.component.*; + + + +/** + * Description of the Class + * + * @author travis + * @created October 1, 2003 + */ +public class LexComponentRepositoryTEMP +{ + + /** + * Description of the Field + */ + public final static String EXACT = "exact"; + /** + * Description of the Field + */ + public final static String STARTS_WITH = "startsWith"; + /** + * Description of the Field + */ + public final static String ANYWHERE = "anywhere"; + private static long start; + + private static long lastUpdate = now(); + + + /** + * Sets the lastUpdate attribute of the LexComponentRepository class + * + * @param last The new lastUpdate value + */ + public static void setLastUpdate( long last ) + { + lastUpdate = last; + } + + + /** + * Gets the lastUpdate attribute of the LexComponentRepository class + * + * @return The lastUpdate value + */ + public static long getLastUpdate() + { + return lastUpdate; + } + + + + /** + * Sets the start attribute of the LexComponentRepository object + * + * @param startTime The new start value + * @since + */ + private static void setStart( long startTime ) + { + Logger logger = Logger.getLogger( "org.thdl.lex" ); + logger.debug( "Query start time: " + new java.util.Date( startTime ) ); + start = startTime; + } + + + + /** + * Gets the start attribute of the LexComponentRepository object + * + * @return The start value + * @since + */ + private static long getStart() + { + return start; + } + + + /** + * Gets the duration attribute of the LexComponentRepository class + * + * @return The duration value + */ + private static long getDuration() + { + long duration = now() - getStart(); + + Logger logger = Logger.getLogger( "org.thdl.lex" ); + logger.debug( "Query finish: " + new java.util.Date( now() ) ); + logger.debug( "Query duration in ms: " + duration ); + logger.info( "Query duration: " + duration / 1000 + " seconds." ); + return duration; + } + + + /** + * Gets the session attribute of the LexComponentRepository class + * + * @return The session value + * @exception HibernateException Description of Exception + * @since + */ + protected static Session getSession() throws HibernateException + { + Session session = HibernateSessionTEMP.currentSession(); + if ( !session.isConnected() ) + { +//session.reconnect(); + } + return session; + } + + + /** + * Description of the Method + * + * @exception LexRepositoryException Description of the Exception + */ + protected static void beginTransaction() throws LexRepositoryException + { + try + { + HibernateTransactionTEMP.beginTransaction(); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + + } + + + /** + * Description of the Method + * + * @param commit Description of Parameter + * @exception LexRepositoryException Description of the Exception + * @since + */ + protected static void endTransaction( boolean commit ) throws LexRepositoryException + { + try + { + HibernateTransactionTEMP.endTransaction( commit ); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + } + + + /** + * Description of the Method + * + * @return Description of the Returned Value + * @since + */ + private static long now() + { + return System.currentTimeMillis(); + } + + + /** + * Description of the Method + * + * @param comp Description of Parameter + * @return Description of the Returned Value + * @exception LexRepositoryException Description of Exception + * @since + */ + private static ITerm assertTerm( ILexComponent comp ) throws LexRepositoryException + { + ITerm term = null; + try + { + term = (ITerm) comp; + } + catch ( Exception e ) + { + throw new LexRepositoryException( "Query Component was not a term." ); + } + return term; + } + + + /** + * Queries the database for Terms that start with the string in the term + * property of the queryComponent. Sets entry property the first hit returned. + * + * @param lexQuery Description of Parameter + * @exception LexRepositoryException Description of Exception + * @since + */ + public static void findTermsByTerm( LexQuery lexQuery ) throws LexRepositoryException + { + setStart( now() ); + beginTransaction(); + ITerm term = assertTerm( lexQuery.getQueryComponent() ); + if ( null == term.getTerm() ) + { + throw new LexRepositoryException( "Query Component term was null." ); + } + + Query query = null; + Iterator it = null; + + String termForQuery = LexUtilities.hqlEscape( term.getTerm() ); + LexLogger.debug( "Escaped term string: " + termForQuery ); + + if ( lexQuery.getFindMode().equals( LexComponentRepository.STARTS_WITH ) ) + { + termForQuery = termForQuery + "%"; + } + else if ( lexQuery.getFindMode().equals( LexComponentRepository.ANYWHERE ) ) + { + termForQuery = "%" + termForQuery + "%"; + } + + String queryString = " FROM org.thdl.lex.component.ITerm as term WHERE term like :term AND term.deleted=0 ORDER BY term"; + try + { + query = getSession().createQuery( queryString ); + query.setString( "term", termForQuery ); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + + try + { + it = query.iterate(); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + + if ( it.hasNext() ) + { + term = (ITerm) it.next(); + lexQuery.setEntry( term ); + lexQuery.getResults().clear(); + lexQuery.getResults().put( term.getMetaId(), term.getTerm() ); + } + else + { + lexQuery.setEntry( null ); + lexQuery.getResults().clear(); + } + while ( it.hasNext() ) + { + term = (ITerm) it.next(); + lexQuery.getResults().put( term.getMetaId(), term.getTerm() ); + } + endTransaction( false ); + lexQuery.setDuration( getDuration() ); + } + + + /** + * Description of the Method + * + * @param pk Description of the Parameter + * @return Description of the Return Value + * @exception LexRepositoryException Description of the Exception + */ + public static ITerm findTermByPk( Integer pk ) throws LexRepositoryException + { + ITerm term = null; + + beginTransaction(); + String queryString = " FROM org.thdl.lex.component.ITerm as term WHERE term.metaId = " + pk.toString(); + try + { + Query query = getSession().createQuery( queryString ); + term = (ITerm) query.uniqueResult(); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + endTransaction( false ); + return term; + } + + + /** + * Description of the Method + * + * @param lexQuery Description of the Parameter + * @return Description of the Return Value + * @exception LexRepositoryException Description of the Exception + */ + public static Map findTermsByMeta( LexQuery lexQuery ) throws LexRepositoryException + { + Logger logger = Logger.getLogger( "org.thdl.lex" ); + ITerm term = assertTerm( lexQuery.getQueryComponent() ); + Map terms = new HashMap(); + ILexComponent comp = null; + ITerm aTerm; + Query query = null; + Iterator it = null; + + setStart( now() ); + beginTransaction(); + if ( null == term.getMeta() ) + { + throw new LexRepositoryException( "Query Component term.meta was null." ); + } + + if ( logger.isDebugEnabled() ) + { + logger.debug( "Tibetan Dictionary begin query!" ); + } + String queryString = "select term from org.thdl.lex.component.Term as term " + //join term collections + + " join term.pronunciations as pron " + + " join term.etymologies as ety " + + " join term.spellings as sp " + + " join term.functions as func " + + " join term.encyclopediaArticles as ency " + + " join term.transitionalData as transData " + + " join term.definitions as def " + + " join term.glosses as glo " + + " join term.keywords as key " + + " join term.translationEquivalents as trans " + + " join term.relatedTerms as rel " + + " join term.passages as pass " + + " join term.registers as reg " + //join def collections + + " join def.subdefinitions as sub " + + " join def.glosses as gloDef " + + " join def.keywords as keyDef " + + " join def.modelSentences as modDef " + + " join def.translationEquivalents as transDef " + + " join def.relatedTerms as relDef " + + " join def.passages as passDef " + + " join def.registers as regDef " + //join subdef collections + + " join sub.glosses as gloSub " + + " join sub.keywords as keySub " + + " join sub.modelSentences as modSub " + + " join sub.translationEquivalents as transSub " + + " join sub.relatedTerms as relSub " + + " join sub.passages as passSub " + + " join sub.registers as regSub " + // join translation collections +/* + " join ety.translations as etyTrans " + + " join term.definitions.translations as defTrans " + + " join term.modelSentences.translations as modTrans " + + " join term.passages.translations as passTrans " + + " join def.subdefinition.translations as subTrans " + + " join def.modelSentences.translations as modDefTrans " + + " join def.passages.translations as passDefTrans " + + " join sub.modelSentences.translations as modSubTrans " + + " join sub.passages.translations as passSubTrans " */ + //restrict by projectSubject in createdByProjSub + + " where term.meta.createdByProjSub = :projSub" + + " or pron.meta.createdByProjSub = :projSub" + + " or ety.meta.createdByProjSub = :projSub" + + " or sp.meta.createdByProjSub = :projSub" + + " or func.meta.createdByProjSub = :projSub" + + " or ency.meta.createdByProjSub = :projSub" + + " or transData.meta.createdByProjSub = :projSub" + + " or def.meta.createdByProjSub = :projSub" + + " or glo.meta.createdByProjSub = :projSub" + + " or key.meta.createdByProjSub = :projSub" + + " or trans.meta.createdByProjSub = :projSub" + + " or rel.meta.createdByProjSub = :projSub" + + " or pass.meta.createdByProjSub = :projSub" + + " or reg.meta.createdByProjSub = :projSub" + + " or subDef.meta.createdByProjSub = :projSub" + + " or gloDef.meta.createdByProjSub = :projSub" + + " or keyDef.meta.createdByProjSub = :projSub" + + " or modDef.meta.createdByProjSub = :projSub" + + " or transDef.meta.createdByProjSub = :projSub" + + " or relDef.meta.createdByProjSub = :projSub" + + " or passDef.meta.createdByProjSub = :projSub" + + " or regDef.meta.createdByProjSub = :projSub" + + " or gloSub.meta.createdByProjSub = :projSub" + + " or keySub.meta.createdByProjSub = :projSub" + + " or modSub.meta.createdByProjSub = :projSub" + + " or transSub.meta.createdByProjSub = :projSub" + + " or relSub.meta.createdByProjSub = :projSub" + + " or passSub.meta.createdByProjSub = :projSub" + + " or regSub.meta.createdByProjSub = :projSub" + + " or etyTrans.meta.createdByProjSub = :projSub" + + " or defTrans.meta.createdByProjSub = :projSub" + + " or modTrans.meta.createdByProjSub = :projSub" + + " or passTrans.meta.createdByProjSub = :projSub" + + " or subTrans.meta.createdByProjSub = :projSub" + + " or modDefTrans.meta.createdByProjSub = :projSub" + + " or passDefTrans.meta.createdByProjSub = :projSub" + + " or modSubTrans.meta.createdByProjSub = :projSub" + + " or passSubTrans.meta.createdByProjSub = :projSub" + //restrict by projectSubject in modifiedByProjSub + + " or term.meta.modifiedByProjSub = :projSub" + + " or pron.meta.modifiedByProjSub = :projSub" + + " or ety.meta.modifiedByProjSub = :projSub" + + " or sp.meta.modifiedByProjSub = :projSub" + + " or func.meta.modifiedByProjSub = :projSub" + + " or ency.meta.modifiedByProjSub = :projSub" + + " or trans.meta.modifiedByProjSub = :projSub" + + " or def.meta.modifiedByProjSub = :projSub" + + " or glo.meta.modifiedByProjSub = :projSub" + + " or key.meta.modifiedByProjSub = :projSub" + + " or trans.meta.modifiedByProjSub = :projSub" + + " or rel.meta.modifiedByProjSub = :projSub" + + " or pass.meta.modifiedByProjSub = :projSub" + + " or reg.meta.modifiedByProjSub = :projSub" + + " or subDef.meta.modifiedByProjSub = :projSub" + + " or gloDef.meta.modifiedByProjSub = :projSub" + + " or keyDef.meta.modifiedByProjSub = :projSub" + + " or modDef.meta.modifiedByProjSub = :projSub" + + " or transDef.meta.modifiedByProjSub = :projSub" + + " or relDef.meta.modifiedByProjSub = :projSub" + + " or passDef.meta.modifiedByProjSub = :projSub" + + " or regDef.meta.modifiedByProjSub = :projSub" + + " or gloSub.meta.modifiedByProjSub = :projSub" + + " or keySub.meta.modifiedByProjSub = :projSub" + + " or modSub.meta.modifiedByProjSub = :projSub" + + " or transSub.meta.modifiedByProjSub = :projSub" + + " or relSub.meta.modifiedByProjSub = :projSub" + + " or passSub.meta.modifiedByProjSub = :projSub" +/* + " or regSub.meta.modifiedByProjSub = :projSub" + + " or etyTrans.meta.modifiedByProjSub = :projSub" + + " or defTrans.meta.modifiedByProjSub = :projSub" + + " or modTrans.meta.modifiedByProjSub = :projSub" + + " or passTrans.meta.modifiedByProjSub = :projSub" + + " or subTrans.meta.modifiedByProjSub = :projSub" + + " or modDefTrans.meta.modifiedByProjSub = :projSub" + + " or passDefTrans.meta.modifiedByProjSub = :projSub" + + " or modSubTrans.meta.modifiedByProjSub = :projSub" + + " or passSubTrans.meta.modifiedByProjSub = :projSub";*/ + + +""; + try + { + query = getSession().createQuery( queryString ); + //query.setMaxResults( 100 ); + query.setInteger( "projSub", lexQuery.getQueryComponent().getMeta().getCreatedByProjSub().intValue() ); + logger.debug( "About to list query" ); + List list = query.list(); + logger.debug( "results size: " + list.size() ); + it = list.iterator(); + logger.debug( "Starting to add terms to map" ); + while ( it.hasNext() ) + { + aTerm = (ITerm) comp; + logger.debug( "successfully cast comp to an ITerm" ); + terms.put( aTerm.getMetaId(), aTerm.getTerm() ); + } + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + endTransaction( false ); + lexQuery.setDuration( getDuration() ); + return terms; + } + public static Map findTermsByMetaViaLc( LexQuery lexQuery ) throws LexRepositoryException + { + Logger logger = Logger.getLogger( "org.thdl.lex" ); + ITerm term = assertTerm( lexQuery.getQueryComponent() ); + Map terms = new HashMap(); + ILexComponent comp = null; + ITerm aTerm; + Query query = null; + Iterator it = null; + + setStart( now() ); + beginTransaction(); + if ( null == term.getMeta() ) + { + throw new LexRepositoryException( "Query Component term.meta was null." ); + } + + if ( logger.isDebugEnabled() ) + { + logger.debug( "Tibetan Dictionary begin query!" ); + } + String queryString = "from org.thdl.lex.component.LexComponent as comp where comp.meta.createdByProjSub=:projSub"; + + try + { + query = getSession().createQuery( queryString ); + //query.setMaxResults( 100 ); + query.setInteger( "projSub", lexQuery.getQueryComponent().getMeta().getCreatedByProjSub().intValue() ); + logger.debug( "About to list query" ); + List list = query.list(); + logger.debug( "results size: " + list.size() ); + it = list.iterator(); + while ( it.hasNext() ) + { + logger.debug( "Starting quest for a term parent" ); + + comp = (ILexComponent) it.next(); + int safetyFirst = 0; + while ( !( comp instanceof ITerm ) && comp != null ) + { + logger.debug( "comp class: " + comp.getClass().getName() ); + comp = comp.getParent(); + if ( comp instanceof ITerm ) + { + try + { + aTerm = (ITerm) comp; + terms.put( aTerm.getMetaId(), aTerm.getTerm() ); + logger.debug( "successfully cast comp to an ITerm" ); + } + catch ( ClassCastException cce ) + { + logger.debug( "LCR caught ClassCastException Failed cast of " +comp.toString() + " to ITerm" ); + throw cce; + } + } + + safetyFirst++; + if ( safetyFirst > 10 ) + { + logger.debug( "could not find an ITerm parent for component: " + comp ); + } + } + } + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + endTransaction( false ); + lexQuery.setDuration( getDuration() ); + return terms; + } + + + /** + * Description of the Method + * + * @param term Description of the Parameter + * @exception LexRepositoryException Description of Exception + * @since + */ + public static void loadTerm( ITerm term ) throws LexRepositoryException + { + try + { + beginTransaction(); + getSession().load( term, term.getMetaId() ); + endTransaction( false ); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + } + + + /** + * Description of the Method + * + * @param lexQuery Description of the Parameter + * @exception LexRepositoryException Description of the Exception + */ + public static void loadTermByPk( LexQuery lexQuery ) throws LexRepositoryException + { + beginTransaction(); + ITerm term = assertTerm( lexQuery.getQueryComponent() ); + loadTerm( term ); + lexQuery.setEntry( term ); + if ( !lexQuery.getResults().containsKey( term.getMetaId() ) ) + { + lexQuery.getResults().put( term.getMetaId(), term.getTerm() ); + } + endTransaction( false ); + } + + + /** + * Description of the Method + * + * @param component Description of the Parameter + * @exception LexRepositoryException Description of the Exception + */ + public static void loadByPk( ILexComponent component ) throws LexRepositoryException + { + + try + { + beginTransaction(); + getSession().load( component, component.getMetaId() ); + endTransaction( false ); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + } + + + /** + * Description of the Method + * + * @param component Description of the Parameter + * @param pk Description of the Parameter + * @exception LexRepositoryException Description of the Exception + */ + public static void loadByPk( ILexComponent component, Integer pk ) throws LexRepositoryException + { + + try + { + beginTransaction(); + getSession().load( component, pk ); + endTransaction( false ); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + } + + + /** + * Gets the recentTerms attribute of the LexComponentRepository class + * + * @param limit Description of the Parameter + * @return The recentTerms value + * @exception LexRepositoryException Description of the Exception + */ + public static List getRecentTerms( int limit ) throws LexRepositoryException + { + Query query = null; + List results = null; + String queryString = " FROM org.thdl.lex.component.ITerm ORDER BY modifiedOn DESC LIMIT " + limit; + try + { + beginTransaction(); + query = getSession().createQuery( queryString ); + results = query.list(); + endTransaction( false ); + getSession().clear(); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + + return results; + } + + + /** + * Description of the Method + * + * @param component Description of the Parameter + * @exception LexRepositoryException Description of the Exception + */ + public static void save( ILexComponent component ) throws LexRepositoryException + { + + try + { + beginTransaction(); + getSession().saveOrUpdate( component ); + endTransaction( true ); + setLastUpdate( now() ); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + } + + + /** + * Description of the Method + * + * @param component Description of the Parameter + * @exception LexRepositoryException Description of the Exception + */ + public static void update( ILexComponent component ) throws LexRepositoryException + { + + try + { + beginTransaction(); + getSession().update( component ); + endTransaction( true ); + setLastUpdate( now() ); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + } + + + /** + * Description of the Method + * + * @param component Description of the Parameter + * @exception LexRepositoryException Description of the Exception + */ + public static void remove( ILexComponent component ) throws LexRepositoryException + { + + try + { + beginTransaction(); + getSession().delete( component ); + endTransaction( true ); + setLastUpdate( now() ); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + } + + + /** + * Description of the Method + * + * @param component Description of the Parameter + * @exception LexRepositoryException Description of the Exception + */ + public static void refresh( ILexComponent component ) throws LexRepositoryException + { + + try + { + beginTransaction(); + getSession().refresh( component ); + endTransaction( true ); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + } + + + /** + * Description of the Method + * + * @exception LexRepositoryException Description of Exception + * @since + */ + public static void cleanup() throws LexRepositoryException + { + try + { + endTransaction( false ); + HibernateSessionTEMP.closeSession(); + } + catch ( HibernateException he ) + { + throw new LexRepositoryException( he ); + } + } +} + + +/* + /join term collections + + " join term.pronunciations as pron " + + " join term.etymologies as ety " + + " join term.spellings as sp " + + " join term.functions as func " + + " join term.encyclopediaArticles as ency " + + " join term.transitionalData as trans " + + " join term.definitions as def " + + " join term.glosses as glo " + + " join term.keywords as key " + + " join term.translationEquivalents as trans " + + " join term.relatedTerms as rel " + + " join term.passages as pass " + + " join term.registers as reg " + join def collections + + " join def.subdefinitions as sub " + + " join def.glosses as gloDef " + + " join def.keywords as keyDef " + + " join def.modelSentences as modDef " + + " join def.translationEquivalents as transDef " + + " join def.relatedTerms as relDef " + + " join def.passages as passDef " + + " join def.registers as regDef " + join subdef collections + + " join sub.glosses as gloSub " + + " join sub.keywords as keySub " + + " join sub.modelSentences as modSub " + + " join sub.translationEquivalents as transSub " + + " join sub.relatedTerms as relSub " + + " join sub.passages as passSub " + + " join sub.registers as regSub " + join translation collections + + " join ety.translations as etyTrans " + + " join term.definitions.translations as defTrans " + + " join term.modelSentences.translations as modTrans " + + " join term.passages.translations as passTrans " + + " join def.subdefinition.translations as subTrans " + + " join def.modelSentences.translations as modDefTrans " + + " join def.passages.translations as passDefTrans " + + " join sub.modelSentences.translations as modSubTrans " + + " join sub.passages.translations as passSubTrans " + /restrict by projectSubject in createdByProjSub + + " where term.meta.createdByProjSub = :projSub" + + " or pron.meta.createdByProjSub = :projSub" + + " or ety.meta.createdByProjSub = :projSub" + + " or sp.meta.createdByProjSub = :projSub" + + " or func.meta.createdByProjSub = :projSub" + + " or ency.meta.createdByProjSub = :projSub" + + " or trans.meta.createdByProjSub = :projSub" + + " or def.meta.createdByProjSub = :projSub" + + " or glo.meta.createdByProjSub = :projSub" + + " or key.meta.createdByProjSub = :projSub" + + " or trans.meta.createdByProjSub = :projSub" + + " or rel.meta.createdByProjSub = :projSub" + + " or pass.meta.createdByProjSub = :projSub" + + " or reg.meta.createdByProjSub = :projSub" + + " or subDef.meta.createdByProjSub = :projSub" + + " or gloDef.meta.createdByProjSub = :projSub" + + " or keyDef.meta.createdByProjSub = :projSub" + + " or modDef.meta.createdByProjSub = :projSub" + + " or transDef.meta.createdByProjSub = :projSub" + + " or relDef.meta.createdByProjSub = :projSub" + + " or passDef.meta.createdByProjSub = :projSub" + + " or regDef.meta.createdByProjSub = :projSub" + + " or gloSub.meta.createdByProjSub = :projSub" + + " or keySub.meta.createdByProjSub = :projSub" + + " or modSub.meta.createdByProjSub = :projSub" + + " or transSub.meta.createdByProjSub = :projSub" + + " or relSub.meta.createdByProjSub = :projSub" + + " or passSub.meta.createdByProjSub = :projSub" + + " or regSub.meta.createdByProjSub = :projSub" + + " or etyTrans.meta.createdByProjSub = :projSub" + + " or defTrans.meta.createdByProjSub = :projSub" + + " or modTrans.meta.createdByProjSub = :projSub" + + " or passTrans.meta.createdByProjSub = :projSub" + + " or subTrans.meta.createdByProjSub = :projSub" + + " or modDefTrans.meta.createdByProjSub = :projSub" + + " or passDefTrans.meta.createdByProjSub = :projSub" + + " or modSubTrans.meta.createdByProjSub = :projSub" + + " or passSubTrans.meta.createdByProjSub = :projSub" + /restrict by projectSubject in modifiedByProjSub + + " or term.meta.modifiedByProjSub = :projSub" + + " or pron.meta.modifiedByProjSub = :projSub" + + " or ety.meta.modifiedByProjSub = :projSub" + + " or sp.meta.modifiedByProjSub = :projSub" + + " or func.meta.modifiedByProjSub = :projSub" + + " or ency.meta.modifiedByProjSub = :projSub" + + " or trans.meta.modifiedByProjSub = :projSub" + + " or def.meta.modifiedByProjSub = :projSub" + + " or glo.meta.modifiedByProjSub = :projSub" + + " or key.meta.modifiedByProjSub = :projSub" + + " or trans.meta.modifiedByProjSub = :projSub" + + " or rel.meta.modifiedByProjSub = :projSub" + + " or pass.meta.modifiedByProjSub = :projSub" + + " or reg.meta.modifiedByProjSub = :projSub" + + " or subDef.meta.modifiedByProjSub = :projSub" + + " or gloDef.meta.modifiedByProjSub = :projSub" + + " or keyDef.meta.modifiedByProjSub = :projSub" + + " or modDef.meta.modifiedByProjSub = :projSub" + + " or transDef.meta.modifiedByProjSub = :projSub" + + " or relDef.meta.modifiedByProjSub = :projSub" + + " or passDef.meta.modifiedByProjSub = :projSub" + + " or regDef.meta.modifiedByProjSub = :projSub" + + " or gloSub.meta.modifiedByProjSub = :projSub" + + " or keySub.meta.modifiedByProjSub = :projSub" + + " or modSub.meta.modifiedByProjSub = :projSub" + + " or transSub.meta.modifiedByProjSub = :projSub" + + " or relSub.meta.modifiedByProjSub = :projSub" + + " or passSub.meta.modifiedByProjSub = :projSub" + + " or regSub.meta.modifiedByProjSub = :projSub" + + " or etyTrans.meta.modifiedByProjSub = :projSub" + + " or defTrans.meta.modifiedByProjSub = :projSub" + + " or modTrans.meta.modifiedByProjSub = :projSub" + + " or passTrans.meta.modifiedByProjSub = :projSub" + + " or subTrans.meta.modifiedByProjSub = :projSub" + + " or modDefTrans.meta.modifiedByProjSub = :projSub" + + " or passDefTrans.meta.modifiedByProjSub = :projSub" + + " or modSubTrans.meta.modifiedByProjSub = :projSub" + + " or passSubTrans.meta.modifiedByProjSub = :projSub"; + */ + diff --git a/src/java/org/thdl/lex/util/dictionary-importer.properties.sample b/src/java/org/thdl/lex/util/dictionary-importer.properties.sample new file mode 100644 index 0000000..caf745a --- /dev/null +++ b/src/java/org/thdl/lex/util/dictionary-importer.properties.sample @@ -0,0 +1 @@ +# Default localized resources for DictionaryImporter dictionaryimporter.driverclassname=org.gjt.mm.mysql.Driver dictionaryimporter.url=jdbc:mysql://localhost:3306/lex?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&user=USERNAME&password=PASSWORD \ No newline at end of file diff --git a/src/java/org/thdl/lex/util/hibernate-data-transfer.cfg.xml.sample b/src/java/org/thdl/lex/util/hibernate-data-transfer.cfg.xml.sample new file mode 100644 index 0000000..e7a765f --- /dev/null +++ b/src/java/org/thdl/lex/util/hibernate-data-transfer.cfg.xml.sample @@ -0,0 +1,57 @@ + + + + + + + + + +com.mysql.jdbc.Driver +jdbc:mysql://localhost/LexNew +USER_XYZ +PASS_XYZ +true +utf-8 + + + + + + + false + true + net.sf.hibernate.dialect.MySQLDialect + + + + + + + + + + +