Pretty Code Blog

Just another weblog about development

21  01 2009

Usando QUERIES em BUNDLES

Classe que usará a query “Exemplo.QUERY_buscaTodos”

package br.com.prettycode.treinamento.model.dao.impl;

public class FuncionarioDAOOracleImpl implements FuncionarioDAO {
(...)

public List<Funcionario> findAllExclusionLogical() {
(...)

conn = getConnectionPool().getConnection();

// query a ser executada
String query = Buscas.getString("Exemplo.QUERY_buscaTodos"); //$NON-NLS-1$

stmt = conn.prepareStatement(query);
(...)

}

Classe que manipula os bundles

package br.com.prettycode.treinamento.util;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class Buscas {
private static final String BUNDLE_NAME = "br.com.prettycode.treinamento.properties.buscasSQL"; //$NON-NLS-1$

private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

private Buscas() {
}

public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}

Arquivo properties (caminho completo: src/br/com/prettycode/treinamento/properties/buscasSQL.properties)

Exemplo.QUERY_buscaTodos=SELECT  FUNC.CODIGO,  FUNC.NOME,  FUNC.CARGO,  FUNC.SALARIO,  FUNC.RESUMO,  FUNC.STATUS,  FUNC.EXCLUIDO,  FUNC.COD_DEPTO,  DEPTO.NOME,  DEPTO.DESCRICAO  FROM  T_FUNCIONARIO FUNC,  T_DEPARTAMENTO DEPTO  WHERE  ((FUNC.EXCLUIDO is null) OR (FUNC.EXCLUIDO = ?))

Leave a Reply

CAPTCHA Image

« »