Advice please: Which of these 2 methods looks better ? like professional code?
Both methods are doing the same thing(simpleUpdate). Except the way am passing the parameters are different. The method manageJob is used to call the method simpleUpdate to update the status in DB.
public <T> void manageJob(Class<T> entityClass,String name,String idName, Car selectedCar){
switch (selectedtask.getGwtApplicationType()) {
case "Cars":
simpleUpdate(entityClass, name, idName, selectedCar.getCarStatus(), selectedCar.getCarId());
break;
default:
break;
}
}
Method 1:
public <T> Boolean simpleUpdate(Object...params) {
Query q = entityManager.createQuery("update "+params[0]+" set "+ params[1]+" ='"+params[3]+"' WHERE "+params[2]+"=:id");
q.setParameter( "id", params[4]);
try {
q.executeUpdate();
return true;
} catch (TransactionRequiredException ex) {
return false;
} catch (IllegalStateException ex) {
return false;
}
}
Method 2:
public <T> Boolean updateStatus(Class<T> entityClass,String name, String idName,String value,String id) {
Query q = entityManager.createQuery("update "+entityClass.getSimpleName()+" set "+ name+" ='"+value+"' WHERE "+idName+"=:id");
q.setParameter( "id", id);
try {
q.executeUpdate();
return true;
} catch (TransactionRequiredException ex) {
return false;
} catch (IllegalStateException ex) {
return false;
}
}