001    // Copyright 2011 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    // http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry5.jpa;
016    
017    import javax.persistence.SharedCacheMode;
018    import javax.persistence.ValidationMode;
019    import javax.persistence.spi.PersistenceUnitInfo;
020    import javax.persistence.spi.PersistenceUnitTransactionType;
021    import java.net.URL;
022    
023    /**
024     * Tapestry's mutable extension of {@link PersistenceUnitInfo} interface used for XML-less configuration
025     * of persistence units.
026     *
027     * @since 5.3
028     */
029    public interface TapestryPersistenceUnitInfo extends PersistenceUnitInfo
030    {
031        /**
032         * Set the the fully qualified name of the persistence provider implementation class.
033         * Corresponds to the <code>provider</code> element in the <code>persistence.xml</code> file.
034         *
035         * @param persistenceProviderClassName
036         *         persistence provider's class name
037         */
038        TapestryPersistenceUnitInfo persistenceProviderClassName(String persistenceProviderClassName);
039    
040        /**
041         * Set the transaction type of the entity managers. Corresponds to
042         * the <code>transaction-type</code> attribute in the <code>persistence.xml</code> file.
043         *
044         * @param transactionType
045         *         transition type to set
046         */
047        TapestryPersistenceUnitInfo transactionType(PersistenceUnitTransactionType transactionType);
048    
049        /**
050         * Set the non-JTA-enabled data source to be used by the persistence provider for accessing data outside a JTA
051         * transaction. Corresponds to the named <code>non-jta-data-source</code> element in the
052         * <code>persistence.xml</code> file.
053         *
054         * @param nonJtaDataSource
055         *         data source to set
056         */
057        TapestryPersistenceUnitInfo nonJtaDataSource(String nonJtaDataSource);
058    
059        /**
060         * Set the JTA-enabled data source to be used by the persistence provider for accessing data outside a JTA
061         * transaction. Corresponds to the named <code>jta-data-source</code> element in the
062         * <code>persistence.xml</code> file.
063         *
064         * @param jtaDataSource
065         *         data source to set
066         */
067        TapestryPersistenceUnitInfo jtaDataSource(String jtaDataSource);
068    
069        /**
070         * Add a managed class name to be used by persistence provider.
071         * Corresponds to a named <code>class</code> element in the <code>persistence.xml</code> file.
072         *
073         * @param className
074         *         class name to add
075         * @see #addManagedClass(Class)
076         */
077        TapestryPersistenceUnitInfo addManagedClassName(String className);
078    
079        /**
080         * Add a managed class to be used by persistence provider.
081         * Corresponds to a named <code>class</code> element in the <code>persistence.xml</code> file.
082         *
083         * @param clazz
084         *         class to add
085         * @see #addManagedClassName(String)
086         */
087        TapestryPersistenceUnitInfo addManagedClass(Class<?> clazz);
088    
089        /**
090         * Defines how the persistence provider must use a second-level cache for the persistence unit.
091         * Corresponds to the <code>shared-cache-mode</code> element in the <code>persistence.xml</code> file.
092         *
093         * @param cacheMode
094         *         cache mode to set
095         */
096        TapestryPersistenceUnitInfo sharedCacheMode(SharedCacheMode cacheMode);
097    
098        /**
099         * Set the validation mode to be used by the persistence provider for the persistence unit.
100         * Corresponds to the <code>validation-mode</code> element in the <code>persistence.xml</code> file.
101         *
102         * @param validationMode
103         *         validation mode to set
104         */
105        TapestryPersistenceUnitInfo validationMode(ValidationMode validationMode);
106    
107        /**
108         * Add a mapping file to be loaded by the persistence provider to determine the mappings for
109         * the entity classes. Corresponds to a <code>mapping-file</code> element in the <code>persistence.xml</code> file.
110         *
111         * @param fileName
112         *         mapping file name to add
113         */
114        TapestryPersistenceUnitInfo addMappingFileName(String fileName);
115    
116        /**
117         * Add a URLs for the jar file or exploded jar file directory that the persistence provider must examine
118         * for managed classes of the persistence unit. Corresponds to a <code>jar-file</code> element in the
119         * <code>persistence.xml</code> file.
120         *
121         * @param url
122         *         url to add
123         */
124        TapestryPersistenceUnitInfo addJarFileUrl(URL url);
125    
126        /**
127         * Add a URLs for the jar file or exploded jar file directory that the persistence provider must examine
128         * for managed classes of the persistence unit. Corresponds to a <code>jar-file</code> element in the
129         * <code>persistence.xml</code> file.
130         *
131         * @param url
132         *         url to add
133         */
134        TapestryPersistenceUnitInfo addJarFileUrl(String url);
135    
136        /**
137         * Add a property. Corresponds to a <code>property</code> element in the <code>persistence.xml</code> file.
138         *
139         * @param name
140         *         property's name
141         * @param value
142         *         property's value
143         */
144        TapestryPersistenceUnitInfo addProperty(String name, String value);
145    
146        /**
147         * Defines whether classes in the root of the persistence unit that have not been explicitly listed
148         * are to be included in the set of managed classes. Corresponds to the <code>exclude-unlisted-classes</code>
149         * element in the <code>persistence.xml</code> file.
150         *
151         * @param exclude
152         *         defines whether to exclude or not
153         */
154        TapestryPersistenceUnitInfo excludeUnlistedClasses(boolean exclude);
155    }