Skip to content
Permalink
Browse files
JUDDI-985 updating the ddl generator after the hibernate update
  • Loading branch information
spyhunter99 committed Oct 23, 2017
1 parent 9c33360 commit 79f0ab8c9841367e546251ac606f7335bed92529
Showing 2 changed files with 141 additions and 119 deletions.
@@ -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>
@@ -1,4 +1,5 @@
package org.apache.juddi.ddl.generator;

/*
* Copyright 2001-2008 The Apache Software Foundation.
*
@@ -16,46 +17,55 @@
*/
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 App(String dir,String packageName) throws Exception {
* @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 @@ private void generate(Dialect dialect) {
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 @@ private static Class<?> loadClass(String className) {
}
}

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,15 +229,15 @@ private List<Class> getClasses(String packageName) throws Exception {
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();
for (int i = 0; i < files.length; i++) {
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)));
}
}
}

0 comments on commit 79f0ab8

Please sign in to comment.