Fix a bug in state history and definition dimension queries
Do not share query bind method with other alarm queries Change-Id: I974a3db80883783f696339776e350a7ff9359935
This commit is contained in:
parent
33d3623f1a
commit
11e1d27f7c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014,2016 Hewlett Packard Enterprise Development Company, L.P.
|
||||
* (C) Copyright 2014,2016 Hewlett Packard Enterprise Development Company LP
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
@ -15,6 +15,8 @@ package monasca.api.infrastructure.persistence;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import org.skife.jdbi.v2.Query;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -48,4 +50,15 @@ public final class SubAlarmDefinitionQueries {
|
||||
|
||||
return sbJoin.toString();
|
||||
}
|
||||
|
||||
public static void bindDimensionsToQuery(Query query, Map<String, String> dimensions) {
|
||||
if (dimensions != null) {
|
||||
int i = 0;
|
||||
for (Map.Entry<String, String> entry: dimensions.entrySet()) {
|
||||
query.bind("dname" + i, entry.getKey());
|
||||
query.bind("dvalue" + i, entry.getValue());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014,2016 Hewlett Packard Enterprise Development Company, L.P.
|
||||
* (C) Copyright 2014,2016 Hewlett Packard Enterprise Development Company LP
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
@ -203,7 +203,7 @@ public class AlarmDefinitionMySqlRepoImpl implements AlarmDefinitionRepo {
|
||||
|
||||
q.registerMapper(new AlarmDefinitionMapper());
|
||||
q = q.mapTo(AlarmDefinition.class);
|
||||
DimensionQueries.bindDimensionsToQuery(q, dimensions);
|
||||
SubAlarmDefinitionQueries.bindDimensionsToQuery(q, dimensions);
|
||||
List<AlarmDefinition> resultSet = (List<AlarmDefinition>) q.list();
|
||||
return resultSet;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
|
||||
* (C) Copyright 2015-2016 Hewlett Packard Enterprise Development Company LP
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
@ -27,7 +27,6 @@ import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import monasca.api.infrastructure.persistence.DimensionQueries;
|
||||
import monasca.api.infrastructure.persistence.Utils;
|
||||
|
||||
public class MySQLUtils
|
||||
@ -64,7 +63,7 @@ public class MySQLUtils
|
||||
|
||||
logger.debug("mysql sql: {}", sql);
|
||||
|
||||
DimensionQueries.bindDimensionsToQuery(query, dimensions);
|
||||
this.bindDimensionsToQuery(query, dimensions);
|
||||
|
||||
alarmIdList = query.map(StringMapper.FIRST).list();
|
||||
}
|
||||
@ -72,4 +71,15 @@ public class MySQLUtils
|
||||
return alarmIdList;
|
||||
}
|
||||
|
||||
private void bindDimensionsToQuery(Query query, Map<String, String> dimensions) {
|
||||
if (dimensions != null) {
|
||||
int i = 0;
|
||||
for (Map.Entry<String, String> entry : dimensions.entrySet()) {
|
||||
query.bind("dname" + i, entry.getKey());
|
||||
query.bind("dvalue" + i, entry.getValue());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user