MatrixColumn c2 = new MatrixColumn();
c2.setCharacter(dnaChar);
matrix.addColumn(c2);
// add two rows:
TaxonLabel taxonLabel = new TaxonLabel();
taxonLabel.setTaxonLabel(newName);
// missing symbol is ?
DiscreteCharState aState = dnaChar.getStateByDescription("" + DiscreteCharState.MISSING_SYMBOL);
assertTrue("? is not a valid state", aState != null);
// create one row with 2 elements:
MatrixRow r1 = new MatrixRow();
r1.setTaxonLabel(taxonLabel);
DiscreteMatrixElement e1 = new DiscreteMatrixElement();
e1.setColumn(c1);
e1.setCharState(aState);
r1.addElement(e1);
DiscreteMatrixElement e2 = new DiscreteMatrixElement();
e2.setColumn(c2);
e2.setCharState(aState);
r1.addElement(e2);
// add two segments, each with one element:
RowSegment seg1 = new RowSegment();
seg1.setStartIndex(0);
seg1.setEndIndex(0);
r1.addSegment(seg1);
RowSegment seg2 = new RowSegment();
seg2.setStartIndex(1);
seg2.setEndIndex(1);
r1.addSegment(seg2);
matrix.addRow(r1);
// TODO: add a second row.
//getMatrixHome().store(taxonLabel);
getMatrixHome().store(c1);
getMatrixHome().store(c2);
getMatrixHome().store(e1);
getMatrixHome().store(e2);
getMatrixHome().store(matrix);
// 2. verify
Long matrixID = matrix.getId();
Long c1ID = c1.getId();
Long c2ID = c2.getId();
Long r1ID = r1.getId();
Long seg1ID = seg1.getId();
Long seg2ID = seg2.getId();
Long e1ID = e1.getId();
Long e2ID = e2.getId();
Long taxonID = taxonLabel.getId();
logger.info("matrix created: " + matrix.getTitle() + "id = " + matrixID + " symbols=" + matrix.getSymbols() + " gap =" + matrix.getGapSymbol());
logger.info("taxonLabel created: " + taxonLabel.getTaxonLabel() + "id = " + taxonID);
logger.info("2 columns created: id = " + c1ID + ", " + c2ID);
logger.info("2 rows created: id = " + r1.getId() + ", ");
logger.info("2 segments created: id = " + seg1.getId() + ", " + seg2.getId());
logger.info("2 elements created: id = " + e1.getId() + ", " + e2.getId());
// force commit immediately, important:
//setComplete();
//endTransaction();
Matrix m = (Matrix)loadObject(Matrix.class, matrixID);
TaxonLabel tl = (TaxonLabel)loadObject(TaxonLabel.class, taxonID);
//String sqlStr = "select count(*) from matrix where matrix_id=" + matrixID;
//int count = jdbcTemplate.queryForInt(sqlStr);
//assertTrue(count == 1);
assertTrue( m!=null );
//assertTrue( tl!=null );