Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8621bad

Browse files
committed
HHH-19879: Move Hibernate Tools' reveng module to Hibernate ORM and merge the relevant ant/gradle/maven plugins
- Add the Reverse Engineering moduleSigned-off-by: Koen Aers <koen.aers@gmail.com>
1 parent009f6b1 commit8621bad

File tree

231 files changed

+23814
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+23814
-0
lines changed

‎settings.gradle‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ project(':hibernate-maven-plugin').projectDir = new File(rootProject.projectDir,
359359
include'hibernate-ant'
360360
project(':hibernate-ant').projectDir=newFile(rootProject.projectDir,"tooling/hibernate-ant")
361361

362+
include'hibernate-reveng'
363+
project(':hibernate-reveng').projectDir=newFile(rootProject.projectDir,"tooling/hibernate-reveng")
364+
362365
rootProject.children.each { project->
363366
project.buildFileName="${project.name}.gradle"
364367
assert project.projectDir.isDirectory()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id"local.publishing-java-module"
3+
}
4+
5+
description="Library providing functionality to perform reverse engineering Hibernate related artefacts from an existing database"
6+
7+
dependencies {
8+
implementation project(':hibernate-core' )
9+
implementation project(':hibernate-ant' )
10+
implementation"org.apache.commons:commons-collections4:4.5.0"
11+
implementation"com.google.googlejavaformat:google-java-format:1.27.0"
12+
implementation"org.freemarker:freemarker:2.3.34"
13+
implementation"org.antlr:antlr4-runtime:4.13.2"
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
packageorg.hibernate.tool.reveng.api.core;
6+
7+
publicinterfaceAssociationInfo {
8+
9+
StringgetCascade();
10+
StringgetFetch();
11+
BooleangetUpdate();
12+
BooleangetInsert();
13+
14+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
packageorg.hibernate.tool.reveng.api.core;
6+
7+
importorg.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
8+
9+
importjava.util.Iterator;
10+
importjava.util.Map;
11+
12+
/**
13+
* Interface for fetching metadata from databases.
14+
* The dialect is configured with a ConnectionProvider but is not
15+
* required to actually use any connections.
16+
*
17+
* The metadata methods all returns Iterator and allows for more efficient and partial reads
18+
* for those databases that has "flakey" JDBC metadata implementions.
19+
*
20+
* @author Max Rydahl Andersen
21+
*
22+
*/
23+
publicinterfaceRevengDialect {
24+
25+
/**
26+
* Configure the metadatadialect.
27+
* @param connectionProvider a {@link ConnectionProvider}
28+
*/
29+
publicvoidconfigure(ConnectionProviderconnectionProvider);
30+
31+
/**
32+
* Return iterator over the tables that mathces catalog, schema and table
33+
*
34+
* @param catalog name or null
35+
* @param schema name or null
36+
* @param table name or null
37+
* @return iterator with map elements that has "TABLE_NAME", "TABLE_SCHEMA", "TABLE_CAT", "TABLE_TYPE" keys.
38+
*/
39+
Iterator<Map<String,Object>>getTables(Stringcatalog,Stringschema,Stringtable);
40+
41+
/**
42+
* Close the iterator.
43+
* @param iterator an iterator returned from one of methods on this dialect
44+
*/
45+
voidclose(Iterator<?>iterator);
46+
47+
/**
48+
* Return iterator over the indexes that mathces catalog, schema and table
49+
*
50+
* @param catalog name or null
51+
* @param schema name or null
52+
* @param table name or null
53+
* @return iterator with map elements that has "TABLE_NAME", "TABLE_SCHEMA", "TABLE_CAT", "INDEX_NAME", "COLUMN_NAME", "NON_UNIQUE", "TYPE" keys.
54+
*/
55+
Iterator<Map<String,Object>>getIndexInfo(Stringcatalog,Stringschema,Stringtable);
56+
57+
/**
58+
* Return iterator over the columns that mathces catalog, schema and table
59+
*
60+
* @param catalog name or null
61+
* @param schema name or null
62+
* @param table name or null
63+
* @param column name or null
64+
* @return iterator with map elements that has "TABLE_NAME", "TABLE_SCHEMA", "TABLE_CAT", "DATA_TYPE", "TYPE_NAME", "COLUMN_NAME", "NULLABLE", "COLUMN_SIZE", "DECIMAL_DIGITS"
65+
*/
66+
Iterator<Map<String,Object>>getColumns(Stringcatalog,Stringschema,Stringtable,Stringcolumn);
67+
68+
/**
69+
* Return iterator over the columns that mathces catalog, schema and table
70+
*
71+
* @param catalog name or null
72+
* @param schema name or null
73+
* @param table name or null
74+
* @return iterator with map elements that has "TABLE_NAME", "TABLE_SCHEMA", "TABLE_CAT", "COLUMN_NAME", "KEY_SEQ", "PK_NAME",
75+
*/
76+
Iterator<Map<String,Object>>getPrimaryKeys(Stringcatalog,Stringschema,Stringname);
77+
78+
79+
/**
80+
* Return iterator over the exported foreign keys that mathces catalog, schema and table
81+
*
82+
* @param catalog name or null
83+
* @param schema name or null
84+
* @param table name or null
85+
* @return iterator with map elements that has "TABLE_NAME", "TABLE_SCHEMA", "TABLE_CAT", "FKTABLE_CAT", "FKTABLE_SCHEM", "FKTABLE_NAME", "FK_NAME", "KEY_SEQ"
86+
*/
87+
Iterator<Map<String,Object>>getExportedKeys(Stringcatalog,Stringschema,Stringtable);
88+
89+
/**
90+
* Does this name need quoting
91+
*
92+
* @param name
93+
* @return
94+
*/
95+
booleanneedQuote(Stringname);
96+
97+
/**
98+
* Close any resources this dialect might have used.
99+
*/
100+
voidclose();
101+
102+
/**
103+
* Use database (possible native) metadata to suggest identifier strategy.
104+
*
105+
* @param catalog
106+
* @param schema
107+
* @param name
108+
* @return iterator with map elements that has "TABLE_NAME", "TABLE_SCHEMA", "TABLE_CAT", "HIBERNATE_STRATEGY" (null if no possible to determine strategy, otherwise return hibernate identifier strategy name/classname)
109+
*/
110+
publicIterator<Map<String,Object>>getSuggestedPrimaryKeyStrategyName(Stringcatalog,Stringschema,Stringtable);
111+
112+
113+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
packageorg.hibernate.tool.reveng.api.core;
6+
7+
importorg.hibernate.dialect.Dialect;
8+
importorg.hibernate.dialect.H2Dialect;
9+
importorg.hibernate.dialect.HSQLDialect;
10+
importorg.hibernate.dialect.MySQLDialect;
11+
importorg.hibernate.dialect.OracleDialect;
12+
importorg.hibernate.dialect.SQLServerDialect;
13+
importorg.hibernate.internal.util.ReflectHelper;
14+
importorg.hibernate.tool.reveng.internal.core.dialect.H2MetaDataDialect;
15+
importorg.hibernate.tool.reveng.internal.core.dialect.HSQLMetaDataDialect;
16+
importorg.hibernate.tool.reveng.internal.core.dialect.JDBCMetaDataDialect;
17+
importorg.hibernate.tool.reveng.internal.core.dialect.MySQLMetaDataDialect;
18+
importorg.hibernate.tool.reveng.internal.core.dialect.OracleMetaDataDialect;
19+
importorg.hibernate.tool.reveng.internal.core.dialect.SQLServerMetaDataDialect;
20+
21+
importjava.lang.reflect.Constructor;
22+
importjava.util.Properties;
23+
24+
publicclassRevengDialectFactory {
25+
26+
privateRevengDialectFactory() {}
27+
28+
publicstaticRevengDialectcreateMetaDataDialect(Dialectdialect,Propertiescfg) {
29+
Stringproperty =cfg.getProperty("hibernatetool.metadatadialect" );
30+
RevengDialectmdd =fromClassName(property);
31+
if(mdd==null) {
32+
mdd =fromDialect(dialect);
33+
}
34+
if(mdd==null) {
35+
mdd =fromDialectName(dialect.getClass().getName());
36+
}
37+
if(mdd==null) {
38+
mdd =newJDBCMetaDataDialect();
39+
}
40+
returnmdd;
41+
}
42+
43+
publicstaticRevengDialectfromClassName(Stringproperty) {
44+
if (property !=null ) {
45+
try {
46+
Class<?>revengDialectClass =ReflectHelper.classForName(
47+
property,
48+
RevengDialectFactory.class );
49+
Constructor<?>revengDialectConstructor =revengDialectClass.getConstructor();
50+
return (RevengDialect)revengDialectConstructor.newInstance();
51+
}
52+
catch (Throwablee) {
53+
thrownewRuntimeException(
54+
"Could not load MetaDataDialect: " +property,e );
55+
}
56+
}
57+
else {
58+
returnnull;
59+
}
60+
}
61+
62+
publicstaticRevengDialectfromDialect(Dialectdialect) {
63+
if(dialect!=null) {
64+
if(dialectinstanceofOracleDialect) {
65+
returnnewOracleMetaDataDialect();
66+
}
67+
elseif (dialectinstanceofH2Dialect) {
68+
returnnewH2MetaDataDialect();
69+
}
70+
elseif (dialectinstanceofMySQLDialect) {
71+
returnnewMySQLMetaDataDialect();
72+
}
73+
elseif (dialectinstanceofHSQLDialect) {
74+
returnnewHSQLMetaDataDialect();
75+
}
76+
elseif (dialectinstanceofSQLServerDialect) {
77+
returnnewSQLServerMetaDataDialect();
78+
}
79+
}
80+
returnnull;
81+
}
82+
83+
publicstaticRevengDialectfromDialectName(Stringdialect) {
84+
if (dialect.toLowerCase().contains("oracle")) {
85+
returnnewOracleMetaDataDialect();
86+
}
87+
if (dialect.toLowerCase().contains("mysql")) {
88+
returnnewMySQLMetaDataDialect();
89+
}
90+
if (dialect.toLowerCase().contains("h2")) {
91+
returnnewH2MetaDataDialect();
92+
}
93+
if (dialect.toLowerCase().contains("hsql")) {
94+
returnnewHSQLMetaDataDialect();
95+
}
96+
if (dialect.toLowerCase().contains("sqlserver")) {
97+
returnnewSQLServerMetaDataDialect();
98+
}
99+
returnnull;
100+
}
101+
102+
103+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
packageorg.hibernate.tool.reveng.api.core;
6+
7+
publicclassRevengSettings {
8+
9+
10+
finalRevengStrategyrootStrategy;
11+
12+
privateStringdefaultPackageName ="";
13+
privatebooleandetectOptimisticLock =true;
14+
privatebooleancreateCollectionForForeignKey =true;
15+
privatebooleancreateManyToOneForForeignKey =true;
16+
privatebooleandetectManyToMany =true;
17+
privatebooleandetectOneToOne =true;
18+
19+
20+
publicRevengSettings(RevengStrategyrootStrategy) {
21+
this.rootStrategy =rootStrategy;
22+
}
23+
24+
publicRevengSettingssetDefaultPackageName(StringdefaultPackageName) {
25+
if(defaultPackageName==null) {
26+
this.defaultPackageName ="";
27+
}
28+
else {
29+
this.defaultPackageName=defaultPackageName.trim();
30+
}
31+
returnthis;
32+
}
33+
34+
/** return the default packageName. Never null, at least the empty string */
35+
publicStringgetDefaultPackageName() {
36+
returndefaultPackageName;
37+
}
38+
39+
/** If true, reverse engineering strategy will try and autodetect columns for optimistc locking, e.g. VERSION and TIMESTAMP */
40+
publicbooleangetDetectOptimsticLock() {
41+
returndetectOptimisticLock ;
42+
}
43+
44+
publicRevengSettingssetDetectOptimisticLock(
45+
booleanoptimisticLockSupportEnabled) {
46+
this.detectOptimisticLock =optimisticLockSupportEnabled;
47+
returnthis;
48+
}
49+
50+
/** if true, a collection will be mapped for each foreignkey */
51+
publicbooleancreateCollectionForForeignKey() {
52+
returncreateCollectionForForeignKey;
53+
}
54+
55+
56+
publicRevengSettingssetCreateCollectionForForeignKey(
57+
booleancreateCollectionForForeignKey) {
58+
this.createCollectionForForeignKey =createCollectionForForeignKey;
59+
returnthis;
60+
}
61+
62+
/** if true, a many-to-one association will be created for each foreignkey found */
63+
publicbooleancreateManyToOneForForeignKey() {
64+
returncreateManyToOneForForeignKey;
65+
}
66+
67+
publicRevengSettingssetCreateManyToOneForForeignKey(
68+
booleancreateManyToOneForForeignKey) {
69+
this.createManyToOneForForeignKey =createManyToOneForForeignKey;
70+
returnthis;
71+
}
72+
73+
publicRevengSettingssetDetectManyToMany(booleanb) {
74+
this.detectManyToMany =b;
75+
returnthis;
76+
}
77+
78+
publicbooleangetDetectManyToMany() {
79+
returndetectManyToMany;
80+
}
81+
82+
publicRevengSettingssetDetectOneToOne(booleanb) {
83+
this.detectOneToOne =b;
84+
returnthis;
85+
}
86+
87+
publicbooleangetDetectOneToOne() {
88+
returndetectOneToOne;
89+
}
90+
91+
/** return the top/root strategy. Allows a lower strategy to ask another question. Be aware of possible recursive loops; e.g. do not call the root.tableToClassName in tableToClassName of a custom reversengineeringstrategy. */
92+
publicRevengStrategygetRootStrategy() {
93+
returnrootStrategy;
94+
}
95+
96+
97+
98+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp