FileDocCategorySizeDatePackage
SchemaExportTask.javaAPI DocHibernate 3.2.56216Tue Apr 10 04:36:20 BST 2007org.hibernate.tool.hbm2ddl

SchemaExportTask

public class SchemaExportTask extends org.apache.tools.ant.taskdefs.MatchingTask
An Ant task for SchemaExport.
<taskdef name="schemaexport"
classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="class.path"/>

<schemaexport
properties="${build.classes.dir}/hibernate.properties"
quiet="no"
text="no"
drop="no"
delimiter=";"
output="${build.dir}/schema-export.sql">
<fileset dir="${build.classes.dir}">
<include name="*.hbm.xml"/>
</fileset>
</schemaexport>
see
SchemaExport
author
Rong C Ou

Fields Summary
private List
fileSets
private File
propertiesFile
private File
configurationFile
private File
outputFile
private boolean
quiet
private boolean
text
private boolean
drop
private boolean
create
private boolean
haltOnError
private String
delimiter
private String
namingStrategy
Constructors Summary
Methods Summary
public voidaddFileset(org.apache.tools.ant.types.FileSet set)


	    
		fileSets.add(set);
	
public voidexecute()
Execute the task

		try {
			log("Running Hibernate Core SchemaExport."); 
			log("This is an Ant task supporting only mapping files, if you want to use annotations see http://tools.hibernate.org.");
			getSchemaExport( getConfiguration() ).execute(!quiet, !text, drop, create);
		}
		catch (HibernateException e) {
			throw new BuildException("Schema text failed: " + e.getMessage(), e);
		}
		catch (FileNotFoundException e) {
			throw new BuildException("File not found: " + e.getMessage(), e);
		}
		catch (IOException e) {
			throw new BuildException("IOException : " + e.getMessage(), e);
		}
		catch (Exception e) {
			throw new BuildException(e);
		}
	
private org.hibernate.cfg.ConfigurationgetConfiguration()

		Configuration cfg = new Configuration();
		if (namingStrategy!=null) {
			cfg.setNamingStrategy(
					(NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
				);
		}
		if (configurationFile != null) {
			cfg.configure( configurationFile );
		}

		String[] files = getFiles();
		for (int i = 0; i < files.length; i++) {
			String filename = files[i];
			if ( filename.endsWith(".jar") ) {
				cfg.addJar( new File(filename) );
			}
			else {
				cfg.addFile(filename);
			}
		}
		return cfg;
	
private java.lang.String[]getFiles()


		List files = new LinkedList();
		for ( Iterator i = fileSets.iterator(); i.hasNext(); ) {

			FileSet fs = (FileSet) i.next();
			DirectoryScanner ds = fs.getDirectoryScanner( getProject() );

			String[] dsFiles = ds.getIncludedFiles();
			for (int j = 0; j < dsFiles.length; j++) {
				File f = new File(dsFiles[j]);
				if ( !f.isFile() ) {
					f = new File( ds.getBasedir(), dsFiles[j] );
				}

				files.add( f.getAbsolutePath() );
			}
		}

		return ArrayHelper.toStringArray(files);
	
private SchemaExportgetSchemaExport(org.hibernate.cfg.Configuration cfg)

		Properties properties = new Properties();
		properties.putAll( cfg.getProperties() );
		if (propertiesFile == null) {
			properties.putAll( getProject().getProperties() );
		}
		else {
			properties.load( new FileInputStream(propertiesFile) );
		}
		cfg.setProperties(properties);
		return new SchemaExport(cfg)
				.setHaltOnError(haltOnError)
				.setOutputFile( outputFile.getPath() )
				.setDelimiter(delimiter);
	
public voidsetConfig(java.io.File configurationFile)
Set a .cfg.xml file, which will be loaded as a resource, from the classpath

param
configurationFile the path to the resource

		this.configurationFile = configurationFile;
	
public voidsetCreate(boolean create)
Enable "create" mode. Database objects will be created but not first dropped.

param
create true to enable create mode

		this.create = create;
	
public voidsetDelimiter(java.lang.String delimiter)
Set the end of statement delimiter for the generated script

param
delimiter the delimiter

		this.delimiter = delimiter;
	
public voidsetDrop(boolean drop)
Enable "drop" mode. Database objects will be dropped but not recreated.

param
drop true to enable drop mode

		this.drop = drop;
	
public voidsetHaltonerror(boolean haltOnError)

		this.haltOnError = haltOnError;
	
public voidsetNamingStrategy(java.lang.String namingStrategy)

		this.namingStrategy = namingStrategy;
	
public voidsetOutput(java.io.File outputFile)
Set the script output file

param
outputFile the file name

		this.outputFile = outputFile;
	
public voidsetProperties(java.io.File propertiesFile)
Set a properties file

param
propertiesFile the properties file name

		if ( !propertiesFile.exists() ) {
			throw new BuildException("Properties file: " + propertiesFile + " does not exist.");
	}

		log("Using properties file " + propertiesFile, Project.MSG_DEBUG);
		this.propertiesFile = propertiesFile;
	
public voidsetQuiet(boolean quiet)
Enable "quiet" mode. The schema will not be written to standard out.

param
quiet true to enable quiet mode

		this.quiet = quiet;
	
public voidsetText(boolean text)
Enable "text-only" mode. The schema will not be exported to the database.

param
text true to enable text-only mode

		this.text = text;