{
CompanyEntity companyEntity;
PersonEntity personEntity, personEntity2;
EmployeeEntity employeeEntity, employeeEntity2;
{
UnitOfWork unitOfWork = module.newUnitOfWork();
try
{
{
EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class );
personEntity = builder.instance();
personEntity.name().set( "Rickard" );
personEntity = builder.newInstance();
}
{
EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class );
personEntity2 = builder.instance();
personEntity2.name().set( "Niclas" );
builder.newInstance();
}
{
EntityBuilder<EmployeeEntity> builder = unitOfWork.newEntityBuilder( EmployeeEntity.class );
employeeEntity = builder.instance();
employeeEntity.person().set( personEntity );
employeeEntity.salary().set( 50000 );
employeeEntity.title().set( "Director" );
employeeEntity = builder.newInstance();
}
{
EntityBuilder<EmployeeEntity> builder = unitOfWork.newEntityBuilder( EmployeeEntity.class );
employeeEntity2 = builder.instance();
employeeEntity2.person().set( personEntity );
employeeEntity2.salary().set( 40000 );
employeeEntity2.title().set( "Developer" );
employeeEntity2 = builder.newInstance();
}
{
EntityBuilder<CompanyEntity> builder = unitOfWork.newEntityBuilder( CompanyEntity.class );
companyEntity = builder.instance();
companyEntity.director().set( employeeEntity );
companyEntity.employees().add( 0, employeeEntity );
companyEntity.employees().add( 0, employeeEntity2 );
companyEntity = builder.newInstance();
}
unitOfWork.complete();
}
finally
{
unitOfWork.discard();
}
}
{
UnitOfWork unitOfWork = module.newUnitOfWork();
try
{
companyEntity = unitOfWork.get( companyEntity );
unitOfWork.remove( companyEntity );
unitOfWork.complete();
}
finally
{
unitOfWork.discard();
}
}
{
UnitOfWork unitOfWork = module.newUnitOfWork();
try
{
unitOfWork.get( employeeEntity );
fail( "Should not work" );
unitOfWork.complete();
}
catch( NoSuchEntityException e )
{
unitOfWork.discard();
}
}
{
UnitOfWork unitOfWork = module.newUnitOfWork();
try
{
unitOfWork.get( employeeEntity2 );
fail( "Should not work" );
unitOfWork.complete();
}
catch( NoSuchEntityException e )
{
unitOfWork.discard();
}
}
}