Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (c) 1997-2013, tinygroup.org ([email protected]).
*
* Licensed under the GPL, Version 3.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.gnu.org/licenses/gpl.html
*
* 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.
* --------------------------------------------------------------------------
* 版权 (c) 1997-2013, tinygroup.org ([email protected]).
*
* 本开源软件遵循 GPL 3.0 协议;
* 如果您不遵循此协议,则不被允许使用此文件。
* 你可以从下面的地址获取完整的协议文本
*
* http://www.gnu.org/licenses/gpl.html
*/
package org.tinygroup.entity;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.tinygroup.commons.tools.Assert;
import org.tinygroup.commons.tools.StringUtil;
import org.tinygroup.context.Context;
import org.tinygroup.entity.common.ConditionField;
import org.tinygroup.entity.common.DisplayField;
import org.tinygroup.entity.common.Field;
import org.tinygroup.entity.common.Group;
import org.tinygroup.entity.common.GroupField;
import org.tinygroup.entity.common.HavingField;
import org.tinygroup.entity.common.OperationField;
import org.tinygroup.entity.common.OrderField;
import org.tinygroup.entity.entitymodel.EntityModel;
import org.tinygroup.entity.util.ModelUtil;
import org.tinygroup.exception.TinySysRuntimeException;
import org.tinygroup.expression.ExpressionManager;
import org.tinygroup.expression.SqlExpression;
import org.tinygroup.logger.Logger;
import org.tinygroup.logger.LoggerFactory;
import org.tinygroup.metadata.config.stdfield.StandardField;
import org.tinygroup.metadata.util.MetadataUtil;
import org.tinygroup.springutil.SpringUtil;
import org.tinygroup.tinydb.BeanDbNameConverter;
import org.tinygroup.tinydb.BeanOperatorManager;
import org.tinygroup.tinydb.operator.DBOperator;
/**
*
* 功能说明:实体模型帮助类
*
* 系统版本: v1.0
* 开发人员: renhui
* 开发时间: 2013-9-6
* 功能描述: 写明作用,调用方式,使用场景,以及特殊情况
*/
public class EntityModelHelper {
private static final String DEFAULT_ORDER_DIRECTION = "asc";
public static final String COMPARE_MODE = "CompareMode";
/**
* LengthEqualsCompareMode比较模式字段值长度参数名称的后缀
*/
public static final String LEVEL_LENGTH = "LevelLength";
public static final String HAVING_COMPARE_MODE = "HavingCompareMode";
public static final String HAVING_FIELD = "HavingField";
public static final String SPLIT = ",";
protected Logger logger = LoggerFactory
.getLogger(ViewServiceProcessor.class);
/**
* 要处理的实体模型
*/
protected EntityModel model;
/**
* 上下文对象
*/
protected Context context;
@SuppressWarnings("rawtypes")
protected DBOperator operator;
protected BeanDbNameConverter converter;
protected String tableName;
protected String primaryKeyName;
protected String primaryPropertyName;
/**
* key:配置fieldId value:bean属性名称
*/
protected Map fieldId2PropertyName = new HashMap();
/**
* key:配置fieldId value:字段名称
*/
protected Map fieldId2DbFieldName = new HashMap();
protected Map fieldId2Field = new HashMap();
protected Map fieldId2ModelId = new HashMap();
private CompareModeContain contain;
public EntityModelHelper(EntityModel model, Context context) {
super();
this.model = model;
this.context = context;
BeanOperatorManager manager = SpringUtil
.getBean(BeanOperatorManager.OPERATOR_MANAGER_BEAN);
this.operator = manager.getDbOperator(model.getName());
Assert.assertNotNull(operator, "operator must not null");
this.converter = operator.getBeanDbNameConverter();
this.tableName = manager.getTableConfigurationByBean(model.getName())
.getName();
contain=SpringUtil.getBean(CompareModeContain.COMPARE_MODE_CONTAIN);
List groups = model.getGroups();
if (groups != null) {
for (Group group : groups) {
List fields = group.getFields();
if (fields != null) {
for (Field field : fields) {
String dbFieldName = getDbFieldName(field
.getStandardFieldId());
if (field.isPrimary()) {
this.primaryKeyName = dbFieldName;
primaryPropertyName = nameConverter(primaryKeyName);
}
fieldId2DbFieldName.put(field.getId(), dbFieldName);
fieldId2PropertyName.put(field.getId(),
nameConverter(dbFieldName));
fieldId2Field.put(field.getId(), field);
String modelId = field.getModelId();
if (StringUtil.isBlank(modelId)) {
modelId = model.getId();
}
fieldId2ModelId.put(field.getId(), modelId);
}
}
}
}
}
public String nameConverter(String dbFieldName) {
return converter.dbFieldNameToPropertyName(dbFieldName);
}
/**
*
*
* @param 找不到标准字段则返回参数
* @return
*/
public String getDbFieldName(String standardFieldId) {
try {
StandardField standardField=getStandardField(standardFieldId);
return standardField.getName();
} catch (Exception e) {
}
return standardFieldId;
}
public StandardField getStandardField(String standardFieldId) {
return MetadataUtil.getStandardField(standardFieldId);
}
/**
*
* 根据fieldId 获取对应的数据库字段名称
*
* @param fieldId
* @return
*/
public String getDbFieldNameWithFieldId(String fieldId) {
return fieldId2DbFieldName.get(fieldId);
}
/**
*
* 根据fieldId 获取对应的bean 属性名称
*
* @param fieldId
* @return
*/
public String getPropertyName(String fieldId) {
return fieldId2PropertyName.get(fieldId);
}
public String aggregateFunctionSqlClause(String functionName,
String fieldName, String aliasName) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(functionName).append("(").append(fieldName)
.append(")");
if (aliasName != null) {
stringBuffer.append(" ").append(aliasName);
}
return stringBuffer.toString();
}
public void generateQuerySqlClause(String tableAliasName,
List conditionFields, List