构建" IS NULL "和" IS NOT NULL "查询的动态条件sql.
@param source 构建所需的资源对象
@return 返回SqlInfo对象
345290
@Override
    public SqlInfo buildSqlInfo(BuildSource source) {
        Node node = source.getNode();

        /* 获取field和match属性,如果匹配中'match'属性没有值或者值为真，则认为是必然生成项. */
        String fieldText = XmlNodeHelper.getAndCheckNodeText(node, ZealotConst.ATTR_FIELD);
        String matchText = XmlNodeHelper.getNodeAttrText(node, ZealotConst.ATTR_MATCH);
        Boolean matchValue = (Boolean) ParseHelper.parseExpressWithException(matchText, source.getParamObj());
        if (StringHelper.isBlank(matchText) || Boolean.TRUE.equals(matchValue)) {
            return XmlSqlInfoBuilder.newInstace(source).buildIsNullSql(fieldText);
        }

        return source.getSqlInfo();
    }
354620
public static <T> T getValueOfCertainColumnOfCertainRecord(String sql, Object... arg) {
        List<T> list = DBUtils.getValueOfCertainColumnOfAllRecord(sql, arg);
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
315499
private static SqlInfo buildFinalSql(SqlInfo sqlInfo, Object paramObj) {
        // 得到生成的SQL，如果有MVEL的模板表达式，则执行计算出该表达式来生成最终的SQL
        String sql = sqlInfo.getJoin().toString();
        sql = ParseHelper.parseTemplate(sql, paramObj);
        return sqlInfo.setSql(StringHelper.replaceBlank(sql));
    }
776070
public Object javaToSql(Object source)
    {
        if (source == null)
            return null;
        try
        {
            return SerializationUtils.serialize((Serializable) source);
        }
        catch(Throwable t)
        {
            throw new ConversionException(t);
        }
    }
1239531
public List<Map<String, String>> getMetadataBySql(Sql sql) throws SQLException {
		
		List<Map<String, String>> table = new ArrayList<Map<String, String>>();

		PreparedStatement ps = createStatment(conn, sql);
		ResultSet rs = ps.executeQuery();
		ResultSetMetaData rsme = rs.getMetaData();

		int columnCount = rsme.getColumnCount();
		for (int i = 1; i <= columnCount; i++) {
			
			Map<String, String> field = new HashMap<String, String>();

			field.put("NAME", rsme.getColumnName(i)); // 字段名称
			field.put("TYPE", rsme.getColumnTypeName(i)); //字段类型名称(例如：VACHAR2)
			field.put("SIZE", Integer.toString(rsme.getPrecision(i))); //字段长度
			field.put("NULLABLE", rsme.isNullable(i) == ResultSetMetaData.columnNullable ? "YES" : "NO"); //是否为空
			field.put("REMARK", rsme.getColumnLabel(i)); //字段注释
			
			table.add(field);
		}


		return table;
	}
380249
@Nullable
  @Override
  public T get(String s) {
    checkNotNull(s);
    checkArgument(!s.isEmpty());
    for (T t : supplier.get()) {
      if (t.id().equals(s)) {
        return t;
      }
    }
    return null;
  }
678221
protected MappedStatement reflect(DefaultResultSetHandler resultSetHandler){
        Field field = ReflectionUtils.findField(DefaultResultSetHandler.class, "mappedStatement");
        field.setAccessible(true);
        Object value = null;
        try {
            value = field.get(resultSetHandler);
            if(value instanceof MappedStatement)
            {
               return (MappedStatement)value;
            }
        } catch (Exception e) {
            LogHelper.error("","默认返回结果集反射参数对象异常，原因："+ e.getMessage(),"DataTableInterceptor.reflect",e);
        }
        return null;
    }
862842
protected void init(Source source) throws SQLException {

        if (source == null) {
            throw Util.nullArgument("source");
        }

        Transformer           transformer =
            JDBCSQLXML.getIdentityTransformer();
        StreamResult          result      = new StreamResult();
        ByteArrayOutputStream baos        = new ByteArrayOutputStream();
        GZIPOutputStream      gzos;

        try {
            gzos = new GZIPOutputStream(baos);
        } catch (IOException ex) {
            throw Exceptions.transformFailed(ex);
        }
        result.setOutputStream(gzos);

        try {
            transformer.transform(source, result);
        } catch (TransformerException ex) {
            throw Exceptions.transformFailed(ex);
        }

        try {
            gzos.close();
        } catch (IOException ex) {
            throw Exceptions.transformFailed(ex);
        }

        byte[] data = baos.toByteArray();

        setGZipData(data);
        setReadable(true);
        setWritable(false);
    }
365542
public final int getJdbcType()
    {
        switch (this.fieldSource)
        {
            case SOURCE_FIELD :
                return this.getFieldRef().getJdbcType().getType();
            case SOURCE_NULL :
                return java.sql.Types.NULL;
            case SOURCE_VALUE :
                return java.sql.Types.VARCHAR;
            default :
                return java.sql.Types.NULL;
        }
    }
432448
public static String isValidSqlWithMessage(Connection con, String sql, List<QueryParameter> parameters) {		
		try {
			QueryUtil qu = new QueryUtil(con, DialectUtil.getDialect(con));
			Map<String, QueryParameter> params = new HashMap<String, QueryParameter>();			
			for (QueryParameter qp : parameters) {
				params.put(qp.getName(), qp);
			}
			qu.getColumnNames(sql, params);
		} catch (Exception ex) {
			LOG.error(ex.getMessage(), ex);
			return ex.getMessage();
		}
		return null;
	}
581945
public static Object stringToSqlValue(String value, int sqlType, boolean isRequired, boolean isEmptyStringNulled) {
        // 设置变量
        String sourceValue = value;
        if (SqlUtils.isTextType(sqlType)) {
            if ((sourceValue == null) || (true == StringUtils.isEmpty(sourceValue) && isEmptyStringNulled)) {
                return isRequired ? REQUIRED_FIELD_NULL_SUBSTITUTE : null;
            } else {
                return sourceValue;
            }
        } else {
            if (StringUtils.isEmpty(sourceValue)) {
                return isEmptyStringNulled ? null : sourceValue;// oracle的返回null，保持兼容
            } else {
                Class<?> requiredType = sqlTypeToJavaTypeMap.get(sqlType);
                if (requiredType == null) {
                    throw new IllegalArgumentException("unknow java.sql.Types - " + sqlType);
                } else if (requiredType.equals(String.class)) {
                    return sourceValue;
                } else if (true == isNumeric(sqlType)) {
                    return convertUtilsBean.convert(sourceValue.trim(), requiredType);
                } else {
                    return convertUtilsBean.convert(sourceValue, requiredType);
                }
            }
        }
    }
691573
@Nullable
    public T query() throws SQLException {
        try (ResultSet r = executeQuery()) {
            if (r.next()) {
                return resultMapper.map(r);
            }
            return null;
        }
    }
711733
public static <T> T makeNullSafe(final T source) {

		if (source == null) {
			return null;  // null is null...
		}

		final Class<?> sourceClass = source.getClass();
		final Set<Field> initiallyNullListFields = new HashSet<Field>();
		final Set<Field> initiallyNullSetFields = new HashSet<Field>();
		final Set<Field> initiallyNullMapFields = new HashSet<Field>();

		final List<Field> memberFields = getNonStaticFields(sourceClass);
		for (Field field : memberFields) {  // should it look for parents classes??

			ReflectionUtils.makeAccessible(field);
			final Object value = ReflectionUtils.getField(field, source);

			// TODO: these can be cached
			final Class<?> fieldType = field.getType();
			final boolean isList = fieldType.isAssignableFrom(List.class);
			final boolean isSet = fieldType.isAssignableFrom(Set.class);
			final boolean isMap = fieldType.isAssignableFrom(Map.class);
			final boolean isCollection = isList || isSet || isMap;

			final boolean isThriftClass = isThriftClass(fieldType);
			if (isThriftClass) {
				if (value != null) {
					// traverse all non-null thrift class attributes
					ReflectionUtils.setField(field, source, makeNullSafe(value));  // recursively call wrap method.
				}
			} else if (isCollection) {
				if (value == null) {
					if (isList) {
						initiallyNullListFields.add(field);
						ReflectionUtils.setField(field, source, new ArrayList<Object>());
					} else if (isSet) {
						initiallyNullSetFields.add(field);
						ReflectionUtils.setField(field, source, new HashSet<Object>());
					} else {
						initiallyNullMapFields.add(field);
						ReflectionUtils.setField(field, source, new HashMap<Object, Object>());
					}
				} else {
					// check values in collection
					if (isList) {
						for (Object o : ((Iterable<?>) value)) {
							Collections.replaceAll((List<Object>) value, o, makeNullSafe(o));
						}
					} else if (isSet) {
						final Set<Object> set = (Set<Object>) value;
						final List<Object> elements = new ArrayList<Object>(set.size());
						for (Object o : ((Iterable<?>) value)) {
							elements.add(makeNullSafe(o));
						}
						set.clear();
						set.addAll(elements);
					}
					// check map values??
				}
			}

		}

		final boolean noNullCollectionField = initiallyNullListFields.isEmpty() &&
				initiallyNullSetFields.isEmpty() && initiallyNullMapFields.isEmpty();
		if (noNullCollectionField) {
			return source;  // doesn't make proxy
		}

		// interceptor that handles thrift write method
		final ThriftNullSafeCollectionInterceptor interceptor = new ThriftNullSafeCollectionInterceptor();
		interceptor.getInitiallyNullListFields().addAll(initiallyNullListFields);
		interceptor.getInitiallyNullSetFields().addAll(initiallyNullSetFields);
		interceptor.getInitiallyNullMapFields().addAll(initiallyNullMapFields);

		// make proxy
		// TODO: should it add some marker interface to distinguish the proxy created by this class??
		ProxyFactory proxyFactory = new ProxyFactory(source);
		proxyFactory.setProxyTargetClass(true); // aka. use cglib for non-interface source
		proxyFactory.addInterface(ThriftWrapperProxyMarker.class);  // add marker interface
		proxyFactory.addAdvice(interceptor);
		return (T) proxyFactory.getProxy();

	}
1282935
private List<From> findFrom(SQLTableSource from) {
        //zhongshu-comment class1.isAssignableFrom(class2) class2是不是class1的子类或者子接口
        //改成用instanceof 应该也行吧：from instanceof SQLExprTableSource
        boolean isSqlExprTable = from.getClass().isAssignableFrom(SQLExprTableSource.class);

        if (isSqlExprTable) {
            SQLExprTableSource fromExpr = (SQLExprTableSource) from;
            String[] split = fromExpr.getExpr().toString().split(",");

            ArrayList<From> fromList = new ArrayList<>();
            for (String source : split) {
                fromList.add(new From(source.trim(), fromExpr.getAlias()));
            }
            return fromList;
        }

        SQLJoinTableSource joinTableSource = ((SQLJoinTableSource) from);
        List<From> fromList = new ArrayList<>();
        fromList.addAll(findFrom(joinTableSource.getLeft()));
        fromList.addAll(findFrom(joinTableSource.getRight()));
        return fromList;
    }
911567
public Object javaToSql(Object source)
    {
        if (source instanceof Boolean)
        {
            if (source.equals(Boolean.TRUE))
            {
                return I_TRUE;
            }
            else
            {
                return I_FALSE;
            }
        }
        else
        {
            return source;
        }
    }
135023
public Object javaToSql(Object source) throws ConversionException
    {

        if (source == null)
        {
            return NULLVALUE;
        }

        try
        {
            List stringList = (List) source;
            if (stringList.isEmpty())
            {
                return NULLVALUE;
            }

            StringBuffer result = new StringBuffer();
            for (int i = 0; i < stringList.size(); i++)
            {
                String newSt = (String) stringList.get(i);
                // introduced in JDK 1.4, replace with commons-lang
                // newSt = newSt.replaceAll("#", "##");
                newSt = StringUtils.replace(newSt, "#", "##");
                if (i > 0)
                {
                    result.append("#");
                }
                result.append(newSt);
            }
            return result.toString();
        }
        catch (ClassCastException e)
        {
            throw new ConversionException("Object is not a List of String it is a"
                    + source.getClass().getName());
        }
    }
422045
public SqlPara getSqlParaByString(String content, Object... paras) {
		Template template = engine.getTemplateByString(content);
		
		SqlPara sqlPara = new SqlPara();
		Map data = new HashMap();
		data.put(SQL_PARA_KEY, sqlPara);
		data.put(PARA_ARRAY_KEY, paras);
		sqlPara.setSql(template.renderToString(data));
		// data 为本方法中创建，不会污染用户数据，无需移除 SQL_PARA_KEY、PARA_ARRAY_KEY
		return sqlPara;
	}