ENTERPRISE JAVA Alper AKALIN İçindekiler İthaf ........................................................................................................... xvii Teşekkür .................................................................................................... xix Yazar Hakkında ......................................................................................... xxi Kitap Hakkında ......................................................................................... xxiii Kitap Konuları ........................................................................................... xxv Kitap Nasıl Okunmalı ............................................................................... xxxi Kullanım Sözleşmesi .............................................................................. xxxiii 1. ECLIPSE .................................................................................................. 1 1.1. Kurulum ......................................................................................... 2 1.2. Proje Oluşturma ............................................................................. 6 1.3. Perspective .................................................................................... 7 1.4. Plug-in .......................................................................................... 10 1.4.1. Marketplace ....................................................................... 10 1.5. Install New Software .................................................................... 12 1.6. Update ......................................................................................... 14 1.7. Eclipse Kısayolları ....................................................................... 14 1.8. Eclipse JDK Değişimi .................................................................. 16 2. XML İŞLEMLER ..................................................................................... 21 2.1. Xml Söz Dizim Kuralları ............................................................... 21 2.1.1. Tag - Etiket ........................................................................ 22 2.1.2. CData ................................................................................ 23 2.1.3. Attribute ............................................................................. 23 2.1.4. Child Element .................................................................... 24 2.1.5. Empty Element .................................................................. 24 2.1.6. Well Formed - Valid ........................................................... 24 2.1.7. Xsl ...................................................................................... 25 2.1.8. Namespace ........................................................................ 25 2.1.9. Prefix ................................................................................. 26 2.2. Xml Schema Definition ................................................................ 27 2.2.1. Element .............................................................................. 27 iii ENTERPRISE JAVA 2.2.2. Attribute ............................................................................. 27 2.2.3. Reference .......................................................................... 28 2.2.4. Type Oluşturma ................................................................. 28 2.2.5. Maxoccurs - Minoccurs ...................................................... 29 2.2.6. Group ................................................................................. 29 2.2.7. Complex Element .............................................................. 30 2.2.8. Basit ve Complex Element ................................................ 32 2.3. Eclispe Xml İşlemler .................................................................... 33 2.4. Java Xml Parser .......................................................................... 41 2.4.1. Sax Parser ......................................................................... 42 2.4.2. Dom Parser ....................................................................... 42 2.4.3. JDom Parser ..................................................................... 43 2.4.4. Jaxp Api ............................................................................. 43 2.4.5. PROJE 102.00-com.xml .................................................... 44 2.5. Jaxb Api ....................................................................................... 48 2.5.1. Jaxb Binding Compiler ...................................................... 48 2.5.2. Binding Runtime Framework ............................................. 49 2.5.3. Marshalling ........................................................................ 49 2.5.4. Unmarshalling .................................................................... 49 2.5.5. PROJE 102.01-com.xml.jaxb ............................................. 50 2.5.6. Jaxb Anotasyon ................................................................. 55 2.6. Marshalling - Unmarshalling ........................................................ 56 2.6.1. PROJE 102.02-com.xml.jaxb.advanced ............................ 56 3. MAVEN .................................................................................................. 61 3.1. Mavenin Geliştirme Sürecine Katkıları ......................................... 61 3.2. Maven Yapısı ............................................................................... 62 3.2.1. Project Object Model ......................................................... 62 3.2.2. Define Goals ...................................................................... 62 3.2.3. Local - Remote Repository ................................................ 63 3.2.4. Project Artifacts ................................................................. 63 3.2.5. Maven Plugins ................................................................... 63 3.2.6. Custom Plugins ................................................................. 63 iv ENTERPRISE JAVA 3.2.7. Maven Build System .......................................................... 63 3.3. Maven Kurulum ........................................................................... 64 3.3.1. Komut Satırından Maven Kullanımı ................................... 68 3.4. Pom.xml ....................................................................................... 71 3.4.1. groupID .............................................................................. 71 3.4.2. artifatctId ............................................................................ 72 3.4.3. Version ............................................................................... 72 3.4.4. Packaging .......................................................................... 72 3.4.5. Properties .......................................................................... 75 3.4.6. Dependencies .................................................................... 75 3.5. Maven ve Eclipse ........................................................................ 76 3.5.1. Eclipse Maven Projesi ....................................................... 76 3.5.2. Maven Proje Yapısı ........................................................... 80 3.5.3. Proje Build ......................................................................... 82 3.5.4. Bağımlılıkların Tanımlanması ............................................ 90 3.5.5. Maven Proje Import ........................................................... 94 3.5.6. Maven Repository .............................................................. 95 4. INTERFACE YÖNELİM ......................................................................... 97 4.1. PROJE 105.00-com.interface ...................................................... 97 4.1.1. inheritancesample1 .......................................................... 101 4.1.2. inheritancesample2 .......................................................... 103 4.1.3. inheritancesample3 .......................................................... 104 4.1.4. interfacesample1 .............................................................. 106 4.1.5. interfacesample2 .............................................................. 107 4.1.6. Eclipse Comparison Tool ................................................. 108 4.1.7. interfacesample3 .............................................................. 111 4.1.8. Modülarite ........................................................................ 112 4.1.9. Kod Okuma Kalitesi ......................................................... 113 4.1.10. Nesne Davranışı ............................................................ 114 4.2. PROJE 105.01-com.interface.design ......................................... 115 4.3. Aslında ne oldu? ........................................................................ 118 4.3.1. Modülarite ........................................................................ 118 v ENTERPRISE JAVA 4.3.2. Sadelik ............................................................................. 119 4.3.3. Kompozisyon ................................................................... 122 4.3.4. İzolasyon .......................................................................... 123 4.3.5. Esnek Bağ ....................................................................... 123 4.3.6. Çok Biçimlilik - Polymorphism ......................................... 124 4.4. Interface Yönelik Programlama ................................................. 125 5. REFLECTION ...................................................................................... 131 5.1. PROJE 106.00-com.reflection ................................................... 131 5.2. Java Dynamic Proxy .................................................................. 133 5.2.1. PROJE 106.01-com.reflection.dynamicProxy .................. 134 5.3. Aslında Ne Oldu? ...................................................................... 140 5.3.1. Invoke Metod ................................................................... 142 5.4. Compile Time ............................................................................ 144 5.5. Runtime ...................................................................................... 146 6. ANNOTATIONS ................................................................................... 149 6.1. Compiler İşlemler ....................................................................... 149 6.1.1. @Deprecated ................................................................... 149 6.1.2. @Override ....................................................................... 150 6.1.3. @SuppressWarnings ....................................................... 150 6.2. Build Time İşlemler .................................................................... 150 6.3. Runtime İşlemler ........................................................................ 150 6.4. Custom Anotasyonlar ................................................................ 151 6.4.1. @Retention ...................................................................... 151 6.4.2. @Target ........................................................................... 151 6.4.3. PROJE 107.00-com.annotation ....................................... 152 6.4.4. PROJE 107.01-com.annotation.dynamic ......................... 154 7. CONSTANT & ENUM .......................................................................... 159 7.1. Constant ..................................................................................... 159 7.1.1. PROJE 108.00-com.constant .......................................... 165 7.1.2. Eclipse Debug ................................................................. 167 7.2. Enum ......................................................................................... 172 7.2.1. PROJE 108.01-com.enum ............................................... 172 vi ENTERPRISE JAVA 8. LOGGING ............................................................................................ 175 8.1. Log4j .......................................................................................... 176 8.1.1. PROJE 109.00-com.logging ............................................ 176 8.2. Log4j Mimarisi ........................................................................... 179 8.2.1. Core Objects .................................................................... 180 8.2.2. Support Objects ............................................................... 180 8.3. Log Level ................................................................................... 182 8.3.1. PROJE 109.01-com.logging.level .................................... 182 8.3.2. Etki Alanı ......................................................................... 186 8.4. Log Dosyası ............................................................................... 191 8.4.1. PROJE 109.02-com.logging.file ....................................... 191 8.5. Log Dosyası Bölme ................................................................... 193 8.5.1. mTail ................................................................................ 194 8.5.2. PROJE 109.03-com.logging.rollingFile ............................ 194 9. JDBC .................................................................................................... 201 9.1. Java Database Connectivity ...................................................... 201 9.1.1. Jdbc Driver ...................................................................... 202 9.1.2. Driver Manager ................................................................ 202 9.1.3. Jdbc Api ........................................................................... 202 9.1.4. Driver Manager ................................................................ 202 9.2. Statements ................................................................................. 203 9.3. Jdbc Ön Hazırlıklar .................................................................... 203 9.3.1. PROJE 110.00-com.jdbc ................................................. 206 9.3.2. Timestamp ....................................................................... 211 9.3.3. Batch Processing ............................................................. 214 9.3.4. Commit ............................................................................ 216 9.3.5. ResultSet ......................................................................... 217 9.4. Refactoring ................................................................................. 220 9.4.1. PROJE 110.01-com.jdbc.refactoring ................................ 220 9.4.2. Veri tabanı Bağlantısı Kapama ........................................ 221 9.4.3. Tekrarlı Yapılar ................................................................ 228 9.4.4. PROJE 110.02-com.jdbc.refactoring.logging ................... 233 vii ENTERPRISE JAVA 9.4.5. Refactoring ...................................................................... 236 9.4.6. Dinamik Veri tabanı Bağlantısı ........................................ 240 9.4.7. PROJE 110.03-com.jdbc.databaseChanging ................... 240 9.4.8. Transaction ...................................................................... 242 9.4.9. Rollback ........................................................................... 248 9.5. Model Sınıflar ............................................................................ 251 9.5.1. PROJE 110.04-com.jdbc.advanced ................................. 253 9.5.2. Data Alanı ........................................................................ 255 9.5.3. Static Metod ..................................................................... 256 9.5.4. Static Block ...................................................................... 257 9.5.5. ToString Metod ................................................................ 261 9.6. Dao ............................................................................................ 263 9.6.1. PROJE 110.05-com.jdbc.dao .......................................... 267 9.6.2. Dao .................................................................................. 267 10. HIBERNATE & JPA ........................................................................... 275 10.1. İlişkisel Veri Tabanı ................................................................. 275 10.1.1. Primary Key ................................................................... 278 10.1.2. Foreign Key ................................................................... 279 10.2. Orm .......................................................................................... 279 10.2.1. Object Relational Mapping ............................................. 282 10.2.2. Uygulama Seviyesi ........................................................ 283 10.2.3. Veri Tabanı Seviyesi ...................................................... 283 10.2.4. Orm Tools ...................................................................... 284 10.3. Hibernate ................................................................................. 286 10.3.1. SessionFactory .............................................................. 287 10.3.2. Session .......................................................................... 287 10.3.3. Persistent Objects .......................................................... 287 10.3.4. TransactionFactory ........................................................ 288 10.3.5. Transaction .................................................................... 288 10.3.6. Connection Provider ...................................................... 288 10.3.7. Pojo ................................................................................ 288 10.3.8. Xml Mapping .................................................................. 289 viii ENTERPRISE JAVA 10.3.9. Annotation Mapping ....................................................... 312 10.4. Jpa ........................................................................................... 321 10.4.1. Jpa Mimarisi .................................................................. 322 10.4.2. Persistence Unit ............................................................ 322 10.4.3. EntityManagerFactory .................................................... 322 10.4.4. EntityManager ................................................................ 323 10.4.5. persistence.xml .............................................................. 323 10.4.6. Annotation Mapping ....................................................... 323 10.4.7. Güvenli Parametre Geçişi .............................................. 329 10.4.8. Named Queries ............................................................. 336 10.5. Object States ........................................................................... 338 10.5.1. Hibernate Nesne Durumları ........................................... 339 10.5.2. Session .......................................................................... 340 10.5.3. PROJE 111.04-com.orm.jpa.objectState ....................... 343 10.5.4. Crud İşlem Statüleri ....................................................... 349 10.6. Jpa More Annotations .............................................................. 352 10.6.1. @Embeddable ............................................................... 352 10.6.2. @Embedded .................................................................. 352 10.6.3. @Basic .......................................................................... 353 10.6.4. @Lob ............................................................................. 353 10.6.5. Filtreleme ....................................................................... 353 10.6.6. 111.05-com.orm.jpa.moreAnnotation ............................. 353 10.6.7. Collections ..................................................................... 357 10.7. Hibernate Object Access ......................................................... 370 10.7.1. Object Levels ................................................................. 371 10.7.2. Fetch Types ................................................................... 382 10.8. Relations .................................................................................. 388 10.8.1. Embedded ..................................................................... 388 10.8.2. ElementCollection .......................................................... 388 10.8.3. OneToOne ..................................................................... 389 10.8.4. OneToMany & ManyToOne ........................................... 389 10.8.5. ManyToMany ................................................................. 390 ix ENTERPRISE JAVA 10.8.6. Cascade Types .............................................................. 390 10.8.7. Unidirectional ................................................................. 390 10.8.8. Bidirectional ................................................................... 390 10.8.9. OneToOne ..................................................................... 390 10.8.10. OneToMany ................................................................. 408 10.8.11. ManyToMany ............................................................... 425 10.9. Inheritance ............................................................................... 430 10.9.1. Single Table ................................................................... 430 10.9.2. Sperate Table ................................................................ 435 10.10. Connection Pooling ................................................................ 437 10.10.1. C3P0 Connection Pool ................................................ 438 10.11. Dao ........................................................................................ 440 10.11.1. PROJE 111.13-com.orm.jpa.dao ................................. 440 11. WEB SERVICES ................................................................................ 445 11.1. Soa .......................................................................................... 445 11.1.1. Xml ................................................................................ 447 11.1.2. Xsd ................................................................................ 447 11.1.3. Web Service .................................................................. 449 11.1.4. Soap Web Services ....................................................... 450 11.1.5. Wsdl ............................................................................... 455 11.1.6. Java Web Services ........................................................ 457 11.1.7. Web Service Interface ................................................... 500 11.1.8. Client Side ..................................................................... 507 12. RESTFUL SERVICES ....................................................................... 517 12.1. Rest ......................................................................................... 519 12.1.1. Http ................................................................................ 520 12.1.2. Html ............................................................................... 520 12.1.3. Resources ...................................................................... 520 12.1.4. Resource Locations ....................................................... 523 12.1.5. Http Methods ................................................................. 524 12.1.6. Meta Data ...................................................................... 524 12.1.7. Status Code ................................................................... 525 x
Description: