This commit is contained in:
adamw 2010-11-11 14:37:19 +01:00
commit b775430385
5 changed files with 29 additions and 12 deletions

View File

@ -65,7 +65,12 @@ public class BasicCollectionInitializor<T extends Collection> extends AbstractCo
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
protected void addToCollection(T collection, Object collectionRow) { protected void addToCollection(T collection, Object collectionRow) {
Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex()); // collectionRow will be the actual object if retrieved from audit relation or middle table
// otherwise it will be a List
Object elementData = collectionRow;
if (collectionRow instanceof java.util.List) {
elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
}
// If the target entity is not audited, the elements may be the entities already, so we have to check // If the target entity is not audited, the elements may be the entities already, so we have to check
// if they are maps or not. // if they are maps or not.

View File

@ -63,13 +63,19 @@ public class ListCollectionInitializor extends AbstractCollectionInitializor<Lis
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
protected void addToCollection(List collection, Object collectionRow) { protected void addToCollection(List collection, Object collectionRow) {
Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex()); // collectionRow will be the actual object if retrieved from audit relation or middle table
// otherwise it will be a List
Object elementData = collectionRow;
Object indexData = collectionRow;
if (collectionRow instanceof java.util.List) {
elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
}
Object element = elementData instanceof Map ? Object element = elementData instanceof Map ?
elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator, elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
(Map<String, Object>) elementData, null, revision) (Map<String, Object>) elementData, null, revision)
: elementData ; : elementData ;
Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator, Object indexObj = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
(Map<String, Object>) indexData, element, revision); (Map<String, Object>) indexData, element, revision);
int index = ((Number) indexObj).intValue(); int index = ((Number) indexObj).intValue();

View File

@ -67,11 +67,17 @@ public class MapCollectionInitializor<T extends Map> extends AbstractCollectionI
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
protected void addToCollection(T collection, Object collectionRow) { protected void addToCollection(T collection, Object collectionRow) {
Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex()); // collectionRow will be the actual object if retrieved from audit relation or middle table
// otherwise it will be a List
Object elementData = collectionRow;
Object indexData = collectionRow;
if (collectionRow instanceof java.util.List) {
elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
}
Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator, Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
(Map<String, Object>) elementData, null, revision); (Map<String, Object>) elementData, null, revision);
Object indexData = ((List) collectionRow).get(indexComponentData.getComponentIndex());
Object index = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator, Object index = indexComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
(Map<String, Object>) indexData, element, revision); (Map<String, Object>) indexData, element, revision);

View File

@ -52,7 +52,7 @@ public final class OneAuditEntityQueryGenerator implements RelationQueryGenerato
/* /*
* The query that we need to create: * The query that we need to create:
* SELECT new list(e) FROM versionsReferencedEntity e * SELECT e FROM versionsReferencedEntity e
* WHERE * WHERE
* (only entities referenced by the association; id_ref_ing = id of the referencing entity) * (only entities referenced by the association; id_ref_ing = id of the referencing entity)
* e.id_ref_ing = :id_ref_ing AND * e.id_ref_ing = :id_ref_ing AND
@ -73,9 +73,9 @@ public final class OneAuditEntityQueryGenerator implements RelationQueryGenerato
String versionsReferencedEntityName = verEntCfg.getAuditEntityName(referencedEntityName); String versionsReferencedEntityName = verEntCfg.getAuditEntityName(referencedEntityName);
// SELECT new list(e) FROM versionsEntity e // SELECT e FROM versionsEntity e
QueryBuilder qb = new QueryBuilder(versionsReferencedEntityName, "e"); QueryBuilder qb = new QueryBuilder(versionsReferencedEntityName, "e");
qb.addProjection("new list", "e", false, false); qb.addProjection(null, "e", false, false);
// WHERE // WHERE
Parameters rootParameters = qb.getRootParameters(); Parameters rootParameters = qb.getRootParameters();
// e.id_ref_ed = :id_ref_ed // e.id_ref_ed = :id_ref_ed

View File

@ -53,7 +53,7 @@ public final class OneEntityQueryGenerator implements RelationQueryGenerator {
/* /*
* The query that we need to create: * The query that we need to create:
* SELECT new list(ee) FROM middleEntity ee WHERE * SELECT ee FROM middleEntity ee WHERE
* (only entities referenced by the association; id_ref_ing = id of the referencing entity) * (only entities referenced by the association; id_ref_ing = id of the referencing entity)
* ee.originalId.id_ref_ing = :id_ref_ing AND * ee.originalId.id_ref_ing = :id_ref_ing AND
* *
@ -73,9 +73,9 @@ public final class OneEntityQueryGenerator implements RelationQueryGenerator {
String revisionPropertyPath = verEntCfg.getRevisionNumberPath(); String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
String originalIdPropertyName = verEntCfg.getOriginalIdPropName(); String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
// SELECT new list(ee) FROM middleEntity ee // SELECT ee FROM middleEntity ee
QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee"); QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
qb.addProjection("new list", "ee", false, false); qb.addProjection(null, "ee", false, false);
// WHERE // WHERE
Parameters rootParameters = qb.getRootParameters(); Parameters rootParameters = qb.getRootParameters();
// ee.originalId.id_ref_ing = :id_ref_ing // ee.originalId.id_ref_ing = :id_ref_ing