@Override public Object getResultSetValue(ResultSet resultSet, int columnIndex, Column column) throws SQLException { if (column.getNativeType() != null) { switch (column.getNativeType()) { case "json": case "jsonb": assert column.getType() == ColumnType.MAP; final String stringValue = resultSet.getString(columnIndex); if (stringValue == null) { return null; } try { return jsonObjectMapper.readValue(stringValue, Map.class); } catch (Exception e) { throw new IllegalArgumentException("Unable to read string as JSON: " + stringValue); } } } return super.getResultSetValue(resultSet, columnIndex, column); }
@Override public Object getResultSetValue(ResultSet resultSet, int columnIndex, Column column) throws SQLException { switch (column.getNativeType()) { case "json": case "jsonb": assert column.getType() == ColumnType.MAP; final String stringValue = resultSet.getString(columnIndex); if (stringValue == null) { return null; } try { return jsonObjectMapper.readValue(stringValue, Map.class); } catch (Exception e) { throw new IllegalArgumentException("Unable to read string as JSON: " + stringValue); } } return super.getResultSetValue(resultSet, columnIndex, column); }
private Map<String, Object> createColumnMap(Column column) { final Map<String, Object> map = new HashMap<>(); map.put("name", column.getName()); map.put("number", column.getColumnNumber()); map.put("type", getTypeName(column)); map.put("size", column.getColumnSize()); map.put("nativeType", column.getNativeType()); map.put("nullable", column.isNullable()); map.put("remarks", column.getRemarks()); map.put("indexed", column.isIndexed()); map.put("quote", column.getQuote()); map.put("primaryKey", column.isPrimaryKey()); return map; }
@Override public void setStatementParameter(PreparedStatement st, int valueIndex, Column column, Object value) throws SQLException { switch (column.getNativeType()) { case "json": case "jsonb": assert column.getType() == ColumnType.MAP; if (value == null) { st.setObject(valueIndex, null); } else { final PGobject pgo = new PGobject(); pgo.setType(column.getNativeType()); if (value instanceof Map) { try { pgo.setValue(jsonObjectMapper.writeValueAsString(value)); } catch (Exception e) { throw new IllegalArgumentException("Unable to write value as JSON string: " + value); } } else { pgo.setValue(value.toString()); } st.setObject(valueIndex, pgo); } return; } super.setStatementParameter(st, valueIndex, column, value); }
@Override public void setStatementParameter(PreparedStatement st, int valueIndex, Column column, Object value) throws SQLException { switch (column.getNativeType()) { case "json": case "jsonb": assert column.getType() == ColumnType.MAP; if (value == null) { st.setObject(valueIndex, null); } else { final PGobject pgo = new PGobject(); pgo.setType(column.getNativeType()); if (value instanceof Map) { try { pgo.setValue(jsonObjectMapper.writeValueAsString(value)); } catch (Exception e) { throw new IllegalArgumentException("Unable to write value as JSON string: " + value); } } else { pgo.setValue(value.toString()); } st.setObject(valueIndex, pgo); } return; } super.setStatementParameter(st, valueIndex, column, value); }
private Column getTextContentColumn(MutableTable table, String preferredColumnName) { MutableColumn column = null; for (Column col : table.getColumns()) { if (NATIVE_TYPE_TEXT.equals(col.getNativeType())) { column = (MutableColumn) col; break; } } if (column == null && preferredColumnName != null) { logger.info("Creating text content column for table: " + table.getName()); column = new MutableColumn(preferredColumnName + TEXT_CONTENT_TEMP_SUFFIX, ColumnType.STRING, table, table .getColumnCount(), true); column.setNativeType(NATIVE_TYPE_TEXT); table.addColumn(column); } return column; }
final String nativeType = column.getNativeType(); final Integer columnSize = column.getColumnSize(); if (nativeType == null) {
final String nativeType = column.getNativeType(); if ("TIMESTAMP".equalsIgnoreCase(nativeType) || "DATETIME".equalsIgnoreCase(nativeType)) { final StringBuilder sb = new StringBuilder();
private MutableColumn getIdColumn(MutableTable table) { MutableColumn column = null; for (Column col : table.getColumns()) { if (NATIVE_TYPE_PRIMARY_KEY.equals(col.getNativeType())) { column = (MutableColumn) col; break; } } if (column == null) { String tableName = table.getName(); logger.info("Creating id column for table: " + tableName); column = new MutableColumn(tableName + "_metamodel_surrogate_id", ColumnType.INTEGER, table, table .getColumnCount(), false); column.setNativeType(NATIVE_TYPE_PRIMARY_KEY); column.setIndexed(true); table.addColumn(column); } return column; }
final String nativeType = column.getNativeType(); if ("TIMESTAMP".equalsIgnoreCase(nativeType) || "DATETIME".equalsIgnoreCase(nativeType)) { final StringBuilder sb = new StringBuilder();
String nativeType = column.getNativeType(); if (!Strings.isNullOrEmpty(nativeType)) { return nativeType;
String nativeType = column.getNativeType(); if (!Strings.isNullOrEmpty(nativeType)) { return nativeType;
Column[] columns = table.getColumns().toArray(new Column[0]); for (Column column : columns) { String nativeType = column.getNativeType();
protected ImmutableColumn(Column column, ImmutableTable table) { this(column.getName(), column.getType(), table, column.getColumnNumber(), column.getColumnSize(), column .getNativeType(), column.isNullable(), column.getRemarks(), column.isIndexed(), column.getQuote(), column.isPrimaryKey()); }
protected ImmutableColumn(Column column, ImmutableTable table) { this(column.getName(), column.getType(), table, column.getColumnNumber(), column.getColumnSize(), column .getNativeType(), column.isNullable(), column.getRemarks(), column.isIndexed(), column.getQuote(), column.isPrimaryKey()); }
@Override public final T like(Column column) { _column.setColumnSize(column.getColumnSize()); _column.setNativeType(column.getNativeType()); _column.setType(column.getType()); _column.setNullable(column.isNullable()); _column.setPrimaryKey(column.isPrimaryKey()); return getReturnObject(); }
@Override public final T like(Column column) { _column.setColumnSize(column.getColumnSize()); _column.setNativeType(column.getNativeType()); _column.setType(column.getType()); _column.setNullable(column.isNullable()); _column.setPrimaryKey(column.isPrimaryKey()); return getReturnObject(); }
/** * Constructs an {@link ImmutableColumn} based on an existing column and a * table. * * @param column * the column to immitate * @param table * the table that the constructed column will pertain to */ public ImmutableColumn(Column column, Table table) { this.name = column.getName(); this.type = column.getType(); this.table = table; this.columnNumber = column.getColumnNumber(); this.columnSize = column.getColumnSize(); this.nativeType = column.getNativeType(); this.nullable = column.isNullable(); this.remarks = column.getRemarks(); this.indexed = column.isIndexed(); this.quote = column.getQuote(); this.primaryKey = column.isPrimaryKey(); }
model.setValueAt(column.getName(), i, 1); model.setValueAt(column.getType(), i, 2); model.setValueAt(column.getNativeType(), i, 3); model.setValueAt(column.getColumnSize(), i, 4);
/** * Constructs an {@link ImmutableColumn} based on an existing column and a * table. * * @param column * the column to immitate * @param table * the table that the constructed column will pertain to */ public ImmutableColumn(Column column, Table table) { this.name = column.getName(); this.type = column.getType(); this.table = table; this.columnNumber = column.getColumnNumber(); this.columnSize = column.getColumnSize(); this.nativeType = column.getNativeType(); this.nullable = column.isNullable(); this.remarks = column.getRemarks(); this.indexed = column.isIndexed(); this.quote = column.getQuote(); this.primaryKey = column.isPrimaryKey(); }