View Javadoc
1   /*
2    * Copyright 2010 James Pether Sörling
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   *	$Id$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.service.impl;
20  
21  import java.io.Serializable;
22  import java.util.List;
23  
24  import javax.persistence.metamodel.SingularAttribute;
25  
26  import com.hack23.cia.service.api.DataContainer;
27  import com.hack23.cia.service.data.api.DataViewer;
28  
29  /**
30   * The Class GenericDataContainer.
31   *
32   * @param <T>
33   *            the generic type
34   * @param <ID>
35   *            the generic type
36   */
37  final class GenericDataContainer<T extends Serializable, I extends Serializable> implements
38  DataContainer<T, I> {
39  
40  
41  
42  	/** The data proxy. */
43  	private final DataViewer dataProxy;
44  
45  	/** The clazz. */
46  	private final Class<T> clazz;
47  
48  	/**
49  	 * Instantiates a new generic data container.
50  	 *
51  	 * @param clazz
52  	 *            the clazz
53  	 * @param dataViewer
54  	 *            the data viewer
55  	 */
56  	GenericDataContainer(final Class<T> clazz, final DataViewer dataViewer) {
57  		this.clazz = clazz;
58  		dataProxy = dataViewer;
59  	}
60  
61  	@Override
62  	public <T, V> T findByQueryProperty(final Class<T> clazz,
63  			final SingularAttribute<T, ? extends Object> property,
64  			final Class<V> clazz2,
65  			final SingularAttribute<V, ? extends Object> property2, final Object value) {
66  		return dataProxy.findByQueryProperty(clazz, property, clazz2, property2, value);
67  	}
68  
69  	@Override
70  	public <T, V> List<T> findListByEmbeddedProperty(final Class<T> clazz,
71  			final SingularAttribute<T, V> property,
72  			final Class<V> clazz2,
73  			final SingularAttribute<V, ? extends Object> property2, final Object value) {
74  		return dataProxy.findListByEmbeddedProperty(clazz, property, clazz2, property2, value);
75  	}
76  
77  
78  
79  	@Override
80  	public List<T> findListByProperty(final Object[] values,
81  			final SingularAttribute<T, ? extends Object>... properties) {
82  		return dataProxy.findListByProperty(clazz, values, properties);
83  	}
84  
85  	@Override
86  	public <T, V> List<T> findOrderedByPropertyListByEmbeddedProperty(final Class<T> clazz, final SingularAttribute<T, V> property,
87  			final Class<V> clazz2, final SingularAttribute<V, ? extends Object> property2, final Object value,
88  			final SingularAttribute<T, ? extends Object> orderByProperty) {
89  		return dataProxy.findOrderedByPropertyListByEmbeddedProperty(clazz,property,clazz2,property2,value,orderByProperty);
90  	}
91  
92  	@Override
93  	public <T, V> List<T> findOrderedListByEmbeddedProperty(final Class<T> clazz, final SingularAttribute<T, V> property,
94  			final Class<V> clazz2, final SingularAttribute<V, ? extends Object> property2, final Object value,
95  			final SingularAttribute<V, ? extends Object> orderByProperty) {
96  		return dataProxy.findOrderedListByEmbeddedProperty(clazz,property,clazz2,property2,value,orderByProperty);
97  	}
98  
99  	@Override
100 	public List<T> findOrderedListByProperty(final SingularAttribute<T, ? extends Object> property, final Object value,
101 			final SingularAttribute<T, ? extends Object> orderByProperty) {
102 		return dataProxy.findOrderedListByProperty(clazz,property,value,orderByProperty);
103 	}
104 
105 	@Override
106 	public List<T> findOrderedListByProperty(final SingularAttribute<T, ? extends Object> orderByProperty, final Object[] values,
107 			final SingularAttribute<T, ? extends Object>... properties) {
108 		return dataProxy.findOrderedListByProperty(clazz,orderByProperty,values, properties);
109 	}
110 
111 	@Override
112 	public List<T> getAll() {
113 		return dataProxy.getAll(clazz);
114 	}
115 
116 	@Override
117 	public List<T> getAllBy(
118 			final SingularAttribute<T, ? extends Object> property,
119 			final Object value) {
120 		return dataProxy.findListByProperty(clazz, property, value);
121 	}
122 
123 	@Override
124 	public List<T> getAllOrderBy(final SingularAttribute<T, ? extends Object> property) {
125 		return dataProxy.getAllOrderBy(clazz,property);
126 	}
127 
128 	@Override
129 	public T load(final I id) {
130 		return dataProxy.load(clazz, id);
131 
132 	}
133 
134 	@Override
135 	public List<T> getPage(final int pageNr, final int resultPerPage) {
136 		return dataProxy.getPage(clazz,pageNr, resultPerPage);
137 	}
138 
139 	@Override
140 	public List<T> getPageOrderBy(final int pageNr, final int resultPerPage, final SingularAttribute<T, ? extends Object> orderBy) {
141 		return dataProxy.getPageOrderBy(clazz,pageNr, resultPerPage, orderBy);
142 	}
143 
144 	@Override
145 	public Long getSize() {
146 		return dataProxy.getSize(clazz);
147 	}
148 
149 }