Search in sources :

Example 31 with LinkedHashMap

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());
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) ArrayList(java.util.ArrayList) PostgreGenericTrigger(org.jkiss.dbeaver.ext.postgresql.model.PostgreGenericTrigger) LinkedHashMap(java.util.LinkedHashMap)

Example 32 with LinkedHashMap

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 33 with LinkedHashMap

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 34 with LinkedHashMap

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);
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) CharacterCodingException(java.nio.charset.CharacterCodingException) BoundStatement(com.datastax.driver.core.BoundStatement) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 35 with LinkedHashMap

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);
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Slice(io.airlift.slice.Slice) DecimalType(com.facebook.presto.spi.type.DecimalType) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) FixedWidthType(com.facebook.presto.spi.type.FixedWidthType) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2393 Map (java.util.Map)691 ArrayList (java.util.ArrayList)674 HashMap (java.util.HashMap)439 Test (org.junit.Test)317 List (java.util.List)297 IOException (java.io.IOException)151 HashSet (java.util.HashSet)128 Set (java.util.Set)110 LinkedHashSet (java.util.LinkedHashSet)100 File (java.io.File)93 LinkedList (java.util.LinkedList)75 TreeMap (java.util.TreeMap)72 Node (org.apache.hadoop.hive.ql.lib.Node)70 NodeProcessor (org.apache.hadoop.hive.ql.lib.NodeProcessor)68 Rule (org.apache.hadoop.hive.ql.lib.Rule)68 GraphWalker (org.apache.hadoop.hive.ql.lib.GraphWalker)66 Dispatcher (org.apache.hadoop.hive.ql.lib.Dispatcher)65 Iterator (java.util.Iterator)64 DefaultRuleDispatcher (org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)64