You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by al...@apache.org on 2017/10/23 00:35:07 UTC
[2/2] juddi git commit: JUDDI-985 updating the ddl generator after
the hibernate update
JUDDI-985 updating the ddl generator after the hibernate update
Project: http://git-wip-us.apache.org/repos/asf/juddi/repo
Commit: http://git-wip-us.apache.org/repos/asf/juddi/commit/79f0ab8c
Tree: http://git-wip-us.apache.org/repos/asf/juddi/tree/79f0ab8c
Diff: http://git-wip-us.apache.org/repos/asf/juddi/diff/79f0ab8c
Branch: refs/heads/master
Commit: 79f0ab8c9841367e546251ac606f7335bed92529
Parents: 9c33360
Author: Alex O'Ree <al...@apache.org>
Authored: Sun Oct 22 20:34:42 2017 -0400
Committer: Alex O'Ree <al...@apache.org>
Committed: Sun Oct 22 20:34:42 2017 -0400
----------------------------------------------------------------------
juddi-ddl-generator/pom.xml | 187 +++++++++----------
.../org/apache/juddi/ddl/generator/App.java | 73 +++++---
2 files changed, 141 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/juddi/blob/79f0ab8c/juddi-ddl-generator/pom.xml
----------------------------------------------------------------------
diff --git a/juddi-ddl-generator/pom.xml b/juddi-ddl-generator/pom.xml
index 7d80605..53c3acf 100644
--- a/juddi-ddl-generator/pom.xml
+++ b/juddi-ddl-generator/pom.xml
@@ -1,102 +1,101 @@
<?xml version="1.0"?>
<!--
- * Copyright 2001-2009 The Apache Software Foundation.
- *
- * 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.
- *
- */ -->
+* Copyright 2001-2009 The Apache Software Foundation.
+*
+* 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.
+*
+*/ -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.juddi</groupId>
- <artifactId>juddi-parent</artifactId>
- <version>3.3.5-SNAPSHOT</version>
- </parent>
- <artifactId>juddi-ddl-generator</artifactId>
- <name>juddi-ddl-generator</name>
- <url>http://maven.apache.org</url>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.juddi</groupId>
- <artifactId>juddi-core</artifactId>
- <version>3.3.5-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- </dependency>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.juddi</groupId>
+ <artifactId>juddi-parent</artifactId>
+ <version>3.3.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>juddi-ddl-generator</artifactId>
+ <name>juddi-ddl-generator</name>
+ <url>http://maven.apache.org</url>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.juddi</groupId>
+ <artifactId>juddi-core</artifactId>
+ <version>3.3.5-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
+
+
- <dependency>
- <groupId>org.postgresql</groupId>
- <artifactId>postgresql</artifactId>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>my-execution</id>
- <phase>compile</phase>
- <goals>
- <goal>java</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <mainClass>org.apache.juddi.ddl.generator.App</mainClass>
- <arguments>
- <argument>juddi-core/target/classes/org/apache/juddi/model/</argument>
- </arguments>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-swf-files</id>
- <phase>test</phase>
- <goals>
- <goal>run</goal>
- </goals>
- <configuration>
- <target name="copy ddl to doc folder">
- <copy todir="../docs/db/ddl/">
- <fileset dir="${project.build.directory}/../" includes="*.ddl">
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>my-execution</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>org.apache.juddi.ddl.generator.App</mainClass>
+ <arguments>
+ <argument>juddi-core/target/classes/org/apache/juddi/model/</argument>
+ </arguments>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-swf-files</id>
+ <phase>test</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target name="copy ddl to doc folder">
+ <copy todir="../docs/db/ddl/">
+ <fileset dir="${project.build.directory}/../" includes="*.ddl">
- </fileset></copy>
- </target>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ </fileset>
+ </copy>
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/juddi/blob/79f0ab8c/juddi-ddl-generator/src/main/java/org/apache/juddi/ddl/generator/App.java
----------------------------------------------------------------------
diff --git a/juddi-ddl-generator/src/main/java/org/apache/juddi/ddl/generator/App.java b/juddi-ddl-generator/src/main/java/org/apache/juddi/ddl/generator/App.java
index 3db85b9..33e922e 100644
--- a/juddi-ddl-generator/src/main/java/org/apache/juddi/ddl/generator/App.java
+++ b/juddi-ddl-generator/src/main/java/org/apache/juddi/ddl/generator/App.java
@@ -1,4 +1,5 @@
package org.apache.juddi.ddl.generator;
+
/*
* Copyright 2001-2008 The Apache Software Foundation.
*
@@ -16,46 +17,55 @@ package org.apache.juddi.ddl.generator;
*/
import java.io.File;
import java.io.IOException;
-import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.EnumSet;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.boot.Metadata;
+import org.hibernate.boot.MetadataSources;
+import org.hibernate.boot.registry.StandardServiceRegistry;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.tool.hbm2ddl.SchemaExport.Action;
+import org.hibernate.tool.schema.TargetType;
/**
- * Source: http://jandrewthompson.blogspot.com/2009/10/how-to-generate-ddl-scripts-from.html
+ * Source:
+ * http://jandrewthompson.blogspot.com/2009/10/how-to-generate-ddl-scripts-from.html
+ * https://stackoverflow.com/a/33761464/1203182
+ * https://stackoverflow.com/a/41894432/1203182
+ *
* @author john.thompson
+ * @author Alex O'Ree
*
*/
public class App {
- private AnnotationConfiguration cfg;
+ private List<Class> jpaClasses = new ArrayList<>();
public App(String packageName) throws Exception {
- cfg = new AnnotationConfiguration();
- cfg.setProperty("hibernate.hbm2ddl.auto", "create");
+
List<Class> classesForPackage = getClassesForPackage(org.apache.juddi.model.Address.class.getPackage());
for (Class<Object> clazz : classesForPackage) {
- cfg.addAnnotatedClass(clazz);
+
+ jpaClasses.add(clazz);
}
}
-
- public App(String dir,String packageName) throws Exception {
- cfg = new AnnotationConfiguration();
- cfg.setProperty("hibernate.hbm2ddl.auto", "create");
+
+ public App(String dir, String packageName) throws Exception {
+
List<Class> c = new ArrayList<Class>();
- processDirectory(new File("../" + dir), packageName,c);
-
- processDirectory(new File(dir), packageName,c);
+ processDirectory(new File("../" + dir), packageName, c);
+
+ processDirectory(new File(dir), packageName, c);
for (Class<Object> clazz : c) {
- cfg.addAnnotatedClass(clazz);
+
+ jpaClasses.add(clazz);
}
-
-
+
}
/**
@@ -64,12 +74,24 @@ public class App {
* @param dbDialect to use
*/
private void generate(Dialect dialect) {
- cfg.setProperty("hibernate.dialect", dialect.getDialectClass());
- SchemaExport export = new SchemaExport(cfg);
+ StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
+ ssrb.applySetting("hibernate.dialect", dialect.getDialectClass());
+ StandardServiceRegistry standardServiceRegistry = ssrb.build();
+
+ MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
+ for (Class clzz : jpaClasses) {
+ metadataSources.addAnnotatedClass(clzz);
+ }
+
+ Metadata metadata = metadataSources.buildMetadata();
+
+ SchemaExport export = new SchemaExport();
+
export.setDelimiter(";");
export.setOutputFile(dialect.name().toLowerCase() + ".ddl");
- export.execute(true, false, false, true);
+ //export.execute(true, false, false, true);
+ export.execute(EnumSet.of(TargetType.SCRIPT), Action.BOTH, metadata);
}
/**
@@ -78,7 +100,7 @@ public class App {
public static void main(String[] args) throws Exception {
App gen = null;
if (args != null && args.length == 1) {
- gen = new App(args[0],"org.apache.juddi.model");
+ gen = new App(args[0], "org.apache.juddi.model");
} else {
gen = new App("org.apache.juddi.model");
}
@@ -99,11 +121,12 @@ public class App {
}
}
- private static void processDirectory(File directory, String pkgname,List<Class> classes) {
+ private static void processDirectory(File directory, String pkgname, List<Class> classes) {
log("Reading Directory '" + directory + "'");
// Get the list of the files contained in the package
- if (!directory.exists())
+ if (!directory.exists()) {
return;
+ }
String[] files = directory.list();
for (int i = 0; i < files.length; i++) {
String fileName = files[i];
@@ -206,7 +229,7 @@ public class App {
directory = new File(resource.toURI().getPath());
} catch (NullPointerException x) {
throw new ClassNotFoundException(packageName + " (" + directory
- + ") does not appear to be a valid package");
+ + ") does not appear to be a valid package");
}
if (directory.exists()) {
String[] files = directory.list();
@@ -214,7 +237,7 @@ public class App {
if (files[i].endsWith(".class")) {
// removes the .class extension
classes.add(Class.forName(packageName + '.'
- + files[i].substring(0, files[i].length() - 6)));
+ + files[i].substring(0, files[i].length() - 6)));
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@juddi.apache.org
For additional commands, e-mail: commits-help@juddi.apache.org