| Revision | 2412 (tree) |
|---|---|
| Time | 2022-10-05 18:47:39 |
| Author | t_nakayama1971 |
(empty log message)
| @@ -20,20 +20,20 @@ | ||
| 20 | 20 | <dependency> |
| 21 | 21 | <groupId>org.hibernate.orm</groupId> |
| 22 | 22 | <artifactId>hibernate-core</artifactId> |
| 23 | - <version>6.0.0.Beta2</version> | |
| 24 | - <scope>provided</scope> | |
| 23 | + <version>6.1.3.Final</version> | |
| 24 | + <scope>compile</scope> | |
| 25 | 25 | </dependency> |
| 26 | 26 | <dependency> |
| 27 | 27 | <groupId>jakarta.persistence</groupId> |
| 28 | 28 | <artifactId>jakarta.persistence-api</artifactId> |
| 29 | 29 | <version>3.1.0</version> |
| 30 | - <scope>provided</scope> | |
| 30 | + <scope>compile</scope> | |
| 31 | 31 | </dependency> |
| 32 | 32 | |
| 33 | 33 | <dependency> |
| 34 | 34 | <groupId>org.hibernate.tool</groupId> |
| 35 | 35 | <artifactId>hibernate-tools-ant</artifactId> |
| 36 | - <version>6.0.0.Beta2</version> | |
| 36 | + <version>6.1.3.Final</version> | |
| 37 | 37 | <scope>runtime</scope> |
| 38 | 38 | </dependency> |
| 39 | 39 | <dependency> |
| @@ -83,7 +83,7 @@ | ||
| 83 | 83 | <dependency> |
| 84 | 84 | <groupId>org.hibernate.tool</groupId> |
| 85 | 85 | <artifactId>hibernate-tools-ant</artifactId> |
| 86 | - <version>6.0.0.Beta2</version> | |
| 86 | + <version>6.1.3.Final</version> | |
| 87 | 87 | </dependency> |
| 88 | 88 | <dependency> |
| 89 | 89 | <groupId>org.postgresql</groupId> |
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | <plugin> |
| 127 | 127 | <groupId>org.hibernate.tool</groupId> |
| 128 | 128 | <artifactId>hibernate-tools-maven</artifactId> |
| 129 | - <version>6.0.0.Beta2</version> | |
| 129 | + <version>6.1.3.Final</version> | |
| 130 | 130 | <configuration> |
| 131 | 131 | <createCollectionForForeignKey>false</createCollectionForForeignKey> |
| 132 | 132 | <createManyToOneForForeignKey>false</createManyToOneForForeignKey> |
| @@ -150,4 +150,18 @@ | ||
| 150 | 150 | </plugin> |
| 151 | 151 | </plugins> |
| 152 | 152 | </build> |
| 153 | + | |
| 154 | + <repositories> | |
| 155 | + <repository> | |
| 156 | + <id>jboss.public</id> | |
| 157 | + <name>JBoss Public Repository</name> | |
| 158 | + <url>https://repository.jboss.org/nexus/content/repositories/public/</url> | |
| 159 | + <releases> | |
| 160 | + <enabled>true</enabled> | |
| 161 | + </releases> | |
| 162 | + <snapshots> | |
| 163 | + <enabled>true</enabled> | |
| 164 | + </snapshots> | |
| 165 | + </repository> | |
| 166 | + </repositories> | |
| 153 | 167 | </project> |
| @@ -1,69 +1,80 @@ | ||
| 1 | -package common.db.dao.hibernate.reveng; | |
| 2 | - | |
| 3 | -import java.util.ArrayList; | |
| 4 | -import java.util.HashMap; | |
| 5 | -import java.util.HashSet; | |
| 6 | -import java.util.List; | |
| 7 | -import java.util.Map; | |
| 8 | -import java.util.Properties; | |
| 9 | -import java.util.Set; | |
| 10 | - | |
| 11 | -import org.hibernate.tool.api.reveng.TableIdentifier; | |
| 12 | -import org.hibernate.tool.internal.reveng.strategy.AbstractStrategy; | |
| 13 | - | |
| 14 | -public final class DefaultStrategy extends AbstractStrategy { | |
| 15 | - | |
| 16 | - private final Map<String, Set<String>> tables = new HashMap<>(); | |
| 17 | - | |
| 18 | - @Override | |
| 19 | - public boolean excludeColumn(final TableIdentifier identifier, final String columnName) { | |
| 20 | - Set<String> columns = this.tables.computeIfAbsent(identifier.getName(), k -> new HashSet<>()); | |
| 21 | - columns.add(columnName); | |
| 22 | - return super.excludeColumn(identifier, columnName); | |
| 23 | - } | |
| 24 | - | |
| 25 | - @Override | |
| 26 | - public String getTableIdentifierStrategyName(final TableIdentifier identifier) { | |
| 27 | - Set<String> columns = this.tables.get(identifier.getName()); | |
| 28 | - if (columns != null) { | |
| 29 | - if (columns.contains("ID") || columns.contains("id")) { | |
| 30 | - return "sequence"; | |
| 31 | - } | |
| 32 | - } | |
| 33 | - return null; | |
| 34 | - } | |
| 35 | - | |
| 36 | - @Override | |
| 37 | - public Properties getTableIdentifierProperties(final TableIdentifier identifier) { | |
| 38 | - Properties params = new Properties(); | |
| 39 | - String name = identifier.getName(); | |
| 40 | - Set<String> columns = this.tables.get(name); | |
| 41 | - if (columns != null) { | |
| 42 | - if (columns.contains("ID") || columns.contains("id")) { | |
| 43 | - if (name.startsWith("ms_") || name.startsWith("MS_")) { | |
| 44 | - params.put("sequence", "sq_master"); | |
| 45 | - } else if (name.startsWith("tr_") || name.startsWith("TR_")) { | |
| 46 | - params.put("sequence", "sq_transaction"); | |
| 47 | - } | |
| 48 | - } | |
| 49 | - } | |
| 50 | - return params; | |
| 51 | - } | |
| 52 | - | |
| 53 | - @Override | |
| 54 | - public List<String> getPrimaryKeyColumnNames(final TableIdentifier identifier) { | |
| 55 | - List<String> list = new ArrayList<>(); | |
| 56 | - list.add("ID"); | |
| 57 | - return list; | |
| 58 | - } | |
| 59 | - | |
| 60 | - @Override | |
| 61 | - public String tableToIdentifierPropertyName(final TableIdentifier identifier) { | |
| 62 | - return null; | |
| 63 | - } | |
| 64 | - | |
| 65 | - @Override | |
| 66 | - public String tableToCompositeIdName(final TableIdentifier identifier) { | |
| 67 | - return null; | |
| 68 | - } | |
| 69 | -} | |
| 1 | +package common.db.dao.hibernate.reveng; | |
| 2 | + | |
| 3 | +import java.sql.Types; | |
| 4 | +import java.util.ArrayList; | |
| 5 | +import java.util.HashMap; | |
| 6 | +import java.util.HashSet; | |
| 7 | +import java.util.List; | |
| 8 | +import java.util.Map; | |
| 9 | +import java.util.Properties; | |
| 10 | +import java.util.Set; | |
| 11 | + | |
| 12 | +import org.hibernate.id.enhanced.SequenceStyleGenerator; | |
| 13 | +import org.hibernate.tool.api.reveng.RevengSettings; | |
| 14 | +import org.hibernate.tool.api.reveng.TableIdentifier; | |
| 15 | +import org.hibernate.tool.internal.reveng.strategy.AbstractStrategy; | |
| 16 | + | |
| 17 | +public final class DefaultStrategy extends AbstractStrategy { | |
| 18 | + | |
| 19 | + private final Map<String, Set<String>> tables = new HashMap<>(); | |
| 20 | + | |
| 21 | + @Override | |
| 22 | + public void setSettings(RevengSettings settings) { | |
| 23 | + settings.setCreateCollectionForForeignKey(false); | |
| 24 | + settings.setCreateManyToOneForForeignKey(false); | |
| 25 | + super.setSettings(settings); | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public boolean excludeColumn(final TableIdentifier identifier, final String columnName) { | |
| 30 | + Set<String> columns = this.tables.computeIfAbsent(identifier.getName(), k -> new HashSet<>()); | |
| 31 | + columns.add(columnName); | |
| 32 | + return super.excludeColumn(identifier, columnName); | |
| 33 | + } | |
| 34 | + | |
| 35 | + @Override | |
| 36 | + public String getTableIdentifierStrategyName(final TableIdentifier identifier) { | |
| 37 | + Set<String> columns = this.tables.get(identifier.getName()); | |
| 38 | + if (columns != null) { | |
| 39 | + if (columns.contains("ID") || columns.contains("id")) { | |
| 40 | + return "sequence"; | |
| 41 | + } | |
| 42 | + } | |
| 43 | + return null; | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public Properties getTableIdentifierProperties(final TableIdentifier identifier) { | |
| 48 | + Properties params = new Properties(); | |
| 49 | + String name = identifier.getName(); | |
| 50 | + Set<String> columns = this.tables.get(name); | |
| 51 | + if (columns != null) { | |
| 52 | + if (columns.contains("ID") || columns.contains("id")) { | |
| 53 | + if (name.startsWith("ms_") || name.startsWith("MS_")) { | |
| 54 | + params.put(SequenceStyleGenerator.SEQUENCE_PARAM, "sq_master"); | |
| 55 | + } else if (name.startsWith("tr_") || name.startsWith("TR_")) { | |
| 56 | + params.put(SequenceStyleGenerator.SEQUENCE_PARAM, "sq_transaction"); | |
| 57 | + } else { | |
| 58 | + params.put(SequenceStyleGenerator.SEQUENCE_PARAM, "generator"); | |
| 59 | + } | |
| 60 | + } | |
| 61 | + } | |
| 62 | + return params; | |
| 63 | + } | |
| 64 | + | |
| 65 | + @Override | |
| 66 | + public List<String> getPrimaryKeyColumnNames(final TableIdentifier identifier) { | |
| 67 | + List<String> list = new ArrayList<>(); | |
| 68 | + list.add("ID"); | |
| 69 | + return list; | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public String columnToHibernateTypeName(final TableIdentifier table, final String columnName, final int sqlType, final int length, | |
| 74 | + final int precision, final int scale, final boolean nullable, final boolean generatedIdentifier) { | |
| 75 | + if (sqlType == Types.TIMESTAMP) { | |
| 76 | + return java.util.Date.class.getName(); | |
| 77 | + } | |
| 78 | + return super.columnToHibernateTypeName(table, columnName, sqlType, length, precision, scale, nullable, generatedIdentifier); | |
| 79 | + } | |
| 80 | +} |