Hibernate SVN: r19859 - core/trunk/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-06-30 07:50:41 -0400 (Wed, 30 Jun 2010)
New Revision: 19859
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/content/collection_mapping.xml
Log:
HHH-5149 Reviewing the collection mapping chapter
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/collection_mapping.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/collection_mapping.xml 2010-06-29 17:53:40 UTC (rev 19858)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/collection_mapping.xml 2010-06-30 11:50:41 UTC (rev 19859)
@@ -113,7 +113,7 @@
this:</para>
<example id="example.collection.mapping.annotations">
- <title>Collection mapping using annotations</title>
+ <title>Collection mapping using @OneToMany and @JoinColumn</title>
<programlisting role="JAVA">@Entity
public class Product {
@@ -126,6 +126,7 @@
void setSerialNumber(String sn) { serialNumber = sn; }
@OneToMany
+ @JoinColumn(name="PART_ID")
public Set<Part> getParts() { return parts; }
void setParts(Set parts) { this.parts = parts; }
}
@@ -137,9 +138,56 @@
}</programlisting>
</example>
- <para>Lets have a look how collections are mapped using Hibernate mapping
- files. Here the first step is to chose the right mapping element, because
- it depends on the type of interface. For example, a
+ <para>Product describes a unidirectional relationship with Part using the
+ join column PART_ID. In this unidirectional one to many scenario you can
+ also use a join table as seen in <xref
+ linkend="example-one-to-many-with-join-table" />.</para>
+
+ <example id="example-one-to-many-with-join-table">
+ <title id="example-one-to-many-with-join-table">Collection mapping using
+ @OneToMany and @JoinTable</title>
+
+ <programlisting role="JAVA">@Entity
+public class Product {
+
+ private String serialNumber;
+ private Set<Part> parts = new HashSet<Part>();
+
+ @Id
+ public String getSerialNumber() { return serialNumber; }
+ void setSerialNumber(String sn) { serialNumber = sn; }
+
+ @OneToMany
+ @JoinTable(
+ name="PRODUCT_PARTS",
+ joinColumns = @JoinColumn( name="PRODUCT_ID"),
+ inverseJoinColumns = @JoinColumn( name="PART_ID")
+ )
+ public Set<Part> getParts() { return parts; }
+ void setParts(Set parts) { this.parts = parts; }
+}
+
+
+@Entity
+public class Part {
+ ...
+}</programlisting>
+ </example>
+
+ <para>Without describing any physical mapping (no
+ <classname>@JoinColumn</classname> or <classname>@JoinTable</classname>),
+ a unidirectional one to many with join table is used. The table name is
+ the concatenation of the owner table name, _, and the other side table
+ name. The foreign key name(s) referencing the owner table is the
+ concatenation of the owner table, _, and the owner primary key column(s)
+ name. The foreign key name(s) referencing the other side is the
+ concatenation of the owner property name, _, and the other side primary
+ key column(s) name. A unique constraint is added to the foreign key
+ referencing the other side table to reflect the one to many.</para>
+
+ <para>Lets have a look now how collections are mapped using Hibernate
+ mapping files. In this case the first step is to chose the right mapping
+ element. It depends on the type of interface. For example, a
<literal><set></literal> element is used for mapping properties of
type <literal>Set</literal>.</para>
@@ -438,6 +486,10 @@
<section id="collections-indexed">
<title id="section.indexed.collections">Indexed collections</title>
+ <para>In the following paragraphs we have a closer at the indexed
+ collections <classname>List</classname> and <classname>Map</classname>
+ how the their index can be mapped in Hibernate.</para>
+
<section>
<title>Lists</title>
@@ -458,7 +510,7 @@
<para>To order lists in memory, add
<literal>@javax.persistence.OrderBy</literal> to your property. This
annotation takes as parameter a list of comma separated properties (of
- the target entity) and order the collection accordingly (eg
+ the target entity) and orders the collection accordingly (eg
<code>firstname asc, age desc</code>), if the string is empty, the
collection will be ordered by the primary key of the target
entity.</para>
@@ -516,7 +568,7 @@
<literal>orders_ORDER</literal>).</para>
<example>
- <title>Additional index column using
+ <title>Explicit index column using
<classname>@OrderColumn</classname></title>
<programlisting language="JAVA" role="JAVA">@Entity
@@ -569,11 +621,11 @@
is 0 like in Java.</para>
</note>
- <para>Using mapping files the index of an array or list is always of
- type <literal>integer</literal> and is mapped using the
- <literal><list-index></literal> element. The mapped column
- contains sequential integers that are numbered from zero by
- default.</para>
+ <para>Looking again at the Hibernate mapping file equivalent, the
+ index of an array or list is always of type <literal>integer</literal>
+ and is mapped using the <literal><list-index></literal> element.
+ The mapped column contains sequential integers that are numbered from
+ zero by default.</para>
<example>
<title>index-list element for indexed collections in xml
@@ -615,20 +667,21 @@
<section>
<title>Maps</title>
- <para>Maps can borrow their keys from one of the associated entity
- properties or have dedicated columns to store an explicit key.</para>
+ <para>The question with <classname>Map</classname>s is where the key
+ value is stored. There are everal options. Maps can borrow their keys
+ from one of the associated entity properties or have dedicated columns
+ to store an explicit key.</para>
<para>To use one of the target entity property as a key of the map,
- use <literal>@MapKey(name="myProperty")</literal>
- (<literal>myProperty</literal> is a property name in the target
- entity). When using <literal>@MapKey</literal> (without property
- name), the target entity primary key is used. The map key uses the
- same column as the property pointed out: there is no additional column
- defined to hold the map key, and it does make sense since the map key
- actually represent a target property. Be aware that once loaded, the
- key is no longer kept in sync with the property, in other words, if
- you change the property value, the key will not change automatically
- in your Java model.</para>
+ use <literal>@MapKey(name="myProperty")</literal>, where
+ <literal>myProperty</literal> is a property name in the target entity.
+ When using <literal>@MapKey</literal> without the name attribuate, the
+ target entity primary key is used. The map key uses the same column as
+ the property pointed out. There is no additional column defined to
+ hold the map key, because the map key represent a target property. Be
+ aware that once loaded, the key is no longer kept in sync with the
+ property. In other words, if you change the property value, the key
+ will not change automatically in your Java model.</para>
<example>
<title>Use of target entity property as map key via
@@ -673,14 +726,14 @@
|-------------|</programlisting>
</example>
- <para>Otherwise, the map key is mapped to a dedicated column or
+ <para>Alternatively the map key is mapped to a dedicated column or
columns. In order to customize the mapping use one of the following
annotations:</para>
<itemizedlist>
<listitem>
<para>@<classname>MapKeyColumn</classname> if the map key is a
- basic type, if you don't specify the column name, the name of the
+ basic type. If you don't specify the column name, the name of the
property followed by underscore followed by <literal>KEY</literal>
is used (for example <literal>orders_KEY</literal>).</para>
</listitem>
@@ -757,11 +810,11 @@
the new standard approach described above</para>
</note>
- <para>Using Hibernate mapping files there exists similar concepts
- using <literal><map-key></literal>,
+ <para>Using Hibernate mapping files there exists equivalent concepts
+ to the descibed annotations. You have to use
+ <literal><map-key></literal>,
<literal><map-key-many-to-many></literal> and
- <literal><composite-map-key></literal> which are even a little
- more flexible since SQL expressions can be used to define the map key.
+ <literal><composite-map-key></literal>.
<literal><map-key></literal> is used for any basic type,
<literal><map-key-many-to-many></literal> for an entity
reference and <literal><composite-map-key></literal> for a
@@ -845,11 +898,11 @@
</section>
<section id="collections-ofvalues" revision="2">
- <title>Collections of values</title>
+ <title>Collections of basic types and embeddable objects</title>
<para>In some situations you don't need to associate two entities but
simply create a collection of basic types or embeddable objects. Use the
- <classname>@ElementCollection</classname> in this case.</para>
+ <classname>@ElementCollection</classname> for this case.</para>
<example>
<title>Collection of basic types mapped via
@@ -869,7 +922,7 @@
<para>The collection table holding the collection data is set using the
<classname>@CollectionTable</classname> annotation. If omitted the
- collection table name default to the concatenation of the name of the
+ collection table name defaults to the concatenation of the name of the
containing entity and the name of the collection attribute, separated by
an underscore. In our example, it would be
<literal>User_nicknames</literal>.</para>
@@ -992,9 +1045,9 @@
<para>Hibernate supports collections implementing
<literal>java.util.SortedMap</literal> and
<literal>java.util.SortedSet</literal>. With annotations you declare a
- sort comparator using <literal>@Sort</literal>. You between the
+ sort comparator using <literal>@Sort</literal>. You chose between the
comparator types unsorted, natural or custom. If you want to use your
- own comparator implementation, you'll also have to express the
+ own comparator implementation, you'll also have to specify the
implementation class using the <literal>comparator</literal> attribute.
Note that you need to use either a <classname>SortedSet</classname> or a
<classname>SortedMap</classname> interface.</para>
@@ -1005,8 +1058,6 @@
<programlisting language="JAVA" role="JAVA">@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="CUST_ID")
@Sort(type = SortType.COMPARATOR, comparator = TicketComparator.class)
-@Where(clause="1=1")
-(a)OnDelete(action=OnDeleteAction.CASCADE)
public SortedSet<Ticket> getTickets() {
return tickets;
}</programlisting>
@@ -1036,17 +1087,18 @@
<literal>unsorted</literal>, <literal>natural</literal> and the name of
a class implementing <literal>java.util.Comparator</literal>.</para>
- <para>Sorted collections actually behave like
- <literal>java.util.TreeSet</literal> or
- <literal>java.util.TreeMap</literal>.</para>
+ <tip>
+ <para>Sorted collections actually behave like
+ <literal>java.util.TreeSet</literal> or
+ <literal>java.util.TreeMap</literal>.</para>
+ </tip>
<para>If you want the database itself to order the collection elements,
use the <literal>order-by</literal> attribute of <literal>set</literal>,
<literal>bag</literal> or <literal>map</literal> mappings. This solution
- is only available under JDK 1.4 or higher and is implemented using
- <literal>LinkedHashSet</literal> or <literal>LinkedHashMap</literal>.
- This performs the ordering in the SQL query and not in the
- memory.</para>
+ is implemented using <literal>LinkedHashSet</literal> or
+ <literal>LinkedHashMap</literal> and performs the ordering in the SQL
+ query and not in the memory.</para>
<example>
<title>Sorting in database using order-by</title>
@@ -1161,10 +1213,11 @@
}</programlisting>
</example>
- <para>Again a look at the maping file approach. There you can define a
- bidirectional one-to-many association by mapping a one-to-many
- association to the same table column(s) as a many-to-one association and
- declaring the many-valued end <literal>inverse="true"</literal>.</para>
+ <para>How does the mappping of a bidirectional mapping look like in
+ Hibernate mapping xml? There you define a bidirectional one-to-many
+ association by mapping a one-to-many association to the same table
+ column(s) as a many-to-one association and declaring the many-valued end
+ <literal>inverse="true"</literal>.</para>
<example>
<title>Bidirectional one to many via Hibernate mapping files</title>
@@ -1233,9 +1286,7 @@
} </programlisting>
</example>
- <para>We've already shown the many declarations and the detailed
- attributes for associations. We'll go deeper in the
- <literal>@JoinTable</literal> description, it defines a
+ <para>In this example <classname>@JoinTable</classname> defines a
<literal>name</literal>, an array of join columns, and an array of
inverse join columns. The latter ones are the columns of the association
table which refer to the <classname>Employee</classname> primary key
@@ -1323,11 +1374,12 @@
<para>You cannot select an indexed collection.</para>
</note></para>
- <para>Here is an example of a bidirectional many-to-many association
- that illustrates how each category can have many items and each item can
- be in many categories:</para>
+ <para><xref linkend="example-many-to-many-mapping-file" /> shows a
+ bidirectional many-to-many association that illustrates how each
+ category can have many items and each item can be in many
+ categories:</para>
- <example>
+ <example id="example-many-to-many-mapping-file">
<title>Many to many association using Hibernate mapping files</title>
<programlisting role="XML"><class name="Category">
@@ -1376,15 +1428,11 @@
<section id="collections-indexedbidirectional">
<title>Bidirectional associations with indexed collections</title>
- <para>Here are some additional consideration for bidirectional mappings
- with indexed collections using Hibernate mapping files. Refer also to
- <xref linkend="section.indexed.collections" /> and <xref
- linkend="section.sorted.collections" />.</para>
-
- <para>A bidirectional association where one end is represented as a
- <literal><list></literal> or <literal><map></literal>,
- requires special consideration. If there is a property of the child
- class that maps to the index column you can use
+ <para>There are some additional considerations for bidirectional
+ mappings with indexed collections (where one end is represented as a
+ <literal><list></literal> or <literal><map></literal>) when
+ using Hibernate mapping files. If there is a property of the child class
+ that maps to the index column you can use
<literal>inverse="true"</literal> on the collection mapping:</para>
<example>
@@ -1491,12 +1539,12 @@
<para>The majority of the many-to-many associations and collections of
values shown previously all map to tables with composite keys, even
- though it has been have suggested that entities should have synthetic
+ though it has been suggested that entities should have synthetic
identifiers (surrogate keys). A pure association table does not seem to
benefit much from a surrogate key, although a collection of composite
- values <emphasis>might</emphasis>. It is for this reason Hibernate
- provides a feature that allows you to map many-to-many associations and
- collections of values to a table with a surrogate key.</para>
+ values <emphasis>might</emphasis>. For this reason Hibernate provides a
+ feature that allows you to map many-to-many associations and collections
+ of values to a table with a surrogate key.</para>
<para>The <literal><idbag></literal> element lets you map a
<literal>List</literal> (or <literal>Collection</literal>) with bag
13 years, 10 months
Hibernate SVN: r19858 - core/branches/gradle2/buildSrc/src/main/groovy/org/hibernate/gradle/javadoc.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-06-29 13:53:40 -0400 (Tue, 29 Jun 2010)
New Revision: 19858
Modified:
core/branches/gradle2/buildSrc/src/main/groovy/org/hibernate/gradle/javadoc/Javadoc.groovy
Log:
use Jdk classes in release plugin and custom Javadoc task
Modified: core/branches/gradle2/buildSrc/src/main/groovy/org/hibernate/gradle/javadoc/Javadoc.groovy
===================================================================
--- core/branches/gradle2/buildSrc/src/main/groovy/org/hibernate/gradle/javadoc/Javadoc.groovy 2010-06-29 17:52:21 UTC (rev 19857)
+++ core/branches/gradle2/buildSrc/src/main/groovy/org/hibernate/gradle/javadoc/Javadoc.groovy 2010-06-29 17:53:40 UTC (rev 19858)
@@ -18,6 +18,7 @@
import org.gradle.external.javadoc.JavadocExecHandleBuilder
import org.gradle.api.tasks.OutputDirectory
import org.gradle.util.ConfigureUtil
+import org.hibernate.gradle.util.Jdk
/**
* TODO : javadoc
@@ -27,6 +28,8 @@
class Javadoc extends SourceTask {
private JavadocExecHandleBuilder javadocExecHandleBuilder = new JavadocExecHandleBuilder();
+ private Jdk jdk;
+
private File destinationDir;
private boolean failOnError = true;
@@ -53,6 +56,10 @@
options.classpath(new ArrayList<File>(getClasspath().getFiles()));
+ if ( jdk != null ) {
+ executable = jdk.getJavadocExecutable()
+ }
+
if (!GUtil.isTrue(options.getWindowTitle()) && GUtil.isTrue(getTitle())) {
options.windowTitle(getTitle());
}
13 years, 10 months
Hibernate SVN: r19857 - core/branches/gradle2/hibernate-release.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-06-29 13:52:21 -0400 (Tue, 29 Jun 2010)
New Revision: 19857
Modified:
core/branches/gradle2/hibernate-release/hibernate-release.gradle
Log:
use Jdk classes in release plugin and custom Javadoc task
Modified: core/branches/gradle2/hibernate-release/hibernate-release.gradle
===================================================================
--- core/branches/gradle2/hibernate-release/hibernate-release.gradle 2010-06-29 17:22:05 UTC (rev 19856)
+++ core/branches/gradle2/hibernate-release/hibernate-release.gradle 2010-06-29 17:52:21 UTC (rev 19857)
@@ -19,11 +19,6 @@
)
}
-task needs16 {
- if ( ! project.hasProperty('jdk16_home') ) {
- throw new Exception( "Property 'jdk16_home' must be set to run release" );
- }
-}
// jDocBook ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -59,7 +54,7 @@
task aggregateJavadocs(type: org.hibernate.gradle.javadoc.Javadoc) {
description = "Build the aggregated JavaDocs for all modules"
- executable = "$jdk16_home/bin/javadoc"
+ jdk = java6Home
maxMemory = '512m'
destinationDir = javadocBuildDir.dir
configure( options ) {
@@ -158,7 +153,7 @@
releaseBuildDir = dir( buildDirName )
-task uberJar(type: Jar, dependsOn: [releaseBuildDir, needs16]) {
+task uberJar(type: Jar, dependsOn: releaseBuildDir) {
description = "Builds the hibernate3.jar 'uber-jar'"
destinationDir = releaseBuildDir.dir
archiveName = 'hibernate3.jar'
@@ -200,7 +195,7 @@
// release bundles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-task prepareReleaseBundles( dependsOn: [buildDocs, aggregateJavadocs, uberJar, needs16] )
+task prepareReleaseBundles( dependsOn: [buildDocs, aggregateJavadocs, uberJar] )
releaseCopySpec = copySpec {
from new File( parent.projectDir, 'lgpl.txt' )
13 years, 10 months
Hibernate SVN: r19856 - core/branches/gradle2.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-06-29 13:22:05 -0400 (Tue, 29 Jun 2010)
New Revision: 19856
Modified:
core/branches/gradle2/settings.gradle
Log:
account for no ~/.gradle/gradle.properties file;
allow properties from command line (via sys-props)
Modified: core/branches/gradle2/settings.gradle
===================================================================
--- core/branches/gradle2/settings.gradle 2010-06-29 08:54:06 UTC (rev 19855)
+++ core/branches/gradle2/settings.gradle 2010-06-29 17:22:05 UTC (rev 19856)
@@ -12,8 +12,11 @@
include 'hibernate-swarmcache'
include 'hibernate-release'
-Properties properties = new Properties()
-properties.load(new FileInputStream(new File(gradle.gradleUserHomeDir, 'gradle.properties')))
+Properties properties = System.getProperties()
+File gradleDotProperties = new File(gradle.gradleUserHomeDir, 'gradle.properties')
+if ( gradleDotProperties.exists() ) {
+ properties.load( new FileInputStream( gradleDotProperties ) )
+}
// handle JDK 1.5 and JDK 1.6 evaluations
org.gradle.util.Jvm jvm = org.gradle.util.Jvm.current();
13 years, 10 months
Hibernate SVN: r19855 - core/trunk/core/src/main/java/org/hibernate/connection.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-06-29 04:54:06 -0400 (Tue, 29 Jun 2010)
New Revision: 19855
Modified:
core/trunk/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java
Log:
HHH-4156 c3p0 is not used when only specific hibernate.c3p0.* properties
and code style format
Modified: core/trunk/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java 2010-06-29 08:33:04 UTC (rev 19854)
+++ core/trunk/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java 2010-06-29 08:54:06 UTC (rev 19855)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,21 +20,20 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.connection;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.Map;
-import java.beans.Introspector;
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,17 +50,20 @@
* to choose either <tt>DriverManagerConnectionProvider</tt>,
* <tt>DatasourceConnectionProvider</tt>, <tt>C3P0ConnectionProvider</tt> or
* <tt>DBCPConnectionProvider</tt>.
+ *
+ * @author Gavin King
* @see ConnectionProvider
- * @author Gavin King
*/
public final class ConnectionProviderFactory {
- private static final Logger log = LoggerFactory.getLogger(ConnectionProviderFactory.class);
+ private static final Logger log = LoggerFactory.getLogger( ConnectionProviderFactory.class );
/**
* Instantiate a <tt>ConnectionProvider</tt> using <tt>System</tt> properties.
+ *
* @return The created connection provider.
+ *
* @throws HibernateException
*/
public static ConnectionProvider newConnectionProvider() throws HibernateException {
@@ -71,8 +73,11 @@
/**
* Instantiate a <tt>ConnectionProvider</tt> using given properties.
* Method newConnectionProvider.
+ *
* @param properties hibernate <tt>SessionFactory</tt> properties
+ *
* @return ConnectionProvider
+ *
* @throws HibernateException
*/
public static ConnectionProvider newConnectionProvider(Properties properties) throws HibernateException {
@@ -83,27 +88,26 @@
* Create a connection provider based on the given information.
*
* @param properties Properties being used to build the {@link org.hibernate.SessionFactory}.
- * @param connectionProviderInjectionData Soemthing to be injected in the conenction provided
+ * @param connectionProviderInjectionData Something to be injected in the connection provided
+ *
* @return The created connection provider
+ *
* @throws HibernateException
*/
- public static ConnectionProvider newConnectionProvider(Properties properties, Map connectionProviderInjectionData) throws HibernateException {
+ public static ConnectionProvider newConnectionProvider(Properties properties, Map connectionProviderInjectionData)
+ throws HibernateException {
ConnectionProvider connections;
- String providerClass = properties.getProperty(Environment.CONNECTION_PROVIDER);
- if ( providerClass!=null ) {
- try {
- log.info("Initializing connection provider: " + providerClass);
- connections = (ConnectionProvider) ReflectHelper.classForName(providerClass).newInstance();
- }
- catch ( Exception e ) {
- log.error( "Could not instantiate connection provider", e );
- throw new HibernateException("Could not instantiate connection provider: " + providerClass);
- }
+ String providerClass = properties.getProperty( Environment.CONNECTION_PROVIDER );
+ if ( providerClass != null ) {
+ connections = initializeConnectionProviderFromConfig( providerClass );
}
- else if ( properties.getProperty(Environment.DATASOURCE)!=null ) {
+ else if ( c3p0ConfigDefined( properties ) && c3p0ProviderPresent() ) {
+ connections = initializeConnectionProviderFromConfig("org.hibernate.connection.C3P0ConnectionProvider");
+ }
+ else if ( properties.getProperty( Environment.DATASOURCE ) != null ) {
connections = new DatasourceConnectionProvider();
}
- else if ( properties.getProperty(Environment.URL)!=null ) {
+ else if ( properties.getProperty( Environment.URL ) != null ) {
connections = new DriverManagerConnectionProvider();
}
else {
@@ -116,31 +120,72 @@
BeanInfo info = Introspector.getBeanInfo( connections.getClass() );
PropertyDescriptor[] descritors = info.getPropertyDescriptors();
int size = descritors.length;
- for (int index = 0 ; index < size ; index++) {
+ for ( int index = 0; index < size; index++ ) {
String propertyName = descritors[index].getName();
if ( connectionProviderInjectionData.containsKey( propertyName ) ) {
Method method = descritors[index].getWriteMethod();
- method.invoke( connections, new Object[] { connectionProviderInjectionData.get( propertyName ) } );
+ method.invoke(
+ connections, new Object[] { connectionProviderInjectionData.get( propertyName ) }
+ );
}
}
}
- catch (IntrospectionException e) {
- throw new HibernateException("Unable to inject objects into the conenction provider", e);
+ catch ( IntrospectionException e ) {
+ throw new HibernateException( "Unable to inject objects into the connection provider", e );
}
- catch (IllegalAccessException e) {
- throw new HibernateException("Unable to inject objects into the conenction provider", e);
+ catch ( IllegalAccessException e ) {
+ throw new HibernateException( "Unable to inject objects into the connection provider", e );
}
- catch (InvocationTargetException e) {
- throw new HibernateException("Unable to inject objects into the conenction provider", e);
+ catch ( InvocationTargetException e ) {
+ throw new HibernateException( "Unable to inject objects into the connection provider", e );
}
}
- connections.configure(properties);
+ connections.configure( properties );
return connections;
}
+ private static boolean c3p0ProviderPresent() {
+ try {
+ ReflectHelper.classForName( "org.hibernate.connection.C3P0ConnectionProvider" );
+ }
+ catch ( ClassNotFoundException e ) {
+ log.warn( "c3p0 properties is specificed, but could not find org.hibernate.connection.C3P0ConnectionProvider from the classpath, " +
+ "these properties are going to be ignored." );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean c3p0ConfigDefined(Properties properties) {
+ Iterator iter = properties.keySet().iterator();
+ while ( iter.hasNext() ) {
+ String property = (String) iter.next();
+ if ( property.startsWith( "hibernate.c3p0" ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static ConnectionProvider initializeConnectionProviderFromConfig(String providerClass) {
+ ConnectionProvider connections;
+ try {
+ log.info( "Initializing connection provider: " + providerClass );
+ connections = (ConnectionProvider) ReflectHelper.classForName( providerClass ).newInstance();
+ }
+ catch ( Exception e ) {
+ log.error( "Could not instantiate connection provider", e );
+ throw new HibernateException( "Could not instantiate connection provider: " + providerClass );
+ }
+ return connections;
+ }
+
// cannot be instantiated
- private ConnectionProviderFactory() { throw new UnsupportedOperationException(); }
+ private ConnectionProviderFactory() {
+ throw new UnsupportedOperationException();
+ }
+
/**
* Transform JDBC connection properties.
*
@@ -153,28 +198,31 @@
Properties result = new Properties();
while ( iter.hasNext() ) {
String prop = (String) iter.next();
- if ( prop.startsWith(Environment.CONNECTION_PREFIX) && !SPECIAL_PROPERTIES.contains(prop) ) {
+ if ( prop.startsWith( Environment.CONNECTION_PREFIX ) && !SPECIAL_PROPERTIES.contains( prop ) ) {
result.setProperty(
- prop.substring( Environment.CONNECTION_PREFIX.length()+1 ),
- properties.getProperty(prop)
+ prop.substring( Environment.CONNECTION_PREFIX.length() + 1 ),
+ properties.getProperty( prop )
);
}
}
- String userName = properties.getProperty(Environment.USER);
- if (userName!=null) result.setProperty( "user", userName );
+ String userName = properties.getProperty( Environment.USER );
+ if ( userName != null ) {
+ result.setProperty( "user", userName );
+ }
return result;
}
private static final Set SPECIAL_PROPERTIES;
+
static {
SPECIAL_PROPERTIES = new HashSet();
- SPECIAL_PROPERTIES.add(Environment.DATASOURCE);
- SPECIAL_PROPERTIES.add(Environment.URL);
- SPECIAL_PROPERTIES.add(Environment.CONNECTION_PROVIDER);
- SPECIAL_PROPERTIES.add(Environment.POOL_SIZE);
- SPECIAL_PROPERTIES.add(Environment.ISOLATION);
- SPECIAL_PROPERTIES.add(Environment.DRIVER);
- SPECIAL_PROPERTIES.add(Environment.USER);
+ SPECIAL_PROPERTIES.add( Environment.DATASOURCE );
+ SPECIAL_PROPERTIES.add( Environment.URL );
+ SPECIAL_PROPERTIES.add( Environment.CONNECTION_PROVIDER );
+ SPECIAL_PROPERTIES.add( Environment.POOL_SIZE );
+ SPECIAL_PROPERTIES.add( Environment.ISOLATION );
+ SPECIAL_PROPERTIES.add( Environment.DRIVER );
+ SPECIAL_PROPERTIES.add( Environment.USER );
}
13 years, 10 months
Hibernate SVN: r19854 - core/branches/Branch_3_5/core/src/main/java/org/hibernate/connection.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-06-29 04:33:04 -0400 (Tue, 29 Jun 2010)
New Revision: 19854
Modified:
core/branches/Branch_3_5/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java
Log:
HHH-4156 c3p0 is not used when only specific hibernate.c3p0.* properties
and format the code style
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java 2010-06-29 07:25:17 UTC (rev 19853)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java 2010-06-29 08:33:04 UTC (rev 19854)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,21 +20,20 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.connection;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.Map;
-import java.beans.Introspector;
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,17 +50,20 @@
* to choose either <tt>DriverManagerConnectionProvider</tt>,
* <tt>DatasourceConnectionProvider</tt>, <tt>C3P0ConnectionProvider</tt> or
* <tt>DBCPConnectionProvider</tt>.
+ *
+ * @author Gavin King
* @see ConnectionProvider
- * @author Gavin King
*/
public final class ConnectionProviderFactory {
- private static final Logger log = LoggerFactory.getLogger(ConnectionProviderFactory.class);
+ private static final Logger log = LoggerFactory.getLogger( ConnectionProviderFactory.class );
/**
* Instantiate a <tt>ConnectionProvider</tt> using <tt>System</tt> properties.
+ *
* @return The created connection provider.
+ *
* @throws HibernateException
*/
public static ConnectionProvider newConnectionProvider() throws HibernateException {
@@ -71,8 +73,11 @@
/**
* Instantiate a <tt>ConnectionProvider</tt> using given properties.
* Method newConnectionProvider.
+ *
* @param properties hibernate <tt>SessionFactory</tt> properties
+ *
* @return ConnectionProvider
+ *
* @throws HibernateException
*/
public static ConnectionProvider newConnectionProvider(Properties properties) throws HibernateException {
@@ -83,27 +88,26 @@
* Create a connection provider based on the given information.
*
* @param properties Properties being used to build the {@link org.hibernate.SessionFactory}.
- * @param connectionProviderInjectionData Soemthing to be injected in the conenction provided
+ * @param connectionProviderInjectionData Something to be injected in the connection provided
+ *
* @return The created connection provider
+ *
* @throws HibernateException
*/
- public static ConnectionProvider newConnectionProvider(Properties properties, Map connectionProviderInjectionData) throws HibernateException {
+ public static ConnectionProvider newConnectionProvider(Properties properties, Map connectionProviderInjectionData)
+ throws HibernateException {
ConnectionProvider connections;
- String providerClass = properties.getProperty(Environment.CONNECTION_PROVIDER);
- if ( providerClass!=null ) {
- try {
- log.info("Initializing connection provider: " + providerClass);
- connections = (ConnectionProvider) ReflectHelper.classForName(providerClass).newInstance();
- }
- catch ( Exception e ) {
- log.error( "Could not instantiate connection provider", e );
- throw new HibernateException("Could not instantiate connection provider: " + providerClass);
- }
+ String providerClass = properties.getProperty( Environment.CONNECTION_PROVIDER );
+ if ( providerClass != null ) {
+ connections = initializeConnectionProviderFromConfig( providerClass );
}
- else if ( properties.getProperty(Environment.DATASOURCE)!=null ) {
+ else if ( c3p0ConfigDefined( properties ) && c3p0ProviderPresent() ) {
+ connections = initializeConnectionProviderFromConfig("org.hibernate.connection.C3P0ConnectionProvider");
+ }
+ else if ( properties.getProperty( Environment.DATASOURCE ) != null ) {
connections = new DatasourceConnectionProvider();
}
- else if ( properties.getProperty(Environment.URL)!=null ) {
+ else if ( properties.getProperty( Environment.URL ) != null ) {
connections = new DriverManagerConnectionProvider();
}
else {
@@ -116,31 +120,72 @@
BeanInfo info = Introspector.getBeanInfo( connections.getClass() );
PropertyDescriptor[] descritors = info.getPropertyDescriptors();
int size = descritors.length;
- for (int index = 0 ; index < size ; index++) {
+ for ( int index = 0; index < size; index++ ) {
String propertyName = descritors[index].getName();
if ( connectionProviderInjectionData.containsKey( propertyName ) ) {
Method method = descritors[index].getWriteMethod();
- method.invoke( connections, new Object[] { connectionProviderInjectionData.get( propertyName ) } );
+ method.invoke(
+ connections, new Object[] { connectionProviderInjectionData.get( propertyName ) }
+ );
}
}
}
- catch (IntrospectionException e) {
- throw new HibernateException("Unable to inject objects into the conenction provider", e);
+ catch ( IntrospectionException e ) {
+ throw new HibernateException( "Unable to inject objects into the connection provider", e );
}
- catch (IllegalAccessException e) {
- throw new HibernateException("Unable to inject objects into the conenction provider", e);
+ catch ( IllegalAccessException e ) {
+ throw new HibernateException( "Unable to inject objects into the connection provider", e );
}
- catch (InvocationTargetException e) {
- throw new HibernateException("Unable to inject objects into the conenction provider", e);
+ catch ( InvocationTargetException e ) {
+ throw new HibernateException( "Unable to inject objects into the connection provider", e );
}
}
- connections.configure(properties);
+ connections.configure( properties );
return connections;
}
+ private static boolean c3p0ProviderPresent() {
+ try {
+ ReflectHelper.classForName( "org.hibernate.connection.C3P0ConnectionProvider" );
+ }
+ catch ( ClassNotFoundException e ) {
+ log.warn( "c3p0 properties is specificed, but could not find org.hibernate.connection.C3P0ConnectionProvider from the classpath, " +
+ "these properties are going to be ignored." );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean c3p0ConfigDefined(Properties properties) {
+ Iterator iter = properties.keySet().iterator();
+ while ( iter.hasNext() ) {
+ String property = (String) iter.next();
+ if ( property.startsWith( "hibernate.c3p0" ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static ConnectionProvider initializeConnectionProviderFromConfig(String providerClass) {
+ ConnectionProvider connections;
+ try {
+ log.info( "Initializing connection provider: " + providerClass );
+ connections = (ConnectionProvider) ReflectHelper.classForName( providerClass ).newInstance();
+ }
+ catch ( Exception e ) {
+ log.error( "Could not instantiate connection provider", e );
+ throw new HibernateException( "Could not instantiate connection provider: " + providerClass );
+ }
+ return connections;
+ }
+
// cannot be instantiated
- private ConnectionProviderFactory() { throw new UnsupportedOperationException(); }
+ private ConnectionProviderFactory() {
+ throw new UnsupportedOperationException();
+ }
+
/**
* Transform JDBC connection properties.
*
@@ -153,28 +198,31 @@
Properties result = new Properties();
while ( iter.hasNext() ) {
String prop = (String) iter.next();
- if ( prop.startsWith(Environment.CONNECTION_PREFIX) && !SPECIAL_PROPERTIES.contains(prop) ) {
+ if ( prop.startsWith( Environment.CONNECTION_PREFIX ) && !SPECIAL_PROPERTIES.contains( prop ) ) {
result.setProperty(
- prop.substring( Environment.CONNECTION_PREFIX.length()+1 ),
- properties.getProperty(prop)
+ prop.substring( Environment.CONNECTION_PREFIX.length() + 1 ),
+ properties.getProperty( prop )
);
}
}
- String userName = properties.getProperty(Environment.USER);
- if (userName!=null) result.setProperty( "user", userName );
+ String userName = properties.getProperty( Environment.USER );
+ if ( userName != null ) {
+ result.setProperty( "user", userName );
+ }
return result;
}
private static final Set SPECIAL_PROPERTIES;
+
static {
SPECIAL_PROPERTIES = new HashSet();
- SPECIAL_PROPERTIES.add(Environment.DATASOURCE);
- SPECIAL_PROPERTIES.add(Environment.URL);
- SPECIAL_PROPERTIES.add(Environment.CONNECTION_PROVIDER);
- SPECIAL_PROPERTIES.add(Environment.POOL_SIZE);
- SPECIAL_PROPERTIES.add(Environment.ISOLATION);
- SPECIAL_PROPERTIES.add(Environment.DRIVER);
- SPECIAL_PROPERTIES.add(Environment.USER);
+ SPECIAL_PROPERTIES.add( Environment.DATASOURCE );
+ SPECIAL_PROPERTIES.add( Environment.URL );
+ SPECIAL_PROPERTIES.add( Environment.CONNECTION_PROVIDER );
+ SPECIAL_PROPERTIES.add( Environment.POOL_SIZE );
+ SPECIAL_PROPERTIES.add( Environment.ISOLATION );
+ SPECIAL_PROPERTIES.add( Environment.DRIVER );
+ SPECIAL_PROPERTIES.add( Environment.USER );
}
13 years, 10 months
Hibernate SVN: r19853 - core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-06-29 03:25:17 -0400 (Tue, 29 Jun 2010)
New Revision: 19853
Modified:
core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/Ingres10Dialect.java
Log:
HHH-5213 Add native SQL Boolean type to Ingres10Dialect
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/Ingres10Dialect.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/Ingres10Dialect.java 2010-06-29 07:24:22 UTC (rev 19852)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/Ingres10Dialect.java 2010-06-29 07:25:17 UTC (rev 19853)
@@ -1,6 +1,7 @@
package org.hibernate.dialect;
import java.sql.Types;
+import java.util.Properties;
import org.hibernate.Hibernate;
import org.hibernate.cfg.Environment;
@@ -8,9 +9,10 @@
/**
* A SQL dialect for Ingres 10 and later versions.
- *
+ * <p/>
* Changes:
* <ul>
+ * <li>Add native BOOLEAN type support</li>
* </ul>
*
* @author Raymond Fan
@@ -18,5 +20,39 @@
public class Ingres10Dialect extends Ingres9Dialect {
public Ingres10Dialect() {
super();
+ registerBooleanSupport();
}
+
+ // Boolean column type support
+
+ /**
+ * The SQL literal value to which this database maps boolean values.
+ *
+ * @param bool The boolean value
+ * @return The appropriate SQL literal.
+ */
+ public String toBooleanValueString(boolean bool) {
+ return bool ? "true" : "false";
+ }
+
+ protected void registerBooleanSupport() {
+ // Column type
+
+ // Boolean type (mapping/BooleanType) mapping maps SQL BIT to Java
+ // Boolean. In order to create a boolean column, BIT needs to be mapped
+ // to boolean as well, similar to H2Dialect.
+ registerColumnType( Types.BIT, "boolean" );
+ registerColumnType( Types.BOOLEAN, "boolean" );
+
+ // Functions
+
+ // true, false and unknown are now valid values
+ // Remove the query substitutions previously added in IngresDialect.
+ Properties properties = getDefaultProperties();
+ String querySubst = properties.getProperty(Environment.QUERY_SUBSTITUTIONS);
+ if (querySubst != null) {
+ String newQuerySubst = querySubst.replace("true=1,false=0","");
+ properties.setProperty(Environment.QUERY_SUBSTITUTIONS, newQuerySubst);
+ }
+ }
}
13 years, 10 months
Hibernate SVN: r19852 - core/trunk/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-06-29 03:24:22 -0400 (Tue, 29 Jun 2010)
New Revision: 19852
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/Ingres10Dialect.java
Log:
HHH-5213 Add native SQL Boolean type to Ingres10Dialect
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/Ingres10Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/Ingres10Dialect.java 2010-06-29 07:07:39 UTC (rev 19851)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/Ingres10Dialect.java 2010-06-29 07:24:22 UTC (rev 19852)
@@ -1,6 +1,7 @@
package org.hibernate.dialect;
import java.sql.Types;
+import java.util.Properties;
import org.hibernate.Hibernate;
import org.hibernate.cfg.Environment;
@@ -8,9 +9,10 @@
/**
* A SQL dialect for Ingres 10 and later versions.
- *
+ * <p/>
* Changes:
* <ul>
+ * <li>Add native BOOLEAN type support</li>
* </ul>
*
* @author Raymond Fan
@@ -18,5 +20,39 @@
public class Ingres10Dialect extends Ingres9Dialect {
public Ingres10Dialect() {
super();
+ registerBooleanSupport();
}
+
+ // Boolean column type support
+
+ /**
+ * The SQL literal value to which this database maps boolean values.
+ *
+ * @param bool The boolean value
+ * @return The appropriate SQL literal.
+ */
+ public String toBooleanValueString(boolean bool) {
+ return bool ? "true" : "false";
+ }
+
+ protected void registerBooleanSupport() {
+ // Column type
+
+ // Boolean type (mapping/BooleanType) mapping maps SQL BIT to Java
+ // Boolean. In order to create a boolean column, BIT needs to be mapped
+ // to boolean as well, similar to H2Dialect.
+ registerColumnType( Types.BIT, "boolean" );
+ registerColumnType( Types.BOOLEAN, "boolean" );
+
+ // Functions
+
+ // true, false and unknown are now valid values
+ // Remove the query substitutions previously added in IngresDialect.
+ Properties properties = getDefaultProperties();
+ String querySubst = properties.getProperty(Environment.QUERY_SUBSTITUTIONS);
+ if (querySubst != null) {
+ String newQuerySubst = querySubst.replace("true=1,false=0","");
+ properties.setProperty(Environment.QUERY_SUBSTITUTIONS, newQuerySubst);
+ }
+ }
}
13 years, 10 months
Hibernate SVN: r19851 - core/trunk/annotations/src/main/java/org/hibernate/annotations.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-06-29 03:07:39 -0400 (Tue, 29 Jun 2010)
New Revision: 19851
Modified:
core/trunk/annotations/src/main/java/org/hibernate/annotations/PolymorphismType.java
Log:
HHH-5336 a few typo fixes
Modified: core/trunk/annotations/src/main/java/org/hibernate/annotations/PolymorphismType.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/annotations/PolymorphismType.java 2010-06-29 07:04:07 UTC (rev 19850)
+++ core/trunk/annotations/src/main/java/org/hibernate/annotations/PolymorphismType.java 2010-06-29 07:07:39 UTC (rev 19851)
@@ -24,7 +24,7 @@
package org.hibernate.annotations;
/**
- * Type of avaliable polymorphism for a particular entity
+ * Type of available polymorphism for a particular entity
*
* @author Emmanuel Bernard
*/
@@ -34,7 +34,7 @@
*/
IMPLICIT,
/**
- * this entity is retrived only if explicitly asked
+ * this entity is retrieved only if explicitly asked
*/
EXPLICIT
-}
\ No newline at end of file
+}
13 years, 10 months
Hibernate SVN: r19850 - core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/annotations.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-06-29 03:04:07 -0400 (Tue, 29 Jun 2010)
New Revision: 19850
Modified:
core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/annotations/PolymorphismType.java
Log:
HHH-5336 a few typo fixes
Modified: core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/annotations/PolymorphismType.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/annotations/PolymorphismType.java 2010-06-29 07:01:11 UTC (rev 19849)
+++ core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/annotations/PolymorphismType.java 2010-06-29 07:04:07 UTC (rev 19850)
@@ -24,7 +24,7 @@
package org.hibernate.annotations;
/**
- * Type of avaliable polymorphism for a particular entity
+ * Type of available polymorphism for a particular entity
*
* @author Emmanuel Bernard
*/
@@ -34,7 +34,7 @@
*/
IMPLICIT,
/**
- * this entity is retrived only if explicitly asked
+ * this entity is retrieved only if explicitly asked
*/
EXPLICIT
}
\ No newline at end of file
13 years, 10 months