public long save(Platform platform) throws IOException { // execute this procedure... MapSqlParameterSource params = new MapSqlParameterSource(); params .addValue("name", platform.getPlatformType().getKey()) .addValue("instrumentModel", platform.getInstrumentModel()) .addValue("description", platform.getDescription()) .addValue("numContainers", platform.getNumContainers()); if (platform.getPlatformId() == null) { SimpleJdbcInsert insert = new SimpleJdbcInsert(template) .withTableName(TABLE_NAME) .usingGeneratedKeyColumns("platformId"); Number newId = insert.executeAndReturnKey(params); platform.setPlatformId(newId.longValue()); } else { params.addValue("platformId", platform.getPlatformId()); NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template); namedTemplate.update(PLATFORM_UPDATE, params); } return platform.getPlatformId(); }
@Test public void testPlatforms() { try { // get row count of experiments in the dataset int expected = getDataSet().getTable("Platform").getRowCount(); // get number of experiments from the DAO int actual = getPlatformDAO().count(); // test data contains 2 experiments, check size of returned list TestCase.assertEquals("Wrong number of Platform", expected, actual); System.out.println("Expected number of Platform: " + expected + ", actual: " + actual); for (Platform d : random(getPlatformDAO(), actual, 5)) { TestCase.assertNotNull(d); TestCase.assertNotNull(d.getPlatformId()); } } catch (Exception e) { e.printStackTrace(); TestCase.fail(); } }
@Transactional(readOnly = false) public long save(Platform platform) throws IOException { getHibernateTemplate().saveOrUpdate(platform); return platform.getPlatformId(); }