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

📄 splitlist.java

📁 检测CPU 内存的 检测CPU 内存的
💻 JAVA
字号:
package com.m2.usertype.hibernate;

import org.hibernate.*;
import org.hibernate.usertype.UserType;
import org.hibernate.HibernateException;
import java.sql.*;
import java.io.Serializable;
import java.util.*;
import org.apache.commons.lang.*;


public class SplitList implements UserType {

	// private List IDs;

	private static final String SPLITTER = ";";

	private static final int[] TYPES = new int[] { Types.VARCHAR };

	public SplitList() {
	}

	/**
	 * sqlTypes
	 *
	 * @return int[]
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	public int[] sqlTypes() {
		return TYPES;
	}

	/**
	 * returnedClass
	 *
	 * @return Class
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	public Class returnedClass() {
		return List.class;
	}

	/**
	 * equals
	 *
	 * @param object
	 *            Object
	 * @param object1
	 *            Object
	 * @return boolean
	 * @throws HibernateException
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	public boolean equals(Object object, Object object1) throws HibernateException {
		if (object == object1) {
			return true;
		}
		if (object != null && object1 != null) {
			List set0 = (List) object;
			List set1 = (List) object1;
			if (set0.size() != set1.size()) {
				return false;
			}
			Object[] s0 = set0.toArray();
			Object[] s1 = set1.toArray();
			if (s0.length != s1.length) {
				return false;
			}
			for (int i = 0; i < s0.length; i++) {
				Long id0 = (Long) s0[i];
				Long id1 = (Long) s1[i];
				if (!id0.equals(id1)) {
					return false;
				}
			}
			return true;
		}
		return false;
	}

	/**
	 * hashCode
	 *
	 * @param object
	 *            Object
	 * @return int
	 * @throws HibernateException
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	public int hashCode(Object object) throws HibernateException {
		List s = (List) object;
		return s.hashCode();
	}

	/**
	 * nullSafeGet
	 *
	 * @param resultSet
	 *            ResultSet
	 * @param stringArray
	 *            String[]
	 * @param object
	 *            Object
	 * @return Object
	 * @throws HibernateException
	 * @throws SQLException
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	public Object nullSafeGet(ResultSet resultSet, String[] stringArray, Object object) throws HibernateException,
			SQLException {
		String value = (String) Hibernate.STRING.nullSafeGet(resultSet, stringArray[0]);
		if (value != null) {
			return parse(value);
		} else {
			return new ArrayList();
		}
	}

	/**
	 * nullSafeSet
	 *
	 * @param preparedStatement
	 *            PreparedStatement
	 * @param object
	 *            Object
	 * @param _int
	 *            int
	 * @throws HibernateException
	 * @throws SQLException
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	public void nullSafeSet(PreparedStatement preparedStatement, Object object, int _int) throws HibernateException,
			SQLException {
		if (object != null) {
			String str = assemble((List) object);
			Hibernate.STRING.nullSafeSet(preparedStatement, str, _int);
		} else {
			Hibernate.STRING.nullSafeSet(preparedStatement, "", _int);
		}
	}

	/**
	 * deepCopy
	 *
	 * @param object
	 *            Object
	 * @return Object
	 * @throws HibernateException
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	@SuppressWarnings("unchecked")
	public Object deepCopy(Object object) throws HibernateException {
		List sourceSet = (List) object;
		List targetSet = new ArrayList();
		if (sourceSet != null) {
			targetSet.addAll(sourceSet);
		}
		return targetSet;
	}

	/**
	 * isMutable
	 *
	 * @return boolean
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	public boolean isMutable() {
		return false;
	}

	/**
	 * disassemble
	 *
	 * @param object
	 *            Object
	 * @return Serializable
	 * @throws HibernateException
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	public Serializable disassemble(Object object) throws HibernateException {
		return (Serializable) deepCopy(object);
	}

	/**
	 * assemble
	 *
	 * @param serializable
	 *            Serializable
	 * @param object
	 *            Object
	 * @return Object
	 * @throws HibernateException
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	public Object assemble(Serializable serializable, Object object) throws HibernateException {
		return deepCopy(serializable);
	}

	/**
	 * replace
	 *
	 * @param object
	 *            Object
	 * @param object1
	 *            Object
	 * @param object2
	 *            Object
	 * @return Object
	 * @throws HibernateException
	 * @todo Implement this org.hibernate.usertype.UserType method
	 */
	public Object replace(Object object, Object object1, Object object2) throws HibernateException {
		return object;
	}

	private String assemble(List set) {
		StringBuffer sb = new StringBuffer();
		Iterator it = set.iterator();
		while (it.hasNext()) {
			sb.append(it.next());
			sb.append(SPLITTER);
		}
		String fs = sb.toString();
		if (fs != null && fs.length() > 0 && fs.endsWith(SPLITTER)) {
			fs = fs.substring(0, fs.length() - 1);
		}
		return fs;
	}

	@SuppressWarnings("unchecked")
	private List parse(String value) {
		String[] strs = StringUtils.split(value, SPLITTER);
		List set = new ArrayList();
		for (int i = 0; i < strs.length; i++) {
			if (!StringUtils.isBlank(strs[i])) {
				set.add(Long.valueOf(strs[i]));
				// System.out.println(strs[i]);
				// set.add(new Long(Long.parseLong(strs[i])));
			}
		}
		return set;
	}

}

⌨️ 快捷键说明

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