private Value convertToUnknownValue(Object x) { checkClosed(); return DataType.convertToValue(conn.getSession(), x, Value.UNKNOWN); }
JavaMethod(Method method, int id) { this.method = method; this.id = id; Class<?>[] paramClasses = method.getParameterTypes(); paramCount = paramClasses.length; if (paramCount > 0) { Class<?> paramClass = paramClasses[0]; if (Connection.class.isAssignableFrom(paramClass)) { hasConnectionParam = true; paramCount--; } } if (paramCount > 0) { Class<?> lastArg = paramClasses[paramClasses.length - 1]; if (lastArg.isArray() && method.isVarArgs()) { varArgs = true; varArgClass = lastArg.getComponentType(); } } Class<?> returnClass = method.getReturnType(); dataType = DataType.getTypeFromClass(returnClass); }
@Override public int getScale() { return DataType.getDataType(dataType).defaultScale; }
/** * Returns the Java class name if this column. * * @param columnIndex (1,2,...) * @return the class name */ @Override public String getColumnClassName(int columnIndex) throws SQLException { int type = DataType.getValueTypeFromResultSet(this, columnIndex); return DataType.getTypeClassName(type); }
@Override public int getInternalType(int[] inputTypes) throws SQLException { int[] sqlTypes = new int[inputTypes.length]; for (int i = 0; i < inputTypes.length; i++) { sqlTypes[i] = DataType.convertTypeToSQLType(inputTypes[i]); } return DataType.convertSQLTypeToValueType(aggregateFunction.getType(sqlTypes)); }
/** * Adds a column to the result set. * All columns must be added before adding rows. * This method uses the default SQL type names. * * @param name null is replaced with C1, C2,... * @param sqlType the value returned in getColumnType(..) * @param precision the precision * @param scale the scale */ public void addColumn(String name, int sqlType, int precision, int scale) { int valueType = DataType.convertSQLTypeToValueType(sqlType); addColumn(name, sqlType, DataType.getDataType(valueType).name, precision, scale); }
paramClass = paramClasses[p]; int type = DataType.getTypeFromClass(paramClass); Value v = args[a].getValue(session); Object o; Object[] objArray = (Object[]) Array.newInstance( paramClass.getComponentType(), array.length); int componentType = DataType.getTypeFromClass( paramClass.getComponentType()); for (int i = 0; i < objArray.length; i++) { o = DataType.getDefaultForPrimitiveType(paramClass); } else { o = DataType.convertTo(session.createConnection(false), v, paramClass); return (Value) returnValue; Value ret = DataType.convertToValue(session, returnValue, dataType); return ret.convertTo(dataType); } finally {
/** * Checks presence of specific table column and returns it. * * @param node Node to check. * @param schemaName Schema name to look for the table in. * @param tblName Table name to check. * @param colName Column name whose presence must be checked. * @return field or {@code null} if not found. * @throws SQLException if failed. */ static QueryField getColumnMeta(IgniteEx node, String schemaName, String tblName, String colName) throws SQLException { try (Connection c = connect(node)) { try (ResultSet rs = c.getMetaData().getColumns(null, schemaName, tblName, colName)) { while (rs.next()) { String name = rs.getString("COLUMN_NAME"); short type = rs.getShort("DATA_TYPE"); String typeClsName = DataType.getTypeClassName(DataType.convertSQLTypeToValueType(type)); short nullable = rs.getShort("NULLABLE"); return new QueryField(name, typeClsName, nullable == 1); } } } return null; }
DataType colType = DataType.getDataType(col.getType()); DataType dfltType = DataType.getDataType(col.getDefaultExpression().getType()); if ((DataType.isStringType(colType.type) && !DataType.isStringType(dfltType.type)) || (DataType.supportsAdd(colType.type) && !DataType.supportsAdd(dfltType.type))) { throw new IgniteSQLException("Invalid default value for column. [colName=" + col.getName() + ", colType=" + colType.name
for (DataType t : DataType.getTypes()) { if (t.hidden || t.sqlType == Value.NULL) { continue; DataType dt = DataType.getDataType(method.getDataType()); add(rows, int dataType = DataType.getTypeFromClass(clazz); DataType dt = DataType.getDataType(dataType); int nullable = clazz.isPrimitive() ? DatabaseMetaData.columnNoNulls : DatabaseMetaData.columnNullable; "" + DataType.convertTypeToSQLType(expr.getType()),
/** * Check whether a given object is a Geometry object. * * @param x the the object * @return true if it is a Geometry object */ public static boolean isGeometry(Object x) { if (x == null) { return false; } return isGeometryClass(x.getClass()); }
/** * Helper function for obtaining type class name for H2. * * @param col Column. * @return Type class name. */ private static String getTypeClassName(GridSqlColumn col) { int type = col.column().getType(); switch (type) { case Value.UUID : if (!handleUuidAsByte) return UUID.class.getName(); default: return DataType.getTypeClassName(type); } } }
private static DataType createString(boolean caseSensitive) { DataType dataType = new DataType(); dataType.prefix = "'"; dataType.suffix = "'"; dataType.params = "LENGTH"; dataType.caseSensitive = caseSensitive; dataType.supportsPrecision = true; dataType.maxPrecision = Integer.MAX_VALUE; dataType.defaultPrecision = Integer.MAX_VALUE; dataType.defaultDisplaySize = Integer.MAX_VALUE; return dataType; }
} else if (!DataType.supportsAdd(dataType)) { throw DbException.get(ErrorCode.SUM_OR_AVG_ON_WRONG_DATATYPE_1, getSQL()); } else { dataType = DataType.getAddProofType(dataType); if (!DataType.supportsAdd(dataType)) { throw DbException.get(ErrorCode.SUM_OR_AVG_ON_WRONG_DATATYPE_1, getSQL()); case BIT_AND: case BIT_OR: if (!DataType.supportsAdd(dataType)) { throw DbException.get(ErrorCode.SUM_OR_AVG_ON_WRONG_DATATYPE_1, getSQL());
/** * Sets the value of a parameter. The object is converted, if required, to * the specified data type before sending to the database. * Objects of unknown classes are serialized (on the client side). * * @param parameterIndex the parameter index (1, 2, ...) * @param x the value, null is allowed * @param targetSqlType the type as defined in java.sql.Types * @throws SQLException if this object is closed */ @Override public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { try { if (isDebugEnabled()) { debugCode("setObject("+parameterIndex+", x, "+targetSqlType+");"); } int type = DataType.convertSQLTypeToValueType(targetSqlType); if (x == null) { setParameter(parameterIndex, ValueNull.INSTANCE); } else { Value v = DataType.convertToValue(conn.getSession(), x, type); setParameter(parameterIndex, v.convertTo(type)); } } catch (Exception e) { throw logAndConvert(e); } }
@Override String prepareRowColumnForSelectStaticStrings(String value, String colName) { int dataType = DataType.getTypeFromClass(value.getClass()); DataType type = DataType.getDataType(dataType); return "CAST(? as " + type.name + ") as " + colName; }
@Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException { prep.setNull(parameterIndex, DataType.convertTypeToSQLType(Value.NULL)); }
java.sql.Array array = (java.sql.Array) x; try { return convertToValue(session, array.getArray(), Value.ARRAY); } catch (SQLException e) { throw DbException.convert(e); Value[] v = new Value[len]; for (int i = 0; i < len; i++) { v[i] = convertToValue(session, o[i], type); } else if (isGeometry(x)) { return ValueGeometry.getFromGeometry(x); } else if (clazz == LocalDateTimeUtils.LOCAL_DATE) {
scale = convertScale(sqlType, scale); int displaySize = MathUtils.convertLongToInt(precision); int type = DataType.convertSQLTypeToValueType(sqlType, sqlTypeName); Column col = new Column(n, type, precision, scale, displaySize); col.setTable(this, i++); scale = convertScale(sqlType, scale); int displaySize = rsMeta.getColumnDisplaySize(i + 1); int type = DataType.getValueTypeFromResultSet(rsMeta, i + 1); Column col = new Column(n, type, precision, scale, displaySize); col.setTable(this, i++);
/** * Convert a SQL type to a value type using SQL type name, in order to * manage SQL type extension mechanism. * * @param sqlType the SQL type * @param sqlTypeName the SQL type name * @return the value type */ public static int convertSQLTypeToValueType(int sqlType, String sqlTypeName) { switch (sqlType) { case Types.OTHER: case Types.JAVA_OBJECT: if (sqlTypeName.equalsIgnoreCase("geometry")) { return Value.GEOMETRY; } } return convertSQLTypeToValueType(sqlType); }