Hibernate SVN: r17949 - core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-11-10 13:17:46 -0500 (Tue, 10 Nov 2009)
New Revision: 17949
Modified:
core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/performance.xml
Log:
HHH-4550 - Document that update-timestamps cache region should not be configured for expiry.
Modified: core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/performance.xml
===================================================================
--- core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/performance.xml 2009-11-10 08:38:09 UTC (rev 17948)
+++ core/branches/Branch_3_3/documentation/manual/src/main/docbook/en-US/content/performance.xml 2009-11-10 18:17:46 UTC (rev 17949)
@@ -699,21 +699,21 @@
<entry>Hashtable (not intended for production use)</entry>
<entry><literal>org.hibernate.cache.HashtableCacheProvider</literal></entry>
<entry>memory</entry>
- <entry></entry>
+ <entry> </entry>
<entry>yes</entry>
</row>
<row>
<entry>EHCache</entry>
<entry><literal>org.hibernate.cache.EhCacheProvider</literal></entry>
<entry>memory, disk</entry>
- <entry></entry>
+ <entry> </entry>
<entry>yes</entry>
</row>
<row>
<entry>OSCache</entry>
<entry><literal>org.hibernate.cache.OSCacheProvider</literal></entry>
<entry>memory, disk</entry>
- <entry></entry>
+ <entry> </entry>
<entry>yes</entry>
</row>
<row>
@@ -721,7 +721,7 @@
<entry><literal>org.hibernate.cache.SwarmCacheProvider</literal></entry>
<entry>clustered (ip multicast)</entry>
<entry>yes (clustered invalidation)</entry>
- <entry></entry>
+ <entry> </entry>
</row>
<row>
<entry>JBoss Cache 1.x</entry>
@@ -902,41 +902,41 @@
<entry>yes</entry>
<entry>yes</entry>
<entry>yes</entry>
- <entry></entry>
+ <entry> </entry>
</row>
<row>
<entry>EHCache</entry>
<entry>yes</entry>
<entry>yes</entry>
<entry>yes</entry>
- <entry></entry>
+ <entry> </entry>
</row>
<row>
<entry>OSCache</entry>
<entry>yes</entry>
<entry>yes</entry>
<entry>yes</entry>
- <entry></entry>
+ <entry> </entry>
</row>
<row>
<entry>SwarmCache</entry>
<entry>yes</entry>
<entry>yes</entry>
- <entry></entry>
- <entry></entry>
+ <entry> </entry>
+ <entry> </entry>
</row>
<row>
<entry>JBoss Cache 1.x</entry>
<entry>yes</entry>
- <entry></entry>
- <entry></entry>
+ <entry> </entry>
+ <entry> </entry>
<entry>yes</entry>
</row>
<row>
<entry>JBoss Cache 2</entry>
<entry>yes</entry>
- <entry></entry>
- <entry></entry>
+ <entry> </entry>
+ <entry> </entry>
<entry>yes</entry>
</row>
</tbody>
@@ -1042,56 +1042,98 @@
hibernate.cache.use_structured_entries true]]></programlisting>
</sect1>
-
+
<sect1 id="performance-querycache" revision="1">
<title>The Query Cache</title>
<para>
Query result sets can also be cached. This is only useful for queries that are run
- frequently with the same parameters. You will first need to enable the query cache:
+ frequently with the same parameters.
</para>
- <programlisting><![CDATA[hibernate.cache.use_query_cache true]]></programlisting>
-
- <para>
- This setting creates two new cache regions: one holding cached query
- result sets (<literal>org.hibernate.cache.StandardQueryCache</literal>), the other
- holding timestamps of the most recent updates to queryable tables
- (<literal>org.hibernate.cache.UpdateTimestampsCache</literal>). Note that the query
- cache does not cache the state of the actual entities in the result set; it caches
- only identifier values and results of value type. The query cache should always be
- used in conjunction with the second-level cache.
- </para>
-
- <para>
- Most queries do not benefit from caching, so by default, queries are not cached. To
- enable caching, call <literal>Query.setCacheable(true)</literal>. This call allows
- the query to look for existing cache results or add its results to the cache when
- it is executed.
- </para>
-
- <para>
- If you require fine-grained control over query cache expiration policies, you can
- specify a named cache region for a particular query by calling
- <literal>Query.setCacheRegion()</literal>.
- </para>
-
- <programlisting><![CDATA[List blogs = sess.createQuery("from Blog blog where blog.blogger = :blogger")
- .setEntity("blogger", blogger)
- .setMaxResults(15)
- .setCacheable(true)
- .setCacheRegion("frontpages")
- .list();]]></programlisting>
+ <sect2 id="performance-querycache-enable">
+ <title>Enabling query caching</title>
+ <para>
+ Caching of query results introduces some overhead in terms of your applications normal
+ transactional processing. For example, if you cache results of a query against Person
+ Hibernate will need to keep track of when those results should be invalidated because
+ changes have been committed against Person. That, coupled with the fact that most
+ applications simply gain no benefit from caching query results, leads Hibernate to
+ disable caching of query results by default. To use query caching, you will first
+ need to enable the query cache:
+ </para>
+ <programlisting><![CDATA[hibernate.cache.use_query_cache true]]></programlisting>
+ <para>
+ This setting creates two new cache regions:
+ <itemizedlist>
+ <listitem>
+ <para>
+ <classname>org.hibernate.cache.StandardQueryCache</classname>, holding
+ the cached query results
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <classname>org.hibernate.cache.UpdateTimestampsCache</classname>, holding
+ timestamps of the most recent updates to queryable tables. These are used
+ to validate the results as they are served from the query cache.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ <important>
+ <para>
+ If you configure your underlying cache implementation to use expiry or
+ timeouts is is very important that the cache timeout of the underlying
+ cache region for the UpdateTimestampsCache be set to a higher value than
+ the timeouts of any of the query caches. In fact, we recommend that the
+ the UpdateTimestampsCache region not be configured for expiry at all. Note,
+ in particular, that an LRU cache expiry policy is never appropriate.
+ </para>
+ </important>
+ <para>
+ As mentioned above, most queries do not benefit from caching or their results. So by
+ default, individual queries are not cached even after enabling query caching. To enable
+ results caching for a particular query, call
+ <literal>org.hibernate.Query.setCacheable(true)</literal>. This call allows the query
+ to look for existing cache results or add its results to the cache when it is executed.
+ </para>
+ <note>
+ <para>
+ The query cache does not cache the state of the actual entities in the cache; it
+ caches only identifier values and results of value type. For this reaso, the query
+ cache should always be used in conjunction with the second-level cache for those
+ entities expected to be cached as part of a query result cache (just as with
+ collection caching).
+ </para>
+ </note>
+ </sect2>
- <para>
- If the query should force a refresh of its query cache region, you should call
- <literal>Query.setCacheMode(CacheMode.REFRESH)</literal>. This is particularly useful
- in cases where underlying data may have been updated via a separate process (i.e.,
- not modified through Hibernate) and allows the application to selectively refresh
- particular query result sets. This is a more efficient alternative to eviction of
- a query cache region via <literal>SessionFactory.evictQueries()</literal>.
- </para>
+ <sect2 id="performance-querycache-regions">
+ <title>Query cache regions</title>
+ <para>
+ If you require fine-grained control over query cache expiration policies, you can
+ specify a named cache region for a particular query by calling
+ <literal>Query.setCacheRegion()</literal>.
+ </para>
+ <programlisting role="JAVA"><![CDATA[List blogs = sess.createQuery("from Blog blog where blog.blogger = :blogger")
+ .setEntity("blogger", blogger)
+ .setMaxResults(15)
+ .setCacheable(true)
+ .setCacheRegion("frontpages")
+ .list();]]></programlisting>
+ <para>
+ If you want to force the query cache to refresh one of its regions (disregard any
+ cached results it finds there) you can use
+ <literal>org.hibernate.Query.setCacheMode(CacheMode.REFRESH)</literal>. In conjunction
+ with the region you have defined for the given query, Hibernate will selectively force
+ the results cached in that particular region to be refreshed. This is particularly useful
+ in cases where underlying data may have been updated via a separate process and is a far more
+ efficient alternative to bulk eviction of the region via
+ <literal>org.hibernate.SessionFactory.evictQueries()</literal>.
+ </para>
+ </sect2>
</sect1>
<sect1 id="performance-collections">
14 years, 6 months
DHL Tracking Number 3YMH6JJY
by DHL Service
Dear customer!
The courier company was not able to deliver your parcel by your address.
You may pickup the parcel at our post office personaly.
The shipping label is attached to this e-mail.
Please print this label to get this package at our post office.
Thank you for attention.
DHL Express Services.
14 years, 6 months
DHL Tracking Number 3YMH6JJY
by DHL Service
Dear customer!
The courier company was not able to deliver your parcel by your address.
You may pickup the parcel at our post office personaly.
The shipping label is attached to this e-mail.
Please print this label to get this package at our post office.
Thank you for attention.
DHL Express Services.
14 years, 6 months
Hibernate SVN: r17948 - in core/trunk/core/src/main/java/org/hibernate: impl and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-11-10 03:38:09 -0500 (Tue, 10 Nov 2009)
New Revision: 17948
Added:
core/trunk/core/src/main/java/org/hibernate/engine/NonFlushedChanges.java
core/trunk/core/src/main/java/org/hibernate/impl/NonFlushedChangesImpl.java
Modified:
core/trunk/core/src/main/java/org/hibernate/engine/CollectionEntry.java
core/trunk/core/src/main/java/org/hibernate/engine/CollectionKey.java
core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java
core/trunk/core/src/main/java/org/hibernate/engine/EntityKey.java
core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java
core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java
core/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
core/trunk/core/src/main/java/org/hibernate/util/MarkerObject.java
Log:
HHH-2762 : SessionImplementor.getNonFlushedChanges()/applyNonFlushedChanges() API and initial implementation
Modified: core/trunk/core/src/main/java/org/hibernate/engine/CollectionEntry.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/CollectionEntry.java 2009-11-07 00:38:39 UTC (rev 17947)
+++ core/trunk/core/src/main/java/org/hibernate/engine/CollectionEntry.java 2009-11-10 08:38:09 UTC (rev 17948)
@@ -266,7 +266,7 @@
}
void afterDeserialize(SessionFactoryImplementor factory) {
- loadedPersister = factory.getCollectionPersister(role);
+ loadedPersister = ( factory == null ? null : factory.getCollectionPersister(role) );
}
public boolean wasDereferenced() {
@@ -414,7 +414,7 @@
( String ) ois.readObject(),
( Serializable ) ois.readObject(),
( Serializable ) ois.readObject(),
- session.getFactory()
+ ( session == null ? null : session.getFactory() )
);
}
}
\ No newline at end of file
Modified: core/trunk/core/src/main/java/org/hibernate/engine/CollectionKey.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/CollectionKey.java 2009-11-07 00:38:39 UTC (rev 17947)
+++ core/trunk/core/src/main/java/org/hibernate/engine/CollectionKey.java 2009-11-10 08:38:09 UTC (rev 17948)
@@ -128,7 +128,7 @@
( Serializable ) ois.readObject(),
( Type ) ois.readObject(),
EntityMode.parse( ( String ) ois.readObject() ),
- session.getFactory()
+ ( session == null ? null : session.getFactory() )
);
}
}
\ No newline at end of file
Modified: core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java 2009-11-07 00:38:39 UTC (rev 17947)
+++ core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java 2009-11-10 08:38:09 UTC (rev 17948)
@@ -104,7 +104,7 @@
final boolean isBeingReplicated,
final boolean loadedWithLazyPropertiesUnfetched) {
this.entityName = entityName;
- this.persister = factory.getEntityPersister( entityName );
+ this.persister = ( factory == null ? null : factory.getEntityPersister( entityName ) );
this.id = id;
this.entityMode = entityMode;
this.status = status;
@@ -322,7 +322,7 @@
ObjectInputStream ois,
SessionImplementor session) throws IOException, ClassNotFoundException {
return new EntityEntry(
- session.getFactory(),
+ ( session == null ? null : session.getFactory() ),
( String ) ois.readObject(),
( Serializable ) ois.readObject(),
EntityMode.parse( ( String ) ois.readObject() ),
Modified: core/trunk/core/src/main/java/org/hibernate/engine/EntityKey.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/EntityKey.java 2009-11-07 00:38:39 UTC (rev 17947)
+++ core/trunk/core/src/main/java/org/hibernate/engine/EntityKey.java 2009-11-10 08:38:09 UTC (rev 17948)
@@ -171,7 +171,7 @@
( String ) ois.readObject(),
( Type ) ois.readObject(),
ois.readBoolean(),
- session.getFactory(),
+ ( session == null ? null : session.getFactory() ),
EntityMode.parse( ( String ) ois.readObject() )
);
}
Added: core/trunk/core/src/main/java/org/hibernate/engine/NonFlushedChanges.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/NonFlushedChanges.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/engine/NonFlushedChanges.java 2009-11-10 08:38:09 UTC (rev 17948)
@@ -0,0 +1,49 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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.
+ *
+ * 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
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.engine;
+
+/**
+ * This interface defines the public API for changes to an EventSource that have not
+ * been flushed to the database.
+ *
+ * @author Gail Badner
+ */
+
+import java.io.Serializable;
+import org.hibernate.event.EventSource;
+
+public interface NonFlushedChanges extends Serializable {
+
+ /**
+ * Extracts the non-flushed Changes from an EventSource into this NonFlushedChanges object.
+ * <p>
+ * @param source
+ */
+ void extractFromSession(EventSource source);
+
+ /**
+ * Remove the non-flushed changes from this NonFlushedChanges object.
+ */
+ void clear();
+}
\ No newline at end of file
Modified: core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java 2009-11-07 00:38:39 UTC (rev 17947)
+++ core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java 2009-11-10 08:38:09 UTC (rev 17948)
@@ -287,6 +287,24 @@
*/
int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException;
+
+ /**
+ * Return changes to this session that have not been flushed yet.
+ *
+ * @return The non-flushed changes.
+ */
+ public NonFlushedChanges getNonFlushedChanges() throws HibernateException;
+
+ /**
+ * Apply non-flushed changes from a different session to this session. It is assumed
+ * that this SessionImpl is "clean" (e.g., has no non-flushed changes, no cached entities,
+ * no cached collections, no queued actions). The specified NonFlushedChanges object cannot
+ * be bound to any session.
+ * <p/>
+ * @param nonFlushedChanges the non-flushed changes
+ */
+ public void applyNonFlushedChanges(NonFlushedChanges nonFlushedChanges) throws HibernateException;
+
// copied from Session:
public EntityMode getEntityMode();
Added: core/trunk/core/src/main/java/org/hibernate/impl/NonFlushedChangesImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/NonFlushedChangesImpl.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/impl/NonFlushedChangesImpl.java 2009-11-10 08:38:09 UTC (rev 17948)
@@ -0,0 +1,109 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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.
+ *
+ * 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
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.impl;
+
+/**
+ * An implementation of NonFlushedChanges.
+ *
+ * @author Gail Badner
+ */
+
+import org.hibernate.engine.NonFlushedChanges;
+import org.hibernate.engine.ActionQueue;
+import org.hibernate.engine.StatefulPersistenceContext;
+import org.hibernate.event.EventSource;
+import org.hibernate.AssertionFailure;
+import org.hibernate.EntityMode;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.io.Serializable;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class NonFlushedChangesImpl implements NonFlushedChanges {
+
+ private static final Logger log = LoggerFactory.getLogger(NonFlushedChangesImpl.class);
+
+ private static class SessionNonFlushedChanges implements Serializable {
+ private transient EntityMode entityMode;
+ private transient ActionQueue actionQueue;
+ private transient StatefulPersistenceContext persistenceContext;
+
+ public SessionNonFlushedChanges(EventSource session) {
+ this.entityMode = session.getEntityMode();
+ this.actionQueue = session.getActionQueue();
+ this.persistenceContext = ( StatefulPersistenceContext ) session.getPersistenceContext();
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+ ois.defaultReadObject();
+ entityMode = EntityMode.parse( ( String ) ois.readObject() );
+ persistenceContext = StatefulPersistenceContext.deserialize( ois, null );
+ actionQueue = ActionQueue.deserialize( ois, null );
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ log.trace( "serializing SessionNonFlushedChanges" );
+ oos.defaultWriteObject();
+ oos.writeObject( entityMode.toString() );
+ persistenceContext.serialize( oos );
+ actionQueue.serialize( oos );
+ }
+ }
+ private Map nonFlushedChangesByEntityMode = new HashMap();
+
+ public NonFlushedChangesImpl( EventSource session ) {
+ extractFromSession( session );
+ }
+
+ public void extractFromSession(EventSource session) {
+ if ( nonFlushedChangesByEntityMode.containsKey( session.getEntityMode() ) ) {
+ throw new AssertionFailure( "Already has non-flushed changes for entity mode: " + session.getEntityMode() );
+ }
+ nonFlushedChangesByEntityMode.put( session.getEntityMode(), new SessionNonFlushedChanges( session ) );
+ }
+
+ private SessionNonFlushedChanges getSessionNonFlushedChanges(EntityMode entityMode) {
+ return ( SessionNonFlushedChanges ) nonFlushedChangesByEntityMode.get( entityMode );
+ }
+
+ /* package-protected */
+ ActionQueue getActionQueue(EntityMode entityMode) {
+ return getSessionNonFlushedChanges( entityMode ).actionQueue;
+ }
+
+ /* package-protected */
+ StatefulPersistenceContext getPersistenceContext(EntityMode entityMode) {
+ return getSessionNonFlushedChanges( entityMode ).persistenceContext;
+ }
+
+ public void clear() {
+ nonFlushedChangesByEntityMode.clear();
+ }
+}
\ No newline at end of file
Modified: core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java 2009-11-07 00:38:39 UTC (rev 17947)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java 2009-11-10 08:38:09 UTC (rev 17948)
@@ -28,6 +28,8 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
@@ -72,6 +74,7 @@
import org.hibernate.engine.CollectionEntry;
import org.hibernate.engine.EntityEntry;
import org.hibernate.engine.EntityKey;
+import org.hibernate.engine.NonFlushedChanges;
import org.hibernate.engine.PersistenceContext;
import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.StatefulPersistenceContext;
@@ -127,9 +130,11 @@
import org.hibernate.stat.SessionStatistics;
import org.hibernate.stat.SessionStatisticsImpl;
import org.hibernate.type.Type;
+import org.hibernate.type.SerializationException;
import org.hibernate.util.ArrayHelper;
import org.hibernate.util.CollectionHelper;
import org.hibernate.util.StringHelper;
+import org.hibernate.util.SerializationHelper;
/**
@@ -377,6 +382,138 @@
}
}
+ /**
+ * Return changes to this session and its child sessions that have not been flushed yet.
+ * <p/>
+ * @return The non-flushed changes.
+ */
+ public NonFlushedChanges getNonFlushedChanges() throws HibernateException {
+ errorIfClosed();
+ checkTransactionSynchStatus();
+ NonFlushedChanges nonFlushedChanges = new NonFlushedChangesImpl( this );
+ if ( childSessionsByEntityMode != null ) {
+ Iterator it = childSessionsByEntityMode.values().iterator();
+ while ( it.hasNext() ) {
+ nonFlushedChanges.extractFromSession( ( EventSource ) it.next() );
+ }
+ }
+ return nonFlushedChanges;
+ }
+
+ /**
+ * Apply non-flushed changes from a different session to this session. It is assumed
+ * that this SessionImpl is "clean" (e.g., has no non-flushed changes, no cached entities,
+ * no cached collections, no queued actions). The specified NonFlushedChanges object cannot
+ * be bound to any session.
+ * <p/>
+ * @param nonFlushedChanges the non-flushed changes
+ */
+ public void applyNonFlushedChanges(NonFlushedChanges nonFlushedChanges) throws HibernateException {
+ errorIfClosed();
+ checkTransactionSynchStatus();
+ replacePersistenceContext( ( ( NonFlushedChangesImpl ) nonFlushedChanges ).getPersistenceContext( entityMode) );
+ replaceActionQueue( ( ( NonFlushedChangesImpl ) nonFlushedChanges ).getActionQueue( entityMode ) );
+ if ( childSessionsByEntityMode != null ) {
+ for ( Iterator it = childSessionsByEntityMode.values().iterator(); it.hasNext(); ) {
+ ( ( SessionImpl ) it.next() ).applyNonFlushedChanges( nonFlushedChanges );
+ }
+ }
+ }
+
+ private void replacePersistenceContext(StatefulPersistenceContext persistenceContextNew) {
+ if ( persistenceContextNew.getSession() != null ) {
+ throw new IllegalStateException( "new persistence context is already connected to a session " );
+ }
+ persistenceContext.clear();
+ ObjectInputStream ois = null;
+ try {
+ ois = new ObjectInputStream( new ByteArrayInputStream( serializePersistenceContext( persistenceContextNew ) ) );
+ this.persistenceContext = StatefulPersistenceContext.deserialize( ois, this );
+ }
+ catch (IOException ex) {
+ throw new SerializationException( "could not deserialize the persistence context", ex );
+ }
+ catch (ClassNotFoundException ex) {
+ throw new SerializationException( "could not deserialize the persistence context", ex );
+ }
+ finally {
+ try {
+ if (ois != null) ois.close();
+ }
+ catch (IOException ex) {}
+ }
+ }
+
+ private static byte[] serializePersistenceContext(StatefulPersistenceContext pc) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream( 512 );
+ ObjectOutputStream oos = null;
+ try {
+ oos = new ObjectOutputStream( baos );
+ ( ( StatefulPersistenceContext ) pc ).serialize( oos );
+ }
+ catch (IOException ex) {
+ throw new SerializationException( "could not serialize persistence context", ex );
+ }
+ finally {
+ if ( oos != null ) {
+ try {
+ oos.close();
+ }
+ catch( IOException ex ) {
+ //ignore
+ }
+ }
+ }
+ return baos.toByteArray();
+ }
+
+ private void replaceActionQueue(ActionQueue actionQueueNew) {
+ if ( actionQueue.hasAnyQueuedActions() ) {
+ throw new IllegalStateException( "cannot replace an ActionQueue with queued actions " );
+ }
+ actionQueue.clear();
+ ObjectInputStream ois = null;
+ try {
+ ois = new ObjectInputStream( new ByteArrayInputStream( serializeActionQueue( actionQueueNew ) ) );
+ actionQueue = ActionQueue.deserialize( ois, this );
+ }
+ catch (IOException ex) {
+ throw new SerializationException( "could not deserialize the action queue", ex );
+ }
+ catch (ClassNotFoundException ex) {
+ throw new SerializationException( "could not deserialize the action queue", ex );
+ }
+ finally {
+ try {
+ if (ois != null) ois.close();
+ }
+ catch (IOException ex) {}
+ }
+ }
+
+ private static byte[] serializeActionQueue(ActionQueue actionQueue) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream( 512 );
+ ObjectOutputStream oos = null;
+ try {
+ oos = new ObjectOutputStream( baos );
+ actionQueue.serialize( oos );
+ }
+ catch (IOException ex) {
+ throw new SerializationException( "could not serialize action queue", ex );
+ }
+ finally {
+ if ( oos != null ) {
+ try {
+ oos.close();
+ }
+ catch( IOException ex ) {
+ //ignore
+ }
+ }
+ }
+ return baos.toByteArray();
+ }
+
public boolean shouldAutoClose() {
return isAutoCloseSessionEnabled() && !isClosed();
}
Modified: core/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java 2009-11-07 00:38:39 UTC (rev 17947)
+++ core/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java 2009-11-10 08:38:09 UTC (rev 17948)
@@ -55,6 +55,7 @@
import org.hibernate.engine.StatefulPersistenceContext;
import org.hibernate.engine.Versioning;
import org.hibernate.engine.LoadQueryInfluencers;
+import org.hibernate.engine.NonFlushedChanges;
import org.hibernate.engine.query.HQLQueryPlan;
import org.hibernate.engine.query.NativeSQLQueryPlan;
import org.hibernate.engine.query.sql.NativeSQLQuerySpecification;
@@ -621,6 +622,14 @@
public void flush() {}
+ public NonFlushedChanges getNonFlushedChanges() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void applyNonFlushedChanges(NonFlushedChanges nonFlushedChanges) {
+ throw new UnsupportedOperationException();
+ }
+
public String getFetchProfile() {
return null;
}
Modified: core/trunk/core/src/main/java/org/hibernate/util/MarkerObject.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/MarkerObject.java 2009-11-07 00:38:39 UTC (rev 17947)
+++ core/trunk/core/src/main/java/org/hibernate/util/MarkerObject.java 2009-11-10 08:38:09 UTC (rev 17948)
@@ -24,10 +24,12 @@
*/
package org.hibernate.util;
+import java.io.Serializable;
+
/**
* @author Gavin King
*/
-public class MarkerObject {
+public class MarkerObject implements Serializable {
private String name;
public MarkerObject(String name) {
14 years, 6 months
DHL Tracking Number 3YMH6JJY
by DHL Service
Dear customer!
The courier company was not able to deliver your parcel by your address.
You may pickup the parcel at our post office personaly.
The shipping label is attached to this e-mail.
Please print this label to get this package at our post office.
Thank you for attention.
DHL Express Services.
14 years, 6 months
DHL Tracking Number 3YMH6JJY
by DHL Service
Dear customer!
The courier company was not able to deliver your parcel by your address.
You may pickup the parcel at our post office personaly.
The shipping label is attached to this e-mail.
Please print this label to get this package at our post office.
Thank you for attention.
DHL Express Services.
14 years, 6 months
Congratulations
by Media Service
Congratulations!! You have won todays Macbook Air.
Please open attached file and see datails.
14 years, 6 months
Hibernate SVN: r17947 - core/trunk/core/src/main/java/org/hibernate/action.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-11-06 19:38:39 -0500 (Fri, 06 Nov 2009)
New Revision: 17947
Modified:
core/trunk/core/src/main/java/org/hibernate/action/CollectionAction.java
Log:
HHH-4545 : change CollectionAction.readObject() to private
Modified: core/trunk/core/src/main/java/org/hibernate/action/CollectionAction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/action/CollectionAction.java 2009-11-06 18:23:48 UTC (rev 17946)
+++ core/trunk/core/src/main/java/org/hibernate/action/CollectionAction.java 2009-11-07 00:38:39 UTC (rev 17947)
@@ -65,7 +65,7 @@
return collection;
}
- protected void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
ois.defaultReadObject();
persister = session.getFactory().getCollectionPersister( collectionRole );
}
14 years, 6 months
Hibernate SVN: r17946 - in jpamodelgen/trunk/src: main/java/org/hibernate/jpamodelgen/annotation and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-11-06 13:23:48 -0500 (Fri, 06 Nov 2009)
New Revision: 17946
Added:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/ElementCollectionTest.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/House.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/Room.java
Modified:
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaAttribute.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java
jpamodelgen/trunk/src/test/suite/unit-tests.xml
Log:
METAGEN-8
Made sure that the right element type is extracted in case the is a ElementCollection on Map.
I think however, there are more problems. We only cover the java.util.Map case. We need to take care of subclasses as well.
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java 2009-11-06 16:02:26 UTC (rev 17945)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java 2009-11-06 18:23:48 UTC (rev 17946)
@@ -109,7 +109,7 @@
logMessage( Diagnostic.Kind.WARNING, "Element already processed (ignoring): " + element );
return;
}
- ClassWriter.writeFile( new AnnotationMetaEntity( pe, element, this, defaultAccessTypeForHierarchy ), this );
+ ClassWriter.writeFile( new AnnotationMetaEntity( element, this, defaultAccessTypeForHierarchy ), this );
elementsAlreadyProcessed.add( element.getQualifiedName().toString() );
}
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java 2009-11-06 16:02:26 UTC (rev 17945)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java 2009-11-06 18:23:48 UTC (rev 17946)
@@ -315,17 +315,13 @@
if ( element.getKind() == ElementKind.CLASS ) {
if ( annotationType.equals( ENTITY_ANN ) ) {
- AnnotationMetaEntity metaEntity = new AnnotationMetaEntity(
- processingEnv, ( TypeElement ) element, context
- );
+ AnnotationMetaEntity metaEntity = new AnnotationMetaEntity( ( TypeElement ) element, context );
// TODO instead of just adding the entity we have to do some merging.
context.getMetaEntitiesToProcess().put( metaEntity.getQualifiedName(), metaEntity );
}
else if ( annotationType.equals( MAPPED_SUPERCLASS_ANN )
|| annotationType.equals( EMBEDDABLE_ANN ) ) {
- AnnotationMetaEntity metaEntity = new AnnotationMetaEntity(
- processingEnv, ( TypeElement ) element, context
- );
+ AnnotationMetaEntity metaEntity = new AnnotationMetaEntity( ( TypeElement ) element, context );
// TODO instead of just adding the entity we have to do some merging.
context.getMetaSuperclassAndEmbeddableToProcess().put( metaEntity.getQualifiedName(), metaEntity );
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaAttribute.java 2009-11-06 16:02:26 UTC (rev 17945)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaAttribute.java 2009-11-06 18:23:48 UTC (rev 17946)
@@ -17,16 +17,14 @@
*/
package org.hibernate.jpamodelgen.annotation;
-import org.hibernate.jpamodelgen.MetaAttribute;
-
import java.beans.Introspector;
-
-import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
+import javax.lang.model.util.Elements;
+import org.hibernate.jpamodelgen.MetaAttribute;
+
/**
- *
* @author Max Andersen
* @author Hardy Ferentschik
* @author Emmanuel Bernard
@@ -35,40 +33,42 @@
final protected Element element;
final protected AnnotationMetaEntity parent;
- final protected ProcessingEnvironment pe;
private final String type;
public AnnotationMetaAttribute(AnnotationMetaEntity parent, Element element, String type) {
this.element = element;
this.parent = parent;
this.type = type;
- this.pe = parent.pe;
}
public String getDeclarationString() {
- return "public static volatile " + parent.importType(getMetaType()) + "<" + parent.importType(parent.getQualifiedName()) + ", " + parent.importType(getTypeDeclaration()) + "> " + getPropertyName() + ";";
+ return "public static volatile " + parent.importType( getMetaType() ) + "<" + parent.importType( parent.getQualifiedName() ) + ", " + parent
+ .importType( getTypeDeclaration() ) + "> " + getPropertyName() + ";";
}
public String getPropertyName() {
- if(element.getKind()==ElementKind.FIELD) {
+ Elements elementsUtil = parent.getContext().getProcessingEnvironment().getElementUtils();
+ if ( element.getKind() == ElementKind.FIELD ) {
return element.getSimpleName().toString();
- } else if (element.getKind()==ElementKind.METHOD) {
-
+ }
+ else if ( element.getKind() == ElementKind.METHOD ) {
String name = element.getSimpleName().toString();
- if(name.startsWith("get")) {
- return pe.getElementUtils().getName(Introspector.decapitalize(name.substring("get".length()))).toString();
- } else if(name.startsWith("is")) {
- return (pe.getElementUtils().getName(Introspector.decapitalize(name.substring("is".length())))).toString();
+ if ( name.startsWith( "get" ) ) {
+ return elementsUtil.getName( Introspector.decapitalize( name.substring( "get".length() ) ) ).toString();
}
- return pe.getElementUtils().getName(Introspector.decapitalize(name)).toString();
- } else {
- return pe.getElementUtils().getName(element.getSimpleName() + "/* " + element.getKind() + " */").toString();
+ else if ( name.startsWith( "is" ) ) {
+ return ( elementsUtil.getName( Introspector.decapitalize( name.substring( "is".length() ) ) ) ).toString();
+ }
+ return elementsUtil.getName( Introspector.decapitalize( name ) ).toString();
}
+ else {
+ return elementsUtil.getName( element.getSimpleName() + "/* " + element.getKind() + " */" ).toString();
+ }
}
abstract public String getMetaType();
public String getTypeDeclaration() {
- return type;
+ return type;
}
}
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java 2009-11-06 16:02:26 UTC (rev 17945)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java 2009-11-06 18:23:48 UTC (rev 17946)
@@ -21,7 +21,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
@@ -62,27 +61,37 @@
*/
public class AnnotationMetaEntity implements MetaEntity {
- final TypeElement element;
- final protected ProcessingEnvironment pe;
+ static Map<String, String> COLLECTIONS = new HashMap<String, String>();
- final ImportContext importContext;
+ static {
+ COLLECTIONS.put( "java.util.Collection", "javax.persistence.metamodel.CollectionAttribute" );
+ COLLECTIONS.put( "java.util.Set", "javax.persistence.metamodel.SetAttribute" );
+ COLLECTIONS.put( "java.util.List", "javax.persistence.metamodel.ListAttribute" );
+ COLLECTIONS.put( "java.util.Map", "javax.persistence.metamodel.MapAttribute" );
+ }
+
+ private final TypeElement element;
+ private final ImportContext importContext;
private Context context;
//used to propagate the access type of the root entity over to subclasses, superclasses and embeddable
private AccessType defaultAccessTypeForHierarchy;
private AccessType defaultAccessTypeForElement;
- public AnnotationMetaEntity(ProcessingEnvironment pe, TypeElement element, Context context) {
+ public AnnotationMetaEntity(TypeElement element, Context context) {
this.element = element;
- this.pe = pe;
+ this.context = context;
importContext = new ImportContextImpl( getPackageName() );
- this.context = context;
}
- public AnnotationMetaEntity(ProcessingEnvironment pe, TypeElement element, Context context, AccessType accessType) {
- this( pe, element, context );
+ public AnnotationMetaEntity(TypeElement element, Context context, AccessType accessType) {
+ this( element, context );
this.defaultAccessTypeForHierarchy = accessType;
}
+ public Context getContext() {
+ return context;
+ }
+
public String getSimpleName() {
return element.getSimpleName().toString();
}
@@ -92,8 +101,8 @@
}
public String getPackageName() {
- PackageElement packageOf = pe.getElementUtils().getPackageOf( element );
- return pe.getElementUtils().getName( packageOf.getQualifiedName() ).toString();
+ PackageElement packageOf = context.getProcessingEnvironment().getElementUtils().getPackageOf( element );
+ return context.getProcessingEnvironment().getElementUtils().getName( packageOf.getQualifiedName() ).toString();
}
public List<MetaAttribute> getMembers() {
@@ -153,10 +162,9 @@
accessType = this.defaultAccessTypeForHierarchy;
}
if ( accessType == null ) {
- //we dont' know
- //if an enity go up
+ //we don't know if an entity go up
//
- //superclasses alre always treated after their entities
+ //superclasses are always treated after their entities
//and their access type are discovered
//FIXME is it really true if only the superclass is changed
TypeElement superClass = element;
@@ -220,7 +228,7 @@
List<? extends Element> myMembers = searchedElement.getEnclosedElements();
for ( Element subElement : myMembers ) {
List<? extends AnnotationMirror> entityAnnotations =
- pe.getElementUtils().getAllAnnotationMirrors( subElement );
+ context.getProcessingEnvironment().getElementUtils().getAllAnnotationMirrors( subElement );
for ( Object entityAnnotation : entityAnnotations ) {
AnnotationMirror annotationMirror = ( AnnotationMirror ) entityAnnotation;
@@ -274,15 +282,6 @@
return sb.toString();
}
- static Map<String, String> COLLECTIONS = new HashMap<String, String>();
-
- static {
- COLLECTIONS.put( "java.util.Collection", "javax.persistence.metamodel.CollectionAttribute" );
- COLLECTIONS.put( "java.util.Set", "javax.persistence.metamodel.SetAttribute" );
- COLLECTIONS.put( "java.util.List", "javax.persistence.metamodel.ListAttribute" );
- COLLECTIONS.put( "java.util.Map", "javax.persistence.metamodel.MapAttribute" );
- }
-
class TypeVisitor extends SimpleTypeVisitor6<AnnotationMetaAttribute, Element> {
AnnotationMetaEntity parent;
@@ -343,15 +342,18 @@
public AnnotationMetaAttribute visitDeclared(DeclaredType t, Element element) {
//FIXME consider XML
if ( isPersistent( element ) ) {
- TypeElement returnedElement = ( TypeElement ) pe.getTypeUtils().asElement( t );
- String collection = COLLECTIONS.get( returnedElement.getQualifiedName().toString() ); // WARNING: .toString() is necessary here since Name equals does not compare to String
-
+ TypeElement returnedElement = ( TypeElement ) context.getProcessingEnvironment()
+ .getTypeUtils()
+ .asElement( t );
+ String fqElementName = returnedElement.getQualifiedName()
+ .toString(); // WARNING: .toString() is necessary here since Name equals does not compare to String
+ String collection = COLLECTIONS.get( fqElementName );
if ( collection != null ) {
- //collection of element
if ( element.getAnnotation( ElementCollection.class ) != null ) {
- final TypeMirror collectionType = t.getTypeArguments().get( 0 );
- final TypeElement collectionElement = ( TypeElement ) pe.getTypeUtils()
- .asElement( collectionType );
+ TypeMirror collectionElementType = getCollectionElementType( t, fqElementName );
+ final TypeElement collectionElement = ( TypeElement ) context.getProcessingEnvironment()
+ .getTypeUtils()
+ .asElement( collectionElementType );
this.parent.context.processElement(
collectionElement,
this.parent.defaultAccessTypeForElement
@@ -385,6 +387,17 @@
}
}
+ private TypeMirror getCollectionElementType(DeclaredType t, String fqElementName) {
+ TypeMirror collectionElementType;
+ if ( Map.class.getCanonicalName().equals( fqElementName ) ) {
+ collectionElementType = t.getTypeArguments().get( 1 );
+ }
+ else {
+ collectionElementType = t.getTypeArguments().get( 0 );
+ }
+ return collectionElementType;
+ }
+
@Override
public AnnotationMetaAttribute visitExecutable(ExecutableType t, Element p) {
String string = p.getSimpleName().toString();
Copied: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/ElementCollectionTest.java (from rev 17903, jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/inheritance/InheritanceTest.java)
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/ElementCollectionTest.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/ElementCollectionTest.java 2009-11-06 18:23:48 UTC (rev 17946)
@@ -0,0 +1,46 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen.test.elementcollection;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.jpamodelgen.test.util.CompilationTest;
+import static org.hibernate.jpamodelgen.test.util.TestUtil.assertClassGenerated;
+import static org.hibernate.jpamodelgen.test.util.TestUtil.assertClassNotFound;
+import static org.hibernate.jpamodelgen.test.util.TestUtil.assertNoGeneratedSourceFile;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ElementCollectionTest extends CompilationTest {
+ /**
+ * METAGEN-8
+ */
+ @Test
+ public void testElementCollectionOnMap() {
+ assertClassGenerated( House.class.getName() + "_" );
+ assertClassGenerated( House.class.getName() + "_" );
+ // side effect of METAGEN-8 was that a meta class for String was created!
+ assertNoGeneratedSourceFile( String.class.getName() + "_" );
+ }
+
+ @Override
+ protected String getTestPackage() {
+ return House.class.getPackage().getName();
+ }
+}
\ No newline at end of file
Added: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/House.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/House.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/House.java 2009-11-06 18:23:48 UTC (rev 17946)
@@ -0,0 +1,43 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen.test.elementcollection;
+
+import java.util.Map;
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.MapKeyColumn;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class House {
+ private Map<String, Room> roomsByName;
+
+ @ElementCollection
+ @MapKeyColumn(name = "room_name")
+ public Map<String, Room> getRoomsByName() {
+ return roomsByName;
+ }
+
+ public void setRoomsByName(Map<String, Room> roomsByName) {
+ this.roomsByName = roomsByName;
+ }
+}
+
+
Property changes on: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/House.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/Room.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/Room.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/Room.java 2009-11-06 18:23:48 UTC (rev 17946)
@@ -0,0 +1,48 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen.test.elementcollection;
+
+import java.math.BigDecimal;
+import javax.persistence.Embeddable;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Embeddable
+public class Room {
+ private BigDecimal length;
+ private BigDecimal width;
+
+ public BigDecimal getLength() {
+ return length;
+ }
+
+ public void setLength(BigDecimal length) {
+ this.length = length;
+ }
+
+ public BigDecimal getWidth() {
+ return width;
+ }
+
+ public void setWidth(BigDecimal width) {
+ this.width = width;
+ }
+}
+
+
Property changes on: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/Room.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java 2009-11-06 16:02:26 UTC (rev 17945)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java 2009-11-06 18:23:48 UTC (rev 17946)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
@@ -22,7 +22,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
@@ -112,7 +111,7 @@
FilenameFilter javaFileFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
- return name.endsWith( ".java" );
+ return name.endsWith( ".java" ) && !name.endsWith( "Test.java" );
}
};
for ( File file : packageDir.listFiles( javaFileFilter ) ) {
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java 2009-11-06 16:02:26 UTC (rev 17945)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java 2009-11-06 18:23:48 UTC (rev 17946)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
@@ -17,13 +17,18 @@
*/
package org.hibernate.jpamodelgen.test.util;
+import java.io.File;
+import java.io.FilenameFilter;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.Vector;
import org.testng.Assert;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.FileAssert.fail;
@@ -32,6 +37,17 @@
*/
public class TestUtil {
+ private static final String PATH_SEPARATOR = System.getProperty( "file.separator" );
+ private static final String outBaseDir;
+
+ static {
+ String tmp = System.getProperty( "outBaseDir" );
+ if ( tmp == null ) {
+ fail( "The system property outBaseDir has to be set and point to the base directory of the test output directory." );
+ }
+ outBaseDir = tmp;
+ }
+
private TestUtil() {
}
@@ -44,6 +60,25 @@
}
}
+ public static void assertClassNotFound(String className) {
+ try {
+ Class.forName( className );
+ fail( "Class " + className + " should not have been found." );
+ }
+ catch ( ClassNotFoundException e ) {
+ // success
+ }
+ }
+
+ public static void assertNoGeneratedSourceFile(String className) {
+ // generate the file name
+ String fileName = className.replace( ".", PATH_SEPARATOR );
+ fileName = fileName.concat( ".java" );
+ File sourceFile = new File(outBaseDir + PATH_SEPARATOR + fileName);
+ assertFalse(sourceFile.exists(), "There should be no source file: " + fileName);
+
+ }
+
public static void assertAbsenceOfField(String className, String fieldName) throws ClassNotFoundException {
assertAbsenceOfField( className, fieldName, "field should not be persistent" );
}
Modified: jpamodelgen/trunk/src/test/suite/unit-tests.xml
===================================================================
--- jpamodelgen/trunk/src/test/suite/unit-tests.xml 2009-11-06 16:02:26 UTC (rev 17945)
+++ jpamodelgen/trunk/src/test/suite/unit-tests.xml 2009-11-06 18:23:48 UTC (rev 17946)
@@ -5,6 +5,7 @@
<packages>
<package name="org.hibernate.jpamodelgen.test.accesstype"/>
<package name="org.hibernate.jpamodelgen.test.arraytype"/>
+ <package name="org.hibernate.jpamodelgen.test.elementcollection"/>
<package name="org.hibernate.jpamodelgen.test.inheritance"/>
<package name="org.hibernate.jpamodelgen.test.xmlmapped"/>
</packages>
14 years, 6 months
Congratulations
by Media Service
Congratulations!! You have won todays Macbook Air.
Please open attached file and see datails.
14 years, 6 months