PageRenderTime 40ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/db/objects/UserProperty.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 110 lines | 65 code | 13 blank | 32 comment | 2 complexity | 014d86f784953f7d7f1fa93906455386 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. * This file is part of YaBS.
  3. *
  4. * YaBS is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * YaBS is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package mpv5.db.objects;
  18. import java.util.Date;
  19. import mpv5.db.common.NodataFoundException;
  20. import mpv5.db.common.QueryParameter;
  21. import javax.swing.JComponent;
  22. import mpv5.db.common.Context;
  23. import mpv5.db.common.DatabaseObject;
  24. import mpv5.db.common.QueryCriteria;
  25. import mpv5.db.common.QueryCriteria2;
  26. import mpv5.db.common.QueryData;
  27. import mpv5.db.common.QueryHandler;
  28. import mpv5.logging.Log;
  29. import mpv5.utils.date.DateConverter;
  30. import static mpv5.db.common.QueryParameter.*;
  31. /**
  32. *
  33. *
  34. */
  35. public class UserProperty extends DatabaseObject {
  36. public UserProperty() {
  37. setContext(Context.getUserProperties());
  38. }
  39. private String value = "";
  40. private int usersids;
  41. @Override
  42. public JComponent getView() {
  43. throw new UnsupportedOperationException("Not supported yet.");
  44. }
  45. /**
  46. * @return the value
  47. */
  48. public String __getValue() {
  49. return value;
  50. }
  51. /**
  52. * @param value the value to set
  53. */
  54. public void setValue(String value) {
  55. this.value = value;
  56. }
  57. @Override
  58. public boolean save() {
  59. if (value == null) {
  60. value = "";
  61. }
  62. QueryCriteria2 q = new QueryCriteria2();
  63. q.and(new QueryParameter(getContext(), "usersids", usersids, EQUALS),
  64. new QueryParameter(getContext(), "groupsids", __getGroupsids(), EQUALS),
  65. new QueryParameter(getContext(), "cname", getCname(), EQUALS));
  66. try {
  67. update(q);
  68. return true;
  69. } catch (Exception e) {
  70. Log.Debug(this, e.getMessage());
  71. QueryHandler.instanceOf().clone(Context.getUserProperties()).delete(q);
  72. return super.save(true);
  73. }
  74. }
  75. private void update(QueryCriteria2 q) throws NodataFoundException {
  76. QueryData d = new QueryData();
  77. d.add("value", value);
  78. d.add("dateadded", DateConverter.getSQLDateString(new Date()));
  79. QueryHandler.instanceOf().clone(Context.getUserProperties()).updateOrCreate(d, q, null);
  80. }
  81. /**
  82. * @return the usersids
  83. */
  84. public int __getUsersids() {
  85. return usersids;
  86. }
  87. /**
  88. * @param usersids the usersids to set
  89. */
  90. public void setUsersids(int usersids) {
  91. this.usersids = usersids;
  92. }
  93. @Override
  94. public mpv5.utils.images.MPIcon getIcon() {
  95. return null;
  96. }
  97. }