com.landawn.abacus.condition.SubQuery Maven / Gradle / Ivy
/*
* Copyright (C) 2015 HaiYang Li
*
* 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.landawn.abacus.condition;
import static com.landawn.abacus.util.WD.COMMA_SPACE;
import static com.landawn.abacus.util.WD._SPACE;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.landawn.abacus.condition.ConditionFactory.CF;
import com.landawn.abacus.util.ClassUtil;
import com.landawn.abacus.util.N;
import com.landawn.abacus.util.NamingPolicy;
import com.landawn.abacus.util.Objectory;
import com.landawn.abacus.util.Strings;
import com.landawn.abacus.util.WD;
/**
*
*/
public class SubQuery extends AbstractCondition {
// For Kryo
final String entityName;
// For Kryo
final Class> entityClass;
private Collection propNames;
// For Kryo
final String sql;
/**
* Field condition.
*/
private Condition condition;
// For Kryo
SubQuery() {
entityName = null;
entityClass = null;
sql = null;
}
/**
*
*
* @param sql
*/
public SubQuery(final String sql) {
this(Strings.EMPTY_STRING, sql);
}
/**
*
*
* @param entityName
* @param sql
*/
public SubQuery(final String entityName, final String sql) {
super(Operator.EMPTY);
this.entityName = entityName;
entityClass = null;
if (Strings.isEmpty(sql)) {
throw new IllegalArgumentException("The sql script can't be null or empty.");
}
propNames = null;
condition = null;
this.sql = sql;
}
/**
*
*
* @param entityName
* @param propNames
* @param condition
*/
public SubQuery(final String entityName, final Collection propNames, final Condition condition) {
super(Operator.EMPTY);
this.entityName = entityName;
entityClass = null;
this.propNames = propNames;
if (condition == null || CriteriaUtil.isClause(condition) || condition instanceof Expression) {
this.condition = condition;
} else {
this.condition = CF.where(condition);
}
sql = null;
}
/**
*
*
* @param entityClass
* @param propNames
* @param condition
*/
public SubQuery(final Class> entityClass, final Collection propNames, final Condition condition) {
super(Operator.EMPTY);
entityName = ClassUtil.getSimpleClassName(entityClass);
this.entityClass = entityClass;
this.propNames = propNames;
if (condition == null || CriteriaUtil.isClause(condition) || condition instanceof Expression) {
this.condition = condition;
} else {
this.condition = CF.where(condition);
}
sql = null;
}
/**
* Gets the sql.
*
* @return
*/
public String getSql() {
return sql;
}
/**
*
*
* @return
*/
public String getEntityName() {
return entityName;
}
/**
*
*
* @return
*/
public Class> getEntityClass() {
return entityClass;
}
/**
* Gets the select prop names.
*
* @return
*/
public Collection getSelectPropNames() {
return propNames;
}
/**
* Gets the condition.
*
* @return
*/
public Condition getCondition() {
return condition;
}
/**
* Gets the parameters.
*
* @return
*/
@Override
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy