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.statics.MoneyWiseCurrency;
23  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticResource;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataSet;
25  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
26  import io.github.tonywasher.joceanus.prometheus.database.PrometheusDataStore;
27  import io.github.tonywasher.joceanus.prometheus.database.PrometheusTableDefinition;
28  import io.github.tonywasher.joceanus.prometheus.database.PrometheusTableStaticData;
29  
30  /**
31   * TableStaticData extension for AccountCategoryType.
32   *
33   * @author Tony Washer
34   */
35  public class MoneyWiseTableCurrency
36          extends PrometheusTableStaticData<MoneyWiseCurrency> {
37      /**
38       * The table name.
39       */
40      protected static final String TABLE_NAME = MoneyWiseCurrency.LIST_NAME;
41  
42      /**
43       * Constructors.
44       *
45       * @param pDatabase the database control
46       */
47      protected MoneyWiseTableCurrency(final PrometheusDataStore pDatabase) {
48          super(pDatabase, TABLE_NAME);
49          final PrometheusTableDefinition myTableDef = getTableDef();
50          myTableDef.addBooleanColumn(MoneyWiseStaticResource.CURRENCY_REPORTING);
51      }
52  
53      @Override
54      protected void declareData(final PrometheusDataSet pData) {
55          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pData;
56          setList(myData.getAccountCurrencies());
57      }
58  
59      @Override
60      protected PrometheusDataValues loadValues() throws OceanusException {
61          /* Access the table definition */
62          final PrometheusTableDefinition myTableDef = getTableDef();
63  
64          /* Build data values */
65          final PrometheusDataValues myValues = getRowValues(MoneyWiseCurrency.OBJECT_NAME);
66          myValues.addValue(MoneyWiseStaticResource.CURRENCY_REPORTING, myTableDef.getBooleanValue(MoneyWiseStaticResource.CURRENCY_REPORTING));
67  
68          /* Return the values */
69          return myValues;
70      }
71  
72      @Override
73      protected void setFieldValue(final MoneyWiseCurrency pItem,
74                                   final MetisDataFieldId iField) throws OceanusException {
75          /* Switch on field id */
76          final PrometheusTableDefinition myTableDef = getTableDef();
77          if (MoneyWiseStaticResource.CURRENCY_REPORTING.equals(iField)) {
78              myTableDef.setBooleanValue(iField, pItem.isReporting());
79          } else {
80              super.setFieldValue(pItem, iField);
81          }
82      }
83  }