1 /*
2 * Copyright 2003 - 2013 The eFaps Team
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Revision: $Rev$
17 * Last Changed: $Date$
18 * Last Changed By: $Author$
19 */
20
21 package org.efaps.db.print;
22
23 import org.efaps.admin.datamodel.SQLTable;
24 import org.efaps.admin.datamodel.Type;
25 import org.efaps.db.wrapper.SQLSelect;
26
27 /**
28 * Select Part that connects a child tablt ot his parent table.
29 *
30 * @author The eFaps Team
31 * @version $Id$
32 */
33 public class ChildTableSelectPart
34 extends AbstractSelectPart
35 {
36
37 /**
38 * Type this SelectPart belongs to.
39 */
40 private final Type type;
41
42 /**
43 * ChildTable of the main table of the {@link #type}.
44 */
45 private final SQLTable table;
46
47 /**
48 * @param _type type this Type this SelectPart belongs to.
49 * @param _table childtable this SelectPart belongs to
50 */
51 public ChildTableSelectPart(final Type _type,
52 final SQLTable _table)
53 {
54 this.type = _type;
55 this.table = _table;
56 }
57
58 /**
59 * {@inheritDoc}
60 */
61 @Override
62 public Type getType()
63 {
64 return this.type;
65 }
66
67 /**
68 * {@inheritDoc}
69 */
70 @Override
71 public int join(final OneSelect _oneSelect,
72 final SQLSelect _select,
73 final int _relIndex)
74 {
75 Integer ret;
76 final String tableName = this.table.getSqlTable();
77 ret = _oneSelect.getTableIndex(tableName, "ID", _relIndex, null);
78 if (ret == null) {
79 ret = _oneSelect.getNewTableIndex(tableName, "ID", _relIndex, null);
80 _select.leftJoin(tableName, ret, "ID", _relIndex, "ID");
81 }
82 return ret;
83 }
84 }