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.MoneyWiseBasicResource;
22  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
23  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWisePayee;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataItem;
25  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
26  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet;
27  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
28  import io.github.tonywasher.joceanus.prometheus.database.PrometheusColumnDefinition;
29  import io.github.tonywasher.joceanus.prometheus.database.PrometheusDataStore;
30  import io.github.tonywasher.joceanus.prometheus.database.PrometheusTableDefinition;
31  import io.github.tonywasher.joceanus.prometheus.database.PrometheusTableDefinition.PrometheusSortOrder;
32  import io.github.tonywasher.joceanus.prometheus.database.PrometheusTableEncrypted;
33  
34  /**
35   * TableEncrypted extension for Payee.
36   */
37  public class MoneyWiseTablePayee
38          extends PrometheusTableEncrypted<MoneyWisePayee> {
39      /**
40       * The name of the table.
41       */
42      protected static final String TABLE_NAME = MoneyWisePayee.LIST_NAME;
43  
44      /**
45       * Constructor.
46       *
47       * @param pDatabase the database control
48       */
49      protected MoneyWiseTablePayee(final PrometheusDataStore pDatabase) {
50          super(pDatabase, TABLE_NAME);
51          final PrometheusTableDefinition myTableDef = getTableDef();
52  
53          /* Declare the columns */
54          final PrometheusColumnDefinition myCatCol = myTableDef.addReferenceColumn(MoneyWiseBasicResource.CATEGORY_NAME, MoneyWiseTablePayeeType.TABLE_NAME);
55          myTableDef.addEncryptedColumn(PrometheusDataResource.DATAITEM_FIELD_NAME, PrometheusDataItem.NAMELEN);
56          myTableDef.addNullEncryptedColumn(PrometheusDataResource.DATAITEM_FIELD_DESC, PrometheusDataItem.DESCLEN);
57          myTableDef.addBooleanColumn(MoneyWiseBasicResource.ASSET_CLOSED);
58  
59          /* Declare Sort Columns */
60          myCatCol.setSortOrder(PrometheusSortOrder.ASCENDING);
61      }
62  
63      @Override
64      protected void declareData(final PrometheusDataSet pData) {
65          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pData;
66          setList(myData.getPayees());
67      }
68  
69      @Override
70      protected PrometheusDataValues loadValues() throws OceanusException {
71          /* Access the table definition */
72          final PrometheusTableDefinition myTableDef = getTableDef();
73  
74          /* Build data values */
75          final PrometheusDataValues myValues = getRowValues(MoneyWisePayee.OBJECT_NAME);
76          myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_NAME, myTableDef.getBinaryValue(PrometheusDataResource.DATAITEM_FIELD_NAME));
77          myValues.addValue(PrometheusDataResource.DATAITEM_FIELD_DESC, myTableDef.getBinaryValue(PrometheusDataResource.DATAITEM_FIELD_DESC));
78          myValues.addValue(MoneyWiseBasicResource.CATEGORY_NAME, myTableDef.getIntegerValue(MoneyWiseBasicResource.CATEGORY_NAME));
79          myValues.addValue(MoneyWiseBasicResource.ASSET_CLOSED, myTableDef.getBooleanValue(MoneyWiseBasicResource.ASSET_CLOSED));
80  
81          /* Return the values */
82          return myValues;
83      }
84  
85      @Override
86      protected void setFieldValue(final MoneyWisePayee pItem,
87                                   final MetisDataFieldId iField) throws OceanusException {
88          /* Switch on field id */
89          final PrometheusTableDefinition myTableDef = getTableDef();
90          if (MoneyWiseBasicResource.CATEGORY_NAME.equals(iField)) {
91              myTableDef.setIntegerValue(iField, pItem.getCategoryId());
92          } else if (PrometheusDataResource.DATAITEM_FIELD_NAME.equals(iField)) {
93              myTableDef.setBinaryValue(iField, pItem.getNameBytes());
94          } else if (PrometheusDataResource.DATAITEM_FIELD_DESC.equals(iField)) {
95              myTableDef.setBinaryValue(iField, pItem.getDescBytes());
96          } else if (MoneyWiseBasicResource.ASSET_CLOSED.equals(iField)) {
97              myTableDef.setBooleanValue(iField, pItem.isClosed());
98          } else {
99              super.setFieldValue(pItem, iField);
100         }
101     }
102 }