You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hise-commits@incubator.apache.org by rr...@apache.org on 2010/01/15 13:57:07 UTC

svn commit: r899631 - in /incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/vendor: ./ OpenJpaVendorAdapter.java

Author: rr
Date: Fri Jan 15 13:57:06 2010
New Revision: 899631

URL: http://svn.apache.org/viewvc?rev=899631&view=rev
Log:
HISE-3: Update

Added:
    incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/vendor/
    incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/vendor/OpenJpaVendorAdapter.java   (with props)

Added: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/vendor/OpenJpaVendorAdapter.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/vendor/OpenJpaVendorAdapter.java?rev=899631&view=auto
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/vendor/OpenJpaVendorAdapter.java (added)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/vendor/OpenJpaVendorAdapter.java Fri Jan 15 13:57:06 2010
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2002-2008 the original author or authors.
+ *
+ * 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.apache.hise.dao.vendor;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.PersistenceProviderImpl;
+
+import org.springframework.orm.jpa.JpaDialect;
+import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
+import org.springframework.orm.jpa.vendor.Database;
+import org.springframework.orm.jpa.vendor.OpenJpaDialect;
+
+/**
+ * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for
+ * Apache OpenJPA. Developed and tested against OpenJPA 1.0.0.
+ *
+ * <p>Exposes OpenJPA's persistence provider and EntityManager extension interface,
+ * and supports {@link AbstractJpaVendorAdapter}'s common configuration settings.
+ *
+ * @author Costin Leau
+ * @author Juergen Hoeller
+ * @since 2.0
+ * @see org.apache.openjpa.persistence.PersistenceProviderImpl
+ * @see org.apache.openjpa.persistence.OpenJPAEntityManager
+ */
+public class OpenJpaVendorAdapter extends AbstractJpaVendorAdapter {
+
+        private final PersistenceProvider persistenceProvider = new PersistenceProviderImpl();
+
+        private final OpenJpaDialect jpaDialect = new OpenJpaDialect();
+
+        private Map<String, Object> extProperties = new HashMap<String, Object>();
+
+        public Map<String, Object> getExtProperties() {
+            return extProperties;
+        }
+
+        public void setExtProperties(Map<String, Object> extProperties) {
+            this.extProperties = extProperties;
+        }
+
+        public PersistenceProvider getPersistenceProvider() {
+                return this.persistenceProvider;
+        }
+
+        @Override
+        public String getPersistenceProviderRootPackage() {
+                return "org.apache.openjpa";
+        }
+
+        @Override
+        public Map<String, Object> getJpaPropertyMap() {
+                Map<String, Object> jpaProperties = new HashMap<String, Object>();
+
+                if (getDatabasePlatform() != null) {
+                        jpaProperties.put("openjpa.jdbc.DBDictionary", getDatabasePlatform());
+                }
+                else if (getDatabase() != null) {
+                        String databaseDictonary = determineDatabaseDictionary(getDatabase());
+                        if (databaseDictonary != null) {
+                                jpaProperties.put("openjpa.jdbc.DBDictionary", databaseDictonary);
+                        }
+                }
+
+                if (isGenerateDdl()) {
+                        jpaProperties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
+                }
+                if (isShowSql()) {
+                        // Taken from the OpenJPA 0.9.6 docs ("Standard OpenJPA Log Configuration + All SQL Statements")
+                        jpaProperties.put("openjpa.Log", "DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE");
+                }
+
+                jpaProperties.putAll(extProperties);
+                
+                return jpaProperties;
+        }
+
+        /**
+         * Determine the OpenJPA database dictionary name for the given database.
+         * @param database the specified database
+         * @return the OpenJPA database dictionary name, or <code>null<code> if none found
+         */
+        protected String determineDatabaseDictionary(Database database) {
+                switch (database) {
+                        case DB2: return "db2";
+                        case DERBY: return "derby";
+                        case HSQL: return "hsql(SimulateLocking=true)";
+                        case INFORMIX: return "informix";
+                        case MYSQL: return "mysql";
+                        case ORACLE: return "oracle";
+                        case POSTGRESQL: return "postgres";
+                        case SQL_SERVER: return "sqlserver";
+                        case SYBASE: return "sybase";
+                        default: return null;
+                }
+        }
+
+        @Override
+        public JpaDialect getJpaDialect() {
+                return this.jpaDialect;
+        }
+
+        @Override
+        public Class<? extends EntityManagerFactory> getEntityManagerFactoryInterface() {
+                return OpenJPAEntityManagerFactorySPI.class;
+        }
+
+        @Override
+        public Class<? extends EntityManager> getEntityManagerInterface() {
+                return OpenJPAEntityManagerSPI.class;
+        }
+
+}
\ No newline at end of file

Propchange: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/dao/vendor/OpenJpaVendorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native