Class: Jerbil::Hibernate::ExportSchemaTask
Description
Generates a SQL schema from EJB3/Hibernate-annotated classes like Hibernate‘s SchemaExport tool. Typically Jerbil::AptTask is used to compile source files and gather a list of entities which then gets serialized to a YAML file. ExportSchemaTask then reads this file and uses Hibernate‘s schema exporting features to generate SQL
Example
Jerbil::Hibernate::ExportSchemaTask.new(:export_schema) do |t|
t.schemafile = "schema.sql"
t.entities_yml = ENTITIES_YML
end
Attributes
| Name | Read/write? | Description | ||
|---|---|---|---|---|
| dialect | RW | Classname implementing the db dialect, defaults to org.hibernate.dialect.MySQL5Dialect | ||
| entities_yml | RW | A file containing a list of entities (javax.persistence.Entity), serialized as a list of strings (YAML format). | ||
| epilogue | RW | |||
| name | RW | |||
| package | RW | FQN of a package containing package-info.java to be used by hibernate. | ||
| preamble | RW | SQL statements to be executed before generated sql. | ||
| prettyprint | RW | Pretty printing of generated SQL (default: true) | ||
| properties_yml | RW | a file containing a map of properties, property names are keys in the map, and property values are values in the map | ||
| schemafile | RW | SQL schema destination file (default: schema.sql) | ||
Public Class methods
new (name=:export_schema) {|self if block_given?| ...}
# File lib/jerbil/hibernate_task.rb, line 51 51: def initialize(name=:export_schema) 52: @name = name 53: @dependencies = [] 54: @classfilter = nil 55: @prettyprint = true 56: @schemafile = "schema.sql" 57: @entities_yml = "entities.yml" 58: @properties_yml = nil 59: @dialect = "org.hibernate.dialect.MySQL5Dialect" 60: 61: yield self if block_given? 62: define 63: end
Public Instance methods
filter (*args, &block)
Filters all entities. Useful to only export schema for a subset of classes.
Example
Jerbil::Hibernate::ExportSchemaTask.new(:export_schema) do |t|
t.filter { |classname| classname =~ /^foo/ }
end
# File lib/jerbil/hibernate_task.rb, line 104 104: def filter(*args, &block) 105: @classfilter = block 106: end
Protected Instance methods
format (sql)
# File lib/jerbil/hibernate_task.rb, line 130 130: def format(sql) 131: Rjb::import('org.hibernate.pretty.DDLFormatter').new(sql).format 132: end
get_config (classes, properties, package=nil)
# File lib/jerbil/hibernate_task.rb, line 109 109: def get_config(classes, properties, package=nil) 110: anncfg = Rjb::import('org.hibernate.cfg.AnnotationConfiguration') 111: acfg = anncfg.new 112: packages = Set.new 113: classes.each do |clazz| 114: #puts "adding " + clazz.class.to_s 115: acfg.addAnnotatedClass(clazz) 116: 117: pkg = clazz.getPackage 118: packages << pkg.getName if pkg && pkg.getAnnotations.length > 0 119: end 120: packages << package if package 121: packages.each { |pkg| acfg.addPackage(pkg) } 122: 123: properties.each do |key,value| 124: acfg.setProperty(key, value) 125: end 126: 127: acfg 128: end