📄 operationstyletype.java
字号:
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
* published by JBoss Inc.; either version 1.0 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
package org.jbpm.bpel.db.type;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import javax.wsdl.OperationType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
/**
* Maps a commons-lang <code>Enum</code> to a Hibernate type.
* @author Juan Cantu
* @version $Revision: 1.3 $ $Date: 2006/09/27 03:53:02 $
*/
public class OperationStyleType implements UserType {
private static final int[] SQLTYPES = { Types.INTEGER };
private static final Log log = LogFactory.getLog(OperationStyleType.class);
private static final OperationType OPERATION_TYPES[] = {
OperationType.REQUEST_RESPONSE, OperationType.ONE_WAY,
OperationType.SOLICIT_RESPONSE, OperationType.NOTIFICATION };
public boolean equals(Object o1, Object o2) {
return o1 == null ? o2 == null : o1.equals(o2);
}
public int hashCode(Object o) throws HibernateException {
return o.hashCode();
}
public Object deepCopy(Object o) throws HibernateException {
return o;
}
public boolean isMutable() {
return false;
}
public Serializable disassemble(Object o) throws HibernateException {
return (Serializable) o;
}
public Object assemble(Serializable s, Object o) throws HibernateException {
return s;
}
public Object replace(Object original, Object target, Object owner) {
return target;
}
public int[] sqlTypes() {
return SQLTYPES;
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException {
final String columnName = names[0];
final Integer typeCode = (Integer) Hibernate.INTEGER.nullSafeGet(rs,
columnName);
OperationType operationType = typeCode != null ? fromInt(typeCode.intValue())
: null;
if (log.isTraceEnabled())
log.trace("returning '" + operationType + "' as column: " + columnName);
return operationType;
}
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, SQLTYPES[0]);
if (log.isTraceEnabled())
log.trace("binding null to parameter: " + index);
}
else {
final int typeCode = toInt((OperationType) value);
st.setInt(index, typeCode);
if (log.isTraceEnabled())
log.trace("binding '" + typeCode + "' to parameter: " + index);
}
}
public Class returnedClass() {
return OperationType.class;
}
public static int toInt(OperationType operationType) {
for (int i = 0; i < OPERATION_TYPES.length; i++)
if (OPERATION_TYPES[i].equals(operationType))
return i;
throw new IllegalArgumentException("unknown operation type: "
+ operationType);
}
public static OperationType fromInt(int code) {
if (code < 0 || code >= OPERATION_TYPES.length)
throw new IllegalArgumentException("unknown operation type code: " + code);
return OPERATION_TYPES[code];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -