001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/api/src/java/org/theospi/portfolio/worksite/mgt/impl/ToolConfigurationUserType.java $
003: * $Id:ToolConfigurationUserType.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.worksite.mgt.impl;
021:
022: import java.io.Serializable;
023: import java.sql.PreparedStatement;
024: import java.sql.ResultSet;
025: import java.sql.SQLException;
026: import java.sql.Types;
027:
028: import org.hibernate.HibernateException;
029: import org.hibernate.usertype.UserType;
030: import org.sakaiproject.component.cover.ComponentManager;
031: import org.sakaiproject.metaobj.worksite.mgt.WorksiteManager;
032: import org.sakaiproject.site.api.ToolConfiguration;
033: import org.theospi.portfolio.worksite.model.ToolConfigurationWrapper;
034:
035: public class ToolConfigurationUserType implements UserType,
036: Serializable {
037: private static final int ID_COLUMN = 0;
038:
039: public int[] sqlTypes() {
040: return new int[] { Types.VARCHAR };
041: }
042:
043: public Class returnedClass() {
044: return ToolConfiguration.class;
045: }
046:
047: public boolean equals(Object x, Object y) throws HibernateException {
048: return (x == y) || (x != null && y != null && x.equals(y));
049: }
050:
051: public Object nullSafeGet(ResultSet resultSet, String[] columns,
052: Object o) throws HibernateException, SQLException {
053: String idValue = resultSet.getString(columns[ID_COLUMN]);
054: if (resultSet.wasNull()) {
055: return null;
056: }
057: ToolConfiguration tool = getWorksiteManager().getTool(idValue);
058: if (tool == null)
059: return null;
060: return new ToolConfigurationWrapper(tool);
061: }
062:
063: public void nullSafeSet(PreparedStatement preparedStatement,
064: Object value, int index) throws HibernateException,
065: SQLException {
066: ToolConfiguration toolConfiguration = (ToolConfiguration) value;
067: if (toolConfiguration == null
068: || toolConfiguration.getId() == null) {
069: preparedStatement.setNull(index, Types.VARCHAR);
070: } else {
071: preparedStatement.setString(index, toolConfiguration
072: .getId());
073: }
074: }
075:
076: public Object deepCopy(Object o) throws HibernateException {
077: return o;
078: }
079:
080: public boolean isMutable() {
081: return false;
082: }
083:
084: protected WorksiteManager getWorksiteManager() {
085: return (WorksiteManager) ComponentManager.getInstance().get(
086: WorksiteManager.class.getName());
087: }
088:
089: public int hashCode(Object arg0) throws HibernateException {
090: // TODO Auto-generated method stub
091: return 0;
092: }
093:
094: public Serializable disassemble(Object arg0)
095: throws HibernateException {
096: // TODO Auto-generated method stub
097: return null;
098: }
099:
100: public Object assemble(Serializable arg0, Object arg1)
101: throws HibernateException {
102: // TODO Auto-generated method stub
103: return null;
104: }
105:
106: public Object replace(Object arg0, Object arg1, Object arg2)
107: throws HibernateException {
108: // TODO Auto-generated method stub
109: return null;
110: }
111: }
|