Your SlideShare is downloading. ×
0
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
2008.07.17 발표
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

2008.07.17 발표

569

Published on

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
569
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Oracle TopLink &amp; JPA <ul><li>Sunjoo Park </li></ul><ul><li>[email_address] </li></ul><ul><li>2008.07.17 </li></ul>
  • 2. 오늘 이야기할 사항 <ul><li>Oracle TopLink 소개 </li></ul><ul><li>JPA in JEUS와 TopLink </li></ul>
  • 3. ￵ TopLink 가 하는 일 <ul><li>Java objects 를 Relational data 혹은 XML element 등과 Mapping 해주는 기능 </li></ul>
  • 4. TopLink Key Features <ul><li>Nonintrusive, flexible, metadata-based architecture </li></ul><ul><li>Comprehensive visual TopLink Workbench </li></ul><ul><li>Advanced mapping support and flexibility </li></ul><ul><li>Object caching support </li></ul><ul><li>Query flexibility </li></ul><ul><li>Just-in-time reading </li></ul><ul><li>Caching </li></ul><ul><li>Object-level transaction support and integration </li></ul><ul><li>Locking </li></ul><ul><li>Multiple performance tuning options </li></ul><ul><li>Architectural flexibility </li></ul>
  • 5. TopLink 구성요소 Standalone J2SE application Environment TopLink Workbench (GUI Tool)
  • 6. TopLink Application Packaging <ul><li>File List </li></ul><ul><ul><li>Java classes that represent the objects mapped </li></ul></ul><ul><ul><li>sessions.xml </li></ul></ul><ul><ul><ul><li>The information required to access a data source </li></ul></ul></ul><ul><ul><li>project.xml </li></ul></ul><ul><ul><ul><li>Object’s mapping information </li></ul></ul></ul>You can use those through TopLink API! sessions.xml project.xml
  • 7. &nbsp;
  • 8. TopLink 의 기능 (1) <ul><li>Object-XML Mapping </li></ul><ul><ul><li>Conversions between </li></ul></ul><ul><ul><ul><li>Java objects </li></ul></ul></ul><ul><ul><ul><li>XML Documents </li></ul></ul></ul><ul><ul><li>Using JAXB </li></ul></ul><ul><ul><li>TopLink JAXB compiler </li></ul></ul><ul><ul><ul><li>To generate TopLink XML projects </li></ul></ul></ul><ul><ul><ul><li>To generate JAXB-compliant object model classes </li></ul></ul></ul>Client JAXB XML TopLink Layer
  • 9. TopLink 의 기능 (1) &lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&gt; &lt;toplink-sessions version=&amp;quot;10g Release 3 (10.1.3.3.0)&amp;quot; xmlns:xsd=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot; xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;&gt; &lt;session xsi:type=&amp;quot;database-session&amp;quot;&gt; &lt;name&gt;examples.ox.model&lt;/name&gt; &lt;event-listener-classes/&gt; &lt;primary-project xsi:type=&amp;quot;xml&amp;quot;&gt;/home/all4you/tmp/xmlmapping/classes/CustomerProject.xml&lt;/primary-project&gt; &lt;login xsi:type=&amp;quot;xml-login&amp;quot;/&gt; &lt;/session&gt; &lt;/toplink-sessions&gt;~ &lt;opm:class-mapping-descriptor xsi:type=&amp;quot;toplink:xml-class-mapping-descriptor&amp;quot;&gt; &lt;opm:class&gt;examples.ox.model.Address&lt;/opm:class&gt; &lt;opm:alias&gt;Address&lt;/opm:alias&gt; &lt;opm:events xsi:type=&amp;quot;toplink:event-policy&amp;quot;/&gt; &lt;opm:querying xsi:type=&amp;quot;toplink:query-policy&amp;quot;/&gt; &lt;opm:attribute-mappings&gt; ............................................ &lt;opm:attribute-mapping xsi:type=&amp;quot;toplink:xml-direct-mapping&amp;quot;&gt; &lt;opm:attribute-name&gt;province&lt;/opm:attribute-name&gt; &lt;opm:field name=&amp;quot;state/text()&amp;quot; xsi:type=&amp;quot;toplink:node&amp;quot;/&gt; &lt;opm:converter xsi:type=&amp;quot;toplink:object-type-converter&amp;quot;&gt; &lt;toplink:type-mappings&gt; &lt;toplink:type-mapping&gt; &lt;toplink:object-value xsi:type=&amp;quot;xsd:string&amp;quot;&gt;Alaska&lt;/toplink:object-value&gt; &lt;toplink:data-value xsi:type=&amp;quot;xsd:string&amp;quot;&gt;AK&lt;/toplink:data-value&gt; &lt;/toplink:type-mapping&gt; &lt;toplink:type-mapping&gt; &lt;toplink:object-value xsi:type=&amp;quot;xsd:string&amp;quot;&gt;Arkansas&lt;/toplink:object-value&gt; &lt;toplink:data-value xsi:type=&amp;quot;xsd:string&amp;quot;&gt;AR&lt;/toplink:data-value&gt; &lt;/toplink:type-mapping&gt; &lt;/toplink:type-mappings&gt; &lt;/opm:converter&gt; &lt;/opm:attribute-mapping&gt; &lt;/opm:attribute-mappings&gt; Project myProject = session.getProject(); XMLContext context = new XMLContext(myProject); XMLMarshaller marshaller = context.createMarshaller(); marshaller.marshal(myObject, outputStream); marshaller.setFormattedOutput(true); XMLUnmarshaller unmarshaller = context.createUnmarshaller(); Employee emp = (Employee)unmarshaller.unmarshal(new File(&amp;quot;employee.xml&amp;quot;)); XMLValidator validator = context.createValidator(); boolean isValid = validator.validate(emp);
  • 10. TopLink 의 기능 (2) <ul><li>Object-Relational Mapping </li></ul><ul><ul><li>Convertions between </li></ul></ul><ul><ul><ul><li>Java objects </li></ul></ul></ul><ul><ul><ul><li>Relational database </li></ul></ul></ul><ul><ul><li>Object, Relation, Constraints, Inheritances </li></ul></ul><ul><ul><li>To access a database using JDBC </li></ul></ul><ul><ul><li>TopLink Essentials - JPA </li></ul></ul>
  • 11. TopLink 의 기능 (2) &lt;session xsi:type=&amp;quot;database-session&amp;quot;&gt; &lt;name&gt;advancedtutorial&lt;/name&gt; &lt;event-listener-classes/&gt; &lt;primary-project xsi:type=&amp;quot;xml&amp;quot;&gt;/home/all4you/tmp/adtutorial/src/META-INF/project.xml&lt;/primary-project&gt; &lt;login xsi:type=&amp;quot;database-login&amp;quot;&gt; &lt;platform-class&gt;oracle.toplink.platform.database.oracle.Oracle10Platform&lt;/platform-class&gt; &lt;user-name&gt;scott&lt;/user-name&gt; &lt;password&gt;3E20F8982C53F4ABA825E30206EC8ADE&lt;/password&gt; &lt;sequencing&gt; &lt;default-sequence xsi:type=&amp;quot;table-sequence&amp;quot;&gt; &lt;name&gt;Default&lt;/name&gt; &lt;/default-sequence&gt; &lt;/sequencing&gt; &lt;driver-class&gt;oracle.jdbc.driver.OracleDriver&lt;/driver-class&gt; &lt;connection-url&gt;jdbc:oracle:thin:@192.168.1.43:1532:ora10g&lt;/connection-url&gt; &lt;/login&gt; &lt;/session&gt; &lt;/toplink-sessions&gt; &lt;opm:class-mapping-descriptors&gt; &lt;opm:class-mapping-descriptor xsi:type=&amp;quot;toplink:relational-class-mapping-descriptor&amp;quot;&gt; &lt;opm:class&gt;example.model.PhoneNumber&lt;/opm:class&gt; &lt;opm:alias&gt;PhoneNumber&lt;/opm:alias&gt; &lt;opm:primary-key&gt; &lt;opm:field table=&amp;quot;PHONE&amp;quot; name=&amp;quot;EMP_ID&amp;quot; xsi:type=&amp;quot;opm:column&amp;quot;/&gt; &lt;opm:field table=&amp;quot;PHONE&amp;quot; name=&amp;quot;TYPE&amp;quot; xsi:type=&amp;quot;opm:column&amp;quot;/&gt; &lt;/opm:primary-key&gt; UnitOfWork uow = session.acquireUnitOfWork(); try { Employee employee = createEmployee(first, last, salary); Address address = createAddress(city, street); employee.setAddress(address); uow.registerNewObject(employee); uow.commit(); } finally { uow.release(); }
  • 12. TopLink 의 기능 (3) <ul><li>Conversions between </li></ul><ul><ul><li>Java objects </li></ul></ul><ul><ul><li>Nonrelational data source(EIS records) </li></ul></ul><ul><li>Using J2EE Connector Architecture </li></ul><ul><li>JCA adapter must support the JCA CCI interface </li></ul>
  • 13. TopLink Essentials - JPA <ul><li>What is &apos;TopLink Essentials&apos;? </li></ul><ul><ul><li>The open source reference implementation of the Java Persistence API (JPA) focused on standardized object-relational persistence and valuable extensions. </li></ul></ul>EJB 3.0 TopLink Essentials glassfish JEUS
  • 14. How to Use JPA <ul><li>Configuration </li></ul><ul><ul><li>Annotations </li></ul></ul><ul><ul><ul><li>Table mapping, Transactions attributes, etc. </li></ul></ul></ul><ul><ul><li>persistence.xml </li></ul></ul><ul><ul><ul><li>Persistence units, Data Sources </li></ul></ul></ul><ul><ul><ul><ul><li>In JavaEE ; using &lt;jta-data-source&gt; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>In J2SE ; using a direct connection to a data source through TopLink Essentials </li></ul></ul></ul></ul><ul><ul><ul><li>Locations </li></ul></ul></ul><ul><ul><ul><ul><li>META-INF/persistence.xml in your classpath </li></ul></ul></ul></ul>
  • 15. How to Use JPA @Entity @NamedQuery(name=&amp;quot;findAllProducts&amp;quot;, query=&amp;quot;SELECT p FROM Product p&amp;quot;) public class Product implements Serializable { @Id private String productId; private double price; private String description; public Product() { } public Product(String productId, double price, String description){ this.productId = productId; this.price = price; this.description = description; } public String getProductId() { return productId; } public void setProductId(String id) { this.productId = id; } &lt;persistence version=&amp;quot;1.0&amp;quot; xmlns=&amp;quot;http://java.sun.com/xml/ns/persistence&amp;quot;&gt; &lt;persistence-unit name=&amp;quot;hellojpa&amp;quot; transaction-type=&amp;quot;JTA&amp;quot;&gt; &lt;jta-data-source&gt;datasource1&lt;/jta-data-source&gt; &lt;!--&lt;jta-data-source&gt;jdbc/sample&lt;/jta-data-source&gt;--&gt; &lt;properties/&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; @PersistenceContext private EntityManager em; ..... public Product createProduct(String productId, double price, String desc){ Product product = new Product(productId, price, desc); em.persist(product); return product; } public Product getProduct(String productId){ return (Product) em.find(Product.class, productId); }
  • 16. XML Mapping Relational Mapping EIS Mapping Oracle TopLink TopLink Essentials glassfish jeus-toplink-essentials.jar JEUS 6
  • 17. &nbsp;

×