You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WidgetPropertyDao.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.dashboard.db;
  21. import com.google.common.base.Function;
  22. import java.util.Arrays;
  23. import java.util.Collection;
  24. import java.util.List;
  25. import org.sonar.db.dashboard.WidgetPropertyDto;
  26. import org.sonar.db.dashboard.WidgetPropertyMapper;
  27. import org.sonar.db.Dao;
  28. import org.sonar.db.DaoUtils;
  29. import org.sonar.db.DbSession;
  30. import org.sonar.db.MyBatis;
  31. public class WidgetPropertyDao implements Dao {
  32. private final MyBatis myBatis;
  33. public WidgetPropertyDao(MyBatis myBatis) {
  34. this.myBatis = myBatis;
  35. }
  36. public WidgetPropertyDto insert(WidgetPropertyDto item) {
  37. DbSession session = myBatis.openSession(false);
  38. try {
  39. return insert(session, item);
  40. } finally {
  41. MyBatis.closeQuietly(session);
  42. }
  43. }
  44. public WidgetPropertyDto insert(DbSession session, WidgetPropertyDto item) {
  45. mapper(session).insert(item);
  46. return item;
  47. }
  48. public void insert(DbSession session, Collection<WidgetPropertyDto> items) {
  49. for (WidgetPropertyDto item : items) {
  50. insert(session, item);
  51. }
  52. }
  53. public WidgetPropertyDto getNullableByKey(Long propertyId) {
  54. DbSession session = myBatis.openSession(false);
  55. try {
  56. return getNullableByKey(session, propertyId);
  57. } finally {
  58. MyBatis.closeQuietly(session);
  59. }
  60. }
  61. public WidgetPropertyDto getNullableByKey(DbSession session, Long propertyId) {
  62. return mapper(session).selectById(propertyId);
  63. }
  64. public Collection<WidgetPropertyDto> findByDashboard(DbSession session, long dashboardKey) {
  65. return mapper(session).selectByDashboard(dashboardKey);
  66. }
  67. public void deleteByWidgetIds(final DbSession session, List<Long> widgetIdsWithPropertiesToDelete) {
  68. DaoUtils.executeLargeInputs(widgetIdsWithPropertiesToDelete, new Function<List<Long>, List<Void>>() {
  69. @Override
  70. public List<Void> apply(List<Long> input) {
  71. mapper(session).deleteByWidgetIds(input);
  72. return Arrays.asList();
  73. }
  74. });
  75. }
  76. private WidgetPropertyMapper mapper(DbSession session) {
  77. return session.getMapper(WidgetPropertyMapper.class);
  78. }
  79. }