KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > jpa > vendor > TopLinkJpaVendorAdapter


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.orm.jpa.vendor;
18
19 import java.util.Map JavaDoc;
20 import java.util.Properties JavaDoc;
21 import java.util.logging.Level JavaDoc;
22
23 import javax.persistence.EntityManager;
24 import javax.persistence.spi.PersistenceProvider;
25
26 import oracle.toplink.essentials.config.TargetDatabase;
27 import oracle.toplink.essentials.config.TopLinkProperties;
28 import oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider;
29
30 import org.springframework.orm.jpa.JpaDialect;
31
32 /**
33  * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for
34  * Oracle TopLink Essentials. Developed and tested against TopLink Essentials v2.
35  *
36  * <p>Exposes TopLink's persistence provider and EntityManager extension interface,
37  * and supports AbstractJpaVendorAdapter's common configuration settings.
38  *
39  * @author Rod Johnson
40  * @author Juergen Hoeller
41  * @since 2.0
42  * @see oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider
43  * @see oracle.toplink.essentials.ejb.cmp3.EntityManager
44  */

45 public class TopLinkJpaVendorAdapter extends AbstractJpaVendorAdapter {
46
47     private final PersistenceProvider persistenceProvider = new EntityManagerFactoryProvider();
48
49     private final JpaDialect jpaDialect = new TopLinkJpaDialect();
50
51
52     public PersistenceProvider getPersistenceProvider() {
53         return this.persistenceProvider;
54     }
55
56     public Map JavaDoc getJpaPropertyMap() {
57         Properties JavaDoc jpaProperties = new Properties JavaDoc();
58
59         if (getDatabasePlatform() != null) {
60             jpaProperties.setProperty(TopLinkProperties.TARGET_DATABASE, getDatabasePlatform());
61         }
62         else if (getDatabase() != null) {
63             String JavaDoc targetDatabase = determineTargetDatabaseName(getDatabase());
64             if (targetDatabase != null) {
65                 jpaProperties.setProperty(TopLinkProperties.TARGET_DATABASE, targetDatabase);
66             }
67         }
68
69         if (isGenerateDdl()) {
70             jpaProperties.setProperty(EntityManagerFactoryProvider.DDL_GENERATION,
71                     EntityManagerFactoryProvider.CREATE_ONLY);
72             jpaProperties.setProperty(EntityManagerFactoryProvider.DDL_GENERATION_MODE,
73                     EntityManagerFactoryProvider.DDL_DATABASE_GENERATION);
74         }
75         if (isShowSql()) {
76             jpaProperties.setProperty(TopLinkProperties.LOGGING_LEVEL, Level.FINE.toString());
77         }
78
79         return jpaProperties;
80     }
81
82     /**
83      * Determine the TopLink target database name for the given database.
84      * @param database the specified database
85      * @return the TopLink target database name, or <code>null<code> if none found
86      */

87     protected String JavaDoc determineTargetDatabaseName(Database database) {
88         switch (database) {
89             case DB2: return TargetDatabase.DB2;
90             case HSQL: return TargetDatabase.HSQL;
91             case INFORMIX: return TargetDatabase.Informix;
92             case MYSQL: return TargetDatabase.MySQL4;
93             case ORACLE: return TargetDatabase.Oracle;
94             case POSTGRESQL: return TargetDatabase.PostgreSQL;
95             case SQL_SERVER: return TargetDatabase.SQLServer;
96             case SYBASE: return TargetDatabase.Sybase;
97             default: return null;
98         }
99     }
100
101     public Class JavaDoc<? extends EntityManager> getEntityManagerInterface() {
102         return oracle.toplink.essentials.ejb.cmp3.EntityManager.class;
103     }
104
105     public JpaDialect getJpaDialect() {
106         return this.jpaDialect;
107     }
108
109 }
110
Popular Tags