001/*
002 * Copyright 2012-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.orm.jpa.hibernate;
018
019import org.hibernate.boot.model.naming.Identifier;
020import org.hibernate.boot.model.naming.ImplicitJoinTableNameSource;
021import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
022import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
023
024/**
025 * Hibernate {@link ImplicitNamingStrategy} that follows Spring recommended naming
026 * conventions. Naming conventions implemented here are identical to
027 * {@link ImplicitNamingStrategyJpaCompliantImpl} with the exception that join table names
028 * are of the form
029 * <code>{owning_physical_table_name}_{association_owning_property_name}</code>.
030 *
031 * @author Andy Wilkinson
032 * @since 1.4.0
033 */
034public class SpringImplicitNamingStrategy extends ImplicitNamingStrategyJpaCompliantImpl {
035
036        @Override
037        public Identifier determineJoinTableName(ImplicitJoinTableNameSource source) {
038                String name = source.getOwningPhysicalTableName() + "_"
039                                + source.getAssociationOwningAttributePath().getProperty();
040                return toIdentifier(name, source.getBuildingContext());
041        }
042
043}