Skip to content

Commit 2274df6

Browse files
author
Xiang Zhong
committed
Change method signature and refactor function call
1 parent 1c7bf6c commit 2274df6

File tree

5 files changed

+44
-54
lines changed

5 files changed

+44
-54
lines changed

ipp-v3-java-devkit/src/main/java/com/intuit/ipp/query/GenerateQuery.java

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public final class GenerateQuery {
5757
*/
5858
private static QueryMessage message = new QueryMessage();
5959

60+
/**
61+
* variable CLASSNAME_SPLIT_PATTERN
62+
*/
63+
private static final String CLASSNAME_SPLIT_PATTERN = "\\$";
64+
6065
/**
6166
* Constructor to have private modifier as it has only static methods
6267
*/
@@ -69,7 +74,7 @@ private GenerateQuery() {
6974
* @return the proxified object
7075
*/
7176
@SuppressWarnings("unchecked")
72-
public static <T> T createQueryEntity(Class<T> cl) {
77+
public static <T> T createQueryEntity(Class<T> cl) throws InstantiationException, IllegalAccessException {
7378
Class<?> proxied = null;
7479
if (cl.isInterface()) {
7580
LOG.debug("The given class is interface");
@@ -82,11 +87,7 @@ public static <T> T createQueryEntity(Class<T> cl) {
8287
.load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
8388
.getLoaded();
8489
}
85-
try {
86-
return (T) proxied.newInstance();
87-
} catch(Exception exception) {
88-
throw new RuntimeException(exception);
89-
}
90+
return (T) proxied.newInstance();
9091
}
9192

9293
/**
@@ -95,25 +96,9 @@ public static <T> T createQueryEntity(Class<T> cl) {
9596
* @return the proxified object
9697
*/
9798
@SuppressWarnings("unchecked")
98-
public static <T> T createQueryEntity(T entity) {
99+
public static <T> T createQueryEntity(T entity) throws InstantiationException, IllegalAccessException {
99100
Class<?> cl = entity.getClass();
100-
Class<?> proxied = null;
101-
if (cl.isInterface()) {
102-
LOG.debug("The given entity is interface");
103-
} else {
104-
proxied = new ByteBuddy()
105-
.subclass(cl)
106-
.method(ElementMatchers.not(ElementMatchers.isClone().or(ElementMatchers.isFinalizer()).or(ElementMatchers.isEquals()).or(ElementMatchers.isHashCode()).or(ElementMatchers.isToString())))
107-
.intercept(MethodDelegation.to(new MyMethodInterceptor()))
108-
.make()
109-
.load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
110-
.getLoaded();
111-
}
112-
try {
113-
return (T) proxied.newInstance();
114-
} catch(Exception exception) {
115-
throw new RuntimeException(exception);
116-
}
101+
return (T) createQueryEntity(cl);
117102
}
118103

119104

@@ -131,7 +116,7 @@ public static <T> T createQueryEntity(T entity) {
131116
return new Path<Object>(currentPath.getPathString().concat(".*"), currentPath.getEntity());
132117
} else {
133118
String name = ret.getClass().getSimpleName();
134-
String[] extracted = name.split("\\$");
119+
String[] extracted = name.split(CLASSNAME_SPLIT_PATTERN);
135120
return new Path<Object>("*", extracted[0]);
136121
}
137122
}
@@ -240,7 +225,7 @@ public static <T extends IEntity> OptionalSyntax selectCount(T entity) {
240225
resetQueryMessage();
241226
getMessage().setSQL("SELECT");
242227
String name = entity.getClass().getSimpleName();
243-
String extracted[] = name.split("\\$");
228+
String extracted[] = name.split(CLASSNAME_SPLIT_PATTERN);
244229
getMessage().setCount(true);
245230
if (extracted.length == LEN_3) {
246231
getMessage().setEntity(extracted[0]);

ipp-v3-java-devkit/src/main/java/com/intuit/ipp/query/MyMethodInterceptor.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public class MyMethodInterceptor {
5353
*/
5454
private static final int NUM_2 = 2;
5555

56+
/**
57+
* variable CLASSNAME_SPLIT_PATTERN
58+
*/
59+
private static final String CLASSNAME_SPLIT_PATTERN = "\\$";
60+
5661
/**
5762
* Constructor MyMethodInterceptor
5863
*
@@ -61,7 +66,7 @@ public MyMethodInterceptor() {
6166
}
6267

6368
@RuntimeType
64-
public Object intercept(@This Object proxyObject, @Origin Method method, @AllArguments Object[] methodArgs, @SuperMethod(nullIfImpossible = true) Method superMethod) throws FMSException {
69+
public Object intercept(@This Object proxyObject, @Origin Method method, @AllArguments Object[] methodArgs, @SuperMethod(nullIfImpossible = true) Method superMethod) throws FMSException, InstantiationException, IllegalAccessException {
6570

6671
if (GenerateQuery.path.get() == null) {
6772
GenerateQuery.path.set(new Path<Object>(extractPropertyName(method), extractEntity(proxyObject)));
@@ -79,7 +84,7 @@ public Object intercept(@This Object proxyObject, @Origin Method method, @AllArg
7984
*/
8085
private String extractEntity(Object obj) {
8186
String name = obj.getClass().getSimpleName();
82-
String[] extracted = name.split("\\$");
87+
String[] extracted = name.split(CLASSNAME_SPLIT_PATTERN);
8388
if (extracted.length == NUM_3) {
8489
return extracted[0];
8590
}
@@ -107,7 +112,7 @@ protected String extractPropertyName(Method method) {
107112
*/
108113
@SuppressWarnings("unchecked")
109114
public <T> T createInstance(Object proxyObject, Method method, Object[] methodArgs, Method superMethod)
110-
throws FMSException {
115+
throws FMSException, InstantiationException, IllegalAccessException {
111116
Object obj = null;
112117
Class<?> type = method.getReturnType();
113118
if (String.class.equals(type)) {

ipp-v3-java-devkit/src/test/java/com/intuit/ipp/query/QueryTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void setCalendar() {
5555
}
5656

5757
@Test
58-
public void testQuery_datatypes() {
58+
public void testQuery_datatypes() throws InstantiationException, IllegalAccessException {
5959
Data data = GenerateQuery.createQueryEntity(new Data());
6060
String query = select($(data.getStringData()), $(data.getIntData()), $(data.getByteData()), $(data.getShortData()), $(data.getLongData()),
6161
$(data.getFloatData()), $(data.getDoubleData()), $(data.getCalendarData()), $(data.isBooleanData()), $(data.getDateData()),
@@ -69,7 +69,7 @@ public void testQuery_datatypes() {
6969
}
7070

7171
@Test
72-
public void testQuery_eq() {
72+
public void testQuery_eq() throws InstantiationException, IllegalAccessException {
7373
Data data = GenerateQuery.createQueryEntity(Data.class);
7474
String query = select($(data)).where($(data.getStringData()).eq("StringValue"), $(data.getIntData()).eq(10),
7575
$(data.getByteData()).eq((byte) 10), $(data.getShortData()).eq((short) 10), $(data.getLongData()).eq((long) 10),
@@ -82,7 +82,7 @@ public void testQuery_eq() {
8282
}
8383

8484
@Test
85-
public void testQuery_eqUsingInvalidEnum() {
85+
public void testQuery_eqUsingInvalidEnum() throws InstantiationException, IllegalAccessException {
8686
Data data = GenerateQuery.createQueryEntity(Data.class);
8787
String query = select($(data)).where($(data.getStringData()).eq("StringValue"), $(data.getIntData()).eq(10),
8888
$(data.getByteData()).eq((byte) 10), $(data.getShortData()).eq((short) 10), $(data.getLongData()).eq((long) 10),
@@ -95,7 +95,7 @@ public void testQuery_eqUsingInvalidEnum() {
9595
}
9696

9797
@Test
98-
public void testQuery_neq() {
98+
public void testQuery_neq() throws InstantiationException, IllegalAccessException {
9999
Data data = GenerateQuery.createQueryEntity(Data.class);
100100
String query = select($(data))
101101
.where($(data.getStringData()).neq("StringValue"), $(data.getIntData()).neq(10), $(data.getByteData()).neq((byte) 10),
@@ -108,7 +108,7 @@ public void testQuery_neq() {
108108
}
109109

110110
@Test
111-
public void testQuery_lt() {
111+
public void testQuery_lt() throws InstantiationException, IllegalAccessException {
112112
Data data = GenerateQuery.createQueryEntity(Data.class);
113113
String query = select($(data)).where($(data.getStringData()).lt("StringValue"), $(data.getIntData()).lt(10),
114114
$(data.getByteData()).lt((byte) 10), $(data.getShortData()).lt((short) 10), $(data.getLongData()).lt((long) 10),
@@ -120,7 +120,7 @@ public void testQuery_lt() {
120120
}
121121

122122
@Test
123-
public void testQuery_lte() {
123+
public void testQuery_lte() throws InstantiationException, IllegalAccessException {
124124
Data data = GenerateQuery.createQueryEntity(Data.class);
125125
String query = select($(data)).where($(data.getStringData()).lte("StringValue"), $(data.getIntData()).lte(10),
126126
$(data.getByteData()).lte((byte) 10), $(data.getShortData()).lte((short) 10), $(data.getLongData()).lte((long) 10),
@@ -132,7 +132,7 @@ public void testQuery_lte() {
132132
}
133133

134134
@Test
135-
public void testQuery_gt() {
135+
public void testQuery_gt() throws InstantiationException, IllegalAccessException {
136136
Data data = GenerateQuery.createQueryEntity(Data.class);
137137
String query = select($(data)).where($(data.getStringData()).gt("StringValue"), $(data.getIntData()).gt(10),
138138
$(data.getByteData()).gt((byte) 10), $(data.getShortData()).gt((short) 10), $(data.getLongData()).gt((long) 10),
@@ -144,7 +144,7 @@ public void testQuery_gt() {
144144
}
145145

146146
@Test
147-
public void testQuery_gte() {
147+
public void testQuery_gte() throws InstantiationException, IllegalAccessException {
148148
Data data = GenerateQuery.createQueryEntity(Data.class);
149149
String query = select($(data)).where($(data.getStringData()).gte("StringValue"), $(data.getIntData()).gte(10),
150150
$(data.getByteData()).gte((byte) 10), $(data.getShortData()).gte((short) 10), $(data.getLongData()).gte((long) 10),
@@ -156,7 +156,7 @@ public void testQuery_gte() {
156156
}
157157

158158
@Test
159-
public void testQuery_in() {
159+
public void testQuery_in() throws InstantiationException, IllegalAccessException {
160160
Data data = GenerateQuery.createQueryEntity(Data.class);
161161
String query = select($(data)).where($(data.getStringData()).in(new String[] { "StringValue1", "StringValue2" }),
162162
$(data.getIntData()).in(new Integer[] { 10, 20 }), $(data.getByteData()).in(new Byte[] { 10, 20 }),
@@ -171,7 +171,7 @@ public void testQuery_in() {
171171
}
172172

173173
@Test
174-
public void testQuery_between() {
174+
public void testQuery_between() throws InstantiationException, IllegalAccessException {
175175
Data data = GenerateQuery.createQueryEntity(Data.class);
176176
String query = select($(data)).where(
177177
$(data.getStringData()).between("StringValue1", "StringValue2"),
@@ -190,7 +190,7 @@ public void testQuery_between() {
190190
}
191191

192192
@Test
193-
public void testQuery_like() {
193+
public void testQuery_like() throws InstantiationException, IllegalAccessException {
194194
Data data = GenerateQuery.createQueryEntity(Data.class);
195195
String query = select($(data)).where($(data.getStringData()).startsWith("StringValue")).generate();
196196
String expectedQuery = "SELECT * FROM Data WHERE StringData LIKE 'StringValue%'";
@@ -209,7 +209,7 @@ public void testQuery_like() {
209209
}
210210

211211
@Test
212-
public void testQuery_select() {
212+
public void testQuery_select() throws InstantiationException, IllegalAccessException {
213213
Data data = GenerateQuery.createQueryEntity(Data.class);
214214
String query = select($(data.getSubData())).generate();
215215
String expectedQuery = "SELECT SubData.* FROM Data";
@@ -218,7 +218,7 @@ public void testQuery_select() {
218218
}
219219

220220
@Test
221-
public void testQuery_orderby() {
221+
public void testQuery_orderby() throws InstantiationException, IllegalAccessException {
222222
Data data = GenerateQuery.createQueryEntity(Data.class);
223223
String query = select($(data)).orderByAscending($(data.getStringData()), $(data.getIntData())).generate();
224224
String expectedQuery = "SELECT * FROM Data ORDERBY StringData, IntData ASC";
@@ -234,7 +234,7 @@ public void testQuery_orderby() {
234234
}
235235

236236
@Test
237-
public void testQuery_not() {
237+
public void testQuery_not() throws InstantiationException, IllegalAccessException {
238238
Data data = GenerateQuery.createQueryEntity(Data.class);
239239
String query = select($(data)).where($(data.getIntData()).eq(10).negate()).generate();
240240
String expectedQuery = "SELECT * FROM Data WHERE NOT IntData = '10'";
@@ -243,7 +243,7 @@ public void testQuery_not() {
243243
}
244244

245245
@Test
246-
public void testQuery_pagination() {
246+
public void testQuery_pagination() throws InstantiationException, IllegalAccessException {
247247
Data data = GenerateQuery.createQueryEntity(Data.class);
248248
String query = select($(data)).skip(10).generate();
249249
String expectedQuery = "SELECT * FROM Data STARTPOSITION 11";
@@ -262,7 +262,7 @@ public void testQuery_pagination() {
262262
}
263263

264264
@Test
265-
public void testQuery_count() {
265+
public void testQuery_count() throws InstantiationException, IllegalAccessException {
266266
Data data = GenerateQuery.createQueryEntity(Data.class);
267267
String query = selectCount(data).generate();
268268
String expectedQuery = "SELECT count(*) FROM Data";
@@ -271,7 +271,7 @@ public void testQuery_count() {
271271
}
272272

273273
@Test
274-
public void testQuery_calendar() {
274+
public void testQuery_calendar() throws InstantiationException, IllegalAccessException {
275275
Data data = GenerateQuery.createQueryEntity(Data.class);
276276

277277
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
@@ -292,7 +292,7 @@ public void testQuery_calendar() {
292292
}
293293

294294
@Test
295-
public void testQuery_line() {
295+
public void testQuery_line() throws InstantiationException, IllegalAccessException {
296296
Invoice data = GenerateQuery.createQueryEntity(Invoice.class);
297297
String query = select($(data.getLine())).generate();
298298
String expectedQuery = "SELECT Line.* FROM Invoice";

ipp-v3-java-devkit/src/test/java/com/intuit/ipp/services/DataServiceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public void testFindAll() throws FMSException {
183183
}
184184

185185
@Test (enabled = false)
186-
public void testExecuteQuery_get() throws FMSException {
186+
public void testExecuteQuery_get() throws FMSException, InstantiationException, IllegalAccessException {
187187
Customer customer = GenerateQuery.createQueryEntity(Customer.class);
188188
String query = select($(customer.getId()), $(customer.getDisplayName())).where($(customer.getId()).eq(EntityCreator.customer.getId())).generate();
189189

@@ -197,7 +197,7 @@ public void testExecuteQuery_get() throws FMSException {
197197
}
198198

199199
@Test(enabled = false)
200-
public void testExecuteQuery_post() throws FMSException {
200+
public void testExecuteQuery_post() throws FMSException, InstantiationException, IllegalAccessException {
201201
Customer customer = GenerateQuery.createQueryEntity(Customer.class);
202202
String query = select($(customer.getId()), $(customer.getDisplayName())).where($(customer.getId()).eq(EntityCreator.customer.getId())).generate();
203203
String newQuery = " ";
@@ -214,7 +214,7 @@ public void testExecuteQuery_post() throws FMSException {
214214
}
215215

216216
@Test(enabled = false)
217-
public void testExecuteQuery_postCompression() throws FMSException {
217+
public void testExecuteQuery_postCompression() throws FMSException, InstantiationException, IllegalAccessException {
218218
Customer customer = GenerateQuery.createQueryEntity(Customer.class);
219219
String query = select($(customer.getId()), $(customer.getDisplayName())).where($(customer.getId()).eq(EntityCreator.customer.getId())).generate();
220220
String newQuery = " ";
@@ -249,7 +249,7 @@ public void testExecuteQuery_invalidQuery() {
249249
}
250250

251251
@Test(enabled = false)
252-
public void testExecuteBatch() throws FMSException {
252+
public void testExecuteBatch() throws FMSException, InstantiationException, IllegalAccessException {
253253
BatchOperation batchOperation = new BatchOperation();
254254

255255
Customer customer = new Customer();
@@ -296,7 +296,7 @@ public void testExecuteBatch_Entity() throws FMSException {
296296
}
297297

298298
@Test (enabled = false)
299-
public void testExecuteBatch_Query() throws FMSException {
299+
public void testExecuteBatch_Query() throws FMSException, InstantiationException, IllegalAccessException {
300300
BatchOperation batchOperation = new BatchOperation();
301301

302302
Customer c = GenerateQuery.createQueryEntity(Customer.class);

ipp-v3-java-devkit/src/test/java/com/intuit/ipp/services/QBODataServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public void testPurchaseQuery_JsonResponse() throws FMSException {
498498
}
499499

500500
@Test (enabled = false)
501-
public void testExecuteQuery_get() throws FMSException {
501+
public void testExecuteQuery_get() throws FMSException, InstantiationException, IllegalAccessException {
502502
Customer customerIn = getCustomer();
503503
Customer customer = GenerateQuery.createQueryEntity(Customer.class);
504504
String query = select($(customer.getId()), $(customer.getDisplayName())).where($(customer.getId()).eq(customerIn.getId())).generate();
@@ -513,7 +513,7 @@ public void testExecuteQuery_get() throws FMSException {
513513
}
514514

515515
@Test(enabled=false)
516-
public void testExecuteQuery_post() throws FMSException {
516+
public void testExecuteQuery_post() throws FMSException, InstantiationException, IllegalAccessException {
517517
Customer customerIn = getCustomer();
518518
Customer customer = GenerateQuery.createQueryEntity(Customer.class);
519519
String query = select($(customer.getId()), $(customer.getDisplayName())).where($(customer.getId()).eq(customerIn.getId())).generate();

0 commit comments

Comments
 (0)