/** * See {@link #heuristicType(String, Properties)} * * @param typeName The name (see heuristic algorithm discussion on {@link #heuristicType(String, Properties)}). * * @return The deduced type; may be null. * * @throws MappingException Can be thrown from {@link #heuristicType(String, Properties)} */ public Type heuristicType(String typeName) throws MappingException { return heuristicType( typeName, null ); }
@Override public Type heuristicType(String name) { return typeResolver.heuristicType( name ); }
private String quoteIdentifier(Object value, Type type) { Type resolvedType = ( !type.getReturnedClass().equals( value.getClass() ) ) ? typeResolver.heuristicType( value.getClass().getName() ) : type; if ( resolvedType instanceof LiteralType ) { LiteralType literalType = (LiteralType) resolvedType; try { return literalType.objectToSQLString( value, dialect ); } catch ( Exception e ) { throw new IllegalArgumentException( e ); } } return String.valueOf( value ); } }
public String getCastType(Class javaType) { SessionFactoryImplementor factory = entityManager.getFactory(); Type hibernateType = factory.getTypeResolver().heuristicType( javaType.getName() ); if ( hibernateType == null ) { throw new IllegalArgumentException( "Could not convert java type [" + javaType.getName() + "] to Hibernate type" ); } return hibernateType.getName(); }
@Override public void setText(String s) { // for some reason the antlr.CommonAST initialization routines force // this method to get called twice. The first time with an empty string if ( StringHelper.isNotEmpty( s ) ) { constantExpression = s; constantValue = ReflectHelper.getConstantValue( s, factory ); heuristicType = factory.getTypeResolver().heuristicType( constantValue.getClass().getName() ); super.setText( s ); } }
@SuppressWarnings("UnnecessaryUnboxing") public ParameterMemento toMemento(SessionFactoryImpl sessionFactory) { final boolean initialPassNullSetting = explicitPassNullSetting != null ? explicitPassNullSetting.booleanValue() : sessionFactory.getSessionFactoryOptions().isProcedureParameterNullPassingEnabled(); return new ParameterMemento( position, name, parameterMode, type, sessionFactory.getTypeResolver().heuristicType( type.getName() ), initialPassNullSetting ); } }
public Type findFunctionReturnType(String functionName, SQLFunction sqlFunction, AST firstArgument) { // determine the type of the first argument... Type argumentType = null; if ( firstArgument != null ) { if ( "cast".equals( functionName ) ) { argumentType = sfi.getTypeResolver().heuristicType( firstArgument.getNextSibling().getText() ); } else if ( SqlNode.class.isInstance( firstArgument ) ) { argumentType = ( (SqlNode) firstArgument ).getDataType(); } } return sqlFunction.getReturnType( argumentType, sfi ); }
@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 + ')'; }
@Override public void setBindValue(T value) { internalSetValue( value ); if ( value != null && hibernateType == null ) { hibernateType = procedureParamBindings.getProcedureCall() .getSession() .getFactory() .getTypeResolver() .heuristicType( value.getClass().getName() ); log.debugf( "Using heuristic type [%s] based on bind value [%s] as `bindType`", hibernateType, value ); } }
@Override @SuppressWarnings("unchecked") public <T> ParameterRegistration<T> registerParameter(String name, Class<T> type, ParameterMode mode) { final ProcedureParameterImpl parameter = new ProcedureParameterImpl( this, name, mode, type, getSession().getFactory().getTypeResolver().heuristicType( type.getName() ), globalParameterPassNullsSetting ); registerParameter( parameter ); return parameter; }
@Override @SuppressWarnings("unchecked") public <T> ParameterRegistration<T> registerParameter(int position, Class<T> type, ParameterMode mode) { final ProcedureParameterImpl procedureParameter = new ProcedureParameterImpl( this, position, mode, type, getSession().getFactory().getTypeResolver().heuristicType( type.getName() ), globalParameterPassNullsSetting ); registerParameter( procedureParameter ); return procedureParameter; }
final Type mappingType = sfi.getTypeResolver().heuristicType( parameterExpression.getParameterType().getName() ); buffer.append( "cast(" ) .append( parameterExpression.render( renderingContext ) )
Type result = getMetadata().getTypeConfiguration().getTypeResolver().heuristicType( typeName, typeParameters );
@Override public Type resolveParameterBindType(Class clazz){ String typename = clazz.getName(); Type type = getTypeResolver().heuristicType( typename ); boolean serializable = type != null && type instanceof SerializableType; if ( type == null || serializable ) { try { getMetamodel().entityPersister( clazz.getName() ); } catch (MappingException me) { if ( serializable ) { return type; } else { throw new HibernateException( "Could not determine a type for class: " + typename ); } } return getTypeHelper().entity( clazz ); } else { return type; } }
private Type determineHibernateType() { final ParameterBind<T> bind = getBind(); // if the bind defines a type, that should be the most specific... final Type bindType = bind.getBindType(); if ( bindType != null ) { return bindType; } // Next, see if the parameter itself has an expected type, and if so use that... final Type paramType = getHibernateType(); if ( paramType != null ) { return paramType; } // here we just have guessing games if ( bind.getValue() != null ) { return procedureCall.getSession() .getFactory() .getTypeResolver() .heuristicType( bind.getValue().getClass().getName() ); } throw new IllegalStateException( "Unable to determine SQL type(s) - Hibernate Type not known" ); }
public Type getType() throws MappingException { final Type metaType = getMetadata().getTypeResolver().heuristicType( metaTypeName ); return getMetadata().getTypeResolver().getTypeFactory().any( metaValues == null ? metaType : new MetaType( metaValues, metaType ), getMetadata().getTypeResolver().heuristicType( identifierTypeName ), isLazy() ); }
return factory.getTypeResolver().heuristicType( hibernateTypeName );
public static NativeSQLQueryScalarReturn extractReturnDescription( JaxbHbmNativeQueryScalarReturnType rtnSource, HbmLocalMetadataBuildingContext context) { final String column = rtnSource.getColumn(); final String typeName = rtnSource.getType(); Type type = null; if ( typeName != null ) { type = context.getMetadataCollector().getTypeResolver().heuristicType( typeName ); if ( type == null ) { throw new MappingException( String.format( "Unable to resolve type [%s] specified for native query scalar return", typeName ), context.getOrigin() ); } } return new NativeSQLQueryScalarReturn( column, type ); }
private static void bindFilterDef(FilterDef defAnn, MetadataBuildingContext context) { Map<String, org.hibernate.type.Type> params = new HashMap<>(); for ( ParamDef param : defAnn.parameters() ) { params.put( param.name(), context.getMetadataCollector().getTypeResolver().heuristicType( param.type() ) ); } FilterDefinition def = new FilterDefinition( defAnn.name(), defAnn.defaultCondition(), params ); LOG.debugf( "Binding filter definition: %s", def.getFilterName() ); context.getMetadataCollector().addFilterDefinition( def ); }
type = walker.getSessionFactoryHelper().getFactory().getTypeResolver().heuristicType( value.getClass().getName() );