2323import org .jboss .logging .Logger ;
2424
2525/**
26- * Basically a map from SQL type code (int) -> {@link DdlType}
26+ * A registry mapping {@link org.hibernate.type.SqlTypes JDBC type codes}
27+ * to instances of the {@link DdlType} interface.
2728 *
2829 * @author Christian Beikov
2930 *
@@ -42,10 +43,17 @@ public DdlTypeRegistry(TypeConfiguration typeConfiguration) {
4243 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4344 // baseline descriptors
4445
46+ /**
47+ * Add a mapping from the {@linkplain DdlType#getSqlTypeCode() type code}
48+ * of the given {@link DdlType} to the given {@code DdlType}.
49+ */
4550 public void addDescriptor (DdlType ddlType ) {
4651 addDescriptor ( ddlType .getSqlTypeCode (), ddlType );
4752 }
4853
54+ /**
55+ * Add a mapping from the given type code to the given {@link DdlType}.
56+ */
4957 public void addDescriptor (int sqlTypeCode , DdlType ddlType ) {
5058 final DdlType previous = ddlTypes .put ( sqlTypeCode , ddlType );
5159 if ( previous != null && previous != ddlType ) {
@@ -57,16 +65,29 @@ public void addDescriptor(int sqlTypeCode, DdlType ddlType) {
5765 addSqlType ( ddlType , sqlTypeCode );
5866 }
5967
68+ /**
69+ * Add a mapping from the {@linkplain DdlType#getSqlTypeCode() type code}
70+ * of the given {@link DdlType} to the given {@code DdlType}, if there
71+ * is no mapping already present for that type code.
72+ */
6073 public void addDescriptorIfAbsent (DdlType ddlType ) {
6174 addDescriptorIfAbsent ( ddlType .getSqlTypeCode (), ddlType );
6275 }
6376
77+ /**
78+ * Add a mapping from the given type code to the given {@link DdlType},
79+ * if there is no mapping already present for the given type code.
80+ */
6481 public void addDescriptorIfAbsent (int sqlTypeCode , DdlType ddlType ) {
6582 if ( ddlTypes .putIfAbsent ( sqlTypeCode , ddlType ) == null ) {
6683 addSqlType ( ddlType , sqlTypeCode );
6784 }
6885 }
6986
87+ /**
88+ * Add a mapping from the given type code to the raw type name of the
89+ * given {@link DdlType}.
90+ */
7091 private void addSqlType (DdlType ddlType , int sqlTypeCode ) {
7192 for ( String rawTypeName : ddlType .getRawTypeNames () ) {
7293 final Integer previousSqlTypeCode = sqlTypes .put ( rawTypeName , sqlTypeCode );
@@ -78,7 +99,8 @@ private void addSqlType(DdlType ddlType, int sqlTypeCode) {
7899 }
79100
80101 /**
81- * Returns the {@link SqlTypes} type code for the given DDL raw type name, or <code>null</code> if it is unknown.
102+ * Returns the {@link SqlTypes} type code for the given DDL raw type name, or
103+ * {@code null} if the type code cannot be determined from the registrations.
82104 */
83105 public Integer getSqlTypeCode (String rawTypeName ) {
84106 return sqlTypes .get ( rawTypeName );
@@ -87,11 +109,11 @@ public Integer getSqlTypeCode(String rawTypeName) {
87109 /**
88110 * Returns the registered {@link DdlType} for the given SQL type code.
89111 * <p>
90- * Not that the "long" types {@link Types#LONGVARCHAR}, {@link Types#LONGNVARCHAR}
91- * and {@link Types#LONGVARBINARY} are considered synonyms for their
92- * non-{@code LONG} counterparts, with the only difference being that
93- * a different default length is used : {@link org.hibernate.Length#LONG}
94- * instead of {@link org.hibernate.Length#DEFAULT}.
112+ * Note that the "long" types {@link Types#LONGVARCHAR}, {@link Types#LONGNVARCHAR},
113+ * and {@link Types#LONGVARBINARY} are considered synonyms for their non-{@code LONG}
114+ * counterparts, with the only difference being that a different default length is
115+ * used by default: {@link org.hibernate.Length#LONG} instead of
116+ * {@link org.hibernate.Length#DEFAULT}.
95117 *
96118 */
97119 public DdlType getDescriptor (int sqlTypeCode ) {
@@ -113,6 +135,15 @@ public DdlType getDescriptor(int sqlTypeCode) {
113135 return ddlType ;
114136 }
115137
138+ /**
139+ * Get the SQL type name for the specified {@link java.sql.Types JDBC type code},
140+ * filling in the placemarkers {@code $l}, {@code $p}, and {@code $s}
141+ * with the default length, precision, and scale for the given SQL dialect.
142+ *
143+ * @param typeCode the JDBC type code
144+ * @param dialect the dialect which determines the default length, precision, and scale
145+ * @return a SQL column type
146+ */
116147 public String getTypeName (int typeCode , Dialect dialect ) {
117148 // explicitly enforce dialect's default precisions
118149 switch ( typeCode ) {
@@ -133,22 +164,36 @@ public String getTypeName(int typeCode, Dialect dialect) {
133164 }
134165 }
135166
167+ /**
168+ * Get the SQL type name for the specified {@link java.sql.Types JDBC type code}
169+ * and size, filling in the placemarkers {@code $l}, {@code $p}, and {@code $s}
170+ * with the length, precision, and scale determined by the given {@linkplain Size
171+ * size object}. The returned type name should be of a SQL type large enough to
172+ * accommodate values of the specified size.
173+ *
174+ * @param typeCode the JDBC type code
175+ * @param size an object which determines the length, precision, and scale
176+ *
177+ * @return the associated type name with the smallest capacity that accommodates
178+ * the given size, if available, and the default type name otherwise
179+ */
136180 public String getTypeName (int typeCode , Size size ) {
137181 return getTypeName ( typeCode , size .getLength (), size .getPrecision (), size .getScale () );
138182 }
139183
140184 /**
141185 * Get the SQL type name for the specified {@link java.sql.Types JDBC type code}
142186 * and size, filling in the placemarkers {@code $l}, {@code $p}, and {@code $s}
143- * with the given length, precision, and scale.
187+ * with the given length, precision, and scale. The returned type name should be
188+ * of a SQL type large enough to accommodate values of the specified size.
144189 *
145190 * @param typeCode the JDBC type code
146191 * @param size the SQL length, if any
147192 * @param precision the SQL precision, if any
148193 * @param scale the SQL scale, if any
149194 *
150- * @return the associated name with smallest capacity >= size, if available and
151- * the default type name otherwise
195+ * @return the associated type name with the smallest capacity that accommodates
196+ * the given size, if available, and the default type name otherwise
152197 */
153198 public String getTypeName (int typeCode , Long size , Integer precision , Integer scale ) {
154199 final DdlType descriptor = getDescriptor ( typeCode );
@@ -165,12 +210,13 @@ public String getTypeName(int typeCode, Long size, Integer precision, Integer sc
165210 }
166211
167212 /**
168- * Whether or not the given type name has been registered for this dialect (including both hibernate type names and
169- * custom-registered type names).
213+ * Determines if there is a registered {@link DdlType} whose {@linkplain
214+ * DdlType#getRawTypeName() raw type name} matches the given type name,
215+ * taking into account DDL types registered by Hibernate.
170216 *
171217 * @param typeName the type name.
172218 *
173- * @return true if the given string has been registered either as a hibernate type or as a custom-registered one
219+ * @return {@code true} if there is a DDL type with the given raw type name
174220 */
175221 public boolean isTypeNameRegistered (final String typeName ) {
176222 for ( DdlType value : ddlTypes .values () ) {
0 commit comments