org.kie.internal.query.data.QueryParameters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kie-internal Show documentation
Show all versions of kie-internal Show documentation
The Drools and jBPM internal API which is NOT backwards compatible between releases.
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* 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 org.kie.internal.query.data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.kie.internal.jaxb.StringKeyObjectValueMapXmlAdapter;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Deprecated // see org.jbpm.query.jpa.data.QueryWhere and org.jbpm.query.jpa.data.QueryCriteria
public class QueryParameters {
@XmlTransient
private boolean union = true;
@XmlTransient
private boolean like = false;
@XmlTransient
private boolean range = false;
@XmlElement
@XmlJavaTypeAdapter(StringKeyObjectValueMapXmlAdapter.class)
private Map> unionParameters = null;
@XmlElement
@XmlJavaTypeAdapter(StringKeyObjectValueMapXmlAdapter.class)
private Map> intersectParameters = null;
@XmlElement
@XmlJavaTypeAdapter(StringKeyObjectValueMapXmlAdapter.class)
private Map> unionRegexParameters = null;
@XmlElement
@XmlJavaTypeAdapter(StringKeyObjectValueMapXmlAdapter.class)
private Map> intersectRegexParameters = null;
@XmlElement
@XmlJavaTypeAdapter(StringKeyObjectValueMapXmlAdapter.class)
private Map> unionRangeParameters = null;
@XmlElement
@XmlJavaTypeAdapter(StringKeyObjectValueMapXmlAdapter.class)
private Map> intersectRangeParameters = null;
public QueryParameters() {
// JAXB constructor
}
// getters
public Map> getUnionParameters() {
if( unionParameters == null ) {
unionParameters = new HashMap<>();
}
return unionParameters;
}
public boolean unionParametersAreEmpty() {
return unionParameters == null ? true : unionParameters.isEmpty();
}
public Map> getIntersectParameters() {
if( intersectParameters == null ) {
intersectParameters = new HashMap<>();
}
return intersectParameters;
}
public boolean intersectParametersAreEmpty() {
return intersectParameters == null ? true : intersectParameters.isEmpty();
}
public Map> getUnionRegexParameters() {
if( unionRegexParameters == null ) {
unionRegexParameters = new HashMap<>();
}
return unionRegexParameters;
}
public boolean unionRegexParametersAreEmpty() {
return unionRegexParameters == null ? true : unionRegexParameters.isEmpty();
}
public Map> getIntersectRegexParameters() {
if( intersectRegexParameters == null ) {
intersectRegexParameters = new HashMap<>();
}
return intersectRegexParameters;
}
public boolean intersectRegexParametersAreEmpty() {
return intersectRegexParameters == null ? true : intersectRegexParameters.isEmpty();
}
public Map> getUnionRangeParameters() {
if( unionRangeParameters == null ) {
unionRangeParameters = new HashMap<>();
}
return unionRangeParameters;
}
public boolean unionRangeParametersAreEmpty() {
return unionRangeParameters == null ? true : unionRangeParameters.isEmpty();
}
public Map> getIntersectRangeParameters() {
if( intersectRangeParameters == null ) {
intersectRangeParameters = new HashMap<>();
}
return intersectRangeParameters;
}
public boolean intersectRangeParametersAreEmpty() {
return intersectRangeParameters == null ? true : intersectRangeParameters.isEmpty();
}
// other logic
public void addAppropriateParam( String listId, T... param ) {
if( param.length == 0 ) {
return;
}
List listParams = getAppropriateParamList(listId, param[0], param.length);
listParams.addAll(Arrays.asList(param));
}
public void addRangeParameter( String listId, T param, boolean start ) {
this.range = true;
List listParams = getAppropriateParamList(listId, param, 2);
int index = start ? 0 : 1;
listParams.set(index, param);
this.range = false;
}
@SuppressWarnings("unchecked")
public List getAppropriateParamList(String listId, T param, int size) {
List listParams = null;
if( like ) {
if( ! (param instanceof String) ) {
throw new IllegalArgumentException("Only String parameters may be used in regular expressions.");
}
List stringListParams = null;
if( union ) {
listParams = (List) getUnionRegexParameters().get(listId);
if( listParams == null ) {
stringListParams = new ArrayList<>(size);
getUnionRegexParameters().put(listId, stringListParams);
}
} else {
listParams = (List) getIntersectParameters().get(listId);
if( listParams == null ) {
stringListParams = new ArrayList<>(size);
getIntersectRegexParameters().put(listId, stringListParams);
}
}
if( listParams == null ) {
return (List) stringListParams;
} else {
return listParams;
}
} else if( range ) {
if( union ) {
listParams = (List) getUnionRangeParameters().get(listId);
if( listParams == null ) {
listParams = Arrays.asList(null, null);
getUnionRangeParameters().put(listId, listParams);
}
} else {
listParams = (List) getIntersectRangeParameters().get(listId);
if( listParams == null ) {
listParams = Arrays.asList(null, null);
getIntersectRangeParameters().put(listId, listParams);
}
}
} else {
if( union ) {
listParams = (List) getUnionParameters().get(listId);
if( listParams == null ) {
listParams = new ArrayList<>(size);
getUnionParameters().put(listId, listParams);
}
} else {
listParams = (List) getIntersectParameters().get(listId);
if( listParams == null ) {
listParams = new ArrayList<>(size);
getIntersectParameters().put(listId, listParams);
}
}
}
return listParams;
}
public void setToUnion() {
this.union = true;
}
public void setToIntersection() {
this.union = false;
}
public boolean isUnion() {
return this.union;
}
public void setToLike() {
this.like = true;
}
public boolean isLike() {
return this.like;
}
public void setToEquals() {
this.like = false;
}
public void setToRange() {
this.range = true;
}
public void setToPrecise() {
this.range = false;
}
public boolean isRange() {
return this.range;
}
public void clear() {
union = true;
like = false;
range = false;
Map [] maps = {
unionParameters,
intersectParameters,
unionRegexParameters,
intersectRegexParameters,
unionRangeParameters,
intersectRangeParameters
};
for( Map paramMap : maps ) {
if( paramMap != null ) {
paramMap.clear();
}
}
}
public QueryParameters(QueryParameters queryParameters) {
this.union = queryParameters.union;
this.like = queryParameters.like;
this.range = queryParameters.range;
this.intersectParameters = queryParameters.intersectParameters == null ? null :
new HashMap<>(queryParameters.intersectParameters);
this.unionParameters = queryParameters.unionParameters == null ? null :
new HashMap<>(queryParameters.unionParameters);
this.intersectRangeParameters = queryParameters.intersectRangeParameters == null ? null :
new HashMap<>(queryParameters.intersectRangeParameters);
this.unionRangeParameters = queryParameters.unionRangeParameters == null ? null :
new HashMap<>(queryParameters.unionRangeParameters);
this.intersectRegexParameters = queryParameters.intersectRegexParameters == null ? null :
new HashMap<>(queryParameters.intersectRegexParameters);
this.unionRegexParameters = queryParameters.unionRegexParameters == null ? null :
new HashMap<>(queryParameters.unionRegexParameters);
}
}