From: <ro...@us...> - 2009-04-21 12:25:51
|
Revision: 135 http://cse-ip.svn.sourceforge.net/cse-ip/?rev=135&view=rev Author: roekens Date: 2009-04-21 12:25:41 +0000 (Tue, 21 Apr 2009) Log Message: ----------- refactoring of sc-idmapper to sc-mapper Modified Paths: -------------- trunk/sandbox/cse-ip/cse-ip-application/pom.xml trunk/sandbox/cse-ip/pom.xml Added Paths: ----------- trunk/sandbox/cse-ip/sc-mapper/ trunk/sandbox/cse-ip/sc-mapper/build.xml trunk/sandbox/cse-ip/sc-mapper/createDDL.jdbc trunk/sandbox/cse-ip/sc-mapper/dropDDL.jdbc trunk/sandbox/cse-ip/sc-mapper/pom.xml trunk/sandbox/cse-ip/sc-mapper/src/ trunk/sandbox/cse-ip/sc-mapper/src/main/ trunk/sandbox/cse-ip/sc-mapper/src/main/java/ trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/ trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/ trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/ trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/ trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapper.java trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapperBean.java trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapperLocal.java trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/MappedClientObject.java trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/MappedClientObjectPK.java trunk/sandbox/cse-ip/sc-mapper/src/main/resources/ trunk/sandbox/cse-ip/sc-mapper/src/main/resources/META-INF/ trunk/sandbox/cse-ip/sc-mapper/src/main/resources/META-INF/persistence.xml trunk/sandbox/cse-ip/sc-mapper/src/test/ trunk/sandbox/cse-ip/sc-mapper/src/test/java/ trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/ trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/ trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/ trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/ trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/IdentityMapperTest.java trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/IdentityMapperWebServiceTest.java trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/MappedClientObjectPKTest.java trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/MappedClientObjectTest.java trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/PersistentUnitConfigurationTest.java trunk/sandbox/cse-ip/sc-mapper/src/test/resources/ trunk/sandbox/cse-ip/sc-mapper/src/test/resources/META-INF/ trunk/sandbox/cse-ip/sc-mapper/src/test/resources/META-INF/persistence.xml trunk/sandbox/cse-ip/sc-mapper/src/test/resources/log4j.properties Removed Paths: ------------- trunk/sandbox/cse-ip/sc-idmapper/ Modified: trunk/sandbox/cse-ip/cse-ip-application/pom.xml =================================================================== --- trunk/sandbox/cse-ip/cse-ip-application/pom.xml 2009-04-21 11:35:08 UTC (rev 134) +++ trunk/sandbox/cse-ip/cse-ip-application/pom.xml 2009-04-21 12:25:41 UTC (rev 135) @@ -17,7 +17,7 @@ <dependencies> <dependency> <groupId>de.campussource.cse</groupId> - <artifactId>sc-idmapper</artifactId> + <artifactId>sc-mapper</artifactId> <version>${pom.version}</version> <type>ejb</type> </dependency> @@ -40,7 +40,7 @@ <modules> <ejbModule> <groupId>de.campussource.cse</groupId> - <artifactId>sc-idmapper</artifactId> + <artifactId>sc-mapper</artifactId> </ejbModule> </modules> <modules> Modified: trunk/sandbox/cse-ip/pom.xml =================================================================== --- trunk/sandbox/cse-ip/pom.xml 2009-04-21 11:35:08 UTC (rev 134) +++ trunk/sandbox/cse-ip/pom.xml 2009-04-21 12:25:41 UTC (rev 135) @@ -106,7 +106,7 @@ <modules> <module>framework</module> <module>ica-his-lsf</module> - <module>sc-idmapper</module> + <module>sc-mapper</module> <module>sc-cdmm</module> <module>sc-common</module> <module>cse-ip-application</module> Added: trunk/sandbox/cse-ip/sc-mapper/build.xml =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/build.xml (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/build.xml 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,41 @@ +<project name="cse-ip :: sc :: mapper :: build" default="install" basedir="."> + <condition property="maven.executable" value="mvn.bat" else="mvn"><os family="windows" /></condition> + + <target name="compile"> + <exec executable="${maven.executable}"> + <arg line="install"/> + </exec> + </target> + + <target name="clean"> + <exec executable="${maven.executable}"> + <arg line="clean"/> + </exec> + </target> + + <target name="install"> + <exec executable="${maven.executable}"> + <arg line="install"/> + </exec> + </target> + + <target name="eclipse"> + <exec executable="${maven.executable}"> + <arg line="eclipse:clean eclipse:eclipse"/> + </exec> + </target> + + <target name="wsgen"> + <exec executable="${maven.executable}"> + <arg line="jaxws:wsgen"/> + </exec> + </target> + + <target name="wsimport"> + <exec executable="${maven.executable}"> + <arg line="jaxws:wsimport"/> + </exec> + </target> + + +</project> Property changes on: trunk/sandbox/cse-ip/sc-mapper/build.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/createDDL.jdbc =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/createDDL.jdbc (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/createDDL.jdbc 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,4 @@ +CREATE TABLE MAPPED_CLIENT_OBJECT (BUS_ID BIGINT NOT NULL, CLIENT_INSTANCE_ID BIGINT NOT NULL, CLIENT_OBJECT_ID VARCHAR(255) NOT NULL, PRIMARY KEY (BUS_ID, CLIENT_INSTANCE_ID)) +ALTER TABLE MAPPED_CLIENT_OBJECT ADD CONSTRAINT UNQ_MAPPED_CLIENT_OBJECT_0 UNIQUE (CLIENT_OBJECT_ID, CLIENT_INSTANCE_ID) +CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(38), PRIMARY KEY (SEQ_NAME)) +INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0) Added: trunk/sandbox/cse-ip/sc-mapper/dropDDL.jdbc =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/dropDDL.jdbc (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/dropDDL.jdbc 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,3 @@ +ALTER TABLE MAPPED_CLIENT_OBJECT DROP FOREIGN KEY UNQ_MAPPED_CLIENT_OBJECT_0 +DROP TABLE MAPPED_CLIENT_OBJECT +DELETE FROM SEQUENCE WHERE SEQ_NAME = 'SEQ_GEN' Added: trunk/sandbox/cse-ip/sc-mapper/pom.xml =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/pom.xml (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/pom.xml 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,141 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>cse-ip</artifactId> + <groupId>de.campussource.cse</groupId> + <version>1.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>de.campussource.cse</groupId> + <artifactId>sc-mapper</artifactId> + <packaging>ejb</packaging> + <name>Service Component Id-Mapper</name> + <version>1.0-SNAPSHOT</version> + + <dependencies> + <dependency> + <groupId>de.campussource.cse</groupId> + <artifactId>test-utilities</artifactId> + <version>${pom.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.sun.xml.ws</groupId> + <artifactId>jaxws-rt</artifactId> + <version>2.1.5</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>de.campussource.cse</groupId> + <artifactId>sc-common</artifactId> + <version>${pom.version}</version> + </dependency> + <dependency> + <groupId>javax.ejb</groupId> + <artifactId>ejb-api</artifactId> + <version>3.0</version> + <!-- <scope>provided</scope>--> + </dependency> + <dependency> + <groupId>javax.persistence</groupId> + <artifactId>persistence-api</artifactId> + <version>1.0</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>${slf4j.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>${slf4j.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>toplink.essentials</groupId> + <artifactId>toplink-essentials</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <resources> + <resource> + <directory>${project.build.directory}/resources-generated</directory> + <includes> + <include>**/*.xsd</include> + <include>**/*.wsdl</include> + <include>**/*.xml</include> + </includes> + </resource> + <resource> + <directory>${project.build.directory}/sources-generated</directory> + <includes> + <include>**/*.java</include> + </includes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-ejb-plugin</artifactId> + <configuration> + <ejbVersion>3.0</ejbVersion> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>jaxws-maven-plugin</artifactId> + <version>1.10</version> + <executions> + <execution> + <phase>generate-test-sources</phase> + <goals> + <goal>wsgen</goal> + <goal>wsimport</goal> + </goals> + </execution> + </executions> + <configuration> + <sei>de.campussource.cse.mapper.IdentityMapperBean</sei> + <packageName>de.campussource.cse.mapper.generated</packageName> + <keep>true</keep> + <genWsdl>true</genWsdl> + <verbose>true</verbose> + <resourceDestDir>${project.build.directory}/resources-generated</resourceDestDir> + <sourceDestDir>${project.build.directory}/sources-generated</sourceDestDir> + <wsdlLocation>${project.build.directory}/resources-generated/IdentityMapperBean.wsdl</wsdlLocation> + </configuration> + </plugin> + </plugins> + </build> + +</project> \ No newline at end of file Property changes on: trunk/sandbox/cse-ip/sc-mapper/pom.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapper.java =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapper.java (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapper.java 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,47 @@ +package de.campussource.cse.mapper; + +import javax.ejb.Remote; + +import de.campussource.cse.common.exception.IdNotFoundException; + +/** + * IdentityMapper manage the administration of mappings between the global + * unique busId and client specific object ids. Each mapping exists of three + * ids. The global unique bus id, the client instance unique object id, and the + * client unique instance id. + * + * @author Ingo Dueppe + */ +@Remote +public interface IdentityMapper { + + /** + * Convert a clientInstanceId and a clientObjectId to a busID. If the busId + * doesn't exist for the given combination of the parameters then a new busId will be generated. + * + * @param clientInstanceId the Id of the client instance. + * @param clientObjectId the Id of the client object. The id can be any arbitrary string. + * @return busId according to the clientInstance- and clientObjectId. + */ + public Long toBusId(Long clientInstanceId, String clientObjectId); + + /** + * Convert the combination of busId and clientInstanceId to a clientObjectId. + * + * @param busId a existing bus id. + * @param clientInstanceId a existing client instance id. + * @return the corresponding clientObjectID + * @throws IdNotFoundException thrown if either the busId or the clientInstanceId doesn't exists. + */ + public String toClientObjectId(Long busId, Long clientInstanceId) throws IdNotFoundException; + + /** + * Save or update the clientObjectId according to the given busId and clientInstanceId. + * + * @param busId the global unique busId. + * @param clientInstanceId the global unique client instance id. + * @param clientObjectId the client unique object id. + */ + public void persistClientObjectId(Long busId, Long clientInstanceId, String clientObjectId); + +} Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapper.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapperBean.java =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapperBean.java (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapperBean.java 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,82 @@ +package de.campussource.cse.mapper; + +import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; +import javax.ejb.TransactionAttributeType; +import javax.jws.WebService; +import javax.persistence.EntityExistsException; +import javax.persistence.EntityManager; +import javax.persistence.NoResultException; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + +import org.apache.commons.lang.Validate; + +import de.campussource.cse.common.exception.IdNotFoundException; + +/** + * Standard IdentityMapper implementation + * @author Ingo Dueppe + */ +@Stateless +@WebService(name="IdentityMapper", targetNamespace="http://cse.campussource.de/mapper") +public class IdentityMapperBean implements IdentityMapper { + + @PersistenceContext + private EntityManager manager; + + @Override + @TransactionAttribute(TransactionAttributeType.REQUIRED) + public void persistClientObjectId(Long busId, Long clientInstanceId, String clientObjectId) { + Validate.notNull(busId, "IdentityMapper.persistClientObjectId: Parameter busId is mandatory."); + Validate.notNull(clientInstanceId, "IdentityMapper.persistClientObjectId: Parameter clientInstanceId is mandatory."); + Validate.notEmpty(clientObjectId, "IdentityMapper.persistClientObjectId: Parameter clientObjectId is mandatory."); + MappedClientObject mapped = new MappedClientObject(busId, clientInstanceId, clientObjectId); + try { + manager.persist(mapped); + } catch (EntityExistsException eee) { + manager.merge(mapped); + } + System.out.println("MappedClientObject "+mapped.toString()); + } + + @Override + @TransactionAttribute(TransactionAttributeType.REQUIRED) + public Long toBusId(Long clientInstanceId, String clientObjectId) { + Validate.notNull(clientInstanceId, "IdentityMapper.toBusId: Parameter clientInstanceId is mandatory."); + Validate.notNull(clientObjectId, "IdentityMapper.toBusId: Parameter clientObjectId is mandatory."); + try { + Query query = manager.createNamedQuery(MappedClientObject.FIND_BUSID); + query.setParameter("clientInstanceId", clientInstanceId); + query.setParameter("clientObjectId", clientObjectId); + return (Long) query.getSingleResult(); + } catch (NoResultException nre) { + return createMapping(clientInstanceId, clientObjectId); + } + } + + private Long createMapping(Long clientInstanceId, String clientObjectId) { + MappedClientObject mapped = new MappedClientObject(); + mapped.setClientInstanceId(clientInstanceId); + mapped.setClientObjectId(clientObjectId); + manager.persist(mapped); + return mapped.getBusId(); + } + + @Override + @TransactionAttribute(TransactionAttributeType.REQUIRED) + public String toClientObjectId(Long busId, Long clientInstanceId) throws IdNotFoundException { + Validate.notNull(busId,"IdentityMapper.toClientObjectId: Parameter busId is mandatory."); + Validate.notNull(clientInstanceId,"IdentityMapper.toClientObjectId: Parameter clientInstanceId is mandatory."); + try { + Query query = manager.createNamedQuery(MappedClientObject.FIND_OBJECTID); + query.setParameter("clientInstanceId", clientInstanceId); + query.setParameter("busId", busId); + return (String) query.getSingleResult(); + } catch (NoResultException nre) { + throw new IdNotFoundException(nre); + } + + } + +} Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapperBean.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapperLocal.java =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapperLocal.java (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapperLocal.java 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,13 @@ +package de.campussource.cse.mapper; + +import javax.ejb.Local; + +/** + * The local interface of IdentityMapper + * @see de.campussource.cse.mapper.IdentityMapper + * @author Ingo Dueppe + */ +@Local +public interface IdentityMapperLocal extends IdentityMapper { + +} Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/IdentityMapperLocal.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/MappedClientObject.java =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/MappedClientObject.java (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/MappedClientObject.java 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,103 @@ +package de.campussource.cse.mapper; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +/** + * @author Ingo Dueppe + */ +@Entity(name="MappedClientObject") +@Table(name = "MAPPED_CLIENT_OBJECT", + uniqueConstraints = @UniqueConstraint(columnNames = { "CLIENT_OBJECT_ID", "CLIENT_INSTANCE_ID" })) +@NamedQueries(value = { + @NamedQuery( + name = "MappedClientObject.findObjectId", + query = "select c.clientObjectId from MappedClientObject c where c.busId=:busId and c.clientInstanceId = :clientInstanceId"), + @NamedQuery( + name = "MappedClientObject.findBusId", + query = "select c.busId from MappedClientObject c where c.clientObjectId=:clientObjectId and c.clientInstanceId = :clientInstanceId") }) +@IdClass(value=MappedClientObjectPK.class) +public class MappedClientObject { + + public static final String FIND_OBJECTID = "MappedClientObject.findObjectId"; + public static final String FIND_BUSID = "MappedClientObject.findBusId"; + + private Long busId; + + private Long clientInstanceId; + + private String clientObjectId; + + public MappedClientObject() { + }; + + public MappedClientObject(Long busId, Long clientInstanceId, String clientObjectId) { + this.busId = busId; + this.clientInstanceId = clientInstanceId; + this.clientObjectId = clientObjectId; + } + + @Id + @Column(name="BUS_ID", nullable = false) + @GeneratedValue(strategy = GenerationType.AUTO) + public Long getBusId() { + return busId; + } + + public void setBusId(Long busId) { + this.busId = busId; + } + + @Id + @Column(name="CLIENT_INSTANCE_ID", nullable=false) + public Long getClientInstanceId() { + return clientInstanceId; + } + + public void setClientInstanceId(Long clientInstanceId) { + this.clientInstanceId = clientInstanceId; + } + + @Column(name="CLIENT_OBJECT_ID", nullable=false) + public String getClientObjectId() { + return clientObjectId; + } + + public void setClientObjectId(String clientObjectId) { + this.clientObjectId = clientObjectId; + } + + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof MappedClientObject)) { + return false; + } + MappedClientObject other = (MappedClientObject) obj; + return new EqualsBuilder().append(busId, other.busId).append(clientInstanceId, other.clientInstanceId).isEquals(); + } + + public int hashCode() { + return new HashCodeBuilder().append(busId).append(clientInstanceId).toHashCode(); + } + + public String toString() { + return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(busId).append(clientInstanceId).append( + clientObjectId).toString(); + } + +} Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/MappedClientObject.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/MappedClientObjectPK.java =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/MappedClientObjectPK.java (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/MappedClientObjectPK.java 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,63 @@ +package de.campussource.cse.mapper; + +import java.io.Serializable; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +/** + * @author Ingo Dueppe + */ +public class MappedClientObjectPK implements Serializable { + + private static final long serialVersionUID = 4835950977456597594L; + + private Long busId; + private Long clientInstanceId; + + public MappedClientObjectPK() { + } + + public MappedClientObjectPK(Long busId, Long clientInstanceId) { + this.busId = busId; + this.clientInstanceId = clientInstanceId; + } + + public Long getBusId() { + return busId; + } + + public void setBusId(Long busId) { + this.busId = busId; + } + + public Long getClientInstanceId() { + return clientInstanceId; + } + + public void setClientInstanceId(Long clientInstanceId) { + this.clientInstanceId = clientInstanceId; + } + + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof MappedClientObjectPK)) { + return false; + } + MappedClientObjectPK other = (MappedClientObjectPK) obj; + return new EqualsBuilder().append(busId, other.busId).append(clientInstanceId, other.clientInstanceId).isEquals(); + } + + public int hashCode() { + return new HashCodeBuilder().append(busId).append(clientInstanceId).toHashCode(); + } + + public String toString() { + return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(busId).append(clientInstanceId).toString(); + } + +} Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/main/java/de/campussource/cse/mapper/MappedClientObjectPK.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/main/resources/META-INF/persistence.xml =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/main/resources/META-INF/persistence.xml (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/main/resources/META-INF/persistence.xml 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,15 @@ +<persistence xmlns="http://java.sun.com/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" + version="1.0"> + <persistence-unit name="cs-mapper"> + <provider>oracle.toplink.essentials.PersistenceProvider</provider> + <jta-data-source>jdbc/cseip</jta-data-source> + <class>de.campussource.cse.mapper.MappedClientObject</class> + </persistence-unit> +</persistence> + + + + + \ No newline at end of file Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/main/resources/META-INF/persistence.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/IdentityMapperTest.java =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/IdentityMapperTest.java (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/IdentityMapperTest.java 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,122 @@ +package de.campussource.cse.mapper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.persistence.RollbackException; + +import org.junit.Before; +import org.junit.Test; + +import de.campussource.cse.common.exception.IdNotFoundException; +import de.campussource.cse.common.exception.ServiceComponentException; +import de.campussource.cse.common.test.AbstractPersistentUnitTest; + +/** + * @author Ingo Dueppe + */ +public class IdentityMapperTest extends AbstractPersistentUnitTest { + + private static final Long UNKNOWN_BUS_ID = -1000L; + private static final Long BUS_ID = 1000L; + private static final Long CLIENT_INSTANCE_ID = 1000L; + private static final String CLIENT_OBJECT_ID = "CSE:SYSTEM:CLIENTID"; + + private IdentityMapper mapper; + + @Before + public void setUp() { + txBegin(); + // CleanUp Database + entityManager.createNativeQuery("DELETE FROM MAPPED_CLIENT_OBJECT").executeUpdate(); + commitAndBeginTx(); + mapper = new IdentityMapperBean(); + autowireByType(mapper); + } + + @Test + public void testBusToClientMapping() throws ServiceComponentException { + Long busId = mapper.toBusId(CLIENT_INSTANCE_ID, CLIENT_OBJECT_ID); + String clientId = mapper.toClientObjectId(busId, CLIENT_INSTANCE_ID); + assertEquals(CLIENT_OBJECT_ID, clientId); + } + + @Test + public void testMultiBusToMapping() throws ServiceComponentException { + for (int i = 0; i < 10; i++) { + Long busId = mapper.toBusId(CLIENT_INSTANCE_ID, CLIENT_OBJECT_ID); + String clientId = mapper.toClientObjectId(busId, CLIENT_INSTANCE_ID); + assertEquals(CLIENT_OBJECT_ID, clientId); + commitAndBeginTx(); + } + } + + @Test(expected = IdNotFoundException.class) + public void testBusIdNotFound() throws IdNotFoundException { + mapper.toClientObjectId(CLIENT_INSTANCE_ID, UNKNOWN_BUS_ID); + } + + @Test(expected = IdNotFoundException.class) + public void testClientObjectIdNotFound() throws IdNotFoundException { + Long busId = mapper.toBusId(CLIENT_INSTANCE_ID, CLIENT_OBJECT_ID); + assertNotNull(busId); + mapper.toClientObjectId(busId, CLIENT_INSTANCE_ID + uniqueId()); + } + + @Test + public void testPersistClientObjectId() throws ServiceComponentException { + // Persist a new mapping of client object id to a given bus id and + // verify the results + mapper.persistClientObjectId(BUS_ID, CLIENT_INSTANCE_ID, CLIENT_OBJECT_ID); + commitAndBeginTx(); + assertEquals(BUS_ID, mapper.toBusId(CLIENT_INSTANCE_ID, CLIENT_OBJECT_ID)); + assertEquals(CLIENT_OBJECT_ID, mapper.toClientObjectId(BUS_ID, CLIENT_INSTANCE_ID)); + // Override the existing mapping to a new client object id and verify + // the results + mapper.persistClientObjectId(BUS_ID, CLIENT_INSTANCE_ID, "NEW:CLIENT:OBJECT:ID"); + assertEquals(BUS_ID, mapper.toBusId(CLIENT_INSTANCE_ID, "NEW:CLIENT:OBJECT:ID")); + assertEquals("NEW:CLIENT:OBJECT:ID", mapper.toClientObjectId(BUS_ID, CLIENT_INSTANCE_ID)); + } + + @Test(expected=RollbackException.class) + public void testErrorPersistClientObjectId() throws ServiceComponentException { + mapper.persistClientObjectId(1L, CLIENT_INSTANCE_ID, CLIENT_OBJECT_ID); + mapper.persistClientObjectId(2L, CLIENT_INSTANCE_ID, CLIENT_OBJECT_ID); + commitAndBeginTx(); + } + + @Test(expected = IllegalArgumentException.class) + public void testToBusNoClientInstanceParameter() throws IdNotFoundException { + mapper.toBusId(null, CLIENT_OBJECT_ID); + } + + @Test(expected = IllegalArgumentException.class) + public void testToBusNoObjectIdParameter() throws IdNotFoundException { + mapper.toBusId(CLIENT_INSTANCE_ID, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testToClientNoBusIdParameter() throws IdNotFoundException { + mapper.toClientObjectId(null, CLIENT_INSTANCE_ID); + } + + @Test(expected = IllegalArgumentException.class) + public void testToClientNoInstanceIdParameter() throws IdNotFoundException { + mapper.toClientObjectId(BUS_ID, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testPersistNoBusIdParameter() throws ServiceComponentException { + mapper.persistClientObjectId(null, CLIENT_INSTANCE_ID, CLIENT_OBJECT_ID); + } + + @Test(expected = IllegalArgumentException.class) + public void testPersistNoInstanceIdParameter() throws ServiceComponentException { + mapper.persistClientObjectId(BUS_ID, null, CLIENT_OBJECT_ID); + } + + @Test(expected = IllegalArgumentException.class) + public void testPersistNoObjectIdParameter() throws ServiceComponentException { + mapper.persistClientObjectId(BUS_ID, CLIENT_INSTANCE_ID, ""); + } +} Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/IdentityMapperTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/IdentityMapperWebServiceTest.java =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/IdentityMapperWebServiceTest.java (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/IdentityMapperWebServiceTest.java 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,18 @@ +package de.campussource.cse.mapper; + +import javax.xml.ws.Endpoint; + +import org.junit.Test; + + + +public class IdentityMapperWebServiceTest { + + @Test + public void testWebService() { + Endpoint endpoint = Endpoint.publish("http://localhost:12345/mapper", new IdentityMapperBean()); +// JOptionPane.showMessageDialog(null, "Mapper Server"); + endpoint.stop(); + } + +} Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/IdentityMapperWebServiceTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/MappedClientObjectPKTest.java =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/MappedClientObjectPKTest.java (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/MappedClientObjectPKTest.java 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,63 @@ +package de.campussource.cse.mapper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * @author Ingo Dueppe + */ +public class MappedClientObjectPKTest { + + @Test + public void testEquals() { + MappedClientObjectPK pk = new MappedClientObjectPK(); + assertTrue(pk.equals(pk)); + + assertFalse(new MappedClientObjectPK().equals(new Object())); + assertFalse(new Object().equals(new MappedClientObjectPK())); + + assertFalse(new MappedClientObjectPK(1L, 1L).equals(new MappedClientObjectPK())); + assertFalse(new MappedClientObjectPK().equals(new MappedClientObjectPK(1L, 1L))); + + assertTrue(new MappedClientObjectPK(1L, 1L).equals(new MappedClientObjectPK(1L, 1L))); + + assertFalse(new MappedClientObjectPK(1L, 2L).equals(new MappedClientObjectPK(2L, 1L))); + assertFalse(new MappedClientObjectPK(1L, 1L).equals(new MappedClientObjectPK(1L, 2L))); + + assertTrue(new MappedClientObjectPK(1L, null).equals(new MappedClientObjectPK(1L, null))); + assertFalse(new MappedClientObjectPK(null, null).equals(new MappedClientObjectPK(1L, null))); + + assertTrue(new MappedClientObjectPK().equals(new MappedClientObjectPK())); + } + + @Test + public void testSetters() { + MappedClientObjectPK pk = new MappedClientObjectPK(); + + assertTrue(pk.getBusId() == null); + assertTrue(pk.getClientInstanceId() == null); + + pk.setBusId(1L); + assertEquals((Long)1L, pk.getBusId()); + + pk.setClientInstanceId(1L); + assertEquals((Long)1L, pk.getClientInstanceId()); + } + + @Test + public void testToString() { + assertFalse(new MappedClientObjectPK().toString().isEmpty()); + } + + @Test + public void testHashCode() { + assertEquals(new MappedClientObjectPK(1L,1L).hashCode(), new MappedClientObjectPK(1L,1L).hashCode()); + assertNotSame(new MappedClientObjectPK(1L,1L).hashCode(), new MappedClientObjectPK(1L,2L).hashCode()); + assertNotSame(new MappedClientObjectPK(1L,1L).hashCode(), new MappedClientObjectPK(2L,1L).hashCode()); + } + +} Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/MappedClientObjectPKTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/MappedClientObjectTest.java =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/MappedClientObjectTest.java (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/MappedClientObjectTest.java 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,54 @@ +package de.campussource.cse.mapper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * @author Ingo Dueppe + */ +public class MappedClientObjectTest { + + @Test + public void testEquals() { + MappedClientObject mapped = new MappedClientObject(); + assertTrue(mapped.equals(mapped)); + + assertFalse(new MappedClientObject().equals(new Object())); + assertFalse(new Object().equals(new MappedClientObject())); + + assertFalse(new MappedClientObject(1L, 1L, "").equals(new MappedClientObject())); + assertFalse(new MappedClientObject().equals(new MappedClientObject(1L, 1L, ""))); + + assertTrue(new MappedClientObject(1L, 1L, "").equals(new MappedClientObject(1L, 1L, ""))); + assertTrue(new MappedClientObject(1L, 1L, "").equals(new MappedClientObject(1L, 1L, "XYZ"))); + + assertFalse(new MappedClientObject(1L, 2L, "").equals(new MappedClientObject(2L, 1L, ""))); + assertFalse(new MappedClientObject(1L, 1L, "").equals(new MappedClientObject(1L, 2L, ""))); + + assertTrue(new MappedClientObject(1L, null, "").equals(new MappedClientObject(1L, null, ""))); + assertFalse(new MappedClientObject(null, null, "").equals(new MappedClientObject(1L, null, ""))); + + assertTrue(new MappedClientObject().equals(new MappedClientObject())); + + assertFalse(new MappedClientObject().equals(null)); + } + + @Test + public void testToString() { + assertFalse(new MappedClientObject().toString().isEmpty()); + assertFalse(new MappedClientObject(1L, 1L,"TEST").toString().isEmpty()); + } + + @Test + public void testHashCode() { + assertEquals(new MappedClientObject(1L,1L,"").hashCode(), new MappedClientObject(1L,1L,"").hashCode()); + assertEquals(new MappedClientObject(1L,1L,"321").hashCode(), new MappedClientObject(1L,1L,"123").hashCode()); + assertNotSame(new MappedClientObject(1L,1L,"").hashCode(), new MappedClientObject(1L,2L,"").hashCode()); + assertNotSame(new MappedClientObject(1L,1L,"").hashCode(), new MappedClientObject(2L,1L,"").hashCode()); + } + +} Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/MappedClientObjectTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/PersistentUnitConfigurationTest.java =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/PersistentUnitConfigurationTest.java (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/PersistentUnitConfigurationTest.java 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,35 @@ +package de.campussource.cse.mapper; + +import static org.junit.Assert.assertNotNull; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import org.junit.Test; + +/** + * @author Ingo Dueppe + */ +public class PersistentUnitConfigurationTest { + + @Test + public void testConfiguration() { + try { + EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("cseip-test"); + EntityManager entityManager = entityManagerFactory.createEntityManager(); + + List<MappedClientObject> mappings = entityManager.createQuery("SELECT m FROM MappedClientObject m").getResultList(); + assertNotNull(mappings); + + entityManager.close(); + entityManagerFactory.close(); + } catch (RuntimeException rt) { + rt.printStackTrace(); + throw rt; + } + } + +} Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/test/java/de/campussource/cse/mapper/PersistentUnitConfigurationTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/test/resources/META-INF/persistence.xml =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/test/resources/META-INF/persistence.xml (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/test/resources/META-INF/persistence.xml 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,21 @@ +<persistence xmlns="http://java.sun.com/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" + version="1.0"> + <persistence-unit name="cseip-test" transaction-type="RESOURCE_LOCAL"> + <provider>oracle.toplink.essentials.PersistenceProvider</provider> + <class>de.campussource.cse.mapper.MappedClientObject</class> + <properties> + <property name="toplink.ddl-generation" value="drop-and-create-tables" /> + <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver" /> + <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/cseiptest?createDatabaseIfNotExist=true" /> + <property name="toplink.jdbc.user" value="root" /> + <property name="toplink.jdbc.password" value="masterkey" /> + </properties> + </persistence-unit> +</persistence> + + + + + \ No newline at end of file Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/test/resources/META-INF/persistence.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/sandbox/cse-ip/sc-mapper/src/test/resources/log4j.properties =================================================================== --- trunk/sandbox/cse-ip/sc-mapper/src/test/resources/log4j.properties (rev 0) +++ trunk/sandbox/cse-ip/sc-mapper/src/test/resources/log4j.properties 2009-04-21 12:25:41 UTC (rev 135) @@ -0,0 +1,15 @@ +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +log4j.rootCategory=debug, stdout + +log4j.logger.org.hibernate=info + +log4j.logger.oracle.toplink=debug + +log4j.logger.org.hibernate.SQL=debug +log4j.logger.org.hibernate.type=debug +log4j.logger.org.hibernate.id=debug +log4j.logger.org.hibernate.cache=debug \ No newline at end of file Property changes on: trunk/sandbox/cse-ip/sc-mapper/src/test/resources/log4j.properties ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |