⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scopestatetype.java

📁 jbpm-bpel-1.1.Beta3 JBoss jBPM Starters Kit  是一个综合包
💻 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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;

import org.jbpm.bpel.graph.exe.ScopeState;

/**
 * Maps a scope state to a Hibernate type.
 * @author Juan Cantu
 * @version $Revision: 1.3 $ $Date: 2006/09/27 03:53:02 $
 */
public class ScopeStateType implements UserType {

  private static final Log log = LogFactory.getLog(ElementType.class);
  private static final int[] SQL_TYPES = { Types.SMALLINT };

  public boolean equals(Object o1, Object o2) {
    return o1 == 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 SQL_TYPES;
  }

  public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
      throws HibernateException, SQLException {
    final String columnName = names[0];
    final Integer code = (Integer) Hibernate.INTEGER.nullSafeGet(rs, columnName);
    ScopeState scopeState = code != null ? ScopeState.fromInt(code.intValue())
        : null;
    if (log.isTraceEnabled())
      log.trace("returning '" + scopeState + "' as column: " + columnName);
    return scopeState;
  }

  public void nullSafeSet(PreparedStatement st, Object value, int index)
      throws HibernateException, SQLException {
    if (value != null) {
      final int code = ((ScopeState) value).toInt();
      st.setInt(index, code);
      if (log.isTraceEnabled())
        log.trace("binding '" + code + "' to parameter: " + index);
    }
    else {
      st.setNull(index, SQL_TYPES[0]);
      if (log.isTraceEnabled())
        log.trace("binding null to parameter: " + index);
    }
  }

  public Class returnedClass() {
    return ScopeState.class;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -