View Javadoc
1   /*
2    * Prometheus: Application Framework
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.prometheus.database;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataFieldId;
21  import io.github.tonywasher.joceanus.prometheus.data.PrometheusControlKey;
22  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
25  
26  /**
27   * Database table class for ControlKey.
28   */
29  public class PrometheusTableControlKeys
30          extends PrometheusTableDataItem<PrometheusControlKey> {
31      /**
32       * The name of the ControlKeys table.
33       */
34      protected static final String TABLE_NAME = PrometheusControlKey.LIST_NAME;
35  
36      /**
37       * Constructor.
38       *
39       * @param pDatabase the database control
40       */
41      protected PrometheusTableControlKeys(final PrometheusDataStore pDatabase) {
42          super(pDatabase, TABLE_NAME);
43          final PrometheusTableDefinition myTableDef = getTableDef();
44  
45          /* Define the columns */
46          myTableDef.addDateColumn(PrometheusDataResource.CONTROLKEY_CREATION);
47          myTableDef.addBinaryColumn(PrometheusDataResource.CONTROLKEY_LOCKBYTES, PrometheusControlKey.LOCKLEN);
48      }
49  
50      @Override
51      protected void declareData(final PrometheusDataSet pData) {
52          setList(pData.getControlKeys());
53      }
54  
55      @Override
56      protected PrometheusDataValues loadValues() throws OceanusException {
57          /* Access the table definition */
58          final PrometheusTableDefinition myTableDef = getTableDef();
59  
60          /* Build data values */
61          final PrometheusDataValues myValues = getRowValues(PrometheusControlKey.OBJECT_NAME);
62          myValues.addValue(PrometheusDataResource.CONTROLKEY_CREATION, myTableDef.getDateValue(PrometheusDataResource.CONTROLKEY_CREATION));
63          myValues.addValue(PrometheusDataResource.CONTROLKEY_LOCKBYTES, myTableDef.getBinaryValue(PrometheusDataResource.CONTROLKEY_LOCKBYTES));
64  
65          /* Return the values */
66          return myValues;
67      }
68  
69      @Override
70      protected void setFieldValue(final PrometheusControlKey pItem,
71                                   final MetisDataFieldId iField) throws OceanusException {
72          /* Switch on field id */
73          final PrometheusTableDefinition myTableDef = getTableDef();
74          if (PrometheusDataResource.CONTROLKEY_CREATION.equals(iField)) {
75              myTableDef.setDateValue(iField, pItem.getCreationDate());
76          } else if (PrometheusDataResource.CONTROLKEY_LOCKBYTES.equals(iField)) {
77              myTableDef.setBinaryValue(iField, pItem.getLockBytes());
78          } else {
79              super.setFieldValue(pItem, iField);
80          }
81      }
82  }