You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SIPRP/trunk/siprp/lembretes/LembretesDataProvider.java

134 lines
4.0 KiB

/*
* LembretesDataProvider.java
*
* Created on February 5, 2007, 6:09 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package siprp.lembretes;
import com.evolute.utils.Singleton;
import com.evolute.utils.arrays.Virtual2DArray;
import com.evolute.utils.db.DBManager;
import com.evolute.utils.db.Executer;
import com.evolute.utils.sql.Assignment;
import com.evolute.utils.sql.Delete;
import com.evolute.utils.sql.Field;
import com.evolute.utils.sql.Insert;
import com.evolute.utils.sql.Select;
import java.util.Date;
import java.util.HashMap;
/**
*
* @author lflores
*/
public class LembretesDataProvider
{
private static final Object LOCK = new Object();
private static LembretesDataProvider instance = null;
private final HashMap<String,TipoLembrete> TIPOS_LEMBRETES_BY_CODIGO =
new HashMap<String,TipoLembrete>();
private TipoLembrete tiposLembrete[];
private Executer EXECUTER;
/** Creates a new instance of LembretesDataProvider */
public LembretesDataProvider()
throws Exception
{
DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
EXECUTER = dbm.getSharedExecuter( this );
}
public static LembretesDataProvider getProvider()
throws Exception
{
synchronized( LOCK )
{
if( instance == null )
{
instance = new LembretesDataProvider();
}
}
return instance;
}
public TipoLembrete[] getTiposLembrete()
throws Exception
{
if( tiposLembrete == null )
{
Select select =
new Select( new String[]{ "lembretes_tipos" },
new String[]{ "id", "codigo", "descricao", "ordem" },
new Field( "activo" ).isEqual( "y" ),
new String[]{ "ordem" },
null );
Virtual2DArray array = EXECUTER.executeQuery( select );
tiposLembrete = new TipoLembrete[ array.columnLength() ];
for( int n = 0; n < tiposLembrete.length; n++ )
{
Integer id = ( Integer ) array.get( n, 0 );
String codigo = ( String ) array.get( n, 1 );
String descricao = ( String ) array.get( n, 2 );
Integer ordem = ( Integer ) array.get( n, 3 );
tiposLembrete[ n ] = new TipoLembrete( id, codigo, descricao, ordem );
TIPOS_LEMBRETES_BY_CODIGO.put( codigo, tiposLembrete[ n ] );
}
}
return tiposLembrete;
}
public TipoLembrete getTipoLembreteByCodigo( String codigo )
throws Exception
{
getTiposLembrete();
return TIPOS_LEMBRETES_BY_CODIGO.get( codigo );
}
public void criarLembrete( Integer tipoID,
Date data,
String descricao,
String texto,
Integer empresaID,
Integer estabelecimentoID,
Integer trabalhadorID,
Integer marcacaoEstabelecimentoID,
Integer marcacaoTrabalhadorID,
boolean enviarEmail,
Integer periodicidadeDias,
Integer periodicidadeMeses )
throws Exception
{
Insert insert =
new Insert( "lembretes",
new Assignment[]{
new Assignment( new Field( "tipo_id" ), tipoID ),
new Assignment( new Field( "data" ), data ),
new Assignment( new Field( "descricao" ), descricao ),
new Assignment( new Field( "texto" ), texto ),
new Assignment( new Field( "empresa_id" ), empresaID ),
new Assignment( new Field( "estabelecimento_id" ), estabelecimentoID ),
new Assignment( new Field( "trabalhador_id" ), trabalhadorID ),
new Assignment( new Field( "marcacao_estabelecimento_id" ), marcacaoEstabelecimentoID ),
new Assignment( new Field( "marcacao_trabalhador_id" ), marcacaoTrabalhadorID ),
new Assignment( new Field( "enviar_email" ), enviarEmail ? "y" : "n" ),
new Assignment( new Field( "periodicidade_dias" ), periodicidadeDias ),
new Assignment( new Field( "periodicidade_meses" ), periodicidadeMeses ) } );
EXECUTER.executeQuery( insert );
}
public void apagarLembreteByMarcacaoTrabalhadorID( Integer marcacaoID )
throws Exception
{
Delete delete =
new Delete( "lembretes",
new Field( "marcacao_trabalhador_id" ).isEqual( marcacaoID ) );
EXECUTER.executeQuery( delete );
}
}