@Override public int[] sqlTypes(Mapping mapping) throws MappingException { return underlyingType.sqlTypes( mapping ); }
public int[] sqlTypes(Mapping mapping) throws MappingException { return baseType.sqlTypes(mapping); }
@Override public int[] sqlTypes(Mapping mapping) throws MappingException { //Not called at runtime so doesn't matter if its slow :) int[] sqlTypes = new int[getColumnSpan( mapping )]; int n = 0; for ( int i = 0; i < propertySpan; i++ ) { int[] subtypes = propertyTypes[i].sqlTypes( mapping ); for ( int subtype : subtypes ) { sqlTypes[n++] = subtype; } } return sqlTypes; }
@Override public int[] sqlTypes(Mapping mapping) throws MappingException { return requireIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping ); }
public int[] sqlTypes(Mapping mapping) throws MappingException { return super.getIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping ); }
protected final int determineJdbcTypeCode(Type firstArgumentType, SessionFactoryImplementor factory) throws QueryException { try { final int[] jdbcTypeCodes = firstArgumentType.sqlTypes( factory ); if ( jdbcTypeCodes.length != 1 ) { throw new QueryException( "multiple-column type in avg()" ); } return jdbcTypeCodes[0]; } catch ( MappingException me ) { throw new QueryException( me ); } }
@Override public int[] sqlTypes(Mapping mapping) throws MappingException { int[] result = new int[getColumnSpan( mapping )]; int n = 0; for ( Type type : userType.getPropertyTypes() ) { for ( int sqlType : type.sqlTypes( mapping ) ) { result[n++] = sqlType; } } return result; }
protected final int determineJdbcTypeCode(Type type, Mapping mapping) throws QueryException { try { final int[] jdbcTypeCodes = type.sqlTypes( mapping ); if ( jdbcTypeCodes.length != 1 ) { throw new QueryException( "multiple-column type in sum()" ); } return jdbcTypeCodes[0]; } catch ( MappingException me ) { throw new QueryException( me ); } }
@Override public int[] getSqlTypes() { if ( mode == ParameterMode.REF_CURSOR ) { // we could use the Types#REF_CURSOR added in Java 8, but that would require requiring Java 8... throw new IllegalStateException( "REF_CURSOR parameters do not have a SQL/JDBC type" ); } return determineHibernateType().sqlTypes( procedureCall.getSession().getFactory() ); }
@Override public void setHibernateType(Type expectedType) { super.setHibernateType( expectedType ); if ( mode == ParameterMode.REF_CURSOR ) { sqlTypes = new int[] { Types.REF_CURSOR }; } else { if ( expectedType == null ) { throw new IllegalArgumentException( "Type cannot be null" ); } else { sqlTypes = expectedType.sqlTypes( procedureCall.getSession().getFactory() ); } } }
@Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { final String[] columns = criteriaQuery.findColumns( propertyName, criteria ); final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName ); final StringBuilder fragment = new StringBuilder(); if ( columns.length > 1 ) { fragment.append( '(' ); } final SessionFactoryImplementor factory = criteriaQuery.getFactory(); final int[] sqlTypes = type.sqlTypes( factory ); for ( int i = 0; i < columns.length; i++ ) { final boolean lower = ignoreCase && (sqlTypes[i] == Types.VARCHAR || sqlTypes[i] == Types.CHAR || sqlTypes[i] == Types.NVARCHAR || sqlTypes[i] == Types.NCHAR); if ( lower ) { fragment.append( factory.getDialect().getLowercaseFunction() ).append( '(' ); } fragment.append( columns[i] ); if ( lower ) { fragment.append( ')' ); } fragment.append( getOp() ).append( "?" ); if ( i < columns.length - 1 ) { fragment.append( " and " ); } } if ( columns.length > 1 ) { fragment.append( ')' ); } return fragment.toString(); }
@Override public String render(Type columnType, List args, SessionFactoryImplementor factory) throws QueryException { if ( args.size()!=2 ) { throw new QueryException( "cast() requires two arguments; found : " + args.size() ); } final String type = (String) args.get( 1 ); final int[] sqlTypeCodes = factory.getTypeResolver().heuristicType( type ).sqlTypes( factory ); if ( sqlTypeCodes.length!=1 ) { throw new QueryException("invalid Hibernate type for cast()"); } String sqlType = factory.getDialect().getCastTypeName( sqlTypeCodes[0] ); if ( sqlType == null ) { //TODO: never reached, since getExplicitHibernateTypeName() actually throws an exception! sqlType = type; } return "cast(" + args.get( 0 ) + " as " + sqlType + ')'; }
/** * Determine whether the two types are "assignment compatible". * * @param target The type defined in the into-clause. * @param source The type defined in the select clause. * * @return True if they are assignment compatible. */ private boolean areCompatible(Type target, Type source) { if ( target.equals( source ) ) { // if the types report logical equivalence, return true... return true; } // otherwise, doAfterTransactionCompletion a "deep equivalence" check... if ( !target.getReturnedClass().isAssignableFrom( source.getReturnedClass() ) ) { return false; } int[] targetDatatypes = target.sqlTypes( getSessionFactoryHelper().getFactory() ); int[] sourceDatatypes = source.sqlTypes( getSessionFactoryHelper().getFactory() ); if ( targetDatatypes.length != sourceDatatypes.length ) { return false; } for ( int i = 0; i < targetDatatypes.length; i++ ) { if ( !areSqlTypesCompatible( targetDatatypes[i], sourceDatatypes[i] ) ) { return false; } } return true; }
public int getSqlTypeCode(Mapping mapping) throws MappingException { org.hibernate.type.Type type = getValue().getType(); try { int sqlTypeCode = type.sqlTypes( mapping )[getTypeIndex()]; if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) { throw new MappingException( "SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() ); } return sqlTypeCode; } catch (Exception e) { throw new MappingException( "Could not determine type for column " + name + " of type " + type.getClass().getName() + ": " + e.getClass().getName(), e ); } }
final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName ); final SessionFactoryImplementor factory = criteriaQuery.getFactory(); final int[] sqlTypes = type.sqlTypes( factory );
public String getIdentitySelectString() { //TODO: cache this in an instvar return getFactory().getDialect().getIdentityColumnSupport() .getIdentitySelectString( getTableName( 0 ), getKeyColumns( 0 )[0], getIdentifierType().sqlTypes( getFactory() )[0] ); }
final int[] sqlTypes = hibernateType.sqlTypes( procedureCall.getSession().getFactory() );
case TIMESTAMP: { typeToUse = CalendarType.INSTANCE; sqlTypesToUse = typeToUse.sqlTypes( procedureCall.getSession().getFactory() ); break; sqlTypesToUse = typeToUse.sqlTypes( procedureCall.getSession().getFactory() ); break; sqlTypesToUse = typeToUse.sqlTypes( procedureCall.getSession().getFactory() ); break;
@Test @TestForIssue( jiraKey = "HHH-9599") public void basicTest() { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); try { Metadata metadata = new MetadataSources( ssr ).addAnnotatedClass( TestEntity.class ).buildMetadata(); ( (MetadataImpl) metadata ).validate(); final PersistentClass entityBinding = metadata.getEntityBinding( TestEntity.class.getName() ); if(metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect || metadata.getDatabase().getDialect() instanceof DB2Dialect){ // See issue HHH-10693 for PostgreSQL, HHH-12753 for DB2 assertEquals( Types.VARCHAR, entityBinding.getProperty( "name" ).getType().sqlTypes( metadata )[0] ); }else { assertEquals( Types.NVARCHAR, entityBinding.getProperty( "name" ).getType().sqlTypes( metadata )[0] ); } } finally { StandardServiceRegistryBuilder.destroy( ssr ); } }