git-svn-id: https://svn.coded.pt/svn/SIPRP@1521 bb69d46d-e84e-40c8-a05a-06db0d633741

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Diogo Neves 15 years ago
parent 72a08143c3
commit 58e860b8be

@ -19,28 +19,55 @@ import javax.servlet.http.HttpSession;
*/
public class Db
{
// String connectionURL = "jdbc:postgresql://evoserver:5432/siprp_20100813"; //testes
// String connectionURL = "jdbc:postgresql://www.evolute.pt:5436/siprp"; //real
String connectionURL = "jdbc:postgresql://localhost:5436/siprp"; //real
//production
private String server = "localhost";
private int port = 5436;
private String db_name = "siprp";
private String User = "postgres";
private String Pass = null;
String User = "postgres";
String Pass = null;
Connection connection = null;
//tests
// private String server = "evoserver";
// private int port = 5432;
// private String db_name = "siprp_20100813";
// private String User = "postgres";
// private String Pass = null;
private String connectionURL = "jdbc:postgresql://" + server + ":" + port + "/" + db_name;
private Connection connection = null;
/** Creates a new instance of Db */
public Db() {
public Db()
{
}
public String getServer() {
return server;
}
public int getPort() {
return port;
}
public String getDb_name() {
return db_name;
}
public String getUser() {
return User;
}
public String getPass() {
return Pass;
}
public Connection connect() throws Exception
{
Class.forName("org.postgresql.Driver").newInstance();
// FacesContext fc = FacesContext.getCurrentInstance();
// ApplicationBean1 application = JSFUtils.getApplicationBean(fc);
// if(application.getConnection() == null)
// {
connection = DriverManager.getConnection(connectionURL, User, Pass);
// application.setConnection(connection);
// }
connection = DriverManager.getConnection(connectionURL, User, Pass);
connection = DriverManager.getConnection(connectionURL, User, Pass);
HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true);
@ -50,9 +77,6 @@ public class Db
public Connection getConnection()
{
// FacesContext fc = FacesContext.getCurrentInstance();
// ApplicationBean1 application = JSFUtils.getApplicationBean(fc);
// connection = application.getConnection();
HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
connection = (Connection) session.getAttribute("connection");
return connection;
@ -62,9 +86,6 @@ public class Db
{
HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
connection = (Connection) session.getAttribute("connection");
// FacesContext fc = FacesContext.getCurrentInstance();
// ApplicationBean1 application = JSFUtils.getApplicationBean(fc);
// connection = application.getConnection();
Statement st;
try
{

@ -0,0 +1,121 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package db.providers;
import com.evolute.entity.evo.EvoDataProvider;
import com.evolute.utils.Singleton;
import com.evolute.utils.db.DBException;
import com.evolute.utils.db.DBManager;
import com.evolute.utils.db.Executer;
import com.evolute.utils.db.JDBCManager;
import com.evolute.utils.db.keyretrievers.PostgresqlAutoKeyRetriever;
import com.evolute.utils.jdbc.DBStatementExecuter;
import com.evolute.utils.jdbc.StatementExecuterFactory;
import com.evolute.utils.sql.Insert;
import com.evolute.utils.sql.SQLQuery;
import com.evolute.utils.strings.UnicodeChecker;
import db.Db;
/**
*
* @author dneves
*/
public class EvoBaseProvider
{
private static EvoBaseProvider INSTANCE = null;
private EvoDataProvider providerInterface;
private DBManager dbManager;
private static final String DB_URL_FULL = "db.url.full";
private EvoBaseProvider() throws DBException
{
init();
}
public static synchronized EvoBaseProvider getInstance() throws DBException
{
if ( INSTANCE == null )
{
INSTANCE = new EvoBaseProvider();
}
return INSTANCE;
}
private void init() throws DBException
{
System.out.println( "EvoBaseProvider . init() : " );
Db db = new Db();
String server = db.getServer();
Integer port = db.getPort();
String dbname = db.getDb_name();
String username = db.getUser();
String password = db.getPass();
System.out.println( "\t" + server + " : " + port + " : " + dbname + " : " + username + " : " + password );
init( server, port, dbname, username, password );
}
private void init( String dbServer, Integer dbPort, String dbName, String dbUsername, String dbPassword )
throws DBException
{
String dbUrl = "jdbc:postgresql://" + dbServer + ":" + dbPort + "/" + dbName + "?prepareThreshold=2";
Singleton.setInstance( DB_URL_FULL, dbUrl );
createDBManager( dbUsername, dbPassword );
initProviderConnection( dbUsername, dbPassword );
}
private void createDBManager( String username, String password )
throws DBException
{
if( dbManager != null )
{
dbManager.close();
}
String dbUrl = ( String ) Singleton.getInstance( DB_URL_FULL );
DBManager manager = new JDBCManager( dbUrl, username, password , 14, 7, 7, new SQLQuery[] { } );
StatementExecuterFactory.initialize( new DBStatementExecuter( manager.getSharedExecuter( EvoBaseProvider.class ) ) );
UnicodeChecker.setUseDoubleSlash( true );
Insert.setDefaultKeyRetriever( PostgresqlAutoKeyRetriever.RETRIEVER );
dbManager = manager;
Singleton.setInstance( Singleton.DEFAULT_DBMANAGER, dbManager );
}
private void initProviderConnection( String username, String password )
{
String dbUrl = ( String ) Singleton.getInstance( DB_URL_FULL );
providerInterface = EvoProviderFactory.createInstance( dbUrl, username, password );
}
public EvoDataProvider getProvider()
{
return providerInterface;
}
public DBManager getDbManager()
{
return dbManager;
}
public Executer getExecuter() throws DBException
{
return getExecuter( this );
}
private Executer getExecuter( Object clazz ) throws DBException
{
if ( getDbManager() == null )
{
init();
}
DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
return dbm.getSharedExecuter( clazz );
}
}

@ -0,0 +1,23 @@
package db.providers;
import com.evolute.entity.ProviderRegistry;
import com.evolute.entity.evo.EvoDataProvider;
import com.evolute.entity.evo.EvoDataProviderFactory;
import com.evolute.entity.utils.ConnectionIdentity;
import com.evolute.utils.Singleton;
public class EvoProviderFactory
{
public static EvoDataProvider createInstance( String url, String user, String password )
{
ProviderRegistry.registerDefaultProviderFactory( new EvoDataProviderFactory() );
ConnectionIdentity conn = new ConnectionIdentity( url, user );
ProviderRegistry.registerDefaultConnection( conn );
EvoDataProvider provider = ( EvoDataProvider ) ProviderRegistry.getDefaultProvider( conn );
provider.setIsUsingCache( Boolean.FALSE );
Singleton.setInstance( Singleton.DEFAULT_OBJECT_PROVIDER, provider );
conn.setPassword( password );
return provider;
}
}

@ -5,7 +5,12 @@
package db.providers;
import com.evolute.utils.db.Executer;
import com.evolute.utils.error.ErrorLogger;
import com.evolute.utils.sql.Assignment;
import com.evolute.utils.sql.Expression;
import com.evolute.utils.sql.Field;
import com.evolute.utils.sql.Update;
import com.evolute.utils.strings.StringPlainer;
import db.entidades.Area;
import db.entidades.EstadoMedida;
@ -92,7 +97,7 @@ public class PlanosDataProvider extends GenericDataProvider{
sql += ")";
System.out.println("SQL CREATE PLANO : " + sql);
st.execute(sql);
st.execute( sql );
return newId;
}
@ -136,91 +141,120 @@ public class PlanosDataProvider extends GenericDataProvider{
p.setUser_hs(null);
}
}
Statement st = createStatement();
String sql = "";
//To Do sql string here :
sql = "UPDATE planos_actuacao SET fase = " + p.getFase() + ", ";
sql += "validacao_director_loja = " + p.getValidacao_director_loja() + ", ";
sql += "validacao_dns = " + p.getValidacao_dns() + ", ";
sql += "validacao_hs = " + p.getValidacao_hs() + ", ";
sql += "observacoes_dl = '" + p.getObservacoes_dl() + "', ";
sql += "observacoes_dns = '" + p.getObservacoes_dns() + "', ";
sql += "obs_correcao = '" + p.getObs_correcao() + "', ";
sql += "correcao = '" + p.getCorrecao() + "', ";
sql += "fase_antes_correcao = " + p.getFase_antes_correcao() + ", ";
sql += "concluido_por_desactivacao = " + ( p.getConcluidoPorDesactivacao() == null ? "false" : p.getConcluidoPorDesactivacao() ) + ", ";
sql += "data_desactivacao = " + ( p.getDataDesactivacao() == null ? null : "'" + new java.sql.Date( p.getDataDesactivacao().getTime() ) + "'" ) + ", ";
if(p.getData_validacao_dir_loja() == null)
{
sql += "data_validacao_dir_loja = " + null + ", ";
}
else
{
java.sql.Date sqlDate = new java.sql.Date(p.getData_validacao_dir_loja().getTime());
sql += "data_validacao_dir_loja = '" + sqlDate + "', ";
}
sql += "user_dir_loja = " + p.getUser_dir_loja() + ", ";
if(p.getData_validacao_dns() == null)
{
sql += "data_validacao_dns = " + null + ", ";
}
else
{
java.sql.Date sqlDate = new java.sql.Date(p.getData_validacao_dns().getTime());
sql += "data_validacao_dns = '" + sqlDate + "', ";
}
sql += "user_dns = " + p.getUser_dns() + ", ";
if(p.getData_validacao_hs() == null)
{
sql += "data_validacao_hs = " + null + ", ";
}
else
{
java.sql.Date sqlDate = new java.sql.Date(p.getData_validacao_hs().getTime());
sql += "data_validacao_hs = '" + sqlDate + "', ";
}
sql += "user_hs = " + p.getUser_hs() + ", ";
if(p.getData_controlo() == null)
{
sql += "data_controlo = " + null + ", ";
}
else
{
java.sql.Date sqlDate = new java.sql.Date(p.getData_controlo().getTime());
sql += "data_controlo = '" + sqlDate + "', ";
}
if(p.getData_email_controlo() == null)
{
sql += "data_email_controlo = " + null + " ";
}
else
{
java.sql.Date sqlDate = new java.sql.Date(p.getData_email_controlo().getTime());
sql += "data_email_controlo = '" + sqlDate + "' ";
}
sql += "WHERE id = " + p.getId();
System.out.println("SQL UPDATE PLANO : " + sql);
ErrorLogger.log( "SAVE : PlanosDataProvider.updatePlano( p ) : " + sql );
st.execute(sql);
Expression where = new Field( "id" ).isEqual( p.getId() );
Update upd = new Update( "planos_actuacao", new Assignment[]
{
new Assignment( new Field( "fase" ), p.getFase() ),
new Assignment( new Field( "validacao_director_loja" ), p.getValidacao_director_loja() ),
new Assignment( new Field( "validacao_dns" ), p.getValidacao_dns() ),
new Assignment( new Field( "validacao_hs" ), p.getValidacao_hs() ),
new Assignment( new Field( "observacoes_dl" ), p.getObservacoes_dl() ),
new Assignment( new Field( "observacoes_dns" ), p.getObservacoes_dns() ),
new Assignment( new Field( "obs_correcao" ), p.getObs_correcao() ),
new Assignment( new Field( "correcao" ), p.getCorrecao() ),
new Assignment( new Field( "fase_antes_correcao" ), p.getFase_antes_correcao() ),
new Assignment( new Field( "concluido_por_desactivacao" ), ( p.getConcluidoPorDesactivacao() == null ? new Boolean( false ) : p.getConcluidoPorDesactivacao() ) ),
new Assignment( new Field( "data_desactivacao" ), p.getDataDesactivacao() ),
new Assignment( new Field( "data_validacao_dir_loja" ), p.getData_validacao_dir_loja() ),
new Assignment( new Field( "user_dir_loja" ), p.getUser_dir_loja() ),
new Assignment( new Field( "data_validacao_dns" ), p.getData_validacao_dns() ),
new Assignment( new Field( "user_dns" ), p.getUser_dns() ),
new Assignment( new Field( "data_validacao_hs" ), p.getData_validacao_hs() ),
new Assignment( new Field( "user_hs" ), p.getUser_hs() ),
new Assignment( new Field( "data_controlo" ), p.getData_controlo() ),
new Assignment( new Field( "data_email_controlo" ), p.getData_email_controlo() )
}, where );
System.out.println( "SQL UPDATE PLANO : " + upd.toString() );
Executer executer = EvoBaseProvider.getInstance().getExecuter();
ErrorLogger.log( "SAVE : PlanosDataProvider.updatePlano( " + p.getId() + " ) : " + upd.toString() );
executer.executeQuery( upd );
// Statement st = createStatement();
// String sql = "";
//
// //To Do sql string here :
// sql = "UPDATE planos_actuacao SET fase = " + p.getFase() + ", ";
// sql += "validacao_director_loja = " + p.getValidacao_director_loja() + ", ";
// sql += "validacao_dns = " + p.getValidacao_dns() + ", ";
// sql += "validacao_hs = " + p.getValidacao_hs() + ", ";
// sql += "observacoes_dl = '" + p.getObservacoes_dl() + "', ";
// sql += "observacoes_dns = '" + p.getObservacoes_dns() + "', ";
// sql += "obs_correcao = '" + p.getObs_correcao() + "', ";
// sql += "correcao = '" + p.getCorrecao() + "', ";
// sql += "fase_antes_correcao = " + p.getFase_antes_correcao() + ", ";
// sql += "concluido_por_desactivacao = " + ( p.getConcluidoPorDesactivacao() == null ? "false" : p.getConcluidoPorDesactivacao() ) + ", ";
// sql += "data_desactivacao = " + ( p.getDataDesactivacao() == null ? null : "'" + new java.sql.Date( p.getDataDesactivacao().getTime() ) + "'" ) + ", ";
//
// if(p.getData_validacao_dir_loja() == null)
// {
// sql += "data_validacao_dir_loja = " + null + ", ";
// }
// else
// {
// java.sql.Date sqlDate = new java.sql.Date(p.getData_validacao_dir_loja().getTime());
// sql += "data_validacao_dir_loja = '" + sqlDate + "', ";
// }
// sql += "user_dir_loja = " + p.getUser_dir_loja() + ", ";
// if(p.getData_validacao_dns() == null)
// {
// sql += "data_validacao_dns = " + null + ", ";
// }
// else
// {
// java.sql.Date sqlDate = new java.sql.Date(p.getData_validacao_dns().getTime());
// sql += "data_validacao_dns = '" + sqlDate + "', ";
// }
// sql += "user_dns = " + p.getUser_dns() + ", ";
// if(p.getData_validacao_hs() == null)
// {
// sql += "data_validacao_hs = " + null + ", ";
// }
// else
// {
// java.sql.Date sqlDate = new java.sql.Date(p.getData_validacao_hs().getTime());
// sql += "data_validacao_hs = '" + sqlDate + "', ";
// }
// sql += "user_hs = " + p.getUser_hs() + ", ";
// if(p.getData_controlo() == null)
// {
// sql += "data_controlo = " + null + ", ";
// }
// else
// {
// java.sql.Date sqlDate = new java.sql.Date(p.getData_controlo().getTime());
// sql += "data_controlo = '" + sqlDate + "', ";
// }
// if(p.getData_email_controlo() == null)
// {
// sql += "data_email_controlo = " + null + " ";
// }
// else
// {
// java.sql.Date sqlDate = new java.sql.Date(p.getData_email_controlo().getTime());
// sql += "data_email_controlo = '" + sqlDate + "' ";
// }
//
// sql += "WHERE id = " + p.getId();
// System.out.println("SQL UPDATE PLANO : " + sql);
//
// ErrorLogger.log( "SAVE : PlanosDataProvider.updatePlano( p ) : " + sql );
// st.execute(sql);
}
public void updateRisco(Risco r) throws Exception
public void updateRisco( Risco r ) throws Exception
{
if(r.getResponsavel_execucao() == null)
{
r.setResponsavel_execucao("");
}
if(r.getPor() == null)
{
r.setPor("");
}
if(r.getRecursos_necessarios() == null)
{
r.setRecursos_necessarios("");
@ -236,40 +270,60 @@ public class PlanosDataProvider extends GenericDataProvider{
if(r.getVerificacao_siprp() == null)
{
r.setVerificacao_siprp("");
}
Statement st = createStatement();
String sql = "";
//To Do sql string here :
sql = "UPDATE plano_riscos SET responsavel_execucao = '" + r.getResponsavel_execucao() + "', ";
sql += "por = '" + r.getPor() + "', ";
sql += "recursos_necessarios = '" + r.getRecursos_necessarios() + "', ";
if(r.getData_inicio() == null)
{
sql += "data_inicio = " + null + ", ";
}
else
{
java.sql.Date sqlDate = new java.sql.Date(r.getData_inicio().getTime());
sql += "data_inicio = '" + sqlDate + "', ";
}
if(r.getData_fim() == null)
{
sql += "data_fim = " + null + ", ";
}
else
{
java.sql.Date sqlDate = new java.sql.Date(r.getData_fim().getTime());
sql += "data_fim = '" + sqlDate + "', ";
}
sql += "parecer_dns = '" + r.getParecer_dns() + "', ";
sql += "parecer_dl = '" + r.getParecer_dl() + "', ";
sql += "verificacao_siprp = '" + r.getVerificacao_siprp() + "' ";
sql += "WHERE id = " + r.getId();
System.out.println("SQL UPDATE RISCO : " + sql);
ErrorLogger.log( "SAVE : PlanosDataProvider.updateRisco( r ) : " + sql );
st.execute(sql);
Expression where = new Field( "id" ).isEqual( r.getId() );
Update upd = new Update( "plano_riscos", new Assignment[]
{
new Assignment( new Field( "responsavel_execucao" ), r.getResponsavel_execucao() ),
new Assignment( new Field( "por" ), r.getPor() ),
new Assignment( new Field( "recursos_necessarios" ), r.getRecursos_necessarios() ),
new Assignment( new Field( "data_inicio" ), r.getData_inicio() ),
new Assignment( new Field( "data_fim" ), r.getData_fim() ),
new Assignment( new Field( "parecer_dns" ), r.getParecer_dns() ),
new Assignment( new Field( "parecer_dl" ), r.getParecer_dl() ),
new Assignment( new Field( "verificacao_siprp" ), r.getVerificacao_siprp() )
}, where );
System.out.println( "SQL UPDATE RISCO : " + upd.toString() );
ErrorLogger.log( "SAVE : PlanosDataProvider.updateRisco( " + r.getId() + " ) : " + upd.toString() );
Executer executer = EvoBaseProvider.getInstance().getExecuter();
executer.executeQuery( upd );
// Statement st = createStatement();
// String sql = "";
//
// sql = "UPDATE plano_riscos SET responsavel_execucao = '" + r.getResponsavel_execucao() + "', ";
// sql += "por = '" + r.getPor() + "', ";
// sql += "recursos_necessarios = '" + r.getRecursos_necessarios() + "', ";
// if(r.getData_inicio() == null)
// {
// sql += "data_inicio = " + null + ", ";
// }
// else
// {
// java.sql.Date sqlDate = new java.sql.Date(r.getData_inicio().getTime());
// sql += "data_inicio = '" + sqlDate + "', ";
// }
// if(r.getData_fim() == null)
// {
// sql += "data_fim = " + null + ", ";
// }
// else
// {
// java.sql.Date sqlDate = new java.sql.Date(r.getData_fim().getTime());
// sql += "data_fim = '" + sqlDate + "', ";
// }
// sql += "parecer_dns = '" + r.getParecer_dns() + "', ";
// sql += "parecer_dl = '" + r.getParecer_dl() + "', ";
// sql += "verificacao_siprp = '" + r.getVerificacao_siprp() + "' ";
// sql += "WHERE id = " + r.getId();
// System.out.println("SQL UPDATE RISCO : " + sql);
//
// ErrorLogger.log( "SAVE : PlanosDataProvider.updateRisco( r ) : " + sql );
// st.execute( sql );
}
public void updateMedidas( Risco risco ) throws Exception
@ -285,12 +339,23 @@ public class PlanosDataProvider extends GenericDataProvider{
emID = m.getValidarMedidaId();
}
String sql = "UPDATE plano_medidas SET estado_medidas_id = " + emID +
" WHERE id = " + m.getId() + " AND risco_id = " + risco.getId();
System.out.println( "SQL UPDATE MEDIDAS : " + sql );
Expression where = new Field( "id" ).isEqual( m.getId() ).and( new Field( "risco_id" ).isEqual( risco.getId() ) );
ErrorLogger.log( "SAVE : PlanosDataProvider.updateMedidas( r ) : " + sql );
st.execute( sql );
Update upd = new Update( "plano_medidas", new Assignment[]
{
new Assignment( new Field( "estado_medidas_id" ), emID )
}, where );
System.out.println( "SQL UPDATE MEDIDAS : " + upd.toString() );
Executer executer = EvoBaseProvider.getInstance().getExecuter();
ErrorLogger.log( "SAVE : PlanosDataProvider.updateMedidas( " + risco.getId() + " ) : " + upd.toString() );
executer.executeQuery( upd );
// String sql = "UPDATE plano_medidas SET estado_medidas_id = " + emID +
// " WHERE id = " + m.getId() + " AND risco_id = " + risco.getId();
// System.out.println( "SQL UPDATE MEDIDAS : " + sql );
// ErrorLogger.log( "SAVE : PlanosDataProvider.updateMedidas( r ) : " + sql );
// st.execute( sql );
}
}

@ -1510,17 +1510,17 @@ public class EditarPlano extends AbstractPageBean {
}
}
public String butGravarPlano_action() {
// TODO: Process the action. Return value is a navigation
// case name where null will return to the same page.
public String butGravarPlano_action()
{
String page = null;
try
{
page = gravarPlano();
getSessionBean1().setMsg("Os dados do Plano de Actuação foram guardados");
}
catch(Exception ex)
catch ( Exception ex )
{
ErrorLogger.logException( new Exception( "Erro na gravacao do plano!" ) );
ErrorLogger.logException( ex );
getSessionBean1().setMsg("Erro na gravação do plano!");
}
@ -1650,9 +1650,8 @@ public class EditarPlano extends AbstractPageBean {
return returnToPage;
}
public String butGravarRisco_action() {
// TODO: Process the action. Return value is a navigation
// case name where null will return to the same page.
public String butGravarRisco_action()
{
PlanosDataProvider pdp = new PlanosDataProvider();
PlanoActuacao p = getSessionBean1().getPlanoActuacao();
int fase = p.getFase().intValue();

@ -519,7 +519,6 @@ public class ListaPlanos extends AbstractPageBean {
return "editar_plano";
}
//TODO:
public String goDesactivarPlano_action()
{
System.out.println( "\ngoDesactivarPlano_action():" );
@ -529,7 +528,6 @@ public class ListaPlanos extends AbstractPageBean {
return null;
}
//TODO:
public String goDesactivarPlanoSeguimento_action()
{
System.out.println( "\ngoDesactivarPlanoSeguimento_action():" );
@ -556,8 +554,6 @@ public class ListaPlanos extends AbstractPageBean {
ErrorLogger.logException( e );
}
}
}

Loading…
Cancel
Save