SettingsEntity.java

  1. /*
  2.  * Copyright (C) 2003-2017 eXo Platform SAS.
  3.  *
  4.  * This program is free software: you can redistribute it and/or modify
  5.  * it under the terms of the GNU Affero 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.  * This program 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 Affero General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU Affero General Public License
  15.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17. package org.exoplatform.settings.jpa.entity;

  18. import org.exoplatform.commons.api.persistence.ExoEntity;

  19. import javax.persistence.*;

  20. /**
  21.  * Created by The eXo Platform SAS
  22.  * Author : eXoPlatform
  23.  *          exo@exoplatform.com
  24.  * Mar 07, 2017
  25.  */
  26. @Entity(name = "SettingsEntity")
  27. @ExoEntity
  28. @Table(name = "STG_SETTINGS")
  29. @NamedQueries({
  30.     @NamedQuery(name = "SettingsEntity.getSettingsByContextAndScope", query = "SELECT s FROM SettingsEntity s " +
  31.         "WHERE s.context.type= :contextType " +
  32.         "AND s.context.name= :contextName " +
  33.         "AND s.scope.name= :scopeName " +
  34.         "AND s.scope.type= :scopeType "),
  35.     @NamedQuery(name = "SettingsEntity.getSettingsByContextAndScopeWithNullName", query = "SELECT s FROM SettingsEntity s " +
  36.         "WHERE s.context.type= :contextType " +
  37.         "AND s.context.name= :contextName " +
  38.         "AND s.scope.name IS NULL " +
  39.         "AND s.scope.type= :scopeType "),
  40.     @NamedQuery(name = "SettingsEntity.getSettingByContextAndScopeAndKey", query = "SELECT s FROM SettingsEntity s " +
  41.         "WHERE s.name = :settingName " +
  42.         "AND s.context.type= :contextType " +
  43.         "AND s.context.name= :contextName " +
  44.         "AND s.scope.name= :scopeName " +
  45.         "AND s.scope.type= :scopeType "),
  46.     @NamedQuery(name = "SettingsEntity.getSettingByContextAndScopeWithNullNameAndKey", query = "SELECT s FROM SettingsEntity s " +
  47.         "WHERE s.name = :settingName " +
  48.         "AND s.context.type= :contextType " +
  49.         "AND s.context.name= :contextName " +
  50.         "AND s.scope.name IS NULL " +
  51.         "AND s.scope.type= :scopeType "),
  52.     @NamedQuery(name = "SettingsEntity.countSettingsByNameAndValueAndScope", query = "SELECT count(s.id) FROM SettingsEntity s " +
  53.         "WHERE s.name = :settingName " +
  54.         "AND s.value LIKE :settingValue " +
  55.         "AND s.scope.name= :scopeName " +
  56.         "AND s.scope.type= :scopeType "),
  57.     @NamedQuery(name = "SettingsEntity.countSettingsByNameAndValueAndScopeWithNullName", query = "SELECT count(s.id) FROM SettingsEntity s " +
  58.         "WHERE s.name = :settingName " +
  59.         "AND s.value LIKE :settingValue " +
  60.         "AND s.scope.name IS NULL " +
  61.         "AND s.scope.type= :scopeType "),
  62.     @NamedQuery(name = "SettingsEntity.getSettingsByContextByTypeAndName", query = "SELECT s FROM SettingsEntity s " +
  63.         "WHERE s.context.type= :contextType " +
  64.         "AND s.context.name= :contextName ")
  65. })
  66. public class SettingsEntity {
  67.   @Id
  68.   @Column(name = "SETTING_ID")
  69.   @SequenceGenerator(name="SEQ_STG_SETTINGS_COMMON_ID", sequenceName="SEQ_STG_SETTINGS_COMMON_ID")
  70.   @GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_STG_SETTINGS_COMMON_ID")
  71.   private long id;

  72.   @Column(name = "NAME")
  73.   private String name;

  74.   @Column(name = "VALUE")
  75.   private String value;

  76.   @ManyToOne
  77.   @JoinColumn(name = "CONTEXT_ID")
  78.   private ContextEntity context;

  79.   @ManyToOne
  80.   @JoinColumn(name = "SCOPE_ID")
  81.   private ScopeEntity scope;


  82.   public long getId() {
  83.     return id;
  84.   }

  85.   public String getName() {
  86.     return name;
  87.   }

  88.   public SettingsEntity setName(String name) {
  89.     this.name = name;
  90.     return this;
  91.   }

  92.   public String getValue() {
  93.     return (value == null) ? "" : value;
  94.   }

  95.   public SettingsEntity setValue(String value) {
  96.     this.value = value;
  97.     return this;
  98.   }

  99.   public ContextEntity getContext() {
  100.     return context;
  101.   }

  102.   public SettingsEntity setContext(ContextEntity context) {
  103.     this.context = context;
  104.     return this;
  105.   }

  106.   public ScopeEntity getScope() {
  107.     return scope;
  108.   }

  109.   public SettingsEntity setScope(ScopeEntity scope) {
  110.     this.scope = scope;
  111.     return this;
  112.   }
  113. }