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

📄 qnametype.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 javax.xml.namespace.QName;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;

/**
 * @author Juan Cantu
 * @version $Revision: 1.4 $ $Date: 2007/01/09 07:05:39 $
 */
public class QNameType implements UserType {

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

  public int[] sqlTypes() {
    return SQL_TYPES;
  }

  public boolean equals(Object x, Object y) throws HibernateException {
    return x == null ? y == null : x.equals(y);
  }

  public int hashCode(Object x) throws HibernateException {
    return x.hashCode();
  }

  public Object deepCopy(Object value) throws HibernateException {
    return value;
  }

  public boolean isMutable() {
    return false;
  }

  public Serializable disassemble(Object value) throws HibernateException {
    return (Serializable) value;
  }

  public Object assemble(Serializable cached, Object owner)
      throws HibernateException {
    return cached;
  }

  public Object replace(Object original, Object target, Object owner)
      throws HibernateException {
    return target;
  }

  public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
      throws HibernateException, SQLException {
    // BPEL-221: QNameType persists namespace property in LOCALNAME_ column
    final String localPartColumn = names[0];
    final String localPart = rs.getString(localPartColumn);

    final String namespaceColumn = names[1];
    final String namespace = rs.getString(namespaceColumn);

    final QName qname = namespace != null && localPart != null ? new QName(
        namespace, localPart) : null;

    if (log.isTraceEnabled()) {
      log.trace("returning '"
          + qname
          + "' as columns: "
          + localPartColumn
          + ", "
          + namespaceColumn);
    }
    return qname;
  }

  public void nullSafeSet(PreparedStatement st, Object value, int localPartIndex)
      throws HibernateException, SQLException {
    final int namespaceIndex = localPartIndex + 1;

    if (value == null) {
      st.setNull(localPartIndex, SQL_TYPES[0]);
      st.setNull(namespaceIndex, SQL_TYPES[1]);

      if (log.isTraceEnabled()) {
        log.trace("binding null to parameter: " + localPartIndex);
        log.trace("binding null to parameter: " + namespaceIndex);
      }
    }
    else {
      final QName qname = (QName) value;

      // BPEL-221: QNameType persists namespace property in LOCALNAME_ column
      final String localPart = qname.getLocalPart();
      st.setString(localPartIndex, localPart);

      final String namespaceURI = qname.getNamespaceURI();
      st.setString(namespaceIndex, namespaceURI);

      if (log.isTraceEnabled()) {
        log.trace("binding '" + localPart + "' to parameter: " + localPartIndex);
        log.trace("binding '"
            + namespaceURI
            + "' to parameter: "
            + namespaceIndex);
      }
    }
  }

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

⌨️ 快捷键说明

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