private static void bindFilterDef(FilterDef defAnn, ExtendedMappings mappings) { Map<String, org.hibernate.type.Type> params = new HashMap<String, org.hibernate.type.Type>(); for ( ParamDef param : defAnn.parameters() ) { params.put( param.name(), TypeFactory.heuristicType( param.type() ) ); } FilterDefinition def = new FilterDefinition( defAnn.name(), defAnn.defaultCondition(), params ); log.info( "Binding filter definition: {}", def.getFilterName() ); mappings.addFilterDefinition( def ); }
/** * Uses heuristics to deduce a Hibernate type given a string naming the type or Java class. * Return an instance of <tt>org.hibernate.type.Type</tt>. */ public static Type heuristicType(String typeName) throws MappingException { return heuristicType( typeName, null ); }
public Type getType() throws MappingException { return new AnyType( metaValues==null ? TypeFactory.heuristicType(metaTypeName) : new MetaType( metaValues, TypeFactory.heuristicType(metaTypeName) ), TypeFactory.heuristicType(identifierTypeName) ); }
public Type getType() throws MappingException { return new AnyType( metaValues==null ? TypeFactory.heuristicType(metaTypeName) : new MetaType( metaValues, TypeFactory.heuristicType(metaTypeName) ), TypeFactory.heuristicType(identifierTypeName) ); }
org.hibernate.type.Type metaType = TypeFactory.heuristicType( value.getMetaType() ); for (MetaValue metaValue : metaAnnDef.metaValues()) { try {
public Type getType() throws MappingException { if (typeName==null) { throw new MappingException("No type name"); } Type result = TypeFactory.heuristicType(typeName, typeParameters); if (result==null) { String msg = "Could not determine type for: " + typeName; if(columns!=null && columns.size()>0) { msg += ", for columns: " + columns; } throw new MappingException(msg); } return result; }
public Type getType() throws MappingException { if (typeName==null) { throw new MappingException("No type name"); } Type result = TypeFactory.heuristicType(typeName, typeParameters); if (result==null) { String msg = "Could not determine type for: " + typeName; if(columns!=null && columns.size()>0) { msg += ", for columns: " + columns; } throw new MappingException(msg); } return result; }
private static void parseFilterDef(Element element, Mappings mappings) { String name = element.attributeValue( "name" ); log.debug( "Parsing filter-def [" + name + "]" ); FilterDefinition def = new FilterDefinition( name ); Iterator params = element.elementIterator( "filter-param" ); while ( params.hasNext() ) { final Element param = (Element) params.next(); final String paramName = param.attributeValue( "name" ); final String paramType = param.attributeValue( "type" ); log.debug( "adding filter parameter : " + paramName + " -> " + paramType ); final Type heuristicType = TypeFactory.heuristicType( paramType ); log.debug( "parameter heuristic type : " + heuristicType ); def.addParameterType( paramName, heuristicType ); } String condition = element.getTextTrim(); if ( StringHelper.isEmpty(condition) ) condition = element.attributeValue( "condition" ); def.setDefaultFilterCondition(condition); log.debug( "Parsed filter-def [" + name + "]" ); mappings.addFilterDefinition( def ); }
public String render(List args, SessionFactoryImplementor factory) throws QueryException { if ( args.size()!=2 ) { throw new QueryException("cast() requires two arguments"); } String type = (String) args.get(1); int[] sqlTypeCodes = TypeFactory.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 getTypeName() actually throws an exception! sqlType = type; } /*else { //trim off the length/precision/scale int loc = sqlType.indexOf('('); if (loc>-1) { sqlType = sqlType.substring(0, loc); } }*/ return "cast(" + args.get(0) + " as " + sqlType + ')'; }
private Type guessType(Class clazz) throws HibernateException { String typename = clazz.getName(); Type type = TypeFactory.heuristicType(typename); boolean serializable = type!=null && type instanceof SerializableType; if (type==null || serializable) { try { session.getFactory().getEntityPersister( clazz.getName() ); } catch (MappingException me) { if (serializable) { return type; } else { throw new HibernateException("Could not determine a type for class: " + typename); } } return Hibernate.entity(clazz); } else { return type; } }
public String render(List args, SessionFactoryImplementor factory) throws QueryException { if ( args.size()!=2 ) { throw new QueryException("cast() requires two arguments"); } String type = (String) args.get(1); int[] sqlTypeCodes = TypeFactory.heuristicType(type).sqlTypes(factory); if ( sqlTypeCodes.length!=1 ) { throw new QueryException("invalid Hibernate type for cast()"); } String sqlType = factory.getDialect().getTypeName( sqlTypeCodes[0], Column.DEFAULT_LENGTH, Column.DEFAULT_PRECISION, Column.DEFAULT_SCALE ); if (sqlType==null) { //TODO: never reached, since getTypeName() actually throws an exception! sqlType = type; } /*else { //trim off the length/precision/scale int loc = sqlType.indexOf('('); if (loc>-1) { sqlType = sqlType.substring(0, loc); } }*/ return "cast(" + args.get(0) + " as " + sqlType + ')'; }
/** * Uses heuristics to deduce a Hibernate type given a string naming the type or Java class. * Return an instance of <tt>org.hibernate.type.Type</tt>. */ public static Type heuristicType(String typeName, Properties parameters) throws MappingException { Type type = TypeFactory.basic( typeName ); if ( type == null ) { Class typeClass; try { typeClass = ReflectHelper.classForName( typeName ); } catch (ClassNotFoundException cnfe) { typeClass = null; } if ( typeClass != null ) { if ( Type.class.isAssignableFrom( typeClass ) ) { try { type = (Type) typeClass.newInstance(); } catch (Exception e) { throw new MappingException( "Could not instantiate Type: " + typeClass.getName(), e ); } injectParameters(type, parameters); } else if ( CompositeUserType.class.isAssignableFrom( typeClass ) ) { type = new CompositeCustomType( typeClass, parameters );
Type type = null; if(typeFromXML!=null) { type = TypeFactory.heuristicType( typeFromXML ); if ( type == null ) { throw new MappingException( "could not determine type " + type );
/** * Find the function return type given the function name and the first argument expression node. * * @param functionName The function name. * @param first The first argument expression. * @return the function return type given the function name and the first argument expression node. */ public Type findFunctionReturnType(String functionName, AST first) { // locate the registered function by the given name SQLFunction sqlFunction = requireSQLFunction( functionName ); // determine the type of the first argument... Type argumentType = null; if ( first != null ) { if ( "cast".equals(functionName) ) { argumentType = TypeFactory.heuristicType( first.getNextSibling().getText() ); } else if ( first instanceof SqlNode ) { argumentType = ( (SqlNode) first ).getDataType(); } } return sqlFunction.getReturnType( argumentType, sfi ); }
private static void bindFilterDef(FilterDef defAnn, ExtendedMappings mappings) { Map<String, org.hibernate.type.Type> params = new HashMap<String, org.hibernate.type.Type>(); for ( ParamDef param : defAnn.parameters() ) { params.put( param.name(), TypeFactory.heuristicType( param.type() ) ); } FilterDefinition def = new FilterDefinition( defAnn.name(), defAnn.defaultCondition(), params ); if ( log.isInfoEnabled() ) log.info( "Binding filter definition: " + def.getFilterName() ); mappings.addFilterDefinition( def ); }
if ( iter.hasNext() ) { HashMap values = new HashMap(); org.hibernate.type.Type metaType = TypeFactory.heuristicType( any.getMetaType() ); while ( iter.hasNext() ) { Element metaValue = (Element) iter.next();
Type type; try { type = TypeFactory.heuristicType( constant.getClass().getName() );
type = TypeFactory.heuristicType( value.getClass().getName() );
type = TypeFactory.heuristicType( value.getClass().getName() );
private void bindProperty(final NakedObjectField field, final Element classElement, final boolean valueFieldAccess) { LOG.debug("Binding persistent property [" + field.getId() + "]"); final Element property = classElement.addElement("property"); setType(field, property, "type", true, valueFieldAccess); final Attribute access = property.attribute("access"); final boolean fieldAccess = access != null && access.getStringValue().equals("field"); property.addAttribute("name", getPropertyName(field, fieldAccess)); final org.hibernate.type.Type type = TypeFactory.heuristicType(property.attribute("type").getValue(), null); if (type instanceof CompositeCustomType) { final String[] names = ((CompositeCustomType) type).getPropertyNames(); for (int i = 0; i < names.length; i++) { final String compositeColumnName = deconflictColumnName(columnName(field.getId()) + "_" + names[i]); property.addElement("column").addAttribute("name", compositeColumnName); } } else { addColumnAttribute(property, columnName(field.getId())); } }