1919import java .util .Calendar ;
2020import java .util .Date ;
2121
22+ import net .bytebuddy .ByteBuddy ;
23+ import net .bytebuddy .dynamic .loading .ClassLoadingStrategy ;
24+ import net .bytebuddy .implementation .MethodDelegation ;
25+ import net .bytebuddy .implementation .SuperMethodCall ;
26+ import net .bytebuddy .matcher .ElementMatchers ;
2227import net .sf .cglib .proxy .Callback ;
2328import net .sf .cglib .proxy .CallbackFilter ;
2429import net .sf .cglib .proxy .Enhancer ;
3439
3540/**
3641 * Class used to generate the query string
37- *
42+ *
3843 */
3944public final class GenerateQuery {
4045
4146 /**
4247 * logger instance
4348 */
4449 private static final org .slf4j .Logger LOG = Logger .getLogger ();
45-
50+
4651 /**
4752 * variable LEN_3
4853 */
4954 private static final int LEN_3 = 3 ;
50-
55+
5156 /**
5257 * variable path
5358 */
5459 public static ThreadLocal <Path <?>> path = new ThreadLocal <Path <?>>();
55-
60+
5661 /**
5762 * varriable message
5863 */
@@ -64,53 +69,94 @@ public final class GenerateQuery {
6469 private GenerateQuery () {
6570 }
6671
67- /**
68- * Method to create the query entity for the given class
69- *
70- * @param cl the class
71- * @return the proxified object
72- */
72+ // /**
73+ // * Method to create the query entity for the given class
74+ // *
75+ // * @param cl the class
76+ // * @return the proxified object
77+ // */
78+ // @SuppressWarnings("unchecked")
79+ // public static <T> T createQueryEntity(Class<T> cl) {
80+ // Enhancer enhancer = new Enhancer();
81+ // if (cl.isInterface()) {
82+ // LOG.debug("The given class is interface");
83+ // //enhancer.setInterfaces(new Class[] { cl });
84+ // //enhancer.setCallback(new MyMethodInterceptor());
85+ // } else {
86+ // enhancer.setSuperclass(cl);
87+ // }
88+ // enhancer.setCallbackFilter(CALLBACK_FILTER);
89+ // enhancer.setCallbacks(new Callback[] {NoOp.INSTANCE, new MyMethodInterceptor()});
90+ // return (T) enhancer.create();
91+ // }
92+ //
93+ // /**
94+ // * Method to create the query for the given entity
95+ // *
96+ // * @param entity the entity
97+ // * @return the proxified object
98+ // */
99+ // @SuppressWarnings("unchecked")
100+ // public static <T> T createQueryEntity(T entity) {
101+ // Class<?> cl = entity.getClass();
102+ // Enhancer enhancer = new Enhancer();
103+ // if (cl.isInterface()) {
104+ // LOG.debug("The given entity is interface");
105+ // //enhancer.setInterfaces(new Class[] { cl });
106+ // //enhancer.setCallback(new MyMethodInterceptor());
107+ // } else {
108+ // enhancer.setSuperclass(cl);
109+ // enhancer.setCallbackFilter(CALLBACK_FILTER);
110+ // enhancer.setCallbacks(new Callback[] {NoOp.INSTANCE, new MyMethodInterceptor()});
111+ // }
112+ // return (T) enhancer.create();
113+ // }
114+
115+
73116 @ SuppressWarnings ("unchecked" )
74117 public static <T > T createQueryEntity (Class <T > cl ) {
75- Enhancer enhancer = new Enhancer () ;
118+ Class <?> proxied = null ;
76119 if (cl .isInterface ()) {
77120 LOG .debug ("The given class is interface" );
78- //enhancer.setInterfaces(new Class[] { cl });
79- //enhancer.setCallback(new MyMethodInterceptor());
80121 } else {
81- enhancer .setSuperclass (cl );
122+ proxied = new ByteBuddy ()
123+ .subclass (cl )
124+ .method (ElementMatchers .any ())
125+ .intercept (MethodDelegation .to (new MyMethodInterceptor ()))
126+ .method (ElementMatchers .isClone ().or (ElementMatchers .isFinalizer ()).or (ElementMatchers .isEquals ()).or (ElementMatchers .isHashCode ()).or (ElementMatchers .isToString ()))
127+ .intercept (SuperMethodCall .INSTANCE )
128+ .make ()
129+ .load (cl .getClassLoader (), ClassLoadingStrategy .Default .WRAPPER )
130+ .getLoaded ();
82131 }
83- enhancer .setCallbackFilter (CALLBACK_FILTER );
84- enhancer .setCallbacks (new Callback [] {NoOp .INSTANCE , new MyMethodInterceptor ()});
85- return (T ) enhancer .create ();
132+ return (T ) proxied ;
86133 }
87134
88- /**
89- * Method to create the query for the given entity
90- *
91- * @param entity the entity
92- * @return the proxified object
93- */
94135 @ SuppressWarnings ("unchecked" )
95136 public static <T > T createQueryEntity (T entity ) {
96137 Class <?> cl = entity .getClass ();
97- Enhancer enhancer = new Enhancer () ;
138+ Class <?> proxied = null ;
98139 if (cl .isInterface ()) {
99140 LOG .debug ("The given entity is interface" );
100- //enhancer.setInterfaces(new Class[] { cl });
101- //enhancer.setCallback(new MyMethodInterceptor());
102141 } else {
103- enhancer .setSuperclass (cl );
104- enhancer .setCallbackFilter (CALLBACK_FILTER );
105- enhancer .setCallbacks (new Callback [] {NoOp .INSTANCE , new MyMethodInterceptor ()});
142+ proxied = new ByteBuddy ()
143+ .subclass (cl )
144+ .method (ElementMatchers .any ())
145+ .intercept (MethodDelegation .to (new MyMethodInterceptor ()))
146+ .method (ElementMatchers .isClone ().or (ElementMatchers .isFinalizer ()).or (ElementMatchers .isEquals ()).or (ElementMatchers .isHashCode ()).or (ElementMatchers .isToString ()))
147+ .intercept (SuperMethodCall .INSTANCE )
148+ .make ()
149+ .load (cl .getClassLoader (), ClassLoadingStrategy .Default .WRAPPER )
150+ .getLoaded ();
106151 }
107- return (T ) enhancer . create () ;
152+ return (T ) proxied ;
108153 }
109154
155+
110156 /**
111157 * when no handler for specific return type is defined which means properties of that type cannot be inserted in filter expression but can be
112158 * listed in select part, it will return Path
113- *
159+ *
114160 * @param ret the object
115161 * @return path the path
116162 */
@@ -129,7 +175,7 @@ public static <T> T createQueryEntity(T entity) {
129175 /**
130176 * When return type is Calendar, it will create CalendarPath which will expose filter methods accepting java.util.Calendar, java.util.Date and
131177 * java.sql.Date
132- *
178+ *
133179 * @param ret
134180 * @return
135181 */
@@ -141,7 +187,7 @@ public static <T> T createQueryEntity(T entity) {
141187
142188 /**
143189 * Method to get the calendar path
144- *
190+ *
145191 * @param ret the date
146192 * @return CalendarPath the calendar path
147193 */
@@ -153,7 +199,7 @@ public static <T> T createQueryEntity(T entity) {
153199
154200 /**
155201 * When return type is String, it will create StringPath which will expose filter methods accepting only String
156- *
202+ *
157203 * @param ret the string
158204 * @return StringPath the string path
159205 */
@@ -165,7 +211,7 @@ public static <T> T createQueryEntity(T entity) {
165211
166212 /**
167213 * Method to get the number path
168- *
214+ *
169215 * @param ret the number
170216 * @return NumberPath the number path
171217 */
@@ -177,7 +223,7 @@ public static <T> T createQueryEntity(T entity) {
177223
178224 /**
179225 * Method to get the boolean path
180- *
226+ *
181227 * @param ret the boolean
182228 * @return BooleanPath the boolean path
183229 */
@@ -189,7 +235,7 @@ public static <T> T createQueryEntity(T entity) {
189235
190236 /**
191237 * Method to get the Enum path
192- *
238+ *
193239 * @param ret the enum
194240 * @return EnumPath the enum path
195241 */
@@ -201,7 +247,7 @@ public static <T> T createQueryEntity(T entity) {
201247
202248 /**
203249 * Method to get the optional syntax
204- *
250+ *
205251 * @param path the path
206252 * @param pathlist the path list
207253 * @return OptionalSyntax the optional syntax
@@ -222,7 +268,7 @@ public static <T extends IEntity> OptionalSyntax select(Path<?> path, Path<?>...
222268
223269 /**
224270 * Method to get the optional syntax for the given entity
225- *
271+ *
226272 * @param entity the entity
227273 * @return OptionalSyntax the optional syntax
228274 */
@@ -240,7 +286,7 @@ public static <T extends IEntity> OptionalSyntax selectCount(T entity) {
240286
241287 /**
242288 * Method to get the query message
243- *
289+ *
244290 * @return QueryMessage the query message
245291 */
246292 public static QueryMessage getMessage () {
@@ -249,7 +295,7 @@ public static QueryMessage getMessage() {
249295
250296 /**
251297 * Method to set the query message
252- *
298+ *
253299 * @param mess the query message
254300 */
255301 public static void setMessage (QueryMessage mess ) {
0 commit comments