
com.intuit.ipp.query.GenerateQuery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ipp-v3-java-devkit Show documentation
Show all versions of ipp-v3-java-devkit Show documentation
IPP Java V3 DevKit Project - Core
The newest version!
/*******************************************************************************
* Copyright (c) 2017 Intuit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.intuit.ipp.query;
import java.util.Calendar;
import java.util.Date;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatchers;
import com.intuit.ipp.core.IEntity;
import com.intuit.ipp.query.expr.BooleanPath;
import com.intuit.ipp.query.expr.CalendarPath;
import com.intuit.ipp.query.expr.EnumPath;
import com.intuit.ipp.query.expr.NumberPath;
import com.intuit.ipp.query.expr.StringPath;
import com.intuit.ipp.util.Logger;
/**
* Class used to generate the query string
*
*/
public final class GenerateQuery {
/**
* logger instance
*/
private static final org.slf4j.Logger LOG = Logger.getLogger();
/**
* variable LEN_3
*/
private static final int LEN_3 = 3;
/**
* variable path
*/
public static ThreadLocal> path = new ThreadLocal>();
/**
* varriable message
*/
private static QueryMessage message = new QueryMessage();
/**
* variable CLASSNAME_SPLIT_PATTERN
*/
private static final String CLASSNAME_SPLIT_PATTERN = "\\$";
/**
* Constructor to have private modifier as it has only static methods
*/
private GenerateQuery() {
}
/**
*
* @param cl the class
* @return the proxified object
*/
@SuppressWarnings("unchecked")
public static T createQueryEntity(Class cl) {
Class> proxied = null;
if (cl.isInterface()) {
LOG.debug("The given class is interface");
} else {
proxied = new ByteBuddy()
.subclass(cl)
.method(ElementMatchers.not(ElementMatchers.isClone().or(ElementMatchers.isFinalizer()).or(ElementMatchers.isEquals()).or(ElementMatchers.isHashCode()).or(ElementMatchers.isToString())))
.intercept(MethodDelegation.to(new MyMethodInterceptor()))
.make()
.load(GenerateQuery.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
}
try {
return (T) proxied.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
LOG.error(e.getMessage());
throw new RuntimeException(e);
}
}
/**
*
* @param entity the entity
* @return the proxified object
*/
@SuppressWarnings("unchecked")
public static T createQueryEntity(T entity) {
Class> cl = entity.getClass();
return (T) createQueryEntity(cl);
}
/**
* when no handler for specific return type is defined which means properties of that type cannot be inserted in filter expression but can be
* listed in select part, it will return Path
*
* @param ret the object
* @return path the path
*/
public static Path> $(Object ret) {
Path> currentPath = path.get();
path.set(null);
if (currentPath != null) {
return new Path
© 2015 - 2025 Weber Informatics LLC | Privacy Policy