/*
	WordNet Access Library
	Copyright (C) 2006 Pavel Simakov
	http://www.softwaresecretweapons.com

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/

package com.oy.shared.wn.samples;

import java.sql.SQLException;

import com.oy.shared.lw.LinguinePerfWatch;
import com.oy.shared.lw.misc.ITrace;
import com.oy.shared.wn.core.WNDatabase;

public class ImportFromFiles {

	private static final String IMPORT_FOLDER = "D:/SETUP/wordnet/WNprolog-2.0/prolog/";	
	private static final String CONN_STRING = "jdbc:mysql://localhost:3306/mysql?user=admin";

	public static void main(String [] args){
		
		LinguinePerfWatch watch = new LinguinePerfWatch();		
		try { 

			// load mySQL JDBC driver; must be on the classpath		
			final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
			try {
				Class.forName(JDBC_DRIVER);
			}catch(Exception e){
				throw new SQLException("Error loading database driver.");
			}

			watch.getPerfAgentContext().setSnapshotFileName("d:/wn.perf.html");
						
			watch.start();
			try {
					
				WNDatabase db = new WNDatabase(
					watch.getPerfAgent(), 
					new ITrace.MockTraceOutImpl(ImportFromFiles.class, ITrace.INFO), 
					CONN_STRING
				);
				db.open();
				try {
					db.initFromPrologFiles(IMPORT_FOLDER);
				} finally{
					db.close();
				}
			
			} finally {
				watch.stop();
			}
		} catch(Exception e){
			e.printStackTrace();
		}
	}
	
}
