Changeset 6174
- Timestamp:
- 11/29/06 17:38:12
- Files:
-
- trunk/example/example.iml (modified) (2 diffs)
- trunk/example/example.ipr (modified) (13 diffs)
- trunk/example/src/jerbil/example/JerbilEntity.java (modified) (2 diffs)
- trunk/lib/jerbil/hibernate_task.rb (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/example/example.iml
r6049 r6174 2 2 <module version="4" relativePaths="true" type="JAVA_MODULE"> 3 3 <component name="ModuleRootManager" /> 4 <component name="NewModuleRootManager" >4 <component name="NewModuleRootManager" inherit-compiler-output="false"> 5 5 <output url="file://$MODULE_DIR$/classes" /> 6 6 <exclude-output /> … … 29 29 </library> 30 30 </orderEntry> 31 <orderEntry type="module-library"> 32 <library> 33 <CLASSES> 34 <root url="jar://$MODULE_DIR$/lib/hibernate-annotations.jar!/" /> 35 </CLASSES> 36 <JAVADOC /> 37 <SOURCES /> 38 </library> 39 </orderEntry> 31 40 <orderEntryProperties /> 32 41 </component> trunk/example/example.ipr
r6049 r6174 4 4 <defaultAnt bundledAnt="true" /> 5 5 </component> 6 <component name="BuildJarProjectSettings"> 7 <option name="BUILD_JARS_ON_MAKE" value="false" /> 8 </component> 9 <component name="CodeStyleProjectProfileManger"> 10 <option name="PROJECT_PROFILE" /> 11 <option name="USE_PROJECT_LEVEL_SETTINGS" value="false" /> 12 </component> 6 13 <component name="CodeStyleSettingsManager"> 7 14 <option name="PER_PROJECT_SETTINGS" /> … … 10 17 <component name="CompilerConfiguration"> 11 18 <option name="DEFAULT_COMPILER" value="Javac" /> 12 <option name="CLEAR_OUTPUT_DIRECTORY" value="false" />13 19 <option name="DEPLOY_AFTER_MAKE" value="0" /> 14 20 <resourceExtensions> … … 33 39 </component> 34 40 <component name="DependencyValidationManager" /> 41 <component name="EclipseCompilerSettings"> 42 <option name="DEBUGGING_INFO" value="true" /> 43 <option name="GENERATE_NO_WARNINGS" value="true" /> 44 <option name="DEPRECATION" value="false" /> 45 <option name="ADDITIONAL_OPTIONS_STRING" value="" /> 46 <option name="MAXIMUM_HEAP_SIZE" value="128" /> 47 </component> 48 <component name="EclipseEmbeddedCompilerSettings"> 49 <option name="DEBUGGING_INFO" value="true" /> 50 <option name="GENERATE_NO_WARNINGS" value="true" /> 51 <option name="DEPRECATION" value="false" /> 52 <option name="ADDITIONAL_OPTIONS_STRING" value="" /> 53 <option name="MAXIMUM_HEAP_SIZE" value="128" /> 54 </component> 35 55 <component name="EntryPointsManager"> 36 56 <entry_points /> … … 42 62 </component> 43 63 <component name="GUI Designer component loader factory" /> 64 <component name="IdProvider" IDEtalkID="3DEFDCA7E26A1BC38A63539E860BD2E6" /> 65 <component name="InspectionProjectProfileManager"> 66 <option name="PROJECT_PROFILE" value="Project Default" /> 67 <option name="USE_PROJECT_LEVEL_SETTINGS" value="false" /> 68 <scopes /> 69 <profiles> 70 <profile version="1.0" is_locked="false"> 71 <option name="myName" value="Project Default" /> 72 <option name="myLocal" value="false" /> 73 <used_levels> 74 <error> 75 <option name="myName" value="ERROR" /> 76 <option name="myVal" value="400" /> 77 </error> 78 <warning> 79 <option name="myName" value="WARNING" /> 80 <option name="myVal" value="300" /> 81 </warning> 82 <information> 83 <option name="myName" value="INFO" /> 84 <option name="myVal" value="200" /> 85 </information> 86 <server> 87 <option name="myName" value="SERVER PROBLEM" /> 88 <option name="myVal" value="100" /> 89 </server> 90 </used_levels> 91 </profile> 92 </profiles> 93 </component> 44 94 <component name="JavacSettings"> 45 95 <option name="DEBUGGING_INFO" value="true" /> … … 63 113 <option name="OTHER_OPTIONS" value="" /> 64 114 <option name="HEAP_SIZE" /> 115 <option name="LOCALE" /> 65 116 <option name="OPEN_IN_BROWSER" value="true" /> 66 117 </component> … … 73 124 <option name="ADDITIONAL_OPTIONS_STRING" value="" /> 74 125 </component> 126 <component name="LogConsolePreferences"> 127 <option name="FILTER_ERRORS" value="false" /> 128 <option name="FILTER_WARNINGS" value="false" /> 129 <option name="FILTER_INFO" value="true" /> 130 <option name="CUSTOM_FILTER" /> 131 </component> 75 132 <component name="Palette2"> 76 133 <group name="Swing"> 77 <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" >134 <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> 78 135 <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> 79 136 </item> 80 <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" >137 <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> 81 138 <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> 82 139 </item> 83 <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" >140 <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> 84 141 <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> 85 142 </item> 86 <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" >143 <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> 87 144 <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> 88 145 </item> 89 <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" >146 <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> 90 147 <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> 91 148 <initial-values> … … 93 150 </initial-values> 94 151 </item> 95 <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" >152 <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> 96 153 <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> 97 154 <initial-values> … … 99 156 </initial-values> 100 157 </item> 101 <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" >158 <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> 102 159 <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> 103 160 <initial-values> … … 105 162 </initial-values> 106 163 </item> 107 <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" >164 <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> 108 165 <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> 109 166 <initial-values> … … 111 168 </initial-values> 112 169 </item> 113 <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" >170 <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> 114 171 <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> 115 172 <preferred-size width="150" height="-1" /> 116 173 </default-constraints> 117 174 </item> 118 <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" >175 <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> 119 176 <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> 120 177 <preferred-size width="150" height="-1" /> 121 178 </default-constraints> 122 179 </item> 123 <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" >180 <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> 124 181 <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> 125 182 <preferred-size width="150" height="-1" /> 126 183 </default-constraints> 127 184 </item> 128 <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" >129 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> 130 <preferred-size width="150" height="50" /> 131 </default-constraints> 132 </item> 133 <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" >134 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> 135 <preferred-size width="150" height="50" /> 136 </default-constraints> 137 </item> 138 <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" >139 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> 140 <preferred-size width="150" height="50" /> 141 </default-constraints> 142 </item> 143 <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" >185 <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> 186 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> 187 <preferred-size width="150" height="50" /> 188 </default-constraints> 189 </item> 190 <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> 191 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> 192 <preferred-size width="150" height="50" /> 193 </default-constraints> 194 </item> 195 <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> 196 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> 197 <preferred-size width="150" height="50" /> 198 </default-constraints> 199 </item> 200 <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> 144 201 <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> 145 202 </item> 146 <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" >147 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> 148 <preferred-size width="150" height="50" /> 149 </default-constraints> 150 </item> 151 <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" >203 <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> 204 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> 205 <preferred-size width="150" height="50" /> 206 </default-constraints> 207 </item> 208 <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> 152 209 <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> 153 210 <preferred-size width="150" height="50" /> 154 211 </default-constraints> 155 212 </item> 156 <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" >157 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> 158 <preferred-size width="150" height="50" /> 159 </default-constraints> 160 </item> 161 <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" >213 <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> 214 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> 215 <preferred-size width="150" height="50" /> 216 </default-constraints> 217 </item> 218 <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> 162 219 <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> 163 220 <preferred-size width="200" height="200" /> 164 221 </default-constraints> 165 222 </item> 166 <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" >223 <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> 167 224 <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> 168 225 <preferred-size width="200" height="200" /> 169 226 </default-constraints> 170 227 </item> 171 <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" >228 <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> 172 229 <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> 173 230 </item> 174 <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" >231 <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> 175 232 <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> 233 </item> 234 <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> 235 <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> 236 </item> 237 <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> 238 <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> 239 </item> 240 <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> 241 <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> 242 <preferred-size width="-1" height="20" /> 243 </default-constraints> 244 </item> 245 <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> 246 <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> 247 </item> 248 <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> 249 <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> 176 250 </item> 177 251 </group> … … 183 257 </component> 184 258 <component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="1.5" /> 259 <component name="ProjectRunConfigurationManager" /> 185 260 <component name="RmicSettings"> 186 261 <option name="IS_EANABLED" value="false" /> … … 189 264 <option name="GENERATE_IIOP_STUBS" value="false" /> 190 265 <option name="ADDITIONAL_OPTIONS_STRING" value="" /> 266 </component> 267 <component name="StarteamVcsAdapter" /> 268 <component name="VssVcs" /> 269 <component name="com.intellij.jsf.UserDefinedFacesConfigs"> 270 <option name="USER_DEFINED_CONFIGS"> 271 <value> 272 <list size="0" /> 273 </value> 274 </option> 191 275 </component> 192 276 <component name="com.sixrr.metrics.MetricsReloaded"> … … 205 289 <option name="INSTRUMENT_CLASSES" value="true" /> 206 290 <option name="COPY_FORMS_RUNTIME_TO_OUTPUT" value="true" /> 291 <option name="DEFAULT_LAYOUT_MANAGER" value="GridLayoutManager" /> 207 292 </component> 208 293 <UsedPathMacros /> trunk/example/src/jerbil/example/JerbilEntity.java
r6049 r6174 1 1 package jerbil.example; 2 3 import org.hibernate.annotations.Index; 2 4 3 5 import javax.persistence.Entity; … … 24 26 } 25 27 28 @Index( name = "name_idx" ) 26 29 public String getName() { 27 30 return name; trunk/lib/jerbil/hibernate_task.rb
r6145 r6174 7 7 module Jerbil 8 8 module Hibernate 9 # Generates a SQL schema from EJB3/Hibernate-annotated classes usingHibernate's9 # Generates a SQL schema from EJB3/Hibernate-annotated classes like Hibernate's 10 10 # SchemaExport tool. Typically Jerbil::AptTask is used to compile source files and 11 11 # gather a list of entities which then gets serialized to a YAML file. 12 # ExportSchemaTask then reads this file and uses Hibernate's schema export er to13 # generate SQL12 # ExportSchemaTask then reads this file and uses Hibernate's schema exporting 13 # features to generate SQL 14 14 # 15 15 # == Example … … 26 26 attr_accessor :schemafile 27 27 28 # A file containing a list of entities (<em>javax.persi tence.Entity</em>),28 # A file containing a list of entities (<em>javax.persistence.Entity</em>), 29 29 # serialized as a list of strings (YAML format). 30 30 attr_accessor :entities_yml … … 36 36 # SQL statements to be executed before generated sql. 37 37 attr_accessor :preamble 38 attr_accessor :epilogue 38 39 39 40 # FQN of a package containing package-info.java to be used by … … 41 42 attr_accessor :package 42 43 44 # Pretty printing of generated SQL (default: true) 45 attr_accessor :prettyprint 46 43 47 def initialize(name=:export_schema) 44 48 @name = name 45 49 @dependencies = [] 46 @package = nil47 50 @classfilter = nil 51 @prettyprint = true 48 52 @schemafile = "schema.sql" 49 53 @entities_yml = "entities.yml" … … 65 69 entity_classes = entities.map {|klass| Rjb::import(klass)} 66 70 67 schemaexporter = SchemaExporter.new( entity_classes, schemafile, dialect, package)68 s chemaexporter.export69 71 cfg = get_config(entity_classes, package) 72 sql = cfg.generateSchemaCreationScript(Rjb::import(dialect).new) 73 70 74 schema = "# -- do not edit ---\n" 71 75 schema << "# generated by Jerbil::Hibernate::ExportSchemaTask at #{Time.new}\n\n" … … 73 77 schema << preamble if preamble 74 78 75 schema << IO.read(schemafile) 76 schema = SqlBeautifier.beautify(schema) 79 sql.each do |s| 80 s = format(s) if prettyprint 81 schema << "#{s};" 82 end 77 83 78 #apt.table_views.each do | table, sql | 79 # schema << "\n\ncreate view #{table} AS #{sql};" 80 #end 81 84 schema << "\n\n#{epilogue}" if epilogue 85 82 86 File.open(schemafile, "w") {|file| file << schema } 83 87 end … … 87 91 88 92 # Filters all entities. Useful to only export schema for a subset of classes. 89 # == Example93 # ====Example 90 94 # Jerbil::Hibernate::ExportSchemaTask.new(:export_schema) do |t| 91 95 # t.filter { |classname| classname =~ /^foo/ } … … 94 98 @classfilter = block 95 99 end 96 end97 98 # Turns the hibernate sql output into something readable. Only tested99 # with the mysql dialect.100 class SqlBeautifier101 def SqlBeautifier.beautify(sql)102 newsql = ""103 sql.to_s.each do |line|104 if line =~ /^create table (\w+) \((.+)\)$/105 tablename = $1.strip106 fields = $2.split(',')107 newtabledef = "create table #{tablename} (\n"108 109 fields.each_with_index do | definition, count |110 newtabledef << "\ #{definition.strip}"111 newtabledef << ",\n" if count < fields.length - 1112 end113 newtabledef << "\n);\n\n"114 newsql << newtabledef115 elsif line =~ /^alter table (\w+) ([^,]+),(.+)+$/116 tablename = $1.strip117 index = $2.strip118 constraint = $3.strip119 newsql << "alter table #{tablename}\n #{index},\n #{constraint};\n\n"120 else121 newsql << line122 end123 end124 newsql125 end126 end127 128 # Wrapper class around129 # {org.hibernate.tool.hbm2ddl.SchemaExport.}[http://www.hibernate.org/hib_docs/v3/api/org/hibernate/tool/hbm2ddl/SchemaExport.html]130 class SchemaExporter131 def initialize(classes, outputfile, dialect, package=nil)132 @exporter = SchemaExporter.get_schema_exporter(classes, dialect, package)133 @exporter.setOutputFile(outputfile)134 end135 136 def export137 @exporter.execute(false,false,false,true)138 end139 140 private141 def SchemaExporter.get_schema_exporter(classes, dialect, package=nil)142 schemaexport = Rjb::import('org.hibernate.tool.hbm2ddl.SchemaExport')143 cfg = get_config(classes, package)144 cfg.getProperties.put('hibernate.dialect', dialect)145 146 schemaexporter = schemaexport.new_with_sig 'Lorg.hibernate.cfg.Configuration;', cfg147 100 148 raise "could not create schemaexporter" if schemaexporter.nil? 149 schemaexporter 150 end 151 152 153 def SchemaExporter.get_config(classes, package=nil) 101 protected 102 def get_config(classes, package=nil) 154 103 anncfg = Rjb::import('org.hibernate.cfg.AnnotationConfiguration') 155 104 acfg = anncfg.new … … 164 113 packages << package if package 165 114 packages.each { |pkg| acfg.addPackage(pkg) } 115 166 116 acfg 117 end 118 119 def format(sql) 120 Rjb::import('org.hibernate.pretty.DDLFormatter').new(sql).format 167 121 end 168 122 end
