You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2008/01/08 13:25:22 UTC
svn commit: r609951 - in
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished: ./
src/main/java/org/apache/cayenne/dba/
src/main/java/org/apache/cayenne/dba/h2/
src/main/resources/org/apache/cayenne/dba/h2/
src/test/java/org/apache/cayenne/unit/ sr...
Author: aadamchik
Date: Tue Jan 8 04:25:20 2008
New Revision: 609951
URL: http://svn.apache.org/viewvc?rev=609951&view=rev
Log:
CAY-884 Add support for H2 Database
Added:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2Adapter.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2MergerFactory.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2Sniffer.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/dba/h2/
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/dba/h2/types.xml
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/H2StackAdapter.java
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/pom.xml
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/pom.xml?rev=609951&r1=609950&r2=609951&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/pom.xml (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/pom.xml Tue Jan 8 04:25:20 2008
@@ -113,12 +113,6 @@
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
-
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>velocity</groupId>
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java?rev=609951&r1=609950&r2=609951&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java Tue Jan 8 04:25:20 2008
@@ -36,6 +36,7 @@
import org.apache.cayenne.dba.db2.DB2Sniffer;
import org.apache.cayenne.dba.derby.DerbySniffer;
import org.apache.cayenne.dba.frontbase.FrontBaseSniffer;
+import org.apache.cayenne.dba.h2.H2Sniffer;
import org.apache.cayenne.dba.hsqldb.HSQLDBSniffer;
import org.apache.cayenne.dba.ingres.IngresSniffer;
import org.apache.cayenne.dba.mysql.MySQLSniffer;
@@ -67,7 +68,8 @@
new MySQLSniffer(), new PostgresSniffer(), new OracleSniffer(),
new SQLServerSniffer(), new HSQLDBSniffer(), new DB2Sniffer(),
new SybaseSniffer(), new DerbySniffer(), new OpenBaseSniffer(),
- new FrontBaseSniffer(), new IngresSniffer(), new SQLiteSniffer()
+ new FrontBaseSniffer(), new IngresSniffer(), new SQLiteSniffer(),
+ new H2Sniffer()
};
/**
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2Adapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2Adapter.java?rev=609951&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2Adapter.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2Adapter.java Tue Jan 8 04:25:20 2008
@@ -0,0 +1,35 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cayenne.dba.h2;
+
+import org.apache.cayenne.dba.JdbcAdapter;
+import org.apache.cayenne.merge.MergerFactory;
+
+/**
+ * @since 3.0
+ */
+public class H2Adapter extends JdbcAdapter {
+
+ @Override
+ public MergerFactory mergerFactory() {
+ return new H2MergerFactory();
+ }
+
+}
\ No newline at end of file
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2MergerFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2MergerFactory.java?rev=609951&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2MergerFactory.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2MergerFactory.java Tue Jan 8 04:25:20 2008
@@ -0,0 +1,50 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cayenne.dba.h2;
+
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.merge.MergerFactory;
+import org.apache.cayenne.merge.MergerToken;
+import org.apache.cayenne.merge.SetColumnTypeToDb;
+
+/**
+ * @since 3.0
+ */
+public class H2MergerFactory extends MergerFactory {
+
+ @Override
+ public MergerToken createSetColumnTypeToDb(
+ final DbEntity entity,
+ DbAttribute columnOriginal,
+ final DbAttribute columnNew) {
+ return new SetColumnTypeToDb(entity, columnOriginal, columnNew) {
+ @Override
+ protected void appendPrefix(StringBuffer sqlBuffer) {
+ sqlBuffer.append("ALTER TABLE ");
+ sqlBuffer.append(entity.getFullyQualifiedName());
+ sqlBuffer.append(" ALTER ");
+ sqlBuffer.append(columnNew.getName());
+ sqlBuffer.append(" ");
+ }
+ };
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2Sniffer.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2Sniffer.java?rev=609951&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2Sniffer.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2Sniffer.java Tue Jan 8 04:25:20 2008
@@ -0,0 +1,39 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cayenne.dba.h2;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.dba.DbAdapterFactory;
+
+/**
+ * @since 3.0
+ */
+public class H2Sniffer implements DbAdapterFactory {
+
+ public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
+ String dbName = md.getDatabaseProductName();
+ return dbName != null && dbName.toUpperCase().indexOf("H2") >= 0
+ ? new H2Adapter()
+ : null;
+ }
+
+}
\ No newline at end of file
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/dba/h2/types.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/dba/h2/types.xml?rev=609951&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/dba/h2/types.xml (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/dba/h2/types.xml Tue Jan 8 04:25:20 2008
@@ -0,0 +1,111 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+
+<!--
+H2 types mapping
+-->
+
+<types>
+ <jdbc-type name="ARRAY">
+ <db-type name="ARRAY"/>
+ </jdbc-type>
+ <jdbc-type name="BIGINT">
+ <db-type name="BIGINT"/>
+ </jdbc-type>
+ <jdbc-type name="BINARY">
+ <db-type name="BINARY"/>
+ </jdbc-type>
+ <jdbc-type name="BIT">
+ <db-type name="BIT"/>
+ </jdbc-type>
+ <jdbc-type name="BLOB">
+ <db-type name="BLOB"/>
+ </jdbc-type>
+ <jdbc-type name="BOOLEAN">
+ <db-type name="BOOLEAN"/>
+ </jdbc-type>
+ <jdbc-type name="CHAR">
+ <db-type name="CHAR"/>
+ </jdbc-type>
+ <jdbc-type name="CLOB">
+ <db-type name="CLOB"/>
+ </jdbc-type>
+ <jdbc-type name="DATALINK">
+ <db-type name="DATALINK"/>
+ </jdbc-type>
+ <jdbc-type name="DATE">
+ <db-type name="DATE"/>
+ </jdbc-type>
+ <jdbc-type name="DECIMAL">
+ <db-type name="DECIMAL"/>
+ </jdbc-type>
+ <jdbc-type name="DOUBLE">
+ <db-type name="DOUBLE"/>
+ </jdbc-type>
+ <jdbc-type name="FLOAT">
+ <db-type name="FLOAT"/>
+ </jdbc-type>
+ <jdbc-type name="INTEGER">
+ <db-type name="INTEGER"/>
+ </jdbc-type>
+ <jdbc-type name="JAVA_OBJECT">
+ <db-type name="JAVA_OBJECT"/>
+ </jdbc-type>
+ <jdbc-type name="LONGVARBINARY">
+ <db-type name="LONGVARBINARY"/>
+ </jdbc-type>
+ <jdbc-type name="LONGVARCHAR">
+ <db-type name="CLOB"/>
+ </jdbc-type>
+ <jdbc-type name="NUMERIC">
+ <db-type name="NUMERIC"/>
+ </jdbc-type>
+ <jdbc-type name="OTHER">
+ <db-type name="OTHER"/>
+ </jdbc-type>
+ <jdbc-type name="REAL">
+ <db-type name="REAL"/>
+ </jdbc-type>
+ <jdbc-type name="REF">
+ <db-type name="REF"/>
+ </jdbc-type>
+ <jdbc-type name="SMALLINT">
+ <db-type name="SMALLINT"/>
+ </jdbc-type>
+ <jdbc-type name="STRUCT">
+ <db-type name="STRUCT"/>
+ </jdbc-type>
+ <jdbc-type name="TIME">
+ <db-type name="TIME"/>
+ </jdbc-type>
+ <jdbc-type name="TIMESTAMP">
+ <db-type name="TIMESTAMP"/>
+ </jdbc-type>
+ <jdbc-type name="TINYINT">
+ <db-type name="TINYINT"/>
+ </jdbc-type>
+ <jdbc-type name="VARBINARY">
+ <db-type name="VARBINARY"/>
+ </jdbc-type>
+ <jdbc-type name="VARCHAR">
+ <db-type name="VARCHAR"/>
+ </jdbc-type>
+</types>
\ No newline at end of file
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/H2StackAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/H2StackAdapter.java?rev=609951&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/H2StackAdapter.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/H2StackAdapter.java Tue Jan 8 04:25:20 2008
@@ -0,0 +1,39 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cayenne.unit;
+
+import org.apache.cayenne.dba.DbAdapter;
+
+
+public class H2StackAdapter extends AccessStackAdapter {
+
+ public H2StackAdapter(DbAdapter adapter) {
+ super(adapter);
+ }
+
+ public boolean supportsLobs() {
+ return true;
+ }
+
+ public boolean supportsStoredProcedures() {
+ return false;
+ }
+
+}
\ No newline at end of file
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml?rev=609951&r1=609950&r2=609951&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml Tue Jan 8 04:25:20 2008
@@ -14,6 +14,7 @@
<bean id="SQLServerAdapter" class="org.apache.cayenne.dba.sqlserver.SQLServerAdapter"/>
<bean id="DB2Adapter" class="org.apache.cayenne.dba.db2.DB2Adapter"/>
<bean id="HSQLDBAdapter" class="org.apache.cayenne.dba.hsqldb.HSQLDBAdapter"/>
+ <bean id="H2Adapter" class="org.apache.cayenne.dba.h2.H2Adapter"/>
<bean id="DerbyAdapter" class="org.apache.cayenne.dba.derby.DerbyAdapter"/>
<bean id="FrontBaseAdapter" class="org.apache.cayenne.dba.frontbase.FrontBaseAdapter"/>
<bean id="IngresAdapter" class="org.apache.cayenne.dba.ingres.IngresAdapter"/>
@@ -49,6 +50,9 @@
<bean id="HSQLDBStackAdapter" class="org.apache.cayenne.unit.HSQLDBStackAdapter">
<constructor-arg><ref bean="HSQLDBAdapter"/></constructor-arg>
</bean>
+ <bean id="H2StackAdapter" class="org.apache.cayenne.unit.H2StackAdapter">
+ <constructor-arg><ref bean="H2Adapter"/></constructor-arg>
+ </bean>
<bean id="DerbyStackAdapter" class="org.apache.cayenne.unit.DerbyStackAdapter">
<constructor-arg><ref bean="DerbyAdapter"/></constructor-arg>
</bean>
@@ -188,6 +192,7 @@
<entry key="org.apache.cayenne.dba.sqlserver.SQLServerAdapter"><ref bean="SQLServerStackAdapter"/></entry>
<entry key="org.apache.cayenne.dba.db2.DB2Adapter"><ref bean="DB2StackAdapter"/></entry>
<entry key="org.apache.cayenne.dba.hsqldb.HSQLDBAdapter"><ref bean="HSQLDBStackAdapter"/></entry>
+ <entry key="org.apache.cayenne.dba.h2.H2Adapter"><ref bean="H2StackAdapter"/></entry>
<entry key="org.apache.cayenne.dba.derby.DerbyAdapter"><ref bean="DerbyStackAdapter"/></entry>
<entry key="org.apache.cayenne.dba.frontbase.FrontBaseAdapter"><ref bean="FrontBaseStackAdapter"/></entry>
<entry key="org.apache.cayenne.dba.ingres.IngresAdapter"><ref bean="IngresStackAdapter"/></entry>