001 /* 002 * JBoss DNA (http://www.jboss.org/dna) 003 * See the COPYRIGHT.txt file distributed with this work for information 004 * regarding copyright ownership. Some portions may be licensed 005 * to Red Hat, Inc. under one or more contributor license agreements. 006 * See the AUTHORS.txt file in the distribution for a full listing of 007 * individual contributors. 008 * 009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA 010 * is licensed to you under the terms of the GNU Lesser General Public License as 011 * published by the Free Software Foundation; either version 2.1 of 012 * the License, or (at your option) any later version. 013 * 014 * JBoss DNA is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 017 * Lesser General Public License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this software; if not, write to the Free 021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 023 */ 024 package org.jboss.dna.common.jdbc.model.spi; 025 026 import java.util.Set; 027 import java.util.HashSet; 028 import org.jboss.dna.common.jdbc.model.api.Attribute; 029 import org.jboss.dna.common.jdbc.model.api.UserDefinedType; 030 import org.jboss.dna.common.jdbc.model.api.SqlType; 031 032 /** 033 * Provides User Defined Type (UDT) specific metadata. Retrieves a description of the user-defined types (UDTs) defined in a 034 * particular schema. Schema-specific UDTs may have type JAVA_OBJECT, STRUCT, or DISTINCT. 035 * 036 * @author <a href="mailto:litsenko_sergey@yahoo.com">Sergiy Litsenko</a> 037 * @since 1.2 (JDBC 2.0) 038 */ 039 public class UserDefinedTypeBean extends SchemaObjectBean implements UserDefinedType { 040 private static final long serialVersionUID = -7493272131759308580L; 041 private Set<Attribute> columns = new HashSet<Attribute>(); 042 private String className; 043 private SqlType sqlType; 044 private SqlType baseType; 045 private UserDefinedType superType; 046 047 /** 048 * Default constructor 049 */ 050 public UserDefinedTypeBean() { 051 } 052 053 /** 054 * Returns JAVA class name for UDT 055 * 056 * @return JAVA class name for UDT 057 */ 058 public String getClassName() { 059 return className; 060 } 061 062 /** 063 * Sets JAVA class name for UDT 064 * 065 * @param className JAVA class name for UDT 066 */ 067 public void setClassName( String className ) { 068 this.className = className; 069 } 070 071 /** 072 * Gets SQL type from java.sql.Types. One of JAVA_OBJECT, STRUCT, or DISTINCT 073 * 074 * @return SQL type from java.sql.Types. One of JAVA_OBJECT, STRUCT, or DISTINCT 075 */ 076 public SqlType getSqlType() { 077 return sqlType; 078 } 079 080 /** 081 * Sets SQL type from java.sql.Types. One of JAVA_OBJECT, STRUCT, or DISTINCT 082 * 083 * @param sqlType the SQL type from java.sql.Types. One of JAVA_OBJECT, STRUCT, or DISTINCT 084 */ 085 public void setSqlType( SqlType sqlType ) { 086 this.sqlType = sqlType; 087 } 088 089 /** 090 * Gets SQL base type from java.sql.Types. Type code of the source type of a DISTINCT type or the type that implements the 091 * user-generated reference type of the SELF_REFERENCING_COLUMN of a structured type as defined in java.sql.Types (null if 092 * DATA_TYPE is not DISTINCT or not STRUCT with REFERENCE_GENERATION = USER_DEFINED) 093 * 094 * @return SQL base type from java.sql.Types. 095 */ 096 public SqlType getBaseType() { 097 return baseType; 098 } 099 100 /** 101 * Sets SQL base type from java.sql.Types. Type code of the source type of a DISTINCT type or the type that implements the 102 * user-generated reference type of the SELF_REFERENCING_COLUMN of a structured type as defined in java.sql.Types (null if 103 * DATA_TYPE is not DISTINCT or not STRUCT with REFERENCE_GENERATION = USER_DEFINED) 104 * 105 * @param baseType the SQL base type from java.sql.Types. 106 */ 107 public void setBaseType( SqlType baseType ) { 108 this.baseType = baseType; 109 } 110 111 /** 112 * Gets a set of UDT attributes 113 * 114 * @return a set of UDT attributes 115 */ 116 public Set<Attribute> getAttributes() { 117 return columns; 118 } 119 120 /** 121 * adds Attribute 122 * 123 * @param attribute the Attribute 124 */ 125 public void addAttribute( Attribute attribute ) { 126 columns.add(attribute); 127 } 128 129 /** 130 * deletes Attribute 131 * 132 * @param attribute the Attribute 133 */ 134 public void deleteAttribute( Attribute attribute ) { 135 columns.remove(attribute); 136 } 137 138 /** 139 * Returns UDT attribute for specified attribute name or null 140 * 141 * @param attributeName the name of attribute 142 * @return UDT attribute for specified attribute name or null. 143 */ 144 public Attribute findAttributeByName( String attributeName ) { 145 for (Attribute a : columns) { 146 if (a.getName().equals(attributeName)) { 147 return a; 148 } 149 } 150 // return nothing 151 return null; 152 } 153 154 // =============================================================== 155 // ------------------- JDBC 3.0 --------------------------------- 156 // =============================================================== 157 158 /** 159 * Retrieves a description of the user-defined type (UDT) hierarchies defined in a particular schema in this database. Only 160 * the immediate super type/ sub type relationship is modeled. 161 * 162 * @return super type for this UDT if any 163 * @since 1.4 (JDBC 3.0) 164 */ 165 public UserDefinedType getSuperType() { 166 return superType; 167 } 168 169 /** 170 * Sets a description of the user-defined type (UDT) hierarchies defined in a particular schema in this database. Only the 171 * immediate super type/ sub type relationship is modeled. 172 * 173 * @param superType the super type for this UDT if any 174 * @since 1.4 (JDBC 3.0) 175 */ 176 public void setSuperType( UserDefinedType superType ) { 177 this.superType = superType; 178 } 179 }