01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com> and
03: * JR Boyens <gnu-jrb[remove] at gmx dot net>
04: * Distributed under the terms of either:
05: * - the common development and distribution license (CDDL), v1.0; or
06: * - the GNU Lesser General Public License, v2.1 or later
07: * $Id: AbstractManyToOneAssociationCollection.java 3716 2007-04-11 06:21:18Z gbevin $
08: */
09: package com.uwyn.rife.database.querymanagers.generic;
10:
11: import java.util.Collection;
12: import java.util.List;
13:
14: import static com.uwyn.rife.database.querymanagers.generic.GenericQueryManagerRelationalUtils.generateManyToOneJoinColumnName;
15:
16: abstract class AbstractManyToOneAssociationCollection<E> implements
17: Collection<E> {
18: private AbstractGenericQueryManager mQueryManager;
19: private int mObjectId;
20: private ManyToOneAssociationDeclaration mDeclaration;
21:
22: AbstractManyToOneAssociationCollection(
23: AbstractGenericQueryManager manager, int objectId,
24: ManyToOneAssociationDeclaration declaration) {
25: mQueryManager = manager;
26: mObjectId = objectId;
27: mDeclaration = declaration;
28: }
29:
30: protected List restoreManyToOneAssociations() {
31: GenericQueryManager association_manager = mQueryManager
32: .createNewManager(mDeclaration.getMainType());
33:
34: RestoreQuery restore_mappings = association_manager
35: .getRestoreQuery().fields(mDeclaration.getMainType())
36: .where(
37: generateManyToOneJoinColumnName(mDeclaration
38: .getMainProperty(), mDeclaration
39: .getMainDeclaration()), "=", mObjectId);
40:
41: // restore the many to one associations
42: return association_manager.restore(restore_mappings);
43: }
44: }
|