Created
July 3, 2015 09:19
-
-
Save paoloyx/a5bc60f8ace5fb9164b5 to your computer and use it in GitHub Desktop.
JavaGeneratedCode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override@WsgOperation("Add products - Create new products.") | |
public List < Map > addProductsQuestionnaire(@WsgParameter("The Context ID") String contextId, @WsgParameter("The new Products object") List < CoachQuestionnaireProduct > products, | |
SearchRequest searchReq) { | |
DataSource ds = datasourceManager.getDatasource(serviceName, contextId); | |
DataSourceTransactionManager dstm = new DataSourceTransactionManager(ds); | |
TransactionStatus status = dstm.getTransaction(new DefaultTransactionDefinition()); | |
NamedParameterJdbcTemplate jdbc = new NamedParameterJdbcTemplate(ds); | |
JdbcTemplate jdbcs = new JdbcTemplate(ds); | |
String sql = "insert into coach_questionnare_product (id, qualification, weight, description, coach_questionnaire_id) values (:products.id, :products.qualification, :products.weight, :products.description, :products.coachQuestionnaireId)"; | |
Map parameters = new HashMap(); | |
List < Map > rv = new ArrayList < Map > (); | |
String exceptionMessage = null; | |
try { | |
for (CoachQuestionnaireProduct products_rec: products) { | |
/* PRE Assignment... */ | |
Object preAssign_products_id = jdbcs.queryForObject("select seq_coaching_product.nextval from dual", Object.class); | |
/* Binding Parameters evaluation... */ | |
parameters.put("products.id", preAssign_products_id); | |
parameters.put("products.qualification", products_rec.getQualification()); | |
parameters.put("products.weight", products_rec.getWeight()); | |
parameters.put("products.description", products_rec.getDescription()); | |
parameters.put("products.coachQuestionnaireId", products_rec.getCoachQuestionnaireId()); | |
/* PRE SQL Template... */ | |
jdbc.update("delete from coach_questionnare_product where coach_questionnaire_id = :products.coachQuestionnaireId", parameters); | |
/* MAIN SQL Template... */ | |
jdbc.update(sql, parameters); | |
rv.add(parameters); | |
} | |
dstm.commit(status); | |
} catch (Exception txe) { | |
dstm.rollback(status); | |
exceptionMessage = txe.getClass() + "/" + txe.getMessage(); | |
txe.printStackTrace(); | |
} finally { | |
if (exceptionMessage != null) throw new RuntimeException(exceptionMessage); | |
return rv; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment