HHH-2614 Blob Length Set to 255 By Default With Derby DB

This commit is contained in:
Strong Liu 2011-07-11 16:54:17 +08:00
parent 310c0441bb
commit b413299847
7 changed files with 53 additions and 7 deletions

View File

@ -24,6 +24,7 @@
package org.hibernate.dialect;
import java.lang.reflect.Method;
import java.sql.Types;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.MappingException;
@ -57,7 +58,12 @@ public class DerbyDialect extends DB2Dialect {
LOG.deprecatedDerbyDialect();
registerFunction( "concat", new DerbyConcatFunction() );
registerFunction( "trim", new AnsiTrimFunction() );
determineDriverVersion();
registerColumnType( Types.BLOB, "blob" );
determineDriverVersion();
if ( driverVersionMajor > 10 || ( driverVersionMajor == 10 && driverVersionMinor >= 7 ) ) {
registerColumnType( Types.BOOLEAN, "boolean" );
}
}
@SuppressWarnings({ "UnnecessaryUnboxing" })

View File

@ -0,0 +1,35 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program 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. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.dialect;
import java.sql.Types;
/**
* @author Strong Liu
*/
public class DerbyTenSevenDialect extends DerbyTenSixDialect{
public DerbyTenSevenDialect() {
registerColumnType( Types.BOOLEAN, "boolean" );
}
}

View File

@ -90,8 +90,8 @@ public class TypeNames {
if ( map!=null && map.size()>0 ) {
// iterate entries ordered by capacity to find first fit
for (Map.Entry<Integer, String> entry: map.entrySet()) {
if ( size <= ( (Integer) entry.getKey() ).intValue() ) {
return replace( (String) entry.getValue(), size, precision, scale );
if ( size <= entry.getKey() ) {
return replace( entry.getValue(), size, precision, scale );
}
}
}

View File

@ -383,7 +383,7 @@ public class Table implements RelationalModel, Serializable {
}
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) {
StringBuffer buf = new StringBuffer( hasPrimaryKey() ? dialect.getCreateTableString() : dialect.getCreateMultisetTableString() )
StringBuilder buf = new StringBuilder( hasPrimaryKey() ? dialect.getCreateTableString() : dialect.getCreateMultisetTableString() )
.append( ' ' )
.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
.append( " (" );

View File

@ -418,7 +418,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
}
}
StringBuffer buf = new StringBuffer()
StringBuilder buf = new StringBuilder()
.append("( ");
Iterator siter = new JoinedIterator(

View File

@ -31,6 +31,7 @@ import org.jboss.logging.Logger;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.DerbyTenFiveDialect;
import org.hibernate.dialect.DerbyTenSevenDialect;
import org.hibernate.dialect.DerbyTenSixDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
@ -84,7 +85,10 @@ public class StandardDialectResolver extends AbstractDialectResolver {
if ( "Apache Derby".equals( databaseName ) ) {
final int databaseMinorVersion = metaData.getDatabaseMinorVersion();
if ( databaseMajorVersion > 10 || ( databaseMajorVersion == 10 && databaseMinorVersion >= 6 ) ) {
if ( databaseMajorVersion > 10 || ( databaseMajorVersion == 10 && databaseMinorVersion >= 7 ) ) {
return new DerbyTenSevenDialect();
}
else if ( databaseMajorVersion > 10 || ( databaseMajorVersion == 10 && databaseMinorVersion >= 6 ) ) {
return new DerbyTenSixDialect();
}
else if ( databaseMajorVersion == 10 && databaseMinorVersion == 5 ) {

View File

@ -39,6 +39,7 @@ import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.metamodel.relational.Size;
import org.hibernate.type.descriptor.WrapperOptions;
@ -82,7 +83,7 @@ public abstract class AbstractStandardBasicType<T>
}
public T fromXMLString(String xml, Mapping factory) throws HibernateException {
return xml == null || xml.length() == 0 ? null : fromStringValue( xml );
return StringHelper.isEmpty( xml ) ? null : fromStringValue( xml );
}
protected MutabilityPlan<T> getMutabilityPlan() {