use of java.util.LinkedHashMap in project dbeaver by serge-rider.
the class PostgreMetaModel method loadTriggers.
@Override
public List<PostgreGenericTrigger> loadTriggers(DBRProgressMonitor monitor, @NotNull GenericStructContainer container, @Nullable GenericTable table) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read triggers")) {
StringBuilder sql = new StringBuilder();
sql.append("SELECT trigger_name,event_manipulation,action_order,action_condition,action_statement,action_orientation,action_timing\n" + "FROM INFORMATION_SCHEMA.TRIGGERS\n" + "WHERE ");
if (table == null) {
sql.append("trigger_schema=? AND event_object_table IS NULL");
} else {
sql.append("event_object_schema=? AND event_object_table=?");
}
try (JDBCPreparedStatement dbStat = session.prepareStatement(sql.toString())) {
if (table == null) {
dbStat.setString(1, container.getSchema().getName());
} else {
dbStat.setString(1, table.getSchema().getName());
dbStat.setString(2, table.getName());
}
Map<String, PostgreGenericTrigger> result = new LinkedHashMap<>();
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, "trigger_name");
if (name == null) {
continue;
}
String manipulation = JDBCUtils.safeGetString(dbResult, "event_manipulation");
PostgreGenericTrigger trigger = result.get(name);
if (trigger != null) {
trigger.addManipulation(manipulation);
continue;
}
String description = "";
trigger = new PostgreGenericTrigger(container, table, name, description, manipulation, JDBCUtils.safeGetString(dbResult, "action_orientation"), JDBCUtils.safeGetString(dbResult, "action_timing"), JDBCUtils.safeGetString(dbResult, "action_statement"));
result.put(name, trigger);
}
}
return new ArrayList<>(result.values());
}
} catch (SQLException e) {
throw new DBException(e, container.getDataSource());
}
}
use of java.util.LinkedHashMap in project jodd by oblac.
the class JsonSerializerTest method testSimpleMap.
// ---------------------------------------------------------------- tests
@Test
public void testSimpleMap() {
Map map = new LinkedHashMap();
map.put("one", "uno");
map.put("two", "duo");
JsonSerializer jsonSerializer = new JsonSerializer();
String json = jsonSerializer.serialize(map);
assertEquals("{\"one\":\"uno\",\"two\":\"duo\"}", json);
map = new LinkedHashMap();
map.put("one", Long.valueOf(173));
map.put("two", Double.valueOf(7.89));
map.put("three", Boolean.TRUE);
map.put("four", null);
map.put("five", "new\nline");
jsonSerializer = new JsonSerializer();
json = jsonSerializer.serialize(map);
assertEquals("{\"one\":173,\"two\":7.89,\"three\":true,\"four\":null,\"five\":\"new\\nline\"}", json);
}
use of java.util.LinkedHashMap in project jodd by oblac.
the class JsonSerializerTest method testInMapVsInBeanbsInList.
@Test
public void testInMapVsInBeanbsInList() {
HashMap<String, Object> params = new HashMap<>();
params.put("myid", Integer.valueOf(4343));
ArrayList<String> names = new ArrayList<>();
names.add("veqna");
// in map
LinkedHashMap<String, Object> rootMap = new LinkedHashMap<>();
rootMap.put("params", params);
rootMap.put("names", names);
JsonSerializer jsonSerializer = new JsonSerializer();
String json = jsonSerializer.serialize(rootMap);
Assert.assertEquals("{\"params\":{\"myid\":4343}}", json);
// in bean
InBean inBean = new InBean();
inBean.setParams(params);
inBean.setNames(names);
jsonSerializer = new JsonSerializer();
json = jsonSerializer.serialize(inBean);
Assert.assertEquals("{}", json);
// in list
ArrayList list = new ArrayList();
list.add(params);
list.add(names);
jsonSerializer = new JsonSerializer();
json = jsonSerializer.serialize(inBean);
Assert.assertEquals("{}", json);
}
use of java.util.LinkedHashMap in project zipkin by openzipkin.
the class CassandraSpanStore method getTraceIdsByAnnotation.
ListenableFuture<Map<Long, Long>> getTraceIdsByAnnotation(String annotationKey, long endTs, long lookback, int limit) {
long startTs = endTs - lookback;
try {
BoundStatement bound = CassandraUtil.bindWithName(selectTraceIdsByAnnotation, "select-trace-ids-by-annotation").setBytes("annotation", CassandraUtil.toByteBuffer(annotationKey)).setSet("bucket", buckets).setBytesUnsafe("start_ts", timestampCodec.serialize(startTs)).setBytesUnsafe("end_ts", timestampCodec.serialize(endTs)).setInt("limit_", limit);
bound.setFetchSize(Integer.MAX_VALUE);
return transform(session.executeAsync(bound), new Function<ResultSet, Map<Long, Long>>() {
@Override
public Map<Long, Long> apply(ResultSet input) {
Map<Long, Long> traceIdsToTimestamps = new LinkedHashMap<>();
for (Row row : input) {
traceIdsToTimestamps.put(row.getLong("trace_id"), timestampCodec.deserialize(row, "ts"));
}
return traceIdsToTimestamps;
}
});
} catch (CharacterCodingException | RuntimeException ex) {
return immediateFailedFuture(ex);
}
}
use of java.util.LinkedHashMap in project presto by prestodb.
the class TypeJsonUtils method stackRepresentationToObjectHelper.
private static Object stackRepresentationToObjectHelper(ConnectorSession session, JsonParser parser, Type type) throws IOException {
// cast('[null]', array(json)) should be casted to a single item array containing a json document "null" instead of sql null.
if (type instanceof JsonType) {
return OBJECT_MAPPER.writeValueAsString(parser.readValueAsTree());
}
if (parser.getCurrentToken() == JsonToken.VALUE_NULL) {
return null;
}
if (type instanceof ArrayType) {
List<Object> list = new ArrayList<>();
checkState(parser.getCurrentToken() == JsonToken.START_ARRAY, "Expected a json array");
while (parser.nextToken() != JsonToken.END_ARRAY) {
list.add(stackRepresentationToObjectHelper(session, parser, ((ArrayType) type).getElementType()));
}
return Collections.unmodifiableList(list);
}
if (type instanceof MapType) {
Map<Object, Object> map = new LinkedHashMap<>();
checkState(parser.getCurrentToken() == JsonToken.START_OBJECT, "Expected a json object");
while (parser.nextValue() != JsonToken.END_OBJECT) {
Object key = mapKeyToObject(session, parser.getCurrentName(), ((MapType) type).getKeyType());
Object value = stackRepresentationToObjectHelper(session, parser, ((MapType) type).getValueType());
map.put(key, value);
}
return Collections.unmodifiableMap(map);
}
if (type instanceof RowType) {
List<Object> list = new ArrayList<>();
checkState(parser.getCurrentToken() == JsonToken.START_ARRAY, "Expected a json array");
int field = 0;
RowType rowType = (RowType) type;
while (parser.nextValue() != JsonToken.END_ARRAY) {
checkArgument(field < rowType.getFields().size(), "Unexpected field for type %s", type);
Object value = stackRepresentationToObjectHelper(session, parser, rowType.getFields().get(field).getType());
list.add(value);
field++;
}
checkArgument(field == rowType.getFields().size(), "Expected %s fields for type %s", rowType.getFields().size(), type);
return Collections.unmodifiableList(list);
}
Slice sliceValue = null;
if (type.getJavaType() == Slice.class) {
sliceValue = Slices.utf8Slice(parser.getValueAsString());
}
BlockBuilder blockBuilder;
if (type instanceof FixedWidthType) {
blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), 1);
} else {
blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), 1, requireNonNull(sliceValue, "sliceValue is null").length());
}
if (type instanceof DecimalType) {
return getSqlDecimal((DecimalType) type, parser.getDecimalValue());
} else if (type.getJavaType() == boolean.class) {
type.writeBoolean(blockBuilder, parser.getBooleanValue());
} else if (type.getJavaType() == long.class) {
type.writeLong(blockBuilder, parser.getLongValue());
} else if (type.getJavaType() == double.class) {
type.writeDouble(blockBuilder, getDoubleValue(parser));
} else if (type.getJavaType() == Slice.class) {
type.writeSlice(blockBuilder, requireNonNull(sliceValue, "sliceValue is null"));
}
return type.getObjectValue(session, blockBuilder.build(), 0);
}
Aggregations