use of org.qi4j.api.entity.EntityBuilder in project qi4j-sdk by Qi4j.
the class AssociationTest method testAssociation.
@Test
public void testAssociation() {
UnitOfWork unitOfWork = module.newUnitOfWork();
try {
Company company = unitOfWork.newEntity(Company.class);
Assert.assertEquals("Company Name Default", "A Company", company.name().get());
{
EntityBuilder<Company> builder = unitOfWork.newEntityBuilder(Company.class);
final Company companyPrototype = builder.instance();
companyPrototype.name().set("JayWay");
company = builder.newInstance();
Assert.assertEquals("Company Name ", "JayWay", company.name().get());
}
company.name().set("Jayway");
Assert.assertEquals("Company Name ", "Jayway", company.name().get());
System.out.println("Name is:" + company.name().get());
EntityBuilder<Person> builder = unitOfWork.newEntityBuilder(Person.class);
builder.instance().name().set("Rickard");
Person rickard = builder.newInstance();
builder = unitOfWork.newEntityBuilder(Person.class);
builder.instance().name().set("Niclas");
builder.instance().friend().set(rickard);
Person niclas = builder.newInstance();
niclas.members().add(rickard);
company.employees().add(0, rickard);
for (Employer employer : rickard.employers()) {
System.out.println(((Nameable) employer).name());
}
Assert.assertEquals(niclas.friend().get(), rickard);
Assert.assertEquals(niclas.members().get(0), rickard);
} finally {
unitOfWork.discard();
}
}
use of org.qi4j.api.entity.EntityBuilder in project qi4j-sdk by Qi4j.
the class LoggingServiceMixin method createLogRecord.
private void createLogRecord(UnitOfWork uow, LogType type, Composite composite, String category, String message, List<Serializable> params) {
if (composite instanceof ServiceComposite) {
EntityBuilder<ServiceLogRecord> builder = uow.newEntityBuilder(ServiceLogRecord.class);
ServiceLogRecord state = builder.instance();
setStandardStuff(type, composite, category, message, state, params);
state.source().set(((ServiceComposite) composite).identity().get());
ServiceLogRecord slr = builder.newInstance();
} else if (composite instanceof EntityComposite) {
EntityBuilder<EntityLogRecord> builder = uow.newEntityBuilder(EntityLogRecord.class);
EntityLogRecord state = builder.instance();
setStandardStuff(type, composite, category, message, state, params);
state.source().set((EntityComposite) composite);
EntityLogRecord elr = builder.newInstance();
} else {
EntityBuilder<CompositeLogRecord> builder = uow.newEntityBuilder(CompositeLogRecord.class);
CompositeLogRecord state = builder.instance();
setStandardStuff(type, composite, category, message, state, params);
state.source().set(composite);
CompositeLogRecord clr = builder.newInstance();
}
}
Aggregations