 /*
 * Copyright (C) 09-sept.-2003  Jean-Yves Beaujean 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 * This program 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 General Public License for
 * more details.
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,  59
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * 
 */
package jxtray.dump;

import java.sql.Connection;
import jxtray.Jxtray;
import jxtray.io.WriterContext;

public abstract class JxtDumpStrategy implements Runnable
{
		protected Thread _thread = null;
		protected boolean _finished = true;
		protected int _cpt=0;
		protected DumperListener _listener=null;
		protected java.sql.Connection _connection = null;
		protected String _lib;
		protected String _table;
		protected String _filename;
		protected WriterContext _output = null;
		
		public JxtDumpStrategy(String filename,DumperListener listener, Connection connection,String lib, String table, WriterContext writer)
		{
			_listener = listener;
			_lib=lib;
			_table=table;
			_connection=connection;
			_filename=filename;
			_output = writer;
		}
	
		public String getName() { return "Default Dumper"; }
		public void run() 
		{
		}
		
		public void dump() 
		{
			_cpt=0;
			_listener.dumpStarted();
			try
			{
				_listener.dumpLog("\n"+Jxtray.getLang("dump.targetfile")+ _filename);
				
			}
			catch ( Exception e )
			{
				_listener.dumpError(e.getMessage());
			}
			try
			{
				if ( _thread == null )
				{
					_finished=false;
					_thread = new Thread(this);
					_thread.start();
				}
			}
			catch ( Exception e )
			{
				_listener.dumpError(e.getMessage());
			}
			
		}
		
		
		protected abstract void dumpData();
		protected abstract void dumpStructure();
		
		public void stop()
		{
			try
			{
				_thread.stop();
				_thread=null;
			}
			catch( Exception e )
			{
			}
			_finished=true;
		}
		
		public boolean isFinished()
		{
			return _finished;
		}
		
}
