All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.addc.commons.queue.PersistenceConfig Maven / Gradle / Ivy

Go to download

The addc-queues library supplies support for internal persistent queues using an optional DERBY database for storage.

The newest version!
package com.addc.commons.queue;

import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

import com.addc.commons.configuration.ConfigurationException;
import com.addc.commons.properties.PropertiesParser;

/**
 * The PersistenceConfig contains the configuration for the persistence layer of
 * a {@link PersistingQueue}. This is controlled by a set of 4 properties:
 * 

* The properties keys: *

* * * * * * * * * * * * * * * * * * * * * * * *
Persistence Properties
PropertyDescription
persistence.enabledtrue/yes if the queues will actually a Derby database to persist data
persistence.locationThe path to the database files
persistence.dbnameThe name of the database
persistence.encryptedtrue/yes if the database is encrypted
*/ public class PersistenceConfig { public static final String LOCATION_KEY= "persistence.location"; public static final String DB_NME_KEY= "persistence.dbName"; public static final String ENABLED_KEY= "persistence.enabled"; public static final String ENCRYPTED_KEY= "persistence.encrypted"; private String dataBaseLocation; private String dataBaseName; private boolean persistent; private boolean encrypted; /** * Create a new PersistenceConfig */ public PersistenceConfig() { } /** * Create a new PersistenceConfig * * @param props * the properties to use * @throws ConfigurationException * If the initialization fails */ public PersistenceConfig(Properties props) throws ConfigurationException { initFromProperties(props); } /** * Get the dataBaseLocation * * @return the dataBaseLocation */ public String getDataBaseLocation() { return dataBaseLocation; } /** * Set the dataBaseLocation * * @param dataBaseLocation * the dataBaseLocation to set */ public void setDataBaseLocation(String dataBaseLocation) { this.dataBaseLocation= dataBaseLocation; } /** * Get the dataBaseName * * @return the dataBaseName */ public String getDataBaseName() { return dataBaseName; } /** * Set the dataBaseName * * @param dataBaseName * the dataBaseName to set */ public void setDataBaseName(String dataBaseName) { this.dataBaseName= dataBaseName; } /** * Query whether the queue should be persistent * * @return whether the queue should be persistent */ public boolean isPersistent() { return persistent; } /** * Set whether the queue should be persistent * * @param persistent * whether the queue should be persistent */ public void setPersistent(boolean persistent) { this.persistent= persistent; } /** * Query whether the queue should be encrypted * * @return whether the queue should be encrypted */ public boolean isEncrypted() { return encrypted; } /** * Set whether the queue should be encrypted * * @param encrypted * whether the queue should be encrypted */ public void setEncrypted(boolean encrypted) { this.encrypted= encrypted; } /** * Get the DERBY Database directory * * @return the DERBY Database directory */ public String getDerbyDbDir() { return dataBaseLocation + "/" + dataBaseName; } private void initFromProperties(Properties props) throws ConfigurationException { Set errors= new HashSet<>(); PropertiesParser parser= new PropertiesParser(props, errors); persistent= parser.parseBoolean(ENABLED_KEY); if (persistent) { dataBaseLocation= parser.parseString(LOCATION_KEY); dataBaseName= parser.parseString(DB_NME_KEY); encrypted= parser.parseBoolean(ENCRYPTED_KEY, false); } if (!errors.isEmpty()) { throw new ConfigurationException(errors); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy