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.moneywise.data.basic.MoneyWiseBasicDataType;
21  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticDataType;
22  import io.github.tonywasher.joceanus.prometheus.database.PrometheusDBConfig;
23  import io.github.tonywasher.joceanus.prometheus.database.PrometheusDataStore;
24  import io.github.tonywasher.joceanus.prometheus.database.PrometheusTableDataItem;
25  
26  /**
27   * Database extension for MoneyWiseData.
28   *
29   * @author Tony Washer
30   */
31  public class MoneyWiseDataStore
32          extends PrometheusDataStore {
33      /**
34       * Construct a new Database class for load.
35       *
36       * @param pDatabase the database
37       * @param pConfig   the config
38       * @throws OceanusException on error
39       */
40      public MoneyWiseDataStore(final String pDatabase,
41                                final PrometheusDBConfig pConfig) throws OceanusException {
42          /* Call super-constructor */
43          super(pDatabase, pConfig);
44  
45          /* Loop through the static types */
46          for (MoneyWiseStaticDataType myType : MoneyWiseStaticDataType.values()) {
47              /* Create the table */
48              addTable(newTable(myType));
49          }
50  
51          /* Loop through the basic types */
52          for (MoneyWiseBasicDataType myType : MoneyWiseBasicDataType.values()) {
53              /* Create the table */
54              addTable(newTbble(myType));
55          }
56      }
57  
58      /**
59       * Construct a new Database class for create database.
60       *
61       * @param pConfig the config
62       * @throws OceanusException on error
63       */
64      public MoneyWiseDataStore(final PrometheusDBConfig pConfig) throws OceanusException {
65          /* Call super-constructor */
66          super(pConfig);
67  
68          /* Loop through the static types */
69          for (MoneyWiseStaticDataType myType : MoneyWiseStaticDataType.values()) {
70              /* Create the table */
71              addTable(newTable(myType));
72          }
73  
74          /* Loop through the basic types */
75          for (MoneyWiseBasicDataType myType : MoneyWiseBasicDataType.values()) {
76              /* Create the table */
77              addTable(newTbble(myType));
78          }
79      }
80  
81      /**
82       * Create new table of required type.
83       *
84       * @param pDataType the data type
85       * @return the new table
86       */
87      private PrometheusTableDataItem<?> newTable(final MoneyWiseStaticDataType pDataType) {
88          /* Switch on data Type */
89          switch (pDataType) {
90              case DEPOSITTYPE:
91                  return new MoneyWiseTableDepositCategoryType(this);
92              case CASHTYPE:
93                  return new MoneyWiseTableCashCategoryType(this);
94              case LOANTYPE:
95                  return new MoneyWiseTableLoanCategoryType(this);
96              case PORTFOLIOTYPE:
97                  return new MoneyWiseTablePortfolioType(this);
98              case PAYEETYPE:
99                  return new MoneyWiseTablePayeeType(this);
100             case SECURITYTYPE:
101                 return new MoneyWiseTableSecurityType(this);
102             case TRANSTYPE:
103                 return new MoneyWiseTableTransCategoryType(this);
104             case ACCOUNTINFOTYPE:
105                 return new MoneyWiseTableAccountInfoType(this);
106             case TRANSINFOTYPE:
107                 return new MoneyWiseTableTransInfoType(this);
108             case CURRENCY:
109                 return new MoneyWiseTableCurrency(this);
110             case TAXBASIS:
111                 return new MoneyWiseTableTaxBasis(this);
112             default:
113                 throw new IllegalArgumentException(pDataType.toString());
114         }
115     }
116 
117     /**
118      * Create new table of required type.
119      *
120      * @param pDataType the data type
121      * @return the new table
122      */
123     private PrometheusTableDataItem<?> newTbble(final MoneyWiseBasicDataType pDataType) {
124         /* Switch on data Type */
125         switch (pDataType) {
126             case TRANSTAG:
127                 return new MoneyWiseTableTransTag(this);
128             case REGION:
129                 return new MoneyWiseTableRegion(this);
130             case DEPOSITCATEGORY:
131                 return new MoneyWiseTableDepositCategory(this);
132             case CASHCATEGORY:
133                 return new MoneyWiseTableCashCategory(this);
134             case LOANCATEGORY:
135                 return new MoneyWiseTableLoanCategory(this);
136             case TRANSCATEGORY:
137                 return new MoneyWiseTableTransCategory(this);
138             case EXCHANGERATE:
139                 return new MoneyWiseTableExchangeRate(this);
140             case PAYEE:
141                 return new MoneyWiseTablePayee(this);
142             case PAYEEINFO:
143                 return new MoneyWiseTablePayeeInfo(this);
144             case SECURITY:
145                 return new MoneyWiseTableSecurity(this);
146             case SECURITYPRICE:
147                 return new MoneyWiseTableSecurityPrice(this);
148             case SECURITYINFO:
149                 return new MoneyWiseTableSecurityInfo(this);
150             case DEPOSIT:
151                 return new MoneyWiseTableDeposit(this);
152             case DEPOSITRATE:
153                 return new MoneyWiseTableDepositRate(this);
154             case DEPOSITINFO:
155                 return new MoneyWiseTableDepositInfo(this);
156             case CASH:
157                 return new MoneyWiseTableCash(this);
158             case CASHINFO:
159                 return new MoneyWiseTableCashInfo(this);
160             case LOAN:
161                 return new MoneyWiseTableLoan(this);
162             case LOANINFO:
163                 return new MoneyWiseTableLoanInfo(this);
164             case PORTFOLIO:
165                 return new MoneyWiseTablePortfolio(this);
166             case PORTFOLIOINFO:
167                 return new MoneyWiseTablePortfolioInfo(this);
168             case TRANSACTION:
169                 return new MoneyWiseTableTransaction(this);
170             case TRANSACTIONINFO:
171                 return new MoneyWiseTableTransInfo(this);
172             default:
173                 throw new IllegalArgumentException(pDataType.toString());
174         }
175     }
176 }