View Javadoc
1   /*
2    * MoneyWise: Finance Application
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.moneywise.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.moneywise.data.basic.MoneyWiseDataSet;
22  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseRegion;
23  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataItem;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
25  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet;
26  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
27  import io.github.tonywasher.joceanus.prometheus.database.PrometheusDataStore;
28  import io.github.tonywasher.joceanus.prometheus.database.PrometheusTableDefinition;
29  import io.github.tonywasher.joceanus.prometheus.database.PrometheusTableEncrypted;
30  
31  /**
32   * TableEncrypted extension Region.
33   */
34  public class MoneyWiseTableRegion
35          extends PrometheusTableEncrypted<MoneyWiseRegion> {
36      /**
37       * The name of the region table.
38       */
39      protected static final String TABLE_NAME = MoneyWiseRegion.LIST_NAME;
40  
41      /**
42       * Constructor.
43       *
44       * @param pDatabase the database control
45       */
46      protected MoneyWiseTableRegion(final PrometheusDataStore pDatabase) {
47          super(pDatabase, TABLE_NAME);
48          final PrometheusTableDefinition myTableDef = getTableDef();
49  
50          /* Declare the columns */
51          myTableDef.addEncryptedColumn(PrometheusDataResource.DATAITEM_FIELD_NAME, PrometheusDataItem.NAMELEN);
52          myTableDef.addNullEncryptedColumn(PrometheusDataResource.DATAITEM_FIELD_DESC, PrometheusDataItem.DESCLEN);
53      }
54  
55      @Override
56      protected void declareData(final PrometheusDataSet pData) {
57          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pData;
58          setList(myData.getRegions());
59      }
60  
61      @Override
62      protected PrometheusDataValues loadValues() throws OceanusException {
63          /* Access the table definition */
64          final PrometheusTableDefinition myTableDef = getTableDef();
65  
66          /* Build data values */
67          final PrometheusDataValues myValues = getRowValues(MoneyWiseRegion.OBJECT_NAME);
68          myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, myTableDef.getBinaryValue(PrometheusDataResource.DATAITEM_FIELD_NAME));
69          myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_DESC, myTableDef.getBinaryValue(PrometheusDataResource.DATAITEM_FIELD_DESC));
70  
71          /* Return the values */
72          return myValues;
73      }
74  
75      @Override
76      protected void setFieldValue(final MoneyWiseRegion pItem,
77                                   final MetisDataFieldId iField) throws OceanusException {
78          /* Switch on field id */
79          final PrometheusTableDefinition myTableDef = getTableDef();
80          if (PrometheusDataResource.DATAITEM_FIELD_NAME.equals(iField)) {
81              myTableDef.setBinaryValue(iField, pItem.getNameBytes());
82          } else if (PrometheusDataResource.DATAITEM_FIELD_DESC.equals(iField)) {
83              myTableDef.setBinaryValue(iField, pItem.getDescBytes());
84          } else {
85              super.setFieldValue(pItem, iField);
86          }
87      }
88  }