View Javadoc
1   /*
2    * Copyright (c) 2001-2017, Zoltan Farkas All Rights Reserved.
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library 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 Lesser General Public
15   * License along with this program; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17   *
18   * Additionally licensed with:
19   *
20   * Licensed under the Apache License, Version 2.0 (the "License");
21   * you may not use this file except in compliance with the License.
22   * You may obtain a copy of the License at
23   *
24   *      http://www.apache.org/licenses/LICENSE-2.0
25   *
26   * Unless required by applicable law or agreed to in writing, software
27   * distributed under the License is distributed on an "AS IS" BASIS,
28   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29   * See the License for the specific language governing permissions and
30   * limitations under the License.
31   */
32  package org.spf4j.concurrent.jdbc;
33  
34  import java.io.Serializable;
35  import java.util.Objects;
36  import javax.annotation.Nonnull;
37  import javax.annotation.ParametersAreNonnullByDefault;
38  import org.spf4j.jdbc.DbType;
39  import org.spf4j.jdbc.JdbcTemplate;
40  /**
41   *
42   * @author zoly
43   */
44  @ParametersAreNonnullByDefault
45  public final class SemaphoreTablesDesc implements Serializable {
46  
47    private static final long serialVersionUID = 1L;
48  
49    public static final SemaphoreTablesDesc DEFAULT = new SemaphoreTablesDesc(
50            System.getProperty("spf4j.jdbc.semaphore.sql.tableName", "SEMAPHORES"),
51            System.getProperty("spf4j.jdbc.semaphore.sql.semaphoreNameColumn", "SEMAPHORE_NAME"),
52            System.getProperty("spf4j.jdbc.semaphore.sql.availablePermitsColumn", "AVAILABLE_PERMITS"),
53            System.getProperty("spf4j.jdbc.semaphore.sql.totalPermitsColumn", "TOTAL_PERMITS"),
54            System.getProperty("spf4j.jdbc.semaphore.sql.lastUpdatedByColumn", "LAST_UPDATED_BY"),
55            System.getProperty("spf4j.jdbc.semaphore.sql.lastUpdatedAtColumn", "LAST_UPDATED_AT"),
56            System.getProperty("spf4j.jdbc.semaphore.sql.permitsByOwnerColumn", "PERMITS_BY_OWNER"),
57            HeartBeatTableDesc.DEFAULT.getOwnerColumn(),
58            System.getProperty("spf4j.jdbc.semaphore.sql.permitsColumn", "PERMITS"),
59            HeartBeatTableDesc.DEFAULT);
60  
61    @Nonnull
62    private final String semaphoreTableName;
63    private final String semNameColumn;
64    private final String availablePermitsColumn;
65    private final String totalPermitsColumn;
66    private final String lastModifiedByColumn;
67    private final String lastModifiedAtColumn;
68    private final String permitsByOwnerTableName;
69    private final String ownerColumn;
70    private final String ownerPermitsColumn;
71    private final HeartBeatTableDesc heartBeatTableDesc;
72  
73    public SemaphoreTablesDesc(final String semaphoreTableName, final String semNameColumn,
74            final String availablePermitsColumn,
75            final String totalPermitsColumn, final String lastModifiedByColumn,
76            final String lastModifiedAtColumn, final String permitsByOwnerTableName,
77            final String ownerColumn, final String ownerPermitsColumn,
78            final HeartBeatTableDesc heartBeatTableDesc) {
79      JdbcTemplate.checkJdbcObjectName(semaphoreTableName);
80      JdbcTemplate.checkJdbcObjectName(semNameColumn);
81      JdbcTemplate.checkJdbcObjectName(availablePermitsColumn);
82      JdbcTemplate.checkJdbcObjectName(totalPermitsColumn);
83      JdbcTemplate.checkJdbcObjectName(lastModifiedByColumn);
84      JdbcTemplate.checkJdbcObjectName(lastModifiedAtColumn);
85      JdbcTemplate.checkJdbcObjectName(permitsByOwnerTableName);
86      JdbcTemplate.checkJdbcObjectName(ownerColumn);
87      JdbcTemplate.checkJdbcObjectName(ownerPermitsColumn);
88      this.semaphoreTableName = semaphoreTableName;
89      this.semNameColumn = semNameColumn;
90      this.availablePermitsColumn = availablePermitsColumn;
91      this.totalPermitsColumn = totalPermitsColumn;
92      this.lastModifiedByColumn = lastModifiedByColumn;
93      this.lastModifiedAtColumn = lastModifiedAtColumn;
94      this.permitsByOwnerTableName = permitsByOwnerTableName;
95      this.ownerColumn = ownerColumn;
96      this.ownerPermitsColumn = ownerPermitsColumn;
97      this.heartBeatTableDesc = heartBeatTableDesc;
98    }
99  
100   public String getSemaphoreTableName() {
101     return semaphoreTableName;
102   }
103 
104   public String getSemNameColumn() {
105     return semNameColumn;
106   }
107 
108   public String getAvailablePermitsColumn() {
109     return availablePermitsColumn;
110   }
111 
112   public String getTotalPermitsColumn() {
113     return totalPermitsColumn;
114   }
115 
116   public String getLastModifiedByColumn() {
117     return lastModifiedByColumn;
118   }
119 
120   public String getLastModifiedAtColumn() {
121     return lastModifiedAtColumn;
122   }
123 
124   public String getPermitsByOwnerTableName() {
125     return permitsByOwnerTableName;
126   }
127 
128   public String getOwnerColumn() {
129     return ownerColumn;
130   }
131 
132   public String getOwnerPermitsColumn() {
133     return ownerPermitsColumn;
134   }
135 
136   public HeartBeatTableDesc getHeartBeatTableDesc() {
137     return heartBeatTableDesc;
138   }
139 
140   public SemaphoreTablesDesc withDbType(final DbType dbType) {
141     return new SemaphoreTablesDesc(semaphoreTableName, semNameColumn, availablePermitsColumn,
142             totalPermitsColumn, lastModifiedByColumn, lastModifiedAtColumn, permitsByOwnerTableName,
143             ownerColumn, ownerPermitsColumn, heartBeatTableDesc.withDbType(dbType));
144   }
145 
146   @Override
147   public int hashCode() {
148     return this.semaphoreTableName.hashCode();
149   }
150 
151   @Override
152   public boolean equals(final Object obj) {
153     if (this == obj) {
154       return true;
155     }
156     if (obj == null) {
157       return false;
158     }
159     if (getClass() != obj.getClass()) {
160       return false;
161     }
162     final SemaphoreTablesDesc other = (SemaphoreTablesDesc) obj;
163     if (!Objects.equals(this.semaphoreTableName, other.semaphoreTableName)) {
164       return false;
165     }
166     if (!Objects.equals(this.semNameColumn, other.semNameColumn)) {
167       return false;
168     }
169     if (!Objects.equals(this.availablePermitsColumn, other.availablePermitsColumn)) {
170       return false;
171     }
172     if (!Objects.equals(this.totalPermitsColumn, other.totalPermitsColumn)) {
173       return false;
174     }
175     if (!Objects.equals(this.lastModifiedByColumn, other.lastModifiedByColumn)) {
176       return false;
177     }
178     if (!Objects.equals(this.lastModifiedAtColumn, other.lastModifiedAtColumn)) {
179       return false;
180     }
181     if (!Objects.equals(this.permitsByOwnerTableName, other.permitsByOwnerTableName)) {
182       return false;
183     }
184     if (!Objects.equals(this.ownerColumn, other.ownerColumn)) {
185       return false;
186     }
187     if (!Objects.equals(this.ownerPermitsColumn, other.ownerPermitsColumn)) {
188       return false;
189     }
190     return Objects.equals(this.heartBeatTableDesc, other.heartBeatTableDesc);
191   }
192 
193 
194 
195   @Override
196   public String toString() {
197     return "SemaphoreTablesDesc{" + "semaphoreTableName=" + semaphoreTableName + ", semNameColumn="
198             + semNameColumn + ", availablePermitsColumn=" + availablePermitsColumn
199             + ", totalPermitsColumn=" + totalPermitsColumn + ", lastModifiedByColumn="
200             + lastModifiedByColumn + ", lastModifiedAtColumn=" + lastModifiedAtColumn
201             + ", permitsByOwnerTableName=" + permitsByOwnerTableName + ", ownerColumn="
202             + ownerColumn + ", ownerReservationsColumn=" + ownerPermitsColumn + '}';
203   }
204 
205 }