0
Guys I’m trying to block a "String" field of having duplicity in the record, however I can not do using DB, I wonder if I can do using "If" directly in the code. below follows the code I’m wanting to check the duplicity:
ComponenteInterface cDAO = FabricaDAO.criarComponenteDAO();
if(componente.getVariavel() != null)
{
cDAO.pesquisarVariavel(variavel);
if(variavel.toLowerCase(localC) )
{
return new RetornoNegocio(Resultado.REPROVADO, "Não foi possível salvar, variável já existente");
}
}
cDAO.salvar(componente);
And why can’t you do it on DB? It’s the only reliable way to do it.
– Maniero
for 2 reasons 1- my boss said that if I create a primary key for it, some older mysql might crash. 2-he wants me to do it in the code, and as I’m learning, all the solutions I think don’t work out.
– Benicius Claro
I can’t imagine why the system would crash because it created a primary key, which should have been there from the beginning, especially if you’re talking about Engines Old Mysql and not just your banks that are in Mysql. And if you don’t, the whole system will be compromised and only increase the problem. You can’t fix a mistake with a new mistake. I’d fire your boss, he has no idea what you’re doing (or you’re saying things that don’t actually happen).
– Maniero
What you ask in the question is the creation of a bug known as race condition (and it’s scary how many people do it in code, unfortunately). Suggest to your boss, if he REALLY said so, to look for reliable references, because the 2 points mentioned are absurd.
– Bacco
https://answall.com/q/159342/101
– Maniero