forked from Coded/SIPRP
				
			no message
	
		
	
				
					
				
			git-svn-id: https://svn.coded.pt/svn/SIPRP@322 bb69d46d-e84e-40c8-a05a-06db0d633741
							parent
							
								
									11757fbb90
								
							
						
					
					
						commit
						9fcd7bbcb5
					
				| @ -0,0 +1,22 @@ | ||||
| /* | ||||
|  * Update.java | ||||
|  * | ||||
|  * Created on 26 de Setembro de 2006, 12:13 | ||||
|  * | ||||
|  * To change this template, choose Tools | Template Manager | ||||
|  * and open the template in the editor. | ||||
|  */ | ||||
| 
 | ||||
| package siprp.update; | ||||
| 
 | ||||
| /** | ||||
|  * | ||||
|  * @author fpalma | ||||
|  */ | ||||
| public interface Update | ||||
| { | ||||
| 	public double getStartVersion(); | ||||
| 	public double getEndVersion(); | ||||
| 	public String[] listChanges(); | ||||
| 	public void doUpdate() throws Exception; | ||||
| } | ||||
| @ -0,0 +1,104 @@ | ||||
| /* | ||||
|  * Updater.java | ||||
|  * | ||||
|  * Created on 26 de Setembro de 2006, 11:49 | ||||
|  * | ||||
|  * To change this template, choose Tools | Template Manager | ||||
|  * and open the template in the editor. | ||||
|  */ | ||||
| 
 | ||||
| package siprp.update; | ||||
| 
 | ||||
| import java.util.*; | ||||
| 
 | ||||
| import com.evolute.utils.*; | ||||
| import com.evolute.utils.arrays.*; | ||||
| import com.evolute.utils.db.*; | ||||
| import com.evolute.utils.sql.*; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * | ||||
|  * @author fpalma | ||||
|  */ | ||||
| public class UpdateList | ||||
| { | ||||
| 	protected static final Update UPDATE_LIST[] =  | ||||
| 			new Update[]{ new siprp.update.updates.V6_1_To_V7_0() }; | ||||
| 	 | ||||
| 	protected static Executer EXECUTER; | ||||
| 	protected static double version = -1; | ||||
| 	 | ||||
| 	/** Creates a new instance of Updater */ | ||||
| 	private UpdateList() | ||||
| 	{ | ||||
| 	} | ||||
| 	 | ||||
| 	public static double getCurrentVersion() | ||||
| 		throws Exception | ||||
| 	{ | ||||
| 		if( version < 0 ) | ||||
| 		{ | ||||
| 			version = getVersion(); | ||||
| 		} | ||||
| 		return version; | ||||
| 	} | ||||
| 	 | ||||
| 	public static Update []getUpdates() | ||||
| 		throws Exception | ||||
| 	{ | ||||
| 		if( version < 0 ) | ||||
| 		{ | ||||
| 			version = getVersion(); | ||||
| 		} | ||||
| 		Vector validUpdates = new Vector(); | ||||
| 		for( int n = 0; n < UPDATE_LIST.length; n++ ) | ||||
| 		{ | ||||
| 			if( version <= UPDATE_LIST[ n ].getStartVersion() ) | ||||
| 			{ | ||||
| 				validUpdates.add( UPDATE_LIST[ n ] ); | ||||
| 			} | ||||
| 		} | ||||
| 		return ( Update [] ) validUpdates.toArray( new Update[ validUpdates.size() ] ); | ||||
| 	} | ||||
| 	 | ||||
| 	protected static double getVersion() | ||||
| 		throws Exception | ||||
| 	{ | ||||
| 		DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER ); | ||||
| 		EXECUTER = dbm.getSharedExecuter(); | ||||
| 		try | ||||
| 		{ | ||||
| 			return readVersion(); | ||||
| 		} | ||||
| 		catch( Exception ex ) | ||||
| 		{ | ||||
| 			createVersionTable(); | ||||
| 		} | ||||
| 		return readVersion(); | ||||
| 	} | ||||
| 	 | ||||
| 	protected static double readVersion() | ||||
| 		throws Exception | ||||
| 	{ | ||||
| 		Select select =  | ||||
| 				new Select( new String[]{ "version" }, | ||||
| 							new String[]{ "MAX(current_version)" }, | ||||
| 							null ); | ||||
| 		Virtual2DArray array = EXECUTER.executeQuery( select ); | ||||
| 		return ( ( Number ) array.get( 0, 0 ) ).doubleValue(); | ||||
| 	} | ||||
| 	 | ||||
| 	protected static void createVersionTable() | ||||
| 		throws Exception | ||||
| 	{ | ||||
| 		com.evolute.utils.sql.Update update =  | ||||
| 				new com.evolute.utils.sql.Update( "CREATE TABLE version( current_version float );" ); | ||||
| 		EXECUTER.executeQuery( update ); | ||||
| 		Insert insert =  | ||||
| 				new Insert( "version", | ||||
| 							new Assignment[]{  | ||||
| 								new Assignment( new Field( "current_version" ), new Double( 0.1 ) ) } ); | ||||
| 		EXECUTER.executeQuery( insert ); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,188 @@ | ||||
| /* | ||||
|  * UpdateWindow.java | ||||
|  * | ||||
|  * Created on 26 de Setembro de 2006, 11:54 | ||||
|  * | ||||
|  * To change this template, choose Tools | Template Manager | ||||
|  * and open the template in the editor. | ||||
|  */ | ||||
| 
 | ||||
| package siprp.update; | ||||
| 
 | ||||
| import java.awt.*; | ||||
| import java.awt.event.*; | ||||
| import javax.swing.*; | ||||
| import java.util.*; | ||||
| 
 | ||||
| import com.evolute.utils.*; | ||||
| import com.evolute.utils.date.*; | ||||
| import com.evolute.utils.db.*; | ||||
| import com.evolute.utils.sql.*; | ||||
| import com.evolute.utils.ui.*; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * | ||||
|  * @author fpalma | ||||
|  */ | ||||
| public class UpdateWindow extends JFrame | ||||
| 		implements ActionListener | ||||
| { | ||||
| 	protected JTextArea logText; | ||||
| 	protected JButton closeButton;	 | ||||
| 	 | ||||
| 	protected Update updates[]; | ||||
| 	protected String filename; | ||||
| 	 | ||||
| 	public static void main( String args[] ) | ||||
| 	{ | ||||
| 		UpdateWindow updateWindow = new UpdateWindow(); | ||||
| 		updateWindow.update(); | ||||
| 	} | ||||
| 	 | ||||
| 	/** Creates a new instance of UpdateWindow */ | ||||
| 	public UpdateWindow() | ||||
| 	{ | ||||
| 		setupComponents(); | ||||
| 	} | ||||
| 	 | ||||
| 	private void setupComponents() | ||||
| 	{ | ||||
| 		setTitle( "Actualiza\u00e7\u00e3o do Software" ); | ||||
| 		setSize( 800, 600 ); | ||||
| 		logText = new JTextArea(); | ||||
| 		logText.setLineWrap( true ); | ||||
| 		logText.setWrapStyleWord( true ); | ||||
| 		logText.setEditable( true ); | ||||
| 		JScrollPane scp =  | ||||
| 				new JScrollPane( logText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, | ||||
| 									JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); | ||||
| 		closeButton = new JButton( "Fechar" ); | ||||
| 		 | ||||
| 		setLayout( new BorderLayout() ); | ||||
| 		add( scp, BorderLayout.CENTER ); | ||||
| 		add( closeButton, BorderLayout.SOUTH ); | ||||
| 	 | ||||
| 		closeButton.setEnabled( false ); | ||||
| 		closeButton.addActionListener( this ); | ||||
| 		 | ||||
| 		setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); | ||||
| 	} | ||||
| 	 | ||||
| 	public void actionPerformed( ActionEvent e ) | ||||
| 	{ | ||||
| 		Object source = e.getSource(); | ||||
| 		if( source.equals( closeButton ) ) | ||||
| 		{ | ||||
| 			close(); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	public void close() | ||||
| 	{ | ||||
| 		SwingUtilities.invokeLater( new Runnable(){ | ||||
| 			public void run() | ||||
| 			{ | ||||
| 				setVisible( false ); | ||||
| 				dispose(); | ||||
| 			} | ||||
| 		} ); | ||||
| 	} | ||||
| 	 | ||||
| 	public void update() | ||||
| 	{ | ||||
| 		log( "A verificar a exist\u00eancia de actualiza\u00e7\u00f5es...\n" ); | ||||
| 		try | ||||
| 		{ | ||||
| 			double version = UpdateList.getCurrentVersion(); | ||||
| 			log( "Vers\u00e3o actual: " + ( version < 6.1 ? 6.1 : version ) + "\n" ); | ||||
| 			updates = UpdateList.getUpdates(); | ||||
| 		} | ||||
| 		catch( Exception ex ) | ||||
| 		{ | ||||
| 			setVisible( true ); | ||||
| 			log( "Erro a verificar actualiza\u00e7\u00f5es!!!" ); | ||||
| 			ex.printStackTrace(); | ||||
| 			updates = new Update[ 0 ]; | ||||
| 		} | ||||
| 		if( updates.length > 0 ) | ||||
| 		{ | ||||
| 			setVisible( true ); | ||||
| 			log( "Existe " + ( updates.length >  1 ? "m " : " " ) + updates.length +  | ||||
| 							" actualiza\u00e7" + ( updates.length >  1 ? "\u00f5es... " : "\u00e3o\n" ) ); | ||||
| 			boolean ok = doUpdates(); | ||||
| 			if( ok ) | ||||
| 			{ | ||||
| 				log( "**** Actualiza\u00e7\u00f5es terminadas ****\n" ); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				log( "**** Actualiza\u00e7\u00f5es abortadas ****\n" ); | ||||
| 				log( "\nPode favor contacte a EVOLUTE\n" ); | ||||
| 			} | ||||
| 			 | ||||
| 		} | ||||
| 		closeButton.setEnabled( true ); | ||||
| 	} | ||||
| 	 | ||||
| 	protected void log( final String newLog ) | ||||
| 	{ | ||||
| 		SwingUtilities.invokeLater( new Runnable(){ | ||||
| 			public void run() | ||||
| 			{ | ||||
| 				logText.append( newLog ); | ||||
| 			} | ||||
| 		} ); | ||||
| 	} | ||||
| 	 | ||||
| 	protected boolean doUpdates() | ||||
| 	{ | ||||
| 		double last = 0.1; | ||||
| 		log( "**** A realizar actualiza\u00e7\u00f5es... **** \n" ); | ||||
| 		for( int n = 0; n < updates.length; n++ ) | ||||
| 		{ | ||||
| 			last = updates[ n ].getEndVersion(); | ||||
| 			String msg = "  " + updates[ n ] + "... \n"; | ||||
| 			String changes[] = updates[ n ].listChanges(); | ||||
| 			for( int c = 0; c < changes.length; c++ ) | ||||
| 			{ | ||||
| 				msg += "     " + changes[ c ] + "\n"; | ||||
| 			} | ||||
| 			log( msg ); | ||||
| 			try | ||||
| 			{ | ||||
| 				updates[ n ].doUpdate(); | ||||
| 			} | ||||
| 			catch( Exception ex ) | ||||
| 			{ | ||||
| 				log( "ERRO ! ! !\nA abortar actualiza\u00e7\u00f5es\n" ); | ||||
| 				ex.printStackTrace(); | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
| 		try | ||||
| 		{ | ||||
| 			DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER ); | ||||
| 			Executer executer = dbm.getSharedExecuter(); | ||||
| 			com.evolute.utils.sql.Update update =  | ||||
| 					new com.evolute.utils.sql.Update( "version", | ||||
| 							new Assignment[]{  | ||||
| 								new Assignment( new Field( "current_version" ), new Double( last ) ) }, | ||||
| 							null ); | ||||
| 			executer.executeQuery( update ); | ||||
| 			log( "Vers\u00e3o actualizada para: " + last + "\n" ); | ||||
| 			return true; | ||||
| 		} | ||||
| 		catch( Exception ex ) | ||||
| 		{ | ||||
| 			log( "ERRO ! ! !\nA abortar actualiza\u00e7\u00f5es\n" ); | ||||
| 			ex.printStackTrace(); | ||||
| 			return false; | ||||
| 		}	 | ||||
| 	} | ||||
| 	 | ||||
| 	public int getUpdateCount() | ||||
| 	{ | ||||
| 		return updates.length; | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,68 @@ | ||||
| /* | ||||
|  * V6_1_To_V7_0.java | ||||
|  * | ||||
|  * Created on 26 de Setembro de 2006, 11:48 | ||||
|  * | ||||
|  * To change this template, choose Tools | Template Manager | ||||
|  * and open the template in the editor. | ||||
|  */ | ||||
| 
 | ||||
| package siprp.update.updates; | ||||
| 
 | ||||
| import com.evolute.utils.*; | ||||
| import com.evolute.utils.arrays.*; | ||||
| import com.evolute.utils.db.*; | ||||
| import com.evolute.utils.sql.*; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * | ||||
|  * @author fpalma | ||||
|  */ | ||||
| public class V6_1_To_V7_0  | ||||
| 		implements siprp.update.Update | ||||
| { | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Creates a new instance of V6_1_To_V7_0 | ||||
| 	 */ | ||||
| 	public V6_1_To_V7_0() | ||||
| 	{ | ||||
| 	} | ||||
| 	 | ||||
| 	public String []listChanges() | ||||
| 	{ | ||||
| 		return new String[]{ "Acrescentar campo de contribuinte nos prestadores",  | ||||
| 								"Acrescentar campo de prestador nas marca\u00e7\u00f5es", | ||||
| 								"Acrescentar campo de prestador no hist\u00f3rico das  marca\u00e7\u00f5es"}; | ||||
| 	} | ||||
| 	 | ||||
| 	public double getStartVersion() | ||||
| 	{ | ||||
| 		return 6.1; | ||||
| 	} | ||||
| 	 | ||||
| 	public double getEndVersion() | ||||
| 	{ | ||||
| 		return 7.0; | ||||
| 	} | ||||
| 	 | ||||
| 	public void doUpdate() | ||||
| 		throws Exception | ||||
| 	{ | ||||
| 		DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER ); | ||||
| 		Executer executer = dbm.getSharedExecuter(); | ||||
| 		com.evolute.utils.sql.Update update =  | ||||
| 				new com.evolute.utils.sql.Update( "ALTER TABLE prestadores ADD contribuinte VARCHAR(64);" ); | ||||
| 		executer.executeQuery( update ); | ||||
| 		update = new com.evolute.utils.sql.Update( "ALTER TABLE marcacoes_trabalhador ADD prestador_id int4 REFERENCES prestadores( id );" ); | ||||
| 		executer.executeQuery( update ); | ||||
| 		update = new com.evolute.utils.sql.Update( "ALTER TABLE marcacoes_trabalhador_estados ADD prestador_id int4 REFERENCES prestadores( id );" ); | ||||
| 		executer.executeQuery( update ); | ||||
| 	} | ||||
| 	 | ||||
| 	public String toString() | ||||
| 	{ | ||||
| 		return "v6.1 para v7.0"; | ||||
| 	} | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue