SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
hibernate                                   sql           import.sql




          LTEX Documented By
          A                                      http://blog.csdn.net/shadowkiss

                                               2009-7-6


                        Hibernate                                 ddl                      im-
    port.sql                classpath                                         hibernate.cfg.xml


1   < property name = " hbm2ddl . auto " > create </ property >
2   or
3   < property name = " hbm2ddl . auto " > create - drop </ property >


                      import.sql                              JVM                 file.encoding
                                        *nix
                  Windows           OS                                                 JVM
               -Dfile.encoding=UTF-8                                 console

                                           UTF-8
                                                          SchemaExport.java :
1   package org . hibernate . tool . hbm2ddl ;
2   ...
3   public class SchemaExport {
4   ...
5         public void execute ( boolean script , boolean export , boolean
               justDrop , boolean justCreate ) {

                                                  1
6   ...
7                           InputStream stream = ConfigHelper .
                                 getResourc e AsSt r eam ( importFile ) ;
8                           importFileReader = new InputS treamR eader ( stream ) ;
9   ...


                                    Hibernate                   JVM                             (
    new InputStreamReader                                  )       SchemaExport




      (I)      classpath                   import.sql.UTF-8


     (II)                                                          import.sql


       1    package cn . qdqn . bms . web . listener ;
       2
       3    import java . io . File ;
       4    import java . io . FileOutputStream ;
       5    import java . io . IOException ;
       6    import java . io . InputStreamReader ;
       7    import java . io . OutputSt re amWrit er ;
       8    import java . io . Reader ;
       9    import java . io . Writer ;
      10    import java . net . URI ;
      11    import java . net . URISyntaxE xc eption ;
      12
      13    import javax . servlet . Ser vlet C onte x tE v e nt ;
      14    import javax . servlet . S er v l e t Co n te x t L i s t e n e r ;
      15
      16    public class HibListener implements S e r v l e t C o n t e x t L i s t e n e r {
      17
      18          /* *
      19              *
      20              */
      21          public void contextDestroyed ( Se r v le t C on t e xt E v en t sce ) {
      22
      23          }


                                                      2
24
25   /* *
26    *
27    */
28   public void contextIn it ialize d ( S er v l et C o nt e x tE v e nt sce ) {
29          String fileName = sce . getSe rvletC ontext () .
                 getInitParameter ( " ddl " ) ;
30          sce . getServletContext () . log ( " Convert " + fileName + "
                 to import . sql " ) ;
31          String srcEnc = fileName . substring ( fileName .
                 lastIndexOf ( " . " ) + 1) ;
32          //      import.sql
33          File importsqlfile = null ;
34          try {
35                importsqlfile = new File ( new URI ( Thread .
                      currentThread ()
36                          . ge t Con tex t Cl a s s L o a d e r () . getResource ( " " )
37                          + " import . sql " ) ) ;
38          } catch ( URISynt ax Except io n e ) {
39                e . printStackTrace () ;
40          }
41
42          //
43          Reader reader = null ;
44          Writer writer = null ;
45          try {
46                reader = new InputStreamR eader ( Thread .
                      currentThread ()
47                          . ge t Con tex t Cl a s s L o a d e r () .
                                 ge tRes o urce A sS t r ea m ( fileName ) ,
48                          srcEnc ) ;
49
50                writer = new OutputS tr ea mW ri te r (
51                          new FileOutputStream ( importsqlfile ) ,
                                 System
52                                       . getProperty ( " file . encoding " ) ) ;
53
54                int c = -1;
55                StringBuffer tempSB = new StringBuffer () ;
56                while (( c = reader . read () ) != -1) {


                                         3
57                               writer . write ( c ) ;
 58                               tempSB . append (( char ) c ) ;
 59                          }
 60                          sce . getServlet Contex t () . log ( tempSB . toString () ) ;
 61                          //
 62                          sce . getServlet Contex t () . log (
 63                                     " Generate import . sql ( "
 64                                                + System . getProperty ( " file .
                                                        encoding " )
 65                                                + " ) success ! " ) ;
 66                     } catch ( Exception e ) {
 67                          e . printStackTrace () ;
 68                     } finally {
 69                          try {
 70                               reader . close () ;
 71                               writer . flush () ;
 72                               writer . close () ;
 73                          } catch ( IOException e ) {
 74                               e . printStackTrace () ;
 75                          }
 76                     }
 77             }
 78
 79     }


(III)           web.xml                                                      SessionFactory
            ,   ssh                       Spring ContextLoaderListener
  1             <! --                hibernate ddl                     import.sql -- >
  2             <! --                                      -- >
  3             < context - param >
  4                     < param - name > ddl </ param - name >
  5                     < param - value > import . sql . UTF -8 </ param - value >
  6             </ context - param >
  7             < listener >
  8                     < listener - class >
  9                          cn . qdqn . bms . web . listener . HibListener
 10                     </ listener - class >
 11             </ listener >




                                                   4
5

Weitere ähnliche Inhalte

Was ist angesagt?

Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
CanSecWest
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
Tony Fabeen
 

Was ist angesagt? (20)

Vert.X: Microservices Were Never So Easy (Clement Escoffier)
Vert.X: Microservices Were Never So Easy (Clement Escoffier)Vert.X: Microservices Were Never So Easy (Clement Escoffier)
Vert.X: Microservices Were Never So Easy (Clement Escoffier)
 
Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD
 
swift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClientswift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClient
 
Do we need Unsafe in Java?
Do we need Unsafe in Java?Do we need Unsafe in Java?
Do we need Unsafe in Java?
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
 
Python twisted
Python twistedPython twisted
Python twisted
 
Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)
 
Preparation for mit ose lab4
Preparation for mit ose lab4Preparation for mit ose lab4
Preparation for mit ose lab4
 
OWASP Proxy
OWASP ProxyOWASP Proxy
OWASP Proxy
 
Down to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsDown to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap Dumps
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
 
Java Runtime: повседневные обязанности JVM
Java Runtime: повседневные обязанности JVMJava Runtime: повседневные обязанности JVM
Java Runtime: повседневные обязанности JVM
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
 
PostgreSQL and PL/Java
PostgreSQL and PL/JavaPostgreSQL and PL/Java
PostgreSQL and PL/Java
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
 
Using ngx_lua in UPYUN
Using ngx_lua in UPYUNUsing ngx_lua in UPYUN
Using ngx_lua in UPYUN
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
Nginx-lua
Nginx-luaNginx-lua
Nginx-lua
 
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
 
From 'dotnet run' to 'hello world'
From 'dotnet run' to 'hello world'From 'dotnet run' to 'hello world'
From 'dotnet run' to 'hello world'
 

Andere mochten auch (8)

Woody's Quotes
Woody's QuotesWoody's Quotes
Woody's Quotes
 
JD James - What we do
JD James - What we do JD James - What we do
JD James - What we do
 
第七颗头骨 & 忘魂花 凤凰
第七颗头骨 & 忘魂花 凤凰第七颗头骨 & 忘魂花 凤凰
第七颗头骨 & 忘魂花 凤凰
 
Science
ScienceScience
Science
 
Photo Album2
Photo Album2Photo Album2
Photo Album2
 
Photo Album1
Photo Album1Photo Album1
Photo Album1
 
Skritter @ IALLT
Skritter @ IALLTSkritter @ IALLT
Skritter @ IALLT
 
Gallery
GalleryGallery
Gallery
 

Ähnlich wie Hibernate Import.Sql I18n

JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
Kiyotaka Oku
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
ChereCheek752
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
knight1128
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
Anung Ariwibowo
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
Charles Nutter
 

Ähnlich wie Hibernate Import.Sql I18n (20)

JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
Mobile Programming - Network Universitas Budi Luhur
Mobile Programming - Network Universitas Budi LuhurMobile Programming - Network Universitas Budi Luhur
Mobile Programming - Network Universitas Budi Luhur
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Testing with Node.js
Testing with Node.jsTesting with Node.js
Testing with Node.js
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
Multithreading in Java
Multithreading in JavaMultithreading in Java
Multithreading in Java
 
Code red SUM
Code red SUMCode red SUM
Code red SUM
 
Bhaloo
BhalooBhaloo
Bhaloo
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Hibernate Import.Sql I18n

  • 1. hibernate sql import.sql LTEX Documented By A http://blog.csdn.net/shadowkiss 2009-7-6 Hibernate ddl im- port.sql classpath hibernate.cfg.xml 1 < property name = " hbm2ddl . auto " > create </ property > 2 or 3 < property name = " hbm2ddl . auto " > create - drop </ property > import.sql JVM file.encoding *nix Windows OS JVM -Dfile.encoding=UTF-8 console UTF-8 SchemaExport.java : 1 package org . hibernate . tool . hbm2ddl ; 2 ... 3 public class SchemaExport { 4 ... 5 public void execute ( boolean script , boolean export , boolean justDrop , boolean justCreate ) { 1
  • 2. 6 ... 7 InputStream stream = ConfigHelper . getResourc e AsSt r eam ( importFile ) ; 8 importFileReader = new InputS treamR eader ( stream ) ; 9 ... Hibernate JVM ( new InputStreamReader ) SchemaExport (I) classpath import.sql.UTF-8 (II) import.sql 1 package cn . qdqn . bms . web . listener ; 2 3 import java . io . File ; 4 import java . io . FileOutputStream ; 5 import java . io . IOException ; 6 import java . io . InputStreamReader ; 7 import java . io . OutputSt re amWrit er ; 8 import java . io . Reader ; 9 import java . io . Writer ; 10 import java . net . URI ; 11 import java . net . URISyntaxE xc eption ; 12 13 import javax . servlet . Ser vlet C onte x tE v e nt ; 14 import javax . servlet . S er v l e t Co n te x t L i s t e n e r ; 15 16 public class HibListener implements S e r v l e t C o n t e x t L i s t e n e r { 17 18 /* * 19 * 20 */ 21 public void contextDestroyed ( Se r v le t C on t e xt E v en t sce ) { 22 23 } 2
  • 3. 24 25 /* * 26 * 27 */ 28 public void contextIn it ialize d ( S er v l et C o nt e x tE v e nt sce ) { 29 String fileName = sce . getSe rvletC ontext () . getInitParameter ( " ddl " ) ; 30 sce . getServletContext () . log ( " Convert " + fileName + " to import . sql " ) ; 31 String srcEnc = fileName . substring ( fileName . lastIndexOf ( " . " ) + 1) ; 32 // import.sql 33 File importsqlfile = null ; 34 try { 35 importsqlfile = new File ( new URI ( Thread . currentThread () 36 . ge t Con tex t Cl a s s L o a d e r () . getResource ( " " ) 37 + " import . sql " ) ) ; 38 } catch ( URISynt ax Except io n e ) { 39 e . printStackTrace () ; 40 } 41 42 // 43 Reader reader = null ; 44 Writer writer = null ; 45 try { 46 reader = new InputStreamR eader ( Thread . currentThread () 47 . ge t Con tex t Cl a s s L o a d e r () . ge tRes o urce A sS t r ea m ( fileName ) , 48 srcEnc ) ; 49 50 writer = new OutputS tr ea mW ri te r ( 51 new FileOutputStream ( importsqlfile ) , System 52 . getProperty ( " file . encoding " ) ) ; 53 54 int c = -1; 55 StringBuffer tempSB = new StringBuffer () ; 56 while (( c = reader . read () ) != -1) { 3
  • 4. 57 writer . write ( c ) ; 58 tempSB . append (( char ) c ) ; 59 } 60 sce . getServlet Contex t () . log ( tempSB . toString () ) ; 61 // 62 sce . getServlet Contex t () . log ( 63 " Generate import . sql ( " 64 + System . getProperty ( " file . encoding " ) 65 + " ) success ! " ) ; 66 } catch ( Exception e ) { 67 e . printStackTrace () ; 68 } finally { 69 try { 70 reader . close () ; 71 writer . flush () ; 72 writer . close () ; 73 } catch ( IOException e ) { 74 e . printStackTrace () ; 75 } 76 } 77 } 78 79 } (III) web.xml SessionFactory , ssh Spring ContextLoaderListener 1 <! -- hibernate ddl import.sql -- > 2 <! -- -- > 3 < context - param > 4 < param - name > ddl </ param - name > 5 < param - value > import . sql . UTF -8 </ param - value > 6 </ context - param > 7 < listener > 8 < listener - class > 9 cn . qdqn . bms . web . listener . HibListener 10 </ listener - class > 11 </ listener > 4
  • 5. 5