Type:
Code:
package ch.bedag.gba.cap.server.persistence.hibernate;
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
public class CapiPK implements Serializable {
private Long mySystemId = null;
private Long myId = null;
public CapiPK() {
super();
}
public CapiPK(Long systemId, Long pid) {
this();
mySystemId = systemId;
myId = pid;
}
public CapiPK(long systemId, long pid) {
super();
mySystemId = new Long(systemId);
myId = new Long(pid);
}
public Long getId() {
return myId;
}
public void setId(Long pid) {
myId = pid;
}
public Long getSystemId() {
return mySystemId;
}
public void setSystemId(Long systemId) {
mySystemId = systemId;
}
public boolean equals(Object obj) {
if (!(obj instanceof CapiPK)) return false;
CapiPK pk = (CapiPK)obj;
return new EqualsBuilder()
.append(mySystemId, pk.mySystemId)
.append(myId, pk.myId)
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(mySystemId)
.append(myId)
.toHashCode();
}
public String toString() {
return new ReflectionToStringBuilder(this).toString();
}
}
CompositeUserType:
[code]package ch.bedag.gba.cap.server.persistence.hibernate;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import net.sf.hibernate.CompositeUserType;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.engine.SessionImplementor;
import net.sf.hibernate.type.Type;
import ch.bedag.gba.server.persistence.PersistenceRuntimeException;
public class CapiPkType implements CompositeUserType {
private static final ch.bedag.gba.common.logging.CapiLogger LOG = ch.bedag.gba.common.logging.CapiLoggerFactory
.getLog(CapiPkType.class);
private static final String[] PROPERTY_NAMES = {"systemId", "id"};
private static final Type[] PROPERTY_TYPES = {Hibernate.LONG, Hibernate.LONG};
public String[] getPropertyNames() {
return PROPERTY_NAMES;
}
public Type[] getPropertyTypes() {
return PROPERTY_TYPES;
}
public Object getPropertyValue(Object component, int property) throws HibernateException {
CapiPK capiPk = (CapiPK)component;
switch (property) {
case 0:
return capiPk.getSystemId();
case 1:
return capiPk.getId();
default:
throw new PersistenceRuntimeException(property+" ist kein g