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;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.efaps.admin.access.AccessTypeEnums;
27 import org.efaps.admin.datamodel.Type;
28 import org.efaps.util.EFapsException;
29
30 /**
31 * PrintQuery is a query uses to get the value for one object, specified by one
32 * instance. The PrintQuery is able to execute various of the parts for the
33 * select from EQL definition.
34 *
35 *
36 * @author The eFaps Team
37 * @version $Id$
38 */
39 public class PrintQuery
40 extends AbstractPrintQuery
41 {
42
43 /**
44 * Instance this PrintQuery is based on.
45 */
46 private final Instance instance;
47
48 /**
49 * Initializes this print query depending on a <code>_type</code> and
50 * <code>_id</code>.
51 *
52 * @param _type type of the eFaps object to print
53 * @param _id id of the eFaps object to print
54 * @throws EFapsException on error
55 */
56 public PrintQuery(final Type _type,
57 final String _id)
58 throws EFapsException
59 {
60 this(Instance.get(_type, _id));
61 }
62
63 /**
64 * Initializes this print query depending on a <code>_type</code> and
65 * <code>_id</code>.
66 *
67 * @param _type type of the eFaps object to print
68 * @param _id id of the eFaps object to print
69 * @throws EFapsException on error
70 */
71 public PrintQuery(final Type _type,
72 final long _id)
73 throws EFapsException
74 {
75 this(Instance.get(_type, _id));
76 }
77
78 /**
79 * Initializes this print query depending on a <code>_type</code> and
80 * <code>_id</code>.
81 *
82 * @param _type type of the eFaps object to print
83 * @param _id id of the eFaps object to print
84 * @throws EFapsException on error
85 */
86 public PrintQuery(final String _type,
87 final String _id)
88 throws EFapsException
89 {
90 this(Instance.get(_type, _id));
91 }
92
93 /**
94 * @param _oid OID of the instance to be updated.
95 * @throws EFapsException on error
96 */
97 public PrintQuery(final String _oid)
98 throws EFapsException
99 {
100 this(Instance.get(_oid));
101 }
102
103 /**
104 * @param _instance instance to be updated.
105 * @throws EFapsException on error
106 */
107 public PrintQuery(final Instance _instance)
108 throws EFapsException
109 {
110 this.instance = _instance;
111 }
112
113 /**
114 * Getter method for instance variable {@link #instance}.
115 *
116 * @return value of instance variable {@link #instance}
117 */
118 public Instance getInstance()
119 {
120 return this.instance;
121 }
122
123 /**
124 * {@inheritDoc}
125 */
126 @Override
127 public Type getMainType()
128 {
129 return this.instance.getType();
130 }
131
132 /**
133 * {@inheritDoc}
134 */
135 @Override
136 public Instance getCurrentInstance()
137 {
138 return this.instance;
139 }
140
141 /**
142 * {@inheritDoc}
143 */
144 @Override
145 public List<Instance> getInstanceList()
146 {
147 final List<Instance> ret = new ArrayList<Instance>();
148 ret.add(this.instance);
149 return ret;
150 }
151
152 /**
153 * {@inheritDoc}
154 */
155 @Override
156 public boolean execute()
157 throws EFapsException
158 {
159 boolean ret = false;
160 if (isMarked4execute()) {
161 if (getMainType().hasAccess(this.instance, AccessTypeEnums.READ.getAccessType())) {
162 ret = executeWithoutAccessCheck();
163 }
164 }
165 return ret;
166 }
167
168 /**
169 * {@inheritDoc}
170 */
171 @Override
172 public boolean isCacheEnabled()
173 {
174 return false;
175 }
176 }