1 24 package org.ofbiz.entity.condition; 25 26 import java.io.Serializable ; 27 import java.util.Collections ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import javolution.util.FastList; 32 import javolution.util.FastMap; 33 34 import org.ofbiz.entity.config.DatasourceInfo; 35 import org.ofbiz.entity.jdbc.SqlJdbcUtil; 36 import org.ofbiz.entity.model.ModelEntity; 37 import org.ofbiz.entity.model.ModelField; 38 import org.ofbiz.entity.model.ModelViewEntity; 39 import org.ofbiz.entity.model.ModelViewEntity.ModelAlias; 40 41 55 public abstract class EntityConditionBase implements Serializable { 56 57 public static final List emptyList = Collections.unmodifiableList(FastList.newInstance()); 58 public static final Map emptyMap = Collections.unmodifiableMap(FastMap.newInstance()); 59 60 protected ModelField getField(ModelEntity modelEntity, String fieldName) { 61 ModelField modelField = null; 62 if (modelEntity != null) { 63 modelField = (ModelField) modelEntity.getField(fieldName); 64 } 65 return modelField; 66 } 67 68 protected String getColName(Map tableAliases, ModelEntity modelEntity, String fieldName, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) { 69 if (modelEntity == null) return fieldName; 70 return getColName(tableAliases, modelEntity, getField(modelEntity, fieldName), fieldName, includeTableNamePrefix, datasourceInfo); 71 } 72 73 protected String getColName(ModelField modelField, String fieldName) { 74 String colName = null; 75 if (modelField != null) { 76 colName = modelField.getColName(); 77 } else { 78 colName = (String ) fieldName; 79 } 80 return colName; 81 } 82 83 protected String getColName(Map tableAliases, ModelEntity modelEntity, ModelField modelField, String fieldName, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) { 84 if (modelEntity == null || modelField == null) return fieldName; 85 86 if (datasourceInfo != null && datasourceInfo.aliasViews && modelEntity instanceof ModelViewEntity) { 88 ModelViewEntity modelViewEntity = (ModelViewEntity) modelEntity; 89 ModelAlias modelAlias = modelViewEntity.getAlias(fieldName); 90 if (modelAlias != null) { 91 return modelAlias.getColAlias(); 92 } 93 } 94 95 String colName = getColName(modelField, fieldName); 96 if (includeTableNamePrefix && datasourceInfo != null) { 97 String tableName = modelEntity.getTableName(datasourceInfo); 98 if (tableAliases.containsKey(tableName)) { 99 tableName = (String ) tableAliases.get(tableName); 100 } 101 colName = tableName + "." + colName; 102 } 103 return colName; 104 } 105 106 protected void addValue(StringBuffer buffer, ModelField field, Object value, List params) { 107 SqlJdbcUtil.addValue(buffer, params == null ? null : field, value, params); 108 } 109 110 public boolean equals(Object obj) { 111 throw new UnsupportedOperationException ("equals:" + getClass().getName()); 112 } 113 114 public int hashCode() { 115 throw new UnsupportedOperationException ("hashCode: " + getClass().getName()); 116 } 117 118 protected static boolean equals(Object o1, Object o2) { 119 return o1 == null ? o2 == null : o1.equals(o2); 120 } 121 122 protected static int hashCode(Object o) { 123 return o != null ? o.hashCode() : 0; 124 } 125 126 public static Boolean castBoolean(boolean result) { 127 return result ? Boolean.TRUE : Boolean.FALSE; 128 } 129 } 130 | Popular Tags |