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 2014/11/02 08:09:59 UTC
[11/48] Installing Maven Failsafe Plugin
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactoryIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactoryIT.java b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactoryIT.java
new file mode 100644
index 0000000..ce2c68d
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactoryIT.java
@@ -0,0 +1,102 @@
+/*****************************************************************
+ * 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.configuration.server;
+
+import com.mockrunner.mock.jdbc.MockDataSource;
+import org.apache.cayenne.configuration.DataNodeDescriptor;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.unit.JNDISetup;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class JNDIDataSourceFactoryIT extends ServerCase {
+
+ @Inject
+ private Injector injector;
+
+ public void testGetDataSource_NameBound() throws Exception {
+
+ DataNodeDescriptor descriptor = new DataNodeDescriptor();
+ descriptor.setParameters("jdbc/TestDS");
+
+ JNDISetup.doSetup();
+
+ MockDataSource dataSource = new MockDataSource();
+ InitialContext context = new InitialContext();
+ context.bind(descriptor.getParameters(), dataSource);
+
+ try {
+
+ JNDIDataSourceFactory factory = new JNDIDataSourceFactory();
+ injector.injectMembers(factory);
+ assertSame(dataSource, factory.getDataSource(descriptor));
+ }
+ finally {
+ // since the context is shared, must clear it after the test
+ context.unbind(descriptor.getParameters());
+ }
+ }
+
+ public void testGetDataSource_NameBoundWithPrefix() throws Exception {
+
+ DataNodeDescriptor descriptor = new DataNodeDescriptor();
+ descriptor.setParameters("jdbc/TestDS");
+
+ JNDISetup.doSetup();
+
+ MockDataSource dataSource = new MockDataSource();
+ InitialContext context = new InitialContext();
+ context.bind("java:comp/env/" + descriptor.getParameters(), dataSource);
+
+ try {
+
+ JNDIDataSourceFactory factory = new JNDIDataSourceFactory();
+ injector.injectMembers(factory);
+ assertSame(dataSource, factory.getDataSource(descriptor));
+ }
+ finally {
+ // since the context is shared, must clear it after the test
+ context.unbind("java:comp/env/" + descriptor.getParameters());
+ }
+ }
+
+ public void testGetDataSource_NameNotBound() throws Exception {
+
+ DataNodeDescriptor descriptor = new DataNodeDescriptor();
+ descriptor.setParameters("jdbc/TestDS");
+
+ JNDISetup.doSetup();
+
+ JNDIDataSourceFactory factory = new JNDIDataSourceFactory();
+ injector.injectMembers(factory);
+
+ try {
+ factory.getDataSource(descriptor);
+ fail("Didn't throw on unbound name");
+ }
+ catch (NameNotFoundException e) {
+ // expected
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactoryTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactoryTest.java b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactoryTest.java
deleted file mode 100644
index 48a65ab..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/JNDIDataSourceFactoryTest.java
+++ /dev/null
@@ -1,104 +0,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.
- ****************************************************************/
-package org.apache.cayenne.configuration.server;
-
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-
-import org.apache.cayenne.configuration.DataNodeDescriptor;
-import org.apache.cayenne.configuration.server.JNDIDataSourceFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.unit.JNDISetup;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-import com.mockrunner.mock.jdbc.MockDataSource;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class JNDIDataSourceFactoryTest extends ServerCase {
-
- @Inject
- private Injector injector;
-
- public void testGetDataSource_NameBound() throws Exception {
-
- DataNodeDescriptor descriptor = new DataNodeDescriptor();
- descriptor.setParameters("jdbc/TestDS");
-
- JNDISetup.doSetup();
-
- MockDataSource dataSource = new MockDataSource();
- InitialContext context = new InitialContext();
- context.bind(descriptor.getParameters(), dataSource);
-
- try {
-
- JNDIDataSourceFactory factory = new JNDIDataSourceFactory();
- injector.injectMembers(factory);
- assertSame(dataSource, factory.getDataSource(descriptor));
- }
- finally {
- // since the context is shared, must clear it after the test
- context.unbind(descriptor.getParameters());
- }
- }
-
- public void testGetDataSource_NameBoundWithPrefix() throws Exception {
-
- DataNodeDescriptor descriptor = new DataNodeDescriptor();
- descriptor.setParameters("jdbc/TestDS");
-
- JNDISetup.doSetup();
-
- MockDataSource dataSource = new MockDataSource();
- InitialContext context = new InitialContext();
- context.bind("java:comp/env/" + descriptor.getParameters(), dataSource);
-
- try {
-
- JNDIDataSourceFactory factory = new JNDIDataSourceFactory();
- injector.injectMembers(factory);
- assertSame(dataSource, factory.getDataSource(descriptor));
- }
- finally {
- // since the context is shared, must clear it after the test
- context.unbind("java:comp/env/" + descriptor.getParameters());
- }
- }
-
- public void testGetDataSource_NameNotBound() throws Exception {
-
- DataNodeDescriptor descriptor = new DataNodeDescriptor();
- descriptor.setParameters("jdbc/TestDS");
-
- JNDISetup.doSetup();
-
- JNDIDataSourceFactory factory = new JNDIDataSourceFactory();
- injector.injectMembers(factory);
-
- try {
- factory.getDataSource(descriptor);
- fail("Didn't throw on unbound name");
- }
- catch (NameNotFoundException e) {
- // expected
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder_InAction_IT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder_InAction_IT.java b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder_InAction_IT.java
new file mode 100644
index 0000000..53f64eb
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder_InAction_IT.java
@@ -0,0 +1,90 @@
+/*****************************************************************
+ * 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.configuration.server;
+
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.conn.DataSourceInfo;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.SQLSelect;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import javax.sql.DataSource;
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class ServerRuntimeBuilder_InAction_IT extends ServerCase {
+
+ @Inject
+ private DBHelper dbHelper;
+
+ @Inject
+ private ServerRuntime runtime;
+
+ @Inject
+ private DataSourceInfo dsi;
+
+ private DataSource dataSource;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("PAINTING_INFO");
+ dbHelper.deleteAll("PAINTING");
+ dbHelper.deleteAll("ARTIST_EXHIBIT");
+ dbHelper.deleteAll("ARTIST_GROUP");
+ dbHelper.deleteAll("ARTIST");
+ dbHelper.deleteAll("EXHIBIT");
+ dbHelper.deleteAll("GALLERY");
+
+ TableHelper tArtist = new TableHelper(dbHelper, "ARTIST");
+ tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+ tArtist.insert(33001, "AA1");
+ tArtist.insert(33002, "AA2");
+
+ this.dataSource = runtime.getDataSource("tstmap");
+ }
+
+ public void testConfigFree_WithDataSource() {
+
+ ServerRuntime localRuntime = new ServerRuntimeBuilder().dataSource(dataSource).build();
+
+ try {
+ List<DataRow> result = SQLSelect.dataRowQuery("SELECT * FROM ARTIST").select(localRuntime.newContext());
+ assertEquals(2, result.size());
+ } finally {
+ localRuntime.shutdown();
+ }
+ }
+
+ public void testConfigFree_WithDBParams() {
+
+ ServerRuntime localRuntime = new ServerRuntimeBuilder().jdbcDriver(dsi.getJdbcDriver())
+ .url(dsi.getDataSourceUrl()).password(dsi.getPassword()).user(dsi.getUserName()).minConnections(1)
+ .maxConnections(2).build();
+
+ try {
+ List<DataRow> result = SQLSelect.dataRowQuery("SELECT * FROM ARTIST").select(localRuntime.newContext());
+ assertEquals(2, result.size());
+ } finally {
+ localRuntime.shutdown();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder_InAction_Test.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder_InAction_Test.java b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder_InAction_Test.java
deleted file mode 100644
index fcaad88..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder_InAction_Test.java
+++ /dev/null
@@ -1,91 +0,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.
- ****************************************************************/
-package org.apache.cayenne.configuration.server;
-
-import java.util.List;
-
-import javax.sql.DataSource;
-
-import org.apache.cayenne.DataRow;
-import org.apache.cayenne.conn.DataSourceInfo;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.SQLSelect;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class ServerRuntimeBuilder_InAction_Test extends ServerCase {
-
- @Inject
- private DBHelper dbHelper;
-
- @Inject
- private ServerRuntime runtime;
-
- @Inject
- private DataSourceInfo dsi;
-
- private DataSource dataSource;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- dbHelper.deleteAll("PAINTING_INFO");
- dbHelper.deleteAll("PAINTING");
- dbHelper.deleteAll("ARTIST_EXHIBIT");
- dbHelper.deleteAll("ARTIST_GROUP");
- dbHelper.deleteAll("ARTIST");
- dbHelper.deleteAll("EXHIBIT");
- dbHelper.deleteAll("GALLERY");
-
- TableHelper tArtist = new TableHelper(dbHelper, "ARTIST");
- tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
- tArtist.insert(33001, "AA1");
- tArtist.insert(33002, "AA2");
-
- this.dataSource = runtime.getDataSource("tstmap");
- }
-
- public void testConfigFree_WithDataSource() {
-
- ServerRuntime localRuntime = new ServerRuntimeBuilder().dataSource(dataSource).build();
-
- try {
- List<DataRow> result = SQLSelect.dataRowQuery("SELECT * FROM ARTIST").select(localRuntime.newContext());
- assertEquals(2, result.size());
- } finally {
- localRuntime.shutdown();
- }
- }
-
- public void testConfigFree_WithDBParams() {
-
- ServerRuntime localRuntime = new ServerRuntimeBuilder().jdbcDriver(dsi.getJdbcDriver())
- .url(dsi.getDataSourceUrl()).password(dsi.getPassword()).user(dsi.getUserName()).minConnections(1)
- .maxConnections(2).build();
-
- try {
- List<DataRow> result = SQLSelect.dataRowQuery("SELECT * FROM ARTIST").select(localRuntime.newContext());
- assertEquals(2, result.size());
- } finally {
- localRuntime.shutdown();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/conn/PoolManagerIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/conn/PoolManagerIT.java b/cayenne-server/src/test/java/org/apache/cayenne/conn/PoolManagerIT.java
new file mode 100644
index 0000000..23c031f
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/conn/PoolManagerIT.java
@@ -0,0 +1,118 @@
+/*****************************************************************
+ * 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.conn;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Connection;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class PoolManagerIT extends ServerCase {
+
+ @Inject
+ private DataSourceInfo dataSourceInfo;
+
+ public void testDataSourceUrl() throws Exception {
+ String driverName = dataSourceInfo.getJdbcDriver();
+ String url = dataSourceInfo.getDataSourceUrl();
+
+ PoolManager pm = new PoolManager(driverName, url, 0, 3, "", "") {
+
+ @Override
+ protected void startMaintenanceThread() {
+ }
+ };
+ assertEquals(url, pm.getDataSourceUrl());
+ assertEquals(driverName, pm.getJdbcDriver());
+ }
+
+ public void testPassword() throws Exception {
+ PoolManager pm = new PoolManager(null, 0, 3, "", "b") {
+
+ @Override
+ protected void startMaintenanceThread() {
+ }
+ };
+ assertEquals("b", pm.getPassword());
+ }
+
+ public void testUserName() throws Exception {
+ PoolManager pm = new PoolManager(null, 0, 3, "a", "") {
+
+ @Override
+ protected void startMaintenanceThread() {
+ }
+ };
+ assertEquals("a", pm.getUserName());
+ }
+
+ public void testMinConnections() throws Exception {
+ PoolManager pm = new PoolManager(null, 0, 3, "", "") {
+
+ @Override
+ protected void startMaintenanceThread() {
+ }
+ };
+ assertEquals(0, pm.getMinConnections());
+ }
+
+ public void testMaxConnections() throws Exception {
+ PoolManager pm = new PoolManager(null, 0, 3, "", "") {
+
+ @Override
+ protected void startMaintenanceThread() {
+ }
+ };
+ assertEquals(3, pm.getMaxConnections());
+ }
+
+ public void testPooling() throws Exception {
+
+ PoolManager pm = new PoolManager(dataSourceInfo.getJdbcDriver(), dataSourceInfo
+ .getDataSourceUrl(), 2, 3, dataSourceInfo.getUserName(), dataSourceInfo
+ .getPassword());
+
+ try {
+ assertEquals(0, pm.getCurrentlyInUse());
+ assertEquals(2, pm.getCurrentlyUnused());
+
+ Connection c1 = pm.getConnection();
+ assertEquals(1, pm.getCurrentlyInUse());
+ assertEquals(1, pm.getCurrentlyUnused());
+
+ Connection c2 = pm.getConnection();
+ assertEquals(2, pm.getCurrentlyInUse());
+ assertEquals(0, pm.getCurrentlyUnused());
+
+ c1.close();
+ assertEquals(1, pm.getCurrentlyInUse());
+ assertEquals(1, pm.getCurrentlyUnused());
+
+ c2.close();
+ assertEquals(0, pm.getCurrentlyInUse());
+ assertEquals(2, pm.getCurrentlyUnused());
+ }
+ finally {
+ pm.shutdown();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/conn/PoolManagerTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/conn/PoolManagerTest.java b/cayenne-server/src/test/java/org/apache/cayenne/conn/PoolManagerTest.java
deleted file mode 100644
index 75a7ac7..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/conn/PoolManagerTest.java
+++ /dev/null
@@ -1,118 +0,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.
- ****************************************************************/
-
-package org.apache.cayenne.conn;
-
-import java.sql.Connection;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class PoolManagerTest extends ServerCase {
-
- @Inject
- private DataSourceInfo dataSourceInfo;
-
- public void testDataSourceUrl() throws Exception {
- String driverName = dataSourceInfo.getJdbcDriver();
- String url = dataSourceInfo.getDataSourceUrl();
-
- PoolManager pm = new PoolManager(driverName, url, 0, 3, "", "") {
-
- @Override
- protected void startMaintenanceThread() {
- }
- };
- assertEquals(url, pm.getDataSourceUrl());
- assertEquals(driverName, pm.getJdbcDriver());
- }
-
- public void testPassword() throws Exception {
- PoolManager pm = new PoolManager(null, 0, 3, "", "b") {
-
- @Override
- protected void startMaintenanceThread() {
- }
- };
- assertEquals("b", pm.getPassword());
- }
-
- public void testUserName() throws Exception {
- PoolManager pm = new PoolManager(null, 0, 3, "a", "") {
-
- @Override
- protected void startMaintenanceThread() {
- }
- };
- assertEquals("a", pm.getUserName());
- }
-
- public void testMinConnections() throws Exception {
- PoolManager pm = new PoolManager(null, 0, 3, "", "") {
-
- @Override
- protected void startMaintenanceThread() {
- }
- };
- assertEquals(0, pm.getMinConnections());
- }
-
- public void testMaxConnections() throws Exception {
- PoolManager pm = new PoolManager(null, 0, 3, "", "") {
-
- @Override
- protected void startMaintenanceThread() {
- }
- };
- assertEquals(3, pm.getMaxConnections());
- }
-
- public void testPooling() throws Exception {
-
- PoolManager pm = new PoolManager(dataSourceInfo.getJdbcDriver(), dataSourceInfo
- .getDataSourceUrl(), 2, 3, dataSourceInfo.getUserName(), dataSourceInfo
- .getPassword());
-
- try {
- assertEquals(0, pm.getCurrentlyInUse());
- assertEquals(2, pm.getCurrentlyUnused());
-
- Connection c1 = pm.getConnection();
- assertEquals(1, pm.getCurrentlyInUse());
- assertEquals(1, pm.getCurrentlyUnused());
-
- Connection c2 = pm.getConnection();
- assertEquals(2, pm.getCurrentlyInUse());
- assertEquals(0, pm.getCurrentlyUnused());
-
- c1.close();
- assertEquals(1, pm.getCurrentlyInUse());
- assertEquals(1, pm.getCurrentlyUnused());
-
- c2.close();
- assertEquals(0, pm.getCurrentlyInUse());
- assertEquals(2, pm.getCurrentlyUnused());
- }
- finally {
- pm.shutdown();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/AutoAdapterIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/AutoAdapterIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/AutoAdapterIT.java
new file mode 100644
index 0000000..f0918cb
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/AutoAdapterIT.java
@@ -0,0 +1,67 @@
+/*****************************************************************
+ * 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;
+
+import org.apache.cayenne.access.DataNode;
+import org.apache.cayenne.access.jdbc.SQLTemplateAction;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.log.NoopJdbcEventLogger;
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class AutoAdapterIT extends ServerCase {
+
+ @Inject
+ private DataNode dataNode;
+
+ public void testGetAdapter_Proxy() throws Exception {
+ Provider<DbAdapter> adapterProvider = mock(Provider.class);
+ when(adapterProvider.get()).thenReturn(dataNode.getAdapter());
+
+ AutoAdapter adapter = new AutoAdapter(adapterProvider, NoopJdbcEventLogger.getInstance());
+ DbAdapter detected = adapter.getAdapter();
+ assertSame(dataNode.getAdapter(), detected);
+ }
+
+ public void testCreateSQLTemplateAction() {
+
+ Provider<DbAdapter> adapterProvider = mock(Provider.class);
+ when(adapterProvider.get()).thenReturn(dataNode.getAdapter());
+
+ AutoAdapter autoAdapter = new AutoAdapter(adapterProvider, NoopJdbcEventLogger.getInstance());
+
+ SQLTemplateAction action = (SQLTemplateAction) autoAdapter.getAction(new SQLTemplate(Artist.class,
+ "select * from artist"), dataNode);
+
+ // it is important for SQLTemplateAction to be used with unwrapped
+ // adapter, as the
+ // adapter class name is used as a key to the correct SQL template.
+ assertNotNull(action.getAdapter());
+ assertFalse(action.getAdapter() instanceof AutoAdapter);
+ assertSame(dataNode.getAdapter(), action.getAdapter());
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java
deleted file mode 100644
index 269efea..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java
+++ /dev/null
@@ -1,67 +0,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.
- ****************************************************************/
-
-package org.apache.cayenne.dba;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.access.jdbc.SQLTemplateAction;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.di.Provider;
-import org.apache.cayenne.log.NoopJdbcEventLogger;
-import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class AutoAdapterTest extends ServerCase {
-
- @Inject
- private DataNode dataNode;
-
- public void testGetAdapter_Proxy() throws Exception {
- Provider<DbAdapter> adapterProvider = mock(Provider.class);
- when(adapterProvider.get()).thenReturn(dataNode.getAdapter());
-
- AutoAdapter adapter = new AutoAdapter(adapterProvider, NoopJdbcEventLogger.getInstance());
- DbAdapter detected = adapter.getAdapter();
- assertSame(dataNode.getAdapter(), detected);
- }
-
- public void testCreateSQLTemplateAction() {
-
- Provider<DbAdapter> adapterProvider = mock(Provider.class);
- when(adapterProvider.get()).thenReturn(dataNode.getAdapter());
-
- AutoAdapter autoAdapter = new AutoAdapter(adapterProvider, NoopJdbcEventLogger.getInstance());
-
- SQLTemplateAction action = (SQLTemplateAction) autoAdapter.getAction(new SQLTemplate(Artist.class,
- "select * from artist"), dataNode);
-
- // it is important for SQLTemplateAction to be used with unwrapped
- // adapter, as the
- // adapter class name is used as a key to the correct SQL template.
- assertNotNull(action.getAdapter());
- assertFalse(action.getAdapter() instanceof AutoAdapter);
- assertSame(dataNode.getAdapter(), action.getAdapter());
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/ConcurrentPkGeneratorIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/ConcurrentPkGeneratorIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/ConcurrentPkGeneratorIT.java
new file mode 100644
index 0000000..eae7470
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/ConcurrentPkGeneratorIT.java
@@ -0,0 +1,115 @@
+/*****************************************************************
+ * 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;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.testdo.qualified.Qualified1;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+@UseServerRuntime("cayenne-default.xml")
+public class ConcurrentPkGeneratorIT extends ServerCase {
+
+ @Inject
+ private ServerRuntime runtime;
+
+ /*
+ * Attempts to discover any problems regarding thread locking in the PkGenerator
+ */
+ public void testConcurrentInserts() throws Exception {
+ final DataMap dataMap = runtime.getDataDomain().getDataMap("qualified");
+
+ // clear out the table
+ ObjectContext context = runtime.newContext();
+ List<Qualified1> qualified1s = context.select(SelectQuery.query(Qualified1.class, null));
+ context.deleteObjects(qualified1s);
+ context.commitChanges();
+
+ // perform concurrent inserts
+ int numThreads = 2;
+ ExecutorService executor = Executors.newFixedThreadPool(numThreads);
+ Runnable task = new Runnable() {
+ public void run() {
+ try {
+ ObjectContext context = runtime.newContext();
+ for (ObjEntity entity : dataMap.getObjEntities()) {
+ context.newObject(entity.getJavaClass());
+ }
+ context.commitChanges();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ };
+
+ for (int j = 0; j < 100; j++) {
+ for (int i = 0; i < numThreads; i++) {
+ executor.submit(task);
+ }
+ }
+
+ // check for completion or deadlock
+ executor.shutdown();
+ try {
+ // normally this completes in less than 2 seconds. If it takes 30 then it failed.
+ boolean didFinish = executor.awaitTermination(30, TimeUnit.SECONDS);
+ if (!didFinish) {
+ fail("Concurrent inserts either deadlocked or contended over the lock too long.");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+
+ // check for gaps in the generated sequence numbers
+ qualified1s = context.select(SelectQuery.query(Qualified1.class, null));
+ assertEquals(100 * numThreads, qualified1s.size());
+
+ Collections.sort(qualified1s, new Comparator<Qualified1>() {
+ public int compare(Qualified1 left, Qualified1 right) {
+ Integer leftPk = Cayenne.intPKForObject(left);
+ Integer rightPk = Cayenne.intPKForObject(right);
+ return leftPk.compareTo(rightPk);
+ }
+ });
+
+ // PKs will be used in order most of the time, but the implementation doesn't guarantee it.
+// int lastPk = Cayenne.intPKForObject(qualified1s.get(0)) - 1;
+// for (Qualified1 qualified1 : qualified1s) {
+// if (lastPk+1 != Cayenne.intPKForObject(qualified1)) {
+// fail("Found gap in sequence number: " + lastPk + " - " + Cayenne.intPKForObject(qualified1));
+// }
+// lastPk++;
+// }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/ConcurrentPkGeneratorTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/ConcurrentPkGeneratorTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/ConcurrentPkGeneratorTest.java
deleted file mode 100644
index f1e4d32..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/ConcurrentPkGeneratorTest.java
+++ /dev/null
@@ -1,115 +0,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.
- ****************************************************************/
-
-package org.apache.cayenne.dba;
-
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.cayenne.Cayenne;
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.testdo.qualified.Qualified1;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime("cayenne-default.xml")
-public class ConcurrentPkGeneratorTest extends ServerCase {
-
- @Inject
- private ServerRuntime runtime;
-
- /*
- * Attempts to discover any problems regarding thread locking in the PkGenerator
- */
- public void testConcurrentInserts() throws Exception {
- final DataMap dataMap = runtime.getDataDomain().getDataMap("qualified");
-
- // clear out the table
- ObjectContext context = runtime.newContext();
- List<Qualified1> qualified1s = context.select(SelectQuery.query(Qualified1.class, null));
- context.deleteObjects(qualified1s);
- context.commitChanges();
-
- // perform concurrent inserts
- int numThreads = 2;
- ExecutorService executor = Executors.newFixedThreadPool(numThreads);
- Runnable task = new Runnable() {
- public void run() {
- try {
- ObjectContext context = runtime.newContext();
- for (ObjEntity entity : dataMap.getObjEntities()) {
- context.newObject(entity.getJavaClass());
- }
- context.commitChanges();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- };
-
- for (int j = 0; j < 100; j++) {
- for (int i = 0; i < numThreads; i++) {
- executor.submit(task);
- }
- }
-
- // check for completion or deadlock
- executor.shutdown();
- try {
- // normally this completes in less than 2 seconds. If it takes 30 then it failed.
- boolean didFinish = executor.awaitTermination(30, TimeUnit.SECONDS);
- if (!didFinish) {
- fail("Concurrent inserts either deadlocked or contended over the lock too long.");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
-
- // check for gaps in the generated sequence numbers
- qualified1s = context.select(SelectQuery.query(Qualified1.class, null));
- assertEquals(100 * numThreads, qualified1s.size());
-
- Collections.sort(qualified1s, new Comparator<Qualified1>() {
- public int compare(Qualified1 left, Qualified1 right) {
- Integer leftPk = Cayenne.intPKForObject(left);
- Integer rightPk = Cayenne.intPKForObject(right);
- return leftPk.compareTo(rightPk);
- }
- });
-
- // PKs will be used in order most of the time, but the implementation doesn't guarantee it.
-// int lastPk = Cayenne.intPKForObject(qualified1s.get(0)) - 1;
-// for (Qualified1 qualified1 : qualified1s) {
-// if (lastPk+1 != Cayenne.intPKForObject(qualified1)) {
-// fail("Found gap in sequence number: " + lastPk + " - " + Cayenne.intPKForObject(qualified1));
-// }
-// lastPk++;
-// }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcAdapterIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcAdapterIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcAdapterIT.java
new file mode 100644
index 0000000..eba8631
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcAdapterIT.java
@@ -0,0 +1,85 @@
+/*****************************************************************
+ * 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;
+
+import org.apache.cayenne.dba.mysql.MySQLAdapter;
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbKeyGenerator;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class JdbcAdapterIT extends ServerCase {
+
+ @Inject
+ private DbAdapter dbAdapter;
+
+ @Inject
+ private AdhocObjectFactory objectFactory;
+
+ public void testExternalTypesForJdbcType() throws Exception {
+ // check a few types
+ checkType(Types.BLOB);
+ checkType(Types.ARRAY);
+ checkType(Types.DATE);
+ checkType(Types.VARCHAR);
+ }
+
+ private void checkType(int type) throws java.lang.Exception {
+ JdbcAdapter adapter = objectFactory.newInstance(
+ JdbcAdapter.class,
+ JdbcAdapter.class.getName());
+
+ String[] types = adapter.externalTypesForJdbcType(type);
+ assertNotNull(types);
+ assertEquals(1, types.length);
+ assertEquals(TypesMapping.getSqlNameByType(type), types[0]);
+ }
+
+ public void testCreateTableQuoteSqlIdentifiers() {
+
+ if (dbAdapter instanceof MySQLAdapter) {
+
+ DbEntity entity = new DbEntity();
+ DbAttribute attr = new DbAttribute();
+ attr.setName("name column");
+ attr.setType(1);
+ entity.addAttribute(attr);
+
+ DbKeyGenerator id = new DbKeyGenerator();
+ entity.setPrimaryKeyGenerator(id);
+
+ DataMap dm = new DataMap();
+ dm.setQuotingSQLIdentifiers(true);
+ entity.setDataMap(dm);
+ entity.setName("name table");
+
+ MySQLAdapter adaptMySQL = (MySQLAdapter) dbAdapter;
+ String str = "CREATE TABLE `name table` (`name column` CHAR NULL) ENGINE=InnoDB";
+ assertEquals(str, adaptMySQL.createTable(entity));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcAdapterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcAdapterTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcAdapterTest.java
deleted file mode 100644
index 01e42d9..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcAdapterTest.java
+++ /dev/null
@@ -1,85 +0,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.
- ****************************************************************/
-
-package org.apache.cayenne.dba;
-
-import java.sql.Types;
-
-import org.apache.cayenne.dba.mysql.MySQLAdapter;
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbKeyGenerator;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class JdbcAdapterTest extends ServerCase {
-
- @Inject
- private DbAdapter dbAdapter;
-
- @Inject
- private AdhocObjectFactory objectFactory;
-
- public void testExternalTypesForJdbcType() throws Exception {
- // check a few types
- checkType(Types.BLOB);
- checkType(Types.ARRAY);
- checkType(Types.DATE);
- checkType(Types.VARCHAR);
- }
-
- private void checkType(int type) throws java.lang.Exception {
- JdbcAdapter adapter = objectFactory.newInstance(
- JdbcAdapter.class,
- JdbcAdapter.class.getName());
-
- String[] types = adapter.externalTypesForJdbcType(type);
- assertNotNull(types);
- assertEquals(1, types.length);
- assertEquals(TypesMapping.getSqlNameByType(type), types[0]);
- }
-
- public void testCreateTableQuoteSqlIdentifiers() {
-
- if (dbAdapter instanceof MySQLAdapter) {
-
- DbEntity entity = new DbEntity();
- DbAttribute attr = new DbAttribute();
- attr.setName("name column");
- attr.setType(1);
- entity.addAttribute(attr);
-
- DbKeyGenerator id = new DbKeyGenerator();
- entity.setPrimaryKeyGenerator(id);
-
- DataMap dm = new DataMap();
- dm.setQuotingSQLIdentifiers(true);
- entity.setDataMap(dm);
- entity.setName("name table");
-
- MySQLAdapter adaptMySQL = (MySQLAdapter) dbAdapter;
- String str = "CREATE TABLE `name table` (`name column` CHAR NULL) ENGINE=InnoDB";
- assertEquals(str, adaptMySQL.createTable(entity));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorIT.java
new file mode 100644
index 0000000..8113a15
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorIT.java
@@ -0,0 +1,88 @@
+/*****************************************************************
+ * 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;
+
+import org.apache.cayenne.access.DataNode;
+import org.apache.cayenne.dba.derby.DerbyPkGenerator;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.SchemaBuilder;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.Collections;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class JdbcPkGeneratorIT extends ServerCase {
+
+ @Inject
+ private DbAdapter adapter;
+
+ @Inject
+ private DataNode node;
+
+ @Inject
+ private SchemaBuilder schemaBuilder;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ schemaBuilder.dropPKSupport();
+ }
+
+ @Override
+ protected void tearDownBeforeInjection() throws Exception {
+
+ if (JdbcPkGenerator.class.isAssignableFrom(adapter.getPkGenerator().getClass())) {
+ // reset PK gen properly before updating PKs in DB
+ JdbcPkGenerator pkGenerator = (JdbcPkGenerator) adapter.getPkGenerator();
+
+ pkGenerator.setPkStartValue(JdbcPkGenerator.DEFAULT_PK_START_VALUE);
+
+ schemaBuilder.dropPKSupport();
+ schemaBuilder.createPKSupport();
+ }
+ }
+
+ public void testLongPk() throws Exception {
+
+ if (!JdbcPkGenerator.class.isAssignableFrom(adapter.getPkGenerator().getClass())) {
+ return;
+ }
+
+ DbEntity artistEntity = node.getEntityResolver().getObjEntity(Artist.class).getDbEntity();
+
+ DbAttribute pkAttribute = artistEntity.getAttribute(Artist.ARTIST_ID_PK_COLUMN);
+
+ JdbcPkGenerator pkGenerator = (JdbcPkGenerator) adapter.getPkGenerator();
+
+ pkGenerator.setPkStartValue(Integer.MAX_VALUE * 2l);
+ if (!JdbcPkGenerator.class.equals(adapter.getPkGenerator().getClass()) &&
+ !DerbyPkGenerator.class.equals(adapter.getPkGenerator().getClass())) { // AUTO_PK_SUPPORT doesn't allow dropping PK support for a single entity
+ pkGenerator.dropAutoPk(node, Collections.singletonList(artistEntity));
+ }
+ pkGenerator.createAutoPk(node, Collections.singletonList(artistEntity));
+ pkGenerator.reset();
+
+ Object pk = pkGenerator.generatePk(node, pkAttribute);
+ assertTrue(pk instanceof Long);
+ assertTrue("PK is too small: " + pk, ((Long) pk).longValue() > Integer.MAX_VALUE);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java
deleted file mode 100644
index 9e567c1..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java
+++ /dev/null
@@ -1,88 +0,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.
- ****************************************************************/
-package org.apache.cayenne.dba;
-
-import java.util.Collections;
-
-import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.dba.derby.DerbyPkGenerator;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.SchemaBuilder;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class JdbcPkGeneratorTest extends ServerCase {
-
- @Inject
- private DbAdapter adapter;
-
- @Inject
- private DataNode node;
-
- @Inject
- private SchemaBuilder schemaBuilder;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- schemaBuilder.dropPKSupport();
- }
-
- @Override
- protected void tearDownBeforeInjection() throws Exception {
-
- if (JdbcPkGenerator.class.isAssignableFrom(adapter.getPkGenerator().getClass())) {
- // reset PK gen properly before updating PKs in DB
- JdbcPkGenerator pkGenerator = (JdbcPkGenerator) adapter.getPkGenerator();
-
- pkGenerator.setPkStartValue(JdbcPkGenerator.DEFAULT_PK_START_VALUE);
-
- schemaBuilder.dropPKSupport();
- schemaBuilder.createPKSupport();
- }
- }
-
- public void testLongPk() throws Exception {
-
- if (!JdbcPkGenerator.class.isAssignableFrom(adapter.getPkGenerator().getClass())) {
- return;
- }
-
- DbEntity artistEntity = node.getEntityResolver().getObjEntity(Artist.class).getDbEntity();
-
- DbAttribute pkAttribute = artistEntity.getAttribute(Artist.ARTIST_ID_PK_COLUMN);
-
- JdbcPkGenerator pkGenerator = (JdbcPkGenerator) adapter.getPkGenerator();
-
- pkGenerator.setPkStartValue(Integer.MAX_VALUE * 2l);
- if (!JdbcPkGenerator.class.equals(adapter.getPkGenerator().getClass()) &&
- !DerbyPkGenerator.class.equals(adapter.getPkGenerator().getClass())) { // AUTO_PK_SUPPORT doesn't allow dropping PK support for a single entity
- pkGenerator.dropAutoPk(node, Collections.singletonList(artistEntity));
- }
- pkGenerator.createAutoPk(node, Collections.singletonList(artistEntity));
- pkGenerator.reset();
-
- Object pk = pkGenerator.generatePk(node, pkAttribute);
- assertTrue(pk instanceof Long);
- assertTrue("PK is too small: " + pk, ((Long) pk).longValue() > Integer.MAX_VALUE);
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/PkGeneratorIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/PkGeneratorIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/PkGeneratorIT.java
new file mode 100644
index 0000000..81c92f8
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/PkGeneratorIT.java
@@ -0,0 +1,84 @@
+/*****************************************************************
+ * 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;
+
+import org.apache.cayenne.access.DataNode;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.unit.UnitDbAdapter;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class PkGeneratorIT extends ServerCase {
+
+ @Inject
+ private UnitDbAdapter accessStackAdapter;
+
+ @Inject
+ private DataNode node;
+
+ private PkGenerator pkGenerator;
+ private DbEntity paintingEntity;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+
+ pkGenerator = node.getAdapter().getPkGenerator();
+ paintingEntity = node.getEntityResolver().getDbEntity("PAINTING");
+
+ List<DbEntity> list = new ArrayList<DbEntity>();
+ list.add(paintingEntity);
+ pkGenerator.createAutoPk(node, list);
+ pkGenerator.reset();
+ }
+
+ public void testGeneratePkForDbEntity() throws Exception {
+ List<Object> pkList = new ArrayList<Object>();
+
+ int testSize = (pkGenerator instanceof JdbcPkGenerator)
+ ? ((JdbcPkGenerator) pkGenerator).getPkCacheSize() * 2
+ : 25;
+ if (testSize < 25) {
+ testSize = 25;
+ }
+
+ for (int i = 0; i < testSize; i++) {
+ Object pk = pkGenerator.generatePk(node, paintingEntity
+ .getPrimaryKeys()
+ .iterator()
+ .next());
+ assertNotNull(pk);
+ assertTrue(pk instanceof Number);
+
+ // check that the number is continuous
+ // of course this assumes a single-threaded test
+ if (accessStackAdapter.supportsBatchPK() && pkList.size() > 0) {
+ Number last = (Number) pkList.get(pkList.size() - 1);
+ assertEquals(last.intValue() + 1, ((Number) pk).intValue());
+ }
+
+ pkList.add(pk);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/PkGeneratorTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/PkGeneratorTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/PkGeneratorTest.java
deleted file mode 100644
index 6f8bfb4..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/PkGeneratorTest.java
+++ /dev/null
@@ -1,84 +0,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.
- ****************************************************************/
-
-package org.apache.cayenne.dba;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.unit.UnitDbAdapter;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class PkGeneratorTest extends ServerCase {
-
- @Inject
- private UnitDbAdapter accessStackAdapter;
-
- @Inject
- private DataNode node;
-
- private PkGenerator pkGenerator;
- private DbEntity paintingEntity;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
-
- pkGenerator = node.getAdapter().getPkGenerator();
- paintingEntity = node.getEntityResolver().getDbEntity("PAINTING");
-
- List<DbEntity> list = new ArrayList<DbEntity>();
- list.add(paintingEntity);
- pkGenerator.createAutoPk(node, list);
- pkGenerator.reset();
- }
-
- public void testGeneratePkForDbEntity() throws Exception {
- List<Object> pkList = new ArrayList<Object>();
-
- int testSize = (pkGenerator instanceof JdbcPkGenerator)
- ? ((JdbcPkGenerator) pkGenerator).getPkCacheSize() * 2
- : 25;
- if (testSize < 25) {
- testSize = 25;
- }
-
- for (int i = 0; i < testSize; i++) {
- Object pk = pkGenerator.generatePk(node, paintingEntity
- .getPrimaryKeys()
- .iterator()
- .next());
- assertNotNull(pk);
- assertTrue(pk instanceof Number);
-
- // check that the number is continuous
- // of course this assumes a single-threaded test
- if (accessStackAdapter.supportsBatchPK() && pkList.size() > 0) {
- Number last = (Number) pkList.get(pkList.size() - 1);
- assertEquals(last.intValue() + 1, ((Number) pk).intValue());
- }
-
- pkList.add(pk);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/TypesMappingIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/TypesMappingIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/TypesMappingIT.java
new file mode 100644
index 0000000..e10d0f1
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/TypesMappingIT.java
@@ -0,0 +1,138 @@
+/*****************************************************************
+ * 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;
+
+import org.apache.cayenne.MockSerializable;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.ServerCaseDataSourceFactory;
+
+import java.math.BigInteger;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.Types;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+public class TypesMappingIT extends ServerCase {
+
+ @Inject
+ private ServerCaseDataSourceFactory dataSourceFactory;
+
+ public void testGetSqlTypeByJava() throws Exception {
+ assertEquals(Types.VARCHAR, TypesMapping.getSqlTypeByJava(String.class));
+
+ // make sure we can handle arrays...
+ assertEquals(Types.BINARY, TypesMapping.getSqlTypeByJava(byte[].class));
+
+ assertEquals(Types.TIMESTAMP, TypesMapping.getSqlTypeByJava(Calendar.class));
+ assertEquals(
+ Types.TIMESTAMP,
+ TypesMapping.getSqlTypeByJava(GregorianCalendar.class));
+ assertEquals(Types.BIGINT, TypesMapping.getSqlTypeByJava(BigInteger.class));
+
+ assertEquals(
+ Types.VARBINARY,
+ TypesMapping.getSqlTypeByJava(MockSerializable.class));
+ assertEquals(Types.VARCHAR, TypesMapping.getSqlTypeByJava(char[].class));
+ assertEquals(Types.VARCHAR, TypesMapping.getSqlTypeByJava(Character[].class));
+ assertEquals(Types.VARBINARY, TypesMapping.getSqlTypeByJava(Byte[].class));
+ }
+
+ public void testGetSqlTypeByJavaString() throws Exception {
+ assertEquals(Types.VARCHAR, TypesMapping.getSqlTypeByJava(String.class.getName()));
+
+ // make sure we can handle arrays...
+ assertEquals(Types.BINARY, TypesMapping.getSqlTypeByJava("byte[]"));
+
+ assertEquals(
+ Types.TIMESTAMP,
+ TypesMapping.getSqlTypeByJava(Calendar.class.getName()));
+ assertEquals(
+ Types.TIMESTAMP,
+ TypesMapping.getSqlTypeByJava(GregorianCalendar.class.getName()));
+ assertEquals(
+ Types.BIGINT,
+ TypesMapping.getSqlTypeByJava(BigInteger.class.getName()));
+
+ assertEquals(
+ Types.VARBINARY,
+ TypesMapping.getSqlTypeByJava(MockSerializable.class.getName()));
+
+ assertEquals(Types.VARCHAR, TypesMapping.getSqlTypeByJava("char[]"));
+ assertEquals(
+ Types.VARCHAR,
+ TypesMapping.getSqlTypeByJava("java.lang.Character[]"));
+ assertEquals(Types.VARBINARY, TypesMapping.getSqlTypeByJava("java.lang.Byte[]"));
+ }
+
+ public void testGetSqlTypeByJavaPrimitive() throws Exception {
+ assertEquals(Types.INTEGER, TypesMapping.getSqlTypeByJava(Integer.TYPE));
+ assertEquals(Types.BIGINT, TypesMapping.getSqlTypeByJava(Long.TYPE));
+ }
+
+ public void testTypeInfoCompleteness() throws Exception {
+ // check counts
+ // since more then 1 database type can map to a single JDBC type
+ Connection conn = dataSourceFactory.getSharedDataSource().getConnection();
+ int len = 0;
+ try {
+ DatabaseMetaData md = conn.getMetaData();
+ ResultSet rs = md.getTypeInfo();
+ try {
+ while (rs.next()) {
+ len++;
+ }
+ }
+ finally {
+ rs.close();
+ }
+ }
+ finally {
+ conn.close();
+ }
+
+ int actualLen = 0;
+ TypesMapping map = createTypesMapping();
+
+ for (List<TypesMapping.TypeInfo> entry : map.databaseTypes.values()) {
+ actualLen += entry.size();
+ }
+
+ // this is bad assertion, since due to some hacks
+ // the same database types may map more then once,
+ // so we have to use <=
+ assertTrue(len <= actualLen);
+ }
+
+ TypesMapping createTypesMapping() throws Exception {
+ Connection conn = dataSourceFactory.getSharedDataSource().getConnection();
+
+ try {
+ DatabaseMetaData md = conn.getMetaData();
+ return new TypesMapping(md);
+ }
+ finally {
+ conn.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/TypesMappingTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/TypesMappingTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/TypesMappingTest.java
deleted file mode 100644
index a3e989f..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/TypesMappingTest.java
+++ /dev/null
@@ -1,138 +0,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.
- ****************************************************************/
-
-package org.apache.cayenne.dba;
-
-import java.math.BigInteger;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.Types;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-import org.apache.cayenne.MockSerializable;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.ServerCaseDataSourceFactory;
-
-public class TypesMappingTest extends ServerCase {
-
- @Inject
- private ServerCaseDataSourceFactory dataSourceFactory;
-
- public void testGetSqlTypeByJava() throws Exception {
- assertEquals(Types.VARCHAR, TypesMapping.getSqlTypeByJava(String.class));
-
- // make sure we can handle arrays...
- assertEquals(Types.BINARY, TypesMapping.getSqlTypeByJava(byte[].class));
-
- assertEquals(Types.TIMESTAMP, TypesMapping.getSqlTypeByJava(Calendar.class));
- assertEquals(
- Types.TIMESTAMP,
- TypesMapping.getSqlTypeByJava(GregorianCalendar.class));
- assertEquals(Types.BIGINT, TypesMapping.getSqlTypeByJava(BigInteger.class));
-
- assertEquals(
- Types.VARBINARY,
- TypesMapping.getSqlTypeByJava(MockSerializable.class));
- assertEquals(Types.VARCHAR, TypesMapping.getSqlTypeByJava(char[].class));
- assertEquals(Types.VARCHAR, TypesMapping.getSqlTypeByJava(Character[].class));
- assertEquals(Types.VARBINARY, TypesMapping.getSqlTypeByJava(Byte[].class));
- }
-
- public void testGetSqlTypeByJavaString() throws Exception {
- assertEquals(Types.VARCHAR, TypesMapping.getSqlTypeByJava(String.class.getName()));
-
- // make sure we can handle arrays...
- assertEquals(Types.BINARY, TypesMapping.getSqlTypeByJava("byte[]"));
-
- assertEquals(
- Types.TIMESTAMP,
- TypesMapping.getSqlTypeByJava(Calendar.class.getName()));
- assertEquals(
- Types.TIMESTAMP,
- TypesMapping.getSqlTypeByJava(GregorianCalendar.class.getName()));
- assertEquals(
- Types.BIGINT,
- TypesMapping.getSqlTypeByJava(BigInteger.class.getName()));
-
- assertEquals(
- Types.VARBINARY,
- TypesMapping.getSqlTypeByJava(MockSerializable.class.getName()));
-
- assertEquals(Types.VARCHAR, TypesMapping.getSqlTypeByJava("char[]"));
- assertEquals(
- Types.VARCHAR,
- TypesMapping.getSqlTypeByJava("java.lang.Character[]"));
- assertEquals(Types.VARBINARY, TypesMapping.getSqlTypeByJava("java.lang.Byte[]"));
- }
-
- public void testGetSqlTypeByJavaPrimitive() throws Exception {
- assertEquals(Types.INTEGER, TypesMapping.getSqlTypeByJava(Integer.TYPE));
- assertEquals(Types.BIGINT, TypesMapping.getSqlTypeByJava(Long.TYPE));
- }
-
- public void testTypeInfoCompleteness() throws Exception {
- // check counts
- // since more then 1 database type can map to a single JDBC type
- Connection conn = dataSourceFactory.getSharedDataSource().getConnection();
- int len = 0;
- try {
- DatabaseMetaData md = conn.getMetaData();
- ResultSet rs = md.getTypeInfo();
- try {
- while (rs.next()) {
- len++;
- }
- }
- finally {
- rs.close();
- }
- }
- finally {
- conn.close();
- }
-
- int actualLen = 0;
- TypesMapping map = createTypesMapping();
-
- for (List<TypesMapping.TypeInfo> entry : map.databaseTypes.values()) {
- actualLen += entry.size();
- }
-
- // this is bad assertion, since due to some hacks
- // the same database types may map more then once,
- // so we have to use <=
- assertTrue(len <= actualLen);
- }
-
- TypesMapping createTypesMapping() throws Exception {
- Connection conn = dataSourceFactory.getSharedDataSource().getConnection();
-
- try {
- DatabaseMetaData md = conn.getMetaData();
- return new TypesMapping(md);
- }
- finally {
- conn.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapterIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapterIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapterIT.java
new file mode 100644
index 0000000..9fa1f1e
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapterIT.java
@@ -0,0 +1,68 @@
+/*****************************************************************
+ * 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.hsqldb;
+
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class HSQLDBAdapterIT extends ServerCase {
+
+ @Inject
+ private AdhocObjectFactory objectFactory;
+
+ public void testCreateTableIgnoresDoublePrecision() {
+ HSQLDBAdapter adapter = objectFactory.newInstance(
+ HSQLDBAdapter.class,
+ HSQLDBAdapter.class.getName());
+ DbEntity e = new DbEntity("Test");
+ DbAttribute dblPrec = new DbAttribute("dbl1");
+ dblPrec.setType(Types.DOUBLE);
+ dblPrec.setMaxLength(22);
+ e.addAttribute(dblPrec);
+
+ String sql = adapter.createTable(e);
+
+ // CAY-1095.
+ // Make sure the double type is preserved, but not precision constraints, due to a bug in HSQLDB.
+ assertTrue(sql.indexOf("DOUBLE") > 0);
+ assertEquals(-1, sql.indexOf("DOUBLE(22)"));
+ }
+
+ public void testCreateTableAddsCachedKeyword() {
+ HSQLDBAdapter adapter = objectFactory.newInstance(
+ HSQLDBAdapter.class,
+ HSQLDBAdapter.class.getName());
+ DbEntity e = new DbEntity("Test");
+ DbAttribute dblPrec = new DbAttribute("dbl1");
+ dblPrec.setType(Types.INTEGER);
+ e.addAttribute(dblPrec);
+
+ String sql = adapter.createTable(e);
+
+ assertEquals(0,sql.indexOf("CREATE CACHED TABLE"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapterTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapterTest.java
deleted file mode 100644
index cef90f1..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapterTest.java
+++ /dev/null
@@ -1,68 +0,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.
- ****************************************************************/
-
-package org.apache.cayenne.dba.hsqldb;
-
-import java.sql.Types;
-
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class HSQLDBAdapterTest extends ServerCase {
-
- @Inject
- private AdhocObjectFactory objectFactory;
-
- public void testCreateTableIgnoresDoublePrecision() {
- HSQLDBAdapter adapter = objectFactory.newInstance(
- HSQLDBAdapter.class,
- HSQLDBAdapter.class.getName());
- DbEntity e = new DbEntity("Test");
- DbAttribute dblPrec = new DbAttribute("dbl1");
- dblPrec.setType(Types.DOUBLE);
- dblPrec.setMaxLength(22);
- e.addAttribute(dblPrec);
-
- String sql = adapter.createTable(e);
-
- // CAY-1095.
- // Make sure the double type is preserved, but not precision constraints, due to a bug in HSQLDB.
- assertTrue(sql.indexOf("DOUBLE") > 0);
- assertEquals(-1, sql.indexOf("DOUBLE(22)"));
- }
-
- public void testCreateTableAddsCachedKeyword() {
- HSQLDBAdapter adapter = objectFactory.newInstance(
- HSQLDBAdapter.class,
- HSQLDBAdapter.class.getName());
- DbEntity e = new DbEntity("Test");
- DbAttribute dblPrec = new DbAttribute("dbl1");
- dblPrec.setType(Types.INTEGER);
- e.addAttribute(dblPrec);
-
- String sql = adapter.createTable(e);
-
- assertEquals(0,sql.indexOf("CREATE CACHED TABLE"));
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/mysql/MySQLAdapterIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/mysql/MySQLAdapterIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/mysql/MySQLAdapterIT.java
new file mode 100644
index 0000000..f80c90b
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/mysql/MySQLAdapterIT.java
@@ -0,0 +1,65 @@
+/*****************************************************************
+ * 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.mysql;
+
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class MySQLAdapterIT extends ServerCase {
+
+ @Inject
+ private AdhocObjectFactory objectFactory;
+
+ public void testCreateTableAppendPKClause() {
+ MySQLAdapter adapter = objectFactory.newInstance(
+ MySQLAdapter.class,
+ MySQLAdapter.class.getName());
+
+ DbEntity e = new DbEntity("Test");
+ DbAttribute pk1 = new DbAttribute("PK1");
+ pk1.setPrimaryKey(true);
+ e.addAttribute(pk1);
+
+ DbAttribute pk2 = new DbAttribute("PK2");
+ pk2.setPrimaryKey(true);
+ e.addAttribute(pk2);
+
+ StringBuffer b1 = new StringBuffer();
+ adapter.createTableAppendPKClause(b1, e);
+
+ assertTrue(b1.indexOf("PK1") > 0);
+ assertTrue(b1.indexOf("PK2") > 0);
+ assertTrue(b1.indexOf("PK1") < b1.indexOf("PK2"));
+
+ pk2.setGenerated(true);
+
+ StringBuffer b2 = new StringBuffer();
+ adapter.createTableAppendPKClause(b2, e);
+
+ assertTrue(b2.indexOf("PK1") > 0);
+ assertTrue(b2.indexOf("PK2") > 0);
+ assertTrue(b2.indexOf("PK1") > b2.indexOf("PK2"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/mysql/MySQLAdapterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/mysql/MySQLAdapterTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/mysql/MySQLAdapterTest.java
deleted file mode 100644
index 87cf911..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/mysql/MySQLAdapterTest.java
+++ /dev/null
@@ -1,65 +0,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.
- ****************************************************************/
-
-package org.apache.cayenne.dba.mysql;
-
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class MySQLAdapterTest extends ServerCase {
-
- @Inject
- private AdhocObjectFactory objectFactory;
-
- public void testCreateTableAppendPKClause() {
- MySQLAdapter adapter = objectFactory.newInstance(
- MySQLAdapter.class,
- MySQLAdapter.class.getName());
-
- DbEntity e = new DbEntity("Test");
- DbAttribute pk1 = new DbAttribute("PK1");
- pk1.setPrimaryKey(true);
- e.addAttribute(pk1);
-
- DbAttribute pk2 = new DbAttribute("PK2");
- pk2.setPrimaryKey(true);
- e.addAttribute(pk2);
-
- StringBuffer b1 = new StringBuffer();
- adapter.createTableAppendPKClause(b1, e);
-
- assertTrue(b1.indexOf("PK1") > 0);
- assertTrue(b1.indexOf("PK2") > 0);
- assertTrue(b1.indexOf("PK1") < b1.indexOf("PK2"));
-
- pk2.setGenerated(true);
-
- StringBuffer b2 = new StringBuffer();
- adapter.createTableAppendPKClause(b2, e);
-
- assertTrue(b2.indexOf("PK1") > 0);
- assertTrue(b2.indexOf("PK2") > 0);
- assertTrue(b2.indexOf("PK1") > b2.indexOf("PK2"));
- }
-}