下面列出了org.hibernate.boot.model.naming.Identifier#render ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void addColumnBinding(SimpleValue value) {
final String logicalColumnName;
if ( StringHelper.isNotEmpty( this.logicalColumnName ) ) {
logicalColumnName = this.logicalColumnName;
}
else {
final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
final Database database = context.getMetadataCollector().getDatabase();
final ImplicitNamingStrategy implicitNamingStrategy = context.getBuildingOptions()
.getImplicitNamingStrategy();
final Identifier implicitName = normalizer.normalizeIdentifierQuoting(
implicitNamingStrategy.determineBasicColumnName(
new ImplicitBasicColumnNameSource() {
@Override
public AttributePath getAttributePath() {
return AttributePath.parse( propertyName );
}
@Override
public boolean isCollectionElement() {
return false;
}
@Override
public MetadataBuildingContext getBuildingContext() {
return context;
}
}
)
);
logicalColumnName = implicitName.render( database.getDialect() );
}
context.getMetadataCollector().addColumnNameBinding( value.getTable(), logicalColumnName, getMappingColumn() );
}
private static String render(Identifier identifier, Dialect dialect) {
if ( identifier == null ) {
return null;
}
return identifier.render( dialect );
}
@Override
public String getLogicalTableName(Table ownerTable) {
final Identifier logicalName = physicalToLogicalTableNameMap.get( ownerTable.getNameIdentifier() );
if ( logicalName == null ) {
throw new MappingException( "Unable to find physical table: " + ownerTable.getName() );
}
return logicalName.render();
}
@Override
public String getPhysicalColumnName(Table table, Identifier logicalName) throws MappingException {
if ( logicalName == null ) {
throw new MappingException( "Logical column name cannot be null" );
}
Table currentTable = table;
String physicalName = null;
while ( currentTable != null ) {
final TableColumnNameBinding binding = columnNameBindingByTableMap.get( currentTable );
if ( binding != null ) {
physicalName = binding.logicalToPhysical.get( logicalName );
if ( physicalName != null ) {
break;
}
}
if ( DenormalizedTable.class.isInstance( currentTable ) ) {
currentTable = ( (DenormalizedTable) currentTable ).getIncludedTable();
}
else {
currentTable = null;
}
}
if ( physicalName == null ) {
throw new MappingException(
"Unable to find column with logical name " + logicalName.render() + " in table " + table.getName()
);
}
return physicalName;
}
@Override
public String getLogicalColumnName(Table table, Identifier physicalName) throws MappingException {
final String physicalNameString = physicalName.render( getDatabase().getJdbcEnvironment().getDialect() );
Identifier logicalName = null;
Table currentTable = table;
while ( currentTable != null ) {
final TableColumnNameBinding binding = columnNameBindingByTableMap.get( currentTable );
if ( binding != null ) {
logicalName = binding.physicalToLogical.get( physicalNameString );
if ( logicalName != null ) {
break;
}
}
if ( DenormalizedTable.class.isInstance( currentTable ) ) {
currentTable = ( (DenormalizedTable) currentTable ).getIncludedTable();
}
else {
currentTable = null;
}
}
if ( logicalName == null ) {
throw new MappingException(
"Unable to find column with physical name " + physicalNameString + " in table " + table.getName()
);
}
return logicalName.render();
}
private static String extract(Identifier identifier) {
if ( identifier == null ) {
return null;
}
return identifier.render();
}
private static String extractName(Identifier identifier) {
return identifier == null ? null : identifier.render();
}
private String render(Identifier identifier) {
return identifier == null ? null : identifier.render();
}
private TableInformation processTableResults(
Identifier catalog,
Identifier schema,
Identifier tableName,
ResultSet resultSet) throws SQLException {
try {
boolean found = false;
TableInformation tableInformation = null;
while ( resultSet.next() ) {
if ( tableName.equals( Identifier.toIdentifier( resultSet.getString( "TABLE_NAME" ),
tableName.isQuoted() ) ) ) {
if ( found ) {
log.multipleTablesFound( tableName.render() );
final String catalogName = catalog == null ? "" : catalog.render();
final String schemaName = schema == null ? "" : schema.render();
throw new SchemaExtractionException(
String.format(
Locale.ENGLISH,
"More than one table found in namespace (%s, %s) : %s",
catalogName,
schemaName,
tableName.render()
)
);
}
else {
found = true;
tableInformation = extractTableInformation( resultSet );
addColumns( tableInformation );
}
}
}
if ( !found ) {
log.tableNotFound( tableName.render() );
}
return tableInformation;
}
finally {
try {
resultSet.close();
}
catch (SQLException ignore) {
}
}
}
private String getDefaultCatalogName(Database database, Dialect dialect) {
final Identifier identifier = database.getDefaultNamespace().getPhysicalName().getCatalog();
return identifier == null ? null : identifier.render( dialect );
}
private String getDefaultSchemaName(Database database, Dialect dialect) {
final Identifier identifier = database.getDefaultNamespace().getPhysicalName().getSchema();
return identifier == null ? null : identifier.render( dialect );
}
@Override
public String getPhysicalTableName(Identifier logicalName) {
final Identifier physicalName = logicalToPhysicalTableNameMap.get( logicalName );
return physicalName == null ? null : physicalName.render();
}
private String extractName(Identifier identifier, Dialect dialect) {
if ( identifier == null ) {
return null;
}
return identifier.render( dialect );
}