use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.
the class PropertiesPanel method createData.
/**
* Create table table or properties using the supplied query
*
* @param query the Query
*
* @return TableModel
*/
protected TableModel createData(Query query) {
DefaultTableModel model = new DefaultTableModel();
for (Object qObj : query) {
AssociationStateHolder state = qi4jspi.stateOf((EntityComposite) qObj);
EntityDescriptor descriptor = qi4jspi.entityDescriptorFor((EntityComposite) qObj);
// genereate column, first time only
if (model.getColumnCount() < 1) {
for (PropertyDescriptor persistentPropertyDescriptor : descriptor.state().properties()) {
model.addColumn(persistentPropertyDescriptor.qualifiedName().name());
}
}
Object[] rowData = new Object[model.getColumnCount()];
int i = 0;
for (PropertyDescriptor persistentPropertyDescriptor : descriptor.state().properties()) {
rowData[i++] = state.propertyFor(persistentPropertyDescriptor.accessor());
}
model.addRow(rowData);
}
return model;
}
use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.
the class AssociationFunction method map.
@Override
public Association<T> map(Composite entity) {
try {
Object target = entity;
if (traversedAssociation != null) {
Association<?> association = traversedAssociation.map(entity);
if (association == null) {
return null;
}
target = association.get();
} else if (traversedManyAssociation != null) {
throw new IllegalArgumentException("Cannot evaluate a ManyAssociation");
} else if (traversedNamedAssociation != null) {
throw new IllegalArgumentException("Cannot evaluate a NamedAssociation");
}
if (target == null) {
return null;
}
CompositeInstance handler = (CompositeInstance) Proxy.getInvocationHandler(target);
return ((AssociationStateHolder) handler.state()).associationFor(accessor);
} catch (IllegalArgumentException e) {
throw e;
} catch (Throwable e) {
throw new IllegalArgumentException(e);
}
}
use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.
the class NamedAssociationFunction method map.
@Override
public NamedAssociation<T> map(Composite entity) {
try {
Object target = entity;
if (traversedAssociation != null) {
target = traversedAssociation.map(entity).get();
}
if (traversedManyAssociation != null) {
throw new IllegalArgumentException("Cannot traverse ManyAssociations");
}
if (traversedNamedAssociation != null) {
throw new IllegalArgumentException("Cannot traverse NamedAssociations");
}
CompositeInstance handler = (CompositeInstance) Proxy.getInvocationHandler(target);
return ((AssociationStateHolder) handler.state()).namedAssociationFor(accessor);
} catch (IllegalArgumentException e) {
throw e;
} catch (Throwable e) {
throw new IllegalArgumentException(e);
}
}
use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.
the class Qi4jSPITest method givenEntityWhenGettingStateThenGetCorrectState.
@Test
public void givenEntityWhenGettingStateThenGetCorrectState() throws Exception {
UnitOfWork unitOfWork = module.newUnitOfWork();
TestEntity testEntity;
try {
EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder(TestEntity.class);
testEntity = builder.newInstance();
AssociationStateHolder state = spi.stateOf(testEntity);
validateState(state, spi.entityDescriptorFor(testEntity));
unitOfWork.complete();
} finally {
unitOfWork.discard();
}
UnitOfWork uow = module.newUnitOfWork();
try {
testEntity = uow.get(testEntity);
validateState(spi.stateOf(testEntity), spi.entityDescriptorFor(testEntity));
uow.complete();
} finally {
uow.discard();
}
}
use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.
the class ValueEqualityTest method givenValuesOfSameTypesAndDifferentStateWhenTestingValueStateEqualityExpectNotEquals.
@Test
public void givenValuesOfSameTypesAndDifferentStateWhenTestingValueStateEqualityExpectNotEquals() {
Some some = buildSomeValue(module);
AssociationStateHolder someState = qi4j.spi().stateOf((ValueComposite) some);
Some some2 = buildSomeValueWithDifferentState(module);
AssociationStateHolder some2State = qi4j.spi().stateOf((ValueComposite) some2);
assertThat("ValueStates not equal", someState, not(equalTo(some2State)));
assertThat("ValueStates hashcode not equal", someState.hashCode(), not(equalTo(some2State.hashCode())));
}
Aggregations