diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2018-02-23 13:35:12 +0100 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2018-02-23 13:35:12 +0100 |
commit | 80ea041e0240eb3d9291eb0d699bb09c90aaa2a9 (patch) | |
tree | c1d950bbdfbc40991e2bcfc7822ff3e181951688 /id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db | |
parent | f35737cbb27dda96caf0435c4bac7d279832e4fd (diff) | |
download | moa-id-spss-80ea041e0240eb3d9291eb0d699bb09c90aaa2a9.tar.gz moa-id-spss-80ea041e0240eb3d9291eb0d699bb09c90aaa2a9.tar.bz2 moa-id-spss-80ea041e0240eb3d9291eb0d699bb09c90aaa2a9.zip |
first untested unfactoring for Postgresql suppport
The scheme of configuration DB changed, therefore this version is incompatible to 3.3.2 configuration
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db')
5 files changed, 202 insertions, 99 deletions
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/AbstractConfigProperty.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/AbstractConfigProperty.java new file mode 100644 index 000000000..d50aa9c6e --- /dev/null +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/AbstractConfigProperty.java @@ -0,0 +1,94 @@ +package at.gv.egovernment.moa.id.commons.db.dao.config; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +public abstract class AbstractConfigProperty implements Serializable{ + /** + * + */ + private static final long serialVersionUID = 1L; + @Id + @Column(name = "propertyKey", unique = true) + protected String key; + + public AbstractConfigProperty() { + super(); + } + + + /** + * Returns the property's value (which might be {@code null}). + * @return The property's value (might be {@code null}). + */ + abstract public String getValue(); + + /** + * Sets the property's value. + * @param value The value + */ + abstract public void setValue(String value); + + /** + * Returns the property's key. + * @return The key. + */ + public String getKey() { + return key; + } + + /** + * Sets the property's key. + * @param key The key + */ + public void setKey(String key) { + this.key = key; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ConfigProperty other = (ConfigProperty) obj; + if (key == null) { + if (other.key != null) + return false; + } else if (!key.equals(other.key)) + return false; + return true; + } + + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append(getImpplementationName()); + builder.append(" [key="); + builder.append(getKey()); + builder.append(", value="); + builder.append(getValue()); + builder.append("]"); + return builder.toString(); + } + + /** + * Get a name for this Entity-Implementation for logging purposes + * + * @return + */ + abstract protected String getImpplementationName(); +}
\ No newline at end of file diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigProperty.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigProperty.java index 6e2743b81..07770fdf3 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigProperty.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigProperty.java @@ -1,95 +1,54 @@ package at.gv.egovernment.moa.id.commons.db.dao.config; -import java.io.Serializable; - import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.Table; + /** - * Reflects a MOAID configuration entry. + * Reflects a MOAID configuration entry with String values. * */ @Table(name = "configproperty") @Entity -public class ConfigProperty implements Serializable { +public class ConfigProperty extends AbstractConfigProperty{ + + + + /** + * + */ private static final long serialVersionUID = 1L; - @Id - @Column(name = "propertyKey", unique = true) - private String key; - @Lob @Column(name = "propertyValue") private String value; - /** - * Returns the property's key. - * @return The key. - */ - public String getKey() { - return key; - } - - /** - * Sets the property's key. - * @param key The key - */ - public void setKey(String key) { - this.key = key; - } - + + /** * Returns the property's value (which might be {@code null}). * @return The property's value (might be {@code null}). */ + @Override public String getValue() { return value; + } /** * Sets the property's value. * @param value The value */ + @Override public void setValue(String value) { this.value = value; } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - return result; + protected String getImpplementationName() { + return this.getClass().getName(); } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ConfigProperty other = (ConfigProperty) obj; - if (key == null) { - if (other.key != null) - return false; - } else if (!key.equals(other.key)) - return false; - return true; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("ConfigProperty [key="); - builder.append(key); - builder.append(", value="); - builder.append(value); - builder.append("]"); - return builder.toString(); - } } diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyByteValues.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyByteValues.java new file mode 100644 index 000000000..51f7e4da6 --- /dev/null +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/ConfigPropertyByteValues.java @@ -0,0 +1,73 @@ +package at.gv.egovernment.moa.id.commons.db.dao.config; + +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Lob; +import javax.persistence.Table; + +import at.gv.egovernment.moa.logging.Logger; + + +/** + * Reflects a MOAID configuration entry with String values. + * + */ +@Table(name = "configpropertybytes") +@Entity +public class ConfigPropertyByteValues extends AbstractConfigProperty{ + + + + /** + * + */ + private static final long serialVersionUID = 1L; + + + @Lob + @Column(name = "propertyValueBytes") + private byte[] value = null; + + + /** + * Returns the property's value (which might be {@code null}). + * @return The property's value (might be {@code null}). + */ + @Override + public String getValue() { + try { + if (value != null) + return new String(value, "UTF-8"); + + } catch (UnsupportedEncodingException e) { + Logger.error("Internal DB read error! Can not read values from configuration DB.", e); + + } + + return null; + + } + + /** + * Sets the property's value. + * @param value The value + */ + @Override + public void setValue(String value) { + try { + this.value = value.getBytes("UTF-8"); + + } catch (UnsupportedEncodingException e) { + Logger.error("Internal DB write error! Can not read write to configuration DB.", e); + + } + } + + @Override + protected String getImpplementationName() { + return this.getClass().getName(); + } +} diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java index aad830d65..213d1a860 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/config/DatabaseConfigPropertyImpl.java @@ -12,6 +12,8 @@ import javax.persistence.TypedQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -32,6 +34,9 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { @PersistenceContext(unitName = "config") private EntityManager em; + @Autowired(required=true) + private ApplicationContext appContext; + /** * * @return EntityManager for database access @@ -56,7 +61,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { */ @Override protected String getValue(String key) throws ConfigurationException { - ConfigProperty property = getProperty(key); + AbstractConfigProperty property = getProperty(key); if (property == null) return null; @@ -74,7 +79,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { */ @Override protected boolean containsKey(String key) throws ConfigurationException { - ConfigProperty property = getProperty(key); + AbstractConfigProperty property = getProperty(key); if (property == null) return false; else @@ -93,7 +98,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { throw new ConfigurationException("No EntityManager set!"); } - ConfigProperty property = new ConfigProperty(); + AbstractConfigProperty property = appContext.getBean(AbstractConfigProperty.class); property.setKey(key); property.setValue(value); log.debug("Storing '{}'.", property.toString()); @@ -104,7 +109,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { protected void deleteKey(String key) { log.debug("Deleting entry with key '{}'.", key); - ConfigProperty el = em.find(ConfigProperty.class, key); + AbstractConfigProperty el = em.find(AbstractConfigProperty.class, key); if (el != null) em.remove(el); @@ -141,8 +146,8 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { throw new ConfigurationException("No EntityManager set!"); } - TypedQuery<ConfigProperty> query = em.createQuery("select * from ConfigProperty dbconfig", ConfigProperty.class); - List<ConfigProperty> all = query.getResultList(); + TypedQuery<AbstractConfigProperty> query = em.createQuery("select * from ConfigProperty dbconfig", AbstractConfigProperty.class); + List<AbstractConfigProperty> all = query.getResultList(); searchString = searchString.replace(".", "\\."); String regex = searchString.replace("*", ".*"); @@ -151,11 +156,11 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { Pattern pattern = Pattern.compile(regex); List<String> keyList = new ArrayList<String>(); - Iterator<ConfigProperty> keyIt; + Iterator<AbstractConfigProperty> keyIt; if (all != null) { keyIt = all.iterator(); while(keyIt.hasNext()) { - ConfigProperty entry = keyIt.next(); + AbstractConfigProperty entry = keyIt.next(); String value = entry.getValue(); String key = entry.getKey(); @@ -188,9 +193,9 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { } - private ConfigProperty getProperty(String key) { + private AbstractConfigProperty getProperty(String key) { log.trace("Looking for configuration property for key '{}'.", key); - ConfigProperty result = em.find(ConfigProperty.class, key); + AbstractConfigProperty result = em.find(AbstractConfigProperty.class, key); if (result != null) { log.trace("Found configuration property {}.", result); } else { @@ -212,32 +217,4 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { } } -// @Override -// public String getPropertyValue(String key) { -// ConfigProperty property = getProperty(key); -// if (property == null) { -// return null; -// } -// return property.getValue(); -// } -// -// @Override -// public List<ConfigProperty> getProperties() { -// -// if (null == em) { -// log.error("No EntityManager set!"); -// return null; -// } -// -// log.debug("Retrieving all properties from database."); -// TypedQuery<ConfigProperty> query = em.createQuery("select mc from ConfigProperty mc", ConfigProperty.class); -// try { -// List<ConfigProperty> propertiesList = query.getResultList(); -// return propertiesList; -// } catch (NoResultException e) { -// log.debug("No property found in database."); -// return null; -// } -// } - }
\ No newline at end of file diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java index eeaf03544..7cb921ee7 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/dao/session/AuthenticatedSessionStore.java @@ -98,9 +98,9 @@ public class AuthenticatedSessionStore implements Serializable{ @Column(name = "pendingRequestID", nullable=true) private String pendingRequestID = ""; - @Column(name = "additionalInformation", nullable=true) + @Column(name = "additionalInformationBytes", nullable=true) @Lob - private String additionalInformation; + private byte[] additionalInformation; @Column(name = "created", updatable=false, nullable=false) @Temporal(TemporalType.TIMESTAMP) @@ -349,14 +349,14 @@ public class AuthenticatedSessionStore implements Serializable{ /** * @return the additionalInformation */ - public String getAdditionalInformation() { + public byte[] getAdditionalInformation() { return additionalInformation; } /** * @param additionalInformation the additionalInformation to set */ - public void setAdditionalInformation(String additionalInformation) { + public void setAdditionalInformation(byte[] additionalInformation) { this.additionalInformation = additionalInformation; } |