生成PreparedStatementSetter对象.

@return PreparedStatementSetter
177480
public PreparedStatementSetter getParameters() {
		if (list.size() == 0) {
			return null;
		}
		PreparedStatementSetter param = new PreparedStatementSetter() {
			@Override
			public void setValues(PreparedStatement pstmt) {
				try {
					StatementParameter.this.setValues(pstmt);
				}
				catch (SQLException e) {
					throw new InvalidParamDataAccessException(e);
				}
			}

		};
		return param;
	}
144128
protected PreparedStatement createStatment(Connection conn, Sql sql) throws SQLException {

		if (sql == null) {
			throw new NullPointerException("Sql Object is NULL");
		}
		String sqlBody = sql.getSql();

		if (StringUtils.isNotEmpty(sqlBody)) {
			PreparedStatement stmt = null;
			if (sql.isProcedure()) {
				stmt = conn.prepareCall("{" + sqlBody + "}");
			} else if (sql.isPreperStatement()) {
				stmt = conn.prepareStatement(sqlBody);
			}
			
			if (stmt != null) {
				Map<Integer, Object> prepareValues = sql.getPreperValues();
	
				Set<Integer> indexSet = prepareValues.keySet();
				for (Integer index : indexSet) {
					Object value = prepareValues.get(index);
					if (index != null && value != null) {
						if (value instanceof String) {
							stmt.setString(index, value.toString());
						} else if (value instanceof Integer) {
							stmt.setInt(index, ((Integer) value).intValue());
						} else if (value instanceof Long) {
							stmt.setLong(index, ((Long) value).longValue());
						} else if (value instanceof Double) {
							stmt.setDouble(index, ((Double) value).doubleValue());
						} else if (value instanceof Float) {
							stmt.setFloat(index, ((Float) value).floatValue());
						} else if (value instanceof Short) {
							stmt.setShort(index, ((Short) value).shortValue());
						} else if (value instanceof Byte) {
							stmt.setByte(index, ((Byte) value).byteValue());
						} else if (value instanceof Boolean) {
							stmt.setBoolean(index, ((Boolean) value).booleanValue());
						} else if (value instanceof Date) {
							stmt.setDate(index, (Date) value);
						} else if (value instanceof Time) {
							stmt.setTime(index, (Time) value, Calendar.getInstance());
						} else if (value instanceof Blob) {
							stmt.setBlob(index, (Blob) value);
						} else if (value instanceof Clob) {
							stmt.setClob(index, (Clob) value);
						} else if (value instanceof BigDecimal) {
							stmt.setBigDecimal(index, (BigDecimal) value);
						} else if (value instanceof byte[]) {
							stmt.setBytes(index, (byte[]) value);
						} else if (value instanceof Out) {
							if (stmt instanceof CallableStatement) {
								int outType = getProcedureOutType((Out)value);
								if (outType != -999) {
									((CallableStatement)stmt).registerOutParameter(index, outType);
								}
							}
						} else {
							stmt.setObject(index, value);
						}
					}
				}
				return stmt;
			} else {
				return conn.prepareStatement(sqlBody);
			}
		}
51371
public static PreparedStatement setLongs(int index, PreparedStatement stmt, long... params)
			throws SQLException {
		return set(index, stmt, null, params, null);
	}
624640
public Statement toStatement() {
    Statement statement = new Statement();
    statement.setQuery(queryBuilder.buildQuery());
    statement.setValues(Maps.toList(queryBuilder.getBindVariableMap(), String_ValueMapEntry.class)
        .toArray(new String_ValueMapEntry[] {}));
    return statement;
  }
147474
public String prepareStatementString() throws SQLException {
		List<ArgumentHolder> argList = new ArrayList<ArgumentHolder>();
		return buildStatementString(argList);
	}
1149531
@Override
    public PoolablePreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
        return prepareStatement(sql, autoGeneratedKeys, -1, -1, -1);
    }
491129
public static PreparedStatement fillParams(PreparedStatement ps, Object... params) throws SQLException {
		if (ArrayUtil.isEmpty(params)) {
			return ps;// 无参数
		}
		Object param;
		for (int i = 0; i < params.length; i++) {
			int paramIndex = i + 1;
			param = params[i];
			if (null != param) {
				if (param instanceof java.util.Date) {
					// 日期特殊处理
					if (param instanceof java.sql.Date) {
						ps.setDate(paramIndex, (java.sql.Date) param);
					} else if (param instanceof java.sql.Time) {
						ps.setTime(paramIndex, (java.sql.Time) param);
					} else {
						ps.setTimestamp(paramIndex, SqlUtil.toSqlTimestamp((java.util.Date) param));
					}
				} else if (param instanceof Number) {
					// 针对大数字类型的特殊处理
					if (param instanceof BigInteger) {
						// BigInteger转为Long
						ps.setLong(paramIndex, ((BigInteger) param).longValue());
					} else if (param instanceof BigDecimal) {
						// BigDecimal的转换交给JDBC驱动处理
						ps.setBigDecimal(paramIndex, (BigDecimal) param);
					} else {
						// 普通数字类型按照默认传入
						ps.setObject(paramIndex, param);
					}
				} else {
					ps.setObject(paramIndex, param);
				}
			} else {
				final ParameterMetaData pmd = ps.getParameterMetaData();
				int sqlType = Types.VARCHAR;
				try {
					sqlType = pmd.getParameterType(paramIndex);
				} catch (SQLException e) {
					// ignore
					// log.warn("Null param of index [{}] type get failed, by: {}", paramIndex, e.getMessage());
				}
				ps.setNull(paramIndex, sqlType);
			}
		}
		return ps;
	}
124442
private function prepareGettersAndSetters()
    {
        $table_descriptor = $this->getStorageDescriptor();

        foreach ($table_descriptor->getFieldNames() as $name) {
            $field = $table_descriptor->getField($name);
            if (array_key_exists('name', $field) &&
                array_key_exists('data_type', $field) &&
                array_key_exists('type', $field)
            ) {
                $field_name = $field['name'];
                if (nb_strStartsWith($field_name, $this->table_name)) {
                    $field_name = preg_replace('/^' . $this->table_name . '_*/', '', $field_name);
                }
                $name = nb_underscore2StudlyCaps($field_name, true, $this->dictionary);
                $entity = nb_underscore2EntityName($field['name'], true, $this->dictionary);
                $this->buildGetter($field, $name, $entity);
                $this->buildSetter($field, $field_name, $name, $entity);
            }
        }
    }
1166493
public function buildCountStatement()
	{
		if( !$this->keys )
			throw new RuntimeException( 'No Columns defined.' );
		if( !$this->tables )
			throw new RuntimeException( 'No Tables defined.' );

		$tables		= array();
		$tables		= "\nFROM\n\t".implode( ",\n\t", $this->tables );
		$conditions	= "";
		$groupings	= "";
		$havings	= "";
		if( $this->conditions )
			$conditions	= "\nWHERE\n\t".implode( " AND\n\t", $this->conditions );
		if( $this->groupings )
			$groupings	= "\nGROUP BY\n\t".implode( ",\n\t", $this->groupings );
		if( $this->havings )
			$havings	= "\nHAVING\n\t".implode( ",\n\t", $this->havings );
		$column	= preg_replace( '/(.+)( AS .+)/i', '\\1', $this->keys[0] );
		$statement = "SELECT COUNT(".$column.") as rowcount".$tables.$conditions.$groupings.$havings;
		return $statement;
	}
785469
public Statement getPreparedStatement(String sql,
			Object[] parameters, boolean returnValues) throws DatabaseException {
		Statement stmt = null;
		try {
			if(supportPreparedStatement()){
				if (appendReturningColumnClause() && returnValues) {
					stmt = connection.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
				} else {
					stmt = connection.prepareStatement(sql);
				}
				if (parameters != null) {
					for (int i = 0; i < parameters.length; i++) {
						((PreparedStatement)stmt).setObject(i + 1,getEquivalentDBObject(parameters[i]));
					}
				}
			}else{//no substition of parameters
				stmt = connection.createStatement();
				return stmt;
			}
		} catch (SQLException e) {
			logSQL(stmt, sql, parameters, true);
			e.printStackTrace();
			throw new DataEntryException(e.getMessage());
		}
		return stmt;
	}
404057
private function createDeleteAll(): string
    {
        // 生成三项
        $this->sql = $this->db->createDelete($this->table, '');
        $this->prepare = $this->sql;
        $this->params = [];

        $this->tables = [$this->table];
        return $this->prepare;
    }
46654
private UserAndPassword executeStatementToUser(PreparedStatement preparedStmt) throws Exception {
		if( preparedStmt.execute() ) {
			// There's a ResultSet to be had
			ResultSet rs = preparedStmt.getResultSet();
			ResultSetMetaData rsmd = rs.getMetaData();

			int numColumns = rsmd.getColumnCount();
			if( numColumns != 5 ) {
				throw new Exception("Unexpected number of columns returned");
			}
			
			if( false == rs.next() ) {
				throw new Exception("Result set empty");
			}

			int userId = JdbcUtils.extractIntResult(rs,rsmd,1);
			String email = JdbcUtils.extractStringResult(rs,rsmd,2);
			String displayName = JdbcUtils.extractStringResult(rs,rsmd,3);
			String dbPassword = JdbcUtils.extractStringResult(rs,rsmd,4);
			int groupId = JdbcUtils.extractIntResult(rs,rsmd,5);

			if( true == rs.next() ) {
				throw new Exception("Result set had more than one result");
			}
			
			// Return user
			UserAndPassword user = new UserAndPassword();
			user.setId(userId);
			user.setUser(email);
			user.setDisplayName(displayName);
			user.setPassword(dbPassword);
			if( 0 == groupId ) {
				user.setAnonymous(true);
			} else if( 1 == groupId ) {
				user.setAdmin(true);
			}
			Vector<Integer> groups = new Vector<Integer>();
			groups.add( new Integer(groupId) );
			user.setGroups(groups);
			return user;
			
		} else {
			// indicates an update count or no results - this must be no results
			throw new Exception("Query returned no results");
		}
	}
425599
private function getUtmSetters()
    {
        if (null === $this->utmSetters) {
            $utmSetters = $this->getUtmTag()->getFieldSetterList();
            unset($utmSetters['query']);
            $this->utmSetters = $utmSetters;
        }

        return $this->utmSetters;
    }
506681
@Override
	public SqlContext createSqlContext() {
		SqlContextImpl sqlContext = new SqlContextImpl();
		Map<String, Parameter> paramMap = new ConcurrentHashMap<>(getConstParameterMap());

		// 自動バインド用パラメータ生成クラスが指定されている場合は、そこで生成されたパラメータをパラメータマップに追加する
		if (autoBindParameterCreators != null && !autoBindParameterCreators.isEmpty()) {
			for (AutoBindParameterCreator creator : getAutoBindParameterCreators()) {
				Map<String, Parameter> bindMap = creator.getBindParameterMap();
				if (bindMap != null && !bindMap.isEmpty()) {
					paramMap.putAll(bindMap);
				}
			}
		}

		sqlContext.setConstParameterMap(paramMap);
		sqlContext.setSqlFilterManager(getSqlFilterManager());
		sqlContext.setParameterMapperManager(new BindParameterMapperManager(parameterMapperManager));
		sqlContext.setQueryAutoParameterBinder(queryAutoParameterBinder);
		sqlContext.setUpdateAutoParameterBinder(updateAutoParameterBinder);

		return sqlContext;
	}
949691
protected function generateSelectSQL()
        {
            $sql = ($this->query->isDistinct()) ? 'SELECT DISTINCT ' : 'SELECT ';

            if ($this->query->isCustomSelection()) {
                if ($this->query->isDistinct() && Core::getDriver() == Core::DRIVER_POSTGRES) {
                    foreach ($this->query->getSortOrders() as $sort_order) {
                        $this->query->addSelectionColumn($sort_order->getColumn());
                    }
                }

                $sql_parts = [];
                foreach ($this->query->getSelectionColumns() as $column => $selection) {
                    $alias = ($selection->getAlias()) ?? $this->query->getSelectionAlias($column);
                    $sub_sql = $selection->getVariableString();
                    if ($selection->isSpecial()) {
                        $sub_sql .= mb_strtoupper($selection->getSpecial()) . '(' . Query::quoteIdentifier($selection->getColumn()) . ')';
                        if ($selection->hasAdditional())
                            $sub_sql .= ' ' . $selection->getAdditional() . ' ';
                        if (mb_strpos($selection->getSpecial(), '(') !== false)
                            $sub_sql .= ')';
                    } else {
                        $sub_sql .= Query::quoteIdentifier($selection->getColumn());
                    }
                    $sub_sql .= ' AS ' . Query::quoteIdentifier($alias);
                    $sql_parts[] = $sub_sql;
                }
                $sql .= implode(', ', $sql_parts);
            } else {
                $this->addAllSelectColumns();
                $sql .= $this->generateSelectAllSQL();
            }

            return $sql;
        }
352153
public PreparedStatement getPreparedStatement(final SqlContext sqlContext) throws SQLException {
		Optional<LocalTransactionContext> txContext = currentTxContext();
		if (txContext.isPresent()) {
			return txContext.get().getPreparedStatement(sqlContext);
		} else {
			if (!this.unmanagedTransaction.isPresent()) {
				this.unmanagedTransaction = Optional
						.of(new LocalTransactionContext(this.connectionSupplier, this.sqlFilterManager));
			}
			return this.unmanagedTransaction.get().getPreparedStatement(sqlContext);
		}
	}
938361
protected function _buildSQL()
	{
		if( $this->_stmt !== null ) {
			return $this->_stmt;
		}

		$i = 1;
		foreach( $this->_parts as $part )
		{
			$this->_stmt .= $part;
			if( isset( $this->_binds[$i] ) ) {
				$this->_stmt .= $this->_binds[$i];
			}
			$i++;
		}

		return $this->_stmt;
	}