/** * Remaps null fields to empty strings suitable for use in the client. * * @param genesDAO the instance to remap * @return the same instance, with nulls remapped to empty strings. */ private GenesDAO remapNulls(GenesDAO genesDAO) { // Re-map null fields to empty strings. if (genesDAO != null) { if (genesDAO.getCentimorgan() == null) genesDAO.setCentimorgan(""); if (genesDAO.getChromosome() == null) genesDAO.setChromosome(""); if (genesDAO.getCytoband() == null) genesDAO.setCytoband(""); if (genesDAO.getEnsembl_ref() == null) genesDAO.setEnsembl_ref(""); if (genesDAO.getFounder_line_number() == null) genesDAO.setFounder_line_number(""); if (genesDAO.getLast_change() == null) genesDAO.setLast_change(""); if (genesDAO.getMgi_ref() == null) genesDAO.setMgi_ref(""); if (genesDAO.getName() == null) genesDAO.setName(""); if (genesDAO.getPlasmid_construct() == null) genesDAO.setPlasmid_construct(""); if (genesDAO.getPromoter() == null) genesDAO.setPromoter(""); if (genesDAO.getSpecies() == null) genesDAO.setSpecies(""); if (genesDAO.getSymbol() == null) genesDAO.setSymbol(""); if (genesDAO.getUsername() == null) genesDAO.setUsername(""); } return genesDAO; }
/** * Saves the given <code>GenesDAO</code> gene * * @param gene the <code>GenesDAO</code> to be saved */ public void save(GenesDAO gene) { Session session = factory.getCurrentSession(); Integer centimorgan = Utils.tryParseInt(gene.getCentimorgan()); gene.setCentimorgan( centimorgan == null ? null : centimorgan .toString()); // Centimorgans are numeric, nullable in the database, so re-map any // non-numeric values to null. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String currentTimestamp = dateFormat.format(new Date()); gene.setLast_change(currentTimestamp); gene.setUsername("EMMA"); try { session.beginTransaction(); session.saveOrUpdate(gene); session.getTransaction().commit(); } catch (HibernateException e) { session.getTransaction().rollback(); throw e; } }