⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amber.xtp

📁 RESIN 3.2 最新源码
💻 XTP
📖 第 1 页 / 共 3 页
字号:
<document>  <header>    <product>resin</product>    <title>Amber</title>    <type>contents</type>    <description>      <p>      Amber is Resin's implementation of the      JPA 1.0 persistence specification, focusing on simplicity and      quality.      </p>    </description>  </header><body><localtoc/><s1 title="See Also"><ul><li>See <a href="../examples/amber-basic/index.xtp">Basic tutorial</a> fora complete single-table example.</li><li>See <a href="../examples/amber-many2one/index.xtp">Many-to-one tutorial</a> for basic relations.</li></ul></s1><s1 title="Quick Start"><ol><li>Expected SQL for the database</li><li>Entity bean implementation</li><li>Servlet loading, querying, and persisting</li><li>persistence.xml configuration</li><li>resin-web.xml configuration</li></ol><example title="Example: House SQL">create table HOUSE (  id integer auto_increment,  name varchar(255))</example><example title="Example: House entity">package demo;import javax.persistence.*;@Entitypublic class House {  @Id  @Column(name="id")  @GeneratedValue  private int _id;  @Basic  @Column(name="name")  private String _name;}</example><example title="Example: HouseServlet">package demo;import javax.ejb.*;import javax.servlet.*;import javax.persistence.*;public class HouseServlet extends GenericServlet {  @PersistenceUnit("test") EntityManagerFactory _factory;  public void load(PrintWriter out)  {    EntityManager amber = _factory.createEntityManager();    try {      House house = amber.find(House.class, 1);      out.println("House: " + house);    } finally {      amber.close();    }  }  public void query(PrintWriter out)  {    EntityManager amber = _factory.createEntityManager();    try {      Query query = amber.createQuery("select o from House o WHERE o.id=1");      out.println("House: " + query.getSingleResult());    } finally {      amber.close();    }  }  @TransactionAttribute  protected void insert(PrintWriter out)  {    EntityManager amber = _factory.createEntityManager();    try {      House house = new House("Gryffindor");      amber.persist(house);    } finally {      amber.close();    }  }}</example><example title="META-INF/persistence.xml">&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">  &lt;persistence-unit name="test">  &lt;/persistence-unit>&lt;/persistence></example><example title="WEB-INF/resin-web.xml">&lt;web-app xmlns="http://caucho.com/ns/resin">  &lt;ejb-server database="jdbc/test"/>  &lt;servlet-mapping url-pattern="/test"                    servlet-class="demo.HouseServlet"/>&lt;/web-app></example></s1><s1 title="API"><s2 title="EntityManager"><def title="javax.persistence.EntityManager">public interface EntityManager {  public &lt;T> T find(Class&lt;T> entityCLass, Object primaryKey);  public &lt;T> T getReference(Class&lt;T> entityClass, Object primaryKey);  public void flush();  public &lt;T> T merge(T entity);  public void persist(Object entity);  public void refresh(Object entity);  public void remove(Object entity);  public FlushModeType getFlushMode();  public void setFlushMode(FlushModeType flushMode);  public Query createQuery(String ql);  public Query createNamedQuery(String name);  public Query createNativeQuery(String sql);  public Query createNativeQuery(String sql, Class resultClass);  public Query createNativeQuery(String sql, String resultSEtMapping);  public void clear();  public void close();  public boolean contains(Object entity);  public Object getDelegate();  public boolean isOpen();  public EntityTransaction getTransaction();  public void joinTransaction();  public void lock(Object entity, LockModeType lockMode);}</def></s2><s2 title="EntityManagerFactory"><def title="javax.persistence.EntityManagerFactory">public interface EntityManagerFactory {  public EntityManager createEntityManager();  public EntityManager createEntityManager(Map map);  public void close();  public boolean isOpen();}</def></s2><s2 title="EntityTransaction"><def title="javax.persistence.EntityTransaction">public interface EntityTransaction {  public void begin();  public void commit();  public void rollback();  public boolean getRollbackOnly();  public void setRollbackOnly();  public boolean isActive();}</def></s2><s2 title="Query"><def title="javax.persistence.Query">public interface Query {  public List getResultList();  public Object getSingleResult();  public int executeUpdate();  public Query setFirstResult(int startPosition);  public Query setFlushMode(FlushModeType flushMode);  public Query setHint(String hintName, Object value);  public Query setMaxResults(int maxResult);  public Query setParameter(String name, Object value);  public Query setParameter(String name, Date date, TemporalType type);   public Query setParameter(String name, Calendar date, TemporalType type);   public Query setParameter(int pos, Object value);  public Query setParameter(int pos, Date date, TemporalType type);   public Query setParameter(int pos, Calendar date, TemporalType type);}</def></s2></s1><s1 title="Annotations"><s2 title="Class Annotations"><s3 title="@DiscriminatorColumn"><p>Configures the discriminator column, which select the entity classin an inheritance relationship.  Each entity class will have acolumn value which uniquely selects the class to be loaded.</p><deftable><tr>  <th>Property</th>  <th>Description</th>  <th>Default</th></tr><tr>  <td>name</td>  <td>The name of the column</td>  <td></td></tr><tr>  <td>discriminatorType</td>  <td>The column type: STRING, CHAR or INTEGER</td>  <td>STRING</td></tr><tr>  <td>columnDefinition</td>  <td>SQL definition used when creating the column</td>  <td></td></tr><tr>  <td>length</td>  <td>default VARCHAR length when creating a STRING column</td>  <td>31</td></tr></deftable><def title="javax.persistence.DiscriminatorColumn">@Target(TYPE)@Retention(RUNTIME)public @interface DiscriminatorColumn {  String name() default "";  DiscriminatorType discriminatorType() default STRING;  String columnDefinition() default "";  int length() default 31;}</def></s3><s3 title="@Embeddable"><p>Annotates the class as an embeddable value.  The class fields willrepresent a collection of table columns embedded as part of acontaining class for the table.</p><def title="javax.persistence.Embeddable">@Target(TYPE)@Retention(RUNTIME)public @interface Embeddable {}</def></s3><s3 title="@Entity"><p>Annotates the class as an entity bean.</p><p>See the <a href="../examples/amber-basic/index.xtp">basic property tutorial</a>and the <a href="../examples/amber-basic-field/index.xtp">basic field tutorial</a>for an introduction.</p><deftable><tr>  <th>Property</th>  <th>Description</th>  <th>Default</th></tr><tr>  <td>name</td>  <td>The name of the bean</td>  <td>The class name (unqualified)</td></tr></deftable><def title="javax.persistence.Entity">@Target(TYPE)@Retention(RUNTIME)public @interface Entity {  String name() default "";}</def><p>The fields or properties will be annotated by @Id, @Basic, etc.Amber will detect either field or property annotation by thetype for the @Id.  In other words, if Amber sees an @Id on a field,it will use field access.  If Amber sees @Id on a method, it will useproperty access.</p></s3><s3 title="@IdClass"><p>The <code>@IdClass</code> annotation specifies the class to be usedto contain a compount primary key.</p><def title="javax.persistence.IdClass">@Target({TYPE})@Retention(RUNTIME)public @interface IdClass {  Class value();}</def></s3><s3 title="@Inheritance"><p>@Inheritance marks the entity bean as supporting inheritance,i.e. the database maps to different Java classes depending ona discriminator value.</p><deftable><tr>  <th>Property</th>  <th>Description</th>  <th>Default</th></tr><tr>  <td>strategy</td>  <td>The mapping strategy for inheritance: SINGLE_TABLE,      JOINED or TABLE_PER_CLASS </td>  <td>SINGLE_TABLE</td></tr></deftable><def title="javax.persistence.Inheritance">@Target(TYPE)@Retention(RUNTIME)public @interface Inheritance {  InteritanceType strategy() default SINGLE_TABLE;}</def></s3><s3 title="@MappedSuperclass"><p>The <code>@MappedSuperclass</code> annotation marks the classas a parent class to an <code>@Entity</code>.</p><def title="javax.persistence.MappedSuperclass">@Target({TYPE})@Retention(RUNTIME)public @interface MappedSuperclass {}</def></s3><s3 title="@SecondaryTable"><p>Specifies a secondary database table for an entity bean.The secondary table will contain the fields with a secondaryTablein the @Column.</p><deftable><tr>  <th>Property</th>  <th>Description</th>  <th>Default</th></tr><tr>  <td>name</td>  <td>The name of the table</td><td>The unqualified class name.</td></tr><tr>  <td>catalog</td>  <td>the table's catalog</td>  <td>none</td></tr><tr>  <td>schema</td>  <td>the table's schema</td><td>none</td></tr><tr>  <td>pkJoinColumns</td>  <td>join column to the primary table</td>  <td>joins the primary key</td></tr><tr>  <td>uniqueConstraint</td>  <td>unique constraints during generation</td>  <td>none</td></tr></deftable><def title="javax.persistence.SecondaryTable">@Target(TYPE)@Retention(RUNTIME)public @interface SecondaryTable {  String name() default "";  String catalog() default "";  String schema() default "";  PrimaryKeyJoinColumn []pkJoinColumns() default {};  UniqueConstraint []uniqueConstraints() default {};}</def></s3><s3 title="@SequenceGenerator"><p>Specifies a sequence table to be used for generating keys.</p><deftable><tr>  <th>Property</th>  <th>Description</th>  <th>Default</th></tr><tr>  <td>name</td>  <td>The amber name of the sequence table</td>  <td>required</td></tr><tr>  <td>sequenceName</td>  <td>The SQL name of the sequence table</td>  <td><var>name</var></td></tr><tr>  <td>initialValue</td>  <td>The initial value to seed the generator</td>  <td>0</td></tr><tr>  <td>allocationSize</td>  <td>The number of values to increment by for each allocation</td>  <td>50</td></tr></deftable><def title="javax.persistence.SequenceGenerator">@Target({TYPE, METHOD, FIELD})@Retention(RUNTIME)public @interface SequenceGenerator {  String name();  String sequenceName() default "";  int initialValue() default 0;  int allocationSize() default 50;}</def></s3><s3 title="@Table"><p>Specifies the database table for an entity bean.  Thedefault table name is the class name.</p><deftable><tr>  <th>Property</th>  <th>Description</th>  <th>Default</th></tr><tr>  <td>name</td>  <td>The name of the table</td>  <td>The unqualified class name.</td></tr><tr>  <td>catalog</td>  <td>the table's catalog</td>  <td>none</td></tr><tr>  <td>schema</td>  <td>the table's schema</td>  <td>none</td></tr><tr>  <td>uniqueConstraint</td>  <td>unique constraints during generation</td>  <td>none</td></tr></deftable><def>package javax.persistence;@Target(TYPE)@Retention(RUNTIME)public @interface Table {  String name() default "";  String catalog() default "";  String schema() default "";  UniqueConstraint []uniqueConstraints() default {};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -