下面列出了org.hibernate.loader.custom.Return#org.hibernate.persister.collection.SQLLoadableCollection 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ColumnCollectionAliases(Map userProvidedAliases, SQLLoadableCollection persister) {
this.userProvidedAliases = userProvidedAliases;
this.keyAliases = getUserProvidedAliases(
"key",
persister.getKeyColumnNames()
);
this.indexAliases = getUserProvidedAliases(
"index",
persister.getIndexColumnNames()
);
this.elementAliases = getUserProvidedAliases(
"element",
persister.getElementColumnNames()
);
this.identifierAlias = getUserProvidedAlias(
"id",
persister.getIdentifierColumnName()
);
}
public ColumnCollectionAliases(Map userProvidedAliases, SQLLoadableCollection persister) {
this.userProvidedAliases = userProvidedAliases;
this.keyAliases = getUserProvidedAliases(
"key",
persister.getKeyColumnNames()
);
this.indexAliases = getUserProvidedAliases(
"index",
persister.getIndexColumnNames()
);
this.elementAliases = getUserProvidedAliases( "element",
persister.getElementColumnNames()
);
this.identifierAlias = getUserProvidedAlias( "id",
persister.getIdentifierColumnName()
);
}
private void addCollection(String role, String alias, Map propertyResults) {
SQLLoadableCollection collectionPersister = ( SQLLoadableCollection ) factory.getCollectionPersister( role );
alias2CollectionPersister.put( alias, collectionPersister );
String suffix = generateCollectionSuffix();
LOG.tracev( "Mapping alias [{0}] to collection-suffix [{1}]", alias, suffix );
alias2CollectionSuffix.put( alias, suffix );
collectionPropertyResultMaps.put( alias, propertyResults );
if ( collectionPersister.isOneToMany() || collectionPersister.isManyToMany() ) {
SQLLoadable persister = ( SQLLoadable ) collectionPersister.getElementPersister();
addPersister( alias, filter( propertyResults ), persister );
}
}
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 );
}
}
public SQLLoadableCollection getCollectionPersisterByAlias(String alias) {
return aliasContext.getCollectionPersister( alias );
}
public SQLLoadableCollection getCollectionPersister(String alias) {
return (SQLLoadableCollection) alias2CollectionPersister.get( alias );
}
private String resolveCollectionProperties(
String aliasName,
String propertyName) {
Map fieldResults = context.getPropertyResultsMapByAlias( aliasName );
SQLLoadableCollection collectionPersister = context.getCollectionPersisterByAlias( aliasName );
String collectionSuffix = context.getCollectionSuffixByAlias( aliasName );
if ( "*".equals( propertyName ) ) {
if( !fieldResults.isEmpty() ) {
throw new QueryException("Using return-propertys together with * syntax is not supported.");
}
String selectFragment = collectionPersister.selectFragment( aliasName, collectionSuffix );
aliasesFound++;
return selectFragment
+ ", "
+ resolveProperties( aliasName, propertyName );
}
else if ( "element.*".equals( propertyName ) ) {
return resolveProperties( aliasName, "*" );
}
else {
String[] columnAliases;
// Let return-propertys override whatever the persister has for aliases.
columnAliases = ( String[] ) fieldResults.get(propertyName);
if ( columnAliases==null ) {
columnAliases = collectionPersister.getCollectionPropertyColumnAliases( propertyName, collectionSuffix );
}
if ( columnAliases == null || columnAliases.length == 0 ) {
throw new QueryException(
"No column name found for property [" + propertyName + "] for alias [" + aliasName + "]",
originalQueryString
);
}
if ( columnAliases.length != 1 ) {
// TODO: better error message since we actually support composites if names are explicitly listed.
throw new QueryException(
"SQL queries only support properties mapped to a single column - property [" +
propertyName + "] is mapped to " + columnAliases.length + " columns.",
originalQueryString
);
}
aliasesFound++;
return columnAliases[0];
}
}
private String resolveCollectionProperties(
String aliasName,
String propertyName) {
Map fieldResults = context.getPropertyResultsMapByAlias( aliasName );
SQLLoadableCollection collectionPersister = context.getCollectionPersisterByAlias( aliasName );
String collectionSuffix = context.getCollectionSuffixByAlias( aliasName );
if ( "*".equals( propertyName ) ) {
if ( !fieldResults.isEmpty() ) {
throw new QueryException( "Using return-propertys together with * syntax is not supported." );
}
String selectFragment = collectionPersister.selectFragment( aliasName, collectionSuffix );
aliasesFound++;
return selectFragment
+ ", "
+ resolveProperties( aliasName, propertyName );
}
else if ( "element.*".equals( propertyName ) ) {
return resolveProperties( aliasName, "*" );
}
else {
String[] columnAliases;
// Let return-propertys override whatever the persister has for aliases.
columnAliases = (String[]) fieldResults.get( propertyName );
if ( columnAliases == null ) {
columnAliases = collectionPersister.getCollectionPropertyColumnAliases( propertyName, collectionSuffix );
}
if ( columnAliases == null || columnAliases.length == 0 ) {
throw new QueryException(
"No column name found for property [" + propertyName + "] for alias [" + aliasName + "]",
originalQuery );
}
if ( columnAliases.length != 1 ) {
// TODO: better error message since we actually support composites if names are explicitly listed.
throw new QueryException(
"SQL queries only support properties mapped to a single column - property [" +
propertyName + "] is mapped to " + columnAliases.length + " columns.",
originalQuery );
}
aliasesFound++;
return columnAliases[0];
}
}
@Override
public SQLLoadableCollection getCollectionPersisterByAlias(String alias) {
return null;
}
public SQLLoadableCollection getCollectionPersisterByAlias(String alias) {
return aliasContext.getCollectionPersister( alias );
}
public SQLLoadableCollection getCollectionPersister(String alias) {
return ( SQLLoadableCollection ) alias2CollectionPersister.get( alias );
}
private String resolveCollectionProperties(
String aliasName,
String propertyName) {
Map fieldResults = context.getPropertyResultsMapByAlias( aliasName );
SQLLoadableCollection collectionPersister = context.getCollectionPersisterByAlias( aliasName );
String collectionSuffix = context.getCollectionSuffixByAlias( aliasName );
if ( "*".equals( propertyName ) ) {
if( !fieldResults.isEmpty() ) {
throw new QueryException("Using return-propertys together with * syntax is not supported.");
}
String selectFragment = collectionPersister.selectFragment( aliasName, collectionSuffix );
aliasesFound++;
return selectFragment
+ ", "
+ resolveProperties( aliasName, propertyName );
}
else if ( "element.*".equals( propertyName ) ) {
return resolveProperties( aliasName, "*" );
}
else {
String[] columnAliases;
// Let return-propertys override whatever the persister has for aliases.
columnAliases = ( String[] ) fieldResults.get(propertyName);
if ( columnAliases==null ) {
columnAliases = collectionPersister.getCollectionPropertyColumnAliases( propertyName, collectionSuffix );
}
if ( columnAliases == null || columnAliases.length == 0 ) {
throw new QueryException(
"No column name found for property [" + propertyName + "] for alias [" + aliasName + "]",
originalQueryString
);
}
if ( columnAliases.length != 1 ) {
// TODO: better error message since we actually support composites if names are explicitly listed.
throw new QueryException(
"SQL queries only support properties mapped to a single column - property [" +
propertyName + "] is mapped to " + columnAliases.length + " columns.",
originalQueryString
);
}
aliasesFound++;
return columnAliases[0];
}
}
SQLLoadableCollection getCollectionPersisterByAlias(String alias);
SQLLoadableCollection getCollectionPersisterByAlias(String alias);
SQLLoadableCollection getCollectionPersisterByAlias(String alias);