1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.service.data.impl;
20
21 import java.util.Locale;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.hibernate.boot.model.naming.Identifier;
25 import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
26 import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
27
28
29
30
31
32 public final class LegacyNamingStrategy implements PhysicalNamingStrategy {
33
34 private static final String REG_EXPR = "([a-z])([A-Z])";
35 private static final String REPLACEMENT_PATTERN = "$1_$2";
36
37
38
39
40
41 public LegacyNamingStrategy() {
42 super();
43 }
44
45
46
47
48
49
50
51
52 private static Identifier convert(final Identifier identifier) {
53 if (identifier == null || StringUtils.isBlank(identifier.getText())) {
54 return identifier;
55 } else {
56 return Identifier.toIdentifier(identifier.getText().replaceAll(REG_EXPR, REPLACEMENT_PATTERN).toLowerCase(Locale.ENGLISH));
57 }
58 }
59
60 @Override
61 public Identifier toPhysicalCatalogName(final Identifier identifier, final JdbcEnvironment jdbcEnv) {
62 return convert(identifier);
63 }
64
65 @Override
66 public Identifier toPhysicalColumnName(final Identifier identifier, final JdbcEnvironment jdbcEnv) {
67 return convert(identifier);
68 }
69
70 @Override
71 public Identifier toPhysicalSchemaName(final Identifier identifier, final JdbcEnvironment jdbcEnv) {
72 return convert(identifier);
73 }
74
75 @Override
76 public Identifier toPhysicalSequenceName(final Identifier identifier, final JdbcEnvironment jdbcEnv) {
77 return convert(identifier);
78 }
79
80 @Override
81 public Identifier toPhysicalTableName(final Identifier identifier, final JdbcEnvironment jdbcEnv) {
82 return convert(identifier);
83 }
84
85 }