|
From: <one...@us...> - 2003-01-26 03:17:48
|
Update of /cvsroot/hibernate/Hibernate2/doc/reference/src
In directory sc8-pr-cvs1:/tmp/cvs-serv9441/reference/src
Modified Files:
session_configuration.xml transactions.xml
Log Message:
new Configuration API
Index: session_configuration.xml
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/doc/reference/src/session_configuration.xml,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** session_configuration.xml 1 Jan 2003 13:46:38 -0000 1.1.1.1
--- session_configuration.xml 26 Jan 2003 03:17:45 -0000 1.2
***************
*** 4,22 ****
<sect1 id="session-configuration-s1">
! <title>Programmatic Datastore Configuration</title>
<para>
! An instance of <literal>net.sf.hibernate.Datastore</literal>
represents an entire set of mappings of an application's Java types to a
relational database. These mappings are compiled from various XML mapping
! files. You may obtain a <literal>Datastore</literal> instance by
! calling <literal>Hibernate.createDatastore()</literal>. Heres an
! example of setting up a datastore from mappings defined in two XML
! configuration files:
</para>
! <programlisting><![CDATA[Datastore ds = Hibernate.createDatastore()
! .storeFile("vertex.hbm.xml")
! .storeFile("edge.hbm.xml");]]></programlisting>
<para>
--- 4,21 ----
<sect1 id="session-configuration-s1">
! <title>Programmatic Configuration</title>
<para>
! An instance of <literal>net.sf.hibernate.Configuration</literal>
represents an entire set of mappings of an application's Java types to a
relational database. These mappings are compiled from various XML mapping
! files. You may obtain a <literal>Configuration</literal> instance by
! instantiating it directly. Heres an example of setting up a datastore from
! mappings defined in two XML configuration files:
</para>
! <programlisting><![CDATA[Configuration cfg = new Configuration()
! .addFile("vertex.hbm.xml")
! .addFile("edge.hbm.xml");]]></programlisting>
<para>
***************
*** 25,31 ****
</para>
! <programlisting><![CDATA[Datastore ds = Hibernate.createDatastore()
! .storeClass(eg.Vertex.class)
! .storeClass(eg.Edge.class);]]></programlisting>
<para>
--- 24,30 ----
</para>
! <programlisting><![CDATA[Configuration cfg = new Configuration()
! .addClass(eg.Vertex.class)
! .addClass(eg.Edge.class);]]></programlisting>
<para>
***************
*** 36,40 ****
<para>
! A <literal>Datastore</literal> is intended as a configuration-time object, to be
discarded once a <literal>SessionFactory</literal> is built.
</para>
--- 35,50 ----
<para>
! A <literal>Configuration</literal> also specifies various optional properties.
! </para>
!
! <programlisting><![CDATA[Properties props = new Properties();
! ...
! Configuration cfg = new Configuration()
! .addClass(eg.Vertex.class)
! .addClass(eg.Edge.class)
! .setProperties(props);]]></programlisting>
!
! <para>
! A <literal>Configuration</literal> is intended as a configuration-time object, to be
discarded once a <literal>SessionFactory</literal> is built.
</para>
***************
*** 44,49 ****
<title>Obtaining a SessionFactory</title>
<para>
! When all mappings have been compiled by the <literal>Datastore</literal>, the application
! must obtain an factory for <literal>Session</literal> instances. This factory is intended
to be shared by all application threads. However, Hibernate does allow your application to
instantiate more than one <literal>SessionFactory</literal>. This is useful if you are
--- 54,59 ----
<title>Obtaining a SessionFactory</title>
<para>
! When all mappings have been parsed by the <literal>Configuration</literal>, the application
! must obtain a factory for <literal>Session</literal> instances. This factory is intended
to be shared by all application threads. However, Hibernate does allow your application to
instantiate more than one <literal>SessionFactory</literal>. This is useful if you are
***************
*** 51,61 ****
</para>
! <programlisting><![CDATA[//configure the SessionFactory using System properties
! SessionFactory sessions = ds.buildSessionFactory();]]></programlisting>
- <programlisting><![CDATA[//configure the SessionFactory using a given instance of java.util.Properties
- Properties props = new Properties();
- ...
- SessionFactory sessions = ds.buildSessionFactory(props);]]></programlisting>
</sect1>
--- 61,66 ----
</para>
! <programlisting><![CDATA[SessionFactory sessions = cfg.buildSessionFactory();]]></programlisting>
</sect1>
***************
*** 65,73 ****
<para>
A <literal>SessionFactory</literal> may open a <literal>Session</literal> on
! a user-provided JDBC connection. This
! design choice frees the application to obtain JDBC connections wherever it
! pleases - from an application server connection pool for example. The
! application must be careful not to open two concurrent sessions on the same
! connection.
</para>
--- 70,76 ----
<para>
A <literal>SessionFactory</literal> may open a <literal>Session</literal> on
! a user-provided JDBC connection. This design choice frees the application to
! obtain JDBC connections wherever it pleases. The application must be careful
! not to open two concurrent sessions on the same connection.
</para>
***************
*** 102,106 ****
<para>
Pass an instance of <literal>java.util.Properties</literal> to
! <literal>Datastore.buildSessionFactory()</literal>.
</para>
</listitem>
--- 105,109 ----
<para>
Pass an instance of <literal>java.util.Properties</literal> to
! <literal>Configuration.setProperties()</literal>.
</para>
</listitem>
***************
*** 126,132 ****
<para>
! Hibernate will obtain (and pool) connections using
! <literal>java.sql.DriverManager</literal> if you set the
! following properties:
</para>
--- 129,134 ----
<para>
! Hibernate will obtain (and pool) connections using <literal>java.sql.DriverManager</literal>
! if you set the following properties:
</para>
***************
*** 173,178 ****
<listitem>
<para>
! <literal>hibernate.connection.xxxx</literal> = <emphasis>pass the JDBC property <literal>xxxx</literal>
! to <literal>DriverManager.getConnection()</literal></emphasis>
</para>
</listitem>
--- 175,180 ----
<listitem>
<para>
! <literal>hibernate.connection.xxxx</literal> = <emphasis>pass the JDBC property
! <literal>xxxx</literal> to <literal>DriverManager.getConnection()</literal></emphasis>
</para>
</listitem>
***************
*** 262,266 ****
<para>
<literal>hibernate.jndi.class</literal> = <emphasis>class of the JNDI
! InitialContextFactory</emphasis> (optional)
</para>
</listitem>
--- 264,274 ----
<para>
<literal>hibernate.jndi.class</literal> = <emphasis>class of the JNDI
! <literal>InitialContextFactory</literal></emphasis> (optional)
! </para>
! </listitem>
! <listitem>
! <para>
! <literal>hibernate.jndi.xxxx</literal> = <emphasis>pass the property <literal>xxxx</literal>
! to the JNDI <literal>InitialContextFactory</literal></emphasis> (optional)
</para>
</listitem>
***************
*** 521,530 ****
<para>
! An alternative approach is to specify a <literal>Datastore</literal> configuration in a
! file called <literal>hibernate.cfg.xml</literal> and then call
! <literal>Hibernate.configure()</literal> as many times as you like during application
! initialization (the actual configuration will only be done once). The configuration file
! is required in the root of your |CLASSPATH|. Your application may then obtain a reference
! to a <literal>SessionFactory</literal> from JNDI. The configuration file format looks like:
</para>
--- 529,535 ----
<para>
! An alternative approach is to specify a full configuration in a file named
! <literal>hibernate.cfg.xml</literal>. The configuration file is expected to
! be in the root of your |CLASSPATH|.
</para>
***************
*** 536,545 ****
<hibernate-configuration>
- <!-- shared properties -->
- <property name="show_sql">false</property>
- <property name="use_outer_join">true</property>
- <property name="jta.UserTransaction">
- java:comp/UserTransaction/
- </property>
<!-- a SessionFactory instance listed as /jndi/name -->
--- 541,544 ----
***************
*** 549,552 ****
--- 548,556 ----
<property name="connection.datasource">my/first/datasource</property>
<property name="dialect">net.sf.hibernate.sql.MySQLDialect</property>
+ <property name="show_sql">false</property>
+ <property name="use_outer_join">true</property>
+ <property name="jta.UserTransaction">
+ java:comp/UserTransaction/
+ </property>
<!-- mapping files -->
***************
*** 556,566 ****
</session-factory>
- <session-factory name="/another/jndi/name">
- <property name="connection.datasource">my/other/datasource</property>
- <property name="dialect">net.sf.hibernate.sql.OracleDialect</property>
- <mapping file="C:/mapping/my_mappings.hbm.xml"/>
- </session-factory>
-
</hibernate-configuration>]]></programlisting>
</sect1>
--- 560,572 ----
</session-factory>
</hibernate-configuration>]]></programlisting>
+
+ <para>
+ Configuring Hibernate is then as simple as
+ </para>
+
+ <programlisting><![CDATA[SessionFactory sf = new Configuration()
+ .configure()
+ .buildSessionFactory();]]></programlisting>
</sect1>
Index: transactions.xml
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/doc/reference/src/transactions.xml,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** transactions.xml 1 Jan 2003 13:46:39 -0000 1.1.1.1
--- transactions.xml 26 Jan 2003 03:17:45 -0000 1.2
***************
*** 13,17 ****
<sect1 id="transactions-s1">
! <title>Datastores, Sessions and Factories</title>
<para>
A <literal>SessionFactory</literal> is an expensive-to-create, threadsafe object
--- 13,17 ----
<sect1 id="transactions-s1">
! <title>Configurations, Sessions and Factories</title>
<para>
A <literal>SessionFactory</literal> is an expensive-to-create, threadsafe object
|