-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,153 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...common/src/main/java/com/ctrip/framework/apollo/common/jpa/TablePrefixNamingStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2023 Apollo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package com.ctrip.framework.apollo.common.jpa; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.hibernate.boot.model.naming.Identifier; | ||
import org.hibernate.boot.model.naming.PhysicalNamingStrategy; | ||
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl; | ||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; | ||
|
||
public class TablePrefixNamingStrategy extends PhysicalNamingStrategyStandardImpl implements | ||
PhysicalNamingStrategy { | ||
|
||
private static final long serialVersionUID = -5268252502936563292L; | ||
|
||
private final String tablePrefix; | ||
|
||
public TablePrefixNamingStrategy(String tablePrefix) { | ||
this.tablePrefix = tablePrefix; | ||
} | ||
|
||
@Override | ||
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) { | ||
String tablePrefix = this.tablePrefix; | ||
if (StringUtils.isEmpty(tablePrefix)) { | ||
return name; | ||
} | ||
String entityTableName = name.getText(); | ||
String physicalTableName = tablePrefix + entityTableName; | ||
return new Identifier(physicalTableName, name.isQuoted()); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
apollo-common/src/main/java/com/ctrip/framework/apollo/common/jpa/TablePrefixProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2023 Apollo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package com.ctrip.framework.apollo.common.jpa; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "spring.jpa.table-prefix") | ||
public class TablePrefixProperties { | ||
|
||
/** | ||
* The table name prefix of config module | ||
*/ | ||
private String configPrefix = ""; | ||
|
||
/** | ||
* The table name prefix of portal module | ||
*/ | ||
private String portalPrefix = ""; | ||
|
||
public String getConfigPrefix() { | ||
return this.configPrefix; | ||
} | ||
|
||
public void setConfigPrefix(String configPrefix) { | ||
this.configPrefix = configPrefix; | ||
} | ||
|
||
public String getPortalPrefix() { | ||
return this.portalPrefix; | ||
} | ||
|
||
public void setPortalPrefix(String portalPrefix) { | ||
this.portalPrefix = portalPrefix; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalApplicationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2023 Apollo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package com.ctrip.framework.apollo.portal; | ||
|
||
import com.ctrip.framework.apollo.common.jpa.TablePrefixNamingStrategy; | ||
import com.ctrip.framework.apollo.common.jpa.TablePrefixProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class PortalApplicationConfig { | ||
|
||
@Bean | ||
public static TablePrefixNamingStrategy tablePrefixNamingStrategy( | ||
TablePrefixProperties tablePrefixProperties) { | ||
return new TablePrefixNamingStrategy(tablePrefixProperties.getPortalPrefix()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.