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.PrometheusControlKeySet;
22  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataKeySet;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet;
25  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet.PrometheusCryptographyDataType;
26  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
27  
28  /**
29   * Database table class for ControlKey.
30   */
31  public class PrometheusTableControlKeySet
32          extends PrometheusTableDataItem<PrometheusControlKeySet> {
33      /**
34       * The name of the DataKeySet table.
35       */
36      protected static final String TABLE_NAME = PrometheusControlKeySet.LIST_NAME;
37  
38      /**
39       * Constructor.
40       *
41       * @param pDatabase the database control
42       */
43      protected PrometheusTableControlKeySet(final PrometheusDataStore pDatabase) {
44          super(pDatabase, TABLE_NAME);
45          final PrometheusTableDefinition myTableDef = getTableDef();
46  
47          /* Define the columns */
48          myTableDef.addReferenceColumn(PrometheusCryptographyDataType.CONTROLKEY, PrometheusTableControlKeys.TABLE_NAME);
49          myTableDef.addBinaryColumn(PrometheusDataResource.KEYSET_KEYSETDEF, PrometheusDataKeySet.WRAPLEN);
50      }
51  
52      @Override
53      protected void declareData(final PrometheusDataSet pData) {
54          setList(pData.getControlKeySets());
55      }
56  
57      @Override
58      protected PrometheusDataValues loadValues() throws OceanusException {
59          /* Access the table definition */
60          final PrometheusTableDefinition myTableDef = getTableDef();
61  
62          /* Build data values */
63          final PrometheusDataValues myValues = getRowValues(PrometheusDataKeySet.OBJECT_NAME);
64          myValues.addValue(PrometheusCryptographyDataType.CONTROLKEY, myTableDef.getIntegerValue(PrometheusCryptographyDataType.CONTROLKEY));
65          myValues.addValue(PrometheusDataResource.KEYSET_KEYSETDEF, myTableDef.getBinaryValue(PrometheusDataResource.KEYSET_KEYSETDEF));
66  
67          /* Return the values */
68          return myValues;
69      }
70  
71      @Override
72      protected void setFieldValue(final PrometheusControlKeySet pItem,
73                                   final MetisDataFieldId iField) throws OceanusException {
74          /* Switch on field id */
75          final PrometheusTableDefinition myTableDef = getTableDef();
76          if (PrometheusCryptographyDataType.CONTROLKEY.equals(iField)) {
77              myTableDef.setIntegerValue(iField, pItem.getControlKeyId());
78          } else if (PrometheusDataResource.KEYSET_KEYSETDEF.equals(iField)) {
79              myTableDef.setBinaryValue(iField, pItem.getSecuredKeySetDef());
80          } else {
81              super.setFieldValue(pItem, iField);
82          }
83      }
84  }