📄 sqlqueryreturnprocessor.java
字号:
( SQLLoadable ) alias2Persister.get( alias ),
( String ) alias2Suffix.get( alias )
);
}
}
else {
collectionAliases = new ColumnCollectionAliases(
( Map ) collectionPropertyResultMaps.get( alias ),
persister
);
if ( isEntityElements ) {
elementEntityAliases = new ColumnEntityAliases(
( Map ) entityPropertyResultMaps.get( alias ),
( SQLLoadable ) alias2Persister.get( alias ),
( String ) alias2Suffix.get( alias )
);
}
}
customReturn = new CollectionFetchReturn(
alias,
ownerCustomReturn,
rtn.getOwnerProperty(),
collectionAliases,
elementEntityAliases,
rtn.getLockMode()
);
}
else {
EntityAliases entityAliases;
if ( queryHadAliases || hasPropertyResultMap( alias ) ) {
entityAliases = new DefaultEntityAliases(
( Map ) entityPropertyResultMaps.get( alias ),
( SQLLoadable ) alias2Persister.get( alias ),
( String ) alias2Suffix.get( alias )
);
}
else {
entityAliases = new ColumnEntityAliases(
( Map ) entityPropertyResultMaps.get( alias ),
( SQLLoadable ) alias2Persister.get( alias ),
( String ) alias2Suffix.get( alias )
);
}
customReturn = new EntityFetchReturn(
alias,
entityAliases,
ownerCustomReturn,
rtn.getOwnerProperty(),
rtn.getLockMode()
);
}
customReturns.add( customReturn );
customReturnsByAlias.put( alias, customReturn );
}
}
return customReturns;
}
private SQLLoadable getSQLLoadable(String entityName) throws MappingException {
EntityPersister persister = factory.getEntityPersister( entityName );
if ( !(persister instanceof SQLLoadable) ) {
throw new MappingException( "class persister is not SQLLoadable: " + entityName );
}
return (SQLLoadable) persister;
}
private String generateEntitySuffix() {
return BasicLoader.generateSuffixes( entitySuffixSeed++, 1 )[0];
}
private String generateCollectionSuffix() {
return collectionSuffixSeed++ + "__";
}
private void processReturn(NativeSQLQueryReturn rtn) {
if ( rtn instanceof NativeSQLQueryScalarReturn ) {
processScalarReturn( ( NativeSQLQueryScalarReturn ) rtn );
}
else if ( rtn instanceof NativeSQLQueryRootReturn ) {
processRootReturn( ( NativeSQLQueryRootReturn ) rtn );
}
else if ( rtn instanceof NativeSQLQueryCollectionReturn ) {
processCollectionReturn( ( NativeSQLQueryCollectionReturn ) rtn );
}
else {
processJoinReturn( ( NativeSQLQueryJoinReturn ) rtn );
}
}
private void processScalarReturn(NativeSQLQueryScalarReturn typeReturn) {
// scalarColumnAliases.add( typeReturn.getColumnAlias() );
// scalarTypes.add( typeReturn.getType() );
}
private void processRootReturn(NativeSQLQueryRootReturn rootReturn) {
if ( alias2Persister.containsKey( rootReturn.getAlias() ) ) {
// already been processed...
return;
}
SQLLoadable persister = getSQLLoadable( rootReturn.getReturnEntityName() );
addPersister( rootReturn.getAlias(), rootReturn.getPropertyResultsMap(), persister );
}
/**
* @param propertyResult
* @param persister
*/
private void addPersister(String alias, Map propertyResult, SQLLoadable persister) {
alias2Persister.put( alias, persister );
String suffix = generateEntitySuffix();
log.trace( "mapping alias [" + alias + "] to entity-suffix [" + suffix + "]" );
alias2Suffix.put( alias, suffix );
entityPropertyResultMaps.put( alias, propertyResult );
}
private void addCollection(String role, String alias, Map propertyResults) {
SQLLoadableCollection collectionPersister = ( SQLLoadableCollection ) factory.getCollectionPersister( role );
alias2CollectionPersister.put( alias, collectionPersister );
String suffix = generateCollectionSuffix();
log.trace( "mapping alias [" + alias + "] to collection-suffix [" + suffix + "]" );
alias2CollectionSuffix.put( alias, suffix );
collectionPropertyResultMaps.put( alias, propertyResults );
if ( collectionPersister.isOneToMany() ) {
SQLLoadable persister = ( SQLLoadable ) collectionPersister.getElementPersister();
addPersister( alias, filter( propertyResults ), persister );
}
}
private Map filter(Map propertyResults) {
Map result = new HashMap( propertyResults.size() );
String keyPrefix = "element.";
Iterator iter = propertyResults.entrySet().iterator();
while ( iter.hasNext() ) {
Map.Entry element = ( Map.Entry ) iter.next();
String path = ( String ) element.getKey();
if ( path.startsWith( keyPrefix ) ) {
result.put( path.substring( keyPrefix.length() ), element.getValue() );
}
}
return result;
}
private void processCollectionReturn(NativeSQLQueryCollectionReturn collectionReturn) {
// we are initializing an owned collection
//collectionOwners.add( new Integer(-1) );
// collectionOwnerAliases.add( null );
String role = collectionReturn.getOwnerEntityName() + '.' + collectionReturn.getOwnerProperty();
addCollection(
role,
collectionReturn.getAlias(),
collectionReturn.getPropertyResultsMap()
);
}
private void processJoinReturn(NativeSQLQueryJoinReturn fetchReturn) {
String alias = fetchReturn.getAlias();
// if ( alias2Persister.containsKey( alias ) || collectionAliases.contains( alias ) ) {
if ( alias2Persister.containsKey( alias ) || alias2CollectionPersister.containsKey( alias ) ) {
// already been processed...
return;
}
String ownerAlias = fetchReturn.getOwnerAlias();
// Make sure the owner alias is known...
if ( !alias2Return.containsKey( ownerAlias ) ) {
throw new HibernateException( "Owner alias [" + ownerAlias + "] is unknown for alias [" + alias + "]" );
}
// If this return's alias has not been processed yet, do so b4 further processing of this return
if ( !alias2Persister.containsKey( ownerAlias ) ) {
NativeSQLQueryNonScalarReturn ownerReturn = ( NativeSQLQueryNonScalarReturn ) alias2Return.get(ownerAlias);
processReturn( ownerReturn );
}
SQLLoadable ownerPersister = ( SQLLoadable ) alias2Persister.get( ownerAlias );
Type returnType = ownerPersister.getPropertyType( fetchReturn.getOwnerProperty() );
if ( returnType.isCollectionType() ) {
String role = ownerPersister.getEntityName() + '.' + fetchReturn.getOwnerProperty();
addCollection( role, alias, fetchReturn.getPropertyResultsMap() );
// collectionOwnerAliases.add( ownerAlias );
}
else if ( returnType.isEntityType() ) {
EntityType eType = ( EntityType ) returnType;
String returnEntityName = eType.getAssociatedEntityName();
SQLLoadable persister = getSQLLoadable( returnEntityName );
addPersister( alias, fetchReturn.getPropertyResultsMap(), persister );
}
}
// public List getCollectionAliases() {
// return collectionAliases;
// }
//
// /*public List getCollectionOwners() {
// return collectionOwners;
// }*/
//
// public List getCollectionOwnerAliases() {
// return collectionOwnerAliases;
// }
//
// public List getCollectionPersisters() {
// return collectionPersisters;
// }
//
// public Map getAlias2Persister() {
// return alias2Persister;
// }
//
// /*public boolean isCollectionInitializer() {
// return isCollectionInitializer;
// }*/
//
//// public List getPersisters() {
//// return persisters;
//// }
//
// public Map getAlias2OwnerAlias() {
// return alias2OwnerAlias;
// }
//
// public List getScalarTypes() {
// return scalarTypes;
// }
// public List getScalarColumnAliases() {
// return scalarColumnAliases;
// }
//
// public List getPropertyResults() {
// return propertyResults;
// }
//
// public List getCollectionPropertyResults() {
// return collectionResults;
// }
//
//
// public Map getAlias2Return() {
// return alias2Return;
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -