diff options
author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2018-02-27 08:54:36 +0100 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2018-02-27 08:54:36 +0100 |
commit | 9d01327960b0531da64ae3ffd1b39592830dd425 (patch) | |
tree | 06d67a5224ba7de9813e6803a5aedd4a30f35cc6 /id/server/moa-id-commons/src | |
parent | 80ea041e0240eb3d9291eb0d699bb09c90aaa2a9 (diff) | |
download | moa-id-spss-9d01327960b0531da64ae3ffd1b39592830dd425.tar.gz moa-id-spss-9d01327960b0531da64ae3ffd1b39592830dd425.tar.bz2 moa-id-spss-9d01327960b0531da64ae3ffd1b39592830dd425.zip |
some more updates are required to support postgresql databases
Diffstat (limited to 'id/server/moa-id-commons/src')
8 files changed, 86 insertions, 49 deletions
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/MOAIDConstants.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/MOAIDConstants.java index 98f0616a5..436dcc91d 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/MOAIDConstants.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/MOAIDConstants.java @@ -134,7 +134,8 @@ public class MOAIDConstants { static { List<String> jdbcDriverWorkaround = new ArrayList<String>(); jdbcDriverWorkaround.add("oracle.jdbc."); - jdbcDriverWorkaround.add("com.microsoft.sqlserver."); + jdbcDriverWorkaround.add("com.microsoft.sqlserver."); + jdbcDriverWorkaround.add("org.postgresql."); JDBC_DRIVER_NEEDS_WORKAROUND = Collections.unmodifiableList(jdbcDriverWorkaround); } diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java index 4fd382606..4944813ad 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java @@ -1,6 +1,5 @@ package at.gv.egovernment.moa.id.commons.config.persistence; -import java.sql.SQLSyntaxErrorException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -17,7 +16,7 @@ import at.gv.egiz.components.configuration.api.Configuration; import at.gv.egiz.components.configuration.api.ConfigurationException; import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; import at.gv.egovernment.moa.id.commons.db.dao.config.AbstractConfigProperty; -import at.gv.egovernment.moa.id.commons.db.dao.config.ConfigProperty; +//import at.gv.egovernment.moa.id.commons.db.dao.config.ConfigProperty; import at.gv.egovernment.moa.id.commons.db.dao.config.DatabaseConfigPropertyImpl; import at.gv.egovernment.moa.id.commons.utils.KeyValueUtils; import at.gv.egovernment.moa.logging.Logger; @@ -56,7 +55,7 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement } - TypedQuery<AbstractConfigProperty> configQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); + TypedQuery<AbstractConfigProperty> configQuery = em.createQuery("select dbconfig from " + dataBaseEntityName + " dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); configQuery.setParameter("key", preFix + "%"); List<AbstractConfigProperty> configResult = configQuery.getResultList(); @@ -94,7 +93,7 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement } - TypedQuery<AbstractConfigProperty> configQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); + TypedQuery<AbstractConfigProperty> configQuery = em.createQuery("select dbconfig from " + dataBaseEntityName + " dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); configQuery.setParameter("key", searchKey.replace("*", "%")); List<AbstractConfigProperty> configResult = configQuery.getResultList(); @@ -128,7 +127,7 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement + MOAIDConfigurationConstants.SERVICE_UNIQUEIDENTIFIER; List<AbstractConfigProperty> oaSearchResult = null; - TypedQuery<AbstractConfigProperty> oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key and dbconfig.value = SUBSTRING(:uniqueID, 1, LENGTH(dbconfig.value))", AbstractConfigProperty.class); + TypedQuery<AbstractConfigProperty> oaSearchQuery = em.createQuery("select dbconfig from " + dataBaseEntityName + " dbconfig where dbconfig.key like :key and dbconfig.value = SUBSTRING(:uniqueID, 1, LENGTH(dbconfig.value))", AbstractConfigProperty.class); oaSearchQuery.setParameter("key", keyId); oaSearchQuery.setParameter("uniqueID", publicURLPrefix); oaSearchResult = oaSearchQuery.getResultList(); @@ -159,7 +158,7 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement List<AbstractConfigProperty> oaSearchResult = new ArrayList<AbstractConfigProperty>(); - TypedQuery<AbstractConfigProperty> oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); + TypedQuery<AbstractConfigProperty> oaSearchQuery = em.createQuery("select dbconfig from " + dataBaseEntityName + " dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); oaSearchQuery.setParameter("key", keyId); List<AbstractConfigProperty> intermResult = oaSearchQuery.getResultList(); if (intermResult != null) { @@ -224,7 +223,7 @@ public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implement String oaType = KeyValueUtils.getFirstChildAfterPrefix(oaIdKey, MOAIDConfigurationConstants.PREFIX_MOAID_SERVICES); String oaKey = KeyValueUtils.getPrefixFromKey(oaIdKey, MOAIDConfigurationConstants.SERVICE_UNIQUEIDENTIFIER); - TypedQuery<AbstractConfigProperty> oaConfigQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); + TypedQuery<AbstractConfigProperty> oaConfigQuery = em.createQuery("select dbconfig from " + dataBaseEntityName + " dbconfig where dbconfig.key like :key", AbstractConfigProperty.class); oaConfigQuery.setParameter("key", oaKey + ".%"); List<AbstractConfigProperty> oaConfigResult = oaConfigQuery.getResultList(); 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 index d50aa9c6e..0d9a1bf8b 100644 --- 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 @@ -8,6 +8,9 @@ import javax.persistence.MappedSuperclass; @MappedSuperclass public abstract class AbstractConfigProperty implements Serializable{ + + + /** * */ @@ -65,7 +68,7 @@ public abstract class AbstractConfigProperty implements Serializable{ return false; if (getClass() != obj.getClass()) return false; - ConfigProperty other = (ConfigProperty) obj; + AbstractConfigProperty other = (AbstractConfigProperty) obj; if (key == null) { if (other.key != null) return false; @@ -76,7 +79,7 @@ public abstract class AbstractConfigProperty implements Serializable{ public String toString() { StringBuilder builder = new StringBuilder(); - builder.append(getImpplementationName()); + builder.append(getImplementationName()); builder.append(" [key="); builder.append(getKey()); builder.append(", value="); @@ -86,9 +89,21 @@ public abstract class AbstractConfigProperty implements Serializable{ } /** - * Get a name for this Entity-Implementation for logging purposes + * Get a name for this Entity-Implementation class * * @return */ - abstract protected String getImpplementationName(); + protected String getImplementationName() { + return getImplementationClass().getSimpleName(); + + } + + /** + * Get get Class of the implemented Entity + * + * @return + */ + abstract protected Class<? extends AbstractConfigProperty> getImplementationClass(); + + }
\ 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 07770fdf3..2cea90e7b 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 @@ -14,8 +14,7 @@ import javax.persistence.Table; @Entity public class ConfigProperty extends AbstractConfigProperty{ - - + /** * */ @@ -46,9 +45,13 @@ public class ConfigProperty extends AbstractConfigProperty{ this.value = value; } + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.commons.db.dao.config.AbstractConfigProperty#getImplementationClass() + */ @Override - protected String getImpplementationName() { - return this.getClass().getName(); + protected Class<? extends AbstractConfigProperty> getImplementationClass() { + return this.getClass(); + } } 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 index 51f7e4da6..c31ca98ed 100644 --- 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 @@ -1,11 +1,9 @@ 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; @@ -27,7 +25,6 @@ public class ConfigPropertyByteValues extends AbstractConfigProperty{ private static final long serialVersionUID = 1L; - @Lob @Column(name = "propertyValueBytes") private byte[] value = null; @@ -58,7 +55,10 @@ public class ConfigPropertyByteValues extends AbstractConfigProperty{ @Override public void setValue(String value) { try { - this.value = value.getBytes("UTF-8"); + if (value == null) + this.value = null; + else + this.value = value.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { Logger.error("Internal DB write error! Can not read write to configuration DB.", e); @@ -66,8 +66,12 @@ public class ConfigPropertyByteValues extends AbstractConfigProperty{ } } + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.commons.db.dao.config.AbstractConfigProperty#getImplementationClass() + */ @Override - protected String getImpplementationName() { - return this.getClass().getName(); + protected Class<? extends AbstractConfigProperty> getImplementationClass() { + return this.getClass(); + } } 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 213d1a860..c202e231b 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 @@ -3,9 +3,9 @@ package at.gv.egovernment.moa.id.commons.db.dao.config; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Map.Entry; import java.util.regex.Pattern; +import javax.annotation.PostConstruct; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.TypedQuery; @@ -36,6 +36,15 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { @Autowired(required=true) private ApplicationContext appContext; + + static protected String dataBaseEntityName; + + @PostConstruct + void postConstructor() { + dataBaseEntityName = appContext.getBean(AbstractConfigProperty.class).getImplementationName(); + log.info("DB-Entity for config: " + dataBaseEntityName); + + } /** * @@ -51,7 +60,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { log.error("No EntityManager set!"); throw new ConfigurationException("No EntityManager set!"); } - TypedQuery<String> query = em.createQuery("select key from ConfigProperty", String.class); + TypedQuery<String> query = em.createQuery("select key from " + dataBaseEntityName, String.class); List<String> result = query.getResultList(); return result; } @@ -109,7 +118,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { protected void deleteKey(String key) { log.debug("Deleting entry with key '{}'.", key); - AbstractConfigProperty el = em.find(AbstractConfigProperty.class, key); + AbstractConfigProperty el = em.find(appContext.getBean(AbstractConfigProperty.class).getClass(), key); if (el != null) em.remove(el); @@ -126,7 +135,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { throw new ConfigurationException("No EntityManager set!"); } - TypedQuery<String> query = em.createQuery("select key from ConfigProperty dbconfig where dbconfig.key like :key", String.class); + TypedQuery<String> query = em.createQuery("select key from " + dataBaseEntityName + " dbconfig where dbconfig.key like :key", String.class); query.setParameter("key", searchString.replace("*", "%")); List<String> result = query.getResultList(); if (result == null) @@ -146,7 +155,7 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { throw new ConfigurationException("No EntityManager set!"); } - TypedQuery<AbstractConfigProperty> query = em.createQuery("select * from ConfigProperty dbconfig", AbstractConfigProperty.class); + TypedQuery<AbstractConfigProperty> query = em.createQuery("select * from " + dataBaseEntityName + " dbconfig", AbstractConfigProperty.class); List<AbstractConfigProperty> all = query.getResultList(); searchString = searchString.replace(".", "\\."); @@ -195,7 +204,8 @@ public class DatabaseConfigPropertyImpl extends AbstractConfigurationImpl { private AbstractConfigProperty getProperty(String key) { log.trace("Looking for configuration property for key '{}'.", key); - AbstractConfigProperty result = em.find(AbstractConfigProperty.class, key); + + AbstractConfigProperty result = em.find(appContext.getBean(AbstractConfigProperty.class).getClass(), key); if (result != null) { log.trace("Found configuration property {}.", result); } else { 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 7cb921ee7..b13f0ba5b 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,12 @@ public class AuthenticatedSessionStore implements Serializable{ @Column(name = "pendingRequestID", nullable=true) private String pendingRequestID = ""; - @Column(name = "additionalInformationBytes", nullable=true) + @Column(name = "additionalInformation", nullable=true) @Lob - private byte[] additionalInformation; + private String additionalInformation; + + @Column(name = "additionalInformationBytes", nullable=true) + private byte[] additionalInformationBytes; @Column(name = "created", updatable=false, nullable=false) @Temporal(TemporalType.TIMESTAMP) @@ -350,14 +353,14 @@ public class AuthenticatedSessionStore implements Serializable{ * @return the additionalInformation */ public byte[] getAdditionalInformation() { - return additionalInformation; + return additionalInformationBytes; } /** * @param additionalInformation the additionalInformation to set */ public void setAdditionalInformation(byte[] additionalInformation) { - this.additionalInformation = additionalInformation; + this.additionalInformationBytes = additionalInformation; } diff --git a/id/server/moa-id-commons/src/main/resources/configuration.beans.xml b/id/server/moa-id-commons/src/main/resources/configuration.beans.xml index 1251cf406..79e2decc1 100644 --- a/id/server/moa-id-commons/src/main/resources/configuration.beans.xml +++ b/id/server/moa-id-commons/src/main/resources/configuration.beans.xml @@ -12,30 +12,32 @@ <context:annotation-config /> <beans profile="!byteBasedConfig"> <bean id="StringBasedConfigProperty" - class="at.gv.egovernment.moa.id.commons.db.dao.config.ConfigProperty"/> + class="at.gv.egovernment.moa.id.commons.db.dao.config.ConfigProperty" + scope="prototype"/> </beans> <beans profile="byteBasedConfig"> <bean id="ByteBasedConfigProperty" - class="at.gv.egovernment.moa.id.commons.db.dao.config.ConfigPropertyByteValues" - /> + class="at.gv.egovernment.moa.id.commons.db.dao.config.ConfigPropertyByteValues" + scope="prototype"/> </beans> - <bean id="configPropertyDao" - class="at.gv.egovernment.moa.id.commons.db.dao.config.DatabaseConfigPropertyImpl"/> + <beans> + <bean id="configPropertyDao" + class="at.gv.egovernment.moa.id.commons.db.dao.config.DatabaseConfigPropertyImpl"/> - <bean id="moaidconfig" class="at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfigurationImpl" /> + <bean id="moaidconfig" class="at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfigurationImpl" /> - <bean name="config" id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> - <property name="packagesToScan" value="at.gv.egovernment.moa.id.commons.db.dao.config" /> - <property name="dataSource" ref="dataSource" /> - <property name="jpaVendorAdapter" ref="jpaVendorAdapter" /> - <property name="persistenceUnitName" value="config" /> - </bean> - - <bean name="transactionManager" id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> - <property name="entityManagerFactory" ref="entityManagerFactory" /> - </bean> - <tx:annotation-driven transaction-manager="transactionManager"/> + <bean name="config" id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> + <property name="packagesToScan" value="at.gv.egovernment.moa.id.commons.db.dao.config" /> + <property name="dataSource" ref="dataSource" /> + <property name="jpaVendorAdapter" ref="jpaVendorAdapter" /> + <property name="persistenceUnitName" value="config" /> + </bean> + <bean name="transactionManager" id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> + <property name="entityManagerFactory" ref="entityManagerFactory" /> + </bean> + <tx:annotation-driven transaction-manager="transactionManager"/> + </beans> </beans>
\ No newline at end of file |