Generic setter for SQL-correspondent values. Forces typecasting for database compatibility.
491812
function setValue(key, val) {
			//util.log(key + ": " + JSON.stringify(val));

			if (val === null) {
				me.values[key] = null;
			} else if (val === undefined) {
				me.values[key] = undefined;
			} else {
				type = model.columns[key]['DATA_TYPE'];

				switch (type) {
					case 'datetime':
					case 'timestamp':
						me.values[key] = new Date(val);
						break;
					case 'text':
					case 'varchar':
						me.values[key] = val.toString();
						break;
					case 'int':
					case 'tinyint':
						if (model.columns[key]['COLUMN_TYPE'] == 'tinyint(1)') {
							me.values[key] = !!val // Boolean
						} else {
							me.values[key] = parseInt(val);
						}
						break;
					default:
						me.values[key] = val;
				}
			}
		}
1167918
static BindTransform getSqlTransform(TypeName typeName) {
		if (Time.class.getName().equals(typeName.toString())) {
			return new SQLTimeBindTransform();
		}

		if (java.sql.Date.class.getName().equals(typeName.toString())) {
			return new SQLDateBindTransform();
		}

		return null;
	}
1059580
private void setProperties(final JSONObject jsonObject, final List<Object> paramlist, final StringBuilder sql) {
        final Iterator<String> keys = jsonObject.keys();

        final StringBuilder insertString = new StringBuilder();
        final StringBuilder wildcardString = new StringBuilder();

        boolean isFirst = true;
        String key;
        Object value;

        while (keys.hasNext()) {
            key = keys.next();

            if (isFirst) {
                insertString.append("(").append(key);
                wildcardString.append("(?");
                isFirst = false;
            } else {
                insertString.append(",").append(key);
                wildcardString.append(",?");
            }

            value = jsonObject.get(key);
            paramlist.add(value);

            if (!keys.hasNext()) {
                insertString.append(")");
                wildcardString.append(")");
            }
        }

        sql.append("insert into ").append(getName()).append(insertString).append(" values ").append(wildcardString);
    }
952974
public void setObject(final int parameterIndex, 
                          final Object x) throws SQLException {

        if (x == null) {
            if ("true".equals(connection.getProperties().
                              get("acolyte.parameter.untypedNull"))) {

                // Fallback to String-VARCHAR
                setObject(parameterIndex, null, Types.VARCHAR);

                return;
            } // end of if

            throw new SQLException("Cannot set parameter from null object");
        } // end of if

        // ---

        final String className = normalizeClassName(x.getClass());

        if (!Defaults.jdbcTypeClasses.containsKey(className)) {
            throw new SQLFeatureNotSupportedException("Unsupported parameter type: " + className);
        } // end of if
        
        // ---

        final int sqlType = Defaults.jdbcTypeClasses.get(className);

        setObject(parameterIndex, x, sqlType);
    }
103795
public static Object getCastingValue(ColumnType columnType, Object value) throws ExecutionException {
        validateInput(columnType);
        Object returnValue = null;
        if (value != null) {
            switch (columnType.getDataType()) {

                case BIGINT:
                    ensureNumber(value);
                    returnValue = ((Number) value).longValue();
                    break;
                case DOUBLE:
                    ensureNumber(value);
                    returnValue = ((Number) value).doubleValue();
                    break;
                case FLOAT:
                    ensureNumber(value);
                    returnValue = ((Number) value).floatValue();
                    break;
                case INT:
                    ensureNumber(value);
                    returnValue = ((Number) value).intValue();
                    break;
                default:
                    returnValue = value;

            }
        }

        return returnValue;
    }
465122
void setValue(int parameterIndex, PreparedStatement preparedStatement,
			Class<?> fieldType, Object fieldValue) throws Exception {

		try {

			if (fieldType == String.class) {
				preparedStatement
						.setString(parameterIndex, (String) fieldValue);
			} else if (fieldType == java.sql.Timestamp.class) {
				preparedStatement.setTimestamp(parameterIndex,
						(java.sql.Timestamp) fieldValue);
			} else if (fieldType == java.sql.Date.class) {
				preparedStatement.setDate(parameterIndex,
						(java.sql.Date) fieldValue);
			} else if (fieldType == java.sql.Time.class) {
				preparedStatement.setTime(parameterIndex,
						(java.sql.Time) fieldValue);
			} else if (fieldType == boolean.class || fieldType == Boolean.class) {

				if (fieldValue != null) {
					boolean boolValue = (boolean) (Boolean) fieldValue;
					preparedStatement.setInt(parameterIndex,
							(boolValue ? 1 : 0));
				} else {
					preparedStatement.setInt(parameterIndex, 0);

				}
			} else if (fieldType == int.class || fieldType == Integer.class) {

				if (fieldValue != null) {
					preparedStatement.setInt(parameterIndex,
							(int) (Integer) fieldValue);
				} else {
					preparedStatement.setNull(parameterIndex,
							java.sql.Types.INTEGER);
				}
			} else if (fieldType == long.class || fieldType == Long.class) {

				if (fieldValue != null) {
					preparedStatement.setLong(parameterIndex,
							(long) (Long) fieldValue);
				} else {
					preparedStatement.setNull(parameterIndex,
							java.sql.Types.INTEGER);
				}
			} else if (fieldType == float.class || fieldType == Float.class) {

				if (fieldValue != null) {
					preparedStatement.setFloat(parameterIndex,
							(float) (Float) fieldValue);
				} else {
					preparedStatement.setNull(parameterIndex,
							java.sql.Types.FLOAT);
				}

			} else if (fieldType == double.class || fieldType == Double.class) {

				if (fieldValue != null) {
					preparedStatement.setDouble(parameterIndex,
							(double) (Double) fieldValue);
				} else {
					preparedStatement.setNull(parameterIndex,
							java.sql.Types.DOUBLE);
				}

			} else {
				final String msg = "Unknown data type. type=" + fieldType
						+ " value=" + fieldValue;
				loge(msg);
				throw new RuntimeException(msg);
			}
		} catch (Exception e) {
			loge("#setValue", e);
			throw e;
		}

	}
824980
private int bindStatement(PreparedStatement stmt, int index, SelectionCriteria crit, ClassDescriptor cld) throws SQLException
    {
        return bindStatementValue(stmt, index, crit.getAttribute(), crit.getValue(), cld);
    }
849907
static SQLTransform getUtilTransform(TypeName type) {
		String typeName = type.toString();

		// Integer.class.getCanonicalName().equals(typeName)
		if (Date.class.getCanonicalName().equals(typeName)) {
			return new DateSQLTransform();
		}
		if (Locale.class.getCanonicalName().equals(typeName)) {
			return new LocaleSQLTransform();
		}
		if (Currency.class.getCanonicalName().equals(typeName)) {
			return new CurrencySQLTransform();
		}
		if (Calendar.class.getCanonicalName().equals(typeName)) {
			return new CalendarSQLTransform();
		}
		if (TimeZone.class.getCanonicalName().equals(typeName)) {
			return new TimeZoneSQLTransform();
		}
		return null;
	}
912486
@Override
    public void set(BindingSetStatementContext<JsonArray> ctx) throws SQLException {
        ctx.statement().setString(ctx.index(), Objects.toString(ctx.convert(converter()).value(), null));
    }
1037944
def _setter(self, obj, value):
        
        if isinstance(value, DynamicValue):  # execute lambda values.
            fvalue = value()

        else:
            fvalue = value

        self._validate(data=fvalue, owner=obj)

        if self._fset_ is not None:
            self._fset_(obj, fvalue)

        else:
            setattr(obj, self._attrname(), value)

        # notify obj about the new value.
        if isinstance(obj, Schema):
            obj._setvalue(self, fvalue)
1141248
public static Object getValue4Type(ResultSet rs, String column, Class<?> typeClass) throws SQLException {

        if (Collection.class.isAssignableFrom(typeClass)) {
            return null;
        }

        try {
            rs.findColumn(column);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        if (typeClass.equals(Integer.class) || typeClass.equals(Integer.TYPE)) {
            return rs.getInt(column);
        }

        if (typeClass.equals(Long.class) || typeClass.equals(Long.TYPE)) {
            return rs.getLong(column);
        }

        if (typeClass.equals(Boolean.class) || typeClass.equals(Boolean.TYPE)) {
            return rs.getBoolean(column);
        }

        if (typeClass.equals(Float.class) || typeClass.equals(Float.TYPE)) {
            return rs.getFloat(column);
        }

        if (typeClass.equals(Double.class) || typeClass.equals(Double.TYPE)) {
            return rs.getDouble(column);
        }

        if (typeClass.equals(Byte.class) || typeClass.equals(Byte.TYPE)) {
            return rs.getByte(column);
        }

        if (typeClass.equals(String.class)) {
            return rs.getString(column);
        }

        if (Date.class.isAssignableFrom(typeClass)) {
            return rs.getTimestamp(column);
        }

        if (java.sql.Date.class.isAssignableFrom(typeClass)) {
            return rs.getDate(column);
        }

        return rs.getObject(column);
    }
515478
public Object getValue(final JavaType type, final ResultSet rs, final int columnIndex) throws SQLException {
		Class<?> rawType = type.getRawType();
		for (PropertyMapper<?> propertyMapper : this.mappers) {
			if (propertyMapper.canAccept(rawType) && propertyMapper.canAcceptTest(type, rs, columnIndex, this)) {
				return propertyMapper.getValue(type, rs, columnIndex, this);
			}
		}

		if (String.class.equals(rawType)) {
			return rs.getString(columnIndex);
		}
		if (Boolean.class.equals(rawType)) {
			boolean result = rs.getBoolean(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (boolean.class.equals(rawType)) {
			return rs.getBoolean(columnIndex);
		}
		if (Byte.class.equals(rawType)) {
			byte result = rs.getByte(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (byte.class.equals(rawType)) {
			return rs.getByte(columnIndex);
		}
		if (Short.class.equals(rawType)) {
			short result = rs.getShort(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (short.class.equals(rawType)) {
			return rs.getShort(columnIndex);
		}
		if (Integer.class.equals(rawType)) {
			int result = rs.getInt(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (int.class.equals(rawType)) {
			return rs.getInt(columnIndex);
		}
		if (Long.class.equals(rawType)) {
			long result = rs.getLong(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (long.class.equals(rawType)) {
			return rs.getLong(columnIndex);
		}
		if (Float.class.equals(rawType)) {
			float result = rs.getFloat(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (float.class.equals(rawType)) {
			return rs.getFloat(columnIndex);
		}
		if (Double.class.equals(rawType)) {
			double result = rs.getDouble(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (double.class.equals(rawType)) {
			return rs.getDouble(columnIndex);
		}
		if (BigDecimal.class.equals(rawType)) {
			return rs.getBigDecimal(columnIndex);
		}
		if (byte[].class.equals(rawType)) {
			return rs.getBytes(columnIndex);
		}
		if (java.sql.Timestamp.class.equals(rawType)) {
			return rs.getTimestamp(columnIndex);
		}
		if (java.sql.Time.class.equals(rawType)) {
			return rs.getTime(columnIndex);
		}
		if (java.sql.Date.class.equals(rawType)) {
			return rs.getDate(columnIndex);
		}
		if (Date.class.equals(rawType)) {
			return rs.getTimestamp(columnIndex);
		}
		if (java.sql.Array.class.equals(rawType)) {
			return rs.getArray(columnIndex);
		}
		if (java.sql.Blob.class.equals(rawType)) {
			return rs.getBlob(columnIndex);
		}
		if (java.sql.Clob.class.equals(rawType)) {
			return rs.getClob(columnIndex);
		}
		if (java.sql.NClob.class.equals(rawType)) {
			return rs.getNClob(columnIndex);
		}
		if (java.sql.Ref.class.equals(rawType)) {
			return rs.getRef(columnIndex);
		}
		if (java.sql.SQLXML.class.equals(rawType)) {
			return rs.getSQLXML(columnIndex);
		}
		for (PropertyMapper<?> propertyMapper : DEFAULT_MAPPERS) {
			if (propertyMapper.canAccept(rawType) && propertyMapper.canAcceptTest(type, rs, columnIndex, this)) {
				return propertyMapper.getValue(type, rs, columnIndex, this);
			}
		}
		return rs.getObject(columnIndex);
	}
1313831
private static Object toDatabaseSupportedValue(Object value) {
        if (value instanceof java.lang.String ||
                value instanceof byte[] ||
                value instanceof Byte[] ||
                value instanceof java.lang.Long ||
                value instanceof java.lang.Integer ||
                value instanceof java.lang.Boolean ||
                value instanceof java.math.BigInteger ||
                value instanceof java.lang.Float ||
                value instanceof java.lang.Double ||
                value instanceof java.math.BigDecimal ||
                value instanceof java.sql.Date ||
                value instanceof java.util.Date ||
                /*
                because java.sql.Time and java.sql.Timestamp is subclass of java.sql.Date so the checks always return true
                value instanceof java.sql.Time || value instanceof java.sql.Timestamp ||
                */
                value instanceof java.util.Calendar
                ) {
            return value;
        } else {
            return Reflection.toType(value, String.class);
        }
    }
838890
public static String sqlValueToString(ResultSet rs, int index, int sqlType) throws SQLException {
        Class<?> requiredType = sqlTypeToJavaTypeMap.get(sqlType);
        if (requiredType == null) {
            throw new IllegalArgumentException("unknow java.sql.Types - " + sqlType);
        }

        return getResultSetValue(rs, index, requiredType);
    }
128095
private void set(String fieldName, Object value) {
    try {
      String subField;
      Iterator<String> levels = Splitter.on(".").split(fieldName).iterator();
      GenericRecord toInsert = record;
      subField = levels.next();
      Object subRecord = toInsert;

      while (levels.hasNext()) {
        if (subRecord instanceof GenericRecord) {
          subRecord = ((GenericRecord)subRecord).get(subField);
        } else if (subRecord instanceof List) {
          subRecord = ((List)subRecord).get(Integer.parseInt(subField));
        } else if (subRecord instanceof Map) {
          subRecord = ((Map)subRecord).get(subField);
        }

        if (subRecord == null) {
          throw new FieldDoesNotExistException("Field " + subField + " not found when trying to set " + fieldName);
        }
        subField = levels.next();
      }

      if (!(subRecord instanceof GenericRecord)) {
        throw new IllegalArgumentException("Field " + fieldName + " does not refer to a record type.");
      }

      toInsert = (GenericRecord)subRecord;
      Object oldValue = toInsert.get(subField);

      toInsert.put(subField, value);

      Schema.Field changedField = toInsert.getSchema().getField(subField);
      GenericData genericData = GenericData.get();

      boolean valid = genericData
          .validate(changedField.schema(), genericData.getField(toInsert, changedField.name(), changedField.pos()));
      if (!valid) {
        toInsert.put(subField, oldValue);
        throw new IncorrectTypeException(
            "Incorrect type - can't insert a " + value.getClass().getCanonicalName() + " into an Avro record of type "
                + changedField.schema().getType().toString());
      }
    } catch (AvroRuntimeException e) {
      throw new FieldDoesNotExistException("Field not found setting name " + fieldName, e);
    }
  }
699470
@SuppressWarnings("unchecked")
  protected <T> T set(DBIDRef id, int index, T value) {
    Object[] d = data.get(DBIDUtil.deref(id));
    if(d == null) {
      d = new Object[rlen];
      data.put(DBIDUtil.deref(id), d);
    }
    T ret = (T) d[index];
    d[index] = value;
    return ret;
  }
649042
@NotNull
    public DbPreparedStatement<T> set(@NotNull String name, @Nullable DbLong value) throws SQLException {
        return value == null ? setNull(name, JDBCType.BIGINT) : set(name, value.getDbValue());
    }