/* ------------------------------------------------------------------ */
/** checks if master-detail relationships including multiple keys work
*/
public void checkMultipleKeys() throws com.sun.star.uno.Exception, java.lang.Exception
{
HsqlDatabase databaseDocument = null;
try
{
databaseDocument = new HsqlDatabase( m_orb );
impl_createTableStructure( databaseDocument );
impl_createForms( databaseDocument );
m_detailForm.setPropertyValue( "MasterFields", new String[] { "ID1", "ID2" } );
m_detailForm.setPropertyValue( "DetailFields", new String[] { "FK_ID1", "FK_ID2" } );
XLoadable loadMaster = UnoRuntime.queryInterface( XLoadable.class, m_masterForm );
XLoadable loadDetail = UnoRuntime.queryInterface( XLoadable.class, m_detailForm );
loadDetail.addLoadListener( this );
// wait until the detail form is loaded
operateMasterAndWaitForDetailForm( loadMaster.getClass().getMethod( "load", new Class[] {} ), loadMaster, new Object[] { } );
// okay, now the master form should be on the first record
assure( "wrong form state after loading (ID1)", m_masterResult.getInt(1) == 1 );
assure( "wrong form state after loading (ID2)", m_masterResult.getInt(2) == 1 );
assure( "wrong form state after loading (value)", m_masterResult.getString(3).equals( "First Record" ) );
// the "XResultSet.next" method
Method methodNext = m_masterResult.getClass().getMethod( "next" , new Class[] {} );
// the values in the linked fields should be identical
int expectedDetailRowCounts[] = { 2, 1 };
do
{
verifyColumnValueIdentity( "ID1", "FK_ID1" );
verifyColumnValueIdentity( "ID2", "FK_ID2" );
m_detailResult.last();
int masterPos = m_masterResult.getRow();
assure( "wrong number of records in detail form, for master form at pos " + masterPos,
((Integer)m_detailForm.getPropertyValue( "RowCount" )).intValue() == expectedDetailRowCounts[ masterPos - 1 ] );
operateMasterAndWaitForDetailForm( methodNext, m_masterResult, new Object[] {} );
}
while ( !m_masterResult.isAfterLast() );
assure( "wrong number of records in master form", 2 == ((Integer)m_masterForm.getPropertyValue( "RowCount" )).intValue() );
}
finally
{
if ( databaseDocument != null )
databaseDocument.closeAndDelete();
impl_cleanUpStep();
}
}