|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jbudget.io.EventDispatcher
org.jbudget.io.DataManager
public class DataManager
A singleton class that is used to manage all the data in the program. It is responsible for saving and reading data from the disk. It is also responsible for making sure that the data on the disk is synchronized with the data in memory.
| Nested Class Summary | |
|---|---|
private class |
DataManager.CommitTimerTask
A class that implements the timer task that is used to save changes periodically, so that they are not lost in case the program crashes. |
static class |
DataManager.PrefDef
|
static class |
DataManager.PrefKeys
|
| Nested classes/interfaces inherited from class org.jbudget.io.EventDispatcher |
|---|
EventDispatcher.AccountListener, EventDispatcher.AllocationListener, EventDispatcher.BudgetListener, EventDispatcher.DataSourceListener, EventDispatcher.MonthListener, EventDispatcher.TransactionListener, EventDispatcher.UserListener |
| Field Summary | |
|---|---|
private DataIndex |
availableDataIndex
Index of the data that has already been loaded in memory |
private java.util.Calendar |
calendar
Calendar instance that is used inside the object |
private org.jbudget.Core.User |
currentUser
Current User |
private static java.util.prefs.Preferences |
defaultPreferences
|
private javax.swing.JFrame |
mainWindow
Main window. |
private java.util.prefs.Preferences |
myPreferences
|
private boolean |
newDataDir
Did we just create a new data directory ? |
private boolean |
newDirectoryCheck
Was a check for an new/empty data directory performed? |
private DataIndex |
primaryDataIndex
Index of the data available on the primary storage. |
private StorageInterface |
primaryStorage
Primary storage component. |
private static boolean |
TESTING
|
private static DataManager |
theManager
the only instance of DatatManager |
(package private) java.util.Timer |
timer
Timer that is used to periodically save the data to permanent storage. |
| Constructor Summary | |
|---|---|
private |
DataManager(java.util.prefs.Preferences ioPreferences)
Creates a new instance of DataManager |
| Method Summary | |
|---|---|
void |
addAccount(org.jbudget.Core.Account account)
Adds and saves an account object. |
void |
addAllocation(org.jbudget.Core.Transaction allocation)
Adds an allocation to a month and to a record for the month. |
void |
addBudget(org.jbudget.Core.Budget budget)
Adds and saves a budget object. |
void |
addMonth(org.jbudget.Core.Month month)
Adds and saves a given month. |
void |
addTransaction(org.jbudget.Core.Transaction tr)
Adds a transaction to a month and to a record for the month. |
void |
addUser(org.jbudget.Core.User user)
Adds and saves a User object. |
void |
clear()
Clears all data. |
void |
close()
Commits all cached data to permanent storage, disposes of any resources that were allocated in the constructor (i.e., closes network connections). |
int |
generateAccountID()
Creates a new numeric account id and increases the counter. |
int |
generateBudgetID()
Creates a new numeric budget id and increases the counter. |
int |
generateExpenseCategoryID()
Creates a new numeric id for an expense category and increases the counter. |
int |
generateIncomeSourceID()
Creates a new numeric id for an income source and increases the counter. |
long |
generateTransactionID()
Creates a new numeric transaction id for and increases the counter. |
int |
generateUID()
Creates a new uid for a new user and increases the counter. |
org.jbudget.Core.Account |
getAccount(int accountID)
Returns an Account object with a given numeric ID |
java.util.List<org.jbudget.Core.Month> |
getAllMonths()
Returns a list of all valid month objects |
java.util.List<org.jbudget.Core.Transaction> |
getAllocations(org.jbudget.Core.TransactionFilter filter)
Returns all transactions that pass a given filter. |
java.util.List<org.jbudget.Core.User> |
getAllUsers(boolean includeSystem,
boolean includeUnknown)
Returns a list of all users. |
org.jbudget.Core.Budget |
getBudget(int budgetID)
Returns a Budget object with given numeric budget ID |
java.util.List<org.jbudget.Core.Account> |
getCashAccounts()
Returns a list of cash accounts for all users of the system |
org.jbudget.Core.User |
getCurrentUser()
Returns current user object |
static DataManager |
getCustomizedInstance(java.util.prefs.Preferences ioPreferences)
Returns a customized version of the DataManager that uses Preferences different from the default. |
java.lang.String |
getIdString()
Returns a string describing the current storage interfaces used by the DataManager. |
static DataManager |
getInstance()
Returns the default instance of the DataManager. |
javax.swing.JFrame |
getMainWindow()
Returns a reference to the main frame of the application. |
org.jbudget.Core.Month |
getMonth(java.util.Date d)
Returns the Month object that corresponds (contains) a given date. |
org.jbudget.Core.Month |
getMonth(int cMonth,
int cYear)
Returns a month object for the given month/year combination. |
java.util.List<org.jbudget.Core.Month> |
getMonths(org.jbudget.Core.TransactionFilter filter)
Returns a list of months that are passed by a given filter. |
static DataManager |
getNewInstance()
Creates a new instance of the DataManager from the defauld preference object for the program. |
org.jbudget.Core.Month |
getPreviousMonth(int cMonth,
int cYear)
Returns the first valid Month object preceeding the month given by the month and year combination. |
org.jbudget.Core.SharedPreferences |
getSharedPreferences()
Returns a reference to the SharedPreferences object used by the program. |
java.util.List<org.jbudget.Core.Transaction> |
getTransactions(org.jbudget.Core.TransactionFilter filter)
Returns all transactions that pass a given filter. |
java.util.List<Pair<java.lang.Integer,java.lang.String>> |
getUnusedAccounts()
Returns a list of pairs of ID, name of unsuded accounts |
java.util.List<Pair<java.lang.Integer,java.lang.String>> |
getUnusedBudgets()
Returns a list of pairs of ID, name of unsuded budgets |
org.jbudget.Core.User |
getUser(int uid)
Returns a User object with a given uid |
java.util.List<Pair<java.lang.Integer,java.lang.String>> |
getValidAccounts()
Returns a list of Pairs (ID, name) of existing accounts |
java.util.List<Pair<java.lang.Integer,java.lang.String>> |
getValidBudgets()
Returns a list of Pairs (ID, name) of existing budgets |
java.util.List<java.lang.Integer> |
getValidMonths(int cYear)
Returns a list of valid months for a given year. |
java.util.List<java.lang.Integer> |
getValidMonths(java.lang.Integer iYear)
Returns a list of valid months for a given year. |
java.util.List<Pair<java.lang.Integer,java.lang.String>> |
getValidUsers()
Returns a list of Pairs (ID, name) of all users. |
java.util.List<Pair<java.lang.Integer,java.lang.String>> |
getValidUsers(boolean showSystem,
boolean showUnknown)
Returns a list of Pairs (ID, name) of existing users. |
java.util.List<java.lang.Integer> |
getValidYears()
Returns a List of valid years. |
void |
handleException(java.lang.Exception ex)
Handles exceptions. |
boolean |
isNewDataDir()
Returns true if a new data directory was created when the program was started. |
boolean |
isUnusedAccount(org.jbudget.Core.Account account)
Returns true if a given account is not used by any budget. |
boolean |
isUnusedAccount(int accountID)
Returns true if an account with the given ID is not used by any budget |
boolean |
isUnusedBudget(org.jbudget.Core.Budget budget)
Returns true if the given budget is not used by any month. |
boolean |
isUnusedBudget(int budgetID)
Returns true if a budget with the given ID is not used by any month |
boolean |
isValidMonth(java.util.Date d)
Returns true if the given Date corresponds to a valid month. |
boolean |
isValidMonth(int cMonth,
int cYear)
Returns true if the given month/year combination corresponds to a valid month. |
org.jbudget.Core.Month |
newMonth(int cMonth,
int cYear)
Creates a new month for the given month/year combination and saves in in the permanent storage. |
void |
removeAccount(int accountID)
Removes an account with a given id. |
void |
removeAllocation(org.jbudget.Core.Transaction allocation)
Removes an allocation record from a Month corresponding to the date of the allocation and from a record for the Month. |
void |
removeBudget(int budgetID)
Removes a budget with the given budget id. |
void |
removeMonth(int cMonth,
int cYear)
Removes a month object. |
void |
removeTransaction(org.jbudget.Core.Transaction tr)
Removes a transaction record from a Month corresponding to the date of the transaction and from a record for the Month. |
void |
removeUnusedBudgets()
Removes all unused budgets |
void |
removeUser(int uid)
Removes an user with a given uid. |
void |
replaceUser(org.jbudget.Core.User user,
org.jbudget.Core.User newUser)
Changes all transactions in all months that are owned by a user 'user' to point to a new user 'newUser'. |
void |
saveAllMonths()
Saves all months to the primary storage. |
void |
saveMonth(org.jbudget.Core.Month month)
Saves the given Month object. |
void |
saveUserPreferences(org.jbudget.Core.User user)
Saves the preferences associated with the given user |
boolean |
setCurrentUser(java.lang.String userName,
java.lang.String password)
Changes the current user |
boolean |
setCurrentUser(org.jbudget.Core.User user,
java.lang.String password)
Changes the current user |
void |
setMainWindow(javax.swing.JFrame mainWindow)
Sets the mainWindow variable. |
void |
updateAccount(org.jbudget.Core.Account account)
Updates an existing account object. |
private void |
updateInitialBalances(org.jbudget.Core.Month month)
Updates the starting balances and expense allocations. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final boolean TESTING
private static final java.util.prefs.Preferences defaultPreferences
private final java.util.prefs.Preferences myPreferences
private DataIndex primaryDataIndex
private StorageInterface primaryStorage
private final DataIndex availableDataIndex
private final java.util.Calendar calendar
private static DataManager theManager
private boolean newDirectoryCheck
private boolean newDataDir
private org.jbudget.Core.User currentUser
private javax.swing.JFrame mainWindow
java.util.Timer timer
| Constructor Detail |
|---|
private DataManager(java.util.prefs.Preferences ioPreferences)
| Method Detail |
|---|
public static DataManager getInstance()
public static DataManager getNewInstance()
public static DataManager getCustomizedInstance(java.util.prefs.Preferences ioPreferences)
public void close()
public boolean isNewDataDir()
public java.lang.String getIdString()
public java.util.List<java.lang.Integer> getValidYears()
public java.util.List<java.lang.Integer> getValidMonths(int cYear)
public java.util.List<java.lang.Integer> getValidMonths(java.lang.Integer iYear)
public boolean isValidMonth(java.util.Date d)
public boolean isValidMonth(int cMonth,
int cYear)
public org.jbudget.Core.Month getMonth(int cMonth,
int cYear)
java.lang.IllegalArgumentException - if there is no record for this month, or
if the values given don't make sense.public org.jbudget.Core.Month getMonth(java.util.Date d)
public org.jbudget.Core.Month getPreviousMonth(int cMonth,
int cYear)
public org.jbudget.Core.Month newMonth(int cMonth,
int cYear)
IllegalArguementException - if this month has been created
previously.
java.lang.IllegalStateException - if there is no Budget that can be
used to create a new Month.
java.io.IOException - if there are any problems with IO operations.public void addMonth(org.jbudget.Core.Month month)
java.lang.IllegalArgumentException - if this month (a month object with
identical month/year) already exists.public void saveMonth(org.jbudget.Core.Month month)
public void removeMonth(int cMonth,
int cYear)
java.lang.IllegalArgumentException - if no such month exists.public java.util.List<org.jbudget.Core.Month> getMonths(org.jbudget.Core.TransactionFilter filter)
public java.util.List<Pair<java.lang.Integer,java.lang.String>> getValidBudgets()
public org.jbudget.Core.Budget getBudget(int budgetID)
java.lang.IllegalArgumentException - if there is no record of a budget with
such id.
java.io.IOException - if there is a problem with IO.public void addBudget(org.jbudget.Core.Budget budget)
java.lang.IllegalArgumentException - if a budget with an ID of a new object
already exists.public void removeBudget(int budgetID)
java.lang.IllegalArgumentException - if the budget is used by at least one
month, so it can not be removed.public void removeUnusedBudgets()
public boolean isUnusedBudget(org.jbudget.Core.Budget budget)
public boolean isUnusedBudget(int budgetID)
public java.util.List<Pair<java.lang.Integer,java.lang.String>> getUnusedBudgets()
public java.util.List<Pair<java.lang.Integer,java.lang.String>> getValidAccounts()
public org.jbudget.Core.Account getAccount(int accountID)
java.lang.IllegalArgumentException - if there is no record of an Account with
such an id.
java.io.IOException - if there is a problem with IO.public void addAccount(org.jbudget.Core.Account account)
java.lang.IllegalArgumentException - if an account with an ID of a new object
already exists.public void updateAccount(org.jbudget.Core.Account account)
public void removeAccount(int accountID)
java.lang.IllegalArgumentException - if the account is used by at least one
budget, so it can not be removed.public boolean isUnusedAccount(org.jbudget.Core.Account account)
public boolean isUnusedAccount(int accountID)
public java.util.List<Pair<java.lang.Integer,java.lang.String>> getUnusedAccounts()
public java.util.List<org.jbudget.Core.Account> getCashAccounts()
public java.util.List<Pair<java.lang.Integer,java.lang.String>> getValidUsers()
public java.util.List<Pair<java.lang.Integer,java.lang.String>> getValidUsers(boolean showSystem,
boolean showUnknown)
showSystemUsers - if true the system users (unknown and
system) are shown.public org.jbudget.Core.User getUser(int uid)
java.lang.IllegalArgumentException - if there is no record of a User with
such a uid.
java.io.IOException - if there is a problem with IO.
public java.util.List<org.jbudget.Core.User> getAllUsers(boolean includeSystem,
boolean includeUnknown)
public void addUser(org.jbudget.Core.User user)
java.lang.IllegalArgumentException - if an user with a uid of a new object
already exists.public void removeUser(int uid)
java.lang.IllegalArgumentException - if the user is used by at least one
budget, so it can not be removed.
public void replaceUser(org.jbudget.Core.User user,
org.jbudget.Core.User newUser)
public void saveUserPreferences(org.jbudget.Core.User user)
public org.jbudget.Core.User getCurrentUser()
public boolean setCurrentUser(java.lang.String userName,
java.lang.String password)
public boolean setCurrentUser(org.jbudget.Core.User user,
java.lang.String password)
public void addTransaction(org.jbudget.Core.Transaction tr)
tr - the Transaction object that will be added to the corresponding
month.public void removeTransaction(org.jbudget.Core.Transaction tr)
tr - the transaction object that will be removed.public java.util.List<org.jbudget.Core.Transaction> getTransactions(org.jbudget.Core.TransactionFilter filter)
public void addAllocation(org.jbudget.Core.Transaction allocation)
allocation - the Transaction object that will be added to the
corresponding month.public void removeAllocation(org.jbudget.Core.Transaction allocation)
allocation - the transaction object that will be removed.public java.util.List<org.jbudget.Core.Transaction> getAllocations(org.jbudget.Core.TransactionFilter filter)
public org.jbudget.Core.SharedPreferences getSharedPreferences()
public void setMainWindow(javax.swing.JFrame mainWindow)
public javax.swing.JFrame getMainWindow()
public void handleException(java.lang.Exception ex)
private void updateInitialBalances(org.jbudget.Core.Month month)
public void saveAllMonths()
addBudget since they are
immutable.
public int generateBudgetID()
public int generateAccountID()
public int generateExpenseCategoryID()
public int generateIncomeSourceID()
public int generateUID()
public long generateTransactionID()
public void clear()
public java.util.List<org.jbudget.Core.Month> getAllMonths()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||