/** * Constructs a SQLQueryImpl given a sql query defined in the mappings. * * @param queryDef The representation of the defined <sql-query/>. * @param session The session to which this SQLQueryImpl belongs. * @param parameterMetadata Metadata about parameters found in the query. */ SQLQueryImpl(NamedSQLQueryDefinition queryDef, SessionImplementor session, ParameterMetadata parameterMetadata) { super( queryDef.getQueryString(), queryDef.getFlushMode(), session, parameterMetadata ); if ( queryDef.getResultSetRef() != null ) { ResultSetMappingDefinition definition = session.getFactory() .getResultSetMapping( queryDef.getResultSetRef() ); if (definition == null) { throw new MappingException( "Unable to find resultset-ref definition: " + queryDef.getResultSetRef() ); } this.queryReturns = new ArrayList<NativeSQLQueryReturn>(Arrays.asList( definition.getQueryReturns() )); } else if ( queryDef.getQueryReturns() != null && queryDef.getQueryReturns().length > 0 ) { this.queryReturns = new ArrayList<NativeSQLQueryReturn>(Arrays.asList( queryDef.getQueryReturns())); } else { this.queryReturns = new ArrayList<NativeSQLQueryReturn>(); } this.querySpaces = queryDef.getQuerySpaces(); this.callable = queryDef.isCallable(); }
public NamedQueryRepository( Iterable<NamedQueryDefinition> namedQueryDefinitions, Iterable<NamedSQLQueryDefinition> namedSqlQueryDefinitions, Iterable<ResultSetMappingDefinition> namedSqlResultSetMappings, Map<String, ProcedureCallMemento> namedProcedureCalls) { final HashMap<String, NamedQueryDefinition> namedQueryDefinitionMap = new HashMap<String, NamedQueryDefinition>(); for ( NamedQueryDefinition namedQueryDefinition : namedQueryDefinitions ) { namedQueryDefinitionMap.put( namedQueryDefinition.getName(), namedQueryDefinition ); } this.namedQueryDefinitionMap = Collections.unmodifiableMap( namedQueryDefinitionMap ); final HashMap<String, NamedSQLQueryDefinition> namedSqlQueryDefinitionMap = new HashMap<String, NamedSQLQueryDefinition>(); for ( NamedSQLQueryDefinition namedSqlQueryDefinition : namedSqlQueryDefinitions ) { namedSqlQueryDefinitionMap.put( namedSqlQueryDefinition.getName(), namedSqlQueryDefinition ); } this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( namedSqlQueryDefinitionMap ); final HashMap<String, ResultSetMappingDefinition> namedSqlResultSetMappingMap = new HashMap<String, ResultSetMappingDefinition>(); for ( ResultSetMappingDefinition resultSetMappingDefinition : namedSqlResultSetMappings ) { namedSqlResultSetMappingMap.put( resultSetMappingDefinition.getName(), resultSetMappingDefinition ); } this.namedSqlResultSetMappingMap = Collections.unmodifiableMap( namedSqlResultSetMappingMap ); this.procedureCallMementoMap = Collections.unmodifiableMap( namedProcedureCalls ); }
/** * Resolve the given result set mapping names * * @param context The context for the resolution. See {@link ResultSetMappingResolutionContext} * @param resultSetMappingNames The names of the result-set-mappings to resolve */ public static void resolveResultSetMappings(ResultSetMappingResolutionContext context, String... resultSetMappingNames) { for ( String resultSetMappingName : resultSetMappingNames ) { log.tracef( "Starting attempt resolve named result-set-mapping : %s", resultSetMappingName ); final ResultSetMappingDefinition mapping = context.findResultSetMapping( resultSetMappingName ); if ( mapping == null ) { throw new UnknownSqlResultSetMappingException( "Unknown SqlResultSetMapping [" + resultSetMappingName + "]" ); } log.tracef( "Found result-set-mapping : %s", mapping.traceLoggableFormat() ); context.addQueryReturns( mapping.getQueryReturns() ); final SQLQueryReturnProcessor processor = new SQLQueryReturnProcessor( mapping.getQueryReturns(), context.getSessionFactory() ); final SQLQueryReturnProcessor.ResultAliasContext processResult = processor.process(); context.addQuerySpaces( processResult.collectQuerySpaces() ); } }
/** * Constructs a SQLQueryImpl given a sql query defined in the mappings. * * @param queryDef The representation of the defined <sql-query/>. * @param session The session to which this SQLQueryImpl belongs. * @param parameterMetadata Metadata about parameters found in the query. */ SQLQueryImpl(NamedSQLQueryDefinition queryDef, SessionImplementor session, ParameterMetadata parameterMetadata) { super( queryDef.getQueryString(), queryDef.getFlushMode(), session, parameterMetadata ); if ( queryDef.getResultSetRef() != null ) { ResultSetMappingDefinition definition = session.getFactory() .getResultSetMapping( queryDef.getResultSetRef() ); if (definition == null) { throw new MappingException( "Unable to find resultset-ref definition: " + queryDef.getResultSetRef() ); } this.queryReturns = Arrays.asList( definition.getQueryReturns() ); } else { this.queryReturns = Arrays.asList( queryDef.getQueryReturns() ); } this.querySpaces = queryDef.getQuerySpaces(); this.callable = queryDef.isCallable(); }
public void addDefaultResultSetMapping(ResultSetMappingDefinition definition) { final String name = definition.getName(); if ( !defaultSqlResultSetMappingNames.contains( name ) && getResultSetMapping( name ) != null ) { removeResultSetMapping( name ); } applyResultSetMapping( definition ); defaultSqlResultSetMappingNames.add( name ); }
/** * Build a ResultSetMappingDefinition given a containing element for the "return-XXX" elements * * @param resultSetElem The element containing the return definitions. * @param path No clue... * @param mappings The current processing state. * @return The description of the mappings... */ protected static ResultSetMappingDefinition buildResultSetMappingDefinition(Element resultSetElem, String path, Mappings mappings) { String resultSetName = resultSetElem.attribute( "name" ).getValue(); if ( path != null ) { resultSetName = path + '.' + resultSetName; } ResultSetMappingDefinition definition = new ResultSetMappingDefinition( resultSetName ); int cnt = 0; Iterator returns = resultSetElem.elementIterator(); while ( returns.hasNext() ) { cnt++; Element returnElem = (Element) returns.next(); String name = returnElem.getName(); if ( "return-scalar".equals( name ) ) { String column = returnElem.attributeValue( "column" ); String typeFromXML = HbmBinder.getTypeFromXML( returnElem ); Type type = null; if(typeFromXML!=null) { type = mappings.getTypeResolver().heuristicType( typeFromXML ); if ( type == null ) { throw new MappingException( "could not determine type " + type ); } } definition.addQueryReturn( new NativeSQLQueryScalarReturn( column, type ) ); } else if ( "return".equals( name ) ) { definition.addQueryReturn( bindReturn( returnElem, mappings, cnt ) ); } else if ( "return-join".equals( name ) ) { definition.addQueryReturn( bindReturnJoin( returnElem, mappings ) ); } else if ( "load-collection".equals( name ) ) { definition.addQueryReturn( bindLoadCollection( returnElem, mappings ) ); } } return definition; }
@Override public void addResultSetMapping(ResultSetMappingDefinition resultSetMappingDefinition) { if ( resultSetMappingDefinition == null || resultSetMappingDefinition.getName() == null ) { throw new IllegalArgumentException( "Result-set mapping object or name is null: " + resultSetMappingDefinition ); } resultSetMappings.put( resultSetMappingDefinition.getName(), resultSetMappingDefinition ); }
public SQLQuery setResultSetMapping(String name) { ResultSetMappingDefinition mapping = session.getFactory().getResultSetMapping( name ); if ( mapping == null ) { throw new MappingException( "Unknown SqlResultSetMapping [" + name + "]" ); } NativeSQLQueryReturn[] returns = mapping.getQueryReturns(); queryReturns.addAll( Arrays.asList( returns ) ); return this; }
private Map<String, ProcedureCallMemento> toProcedureCallMementos( Map<String, NamedProcedureCallDefinition> definitions, Map<String, ResultSetMappingDefinition> resultSetMappingMap) { final Map<String, ProcedureCallMemento> rtn = new HashMap<String, ProcedureCallMemento>(); if ( definitions != null ) { for (String name : definitions.keySet()){ rtn.put( name, definitions.get( name ).toMemento( this, resultSetMappingMap )); } } return rtn; }
/** * The result-set-mapping(s) return form * * @param session The session * @param procedureName The name of the procedure to call * @param resultSetMappings The names of the result set mappings making up the result */ public ProcedureCallImpl(final SessionImplementor session, String procedureName, String... resultSetMappings) { super( session ); this.procedureName = procedureName; final List<NativeSQLQueryReturn> collectedQueryReturns = new ArrayList<NativeSQLQueryReturn>(); final Set<String> collectedQuerySpaces = new HashSet<String>(); Util.resolveResultSetMappings( new Util.ResultSetMappingResolutionContext() { @Override public SessionFactoryImplementor getSessionFactory() { return session.getFactory(); } @Override public ResultSetMappingDefinition findResultSetMapping(String name) { return session.getFactory().getResultSetMapping( name ); } @Override public void addQueryReturns(NativeSQLQueryReturn... queryReturns) { Collections.addAll( collectedQueryReturns, queryReturns ); } @Override public void addQuerySpaces(String... spaces) { Collections.addAll( collectedQuerySpaces, spaces ); } }, resultSetMappings ); this.queryReturns = collectedQueryReturns.toArray( new NativeSQLQueryReturn[ collectedQueryReturns.size() ] ); this.synchronizedQuerySpaces = collectedQuerySpaces; }
public void addResultSetMapping(ResultSetMappingDefinition sqlResultSetMapping) { final String name = sqlResultSetMapping.getName(); if ( resultSetMappings.containsKey(name) ) { throw new DuplicateMappingException("resultSet", name); } resultSetMappings.put(name, sqlResultSetMapping); }
/** * Build a ResultSetMappingDefinition given a containing element for the "return-XXX" elements * * @param resultSetElem The element containing the return definitions. * @param path No clue... * @param mappings The current processing state. * @return The description of the mappings... */ protected static ResultSetMappingDefinition buildResultSetMappingDefinition(Element resultSetElem, String path, Mappings mappings) { String resultSetName = resultSetElem.attribute( "name" ).getValue(); if ( path != null ) { resultSetName = path + '.' + resultSetName; } ResultSetMappingDefinition definition = new ResultSetMappingDefinition( resultSetName ); int cnt = 0; Iterator returns = resultSetElem.elementIterator(); while ( returns.hasNext() ) { cnt++; Element returnElem = (Element) returns.next(); String name = returnElem.getName(); if ( "return-scalar".equals( name ) ) { String column = returnElem.attributeValue( "column" ); String typeFromXML = HbmBinder.getTypeFromXML( returnElem ); Type type = null; if(typeFromXML!=null) { type = TypeFactory.heuristicType( typeFromXML ); if ( type == null ) { throw new MappingException( "could not determine type " + type ); } } definition.addQueryReturn( new NativeSQLQueryScalarReturn( column, type ) ); } else if ( "return".equals( name ) ) { definition.addQueryReturn( bindReturn( returnElem, mappings, cnt ) ); } else if ( "return-join".equals( name ) ) { definition.addQueryReturn( bindReturnJoin( returnElem, mappings ) ); } else if ( "load-collection".equals( name ) ) { definition.addQueryReturn( bindLoadCollection( returnElem, mappings ) ); } } return definition; }
public SQLQuery setResultSetMapping(String name) { ResultSetMappingDefinition mapping = session.getFactory().getResultSetMapping( name ); if ( mapping == null ) { throw new MappingException( "Unknown SqlResultSetMapping [" + name + "]" ); } NativeSQLQueryReturn[] returns = mapping.getQueryReturns(); int length = returns.length; for ( int index = 0 ; index < length ; index++ ) { queryReturns.add( returns[index] ); } return this; }
public ResultSetMappingDefinition getResultSetMapping(String name) { return sessionFactoryImplementor.getResultSetMapping(name); }
protected void reset() { metadataSourceQueue = new MetadataSourceQueue(); createReflectionManager(); classes = new HashMap<String,PersistentClass>(); imports = new HashMap<String,String>(); collections = new HashMap<String,Collection>(); tables = new TreeMap<String,Table>(); namedQueries = new HashMap<String,NamedQueryDefinition>(); namedSqlQueries = new HashMap<String,NamedSQLQueryDefinition>(); sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>(); namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>(); namedProcedureCallMap = new HashMap<String, NamedProcedureCallDefinition>( ); typeDefs = new HashMap<String,TypeDef>(); filterDefinitions = new HashMap<String, FilterDefinition>(); fetchProfiles = new HashMap<String, FetchProfile>(); auxiliaryDatabaseObjects = new ArrayList<AuxiliaryDatabaseObject>(); tableNameBinding = new HashMap(); columnNameBindingPerTable = new HashMap(); secondPasses = new ArrayList<SecondPass>(); propertyReferences = new ArrayList<Mappings.PropertyReference>(); extendsQueue = new HashMap<ExtendsQueueEntry, String>(); xmlHelper = new XMLHelper(); interceptor = EmptyInterceptor.INSTANCE; properties = Environment.getProperties(); entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER; sqlFunctions = new HashMap<String, SQLFunction>(); entityTuplizerFactory = new EntityTuplizerFactory(); // componentTuplizerFactory = new ComponentTuplizerFactory(); identifierGeneratorFactory = new DefaultIdentifierGeneratorFactory(); mappedSuperClasses = new HashMap<Class<?>, MappedSuperclass>(); metadataSourcePrecedence = Collections.emptyList(); namedGenerators = new HashMap<String, IdGenerator>(); joins = new HashMap<String, Map<String, Join>>(); classTypes = new HashMap<String, AnnotatedClassType>(); generatorTables = new HashMap<String, Properties>(); defaultNamedQueryNames = new HashSet<String>(); defaultNamedNativeQueryNames = new HashSet<String>(); defaultSqlResultSetMappingNames = new HashSet<String>(); defaultNamedProcedure = new HashSet<String>( ); defaultNamedGenerators = new HashSet<String>(); uniqueConstraintHoldersByTable = new HashMap<Table, List<UniqueConstraintHolder>>(); jpaIndexHoldersByTable = new HashMap<Table,List<JPAIndexHolder>>( ); mappedByResolver = new HashMap<String, String>(); propertyRefResolver = new HashMap<String, String>(); caches = new ArrayList<CacheHolder>(); namingStrategyDelegator = LegacyNamingStrategyDelegator.DEFAULT_INSTANCE; setEntityResolver( new EJB3DTDEntityResolver() ); anyMetaDefs = new HashMap<String, AnyMetaDef>(); propertiesAnnotatedWithMapsId = new HashMap<XClass, Map<String, PropertyData>>(); propertiesAnnotatedWithIdAndToOne = new HashMap<XClass, Map<String, PropertyData>>(); specjProprietarySyntaxEnabled = System.getProperty( "hibernate.enable_specj_proprietary_syntax" ) != null; }
public ResultSetMappingDefinition getResultSetMapping(String name) { return sqlResultSetMappings.get(name); }
public void addResultSetMapping(ResultSetMappingDefinition sqlResultSetMapping) throws DuplicateMappingException { if ( !defaultSqlResultSetMappingNames.contains( sqlResultSetMapping.getName() ) ) { applyResultSetMapping( sqlResultSetMapping ); } }
public void applyResultSetMapping(ResultSetMappingDefinition sqlResultSetMapping) throws DuplicateMappingException { Object old = sqlResultSetMappings.put( sqlResultSetMapping.getName(), sqlResultSetMapping ); if ( old != null ) { throw new DuplicateMappingException( "resultSet", sqlResultSetMapping.getName() ); } }
public void doSecondPass(Map persistentClasses) throws MappingException { String queryName = queryElem.attribute( "name" ).getValue(); if (path!=null) queryName = path + '.' + queryName; boolean cacheable = "true".equals( queryElem.attributeValue( "cacheable" ) ); String region = queryElem.attributeValue( "cache-region" ); Attribute tAtt = queryElem.attribute( "timeout" ); Integer timeout = tAtt == null ? null : Integer.valueOf( tAtt.getValue() ); Attribute fsAtt = queryElem.attribute( "fetch-size" ); Integer fetchSize = fsAtt == null ? null : Integer.valueOf( fsAtt.getValue() ); Attribute roAttr = queryElem.attribute( "read-only" ); boolean readOnly = roAttr != null && "true".equals( roAttr.getValue() ); Attribute cacheModeAtt = queryElem.attribute( "cache-mode" ); String cacheMode = cacheModeAtt == null ? null : cacheModeAtt.getValue(); Attribute cmAtt = queryElem.attribute( "comment" ); String comment = cmAtt == null ? null : cmAtt.getValue(); java.util.List<String> synchronizedTables = new ArrayList<String>(); Iterator tables = queryElem.elementIterator( "synchronize" ); while ( tables.hasNext() ) { synchronizedTables.add( ( (Element) tables.next() ).attributeValue( "table" ) ); } boolean callable = "true".equals( queryElem.attributeValue( "callable" ) ); NamedSQLQueryDefinition namedQuery; Attribute ref = queryElem.attribute( "resultset-ref" ); String resultSetRef = ref == null ? null : ref.getValue(); if ( StringHelper.isNotEmpty( resultSetRef ) ) { namedQuery = new NamedSQLQueryDefinitionBuilder().setName( queryName ) .setQuery( queryElem.getText() ) .setResultSetRef( resultSetRef ) .setQuerySpaces( synchronizedTables ) .setCacheable( cacheable ) .setCacheRegion( region ) .setTimeout( timeout ) .setFetchSize( fetchSize ) .setFlushMode( FlushMode.interpretExternalSetting( queryElem.attributeValue( "flush-mode" ) ) ) .setCacheMode( CacheMode.interpretExternalSetting( cacheMode ) ) .setReadOnly( readOnly ) .setComment( comment ) .setParameterTypes( HbmBinder.getParameterTypes( queryElem ) ) .setCallable( callable ) .createNamedQueryDefinition(); //TODO check there is no actual definition elemnents when a ref is defined } else { ResultSetMappingDefinition definition = buildResultSetMappingDefinition( queryElem, path, mappings ); namedQuery = new NamedSQLQueryDefinitionBuilder().setName( queryName ) .setQuery( queryElem.getText() ) .setQueryReturns( definition.getQueryReturns() ) .setQuerySpaces( synchronizedTables ) .setCacheable( cacheable ) .setCacheRegion( region ) .setTimeout( timeout ) .setFetchSize( fetchSize ) .setFlushMode( FlushMode.interpretExternalSetting( queryElem.attributeValue( "flush-mode" ) ) ) .setCacheMode( CacheMode.interpretExternalSetting( cacheMode ) ) .setReadOnly( readOnly ) .setComment( comment ) .setParameterTypes( HbmBinder.getParameterTypes( queryElem ) ) .setCallable( callable ) .createNamedQueryDefinition(); } if ( LOG.isDebugEnabled() ) { LOG.debugf( "Named SQL query: %s -> %s", namedQuery.getName(), namedQuery.getQueryString() ); } mappings.addSQLQuery( queryName, namedQuery ); }
public void doSecondPass(Map persistentClasses) throws MappingException { ResultSetMappingDefinition definition = buildResultSetMappingDefinition( element, path, mappings); mappings.addResultSetMapping( definition ); }
@Override public Iterable<ResultSetMappingDefinition> getResultSetMappingDefinitions() { return resultSetMappings.values(); }
public ResultSetMappingDefinition getResultSetMapping(String mappingName) { return namedQueryRepository.getResultSetMappingDefinition( mappingName ); }
public ResultSetMappingDefinition getResultSetMappingDefinition(String mappingName) { return namedSqlResultSetMappingMap.get( mappingName ); }
public void doSecondPass(Map persistentClasses) throws MappingException { String queryName = queryElem.attribute( "name" ).getValue(); if (path!=null) queryName = path + '.' + queryName; boolean cacheable = "true".equals( queryElem.attributeValue( "cacheable" ) ); String region = queryElem.attributeValue( "cache-region" ); Attribute tAtt = queryElem.attribute( "timeout" ); Integer timeout = tAtt == null ? null : new Integer( tAtt.getValue() ); Attribute fsAtt = queryElem.attribute( "fetch-size" ); Integer fetchSize = fsAtt == null ? null : new Integer( fsAtt.getValue() ); Attribute roAttr = queryElem.attribute( "read-only" ); boolean readOnly = roAttr != null && "true".equals( roAttr.getValue() ); Attribute cacheModeAtt = queryElem.attribute( "cache-mode" ); String cacheMode = cacheModeAtt == null ? null : cacheModeAtt.getValue(); Attribute cmAtt = queryElem.attribute( "comment" ); String comment = cmAtt == null ? null : cmAtt.getValue(); java.util.List synchronizedTables = new ArrayList(); Iterator tables = queryElem.elementIterator( "synchronize" ); while ( tables.hasNext() ) { synchronizedTables.add( ( (Element) tables.next() ).attributeValue( "table" ) ); } boolean callable = "true".equals( queryElem.attributeValue( "callable" ) ); NamedSQLQueryDefinition namedQuery; Attribute ref = queryElem.attribute( "resultset-ref" ); String resultSetRef = ref == null ? null : ref.getValue(); if ( StringHelper.isNotEmpty( resultSetRef ) ) { namedQuery = new NamedSQLQueryDefinition( queryElem.getText(), resultSetRef, synchronizedTables, cacheable, region, timeout, fetchSize, HbmBinder.getFlushMode( queryElem.attributeValue( "flush-mode" ) ), HbmBinder.getCacheMode( cacheMode ), readOnly, comment, HbmBinder.getParameterTypes( queryElem ), callable ); //TODO check there is no actual definition elemnents when a ref is defined } else { ResultSetMappingDefinition definition = buildResultSetMappingDefinition( queryElem, path, mappings ); namedQuery = new NamedSQLQueryDefinition( queryElem.getText(), definition.getQueryReturns(), synchronizedTables, cacheable, region, timeout, fetchSize, HbmBinder.getFlushMode( queryElem.attributeValue( "flush-mode" ) ), HbmBinder.getCacheMode( cacheMode ), readOnly, comment, HbmBinder.getParameterTypes( queryElem ), callable ); } log.debug( "Named SQL query: " + queryName + " -> " + namedQuery.getQueryString() ); mappings.addSQLQuery( queryName, namedQuery ); }
public ResultSetMappingDefinition getResultSetMapping(String name) { return (ResultSetMappingDefinition) resultSetMappings.get(name); }
public ResultSetMappingDefinition getResultSetMapping(String resultSetName) { return (ResultSetMappingDefinition) sqlResultSetMappings.get(resultSetName); }
public ResultSetMappingDefinition getResultSetMapping(String resultSetName) { return sqlResultSetMappings.get(resultSetName); }
/** * Get the metadata for a named SQL result set mapping. * * @param name The mapping name. * @return The SQL result set mapping metadat, or null if none found. */ public ResultSetMappingDefinition getResultSetMapping(String name);
/** * Adds the metadata for a named SQL result set mapping to this repository. * * @param sqlResultSetMapping The metadata * @throws DuplicateMappingException If metadata for another SQL result mapping was * already found under the given name. */ public void addResultSetMapping(ResultSetMappingDefinition sqlResultSetMapping) throws DuplicateMappingException;
/** * Locate a ResultSetMappingDefinition by name * * @param name The name of the ResultSetMappingDefinition to locate * * @return The ResultSetMappingDefinition */ public ResultSetMappingDefinition findResultSetMapping(String name);
public void addDefaultResultSetMapping(ResultSetMappingDefinition definition);
public Iterable<ResultSetMappingDefinition> getResultSetMappingDefinitions();
public void addResultSetMapping(ResultSetMappingDefinition resultSetMappingDefinition);
public ResultSetMappingDefinition getResultSetMapping(String name);