You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/09/09 17:07:33 UTC
[01/13] ISIS-522: mothballing SQL OS.
Updated Branches:
refs/heads/master f807fab44 -> 405616090
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/src/main/resources/log4j.properties b/mothballed/component/objectstore/sql/sql-tests-served/src/main/resources/log4j.properties
new file mode 100644
index 0000000..bcafd74
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/src/main/resources/log4j.properties
@@ -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.
+# apache's log4j is used to provide system logging.
+log4j.rootCategory=DEBUG, Console, File
+#log4j.rootCategory=INFO, Console, File
+
+
+# The console appender
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.target=System.out
+log4j.appender.Console.layout=org.apache.log4j.PatternLayout
+log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} [%-20c{1} %-10t %-5p] %m%n
+
+
+log4j.appender.File=org.apache.log4j.RollingFileAppender
+log4j.appender.File.file=isis.log
+log4j.appender.File.append=false
+#log4j.appender.File.maxFileSize=500KB
+#log4j.appender.File.maxBackupIndex=1
+log4j.appender.File.layout=org.apache.log4j.PatternLayout
+log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
+
+
+
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/src/site/apt/index.apt b/mothballed/component/objectstore/sql/sql-tests-served/src/site/apt/index.apt
new file mode 100644
index 0000000..1668418
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/src/site/apt/index.apt
@@ -0,0 +1,29 @@
+~~ 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.
+
+
+
+SQL ObjectStore Integration Tests
+
+ This module runs tests against a few common database servers.
+
+ It will need to be configured for your server environment.
+
+Further Info
+
+ See this module's {{{./apidocs/index.html}Javadoc}} and {{{../docbkx/html/guide/isis-sql-objectstore.html}User Guide}} for more information.
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/src/site/apt/jottings.apt b/mothballed/component/objectstore/sql/sql-tests-served/src/site/apt/jottings.apt
new file mode 100644
index 0000000..c5d1200
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/src/site/apt/jottings.apt
@@ -0,0 +1,24 @@
+~~ 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.
+
+
+
+Jottings
+
+ This page is to capture any random jottings relating to this module prior
+ to being moved into formal documentation.
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/src/site/site.xml
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/src/site/site.xml b/mothballed/component/objectstore/sql/sql-tests-served/src/site/site.xml
new file mode 100644
index 0000000..521d3ce
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/src/site/site.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project>
+
+ <body>
+ <breadcrumbs>
+ <item name="Integration Tests" href="index.html"/>
+ </breadcrumbs>
+
+ <menu name="SQL ObjectStore Tests">
+ <item name="About" href="index.html" />
+ </menu>
+
+ <menu name="SQL OS Modules">
+ <item name="Implementation" href="../sql-impl/index.html" />
+ <item name="Common Tests" href="../sql-tests-common/index.html" />
+ <item name="Integration Tests" href="../sql-tests-served/index.html" />
+ </menu>
+
+ <menu name="Maven Reports" ref="reports" />
+ </body>
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/db2.properties
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/db2.properties b/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/db2.properties
new file mode 100644
index 0000000..4e5195d
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/db2.properties
@@ -0,0 +1,27 @@
+# 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.
+
+
+
+# Sample configuration
+# Edit this file with your server and authentication details.
+
+# DB2 test
+isis.persistence.sql.jdbc.driver=com.ibm.db2.jcc.DB2Driver
+isis.persistence.sql.jdbc.connection=jdbc:db2://gtd-dev:50000/proddb
+isis.persistence.sql.jdbc.user=db2admin
+isis.persistence.sql.jdbc.password=db2srvtest
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/mssqlserver.properties
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/mssqlserver.properties b/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/mssqlserver.properties
new file mode 100644
index 0000000..b1db3b7
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/mssqlserver.properties
@@ -0,0 +1,32 @@
+# 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.
+
+
+
+# Sample configuration
+# Edit this file with your server and authentication details.
+
+
+# SQL Server
+#isis.persistence.sql.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
+#isis.persistence.sql.jdbc.connection=jdbc:sqlserver://SPRSRMS21;databaseName=AnalyticalData
+
+isis.persistence.sql.jdbc.driver=net.sourceforge.jtds.jdbc.Driver
+isis.persistence.sql.jdbc.connection=jdbc:jtds:sqlserver://SPRSRMS21;databaseName=AnalyticalData
+
+isis.persistence.sql.jdbc.user=grip
+isis.persistence.sql.jdbc.password=grip
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/mysql.properties
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/mysql.properties b/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/mysql.properties
new file mode 100644
index 0000000..117c681
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/mysql.properties
@@ -0,0 +1,29 @@
+# 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.
+
+
+# Sample configuration
+# Edit this file with your server and authentication details.
+#
+# If this file exists, it overrides the MySqlTest#getProperties() method
+isis.persistor.sql.jdbc.driver=com.mysql.jdbc.Driver
+isis.persistor.sql.jdbc.connection=jdbc:mysql://abacus/noftest?useTimezone=false
+#true&serverTimezone=GMT
+isis.persistor.sql.jdbc.user=nof
+isis.persistor.sql.jdbc.password=
+
+isis.persistor.sql.datatypes.double=DOUBLE PRECISION
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/postgresql.properties
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/postgresql.properties b/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/postgresql.properties
new file mode 100644
index 0000000..b9fccfb
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/src/test/config/postgresql.properties
@@ -0,0 +1,29 @@
+# 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.
+
+
+# Sample configuration
+# Edit this file with your server and authentication details.
+# If this file exists, it overrides the PostreSqlTest#getProperties() method
+isis.persistor.sql.jdbc.driver=org.postgresql.Driver
+isis.persistor.sql.jdbc.connection=jdbc:postgresql://abacus/noftest
+isis.persistor.sql.jdbc.user=nof
+isis.persistor.sql.jdbc.password=
+
+isis.persistor.sql.datatypes.timestamp=TIMESTAMP
+isis.persistor.sql.datatypes.datetime=TIMESTAMP
+isis.persistor.sql.datatypes.double=DOUBLE PRECISION
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/MySqlIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/MySqlIntegrationTest.java b/mothballed/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/MySqlIntegrationTest.java
new file mode 100644
index 0000000..25e838a
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/MySqlIntegrationTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.util.Properties;
+
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestData;
+
+public class MySqlIntegrationTest extends SqlIntegrationTestData {
+
+ /**/
+ @Override
+ public Properties getProperties() {
+ Properties properties = super.getProperties();
+ if (properties == null) {
+ // Only used if *sql.properties is not found
+ properties = new Properties();
+ properties.put(SqlObjectStore.BASE_NAME + ".jdbc.driver", "com.mysql.jdbc.Driver");
+ // properties.put(SqlObjectStore.BASE_NAME + ".jdbc.connection",
+ // "jdbc:mysql://abacus/noftest&useTimezone=true&serverTimezone=GMT");
+ properties.put(SqlObjectStore.BASE_NAME + ".jdbc.connection", "jdbc:mysql://abacus/noftest&useLegacyDatetimeCode=false");
+ properties.put(SqlObjectStore.BASE_NAME + ".jdbc.user", "nof");
+ properties.put(SqlObjectStore.BASE_NAME + ".jdbc.jdbc.password", "");
+ }
+ return properties;
+ }
+
+ /**/
+
+ @Override
+ public String getPropertiesFilename() {
+ return "mysql.properties";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/PostgreSqlIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/PostgreSqlIntegrationTest.java b/mothballed/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/PostgreSqlIntegrationTest.java
new file mode 100644
index 0000000..b3ca865
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/PostgreSqlIntegrationTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.util.Properties;
+
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestData;
+
+public class PostgreSqlIntegrationTest extends SqlIntegrationTestData {
+
+ @Override
+ public Properties getProperties() {
+ Properties properties = super.getProperties();
+ if (properties == null) {
+ properties = new Properties();
+ // Only used if src/test/config/postgresql.properties does not
+ // exist.
+ properties.put(SqlObjectStore.BASE_NAME + ".jdbc.driver", "org.postgresql.Driver");
+ properties.put(SqlObjectStore.BASE_NAME + ".jdbc.connection", "jdbc:postgresql://abacus/noftest");
+ properties.put(SqlObjectStore.BASE_NAME + ".jdbc.user", "nof");
+ properties.put(SqlObjectStore.BASE_NAME + ".jdbc.password", "");
+
+ // properties.put(SqlObjectStore.BASE_NAME + ".datatypes.timestamp",
+ // "TIMESTAMP");
+ // properties.put(SqlObjectStore.BASE_NAME + ".datatypes.datetime",
+ // "TIMESTAMP");
+ }
+ return properties;
+ }
+
+ @Override
+ public String getPropertiesFilename() {
+ return "postgresql.properties";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/src/docbkx/guide/isis-sql-objectstore.xml
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/src/docbkx/guide/isis-sql-objectstore.xml b/mothballed/component/objectstore/sql/src/docbkx/guide/isis-sql-objectstore.xml
new file mode 100644
index 0000000..6858fe9
--- /dev/null
+++ b/mothballed/component/objectstore/sql/src/docbkx/guide/isis-sql-objectstore.xml
@@ -0,0 +1,886 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"file:./src/docbkx/dtd-4.5/docbookx.dtd">
+<book>
+ <bookinfo>
+ <title><?eval ${docbkxGuideTitle}?></title>
+
+ <subtitle><?eval ${docbkxGuideSubTitle}?></subtitle>
+
+ <releaseinfo><?eval ${project.version}?></releaseinfo>
+
+ <authorgroup>
+ <author>
+ <firstname>Kevin</firstname>
+
+ <surname>Meyer</surname>
+ </author>
+
+ <author>
+ <firstname>Robert</firstname>
+
+ <surname>Matthews</surname>
+ </author>
+ </authorgroup>
+
+ <legalnotice>
+ <para>Permission is granted to make and distribute verbatim copies of
+ this manual provided that the copyright notice and this permission
+ notice are preserved on all copies.</para>
+ </legalnotice>
+ </bookinfo>
+
+ <!-- front matter -->
+
+ <toc></toc>
+
+ <preface id="preface">
+ <title>Preface</title>
+
+ <para><emphasis>Apache Isis</emphasis> is designed to allow programmers
+ rapidly develop domain-driven applications following the <ulink
+ url="http://en.wikipedia.org/wiki/Naked_Objects">Naked Objects</ulink>
+ pattern. It is made up of a core framework plus a number of alternate
+ implementations, and supports various viewers and object stores. Apache
+ Isis is hosted at the <ulink url="http://incubator.apache.org/isis">Apache
+ Foundation</ulink>, and is licensed under <ulink
+ url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software
+ License v2</ulink>.</para>
+
+ <para>This guide is written for programmers who want to use the
+ <emphasis>SQL Object Store</emphasis> to persist domain objects running
+ within the <emphasis>Apache Isis</emphasis> framework. Specifically, it
+ covers how to write repository implementations, how to configure the
+ object store, and how to deploy your applications using the object
+ store.</para>
+ </preface>
+
+ <!--main content -->
+
+ <chapter id="chp.Intro">
+ <title>Operation</title>
+
+ <abstract>
+ <para>What's it all about?</para>
+ </abstract>
+
+ <sect1>
+ <title>Background</title>
+
+ <para>The SQL objectstore provides a fully-automatic object store that
+ uses a jdbc SQL-compatible database server.</para>
+
+ <para>All domain objects (entities) are introspected during
+ initialisation, and have a 1-to-1 mapping onto a database table. All
+ properties (values) are mapped onto one or more columns with each
+ database table.</para>
+
+ <para>Domain object classes are introspected and all properties
+ recursively introspected to value types. Thus, if a property stores a
+ reference to a class, that class's properties are introspected,
+ etc.</para>
+ </sect1>
+
+ <sect1>
+ <title>Setup</title>
+
+ <sect2>
+ <title>Properties</title>
+
+ <para>The SQL objectstore is setup via the
+ <code>isis.properties</code> file. The required variables are given
+ below:</para>
+
+ <blockquote>
+ <para><property>isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver</property></para>
+
+ <para><property>isis.persistor.sql.jdbc.connection=jdbc:hsqldb:file:hsql-db/tests</property></para>
+
+ <para><property>isis.persistor.sql.jdbc.user=sa</property></para>
+
+ <para><property>isis.persistor.sql.jdbc.password=</property></para>
+ </blockquote>
+
+ <para>The driver property must contain the name of the jdbc driver
+ class that provides access to your SQL server. Known examples are
+ given below in <xref linkend="sec.servers.tested" />.</para>
+ </sect2>
+
+ <sect2>
+ <title>Table Creation</title>
+
+ <para>Missing database tables are automatically created when the SQL
+ objectstore is initialised.</para>
+
+ <para>Please note that changes to domain classes such as renaming
+ fields (properties) or the classes themselves, are
+ <emphasis>not</emphasis> automatically detected. If you rename a
+ property after a table has been created, you should use the
+ appropriate database administration tool to rename the column in the
+ containing table.</para>
+
+ <para>If you rename a domain class (entity), you must also rename the
+ appropriate table.</para>
+ </sect2>
+ </sect1>
+
+ <sect1>
+ <title>Mappers</title>
+
+ <para>The mappers take care of mapping a value type onto a SQL data
+ type. Default mappers are provided by
+ JdbcFieldMappingFactoryInstaller.</para>
+
+ <sect2>
+ <title id="sec.mappers.modifiable-values">Modifiable values</title>
+
+ <para>The following SQL datatypes can be overridden, if specified in
+ the properties file (the default value is given in parenthesis), [the
+ mapped value classes are given in square brackets]:<simplelist>
+ <member>isis.persistor.sql.datatypes.timestamp (DATETIME)
+ [TimeStamp, java.sql.Timestamp]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.datetime (DATETIME)
+ [DateTime]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.date (DATE) [Date,
+ java.sql.Date, java.util.Date]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.time (TIME) [Time]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.double (FLOAT)
+ [double]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.float (FLOAT)
+ [float]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.short (INT) [short]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.long (INT) [long,
+ Color]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.int (INT) [int]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.boolean (CHAR(1))
+ [boolean]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.string (VARCHAR(65))
+ [String]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.longstring (VARCHAR(128))
+ [String]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.password (VARCHAR(120))
+ [Password]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.default (VARCHAR(65))
+ [Everything else, e.g. Image]</member>
+ </simplelist></para>
+
+ <para><simplelist>
+ <member>isis.persistor.sql.datatypes.primarykey (INTEGER)
+ [IdMappingAbstract -> JdbcObjectReferenceMapping ->
+ JdbcObjectReferenceFieldMapping]</member>
+ </simplelist></para>
+
+ <para>The final value, primarykey, is a special value.</para>
+
+ <para>In general, be very careful about changing the SQL data type, as
+ the default value mappers are written assuming the default values.
+ Data parsing uses prepared statements and reads/writes values as
+ objects.</para>
+
+ <para>The datatype longstring is used to store classnames, required
+ for polymorphism.</para>
+ </sect2>
+
+ <sect2>
+ <title>Floating Point Value Limits</title>
+
+ <para><emphasis>Caution:</emphasis> Testing on certain database
+ servers (MySQL and PostgreSQL) has shown that <code>float</code>s and
+ <code>double</code>s (stored as <code>FLOAT</code> or <code>DOUBLE
+ PRECISION</code> respectively) are not stored to the same resolution
+ as supported by Java. The tested range of float is 1E-37 to 1E38, and
+ the tested range of double is 1E-307 to 1E308.</para>
+ </sect2>
+
+ <sect2>
+ <title>Fixed values</title>
+
+ <para>The following classes are not modifiable:</para>
+
+ <para>[char] is set to CHAR(1)</para>
+
+ <para>[Money] value is FLOAT, currency is VARCHAR(3)</para>
+
+ <para>[Percentage] is FLOAT</para>
+ </sect2>
+
+ <sect2>
+ <title>Modifying individual property types</title>
+
+ <para>By default, all property types will use the SQL datatype, as
+ determined above (see <xref
+ linkend="sec.mappers.modifiable-values" />), but it is possible to
+ override these values for individual object properties, by specifying
+ the following override in the properties file:</para>
+
+ <para><property>isis.persistor.sql.automapper.type.<object>.<property>=<SQL
+ data type></property></para>
+
+ <para>where</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>object is the final part of the domain object name (e.g. in
+ my.domain.Member, it'll be Member)</para>
+ </listitem>
+
+ <listitem>
+ <para>property is the lower case property name (e.g. in getName(),
+ it'll be name)</para>
+ </listitem>
+
+ <listitem>
+ <para>SQL data type is an acceptable datatype (e.g. VARCHAR(255)
+ )</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>Again, please be very careful about changing the defaults as the
+ value mappers make assumptions about the underlying data type.</para>
+
+ <para>It is safe to change the size of VARCHAR() types, e.g. when you
+ know only a partcular field requires more that 65 characters, the
+ default String length.</para>
+ </sect2>
+ </sect1>
+
+ <sect1>
+ <title>Naming Conventions</title>
+
+ <para>While case is determined by the capabilities of the database
+ driver, all SQL names will be written in UPPER CASE, below.</para>
+
+ <sect2>
+ <title>Tables</title>
+
+ <para>By default, all Isis tables are preceded with "ISIS_". This
+ behaviour can be altered by specifying a replacement table prefix. See
+ <xref linkend="sec.defaults.tableprefix" />.</para>
+
+ <sect3>
+ <title>Internal Tables</title>
+
+ <para>ISIS_ADMIN_SERIAL_ID ISIS_ADMIN_SERVICES</para>
+ </sect3>
+
+ <sect3>
+ <title>Domain Tables</title>
+
+ <para>Only the "class" part of the package name is used. Thus a
+ domain class called "some.package.Client", will be mapped onto a
+ table "ISIS_CLIENT" (assuming that the default table prefix has not
+ been changed).</para>
+ </sect3>
+ </sect2>
+
+ <sect2>
+ <title>Columns</title>
+
+ <sect3>
+ <title>Internal column: pk_id</title>
+
+ <para>ID column: PK_ID</para>
+
+ <para>VERSION BIGINT,</para>
+
+ <para>MODIFIED_BY VARCHAR(32),</para>
+
+ <para>MODIFIED_ON TIMESTAMP</para>
+
+ <para>The default ID column name is "PK_ID", but this can be
+ over-ridden by specifying the new name in the properties
+ file:</para>
+
+ <para><property>isis.persistor.sql.pk_id=id</property></para>
+
+ <para><property>ID column: ID</property></para>
+
+ <para><property>Used internally by Isis to record services, in the
+ table "ISIS_ADMIN_SERVICES".</property></para>
+ </sect3>
+
+ <sect3>
+ <title>Properties</title>
+
+ <para>Most properties are named as per the class property. This
+ means you must take care not to use SQL reserved labels are property
+ names. The exceptions are collections and multi-field values (e.g.
+ Money).</para>
+ </sect3>
+
+ <sect3>
+ <title>Collections</title>
+
+ <para>Collections are mapped onto the child class:</para>
+
+ <para>If a parent class (some.package.Parent) has a collection of
+ (some.other.package.Child) named "children", the child table
+ (ISIS_CHILD) gets a column labeled "FK_PARENT_CHILDREN" of type
+ primarykey. The child property is assigned the ID of the parent
+ class.</para>
+
+ <para>This means that a given child can only appear in one parent's
+ collection of the same name.</para>
+ </sect3>
+
+ <sect3>
+ <title>Multi-field values</title>
+
+ <para>Some value types need more than 1 field to store their values,
+ e.g. Money - some.package.class#price.</para>
+
+ <para>In this case, the SQL objectstore creates 2 fields, price1 and
+ price2.</para>
+
+ <para>See "<code>JdbcMoneyValueMapper</code>", which extends
+ "<code>AbstractJdbcMultiFieldMapping</code>".</para>
+ </sect3>
+ </sect2>
+ </sect1>
+
+ <sect1>
+ <title>Number of instances returned by queries</title>
+
+ <para>By default, only up to 100 object instances are returned by
+ queries. This value can be changed by specifying:</para>
+
+ <para><property>isis.persistor.sql.maxinstances=100</property></para>
+ </sect1>
+
+ <sect1>
+ <title>Versioning</title>
+
+ <para>Isis uses a version number to assist in detecting concurrency
+ conflicts.</para>
+
+ <para>However, if you need to turn off versioning completely, or for a
+ particular table, you can control it with:</para>
+
+ <para><property>isis.persistor.sql.default.versioning=false</property></para>
+
+ <para>for global control, or by table:</para>
+
+ <para><property>isis.persistor.sql.default.versioning.members=false</property></para>
+ </sect1>
+
+ <sect1>
+ <title>Password values</title>
+
+ <para>The <code>JdbcPasswordValueMapper</code> value mapper has the
+ ability to (weakly) encode the password value strings stored in the
+ database tables.</para>
+
+ <para>By adding the following property values:</para>
+
+ <blockquote>
+ <para><property>isis.persistor.sql.default.password.seed=<random
+ string></property></para>
+
+ <para><property>isis.persistor.sql.default.password.length=<integer
+ length></property></para>
+ </blockquote>
+
+ <para>You can enable a weak password encoding/decoding scheme that will
+ obscure password values from casual browsers of your database
+ tables.</para>
+
+ <para>The length of all stored passwords is the same, and determined by
+ the <property>isis.persistor.sql.default.password.length</property>
+ property. This length must not exceed the SQL storage, as defined in
+ <xref linkend="sec.mappers.modifiable-values" />.</para>
+
+ <para>The passwords are convolved with the value of the string given by
+ the <property>isis.persistor.sql.default.password.seed</property>
+ property, and the resulting string is stored in the database
+ table.</para>
+
+ <para>If <property>isis.persistor.sql.default.password.seed</property>
+ is undefined (null), the passwords are stored as plain text.</para>
+ </sect1>
+ </chapter>
+
+ <chapter id="ch.supported.dbs">
+ <title>Supported Database Servers</title>
+
+ <abstract>
+ <para>Which SQL database servers have been used?</para>
+ </abstract>
+
+ <sect1>
+ <!--content: List of database servers tested.-->
+
+ <title id="sec.servers.tested">Tested</title>
+
+ <para>The following database servers are tested in the object store
+ integration tests:<itemizedlist>
+ <listitem>
+ <para>HSQLDB (tested against 1.8.0.10)</para>
+ </listitem>
+
+ <listitem>
+ <para>Postgresql (tested on 8.3.12-ubuntu9.04)</para>
+ </listitem>
+
+ <listitem>
+ <para>MySQL (tested on 5.1.31-1ubuntu2)</para>
+ </listitem>
+
+ <listitem>
+ <para>Microsoft SQL Server 2008 (Only from 2008 is DATE and TIME
+ supported)</para>
+ </listitem>
+ </itemizedlist></para>
+
+ <sect2>
+ <title>HSQLDB</title>
+
+ <para></para>
+ </sect2>
+
+ <sect2>
+ <title>Postgresql</title>
+
+ <para><blockquote>
+ <para><property>isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver</property></para>
+
+ <para><property>isis.persistor.sql.jdbc.connection=jdbc:hsqldb:file:hsql-db/tests</property></para>
+
+ <para><property>isis.persistor.sql.jdbc.user=sa</property></para>
+
+ <para><property>isis.persistor.sql.jdbc.password=</property></para>
+ </blockquote>The default <classname>TimeStamp</classname> and
+ <classname>DateTime</classname> SQL data class is DATETIME, which does
+ not work on Postgresql. Here, the default must be replaced with the
+ following properties file entries:</para>
+
+ <blockquote>
+ <para>isis.persistor.sql.datatypes.timestamp=TIMESTAMP</para>
+
+ <para>isis.persistor.sql.datatypes.datetme=TIMESTAMP</para>
+
+ <para>isis.persistor.sql.datatypes.double=DOUBLE PRECISION</para>
+ </blockquote>
+
+ <para></para>
+ </sect2>
+
+ <sect2>
+ <title>MySQL</title>
+
+ <para>There was an issue with storing and correctly retrieving date
+ (time) values - a special "try .. catch" has been used to ensure that
+ UTC temporal values are correctly retrieved.</para>
+
+ <para>The following data type overrides may be required:</para>
+
+ <blockquote>
+ <para>isis.persistor.sql.datatypes.double=DOUBLE PRECISION</para>
+ </blockquote>
+
+ <para></para>
+ </sect2>
+
+ <sect2>
+ <title>Microsoft SQL Server 2008</title>
+
+ <para>The sourceforge driver seemed to work well enough for
+ testing.</para>
+
+ <para>The tested connection parameters were:</para>
+
+ <para><blockquote>
+ <para># SQL Server </para>
+
+ <para>#isis.persistence.sql.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver</para>
+
+ <para>isis.persistence.sql.jdbc.driver=net.sourceforge.jtds.jdbc.Driver</para>
+
+ <para>isis.persistence.sql.jdbc.connection=jdbc:jtds:sqlserver://<server>;databaseName=<database></para>
+
+ <para>isis.persistence.sql.jdbc.user=<user></para>
+
+ <para>isis.persistence.sql.jdbc.password=<password></para>
+ </blockquote></para>
+
+ <para></para>
+ </sect2>
+
+ <sect2>
+ <title>IBM DB2 (v8)</title>
+
+ <para>Beware! This version of DB2 has a very small limit on table and
+ column names. You will have to keep your domain class and property
+ names short to suit, especially collections!</para>
+
+ <para>The tested connection parameters were:</para>
+
+ <blockquote>
+ <para># DB2 test</para>
+
+ <para>
+ isis.persistence.sql.jdbc.driver=com.ibm.db2.jcc.DB2Driver</para>
+
+ <para>
+ isis.persistence.sql.jdbc.connection=jdbc:db2://<host>:50000/<database></para>
+
+ <para> isis.persistence.sql.jdbc.user=<user></para>
+
+ <para> isis.persistence.sql.jdbc.password=<password></para>
+ </blockquote>
+ </sect2>
+ </sect1>
+
+ <sect1>
+ <title>Tested values</title>
+
+ <para>The following value types have been tested (stored and
+ retrieved):</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>standard values: integer, short, long (INT), float, double
+ (FLOAT), char (CHAR(2)).</para>
+ </listitem>
+
+ <listitem>
+ <para>standard classes: Money (FLOAT and VARCHAR(3)), Percentage
+ (FLOAT), Password (VARCHAR(12)), Color (INT), String (VARCHAR
+ (65)).</para>
+ </listitem>
+
+ <listitem>
+ <para>Special value mappers:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para><code>org.apache.isis.applib.value.date</code> and
+ <code>java.sql.date</code> (DATE, via
+ <code>org.apache.isis.alternatives.objectstore.sql.jdbc.JdbcDateMapper</code>)</para>
+ </listitem>
+
+ <listitem>
+ <para>Time, DateTime (DATETIME), java.sql.Time, java.util.Date,
+ java.sql.Timestamp (DATETIME), TimeStamp (DATETIME) blah</para>
+ </listitem>
+ </itemizedlist>
+ </listitem>
+
+ <listitem>
+ <para></para>
+ </listitem>
+ </itemizedlist>
+
+ <para>Default automapper is installed by
+ <code>org.apache.isis.alternatives.objectstore.sql.FieldMappingFactoryInstaller</code>
+ ..</para>
+
+ <para>Default automapper is
+ <code>org.apache.isis.objectstore.sql.jdbc.installer.JdbcFieldMappingFactoryInstaller</code></para>
+
+ <para></para>
+ </sect1>
+ </chapter>
+
+ <chapter>
+ <title id="sec.defaults">Defaults</title>
+
+ <para>The SQL objectstore exposes several defaults that can be replaced
+ either in configuration or at runtime.</para>
+
+ <para>The class
+ <code>org.apache.isis.objectstore.sql.Defaults</code>
+ contains the following:</para>
+
+ <para>Programmatic, at runtime:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>TimeZone: <code>setTimeZone(DateTimeZone.UTC)</code></para>
+ </listitem>
+ </itemizedlist>
+
+ <para>Configuration, e.g. in isis.properties:</para>
+
+ <para><itemizedlist>
+ <listitem>
+ <para>Primary key column:</para>
+
+ <para><property>isis.persistor.sql.default.pk_id=pk_id</property></para>
+ </listitem>
+
+ <listitem>
+ <para>Service ID column:</para>
+
+ <para><property>isis.persistor.sql.default.id=id</property></para>
+ </listitem>
+
+ <listitem>
+ <para>Maximum records returned by objectstore methods that return a
+ list/collection, such as <code>allMatches()</code>, etc:</para>
+
+ <para><property><property>isis.persistor.sql.default.maxinstances=100</property></property></para>
+ </listitem>
+
+ <listitem>
+ <para id="sec.defaults.tableprefix" xreflabel="Table Prefix">Table
+ prefix. The default prefix "isis_" is added to all table created by
+ the object store. This prefix can be replaced, or left off entirely
+ by specifying an empty value, e.g.:</para>
+
+ <para><property>isis.persistor.sql.default.tableprefix=</property></para>
+ </listitem>
+
+ <listitem>
+ <para>See "Modifiable values", <link
+ linkend="sec.mappers.modifiable-values">above</link>.</para>
+ </listitem>
+ </itemizedlist></para>
+ </chapter>
+
+ <chapter>
+ <title>Polymorphism</title>
+
+ <para>The SQL Objectstore supports polymorphic classes. Both properties
+ and collections are supported.</para>
+
+ <sect1>
+ <title>Properties</title>
+
+ <para>Polymorphic properties are handled with
+ <classname>JdbcPolymorphicObjectReferenceMapping</classname>.</para>
+
+ <para>Two columns are created in the class table: The actual instance
+ class type, and the instance ID.</para>
+ </sect1>
+
+ <sect1>
+ <title>Collections</title>
+
+ <para>There are two implementations currently selectable by editting
+ <classname>AbstractAutoMapper</classname>.</para>
+
+ <para>The default implementation is
+ <classname>PolymorphicForeignKeyInChildCollectionBaseMapper</classname>.</para>
+
+ <sect2>
+ <title>PolymorphicForeignKeyInChildCollectionBaseMapper</title>
+
+ <para>Creates two columns in the child class table, to contain the
+ child class type and child class ID.</para>
+
+ <para>Used to map 1-to-many collections by creating, in the collection
+ child table (which may be an interface or abstract class), 2 columns
+ per parent collection.</para>
+
+ <para>The first column is the class type, the second is the entity
+ ID.</para>
+
+ <para>The columns are named by combining the final part of the parent
+ class name and the collection variable name.</para>
+
+ <para>Collection loading is a case of iterating through all collection
+ entries and adding the named class instance of the stored ID.</para>
+ </sect2>
+
+ <sect2>
+ <title>PolymorphicForeignKeyInChildCollectionMapper</title>
+
+ <para>Used to map 1-to-many collections by creating, in the child
+ table, 1 column per parent collection.</para>
+
+ <para>The column is named by combining the final part of the parent
+ class name and the collection variable name.</para>
+
+ <para>Collection loading is a case of iterating through all subclasses
+ of the collection type and adding class instances of the stored ID.
+ This could be problematic if different subclasses have the same
+ ID.</para>
+ </sect2>
+ </sect1>
+ </chapter>
+
+ <appendix>
+ <title>Example</title>
+
+ <para></para>
+
+ <para><property>isis.persistor.sql.jdbc.driver=com.mysql.jdbc.Driver</property></para>
+
+ <para><property>isis.persistor.sql.jdbc.connection=jdbc:mysql://localhost/isis_data</property></para>
+
+ <para><property>isis.persistor.sql.jdbc.user=isis</property></para>
+
+ <para><property>isis.persistor.sql.jdbc.password=noneofyourbusiness</property></para>
+
+ <para><property></property></para>
+
+ <para><property>isis.persistor.sql.default.versioning.Member=false
+ </property></para>
+
+ <para><property>isis.persistor.sql.automapper.type.Member.address=VARCHAR(255)
+ </property></para>
+
+ <para><property>isis.persistor.sql.automapper.type.Member.comments=VARCHAR(255)
+ </property></para>
+ </appendix>
+
+ <appendix>
+ <title>Correspondence</title>
+
+ <abstract>
+ <para>Who said what, when?</para>
+ </abstract>
+
+ <sect1 id="sec.module-ui">
+ <title>Email</title>
+
+ <para></para>
+
+ <sect2>
+ <title>2011/02/01, Response by Dan Haywood</title>
+
+ <para><remark>At the moment I'm just putting down whatever comes into
+ my head, with a view of later editting it into a coherent document,
+ but obviously there are questions of level of detail, etc. For
+ example, should I really bother with describing what persistance is,
+ and how the domain classes are introspected?! </remark></para>
+
+ <para>I don't think so, no.</para>
+
+ <para>That said, if you do find yourself writing "introductory"
+ material like this, we can always move it. The place for such stuff
+ should probably be the "core" documentation
+ (core/src/docbkx/guide/isis-core.xml), which is what I'm chipping away
+ at myself.</para>
+
+ <para><remark>Yes to: what SQL data types are used by default, yes to:
+ how to override the automappers and provide your own mapper, yes to:
+ how collections and parent/child relatonships are handled, etc.
+ </remark></para>
+
+ <para>It'd be worth showing examples of all the different types of
+ mappings supported, as well as those that are not supported.</para>
+
+ <para>For example:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>Id generation - how is that supported?</para>
+ </listitem>
+
+ <listitem>
+ <para>optimistic locking - how supported?</para>
+ </listitem>
+
+ <listitem>
+ <para>one<->many</para>
+ </listitem>
+
+ <listitem>
+ <para>one<-many</para>
+ </listitem>
+
+ <listitem>
+ <para>one->many</para>
+ </listitem>
+
+ <listitem>
+ <para>two one<->many relationships between same types A and
+ B (if I recall, this isn't supported?)</para>
+ </listitem>
+
+ <listitem>
+ <para>many<->many</para>
+ </listitem>
+
+ <listitem>
+ <para>many->many - subtype relationships (roll-up, roll-down,
+ table per subtype)</para>
+ </listitem>
+
+ <listitem>
+ <para>polymorphic relationships to interfaces</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>You could also peruse some of the Hibernate ORM docs for
+ examples of mappings there; that might prompt you to consider some
+ additional scenarios.</para>
+
+ <para><remark>What else?</remark></para>
+
+ <para>Obviously, any additional entries required in isis.properties to
+ enable the SQL object store. In addition, as background it'd be worth
+ explaining about the different subcomponents used by the object store:
+ the OidGenerator, PersistAlgorithm, TransactionManager Also, I know
+ that the JPA object store has to configure a different
+ ClassSubstitutor/ObjectFactory, because it leaves the ORM to perform
+ cglib proxying. I don't think you have any similar restrictions, but
+ it might be worth saying so.</para>
+ </sect2>
+ </sect1>
+
+ <sect1>
+ <title>Edit History</title>
+
+ <para>Last editted: Kevin, 17/10/2011.<!--dd/mm/yyyy--></para>
+ </sect1>
+ </appendix>
+</book>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/src/main/appended-resources/supplemental-models.xml
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/src/main/appended-resources/supplemental-models.xml b/mothballed/component/objectstore/sql/src/main/appended-resources/supplemental-models.xml
new file mode 100644
index 0000000..ecd3906
--- /dev/null
+++ b/mothballed/component/objectstore/sql/src/main/appended-resources/supplemental-models.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<supplementalDataModels xmlns="http://maven.apache.org/supplemental-model/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/supplemental-model/1.0.0 http://maven.apache.org/xsd/supplemental-model-1.0.0.xsd">
+
+ <supplement>
+ <project>
+ <groupId>aopalliance</groupId>
+ <artifactId>aopalliance</artifactId>
+ <version>1.0</version>
+ <licenses>
+ <license>
+ <name>Public Domain</name>
+ </license>
+ </licenses>
+ </project>
+ </supplement>
+
+ <supplement>
+ <!-- not quite sure why licenses:download-license flags this, since license info seems to be in its POM -->
+ <project>
+ <groupId>org.datanucleus</groupId>
+ <artifactId>datanucleus-jodatime</artifactId>
+ <version>3.1.1</version>
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ </license>
+ </licenses>
+ </project>
+ </supplement>
+
+ <supplement>
+ <project>
+ <groupId>org.scannotation</groupId>
+ <artifactId>scannotation</artifactId>
+ <version>1.0.3</version>
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ </project>
+ </supplement>
+
+ <supplement>
+ <project>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ <licenses>
+ <license>
+ <name>BSD License</name>
+ <url>http://dom4j.sourceforge.net/dom4j-1.6.1/license.html</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ </project>
+ </supplement>
+
+ <supplement>
+ <project>
+ <groupId>net.jcip</groupId>
+ <artifactId>jcip-annotations</artifactId>
+ <version>1.0</version>
+ <licenses>
+ <license>
+ <name>Creative Commons Attribution 2.5 License</name>
+ <url>http://creativecommons.org/licenses/by/2.5/</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ </project>
+ </supplement>
+
+
+ <supplement>
+ <project>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.7.0</version>
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ </project>
+ </supplement>
+
+
+</supplementalDataModels>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/src/site/apt/index.apt b/mothballed/component/objectstore/sql/src/site/apt/index.apt
new file mode 100644
index 0000000..fa4323b
--- /dev/null
+++ b/mothballed/component/objectstore/sql/src/site/apt/index.apt
@@ -0,0 +1,48 @@
+~~ 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.
+
+
+
+SQL ObjectStore
+
+ The <sql> object store module provides the ability to persist
+ domain objects into an RDBMS. It has no external dependencies,
+ using simply JDBC.
+
+ For more information, see the
+ {{{./sql-impl/index.html}Implementation}},
+ {{{./sql-tests-common/index.html}Common Tests}} and
+ {{{./sql-tests-served/index.html}Served Tests}}
+ documentation.
+
+
+Alternatives
+
+ Alternatives include:
+
+ * the {{{../dflt/index.html}dflt}} in-memory object store (for prototyping only)
+
+ * the {{{../xml/index.html}XML}} object store
+
+ * the {{{../nosql/index.html}NoSQL}} object store
+
+ []
+
+ Another more sophisticated but also more complex alternative has been implemented
+ using JPA. However, this is currently not part of Isis because it has a
+ dependency on Hibernate (not compatible with the Apache license). One
+ option under consideration is to port JPA object store to use OpenJPA.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/src/site/apt/jottings.apt b/mothballed/component/objectstore/sql/src/site/apt/jottings.apt
new file mode 100644
index 0000000..c5d1200
--- /dev/null
+++ b/mothballed/component/objectstore/sql/src/site/apt/jottings.apt
@@ -0,0 +1,24 @@
+~~ 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.
+
+
+
+Jottings
+
+ This page is to capture any random jottings relating to this module prior
+ to being moved into formal documentation.
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/src/site/site.xml
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/src/site/site.xml b/mothballed/component/objectstore/sql/src/site/site.xml
new file mode 100644
index 0000000..f3e4146
--- /dev/null
+++ b/mothballed/component/objectstore/sql/src/site/site.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project>
+
+ <body>
+ <breadcrumbs>
+ <item name="SQL" href="index.html"/>
+ </breadcrumbs>
+
+ <menu name="SQL Objectstore">
+ <item name="About" href="index.html" />
+ <item name="Jottings" href="jottings.html" />
+ </menu>
+
+ <menu name="Objectstore Modules">
+ <item name="Default (in-mem)" href="../dflt/index.html" />
+ <item name="XML" href="../xml/index.html" />
+ <item name="SQL" href="../sql/index.html" />
+ <item name="NoSQL" href="../nosql/index.html" />
+ </menu>
+
+ <menu name="SQL OS Modules">
+ <item name="Implementation" href="./sql-impl/index.html" />
+ <item name="Tests" href="./sql-tests-common/index.html" />
+ <item name="Integration Tests" href="./sql-tests-served/index.html" />
+ </menu>
+
+ <menu name="Documentation">
+ <item name="${docbkxGuideTitle} (PDF)" href="docbkx/pdf/${docbkxGuideName}.pdf" />
+ <item name="${docbkxGuideTitle} (HTML)" href="docbkx/html/guide/${docbkxGuideName}.html" />
+ </menu>
+
+ <menu name="Maven Reports" ref="reports" />
+ </body>
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index f29f789..2048932 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,7 +49,6 @@
<module>core</module>
<module>component/objectstore/xml</module>
- <module>component/objectstore/sql</module>
<module>component/objectstore/nosql</module>
<module>component/objectstore/jdo</module>
<module>component/progmodel/groovy</module>
[02/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java b/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java
new file mode 100755
index 0000000..0747bcd
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java
@@ -0,0 +1,190 @@
+/*
+ * 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.isis.objectstore.sql.common;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.FixMethodOrder;
+import org.junit.Rule;
+import org.junit.runners.MethodSorters;
+
+import org.apache.isis.core.tck.dom.poly.ReferencingPolyTypesEntity;
+import org.apache.isis.core.tck.dom.sqlos.SqlDomainObjectRepository;
+import org.apache.isis.core.tck.dom.sqlos.data.SqlDataClass;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures.State;
+
+/**
+ * @author Kevin kevin@kmz.co.za
+ *
+ * This common test class is used by all sql objectstore tests to manage the Isis framework.
+ *
+ * @version $Rev$ $Date$
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public abstract class SqlIntegrationTestCommonBase {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ protected SqlIntegrationTestFixtures getSqlIntegrationTestFixtures() {
+ return SqlIntegrationTestFixtures.getInstance();
+ }
+
+ protected SqlDomainObjectRepository factory;
+ protected SqlDataClass sqlDataClass;
+ protected ReferencingPolyTypesEntity referencingPolyTypesEntity;
+
+ public Properties getProperties() {
+ try {
+ final Properties properties = new Properties();
+ properties.load(new FileInputStream("src/test/config/" + getPropertiesFilename()));
+ return properties;
+ } catch (final FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public abstract String getPropertiesFilename();
+
+ protected void setFixtureInitializationStateIfNot(State state, String persistenceMechanism) {
+ if (!persistenceMechanismIs(persistenceMechanism)) {
+ setFixtureInitializationState(state);
+ }
+ }
+
+ protected void setFixtureInitializationState(final State state, final String persistenceMechanism) {
+ if (persistenceMechanismIs(persistenceMechanism)) {
+ setFixtureInitializationState(state);
+ }
+ }
+
+ protected void setFixtureInitializationState(final State state) {
+ getSqlIntegrationTestFixtures().setState(state);
+ }
+
+ protected boolean persistenceMechanismIs(final String persistenceMechanism) {
+ return getProperties().getProperty("isis.persistor").equals(persistenceMechanism);
+ }
+
+ /**
+ * This method can be used to do any DB specific actions the first time the test framework is setup. e.g. In the XML
+ * test, it must delete all XML files in the data store directory.
+ *
+ * You can also use @BeforeClass to perform pre-connection cleanup, such as deleting hsql-db data directories.
+ */
+ public void resetPersistenceStoreDirectlyIfRequired() {
+ }
+
+ protected void testSetup() {
+ resetPersistenceStoreDirectlyIfRequired();
+ getSqlIntegrationTestFixtures().setState(State.INITIALIZE);
+ }
+
+ // //////////////////////////////////////////////////////////////////////////////
+ // before, after
+ // //////////////////////////////////////////////////////////////////////////////
+
+ @Before
+ public void setUpSystem() throws Exception {
+ org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
+
+ if (!getSqlIntegrationTestFixtures().getState().isInitialize()) {
+ return;
+ }
+
+ final Properties properties = getProperties();
+ if (properties == null) {
+ getSqlIntegrationTestFixtures().initSystem("src/test/config", getPropertiesFilename());
+ } else {
+ getSqlIntegrationTestFixtures().initSystem(properties);
+ }
+
+ final String sqlSetupString = getSqlSetupString();
+ if (sqlSetupString != null) {
+ getSqlIntegrationTestFixtures().sqlExecute(sqlSetupString);
+ }
+ }
+
+ /**
+ * optional hook
+ */
+ protected String getSqlSetupString() {
+ return null;
+ }
+
+ @Before
+ public void setUpFactory() throws Exception {
+ factory = getSqlIntegrationTestFixtures().getSqlDataClassFactory();
+
+ // may have been setup by previous test
+ sqlDataClass = getSqlIntegrationTestFixtures().getSqlDataClass();
+ referencingPolyTypesEntity = getSqlIntegrationTestFixtures().getPolyTestClass();
+ }
+
+
+
+ // //////////////////////////////////////////////////////////////////////////////
+ // after
+ // //////////////////////////////////////////////////////////////////////////////
+
+
+ @After
+ public void tearDown() throws Exception {
+
+
+
+ if (!getSqlIntegrationTestFixtures().getState().isInitialize()) {
+ return;
+ }
+ final String sqlTeardownString = getSqlTeardownString();
+ if (sqlTeardownString != null) {
+ try {
+ getSqlIntegrationTestFixtures().sqlExecute(sqlTeardownString);
+ } catch (final SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ getSqlIntegrationTestFixtures().shutDown();
+ }
+
+
+ /**
+ * optional hook
+ */
+ protected String getSqlTeardownString() {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java b/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java
new file mode 100644
index 0000000..dcb5db1
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java
@@ -0,0 +1,651 @@
+/*
+ * 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.isis.objectstore.sql.common;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import org.apache.isis.applib.value.Color;
+import org.apache.isis.applib.value.Date;
+import org.apache.isis.applib.value.DateTime;
+import org.apache.isis.applib.value.Image;
+import org.apache.isis.applib.value.Money;
+import org.apache.isis.applib.value.Password;
+import org.apache.isis.applib.value.Percentage;
+import org.apache.isis.applib.value.Time;
+import org.apache.isis.applib.value.TimeStamp;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.tck.dom.scalars.PrimitiveValuedEntity;
+import org.apache.isis.core.tck.dom.sqlos.SqlDomainObjectRepository;
+import org.apache.isis.core.tck.dom.sqlos.data.SimpleClass;
+import org.apache.isis.core.tck.dom.sqlos.data.SimpleClassTwo;
+import org.apache.isis.core.tck.dom.sqlos.data.SqlDataClass;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures.State;
+
+/**
+ * @author Kevin kevin@kmz.co.za
+ *
+ * This common class is used by the datatype tests (values, objects, collections) to ensure proper creation and
+ * reloading of domain objects.
+ *
+ * There are two "tests", with the framework re-initialised each time (to flush any objectstore memory of any
+ * created domain objects).
+ *
+ * The Singleton class {@link SqlIntegrationTestFixtures} is used to preserve values between tests.
+ *
+ * @version $Rev$ $Date$
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public abstract class SqlIntegrationTestData extends SqlIntegrationTestCommonBase {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SqlIntegrationTestData.class);
+
+ private static List<SimpleClass> simpleClassList1 = new ArrayList<SimpleClass>();
+ private static List<SimpleClass> simpleClassList2 = new ArrayList<SimpleClass>();
+
+ private static SimpleClassTwo simpleClassTwoA;
+ private static SimpleClassTwo simpleClassTwoB;
+
+ private static PrimitiveValuedEntity pve1;
+ private static PrimitiveValuedEntity pve2;
+
+
+ @Before
+ public void setUpXactn() throws Exception {
+ IsisContext.getTransactionManager().startTransaction();
+ }
+
+ @After
+ public void tearDownXactn() throws Exception {
+ IsisContext.getTransactionManager().endTransaction();
+ assertThat(IsisContext.getTransactionManager().getTransaction().getState().isComplete(), is(true));
+
+ }
+
+
+ /**
+ * Uses factory methods within the Isis framework to create the test data,
+ * thus exercising the "create data" portion of the object store.
+ *
+ * The Isis framework will be again be re-created in the next test unless the
+ * object store is "in-memory" (this is required since "in-memory" has to be
+ * left alone for created data to still be present in the next test).
+ */
+ @Test
+ public void testSetupStore() throws Exception {
+ testSetup();
+ setUpFactory();
+ testCreate();
+ }
+
+ protected void testCreate() throws Exception {
+
+ sqlDataClass = factory.newDataClass();
+
+ sqlDataClass.setString("Test String");
+ sqlDataClass.setDate(Data.applibDate);
+ sqlDataClass.setSqlDate(Data.sqlDate);
+ sqlDataClass.setMoney(Data.money);
+ sqlDataClass.setDateTime(Data.dateTime);
+ sqlDataClass.setTimeStamp(Data.timeStamp);
+ sqlDataClass.setTime(Data.time);
+ sqlDataClass.setColor(Data.color);
+ sqlDataClass.setImage(Data.image);
+ sqlDataClass.setPassword(Data.password);
+ sqlDataClass.setPercentage(Data.percentage);
+
+ // Setup SimpleClassTwo
+ simpleClassTwoA = factory.newSimpleClassTwo();
+ simpleClassTwoA.setText("A");
+ simpleClassTwoA.setIntValue(999);
+ simpleClassTwoA.setBooleanValue(true);
+
+ simpleClassTwoB = factory.newSimpleClassTwo();
+ simpleClassTwoB.setText("B");
+
+ sqlDataClass.setSimpleClassTwo(simpleClassTwoA);
+
+ // NumericClasses
+ // standard min types
+ pve2 = factory.newPrimitiveValuedEntity();
+ LOG.info( "Bits to represent Double: " + Double.SIZE);
+ pve2.setIntProperty(Data.intMinValue);
+ pve2.setShortProperty(Data.shortMinValue);
+ pve2.setLongProperty(Data.longMinValue);
+ pve2.setDoubleProperty(Data.doubleMinValue);
+ pve2.setFloatProperty(Data.floatMinValue);
+ pve2.setCharProperty((char) (32)); // temporary work around: See ISIS-269
+
+ sqlDataClass.setPrimitiveValuedEntityMin(pve2);
+
+ // standard max types
+ pve1 = factory.newPrimitiveValuedEntity();
+ pve1.setIntProperty(Data.intMaxValue);
+ pve1.setShortProperty(Data.shortMaxValue);
+ pve1.setLongProperty(Data.longMaxValue);
+ pve1.setDoubleProperty(Data.doubleMaxValue);
+ pve1.setFloatProperty(Data.floatMaxValue);
+ pve1.setCharProperty((char) (255));
+
+ sqlDataClass.setPrimitiveValuedEntityMax(pve1);
+
+ // Initialise collection1
+ boolean bMustAdd = false;
+ if (simpleClassList1.size() == 0) {
+ bMustAdd = true;
+ }
+ for (final String string : Data.stringList1) {
+ final SimpleClass simpleClass = factory.newSimpleClass();
+ simpleClass.setString(string);
+ simpleClass.setSimpleClassTwoA(simpleClassTwoA);
+ sqlDataClass.addToSimpleClasses1(simpleClass);
+ if (bMustAdd) {
+ simpleClassList1.add(simpleClass);
+ }
+ }
+
+ // Initialise collection2
+ for (final String string : Data.stringList2) {
+ final SimpleClass simpleClass = factory.newSimpleClass();
+ simpleClass.setString(string);
+ simpleClass.setSimpleClassTwoA(simpleClassTwoB);
+ sqlDataClass.addToSimpleClasses2(simpleClass);
+ if (bMustAdd) {
+ simpleClassList2.add(simpleClass);
+ }
+ }
+
+ // Initialise Image
+ Image image = new Image(new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } });
+ sqlDataClass.setImage(image);
+
+ // Save
+ factory.save(sqlDataClass);
+
+ setFixtureInitializationState(State.DONT_INITIALIZE, "in-memory");
+ }
+
+ /**
+ * The actual "tests". Unless the test is using the "in-memory" object store
+ * the Isis framework is re-created, thus ensuring that no domain objects are
+ * left over from the previous "create" step, forcing the objects to be created
+ * via the object store.
+ *
+ * Exercises the "restore data" portion of the object store.
+ *
+ * Confirms that values and objects (single and collections) are loaded as expected.
+ * Especially, it confirms that dates, times, etc, do not suffer from differences in
+ * time zones between the database and the Isis framework.
+ */
+ @Test
+ public void testTestAll() throws Exception {
+
+ testLoad();
+
+ setUpFactory();
+
+ testString();
+ setStringToDifferentValue();
+ testSimpleClassCollection1Lazy();
+
+ testMoney();
+ testColor();
+ testPassword();
+ testPercentage();
+
+ testImage();
+
+ testStandardValueTypesMaxima();
+ testStandardValueTypesMinima();
+
+ testSingleReferenceLazy();
+ testSimpleClassTwoReferenceLazy();
+
+ testSimpleClassCollection1();
+ testSimpleClassCollection2();
+
+ testSingleReferenceResolve();
+ testSimpleClassTwoReferenceResolve();
+ testSimpleClassTwo();
+ testUpdate1();
+ testUpdate2();
+ testUpdateCollectionIsDirty();
+ testFindByMatchString();
+ testFindByMatchEntity();
+
+ testApplibDate();
+ testSqlDate();
+ testTime();
+ testTimeStamp();
+ testDateTimezoneIssue();
+ testDateTime();
+
+ // Test LIMIT statement
+ testLimitCount();
+
+ // Must be here so that the Isis framework is initialised for the next test package.
+ setFixtureInitializationState(State.INITIALIZE);
+ }
+
+ private void testLoad() throws Exception {
+ final List<SqlDataClass> dataClasses = factory.allDataClasses();
+ IsisContext.getTransactionManager().flushTransaction();
+
+ assertEquals(1, dataClasses.size());
+ final SqlDataClass sqlDataClass = dataClasses.get(0);
+ getSqlIntegrationTestFixtures().setSqlDataClass(sqlDataClass);
+
+ setFixtureInitializationState(State.DONT_INITIALIZE);
+ }
+
+ private void testString() {
+ assertEquals("Test String", sqlDataClass.getString());
+ }
+
+ private void setStringToDifferentValue() {
+ sqlDataClass.setString("String 2");
+ }
+
+ private void testSimpleClassCollection1Lazy() {
+ final List<SimpleClass> collection = sqlDataClass.simpleClasses1;
+
+ assertEquals("collection size is not equal!", collection.size(), simpleClassList1.size());
+ }
+
+ /**
+ * Test {@link SqlDataClass} {@link Date} field.
+ *
+ * @throws Exception
+ */
+ private void testApplibDate() {
+
+ LOG.info("Test: testDate() '2010-3-5' = 1267747200000");
+
+ // 2010-3-5 = 1267747200000
+ LOG.info( "applibDate.dateValue() as String: " + Data.applibDate);
+ LOG.info( "applibDate.dateValue() as Long: " + Data.applibDate.getMillisSinceEpoch());
+
+ // 2010-3-5 = 1267747200000
+ LOG.info( "sqlDataClass.getDate() as String: " + sqlDataClass.getDate());
+ LOG.info( "sqlDataClass.getDate().getTime() as Long: " + sqlDataClass.getDate().getMillisSinceEpoch());
+
+ if (!Data.applibDate.isEqualTo(sqlDataClass.getDate())) {
+ fail("Applib date: Test '2010-3-5', expected " + Data.applibDate.toString() + ", but got "
+ + sqlDataClass.getDate().toString() + ". Check log for more info.");
+ } else {
+ // LOG.log(Level.INFO,
+ // "SQL applib.value.date: test passed! Woohoo!");
+ }
+
+ }
+
+ /**
+ * Test {@link SqlDataClass} {@link java.sql.Date} field.
+ *
+ * @throws Exception
+ */
+ private void testSqlDate() {
+
+ LOG.info( "Test: testSqlDate() '2011-4-8' == 1302220800000");
+
+ // 2011-4-8 = 1302220800000
+ LOG.info( "sqlDate.toString() as String:" + Data.sqlDate); // shows
+ // as
+ // 2011-04-07
+ LOG.info( "sqlDate.getTime() as Long:" + Data.sqlDate.getTime());
+
+ // 2011-4-8 = 1302220800000
+ LOG.info( "sqlDataClass.getSqlDate() as String:" + sqlDataClass.getSqlDate()); // shows
+ // as
+ // 2011-04-07
+ LOG.info( "sqlDataClass.getSqlDate().getTime() as Long:" + sqlDataClass.getSqlDate().getTime());
+
+ if (Data.sqlDate.compareTo(sqlDataClass.getSqlDate()) != 0) {
+ fail("SQL date: Test '2011-4-8', expected " + Data.sqlDate.toString() + ", but got "
+ + sqlDataClass.getSqlDate().toString() + ". Check log for more info.");
+ } else {
+ // LOG.log(Level.INFO, "SQL date: test passed! Woohoo!");
+ }
+
+ }/**/
+
+ private void testDateTimezoneIssue() {
+ /*
+ * At the moment, applib Date and java.sql.Date are restored from ValueSemanticsProviderAbstractTemporal with an
+ * explicit hourly offset that comes from the timezone. I.e. in South Africa, with TZ +2h00, they have an
+ * implicit time of 02h00 (2AM). This can potentially seriously screw up GMT-X dates, which, I suspect, will
+ * actually be set to the dat BEFORE.
+ *
+ * This test is a simple test to confirm that date/time before and after checks work as expected.
+ */
+
+ DateTime dateTime = sqlDataClass.getDateTime(); // new DateTime(2010, 3, 5, 1, 23);
+ Date date = sqlDataClass.getDate(); // new Date(2010, 3, 5);
+
+ // java.sql.Date sqlDate = sqlDataClass.getSqlDate(); // "2010-03-05"
+ // assertTrue("dateTime's value (" + dateTime.dateValue() + ") should be after java.sql.date's (" + sqlDate +
+ // ")",
+ // dateTime.dateValue().after(sqlDate));
+
+ assertTrue("dateTime's value (" + dateTime.dateValue() + ") should be after date's (" + date + ")", dateTime
+ .dateValue().after(date.dateValue()));
+
+ }
+
+ /**
+ * Test {@link Money} type.
+ */
+ private void testMoney() {
+ assertEquals(Data.money, sqlDataClass.getMoney());
+ }
+
+ /**
+ * Test {@link DateTime} type.
+ */
+ private void testDateTime() {
+
+ LOG.info( "Test: testDateTime()");
+ LOG.info( "sqlDataClass.getDateTime() as String:" + sqlDataClass.getDateTime());
+ LOG.info( "dateTime.toString() as String:" + Data.dateTime);
+
+ LOG.info( "sqlDataClass.getDateTime().getTime() as Long:"
+ + sqlDataClass.getDateTime().millisSinceEpoch());
+ LOG.info( "dateTime.getTime() as Long:" + Data.dateTime.millisSinceEpoch());
+
+ if (!Data.dateTime.equals(sqlDataClass.getDateTime())) {
+ fail("DateTime " + Data.dateTime.toString() + " is not expected " + sqlDataClass.getDateTime().toString());
+ }
+ }
+
+ /**
+ * Test {@link TimeStamp} type.
+ */
+ private void testTimeStamp() {
+ assertTrue(
+ "TimeStamp " + sqlDataClass.getTimeStamp().toString() + " does not equal expected "
+ + Data.timeStamp.toString(), Data.timeStamp.isEqualTo(sqlDataClass.getTimeStamp()));
+ }
+
+ /**
+ * Test {@link Time} type.
+ */
+ /**/
+ private void testTime() {
+ assertNotNull("sqlDataClass is null", sqlDataClass);
+ assertNotNull("getTime() is null", sqlDataClass.getTime());
+ assertTrue("Time 14h56: expected " + Data.time.toString() + ", but got " + sqlDataClass.getTime().toString(),
+ Data.time.isEqualTo(sqlDataClass.getTime()));
+ }
+
+ /**
+ * Test {@link Color} type.
+ */
+ private void testColor() {
+ assertEquals(Data.color, sqlDataClass.getColor());
+ }
+
+ /**
+ * Test {@link Image} type.
+ */
+ private void testImage() {
+ Image image1 = new Image(new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } });
+ Image image2 = sqlDataClass.getImage();
+ // REVIEW: Only XML persistor fails here...
+ if (!persistenceMechanismIs("xml")) {
+ assertImagesEqual(image1, image2);
+ }
+ }
+
+ private void assertImagesEqual(Image image2, Image image3) {
+ assertEquals(image2.getHeight(), image3.getHeight());
+ assertEquals(image2.getWidth(), image3.getWidth());
+ boolean same = true;
+ int i = 0, j = 0;
+ int p1 = 0, p2 = 0;
+ String error = "";
+ int[][] i1 = image2.getImage(), i2 = image3.getImage();
+ for (i = 0; same && i < image2.getHeight(); i++) {
+ int[] r1 = i1[i], r2 = i2[i];
+ for (j = 0; same && j < image2.getWidth(); j++) {
+ p1 = r1[j];
+ p2 = r2[j];
+ if (p1 != p2) {
+ same = false;
+ error = "Images differ at i = " + i + ", j = " + j + ", " + p1 + " is not " + p2 + "!";
+ break;
+ }
+ }
+ }
+ assertTrue(error, same);
+ }
+
+ /**
+ * Test {@link Password} type.
+ */
+ private void testPassword() {
+ assertEquals(Data.password, sqlDataClass.getPassword());
+ }
+
+ /**
+ * Test {@link Percentage} type.
+ */
+ private void testPercentage() {
+ assertEquals(Data.percentage, sqlDataClass.getPercentage());
+ }
+
+ private void testStandardValueTypesMaxima() {
+ final PrimitiveValuedEntity pveMax = sqlDataClass.getPrimitiveValuedEntityMax();
+
+ assertEquals(Data.shortMaxValue, pveMax.getShortProperty());
+ assertEquals(Data.intMaxValue, pveMax.getIntProperty());
+ assertEquals(Data.longMaxValue, pveMax.getLongProperty());
+ assertEquals(Data.doubleMaxValue, pveMax.getDoubleProperty(), 0.00001f); // fails
+ // in
+ assertEquals(Data.floatMaxValue, pveMax.getFloatProperty(), 0.00001f);
+ }
+
+ private void testStandardValueTypesMinima() {
+ final PrimitiveValuedEntity pveMin = sqlDataClass.getPrimitiveValuedEntityMin();
+
+ assertEquals(Data.shortMinValue, pveMin.getShortProperty());
+ assertEquals(Data.intMinValue, pveMin.getIntProperty());
+ assertEquals(Data.longMinValue, pveMin.getLongProperty());
+ assertEquals(Data.doubleMinValue, pveMin.getDoubleProperty(), 0.00001f); // fails
+ // in
+ // MySQL
+ // =
+ // infinity
+ assertEquals(Data.floatMinValue, pveMin.getFloatProperty(), 0.00001f);
+ }
+
+ /**
+ * Test {@link StringCollection} type.
+ */
+ /*
+ * public void testStringCollection(){ SqlDataClass sqlDataClass = SqlIntegrationTestSingleton.getPerson();
+ * List<String> collection = sqlDataClass.getStringCollection(); int i = 0; for (String string : collection) {
+ * assertEquals(SqlIntegrationTestCommon.stringList.get(i++), string); } }
+ */
+
+ private void testSingleReferenceLazy() {
+ final SimpleClassTwo a = sqlDataClass.getSimpleClassTwo();
+ if (!persistenceMechanismIs("in-memory")) {
+ assertEquals(null, a.text); // must check direct value, as
+ // framework can auto-resolve, if you use getText()
+ }
+ }
+
+ /**
+ * Test a collection of {@link SimpleClass} type.
+ */
+ private void testSimpleClassCollection1() {
+ final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
+
+ assertEquals("collection size is not equal!", simpleClassList1.size(), collection.size());
+
+ int i = 0;
+ for (final SimpleClass simpleClass : simpleClassList1) {
+ assertEquals(simpleClass.getString(), collection.get(i++).getString());
+ }
+ }
+
+ /**
+ * Test another collection of {@link SimpleClass} type.
+ */
+ private void testSimpleClassCollection2() {
+ final List<SimpleClass> collection = sqlDataClass.getSimpleClasses2();
+
+ assertEquals("collection size is not equal!", simpleClassList2.size(), collection.size());
+
+ int i = 0;
+ for (final SimpleClass simpleClass : simpleClassList2) {
+ assertEquals(simpleClass.getString(), collection.get(i++).getString());
+ }
+ }
+
+ private void testSimpleClassTwoReferenceLazy() {
+ final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
+ if (getProperties().getProperty("isis.persistor") != "in-memory") {
+ for (final SimpleClass simpleClass : collection) {
+ final SimpleClassTwo a = simpleClass.getSimpleClassTwoA();
+ assertEquals(null, a.text); // must check direct value, as
+ // framework can auto-resolve, if
+ // you use getText()
+ }
+ }
+ }
+
+ private void testSingleReferenceResolve() {
+ final SimpleClassTwo a = sqlDataClass.getSimpleClassTwo();
+ factory.resolve(a);
+ assertEquals(simpleClassTwoA.getText(), a.getText());
+ }
+
+ private void testSimpleClassTwoReferenceResolve() {
+ final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
+ for (final SimpleClass simpleClass : collection) {
+ final SimpleClassTwo a = simpleClass.getSimpleClassTwoA();
+ factory.resolve(a);
+ assertEquals(simpleClassTwoA.getText(), a.getText());
+ assertEquals(simpleClassTwoA.getIntValue(), a.getIntValue());
+ assertEquals(simpleClassTwoA.getBooleanValue(), a.getBooleanValue());
+ }
+ }
+
+ private void testSimpleClassTwo() {
+ final SqlDomainObjectRepository factory = getSqlIntegrationTestFixtures().getSqlDataClassFactory();
+ final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
+ assertEquals(2, classes.size());
+ for (final SimpleClassTwo simpleClass : classes) {
+ // assertEquals(simpleClassTwoA.getText(), simpleClass.getText());
+ assertTrue("AB".contains(simpleClass.getText()));
+ }
+ }
+
+ private void testUpdate1() {
+ final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
+ assertEquals(2, classes.size());
+
+ final SimpleClassTwo simpleClass = classes.get(0);
+ simpleClass.setText("XXX");
+ simpleClass.setBooleanValue(false);
+ simpleClassTwoA.setBooleanValue(false);
+
+ setFixtureInitializationStateIfNot(State.INITIALIZE, "in-memory");
+ }
+
+ private void testUpdate2() {
+ final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
+ assertEquals(2, classes.size());
+
+ final SimpleClassTwo simpleClass = classes.get(0);
+ assertEquals("XXX", simpleClass.getText());
+ assertEquals(simpleClassTwoA.getBooleanValue(), simpleClass.getBooleanValue());
+
+ setFixtureInitializationState(State.DONT_INITIALIZE);
+ }
+
+ private void testUpdateCollectionIsDirty() {
+
+ final List<SqlDataClass> sqlDataClasses = factory.allDataClasses();
+ final SqlDataClass sqlDataClass = sqlDataClasses.get(0);
+
+ final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
+ final SimpleClass simpleClass1 = collection.get(0);
+
+ collection.remove(simpleClass1);
+
+ // REVIEW: I'm very doubtful about this...
+ // what exactly is meant by updating an internal collection?
+ if (!persistenceMechanismIs("xml")) {
+ factory.update(collection);
+ }
+
+ factory.update(sqlDataClass);
+ }
+
+ private void testLimitCount() {
+ final List<SimpleClass> subset = factory.someSimpleClasses(0, 2);
+ assertEquals(2, subset.size());
+ // TODO: This test does not confirm that the *right* 2 were returned.
+ }
+
+ private void testFindByMatchString() {
+ final SimpleClass simpleClassMatch = new SimpleClass();
+ simpleClassMatch.setString(Data.stringList1.get(1));
+
+ final List<SimpleClass> classes = factory.allSimpleClassesThatMatch(simpleClassMatch);
+ assertEquals(1, classes.size());
+
+ }
+
+ private void testFindByMatchEntity() {
+ final List<SimpleClassTwo> classTwos = factory.allSimpleClassTwos();
+
+ final SimpleClass simpleClassMatch = new SimpleClass();
+ simpleClassMatch.setSimpleClassTwoA(classTwos.get(0));
+
+ final List<SimpleClass> classes = factory.allSimpleClassesThatMatch(simpleClassMatch);
+
+ // TODO: Why is this hack required?
+ if (!getProperties().getProperty("isis.persistor").equals("in-memory")) {
+ assertEquals(Data.stringList1.size(), classes.size());
+ } else {
+ assertEquals(Data.stringList1.size() + 2, classes.size());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestFixtures.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestFixtures.java b/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestFixtures.java
new file mode 100644
index 0000000..ada7051
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestFixtures.java
@@ -0,0 +1,230 @@
+/*
+ * 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.isis.objectstore.sql.common;
+
+import java.io.FileInputStream;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures.Fixtures.Initialization;
+import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
+import org.apache.isis.core.tck.dom.poly.ReferencingPolyTypesEntity;
+import org.apache.isis.core.tck.dom.scalars.PrimitiveValuedEntity;
+import org.apache.isis.core.tck.dom.sqlos.SqlDomainObjectRepository;
+import org.apache.isis.core.tck.dom.sqlos.data.SimpleClass;
+import org.apache.isis.core.tck.dom.sqlos.data.SimpleClassTwo;
+import org.apache.isis.core.tck.dom.sqlos.data.SqlDataClass;
+import org.apache.isis.objectstore.sql.SqlObjectStore;
+
+/**
+ * @author Kevin
+ *
+ */
+public class SqlIntegrationTestFixtures {
+
+ static SqlIntegrationTestFixtures instance;
+
+ public static SqlIntegrationTestFixtures getInstance() {
+ if (instance == null) {
+ instance = new SqlIntegrationTestFixtures();
+ }
+ return instance;
+ }
+
+ public static void recreate() {
+ instance = new SqlIntegrationTestFixtures();
+ }
+
+ public enum State {
+ INITIALIZE, DONT_INITIALIZE;
+
+ public boolean isInitialize() {
+ return this == INITIALIZE;
+ }
+ }
+
+ private State state = State.INITIALIZE;
+
+ public State getState() {
+ return state;
+ }
+
+ public void setState(final State state) {
+ this.state = state;
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ //
+ // /////////////////////////////////////////////////////////////////////////
+
+ private IsisSystemWithFixtures system;
+
+ // JDBC
+ private Connection conn = null;
+ private Statement stmt = null;
+
+ public void initSystem(final String propertiesDirectory, final String propertiesFileName) throws Exception {
+
+ final Properties properties = new Properties();
+ properties.load(new FileInputStream(propertiesDirectory + "/" + propertiesFileName));
+
+ initSystem(properties);
+ }
+
+ public void initSystem(final Properties properties) throws Exception {
+ final IsisConfigurationDefault configuration = new IsisConfigurationDefault();
+ configuration.add(properties);
+
+ sqlDomainObjectRepository = new SqlDomainObjectRepository();
+ if (system != null) {
+ system.tearDownSystem();
+ }
+
+ final PersistenceMechanismInstallerAbstract persistorInstaller = Utils.createPersistorInstaller(configuration);
+ system =
+ IsisSystemWithFixtures.builder().with(configuration).withServices(sqlDomainObjectRepository)
+ .with(Initialization.NO_INIT).with(persistorInstaller).build();
+
+ system.setUpSystem();
+
+ registerDriverAndConnect(configuration);
+ }
+
+ public void shutDown() throws Exception {
+ if (system != null) {
+ system.tearDownSystem();
+ }
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ //
+ // /////////////////////////////////////////////////////////////////////////
+
+ @SuppressWarnings("unchecked")
+ private void registerDriverAndConnect(final IsisConfiguration isisConfiguration) throws SQLException,
+ ClassNotFoundException, InstantiationException, IllegalAccessException {
+ final String jdbcClassName = isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.driver");
+ if (jdbcClassName == null) {
+ conn = null;
+ stmt = null;
+ return;
+ }
+ final Class<Driver> driverClass = (Class<Driver>) Class.forName(jdbcClassName);
+ final Driver driver = driverClass.newInstance();
+ DriverManager.registerDriver(driver);
+
+ // jdbc - connect to DB and drop tables.
+ conn =
+ DriverManager.getConnection(isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.connection"),
+ isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.user"),
+ isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.password"));
+ stmt = conn.createStatement();
+ }
+
+ public void dropTable(final String tableName) {
+ if (stmt == null) {
+ if (tableName.equalsIgnoreCase("sqldataclass")) {
+ final List<SqlDataClass> list = sqlDomainObjectRepository.allDataClasses();
+ for (final SqlDataClass sqlDataClass : list) {
+ sqlDomainObjectRepository.delete(sqlDataClass);
+ }
+ return;
+ }
+ if (tableName.equalsIgnoreCase("simpleclass")) {
+ final List<SimpleClass> list = sqlDomainObjectRepository.allSimpleClasses();
+ for (final SimpleClass sqlClass : list) {
+ sqlDomainObjectRepository.delete(sqlClass);
+ }
+ return;
+ }
+ if (tableName.equalsIgnoreCase("simpleclasstwo")) {
+ final List<SimpleClassTwo> list = sqlDomainObjectRepository.allSimpleClassTwos();
+ for (final SimpleClassTwo sqlClass : list) {
+ sqlDomainObjectRepository.delete(sqlClass);
+ }
+ return;
+ }
+ if (tableName.equalsIgnoreCase("primitivevaluedentity")) {
+ final List<PrimitiveValuedEntity> list = sqlDomainObjectRepository.allPrimitiveValueEntities();
+ for (final PrimitiveValuedEntity pve : list) {
+ sqlDomainObjectRepository.delete(pve);
+ }
+ return;
+ }
+ throw new IsisException("Unknown table: " + tableName);
+ }
+
+ try {
+ String tableIdentifier = Utils.tableIdentifierFor(tableName);
+ stmt.executeUpdate("DROP TABLE " + tableIdentifier);
+ } catch (final SQLException e) {
+ // this can happen, not a problem.
+ // e.printStackTrace();
+ }
+ }
+
+ public void sqlExecute(final String sqlString) throws SQLException {
+ if (stmt != null) {
+ stmt.executeUpdate(sqlString);
+ }
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ //
+ // /////////////////////////////////////////////////////////////////////////
+
+ private SqlDomainObjectRepository sqlDomainObjectRepository = null;
+
+ private SqlDataClass sqlDataClass;
+ private ReferencingPolyTypesEntity referencingPolyTypesEntity;
+
+ public SqlDomainObjectRepository getSqlDataClassFactory() {
+ return sqlDomainObjectRepository;
+ }
+
+ public SqlDataClass getSqlDataClass() {
+ return sqlDataClass;
+ }
+
+ public void setSqlDataClass(SqlDataClass sqlDataClass) {
+ this.sqlDataClass = sqlDataClass;
+ }
+
+ public ReferencingPolyTypesEntity getPolyTestClass() {
+ return referencingPolyTypesEntity;
+ }
+
+ public void setPolyTestClass(final ReferencingPolyTypesEntity referencingPolyTypesEntity) {
+ this.referencingPolyTypesEntity = referencingPolyTypesEntity;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Utils.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Utils.java b/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Utils.java
new file mode 100644
index 0000000..c037e61
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Utils.java
@@ -0,0 +1,61 @@
+/*
+ * 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.isis.objectstore.sql.common;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.objectstore.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.SqlObjectStore;
+import org.apache.isis.objectstore.sql.SqlPersistorInstaller;
+import org.apache.isis.objectstore.xml.XmlPersistenceMechanismInstaller;
+
+public class Utils {
+
+ static PersistenceMechanismInstallerAbstract createPersistorInstaller(final IsisConfiguration configuration) {
+
+ final String jdbcDriver = configuration.getString(SqlObjectStore.BASE_NAME + ".jdbc.driver");
+ if (jdbcDriver != null) {
+ return new SqlPersistorInstaller();
+ }
+
+ final String persistor = configuration.getString("isis.persistor");
+ if (persistor.equals(InMemoryPersistenceMechanismInstaller.NAME)) {
+ return new InMemoryPersistenceMechanismInstaller();
+ }
+ if (persistor.equals(XmlPersistenceMechanismInstaller.NAME)) {
+ return new XmlPersistenceMechanismInstaller();
+ }
+ if (persistor.equals(SqlPersistorInstaller.NAME)) {
+ return new SqlPersistorInstaller();
+ }
+ return new InMemoryPersistenceMechanismInstaller();
+ }
+
+ static String tableIdentifierFor(final String tableName) {
+ if (tableName.substring(0, 4).toUpperCase().equals("ISIS")) {
+ return Sql.tableIdentifier(tableName);
+ } else {
+ return Sql.tableIdentifier("isis_" + tableName);
+ }
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties b/mothballed/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties
new file mode 100644
index 0000000..b36337f
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties
@@ -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.
+# apache's log4j is used to provide system logging.
+log4j.rootCategory=DEBUG, File
+log4j.rootCategory=INFO, Console
+
+
+# The console appender
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.target=System.out
+log4j.appender.Console.layout=org.apache.log4j.PatternLayout
+log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} [%-20c{1} %-10t %-5p] %m%n
+
+
+log4j.appender.File=org.apache.log4j.RollingFileAppender
+log4j.appender.File.file=isis.log
+log4j.appender.File.append=false
+#log4j.appender.File.maxFileSize=500KB
+#log4j.appender.File.maxBackupIndex=1
+log4j.appender.File.layout=org.apache.log4j.PatternLayout
+log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
+
+
+
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt b/mothballed/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt
new file mode 100644
index 0000000..025703e
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt
@@ -0,0 +1,28 @@
+~~ 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.
+
+
+
+SQL ObjectStore Integration Tests
+
+ This module holds the integration tests for the {{{../index.html}SQL ObjectStore}}.
+
+Further Info
+
+ See this module's {{{./apidocs/index.html}Javadoc}} and {{{../docbkx/html/guide/isis-sql-objectstore.html}User Guide}} for more information.
+
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt b/mothballed/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt
new file mode 100644
index 0000000..c5d1200
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt
@@ -0,0 +1,24 @@
+~~ 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.
+
+
+
+Jottings
+
+ This page is to capture any random jottings relating to this module prior
+ to being moved into formal documentation.
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/site/site.xml
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/site/site.xml b/mothballed/component/objectstore/sql/sql-tests-common/src/site/site.xml
new file mode 100644
index 0000000..9aa405b
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/site/site.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project>
+
+ <body>
+ <breadcrumbs>
+ <item name="Tests" href="index.html"/>
+ </breadcrumbs>
+
+ <menu name="SQL Objectstore Tests">
+ <item name="About" href="index.html" />
+ </menu>
+
+ <menu name="SQL OS Modules">
+ <item name="Implementation" href="../sql-impl/index.html" />
+ <item name="Tests" href="../sql-tests-common/index.html" />
+ <item name="Integration Tests" href="../sql-tests-served/index.html" />
+ </menu>
+
+ <menu name="Maven Reports" ref="reports" />
+ </body>
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties b/mothballed/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties
new file mode 100644
index 0000000..cd5ea6e
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties
@@ -0,0 +1,29 @@
+# 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.
+isis.persistor=sql
+
+isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver
+isis.persistor.sql.jdbc.connection=jdbc:hsqldb:file:hsql-db/polytests
+isis.persistor.sql.jdbc.user=sa
+isis.persistor.sql.jdbc.password=
+
+# testing
+isis.logging.objectstore=on
+isis.persistor.sql.default.command.beginTransaction=
+isis.persistor.sql.default.command.commitTransaction=
+isis.persistor.sql.default.command.abortTransaction=
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties b/mothballed/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties
new file mode 100644
index 0000000..22c9758
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties
@@ -0,0 +1,33 @@
+# 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.
+isis.persistor=sql
+
+isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver
+isis.persistor.sql.jdbc.connection=jdbc:hsqldb:file:hsql-db/tests
+isis.persistor.sql.jdbc.user=sa
+isis.persistor.sql.jdbc.password=
+
+# testing
+isis.persistor.sql.datatypes.string=VARCHAR(70)
+isis.persistor.sql.default.password.seed=gfkhgdf76453fhgj#$
+isis.persistor.sql.default.command.beginTransaction=
+isis.persistor.sql.default.command.commitTransaction=
+isis.persistor.sql.default.command.abortTransaction=
+
+isis.persistor.sql.datatypes.blob=BLOB(1000)
+
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java b/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java
new file mode 100644
index 0000000..17b9bfc
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+
+import org.apache.isis.core.unittestsupport.files.Files;
+import org.apache.isis.core.unittestsupport.files.Files.Recursion;
+import org.apache.isis.objectstore.sql.common.Data;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestData;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures;
+
+/**
+ * @author Kevin kevin@kmz.co.za
+ *
+ * This test implementation uses the HyperSQL database engine to perform "serverless" tests of data creation and
+ * reloading.
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class HsqlTest extends SqlIntegrationTestData {
+
+ @BeforeClass
+ public static void deleteHsqlDbFiles() {
+ Files.deleteFilesWithPrefix("hsql-db", "tests", Recursion.DONT_RECURSE);
+ }
+
+ @Override
+ protected void testCreate() throws Exception {
+ final SqlIntegrationTestFixtures sqlIntegrationTestFixtures = getSqlIntegrationTestFixtures();
+ for (final String tableName : Data.getTableNames()) {
+ sqlIntegrationTestFixtures.dropTable(tableName);
+ }
+ super.testCreate();
+ }
+
+ // @Override
+ // protected String getSqlSetupString() {
+ // return "COMMIT;";
+ // }
+
+ @Override
+ public String getPropertiesFilename() {
+ return "hsql.properties";
+ }
+
+ @Override
+ public String getSqlTeardownString() {
+ return "SHUTDOWN;";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java b/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java
new file mode 100755
index 0000000..49039e5
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java
@@ -0,0 +1,374 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.tck.dom.poly.Empty;
+import org.apache.isis.core.tck.dom.poly.EmptyEntityWithOwnProperty;
+import org.apache.isis.core.tck.dom.poly.ReferencingPolyTypesEntity;
+import org.apache.isis.core.tck.dom.poly.SelfReferencingEntity;
+import org.apache.isis.core.tck.dom.poly.StringBaseEntity;
+import org.apache.isis.core.tck.dom.poly.StringBaseEntitySub;
+import org.apache.isis.core.tck.dom.poly.StringBaseEntitySubThree;
+import org.apache.isis.core.tck.dom.poly.StringBaseEntitySubTwo;
+import org.apache.isis.core.tck.dom.poly.Stringable;
+import org.apache.isis.core.tck.dom.poly.StringableEntityWithOwnDerivedProperty;
+import org.apache.isis.core.tck.dom.poly.StringableEntityWithOwnProperties;
+import org.apache.isis.core.tck.dom.poly.StringableEntityWithOwnProperty;
+import org.apache.isis.core.unittestsupport.files.Files;
+import org.apache.isis.core.unittestsupport.files.Files.Recursion;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestCommonBase;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures.State;
+
+/**
+ * @author Kevin kevin@kmz.co.za
+ *
+ * This test implementation uses the HyperSQL database engine to perform "serverless" tests of polymorphic class
+ * object creation and reloading.
+ *
+ * The sql object store thus allows your domain objects to have properties referenced via interface or
+ * superclass. Both single reference properties and property collections are supported.
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class PolymorphismTest extends SqlIntegrationTestCommonBase {
+
+ private static final String IMPL_A_STRING = "Impl A String";
+ private static final String IMPL_B_STRING = "Impl B String";
+ private static final String CHILD_1 = "Child 1";
+
+ private static StringableEntityWithOwnProperty polyIntImpA;
+ private static StringableEntityWithOwnProperties polyIntImpB;
+
+ @Override
+ public String getPropertiesFilename() {
+ return "hsql-poly.properties";
+ }
+
+ @BeforeClass
+ public static void deleteHsqlDbFiles() {
+ Files.deleteFilesWithPrefix("hsql-db", "poly", Recursion.DONT_RECURSE);
+ }
+
+ @Override
+ public void resetPersistenceStoreDirectlyIfRequired() {
+ getSqlIntegrationTestFixtures();
+ }
+
+ @Override
+ public String getSqlTeardownString() {
+ return "SHUTDOWN;";
+ }
+
+ // Order is important. The next three "tests" must be executed in the correct sequential order.
+ @Test
+ /**
+ * Sets up the database connection and tells the test framework to create an instance of the
+ * Isis framework for the next "test".
+ */
+ public void test1SetupStoreAndDatabaseConnection() throws Exception {
+ testSetup();
+ }
+
+ @Before
+ public void setUpXactn() throws Exception {
+ IsisContext.getTransactionManager().startTransaction();
+ }
+
+ @After
+ public void tearDownXactn() throws Exception {
+ IsisContext.getTransactionManager().endTransaction();
+ assertThat(IsisContext.getTransactionManager().getTransaction().getState().isComplete(), is(true));
+
+ }
+
+ @Test
+ /**
+ * Uses the database connection to drop database tables related to these tests.
+ * This forces (and exercises the ability of) the object store to re-create the tables.
+ *
+ * Also uses factory methods within the Isis framework to create the test data,
+ * thus exercising the "create data" portion of the object store.
+ *
+ * The Isis framework will be again be re-created in the next test unless the
+ * object store is "in-memory" (this is required since "in-memory" has to be
+ * left alone for created data to still be present in the next test).
+ */
+ public void test2SetupDataWithDatabaseConnection() throws Exception {
+ final SqlIntegrationTestFixtures sqlIntegrationTestFixtures = getSqlIntegrationTestFixtures();
+ sqlIntegrationTestFixtures.dropTable("ISIS_SELFREFERENCINGENTITY");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGABLEENTITYWITHOWNPROPERTY");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGABLEENTITYWITHOWNPROPERTIES");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITYSUB");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITYSUBTWO");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITYSUBTHREE");
+ sqlIntegrationTestFixtures.dropTable("ISIS_REFERENCINGPOLYTYPESENTITY");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITY");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGABLE");
+
+ final ReferencingPolyTypesEntity referencingPolyTypesEntity = factory.newPolyTestClass();
+ referencingPolyTypesEntity.setString("polyTestClassString");
+
+ // Setup self-referencing collection
+ final SelfReferencingEntity polySelfRefClassParent = factory.newPolySelfRefClass();
+ polySelfRefClassParent.setString("Parent");
+
+ final SelfReferencingEntity polySelfRefClassChild1 = factory.newPolySelfRefClass();
+ polySelfRefClassChild1.setString(CHILD_1);
+ polySelfRefClassParent.addToPolySelfRefClasses(polySelfRefClassChild1);
+
+ final SelfReferencingEntity polySelfRefClassChild2 = factory.newPolySelfRefClass();
+ polySelfRefClassChild2.setString("Child 2");
+ polySelfRefClassParent.addToPolySelfRefClasses(polySelfRefClassChild2);
+ factory.save(polySelfRefClassChild2);
+
+ final SelfReferencingEntity polySelfRefClassChild3 = factory.newPolySelfRefClass();
+ polySelfRefClassChild3.setString("Child 1 of Child 1");
+ polySelfRefClassChild1.addToPolySelfRefClasses(polySelfRefClassChild3);
+
+ factory.save(polySelfRefClassChild3);
+ factory.save(polySelfRefClassChild1);
+
+ factory.save(polySelfRefClassParent);
+ referencingPolyTypesEntity.setPolySelfRefClass(polySelfRefClassParent);
+
+ // polyTestClass.setPolyTestInterface(polyTestClass);
+
+ polyIntImpA = factory.newPolyInterfaceImplA();
+ polyIntImpA.setString(IMPL_A_STRING);
+ polyIntImpA.setSpecial("special");
+ factory.save(polyIntImpA);
+
+ referencingPolyTypesEntity.setPolyInterfaceType(polyIntImpA);
+ referencingPolyTypesEntity.getPolyInterfaces().add(polyIntImpA);
+
+ // setup the polyTestClass
+ final StringBaseEntitySub stringBaseEntitySub = factory.newPolySubClassOne();
+ stringBaseEntitySub.setStringBase("PolySubClassOne 1");
+ stringBaseEntitySub.setStringClassOne("Class 1");
+
+ final StringBaseEntitySubTwo stringBaseEntitySubTwo = factory.newPolySubClassTwo();
+ stringBaseEntitySubTwo.setStringBase("PolySubClassTwo 1");
+ stringBaseEntitySubTwo.setStringClassTwo("Class 2");
+
+ final StringBaseEntitySubThree stringBaseEntitySubThree = factory.newPolySubClassThree();
+ stringBaseEntitySubThree.setStringBase("PolySubClassThree 1");
+ stringBaseEntitySubThree.setStringClassThree("Another String");
+ stringBaseEntitySubThree.setStringClassTwo("Class 3");
+
+ referencingPolyTypesEntity.getPolyBaseClasses().add(stringBaseEntitySub);
+ referencingPolyTypesEntity.getPolyBaseClasses().add(stringBaseEntitySubTwo);
+ referencingPolyTypesEntity.getPolyBaseClasses().add(stringBaseEntitySubThree);
+
+ factory.save(stringBaseEntitySub);
+ factory.save(stringBaseEntitySubTwo);
+ factory.save(stringBaseEntitySubThree);
+
+ // store it and step the state engine
+ factory.save(referencingPolyTypesEntity);
+
+ setFixtureInitializationState(State.DONT_INITIALIZE, "in-memory");
+ }
+
+ /**
+ * The actual "tests". Unless the test is using the "in-memory" object store
+ * the Isis framework is re-created, thus ensuring that no domain objects are
+ * left over from the previous "create" step, forcing the objects to be created
+ * via the object store.
+ *
+ * Exercises the "restore data" portion of the object store.
+ *
+ * Confirms that polymorphic classes are loaded as expected (via interface,
+ * via super-class, etc.)
+ */
+ @Test
+ public void test3All() throws Exception {
+ load();
+
+ setUpFactory();
+
+ polymorphicLoad();
+ interfaceLoad();
+ loadSelfReferencingCollection();
+ interfaceLoadProperty();
+ interfaceLoadCollection();
+ interfaceEditSave();
+ interfaceEditLoad();
+ allInterfacesInstancesLoaded();
+ interfacesLoadedByQuery();
+ interfacesLoadedByQuerySpecial();
+ findByMatchPartialEntity();
+ cannotFindByMatchWithWrongValue();
+
+ // Must be here so that the Isis framework is initialised for the next test package.
+ setFixtureInitializationState(State.INITIALIZE);
+ }
+
+ private void load() {
+ final List<ReferencingPolyTypesEntity> dataClasses = factory.allPolyTestClasses();
+ assertEquals(1, dataClasses.size());
+ final ReferencingPolyTypesEntity referencingPolyTypesEntity = dataClasses.get(0);
+
+ getSqlIntegrationTestFixtures().setPolyTestClass(referencingPolyTypesEntity);
+
+ setFixtureInitializationState(State.DONT_INITIALIZE);
+ }
+
+ private void polymorphicLoad() {
+ final List<StringBaseEntity> polyBaseClasses = referencingPolyTypesEntity.getPolyBaseClasses();
+ assertEquals(3, polyBaseClasses.size());
+
+ StringBaseEntity polyClassBase = polyBaseClasses.get(0);
+ assertTrue(polyClassBase instanceof StringBaseEntitySub);
+ assertEquals("PolySubClassOne 1", polyClassBase.getStringBase());
+ final StringBaseEntitySub stringBaseEntitySub = (StringBaseEntitySub) polyClassBase;
+ assertEquals("Class 1", stringBaseEntitySub.getStringClassOne());
+
+ polyClassBase = polyBaseClasses.get(1);
+ assertTrue(polyClassBase instanceof StringBaseEntitySubTwo);
+ final StringBaseEntitySubTwo stringBaseEntitySubTwo = (StringBaseEntitySubTwo) polyClassBase;
+ assertEquals("Class 2", stringBaseEntitySubTwo.getStringClassTwo());
+
+ polyClassBase = polyBaseClasses.get(2);
+ assertTrue(polyClassBase instanceof StringBaseEntitySubThree);
+ final StringBaseEntitySubThree stringBaseEntitySubThree = (StringBaseEntitySubThree) polyClassBase;
+ assertEquals("Class 3", stringBaseEntitySubThree.getStringClassTwo());
+ assertEquals("Another String", stringBaseEntitySubThree.getStringClassThree());
+ }
+
+ private void interfaceLoad() {
+ final Stringable loaded = referencingPolyTypesEntity.getPolyInterfaceType();
+ factory.resolve(loaded);
+ assertEquals(polyIntImpA.getString(), loaded.getString());
+ }
+
+ private void loadSelfReferencingCollection() {
+ final SelfReferencingEntity polySelfRefParent = referencingPolyTypesEntity.getPolySelfRefClass();
+ final List<SelfReferencingEntity> list = polySelfRefParent.getPolySelfRefClasses();
+ assertEquals(2, list.size());
+
+ SelfReferencingEntity polySelfRefChild1 = null;
+ for (final SelfReferencingEntity selfReferencingEntity : list) {
+ if (selfReferencingEntity.getString().equals(CHILD_1)) {
+ polySelfRefChild1 = selfReferencingEntity;
+ }
+ }
+ assertNotNull(polySelfRefChild1);
+
+ assertEquals(CHILD_1, polySelfRefChild1.title());
+
+ List<SelfReferencingEntity> list2 = polySelfRefChild1.getPolySelfRefClasses();
+ factory.resolve(polySelfRefChild1);
+ list2 = polySelfRefChild1.getPolySelfRefClasses();
+ assertEquals(1, list2.size());
+ }
+
+ private void interfaceLoadProperty() {
+ final Stringable loaded = referencingPolyTypesEntity.getPolyInterfaceType();
+ assertEquals(polyIntImpA.getString(), loaded.getString());
+ }
+
+ private void interfaceLoadCollection() {
+ final List<Stringable> list = referencingPolyTypesEntity.getPolyInterfaces();
+
+ assertEquals(1, list.size());
+ final Stringable loaded = list.get(0);
+
+ assertEquals(polyIntImpA.getString(), loaded.getString());
+ }
+
+ private void interfaceEditSave() {
+ polyIntImpB = factory.newPolyInterfaceImplB();
+ polyIntImpB.setString(IMPL_B_STRING);
+ polyIntImpB.setSpecial("special");
+ polyIntImpB.setInteger(1);
+
+ factory.save(polyIntImpB);
+
+ referencingPolyTypesEntity.setPolyInterfaceType(polyIntImpB);
+
+ setFixtureInitializationState(State.INITIALIZE);
+ }
+
+ private void interfaceEditLoad() {
+ load(); // reload data
+
+ final Stringable loaded = referencingPolyTypesEntity.getPolyInterfaceType();
+ assertEquals(polyIntImpB.getString(), loaded.getString());
+ }
+
+ private void allInterfacesInstancesLoaded() {
+ final List<Stringable> list = factory.allPolyInterfaces();
+ assertEquals(2, list.size());
+ }
+
+ private void interfacesLoadedByQuery() {
+ // PolyInterface query = polyIntImpA;
+
+ final StringableEntityWithOwnDerivedProperty query = new StringableEntityWithOwnDerivedProperty();
+ query.setString(IMPL_A_STRING);
+
+ final List<Stringable> list = factory.queryPolyInterfaces(query);
+ assertEquals(1, list.size());
+ }
+
+ private void interfacesLoadedByQuerySpecial() {
+
+ final StringableEntityWithOwnDerivedProperty query = new StringableEntityWithOwnDerivedProperty();
+
+ final List<Stringable> list = factory.queryPolyInterfaces(query);
+ assertEquals(2, list.size());
+ }
+
+ private void findByMatchPartialEntity() {
+ final Empty match = new EmptyEntityWithOwnProperty();
+ final List<Empty> matches = factory.allEmptyInterfacesThatMatch(match);
+ assertEquals(1, matches.size());
+
+ final Empty empty = matches.get(0);
+ final StringableEntityWithOwnProperties imp = (StringableEntityWithOwnProperties) empty;
+ assertEquals(IMPL_B_STRING, imp.getString());
+ }
+
+ private void cannotFindByMatchWithWrongValue() {
+ final StringableEntityWithOwnProperties match = new StringableEntityWithOwnProperties();
+ match.setInteger(0);
+ final List<Empty> matches = factory.allEmptyInterfacesThatMatch(match);
+ assertEquals(0, matches.size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/InMemoryPersistenceTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/InMemoryPersistenceTest.java b/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/InMemoryPersistenceTest.java
new file mode 100644
index 0000000..4885b77
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/InMemoryPersistenceTest.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.isis.objectstore.sql.crosscheck;
+
+import java.util.Properties;
+
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestData;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures.State;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class InMemoryPersistenceTest extends SqlIntegrationTestData {
+
+ @Override
+ public Properties getProperties() {
+ final Properties properties = new Properties();
+ properties.put("isis.persistor", "in-memory");
+ properties.put("isis.logging.objectstore", "off");
+ return properties;
+ }
+
+ @Override
+ protected void testSetup() {
+ resetPersistenceStoreDirectlyIfRequired();
+ SqlIntegrationTestFixtures.recreate();
+ try {
+ SqlIntegrationTestFixtures.getInstance().initSystem(getProperties());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ getSqlIntegrationTestFixtures().setState(State.INITIALIZE);
+ }
+
+ @Override
+ public String getPropertiesFilename() {
+ return "inmemory.properties";
+ }
+
+ @Override
+ public String getSqlTeardownString() {
+ return "SHUTDOWN;";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/XmlPersistenceTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/XmlPersistenceTest.java b/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/XmlPersistenceTest.java
new file mode 100644
index 0000000..1916a95
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/XmlPersistenceTest.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.isis.objectstore.sql.crosscheck;
+
+import java.util.Properties;
+
+import org.apache.isis.core.unittestsupport.files.Files;
+import org.apache.isis.core.unittestsupport.files.Files.Recursion;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestData;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures;
+import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures.State;
+
+public class XmlPersistenceTest extends SqlIntegrationTestData {
+
+ @Override
+ public void resetPersistenceStoreDirectlyIfRequired() {
+ Files.deleteFiles("xml/objects", ".xml", Recursion.DO_RECURSE);
+ }
+
+ @Override
+ protected void testSetup() {
+ resetPersistenceStoreDirectlyIfRequired();
+ SqlIntegrationTestFixtures.recreate();
+ try {
+ SqlIntegrationTestFixtures.getInstance().initSystem(getProperties());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ getSqlIntegrationTestFixtures().setState(State.INITIALIZE);
+ }
+
+ @Override
+ public Properties getProperties() {
+ final Properties properties = new Properties();
+ properties.put("isis.persistor", "xml");
+ properties.put("isis.logging.objectstore", "off");
+ return properties;
+ }
+
+ @Override
+ public String getPropertiesFilename() {
+ return "xml.properties";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-served/pom.xml
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-served/pom.xml b/mothballed/component/objectstore/sql/sql-tests-served/pom.xml
new file mode 100644
index 0000000..1fc1aef
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-served/pom.xml
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-sql</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>isis-objectstore-sql-tests-served</artifactId>
+
+ <name>Isis SQL ObjectStore Integration Tests - Served</name>
+
+ <properties>
+ <siteBaseDir>..</siteBaseDir>
+ <relativeUrl>sql-tests-served/</relativeUrl>
+
+ <postgresql.version>9.2-1002.jdbc4</postgresql.version>
+ <mysql.version>5.1.25</mysql.version>
+ </properties>
+
+ <!-- used in Site generation for relative references. -->
+ <url>http://isis.apache.org/${relativeUrl}</url>
+
+ <description>Runs the common tests against a few server implementations.
+Just add your server implementation to org.apache.isis.extensions.sql.objectstore</description>
+ <build>
+ <plugins>
+ <!-- TODO: currently set to ignore test failures -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <testFailureIgnore>true</testFailureIgnore>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>${maven-project-info-reports-plugin}</version>
+ <inherited>false</inherited>
+ <configuration>
+ <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <inherited>false</inherited>
+ <reports>
+ <report>dependency-management</report>
+ <report>dependencies</report>
+ <report>dependency-convergence</report>
+ <report>plugins</report>
+ <report>summary</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- SQL integration tests common -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>isis-objectstore-sql-tests-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- JDBC drivers -->
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>${postgresql.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>${mysql.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-runtime</artifactId>
+ </dependency>
+ <!-- Required for TestProxy -->
+ <!-- Isis defaults -->
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-objectstore</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-objectstore</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-bytecode-cglib</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+
+ <!-- Isis Object store -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>isis-objectstore-sql-impl</artifactId>
+ </dependency>
+
+ <!-- Test common -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>isis-objectstore-sql-tests-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>isis-objectstore-sql-tests-common</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+
+ <!-- Required to support the implemented servers -->
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
+ </dependencies>
+</project>
[06/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingLookup.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingLookup.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingLookup.java
new file mode 100644
index 0000000..32ca76c
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingLookup.java
@@ -0,0 +1,131 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.jdbc.JdbcGeneralValueMapper;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+import org.apache.isis.objectstore.sql.mapping.FieldMappingFactory;
+import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
+import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMappingFactory;
+
+public class FieldMappingLookup {
+ private static final Logger LOG = LoggerFactory.getLogger(FieldMappingLookup.class);
+ private final Map<ObjectSpecification, FieldMappingFactory> fieldMappings = new HashMap<ObjectSpecification, FieldMappingFactory>();
+ private final Map<ObjectSpecification, ObjectReferenceMappingFactory> referenceMappings = new HashMap<ObjectSpecification, ObjectReferenceMappingFactory>();
+ private FieldMappingFactory referenceFieldMappingfactory;
+ private ObjectReferenceMappingFactory objectReferenceMappingfactory;
+
+ public FieldMapping createMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ final ObjectSpecification spec = field.getSpecification();
+ FieldMappingFactory factory = fieldMappings.get(spec);
+ if (factory != null) {
+ return factory.createFieldMapping(object, field);
+ } else if (spec.isEncodeable()) {
+ factory = new JdbcGeneralValueMapper.Factory(Defaults.TYPE_DEFAULT());
+ addFieldMappingFactory(spec, factory);
+ return factory.createFieldMapping(object, field);
+ } else {// if (true /* TODO test for reference */) {
+ factory = referenceFieldMappingfactory;
+ addFieldMappingFactory(spec, factory);
+ return factory.createFieldMapping(object, field);
+ // } else {
+ // throw new IsisException("No mapper for " + spec +
+ // " (no default mapper)");
+ }
+ }
+
+ public ObjectReferenceMapping createMapping(final ObjectSpecification spec) {
+ return createMapping(spec.getShortIdentifier(), spec);
+ }
+
+ public ObjectReferenceMapping createMapping(final String columnName, final ObjectSpecification spec) {
+ ObjectReferenceMappingFactory factory = referenceMappings.get(spec);
+ if (factory != null) {
+ return factory.createReferenceMapping(columnName, spec);
+ } else if (spec.isEncodeable()) {
+ // TODO add generic encodeable mapping
+ throw new NotYetImplementedException();
+ } else {// if (true /* TODO test for reference */) {
+ factory = objectReferenceMappingfactory;
+ // add(spec, factory);
+ return factory.createReferenceMapping(columnName, spec); // TODO:
+ // here
+ // } else {
+ // throw new IsisException("No mapper for " + spec +
+ // " (no default mapper)");
+ }
+ }
+
+ public void addFieldMappingFactory(final Class<?> valueType, final FieldMappingFactory mapper) {
+ final ObjectSpecification spec = IsisContext.getSpecificationLoader().loadSpecification(valueType);
+ addFieldMappingFactory(spec, mapper);
+ }
+
+ private void addFieldMappingFactory(final ObjectSpecification specification, final FieldMappingFactory mapper) {
+ LOG.debug("add mapper " + mapper + " for " + specification);
+ fieldMappings.put(specification, mapper);
+ }
+
+ public void addReferenceMappingFactory(final ObjectSpecification specification, final ObjectReferenceMappingFactory mapper) {
+ LOG.debug("add mapper " + mapper + " for " + specification);
+ referenceMappings.put(specification, mapper);
+ }
+
+ public void init() {
+ // fieldMappingFactory.load(this);
+ }
+
+ public IdMapping createIdMapping() {
+ // TODO inject and use external factory
+ final IdMapping idMapping = new IdMapping();
+ idMapping.init();
+ return idMapping;
+ }
+
+ public VersionMapping createVersionMapping() {
+ // TODO inject and use external factory
+ final VersionMapping versionMapping = new VersionMapping();
+ versionMapping.init();
+ return versionMapping;
+ }
+
+ public void setReferenceFieldMappingFactory(final FieldMappingFactory referenceMappingfactory) {
+ this.referenceFieldMappingfactory = referenceMappingfactory;
+ }
+
+ public void setObjectReferenceMappingfactory(final ObjectReferenceMappingFactory objectReferenceMappingfactory) {
+ this.objectReferenceMappingfactory = objectReferenceMappingfactory;
+ }
+
+ public TitleMapping createTitleMapping() {
+ // TODO inject and use external factory
+ return new TitleMapping();
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMapping.java
new file mode 100644
index 0000000..544da36
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMapping.java
@@ -0,0 +1,40 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+
+public class IdMapping extends IdMappingAbstract {
+
+ public void init() {
+ String idColumn = null;
+ // idColumn = configParameters.getString(parameterBase + "id");
+ if (idColumn == null) {
+ idColumn = Defaults.getPkIdLabel();
+ }
+ setColumn(idColumn);
+ }
+
+ public void appendUpdateValues(final StringBuffer sql, final ObjectAdapter object) {
+ }
+
+ public void initializeField(final ObjectAdapter object, final Results rs) {
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMappingAbstract.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMappingAbstract.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMappingAbstract.java
new file mode 100644
index 0000000..8d6a2a4
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMappingAbstract.java
@@ -0,0 +1,112 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+
+public class IdMappingAbstract {
+ private String column;
+
+ protected void setColumn(final String column) {
+ this.column = Sql.identifier(column);
+ }
+
+ protected String getColumn() {
+ return column;
+ }
+
+ public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final RootOid oid) {
+ sql.append(column);
+ sql.append(" = ");
+ appendObjectId(connector, sql, oid);
+ }
+
+ public void appendObjectId(final DatabaseConnector connector, final StringBuffer sql, final RootOid oid) {
+ sql.append("?");
+ connector.addToQueryValues(primaryKey(oid));
+ }
+
+ public void appendCreateColumnDefinitions(final StringBuffer sql) {
+ sql.append(column);
+ sql.append(" ");
+ sql.append(Defaults.TYPE_PK() + " NOT NULL PRIMARY KEY");
+ }
+
+ public void appendColumnDefinitions(final StringBuffer sql) {
+ sql.append(column);
+ sql.append(" ");
+ sql.append(Defaults.TYPE_PK());
+ }
+
+ public void appendColumnNames(final StringBuffer sql) {
+ sql.append(column);
+ }
+
+ public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ if (object == null) {
+ sql.append("NULL");
+ } else {
+ appendObjectId(connector, sql, (RootOid) object.getOid());
+ // sql.append(connector.addToQueryValues(primaryKeyAsObject(object.getOid())));
+ }
+ }
+
+ public String primaryKey(final RootOid oid) {
+ return oid.getIdentifier();
+ }
+
+ public TypedOid recreateOid(final Results rs, final ObjectSpecification specification) {
+ final Object object = rs.getObject(column);
+ if (object == null) {
+ return null;
+ }
+ final int id = ((Integer) object).intValue();
+ return new RootOidDefault(specification.getSpecId(), "" + id, Oid.State.PERSISTENT);
+ }
+
+ protected ObjectAdapter getAdapter(final ObjectSpecification spec, final Oid oid) {
+ final ObjectAdapter adapter = getAdapterManager().getAdapterFor(oid);
+ if (adapter != null) {
+ return adapter;
+ }
+ // REVIEW: where the oid is a TypedOid, the following two lines could be replaced by
+ // getPersistenceSession().recreatePersistentAdapter(oid)
+ // is preferable, since then reuses the PojoRecreator impl defined within SqlPersistorInstaller
+ final Object recreatedPojo = spec.createObject();
+ return getPersistenceSession().mapRecreatedPojo(oid, recreatedPojo);
+ }
+
+ protected AdapterManager getAdapterManager() {
+ return getPersistenceSession().getAdapterManager();
+ }
+
+ protected PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MappingLookup.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MappingLookup.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MappingLookup.java
new file mode 100644
index 0000000..92a0af2
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MappingLookup.java
@@ -0,0 +1,26 @@
+/*
+ * 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.isis.objectstore.sql;
+
+public class MappingLookup {
+ // private ObjectMappingLookup classMappingLookup;
+ // private FieldMappingLookup fieldMappingLookup;
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MultipleResults.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MultipleResults.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MultipleResults.java
new file mode 100644
index 0000000..35dafe4
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MultipleResults.java
@@ -0,0 +1,24 @@
+/*
+ * 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.isis.objectstore.sql;
+
+public interface MultipleResults {
+ Results nextResults();
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMapping.java
new file mode 100644
index 0000000..64034e5
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMapping.java
@@ -0,0 +1,57 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.util.Vector;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByPattern;
+
+public interface ObjectMapping {
+ void createObject(DatabaseConnector connector, ObjectAdapter object);
+
+ void destroyObject(DatabaseConnector connector, ObjectAdapter object);
+
+ Vector<ObjectAdapter> getInstances(DatabaseConnector connector, ObjectSpecification spec, long startIndex, long rowCount);
+
+ Vector<ObjectAdapter> getInstances(DatabaseConnector connector, ObjectSpecification spec, String title, long startIndex, long rowCount);
+
+ Vector<ObjectAdapter> getInstances(DatabaseConnector connector, ObjectSpecification spec, PersistenceQueryFindByPattern query);
+
+ ObjectAdapter getObject(DatabaseConnector connector, TypedOid typedOid);
+
+ boolean hasInstances(DatabaseConnector connector, ObjectSpecification cls);
+
+ void resolve(DatabaseConnector connector, ObjectAdapter object);
+
+ void resolveCollection(DatabaseConnector connector, ObjectAdapter object, ObjectAssociation field);
+
+ void save(DatabaseConnector connector, ObjectAdapter object);
+
+ void shutdown();
+
+ void startup(DatabaseConnector connection, ObjectMappingLookup objectMapperLookup);
+
+ boolean saveCollection(DatabaseConnector connection, ObjectAdapter parent, String fieldName);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingFactory.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingFactory.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingFactory.java
new file mode 100644
index 0000000..0a5976b
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingFactory.java
@@ -0,0 +1,24 @@
+/*
+ * 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.isis.objectstore.sql;
+
+public interface ObjectMappingFactory {
+ ObjectMapping createMapper(String className, String propertiesBase, FieldMappingLookup fieldMapperLookup, ObjectMappingLookup objectMapperLookup);
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingLookup.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingLookup.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingLookup.java
new file mode 100644
index 0000000..3535b5f
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingLookup.java
@@ -0,0 +1,153 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.debug.DebuggableWithTitle;
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.commons.factory.InstanceCreationException;
+import org.apache.isis.core.commons.factory.InstanceUtil;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.Contributed;
+import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+
+public class ObjectMappingLookup implements DebuggableWithTitle {
+ private static final Logger LOG = LoggerFactory.getLogger(ObjectMappingLookup.class);
+ private DatabaseConnectorPool connectionPool;
+ private final Map<ObjectSpecification, ObjectMapping> mappings = new HashMap<ObjectSpecification, ObjectMapping>();
+ private ObjectMappingFactory objectMappingFactory;
+ private FieldMappingLookup fieldMappingLookup;
+
+ public ObjectMapping getMapping(final ObjectSpecification spec, final DatabaseConnector connection) {
+ String fullName = spec.getFullIdentifier();
+ ObjectMapping mapping = mappings.get(spec);
+ if (mapping == null) {
+ final String propertiesBase = SqlObjectStore.BASE_NAME + ".automapper.default";
+ mapping = objectMappingFactory.createMapper(fullName, propertiesBase, fieldMappingLookup, this);
+ add(spec, mapping, connection);
+ }
+ LOG.debug(" mapper for " + spec.getSingularName() + " -> " + mapping);
+ if (mapping == null) {
+ throw new IsisException("No mapper for " + spec + " (no default mapper)");
+ }
+ return mapping;
+ }
+
+ public ObjectMapping getMapping(final ObjectAdapter object, final DatabaseConnector connection) {
+ return getMapping(object.getSpecification(), connection);
+ }
+
+ public void setConnectionPool(final DatabaseConnectorPool connectionPool) {
+ this.connectionPool = connectionPool;
+ }
+
+ // / ???
+ public void setObjectMappingFactory(final ObjectMappingFactory mapperFactory) {
+ this.objectMappingFactory = mapperFactory;
+ }
+
+ public void setValueMappingLookup(final FieldMappingLookup fieldMappingLookup) {
+ this.fieldMappingLookup = fieldMappingLookup;
+ }
+
+ private void add(final String className, final ObjectMapping mapper) {
+ final ObjectSpecification spec = IsisContext.getSpecificationLoader().loadSpecification(className);
+ if (spec.getProperties(Contributed.EXCLUDED).size() == 0) {
+ throw new SqlObjectStoreException(spec.getFullIdentifier() + " has no fields to persist: " + spec);
+ }
+ add(spec, mapper, null);
+ }
+
+ public void add(final ObjectSpecification specification, final ObjectMapping mapper, DatabaseConnector connection) {
+ LOG.debug("add mapper " + mapper + " for " + specification);
+ if (connection == null) {
+ connection = connectionPool.acquire();
+ }
+ mapper.startup(connection, this);
+ connectionPool.release(connection);
+ mappings.put(specification, mapper);
+ }
+
+ public void init() {
+ fieldMappingLookup.init();
+
+ final String prefix = SqlObjectStore.BASE_NAME + ".mapper.";
+ final IsisConfiguration subset = IsisContext.getConfiguration().createSubset(prefix);
+ for (final String className : subset) {
+ final String value = subset.getString(className);
+
+ if (value.startsWith("auto.")) {
+ final String propertiesBase = SqlObjectStore.BASE_NAME + ".automapper." + value.substring(5) + ".";
+ add(className, objectMappingFactory.createMapper(className, propertiesBase, fieldMappingLookup, this));
+ } else if (value.trim().equals("auto")) {
+ final String propertiesBase = SqlObjectStore.BASE_NAME + ".automapper.default";
+ add(className, objectMappingFactory.createMapper(className, propertiesBase, fieldMappingLookup, this));
+ } else {
+ LOG.debug("mapper " + className + "=" + value);
+
+ try {
+ add(className, InstanceUtil.createInstance(value, ObjectMapping.class));
+ } catch (final ObjectPersistenceException ex) {
+ throw new InstanceCreationException("Failed to set up mapper for " + className, ex);
+ }
+ }
+ }
+ }
+
+ public void shutdown() {
+ for (final ObjectMapping mapping : mappings.values()) {
+ try {
+ mapping.shutdown();
+ } catch (final ObjectPersistenceException ex) {
+ LOG.error("Shutdown mapper " + mapping, ex);
+ }
+ }
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln("field mapping lookup", fieldMappingLookup);
+ debug.appendln("object mapping factory", objectMappingFactory);
+ debug.appendTitle("Mappings");
+ int i = 1;
+ for (final ObjectSpecification specification : mappings.keySet()) {
+ debug.appendln(i++ + ". " + specification.getShortIdentifier());
+ final ObjectMapping mapper = mappings.get(specification);
+ debug.indent();
+ debug.append(mapper);
+ debug.unindent();
+ }
+ }
+
+ @Override
+ public String debugTitle() {
+ return "Object Mapping Lookup";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Parameter.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Parameter.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Parameter.java
new file mode 100644
index 0000000..aa192ff
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Parameter.java
@@ -0,0 +1,30 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
+
+public interface Parameter {
+ void setupParameter(int parameter, StoredProcedure procedure) throws ObjectPersistenceException;
+
+ // String getRestoreString();
+
+ void retrieve(int parameter, StoredProcedure procedure) throws ObjectPersistenceException;
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Results.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Results.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Results.java
new file mode 100644
index 0000000..2361447
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Results.java
@@ -0,0 +1,63 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.io.InputStream;
+import java.sql.Time;
+import java.util.Calendar;
+import java.util.Date;
+
+public interface Results {
+
+ void close();
+
+ int getInt(String columnName);
+
+ long getLong(String columnName);
+
+ double getDouble(String columnName);
+
+ String getString(String columnName);
+
+ Float getFloat(String columnName);
+
+ Object getShort(String columnName);
+
+ Object getBoolean(String columnName);
+
+ boolean next();
+
+ Date getJavaDateOnly(String dateColumn);
+
+ Time getJavaTimeOnly(String timeColumn);
+
+ Date getJavaDateTime(String lastActivityDateColumn, Calendar calendar);
+
+ org.apache.isis.applib.value.Date getDate(String columnName);
+
+ org.apache.isis.applib.value.Time getTime(String columnName);
+
+ Object getObject(String column);
+
+ Object getAsType(String columnName, Class<?> clazz);
+
+ InputStream getStream(String column);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Sql.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Sql.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Sql.java
new file mode 100644
index 0000000..eb26a1f
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Sql.java
@@ -0,0 +1,108 @@
+/*
+ * 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.isis.objectstore.sql;
+
+/**
+ * SQL functions, commands, names that are database dependent
+ */
+public class Sql {
+ private Sql() {
+ }
+
+ private static SqlMetaData metadata;
+
+ // public static String timestamp = "CURRENT_TIMESTAMP";
+
+ public static void setMetaData(final SqlMetaData metadata) {
+ Sql.metadata = metadata;
+ }
+
+ public static String escapeAndQuoteValue(final String encodedString) {
+ if (encodedString == null || encodedString.equals("NULL")) {
+ return "NULL";
+ }
+ // StringBuffer buffer = new StringBuffer("'");
+ final StringBuffer buffer = new StringBuffer(metadata.getQuoteString());
+ for (int i = 0; i < encodedString.length(); i++) {
+ final char c = encodedString.charAt(i);
+ if (c == '\'') {
+ buffer.append("\\'");
+ } else if (c == '\\') {
+ buffer.append("\\\\");
+ } else {
+ buffer.append(c);
+ }
+ }
+ // buffer.append("'");
+ buffer.append(metadata.getQuoteString());
+ final String string = buffer.toString();
+ return string;
+ }
+
+ public static String sqlName(final String name) {
+ // TODO need to deal with non-ascii (ie unicode characters)
+ return name.replace(' ', '_').toLowerCase();
+
+ /*
+ * int length = name.length(); StringBuffer convertedName = new
+ * StringBuffer(length); for (int i = 0; i < length; i++) { char ch =
+ * name.charAt(i); if (ch == ' ') { i++; //ch = name.charAt(i);
+ * //Character.toUpperCase(ch); ch = '_'; } convertedName.append(ch); }
+ * return convertedName.toString();
+ */
+ }
+
+ public static String sqlFieldName(final String name) {
+ final int length = name.length();
+ final StringBuffer convertedName = new StringBuffer(length);
+ boolean lastWasLowerCase = false;
+ for (int i = 0; i < length; i++) {
+ final char ch = name.charAt(i);
+ if (Character.isUpperCase(ch)) {
+ if (lastWasLowerCase) {
+ convertedName.append('_');
+ }
+ lastWasLowerCase = false;
+ } else {
+ lastWasLowerCase = true;
+ }
+ convertedName.append(ch);
+ }
+ return sqlName(convertedName.toString());
+ }
+
+ public static String identifier(final String name) {
+ // return metadata.quoteIdentifier(name);
+ return tableIdentifier(name);
+ }
+
+ public static String tableIdentifier(final String name) {
+ if (metadata.isStoresMixedCaseIdentifiers()) {
+ return name;
+ } else if (metadata.isStoresLowerCaseIdentifiers()) {
+ return name.toLowerCase();
+ } else if (metadata.isStoresUpperCaseIdentifiers()) {
+ return name.toUpperCase();
+ } else {
+ throw new SqlObjectStoreException("No case preference set up: " + name);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlExecutionContext.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlExecutionContext.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlExecutionContext.java
new file mode 100644
index 0000000..63196ab
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlExecutionContext.java
@@ -0,0 +1,46 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
+import org.apache.isis.core.runtime.system.transaction.MessageBroker;
+import org.apache.isis.core.runtime.system.transaction.UpdateNotifier;
+
+public class SqlExecutionContext implements PersistenceCommandContext {
+ private final DatabaseConnector connection;
+
+ public SqlExecutionContext(final DatabaseConnector connection, final IsisTransactionManager transactionManager, final MessageBroker messageBroker, final UpdateNotifier updateNotifier) {
+ this.connection = connection;
+ }
+
+ public DatabaseConnector getConnection() {
+ return connection;
+ }
+
+ @Override
+ public void start() {
+ }
+
+ @Override
+ public void end() {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlIdentifierGenerator.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlIdentifierGenerator.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlIdentifierGenerator.java
new file mode 100644
index 0000000..f2ef52c
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlIdentifierGenerator.java
@@ -0,0 +1,148 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.ensure.Assert;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
+import org.apache.isis.core.runtime.system.persistence.IdentifierGenerator;
+
+public class SqlIdentifierGenerator implements IdentifierGenerator {
+
+ private final DatabaseConnectorPool connectionPool;
+ private final IdNumbers ids = new IdNumbers();
+
+ //////////////////////////////////////////////////////////////////
+ // constructor
+ //////////////////////////////////////////////////////////////////
+
+ public SqlIdentifierGenerator(final DatabaseConnectorPool connectionPool) {
+ this.connectionPool = connectionPool;
+ }
+
+ ///////////////////////////////////////////////////////
+ // API
+ ///////////////////////////////////////////////////////
+
+ @Override
+ public String createAggregateLocalId(ObjectSpecId objectSpecId, final Object pojo, final ObjectAdapter parentAdapter) {
+ throw new SqlObjectStoreException("Aggregated objects are not supported in this store");
+ }
+
+ @Override
+ public String createTransientIdentifierFor(ObjectSpecId objectSpecId, final Object pojo) {
+ return ""+ids.nextTransientId();
+ }
+
+ @Override
+ public String createPersistentIdentifierFor(ObjectSpecId objectSpecId, Object pojo, RootOid transientRootOid) {
+ Assert.assertNotNull("No connection set up", connectionPool);
+ return "" + (int) ids.nextPersistentId(connectionPool);
+ }
+
+
+ ///////////////////////////////////////////////////////
+ // Debug
+ ///////////////////////////////////////////////////////
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln(this.toString());
+ debug.indent();
+ ids.debugData(debug);
+ debug.unindent();
+ }
+
+ @Override
+ public String debugTitle() {
+ return "Sql Identifier Generator";
+ }
+}
+
+
+
+class IdNumbers {
+
+ private static final Logger LOG = LoggerFactory.getLogger(IdNumbers.class);
+
+ private static final String NUMBER_COLUMN = "number";
+ private static final String TABLE_NAME = "isis_admin_serial_id";
+ private static int BATCH_SIZE = 50;
+ private long transientNumber = -9999999;
+ private long lastId = 0;
+ private long newBatchAt = 0;
+
+ public synchronized long nextTransientId() {
+ return transientNumber++;
+ }
+
+ public synchronized long nextPersistentId(final DatabaseConnectorPool connectionPool) {
+ if (lastId > newBatchAt) {
+ throw new SqlObjectStoreException("ID exception, last id (" + lastId + ") past new batch boundary (" + newBatchAt + ")");
+ }
+ if (lastId == newBatchAt) {
+ prepareNewBatch(connectionPool);
+ }
+ lastId++;
+ return lastId;
+ }
+
+ private void prepareNewBatch(final DatabaseConnectorPool connectionPool) {
+ final DatabaseConnector db = connectionPool.acquire();
+ try {
+ final String tableName = Sql.tableIdentifier(TABLE_NAME);
+ final String numberColumn = Sql.identifier(NUMBER_COLUMN);
+ if (!db.hasTable(tableName)) {
+ lastId = 1;
+ newBatchAt = BATCH_SIZE;
+ db.update("create table " + tableName + " (" + numberColumn + " INTEGER)");
+ db.update("insert into " + tableName + " values (" + newBatchAt + ")");
+ LOG.debug("Initial ID batch created, from " + lastId + " to " + newBatchAt);
+ } else {
+ if (db.update("update " + tableName + " set " + numberColumn + " = " + numberColumn + " + " + BATCH_SIZE) != 1) {
+ throw new SqlObjectStoreException("failed to update serial id table; no rows updated");
+ }
+ final Results rs = db.select("select " + numberColumn + " from " + tableName);
+ rs.next();
+ newBatchAt = rs.getLong(NUMBER_COLUMN); // TODO here
+ lastId = newBatchAt - BATCH_SIZE;
+ LOG.debug("New ID batch created, from " + lastId + " to " + newBatchAt);
+ rs.close();
+ }
+ } catch (final ObjectPersistenceException e) {
+ throw e;
+ } finally {
+ connectionPool.release(db);
+ }
+ }
+
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln("id", lastId);
+ debug.appendln("transient id", transientNumber);
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlMetaData.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlMetaData.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlMetaData.java
new file mode 100644
index 0000000..5e0b718
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlMetaData.java
@@ -0,0 +1,36 @@
+/*
+ * 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.isis.objectstore.sql;
+
+public interface SqlMetaData {
+ String getKeywords();
+
+ String getTimeDateFunctions();
+
+ boolean isStoresLowerCaseIdentifiers();
+
+ boolean isStoresMixedCaseIdentifiers();
+
+ boolean isStoresUpperCaseIdentifiers();
+
+ String getQuoteString();
+
+ String quoteIdentifier(String identifier);
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStore.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStore.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStore.java
new file mode 100644
index 0000000..98695e6
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStore.java
@@ -0,0 +1,508 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.util.List;
+import java.util.Vector;
+
+import com.google.common.collect.Lists;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.debug.DebugString;
+import org.apache.isis.core.commons.ensure.IsisAssertException;
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.CollectionOid;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.persistence.objectstore.ObjectStoreSpi;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.CreateObjectCommand;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.SaveObjectCommand;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryBuiltInAbstract;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindAllInstances;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByPattern;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByTitle;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.PersistenceQuery;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
+import org.apache.isis.core.runtime.system.transaction.MessageBroker;
+import org.apache.isis.core.runtime.system.transaction.UpdateNotifier;
+
+public final class SqlObjectStore implements ObjectStoreSpi {
+
+ private static final String TABLE_NAME = "isis_admin_services";
+ // private static final String ID_COLUMN = "id";
+ // private static final String PRIMARYKEY_COLUMN = "pk_id";
+ public static final String BASE_NAME = "isis.persistor.sql";
+ private static final Logger LOG = LoggerFactory.getLogger(SqlObjectStore.class);
+ private DatabaseConnectorPool connectionPool;
+ private ObjectMappingLookup objectMappingLookup;
+ private boolean isInitialized;
+
+ @Override
+ public String name() {
+ return "SQL Object Store";
+ }
+
+ @Override
+ public void open() {
+ Sql.setMetaData(connectionPool.acquire().getMetaData());
+
+ if (!isInitialized) {
+ Defaults.initialise(BASE_NAME, IsisContext.getConfiguration());
+ Defaults.setPkIdLabel(Sql.identifier(Defaults.getPkIdLabel()));
+ Defaults.setIdColumn(Sql.identifier(Defaults.getIdColumn()));
+ }
+
+ final DebugBuilder debug = new DebugString();
+ connectionPool.debug(debug);
+ LOG.info("Database: " + debug);
+
+ objectMappingLookup.init();
+
+ final DatabaseConnector connector = connectionPool.acquire();
+ final String tableIdentifier = Sql.tableIdentifier(TABLE_NAME);
+ isInitialized = connector.hasColumn(tableIdentifier, Defaults.getPkIdLabel());
+ if (!isInitialized) {
+ if (connector.hasTable(tableIdentifier)) {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("drop table ");
+ sql.append(tableIdentifier);
+ connector.update(sql.toString());
+ }
+ final StringBuffer sql = new StringBuffer();
+ sql.append("create table ");
+ sql.append(tableIdentifier);
+ sql.append(" (");
+ sql.append(Defaults.getPkIdLabel());
+ sql.append(" int, ");
+ sql.append(Defaults.getIdColumn());
+ sql.append(" varchar(255)");
+ sql.append(")");
+ connector.update(sql.toString());
+ }
+ }
+
+ @Override
+ public boolean isFixturesInstalled() {
+ return isInitialized;
+ }
+
+ @Override
+ public void registerService(final RootOid rootOid) {
+ final DatabaseConnector connector = connectionPool.acquire();
+
+ final StringBuffer sql = new StringBuffer();
+ sql.append("insert into ");
+ sql.append(Sql.tableIdentifier(TABLE_NAME));
+ sql.append(" (");
+ sql.append(Defaults.getPkIdLabel());
+ sql.append(", ");
+ sql.append(Defaults.getIdColumn());
+ sql.append(") values (?,?)");
+
+ final RootOidDefault sqlOid = (RootOidDefault) rootOid;
+ connector.addToQueryValues(sqlOid.getIdentifier());
+ connector.addToQueryValues(rootOid.getObjectSpecId().asString());
+
+ connector.insert(sql.toString());
+ connectionPool.release(connector);
+ }
+
+ @Override
+ public void reset() {
+ }
+
+ @Override
+ public void close() {
+ objectMappingLookup.shutdown();
+ connectionPool.shutdown();
+ }
+
+ @Override
+ public void startTransaction() {
+ executeSql(Defaults.START_TRANSACTION());
+ }
+
+ @Override
+ public void abortTransaction() {
+ executeSql(Defaults.ABORT_TRANSACTION());
+ }
+
+ @Override
+ public void endTransaction() {
+ executeSql(Defaults.COMMIT_TRANSACTION());
+ }
+
+ private void executeSql(String sql) {
+ final DatabaseConnector connector = connectionPool.acquire();
+ try {
+ connector.begin();
+ connector.update(sql);
+ connector.commit();
+ // connector.close();
+ } finally {
+ connectionPool.release(connector);
+ }
+ }
+
+ @Override
+ public CreateObjectCommand createCreateObjectCommand(final ObjectAdapter object) {
+ return new CreateObjectCommand() {
+ @Override
+ public void execute(final PersistenceCommandContext context) {
+ final DatabaseConnector connection = ((SqlExecutionContext) context).getConnection();
+ LOG.debug(" create object " + object);
+ final ObjectMapping mapping = objectMappingLookup.getMapping(object, connection);
+ mapping.createObject(connection, object);
+ }
+
+ @Override
+ public ObjectAdapter onAdapter() {
+ return object;
+ }
+
+ @Override
+ public String toString() {
+ return "CreateObjectCommand [object=" + object + "]";
+ }
+ };
+ }
+
+ @Override
+ public DestroyObjectCommand createDestroyObjectCommand(final ObjectAdapter object) {
+ return new DestroyObjectCommand() {
+ @Override
+ public void execute(final PersistenceCommandContext context) {
+ final DatabaseConnector connection = ((SqlExecutionContext) context).getConnection();
+ LOG.debug(" destroy object " + object);
+ final ObjectMapping mapping = objectMappingLookup.getMapping(object, connection);
+ mapping.destroyObject(connection, object);
+ }
+
+ @Override
+ public ObjectAdapter onAdapter() {
+ return object;
+ }
+
+ @Override
+ public String toString() {
+ return "DestroyObjectCommand [object=" + object + "]";
+ }
+ };
+ }
+
+ @Override
+ public SaveObjectCommand createSaveObjectCommand(final ObjectAdapter adapter) {
+ return new SaveObjectCommand() {
+ @Override
+ public void execute(final PersistenceCommandContext context) {
+ final DatabaseConnector connection = ((SqlExecutionContext) context).getConnection();
+ LOG.debug(" save object " + adapter.toString());
+
+ try {
+ final ObjectSpecification adapterSpec = adapter.getSpecification();
+ if (!adapterSpec.isParented()) {
+ saveRootAdapter(adapter, connection);
+ } else if (adapterSpec.isParentedOrFreeCollection()) {
+ saveParentedCollectionAdapter(adapter, connection);
+ } else {
+ throw new NotYetImplementedException("cannot yet persist aggregated objects: "
+ + adapter.toString());
+ }
+ } finally {
+ connectionPool.release(connection);
+ }
+ }
+
+ private void saveRootAdapter(final ObjectAdapter adapter, final DatabaseConnector connection) {
+ final ObjectMapping mapping = objectMappingLookup.getMapping(adapter, connection);
+ mapping.save(connection, adapter);
+ }
+
+ private void saveParentedCollectionAdapter(final ObjectAdapter collectionAdapter,
+ final DatabaseConnector connection) {
+ final ObjectAdapter parent = collectionAdapter.getAggregateRoot();
+ LOG.debug("change to internal collection being persisted through parent");
+
+ final Oid oid = collectionAdapter.getOid();
+ final CollectionOid collectionOid = (CollectionOid) oid;
+ if (!(oid instanceof CollectionOid)) {
+ throw new IsisAssertException("object should have a CollectionOid");
+ }
+
+ final ObjectMapping mapping = objectMappingLookup.getMapping(parent, connection);
+ if (!mapping.saveCollection(connection, parent, collectionOid.getName())) {
+ final ObjectMapping parentMapping = objectMappingLookup.getMapping(parent, connection);
+ parentMapping.save(connection, collectionAdapter);
+ }
+ }
+
+ @Override
+ public ObjectAdapter onAdapter() {
+ return adapter;
+ }
+
+ @Override
+ public String toString() {
+ return "SaveObjectCommand [object=" + adapter + "]";
+ }
+
+ };
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln("initialised", isInitialized);
+ debug.appendln("connection pool", connectionPool);
+ debug.appendln("Database:");
+ debug.indent();
+ connectionPool.debug(debug);
+ debug.unindent();
+ objectMappingLookup.debugData(debug);
+ }
+
+ @Override
+ public String debugTitle() {
+ return null;
+ }
+
+ @Override
+ public void execute(final List<PersistenceCommand> commands) {
+ final DatabaseConnector connector = connectionPool.acquire();
+ connector.begin();
+
+ final IsisTransactionManager transactionManager = IsisContext.getTransactionManager();
+ final MessageBroker messageBroker = IsisContext.getMessageBroker();
+ final UpdateNotifier updateNotifier = IsisContext.getUpdateNotifier();
+ final SqlExecutionContext context =
+ new SqlExecutionContext(connector, transactionManager, messageBroker, updateNotifier);
+ try {
+ for (final PersistenceCommand command : commands) {
+ command.execute(context);
+ }
+ connector.commit();
+ } catch (final IsisException e) {
+ LOG.warn("Failure during execution", e);
+ connector.rollback();
+ throw e;
+ } finally {
+ connectionPool.release(connector);
+ }
+ }
+
+ public boolean flush(final PersistenceCommand[] commands) {
+ return false;
+ }
+
+ @Override
+ public List<ObjectAdapter> loadInstancesAndAdapt(final PersistenceQuery query) {
+ if (query instanceof PersistenceQueryFindByTitle) {
+ return findByTitle((PersistenceQueryFindByTitle) query, query.getStart(), query.getCount());
+ } else if (query instanceof PersistenceQueryFindAllInstances) {
+ return getAllInstances((PersistenceQueryFindAllInstances) query, query.getStart(), query.getCount());
+ } else if (query instanceof PersistenceQueryFindByPattern) {
+ return findByPattern((PersistenceQueryFindByPattern) query, query.getStart(), query.getCount());
+ } else {
+ throw new SqlObjectStoreException("Query type not supported: " + query);
+ }
+ }
+
+ private List<ObjectAdapter> findByPattern(final PersistenceQueryFindByPattern query, final long startIndex, final long rowCount) {
+ final ObjectSpecification specification = query.getSpecification();// query.getPattern().getSpecification();//
+ // getSpecification();
+ final DatabaseConnector connector = connectionPool.acquire();
+ try {
+ final List<ObjectAdapter> matchingInstances = Lists.newArrayList();
+
+ addSpecQueryInstances(specification, connector, query, matchingInstances, startIndex, rowCount);
+ return matchingInstances;
+
+ } finally {
+ connectionPool.release(connector);
+ }
+ }
+
+ private void addSpecQueryInstances(final ObjectSpecification specification, final DatabaseConnector connector,
+ final PersistenceQueryFindByPattern query, final List<ObjectAdapter> matchingInstances, long startIndex, long rowCount) {
+
+ if (specification.isAbstract() == false) {
+ final ObjectMapping mapper = objectMappingLookup.getMapping(specification, connector);
+ final Vector<ObjectAdapter> instances = mapper.getInstances(connector, specification, query);
+ matchingInstances.addAll(instances);
+
+ }
+ if (specification.hasSubclasses()) {
+ final List<ObjectSpecification> subclasses = specification.subclasses();
+ for (final ObjectSpecification subclassSpec : subclasses) {
+ addSpecQueryInstances(subclassSpec, connector, query, matchingInstances, startIndex, rowCount);
+ }
+ }
+ }
+
+ private List<ObjectAdapter> getAllInstances(final PersistenceQueryBuiltInAbstract criteria, final long startIndex, final long rowCount) {
+ final ObjectSpecification spec = criteria.getSpecification();
+ return allInstances(spec, startIndex, rowCount);
+ }
+
+ private List<ObjectAdapter> allInstances(final ObjectSpecification spec, long startIndex, long rowCount) {
+ final DatabaseConnector connector = connectionPool.acquire();
+ final List<ObjectAdapter> matchingInstances = Lists.newArrayList();
+
+ addSpecInstances(spec, connector, matchingInstances, startIndex, rowCount);
+
+ connectionPool.release(connector);
+ return matchingInstances;
+ }
+
+ private void addSpecInstances(final ObjectSpecification spec, final DatabaseConnector connector,
+ final List<ObjectAdapter> matchingInstances, final long startIndex, final long rowCount) {
+
+ if (!spec.isAbstract()) {
+ final ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
+ final List<ObjectAdapter> instances = mapper.getInstances(connector, spec, startIndex, rowCount);
+ matchingInstances.addAll(instances);
+ }
+
+ if (spec.hasSubclasses()) {
+ final List<ObjectSpecification> subclasses = spec.subclasses();
+ for (final ObjectSpecification subclassSpec : subclasses) {
+ addSpecInstances(subclassSpec, connector, matchingInstances, startIndex, rowCount);
+ }
+ }
+
+ }
+
+ private List<ObjectAdapter> findByTitle(final PersistenceQueryFindByTitle criteria, final long startIndex, final long rowCount) {
+ final ObjectSpecification spec = criteria.getSpecification();
+ final DatabaseConnector connector = connectionPool.acquire();
+ final ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
+
+ final Vector<ObjectAdapter> instances = mapper.getInstances(connector, spec, criteria.getTitle(), startIndex, rowCount);
+ connectionPool.release(connector);
+
+ return instances;
+ }
+
+ @Override
+ public ObjectAdapter loadInstanceAndAdapt(final TypedOid oid) {
+ final DatabaseConnector connection = connectionPool.acquire();
+ final ObjectSpecification objectSpec = getSpecificationLookup().lookupBySpecId(oid.getObjectSpecId());
+ final ObjectMapping mapper = objectMappingLookup.getMapping(objectSpec, connection);
+ final ObjectAdapter object = mapper.getObject(connection, oid);
+ connectionPool.release(connection);
+ return object;
+ }
+
+ @Override
+ public RootOid getOidForService(ObjectSpecification serviceSpec) {
+
+ final DatabaseConnector connector = connectionPool.acquire();
+ try {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("select ");
+ sql.append(Defaults.getPkIdLabel());
+ sql.append(" from ");
+ sql.append(Sql.tableIdentifier(TABLE_NAME));
+ sql.append(" where ");
+ sql.append(Defaults.getIdColumn());
+ sql.append(" = ?");
+ connector.addToQueryValues(serviceSpec.getSpecId().asString());
+
+ final Results results = connector.select(sql.toString());
+ if (!results.next()) {
+ return null;
+ }
+ final int id = results.getInt(Defaults.getPkIdLabel());
+ return RootOidDefault.create(serviceSpec.getSpecId(), "" + id);
+
+ } finally {
+ connectionPool.release(connector);
+ }
+ }
+
+ @Override
+ public boolean hasInstances(final ObjectSpecification spec) {
+ final DatabaseConnector connection = connectionPool.acquire();
+ final ObjectMapping mapper = objectMappingLookup.getMapping(spec, connection);
+ final boolean hasInstances = mapper.hasInstances(connection, spec);
+ connectionPool.release(connection);
+ return hasInstances;
+ }
+
+ @Override
+ public void resolveField(final ObjectAdapter object, final ObjectAssociation field) {
+ if (field.isOneToManyAssociation()) {
+ final DatabaseConnector connection = connectionPool.acquire();
+ final ObjectSpecification spec = object.getSpecification();
+ final ObjectMapping mapper = objectMappingLookup.getMapping(spec, connection);
+ mapper.resolveCollection(connection, object, field);
+ connectionPool.release(connection);
+ } else {
+ resolveImmediately(field.get(object));
+ }
+ }
+
+ @Override
+ public void resolveImmediately(final ObjectAdapter object) {
+ final DatabaseConnector connector = connectionPool.acquire();
+ final ObjectMapping mapping = objectMappingLookup.getMapping(object, connector);
+ mapping.resolve(connector, object);
+ connectionPool.release(connector);
+ }
+
+ // /////////////////////////////////////////////////////////
+ // Dependencies (injected)
+ // /////////////////////////////////////////////////////////
+
+ public void setConnectionPool(final DatabaseConnectorPool connectionPool) {
+ this.connectionPool = connectionPool;
+ }
+
+ public void setMapperLookup(final ObjectMappingLookup mapperLookup) {
+ this.objectMappingLookup = mapperLookup;
+ }
+
+ // /////////////////////////////////////////////////////////
+ // Dependencies (from context)
+ // /////////////////////////////////////////////////////////
+
+ protected AdapterManager getAdapterManager() {
+ return IsisContext.getPersistenceSession().getAdapterManager();
+ }
+
+ protected SpecificationLoader getSpecificationLookup() {
+ return IsisContext.getSpecificationLoader();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStoreException.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStoreException.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStoreException.java
new file mode 100644
index 0000000..d2be600
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStoreException.java
@@ -0,0 +1,42 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
+
+public class SqlObjectStoreException extends ObjectPersistenceException {
+ private static final long serialVersionUID = 1L;
+
+ public SqlObjectStoreException() {
+ super();
+ }
+
+ public SqlObjectStoreException(final String s) {
+ super(s);
+ }
+
+ public SqlObjectStoreException(final String s, final Throwable cause) {
+ super(s, cause);
+ }
+
+ public SqlObjectStoreException(final Throwable cause) {
+ super(cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlPersistorInstaller.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlPersistorInstaller.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlPersistorInstaller.java
new file mode 100644
index 0000000..9fa2090
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlPersistorInstaller.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.isis.objectstore.sql;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapterFactory;
+import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
+import org.apache.isis.core.runtime.persistence.objectstore.ObjectStoreSpi;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.AdapterManagerSpi;
+import org.apache.isis.core.runtime.system.persistence.IdentifierGenerator;
+import org.apache.isis.objectstore.sql.auto.AutoMapperFactory;
+import org.apache.isis.objectstore.sql.jdbc.JdbcConnectorFactory;
+import org.apache.isis.objectstore.sql.jdbc.installer.JdbcFieldMappingFactoryInstaller;
+
+public class SqlPersistorInstaller extends PersistenceMechanismInstallerAbstract {
+
+ public static final String NAME = "sql";
+
+ private SqlObjectStore objectStore;
+ private DatabaseConnectorPool connectionPool;
+
+ public SqlPersistorInstaller() {
+ super(NAME);
+ }
+
+ @Override
+ protected ObjectStoreSpi createObjectStore(final IsisConfiguration configuration, final ObjectAdapterFactory objectFactory, final AdapterManagerSpi adapterManager) {
+
+ if (objectStore == null) {
+ final FieldMappingLookup fieldMappingLookup = new FieldMappingLookup();
+ final JdbcFieldMappingFactoryInstaller installer = new JdbcFieldMappingFactoryInstaller();
+
+ Defaults.initialise(SqlObjectStore.BASE_NAME, IsisContext.getConfiguration());
+
+ installer.load(fieldMappingLookup);
+ // fieldMappingLookup.setValueMappingFactory(new
+ // JdbcFieldMappingFactoryInstaller());
+
+ final ObjectMappingLookup objectMappingLookup = new ObjectMappingLookup();
+ objectMappingLookup.setValueMappingLookup(fieldMappingLookup);
+ objectMappingLookup.setObjectMappingFactory(new AutoMapperFactory());
+ objectMappingLookup.setConnectionPool(connectionPool);
+
+ final SqlObjectStore objectStore = new SqlObjectStore();
+ objectStore.setMapperLookup(objectMappingLookup);
+ objectStore.setConnectionPool(connectionPool);
+ this.objectStore = objectStore;
+ }
+ return objectStore;
+ }
+
+ public SqlObjectStore getObjectStore() {
+ return objectStore;
+ }
+
+ @Override
+ public IdentifierGenerator createIdentifierGenerator(final IsisConfiguration configuration) {
+ final DatabaseConnectorFactory connectorFactory = new JdbcConnectorFactory();
+ connectionPool = new DatabaseConnectorPool(connectorFactory, 1);
+
+ return new SqlIdentifierGenerator(connectionPool);
+ }
+
+ /*
+ *
+ *
+ * @Override protected AdapterManagerExtended createAdapterManager(final
+ * IsisConfiguration configuration) { return new XmlAdapterManager(); }
+ */
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/StoredProcedure.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/StoredProcedure.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/StoredProcedure.java
new file mode 100644
index 0000000..ba02c91
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/StoredProcedure.java
@@ -0,0 +1,26 @@
+/*
+ * 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.isis.objectstore.sql;
+
+public interface StoredProcedure {
+
+ boolean getBoolean(int i);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/TitleMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/TitleMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/TitleMapping.java
new file mode 100644
index 0000000..65bb24d
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/TitleMapping.java
@@ -0,0 +1,71 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+
+public class TitleMapping {
+ private final String column = Sql.identifier("NO_title");
+
+ protected String getColumn() {
+ return column;
+ }
+
+ public void appendWhereClause(final StringBuffer sql, final String title) {
+ appendAssignment(sql, title);
+ }
+
+ private void appendAssignment(final StringBuffer sql, final String title) {
+ sql.append(column);
+ sql.append(" = ");
+ appendTitle(sql, title);
+ }
+
+ public void appendColumnDefinitions(final StringBuffer sql) {
+ sql.append(column);
+ sql.append(" ");
+ sql.append("varchar(200)");
+ }
+
+ public void appendColumnNames(final StringBuffer sql) {
+ sql.append(column);
+ }
+
+ public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ if (object == null) {
+ sql.append("NULL");
+ } else {
+ connector.addToQueryValues(object.titleString().toLowerCase());
+ }
+ sql.append("?");
+ }
+
+ private void appendTitle(final StringBuffer sql, final String title) {
+ final String titleString = title.toLowerCase();
+ sql.append(Sql.escapeAndQuoteValue(titleString));
+ }
+
+ public void appendUpdateAssignment(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ sql.append(column);
+ sql.append(" = ");
+ appendInsertValues(connector, sql, object);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/VersionMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/VersionMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/VersionMapping.java
new file mode 100644
index 0000000..768c485
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/VersionMapping.java
@@ -0,0 +1,106 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.sql.Timestamp;
+import java.util.Date;
+
+import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+
+public class VersionMapping {
+ private String lastActivityDateColumn;
+ private String lastActivityUserColumn;
+ private String versionColumn;
+
+ public void init() {
+ lastActivityDateColumn = Sql.identifier("MODIFIED_ON");
+ lastActivityUserColumn = Sql.identifier("MODIFIED_BY");
+ versionColumn = Sql.identifier("VERSION");
+ }
+
+ public String insertColumns() {
+ return versionColumn + ", " + lastActivityUserColumn + ", " + lastActivityDateColumn;
+ }
+
+ public String insertValues(final DatabaseConnector connector, final Version version) {
+ connector.addToQueryValues(version.getSequence());
+ IsisContext.getSession().getAuthenticationSession().getUserName();
+ String user = IsisContext.getSession().getAuthenticationSession().getUserName();// version.getUser();
+ if (user == "") {
+ user = "unknown";
+ }
+ connector.addToQueryValues(user);
+ connector.addToQueryValues(new Timestamp(new Date().getTime()));
+ return "?,?,?";
+ }
+
+ public String whereClause(final DatabaseConnector connector, final Version version) {
+ connector.addToQueryValues(version.getSequence());
+ return versionColumn + " = ?";
+ }
+
+ public String updateAssigment(final DatabaseConnector connector, final long nextSequence) {
+ connector.addToQueryValues(nextSequence);
+ return versionColumn + " = ?";
+ }
+
+ public String appendColumnNames() {
+ final StringBuffer sql = new StringBuffer();
+ sql.append(versionColumn);
+ sql.append(",");
+ sql.append(lastActivityUserColumn);
+ sql.append(",");
+ sql.append(lastActivityDateColumn);
+ return sql.toString();
+ }
+
+ public String appendColumnDefinitions() {
+ final StringBuffer sql = new StringBuffer();
+
+ sql.append(versionColumn);
+ sql.append(" bigint");
+
+ sql.append(",");
+ sql.append(lastActivityUserColumn);
+ sql.append(" varchar(32)");
+
+ sql.append(",");
+ sql.append(lastActivityDateColumn);
+ sql.append(" " + Defaults.TYPE_TIMESTAMP());
+
+ return sql.toString();
+ }
+
+ public Object appendUpdateValues(final DatabaseConnector connector, final long versionSequence) {
+ connector.addToQueryValues(versionSequence);
+ return versionColumn + "= ?";
+ }
+
+ public Version getLock(final Results rs) {
+ final long number = rs.getLong(versionColumn);
+ final String user = rs.getString(lastActivityUserColumn);
+ final Date time = rs.getJavaDateTime(lastActivityDateColumn, Defaults.getCalendar());
+ final Version version = SerialNumberVersion.create(number, user, time);
+ return version;
+ }
+
+}
[05/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java
new file mode 100644
index 0000000..c5ae7ef
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java
@@ -0,0 +1,357 @@
+/*
+ * 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.isis.objectstore.sql.auto;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.metamodel.spec.feature.Contributed;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.objectstore.sql.AbstractMapper;
+import org.apache.isis.objectstore.sql.CollectionMapper;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.FieldMappingLookup;
+import org.apache.isis.objectstore.sql.ObjectMappingLookup;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.SqlObjectStoreException;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+public abstract class AbstractAutoMapper extends AbstractMapper {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractAutoMapper.class);
+
+ protected final Map<ObjectAssociation, FieldMapping> fieldMappingByField = Maps.newLinkedHashMap();
+
+ protected CollectionMapper collectionMappers[];
+ protected String collectionMapperFields[];
+ protected boolean dbCreatesId;
+
+ protected ObjectSpecification specification;
+ protected String table;
+
+ final String className;
+ final String parameterBase;
+ final FieldMappingLookup lookup;
+ final ObjectMappingLookup objectMappingLookup;
+
+ protected AbstractAutoMapper(final String className, final String parameterBase, final FieldMappingLookup lookup,
+ final ObjectMappingLookup objectMappingLookup) {
+ this.specification = specificationFor(className);
+ this.className = className;
+ this.parameterBase = parameterBase;
+ this.lookup = lookup;
+ this.objectMappingLookup = objectMappingLookup;
+ }
+
+ protected AbstractAutoMapper(final FieldMappingLookup lookup, final AbstractAutoMapper abstractAutoMapper,
+ final String className) {
+
+ this.specification = getSpecificationLoader().loadSpecification(className);
+ this.className = className;
+
+ this.parameterBase = null;
+ this.lookup = null;
+ this.objectMappingLookup = null;
+ }
+
+ private static ObjectSpecification specificationFor(final String className) {
+ ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(className);
+ List<OneToOneAssociation> properties = specification.getProperties(Contributed.EXCLUDED);
+ if (isNullOrEmpty(properties) && !specification.isAbstract()) {
+ throw new SqlObjectStoreException(specification.getFullIdentifier() + " has no fields: " + specification);
+ }
+ return specification;
+ }
+
+ protected void setUpFieldMappers() {
+ setUpFieldMappers(lookup, objectMappingLookup, className, parameterBase);
+ }
+
+ private void setUpFieldMappers(final FieldMappingLookup lookup, final ObjectMappingLookup objectMappingLookup,
+ final String className, final String parameterBase) {
+ final IsisConfiguration configParameters = getConfiguration();
+ table = configParameters.getString(parameterBase + ".table." + className);
+ if (table == null) {
+ final String name = getTableNameFromSpecification(specification);
+ table = name;
+ } else {
+ table = Sql.tableIdentifier(table);
+ }
+
+ dbCreatesId = configParameters.getBoolean(parameterBase + "db-ids", false);
+ if (configParameters.getBoolean(parameterBase + "all-fields", true)) {
+ setupFullMapping(lookup, objectMappingLookup, className, configParameters, parameterBase);
+ } else {
+ // setupSpecifiedMapping(specification, configParameters,
+ // parameterBase);
+ }
+
+ LOG.info("table mapping: " + table + " (" + columnList(fieldMappingByField) + ")");
+ }
+
+ protected String getTableNameFromSpecification(final ObjectSpecification objectSpecification) {
+ return Sql.tableIdentifier(Sql.sqlName(Defaults.getTablePrefix() + objectSpecification.getShortIdentifier()));
+ }
+
+ protected List<ObjectAssociation> fields = new ArrayList<ObjectAssociation>();
+
+ protected void getExtraFields(final List<ObjectAssociation> fields) {
+ }
+
+ private void setupFullMapping(final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup,
+ final String className, final IsisConfiguration configParameters, final String parameterBase) {
+
+ fields.addAll(specification.getAssociations(Contributed.EXCLUDED));
+
+ int simpleFieldCount = 0;
+ int collectionFieldCount = 0;
+ for (int i = 0; i < fields.size(); i++) {
+ if (fields.get(i).isNotPersisted()) {
+ continue;
+ } else if (fields.get(i).isOneToManyAssociation()) {
+ collectionFieldCount++;
+ } else {
+ simpleFieldCount++;
+ }
+ }
+
+ final ObjectAssociation[] oneToOneProperties = new ObjectAssociation[simpleFieldCount];
+ final ObjectAssociation[] oneToManyProperties = new ObjectAssociation[collectionFieldCount];
+ collectionMappers = new CollectionMapper[collectionFieldCount];
+ collectionMapperFields = new String[collectionFieldCount];
+ final IsisConfiguration subset = getConfiguration().createSubset(parameterBase + ".mapper.");
+
+ for (int i = 0, simpleFieldNo = 0, collectionFieldNo = 0; i < fields.size(); i++) {
+ final ObjectAssociation field = fields.get(i);
+ if (field.isNotPersisted()) {
+ continue;
+ } else if (field.isOneToManyAssociation()) {
+ oneToManyProperties[collectionFieldNo] = field;
+
+ // TODO: Replace "new ForeignKeyCollectionMapper" with a factory
+ // method(?) to allow a different
+ // default CollectionMapper
+
+ // TODO: I think the default order should be changed - and I
+ // think I (KAM) have dropped support for the
+ // original "association-table" implementation. This means the
+ // current checks are misleading.
+ final String type = subset.getString(field.getId());
+ if (type == null || type.equals("association-table")) {
+ // collectionMappers[collectionFieldNo] = new
+ // AutoCollectionMapper(specification,
+ // oneToManyProperties[collectionFieldNo], lookup);
+ // collectionMappers[collectionFieldNo] = new
+ // ForeignKeyCollectionMapper(oneToManyProperties[collectionFieldNo],
+ // parameterBase, lookup,
+ // objectMapperLookup);
+
+ CollectionMapper collectionMapper = null;
+
+ // Trying to detect recursion, here.
+ // Let ForeignKeyInChildCollectionMapper find itself when a
+ // field is a collection of the current
+ // field type.
+ if (this instanceof ForeignKeyInChildCollectionMapper) {
+ final ForeignKeyInChildCollectionMapper mc = (ForeignKeyInChildCollectionMapper) this;
+
+ if (mc.priorField == field) {
+ collectionMapper = mc;
+ }
+ }
+
+ if (collectionMapper == null) {
+ // TODO: Polymorphism - is it sufficient for the
+ // collectionMapper to handle the subclasses?
+ final ObjectSpecification fieldSpecification = field.getSpecification();
+ if (fieldSpecification.hasSubclasses() || fieldSpecification.isAbstract()) {
+ // PolymorphicForeignKeyInChildCollectionBaseMapper
+ // Or PolymorphicForeignKeyInChildCollectionMapper
+ collectionMapper =
+ new PolymorphicForeignKeyInChildCollectionBaseMapper(
+ oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup,
+ this, field);
+ } else {
+ final ForeignKeyInChildCollectionMapper mapper =
+ new ForeignKeyInChildCollectionMapper(oneToManyProperties[collectionFieldNo],
+ parameterBase, lookup, objectMapperLookup, this, field);
+ mapper.setUpFieldMappers();
+ collectionMapper = mapper;
+ }
+ }
+
+ collectionMappers[collectionFieldNo] = collectionMapper;
+ collectionMapperFields[collectionFieldNo] = field.getId();
+
+ } else if (type.equals("fk-table")) {
+ final String property = parameterBase + field.getId() + ".element-type";
+ final String elementType = configParameters.getString(property);
+ if (elementType == null) {
+ throw new SqlObjectStoreException("Expected property " + property);
+ }
+ /*
+ * collectionMappers[collectionFieldNo] = new ForeignKeyCollectionMapper(elementType,
+ * oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup);
+ */
+ } else {
+ // TODO use other mappers where necessary
+ throw new NotYetImplementedException("for " + type);
+ }
+
+ collectionFieldNo++;
+ } else if (field.isOneToOneAssociation()) {
+ oneToOneProperties[simpleFieldNo] = field;
+ simpleFieldNo++;
+ } else {
+ oneToOneProperties[simpleFieldNo] = field;
+ simpleFieldNo++;
+ }
+ }
+
+ for (final ObjectAssociation field : oneToOneProperties) {
+ if (fieldMappingByField.containsKey(field)) {
+ continue;
+ }
+ final FieldMapping mapping = lookup.createMapping(specification, field);
+ fieldMappingByField.put(field, mapping);
+ }
+ }
+
+ protected String columnList(final Map<ObjectAssociation, FieldMapping> fieldMappingByField) {
+ return columnList(fieldMappingByField.values());
+ }
+
+ /*
+ * private void setupSpecifiedMapping( final ObjectSpecification specification, final IsisConfiguration
+ * configParameters, final String parameterBase) { IsisConfiguration columnMappings =
+ * IsisContext.getConfiguration().createSubset(parameterBase + "column"); int columnsSize = columnMappings.size();
+ * // columnNames = new String[columnsSize]; oneToOneProperties = new ObjectAssociation[columnsSize];
+ *
+ * int i = 0; for (Enumeration names = columnMappings.propertyNames(); names.hasMoreElements(); i++) { String
+ * columnName = (String) names.nextElement(); String fieldName = columnMappings.getString(columnName);
+ * oneToOneProperties[i] = specification.getAssociation(fieldName); // columnNames[i] = columnName; }
+ *
+ * IsisConfiguration collectionMappings = IsisContext.getConfiguration().createSubset( parameterBase +
+ * "collection"); int collectionsSize = collectionMappings.size(); collectionMappers = new
+ * AutoCollectionMapper[collectionsSize]; oneToManyProperties = new ObjectAssociation[collectionsSize];
+ *
+ * int j = 0; for (Enumeration names = collectionMappings.propertyNames(); names.hasMoreElements(); j++) { String
+ * propertyName = (String) names.nextElement(); String collectionName = collectionMappings.getString(propertyName);
+ * String type = collectionMappings.getString(collectionName);
+ *
+ * oneToManyProperties[j] = specification.getAssociation(collectionName); if (type.equals("auto")) {
+ * collectionMappers[j] = new AutoCollectionMapper(this, specification, oneToManyProperties[j], getLookup()); } else
+ * { // TODO use other mappers where necessary // new ReversedAutoAssociationMapper(specification, collectionName,
+ * parameterBase);
+ *
+ * throw new NotYetImplementedException(); } } }
+ */
+ protected String columnList(final Collection<FieldMapping> fieldMappings) {
+ final StringBuffer sql = new StringBuffer();
+ for (final FieldMapping mapping : fieldMappings) {
+ if (sql.length() > 0) {
+ sql.append(",");
+ }
+ mapping.appendColumnNames(sql);
+ }
+ return sql.toString();
+ }
+
+ protected ObjectAdapter getAdapter(final ObjectSpecification spec, final Oid oid) {
+ final ObjectAdapter adapter = getAdapterManager().getAdapterFor(oid);
+ if (adapter != null) {
+ return adapter;
+ }
+
+ // REVIEW: where the oid is a TypedOid, the following two lines could be replaced by
+ // getPersistenceSession().recreatePersistentAdapter(oid)
+ // is preferable, since then reuses the PojoRecreator impl defined within SqlPersistorInstaller
+ final Object recreatedPojo = spec.createObject();
+ return getPersistenceSession().mapRecreatedPojo(oid, recreatedPojo);
+ }
+
+ protected FieldMapping fieldMappingFor(final ObjectAssociation field) {
+ return fieldMappingByField.get(field);
+ }
+
+ @Override
+ public boolean needsTables(final DatabaseConnector connection) {
+ for (int i = 0; collectionMappers != null && i < collectionMappers.length; i++) {
+ if (collectionMappers[i].needsTables(connection)) {
+ return true;
+ }
+ }
+ return !connection.hasTable(table);
+ }
+
+ protected String values(final DatabaseConnector connector, final ObjectAdapter object) {
+ final StringBuffer sql = new StringBuffer();
+ for (final FieldMapping mapping : fieldMappingByField.values()) {
+ mapping.appendInsertValues(connector, sql, object);
+ sql.append(",");
+ }
+ return sql.toString();
+ }
+
+ private static boolean isNullOrEmpty(List<?> list) {
+ return list == null || list.size() == 0;
+ }
+
+ @Override
+ public String toString() {
+ return "AbstractAutoMapper [table=" + table + ",noColumns=" + fieldMappingByField.size() + ",specification="
+ + specification.getFullIdentifier() + "]";
+ }
+
+ protected SpecificationLoaderSpi getSpecificationLoader() {
+ return IsisContext.getSpecificationLoader();
+ }
+
+ protected IsisConfiguration getConfiguration() {
+ return IsisContext.getConfiguration();
+ }
+
+ protected PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+ protected AdapterManager getAdapterManager() {
+ return getPersistenceSession().getAdapterManager();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java
new file mode 100644
index 0000000..c76cc15
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java
@@ -0,0 +1,172 @@
+/*
+ * 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.isis.objectstore.sql.auto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.persistence.PersistorUtil;
+import org.apache.isis.objectstore.sql.AbstractMapper;
+import org.apache.isis.objectstore.sql.CollectionMapper;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.FieldMappingLookup;
+import org.apache.isis.objectstore.sql.IdMapping;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.jdbc.JdbcObjectReferenceMapping;
+import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
+
+public class AutoCollectionMapper extends AbstractMapper implements CollectionMapper {
+ private static final Logger LOG = LoggerFactory.getLogger(AutoCollectionMapper.class);
+ private String tableName;
+ private final ObjectAssociation field;
+ private final ObjectReferenceMapping elementMapping;
+ private final IdMapping idMapping;
+
+ public AutoCollectionMapper(final ObjectSpecification specification, final ObjectAssociation field,
+ final FieldMappingLookup lookup) {
+ this.field = field;
+
+ final ObjectSpecification spec = field.getFacet(TypeOfFacet.class).valueSpec();
+ idMapping = lookup.createIdMapping();
+ elementMapping = lookup.createMapping(spec);
+
+ final String className = specification.getShortIdentifier();
+ final String columnName = field.getId();
+ tableName = Sql.sqlName(className) + "_" + asSqlName(columnName);
+ tableName = Sql.identifier(tableName);
+ }
+
+ @Override
+ public void createTables(final DatabaseConnector connector) {
+ if (!connector.hasTable(tableName)) {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("create table ");
+ sql.append(tableName);
+ sql.append(" (");
+
+ idMapping.appendColumnDefinitions(sql);
+ sql.append(", ");
+ elementMapping.appendColumnDefinitions(sql);
+
+ sql.append(")");
+
+ connector.update(sql.toString());
+ }
+ }
+
+ @Override
+ public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter parentAdapter) {
+ final ObjectAdapter collectionAdapter = field.get(parentAdapter);
+ if (!collectionAdapter.canTransitionToResolving()) {
+ return;
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("loading internal collection " + field);
+ }
+
+ try {
+ PersistorUtil.startResolving(collectionAdapter);
+
+ final StringBuffer sql = new StringBuffer();
+ sql.append("select ");
+ idMapping.appendColumnNames(sql);
+ sql.append(", ");
+ elementMapping.appendColumnNames(sql);
+ sql.append(" from ");
+ sql.append(tableName);
+
+ final Results rs = connector.select(sql.toString());
+ final List<ObjectAdapter> list = new ArrayList<ObjectAdapter>();
+ while (rs.next()) {
+ final ObjectAdapter element = ((JdbcObjectReferenceMapping) elementMapping).initializeField(rs);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(" element " + element.getOid());
+ }
+ list.add(element);
+ }
+ final CollectionFacet collectionFacet =
+ collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
+ collectionFacet.init(collectionAdapter, list.toArray(new ObjectAdapter[list.size()]));
+ rs.close();
+ } finally {
+ PersistorUtil.toEndState(collectionAdapter);
+ }
+ }
+
+ @Override
+ public boolean needsTables(final DatabaseConnector connector) {
+ return !connector.hasTable(tableName);
+ }
+
+ @Override
+ public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent) {
+ final ObjectAdapter collection = field.get(parent);
+ LOG.debug("saving internal collection " + collection);
+
+ StringBuffer sql = new StringBuffer();
+ sql.append("delete from ");
+ sql.append(tableName);
+ sql.append(" where ");
+ final RootOid oid = (RootOid) parent.getOid();
+ idMapping.appendWhereClause(connector, sql, oid);
+ connector.update(sql.toString());
+
+ sql = new StringBuffer();
+ sql.append("insert into ");
+ sql.append(tableName);
+ sql.append(" (");
+ idMapping.appendColumnNames(sql);
+ sql.append(", ");
+ elementMapping.appendColumnNames(sql);
+ sql.append(" ) values (");
+ idMapping.appendInsertValues(connector, sql, parent);
+ sql.append(", ");
+
+ final CollectionFacet collectionFacet = collection.getSpecification().getFacet(CollectionFacet.class);
+ for (final ObjectAdapter element : collectionFacet.iterable(collection)) {
+ final StringBuffer values = new StringBuffer();
+ elementMapping.appendInsertValues(connector, values, element);
+ connector.update(sql.toString() + values + ")");
+ }
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln(field.getName(), "collection");
+ debug.indent();
+ debug.appendln("Table", tableName);
+ debug.appendln("ID mapping", idMapping);
+ debug.appendln("Element mapping", elementMapping);
+ debug.unindent();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapper.java
new file mode 100644
index 0000000..54efdec
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapper.java
@@ -0,0 +1,514 @@
+/*
+ * 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.isis.objectstore.sql.auto;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Vector;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.debug.DebuggableWithTitle;
+import org.apache.isis.core.commons.lang.MethodExtensions;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.core.metamodel.facets.notpersisted.NotPersistedFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.ObjectSpecificationException;
+import org.apache.isis.core.metamodel.spec.feature.Contributed;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
+import org.apache.isis.core.runtime.persistence.PersistorUtil;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByPattern;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.CollectionMapper;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.FieldMappingLookup;
+import org.apache.isis.objectstore.sql.IdMapping;
+import org.apache.isis.objectstore.sql.ObjectMapping;
+import org.apache.isis.objectstore.sql.ObjectMappingLookup;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.SqlObjectStoreException;
+import org.apache.isis.objectstore.sql.TitleMapping;
+import org.apache.isis.objectstore.sql.VersionMapping;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+public class AutoMapper extends AbstractAutoMapper implements ObjectMapping, DebuggableWithTitle {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AutoMapper.class);
+ private final IdMapping idMapping;
+ private final VersionMapping versionMapping;
+ private final TitleMapping titleMapping;
+ private final boolean useVersioning;
+
+ public AutoMapper(final String className, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup) {
+ super(className, parameterBase, lookup, objectMapperLookup);
+ idMapping = lookup.createIdMapping();
+ versionMapping = lookup.createVersionMapping();
+ titleMapping = lookup.createTitleMapping();
+
+ useVersioning = Defaults.useVersioning(specification.getShortIdentifier());
+
+ setUpFieldMappers();
+ }
+
+ protected VersionMapping getVersionMapping() {
+ return versionMapping;
+ }
+
+ protected IdMapping getIdMapping() {
+ return idMapping;
+ }
+
+ @Override
+ public void createTables(final DatabaseConnector connection) {
+ if (!connection.hasTable(table)) {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("create table ");
+ sql.append(table);
+ sql.append(" (");
+ idMapping.appendCreateColumnDefinitions(sql);
+ sql.append(", ");
+ for (final FieldMapping mapping : fieldMappingByField.values()) {
+ mapping.appendColumnDefinitions(sql);
+ sql.append(",");
+ }
+ titleMapping.appendColumnDefinitions(sql);
+ sql.append(", ");
+ sql.append(versionMapping.appendColumnDefinitions());
+ sql.append(")");
+ connection.update(sql.toString());
+ }
+ for (int i = 0; collectionMappers != null && i < collectionMappers.length; i++) {
+ if (collectionMappers[i].needsTables(connection)) {
+ collectionMappers[i].createTables(connection);
+ }
+ }
+ }
+
+ @Override
+ public void createObject(final DatabaseConnector connector, final ObjectAdapter object) {
+ final int versionSequence = 1;
+ final Version version = createVersion(versionSequence);
+
+ final StringBuffer sql = new StringBuffer();
+ sql.append("insert into " + table + " (");
+ idMapping.appendColumnNames(sql);
+ sql.append(", ");
+ final String columnList = columnList(fieldMappingByField);
+ if (columnList.length() > 0) {
+ sql.append(columnList);
+ sql.append(", ");
+ }
+ titleMapping.appendColumnNames(sql);
+ sql.append(", ");
+ sql.append(versionMapping.insertColumns());
+ sql.append(") values (");
+ idMapping.appendInsertValues(connector, sql, object);
+ sql.append(", ");
+ sql.append(values(connector, object));
+ titleMapping.appendInsertValues(connector, sql, object);
+ sql.append(", ");
+ sql.append(versionMapping.insertValues(connector, version));
+ sql.append(") ");
+
+ connector.insert(sql.toString());
+ object.setVersion(version);
+
+ for (final CollectionMapper collectionMapper : collectionMappers) {
+ collectionMapper.saveInternalCollection(connector, object);
+ }
+ }
+
+ @Override
+ public void destroyObject(final DatabaseConnector connector, final ObjectAdapter adapter) {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("delete from " + table + " WHERE ");
+ final RootOid oid = (RootOid) adapter.getOid();
+ idMapping.appendWhereClause(connector, sql, oid);
+ sql.append(" AND ");
+ sql.append(versionMapping.whereClause(connector, adapter.getVersion()));
+ final int updateCount = connector.update(sql.toString());
+ if (updateCount == 0) {
+ LOG.info("concurrency conflict object " + this + "; no deletion performed");
+ throw new ConcurrencyException("", adapter.getOid());
+ }
+ }
+
+ @Override
+ public Vector<ObjectAdapter> getInstances(final DatabaseConnector connector, final ObjectSpecification spec,
+ final long startIndex, final long rowCount) {
+ final StringBuffer sql = createSelectStatement();
+ final Vector<ObjectAdapter> instances = new Vector<ObjectAdapter>();
+ loadInstancesToVector(connector, spec, completeSelectStatement(sql, startIndex, rowCount), instances);
+ return instances;
+ }
+
+ @Override
+ public Vector<ObjectAdapter> getInstances(final DatabaseConnector connector, final ObjectSpecification spec,
+ final PersistenceQueryFindByPattern query) {
+ final Vector<ObjectAdapter> instances = new Vector<ObjectAdapter>();
+
+ final StringBuffer sql = createSelectStatement();
+ int initialLength = 0;
+
+ int foundFields = 0;
+ final ObjectAdapter pattern = query.getPattern();
+
+ // for all fields in the query.getPattern, build a SQL select clause for
+ // this spec.
+ final Object o = pattern.getObject();
+ final ObjectSpecification patternSpec = pattern.getSpecification();
+ final List<ObjectAssociation> patternAssociations = patternSpec.getAssociations(Contributed.EXCLUDED);
+ for (final ObjectAssociation patternAssoc : patternAssociations) {
+ final Method method;
+ final Identifier identifier = patternAssoc.getIdentifier();
+ final String memberName = identifier.getMemberName();
+ final String methodName = memberName.substring(0, 1).toUpperCase() + memberName.substring(1);
+
+ try {
+ if (true) {
+ final ObjectAdapter field = patternAssoc.get(pattern);
+ if (field != null) {
+ final String id = patternAssoc.getId();
+ try {
+ final ObjectAssociation oa = spec.getAssociation(id);
+ final NotPersistedFacet fc = oa.getFacet(NotPersistedFacet.class);
+ if (fc != null) {
+ continue;
+ }
+ } catch (final ObjectSpecificationException e) {
+ // this is OK
+ }
+
+ if (foundFields == 0) {
+ sql.append(" WHERE ");
+ initialLength = sql.length();
+ }
+
+ if (sql.length() > initialLength) {
+ sql.append(" AND ");
+ }
+
+ final FieldMapping fieldMapping = fieldMappingFor(patternAssoc);
+ if (fieldMapping != null) {
+ fieldMapping.appendWhereClause(connector, sql, pattern);
+ } else {
+ // Have to use getXXX method if the fieldMapping is
+ // null..
+ final ObjectSpecification specification = patternAssoc.getSpecification();
+
+ method = o.getClass().getMethod("get" + methodName, (Class<?>[]) null);
+ final Object res = MethodExtensions.invoke(method, o);
+
+ if (specification.isValue()) {
+ // If the property (memberName) is a value type,
+ // use the value.
+ final String fieldName = Sql.sqlFieldName(identifier.getMemberName());
+ sql.append(fieldName + "=?");
+ connector.addToQueryValues(res);
+ } else {
+ throw new SqlObjectStoreException("Unhandled combination!");
+ }
+ }
+ foundFields++;
+ }
+ }
+ } catch (final SecurityException e) {
+ LOG.debug(e.getMessage());
+ } catch (final NoSuchMethodException e) {
+ LOG.info("Unable to invode method: get" + methodName + " in getInstances");
+ LOG.debug(e.getMessage());
+ }
+ }
+ // if (foundFields > 0) {
+ loadInstancesToVector(connector, spec, completeSelectStatement(sql, query.getStart(), query.getCount()), instances);
+ // }
+ return instances;
+ }
+
+ @Override
+ public Vector<ObjectAdapter> getInstances(final DatabaseConnector connector, final ObjectSpecification spec,
+ final String title, final long startIndex, final long rowCount) {
+ final Vector<ObjectAdapter> instances = new Vector<ObjectAdapter>();
+
+ final StringBuffer sql = createSelectStatement();
+ sql.append(" WHERE ");
+ titleMapping.appendWhereClause(sql, title);
+ loadInstancesToVector(connector, spec, completeSelectStatement(sql, startIndex, rowCount), instances);
+ return instances;
+ }
+
+ @Override
+ public ObjectAdapter getObject(final DatabaseConnector connector, final TypedOid typedOid) {
+ final StringBuffer sql = createSelectStatement();
+ sql.append(" WHERE ");
+ idMapping.appendWhereClause(connector, sql, (RootOid) typedOid);
+ final Results rs = connector.select(completeSelectStatement(sql, 0, 0));
+ final ObjectSpecification objectSpec = getSpecificationLoader().lookupBySpecId(typedOid.getObjectSpecId());
+ if (rs.next()) {
+ return loadMappedObject(connector, objectSpec, rs);
+ } else {
+ throw new ObjectNotFoundException("No object with with " + typedOid + " in table " + table);
+ }
+ }
+
+ @Override
+ public boolean hasInstances(final DatabaseConnector connector, final ObjectSpecification cls) {
+ final String statement = "select count(*) from " + table;
+ final int instances = connector.count(statement);
+ return instances > 0;
+ }
+
+ private StringBuffer createSelectStatement() {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("select ");
+ idMapping.appendColumnNames(sql);
+ sql.append(", ");
+ final String columnList = columnList(fieldMappingByField);
+ if (columnList.length() > 0) {
+ sql.append(columnList);
+ sql.append(", ");
+ }
+ sql.append(versionMapping.insertColumns());
+ sql.append(" from " + table);
+ return sql;
+ } /*
+ * if (whereClause != null) { sql.append(" WHERE ");
+ * sql.append(whereClause); } else if (whereClause != null) {
+ * sql.append(" WHERE "); idMapping.appendWhereClause(sql, oid); }
+ */
+
+ private String completeSelectStatement(final StringBuffer sql, final long startIndex, final long rowCount) {
+ sql.append(" order by ");
+ idMapping.appendColumnNames(sql);
+
+ if ((startIndex != 0) || (rowCount != 0)) {
+ sql.append(" ");
+ sql.append(Defaults.getLimitsClause(startIndex, rowCount));
+ }
+
+ return sql.toString();
+ }
+
+ protected void loadFields(final ObjectAdapter adapter, final Results rs) {
+ PersistorUtil.startResolving(adapter);
+ try {
+ for (final FieldMapping mapping : fieldMappingByField.values()) {
+ mapping.initializeField(adapter, rs);
+ }
+ /*
+ * for (int i = 0; i < oneToManyProperties.length; i++) { /* Need to
+ * set up collection to be a ghost before we access as below
+ */
+ // CollectionAdapter collection = (CollectionAdapter)
+ /*
+ * oneToManyProperties[i].get(object); }
+ */
+ adapter.setVersion(versionMapping.getLock(rs));
+ } finally {
+ PersistorUtil.toEndState(adapter);
+ }
+ }
+
+ // KAM
+ private void loadCollections(final DatabaseConnector connector, final ObjectAdapter instance) {
+
+ for (final CollectionMapper mapper : collectionMappers) {
+ mapper.loadInternalCollection(connector, instance);
+ }
+ }
+
+ private void loadInstancesToVector(final DatabaseConnector connector, final ObjectSpecification cls, final String selectStatment, final Vector<ObjectAdapter> instances) {
+ LOG.debug("loading instances from SQL " + table);
+
+ try {
+ final Results rs = connector.select(selectStatment);
+ final int maxInstances = Defaults.getMaxInstances();
+ for (int count = 0; rs.next() && count < maxInstances; count++) {
+ final ObjectAdapter instance = loadMappedObject(connector, cls, rs);
+ LOG.debug(" instance " + instance);
+ instances.addElement(instance);
+ }
+ rs.close();
+ } catch (final SqlObjectStoreException e) {
+ // Invalid SELECT means no object found.. don't worry about it,
+ // here.
+ }
+ }
+
+ private ObjectAdapter loadMappedObject(final DatabaseConnector connector, final ObjectSpecification cls, final Results rs) {
+ final Oid oid = idMapping.recreateOid(rs, specification);
+ final ObjectAdapter adapter = getAdapter(cls, oid);
+
+ if (adapter.canTransitionToResolving()) {
+ loadFields(adapter, rs);
+ loadCollections(connector, adapter); // KAM
+ }
+ return adapter;
+ }
+
+ @Override
+ public void resolve(final DatabaseConnector connector, final ObjectAdapter object) {
+ LOG.debug("loading data from SQL " + table + " for " + object);
+ final StringBuffer sql = new StringBuffer();
+ sql.append("select ");
+ sql.append(columnList(fieldMappingByField));
+ sql.append(",");
+ sql.append(versionMapping.appendColumnNames());
+ sql.append(" from " + table + " WHERE ");
+ final RootOid oid = (RootOid) object.getOid();
+ idMapping.appendWhereClause(connector, sql, oid);
+
+ final Results rs = connector.select(sql.toString());
+ if (rs.next()) {
+ loadFields(object, rs);
+ rs.close();
+
+ for (final CollectionMapper collectionMapper : collectionMappers) {
+ collectionMapper.loadInternalCollection(connector, object);
+ }
+ } else {
+ rs.close();
+ throw new SqlObjectStoreException("Unable to load data from " + table + " with id " + object.getOid().enString(getOidMarshaller()));
+ }
+ }
+
+ @Override
+ public void resolveCollection(final DatabaseConnector connector, final ObjectAdapter object, final ObjectAssociation field) {
+ if (collectionMappers.length > 0) {
+ final DatabaseConnector secondConnector = connector.getConnectionPool().acquire();
+ for (final CollectionMapper collectionMapper : collectionMappers) {
+ collectionMapper.loadInternalCollection(secondConnector, object);
+ }
+ connector.getConnectionPool().release(secondConnector);
+ }
+ }
+
+ @Override
+ public void startup(final DatabaseConnector connector, final ObjectMappingLookup objectMapperLookup) {
+ if (needsTables(connector)) {
+ createTables(connector);
+ }
+ }
+
+ @Override
+ public void save(final DatabaseConnector connector, final ObjectAdapter adapter) {
+ final Version version = adapter.getVersion();
+ final long nextSequence;
+ if (useVersioning) {
+ nextSequence = version.getSequence() + 1;
+ } else {
+ nextSequence = version.getSequence();
+ }
+
+ final StringBuffer sql = new StringBuffer();
+ sql.append("UPDATE " + table + " SET ");
+ for (final FieldMapping mapping : fieldMappingByField.values()) {
+ mapping.appendUpdateValues(connector, sql, adapter);
+ sql.append(", ");
+ }
+ sql.append(versionMapping.updateAssigment(connector, nextSequence));
+ sql.append(", ");
+ titleMapping.appendUpdateAssignment(connector, sql, adapter);
+ sql.append(" WHERE ");
+ final RootOid oid = (RootOid) adapter.getOid();
+ idMapping.appendWhereClause(connector, sql, oid);
+ if (useVersioning) {
+ sql.append(" AND ");
+ sql.append(versionMapping.whereClause(connector, adapter.getVersion()));
+ }
+
+ final int updateCount = connector.update(sql.toString());
+ if (updateCount == 0) {
+ LOG.info("concurrency conflict object " + this + "; no update performed");
+ throw new ConcurrencyException("", adapter.getOid());
+ } else {
+ adapter.setVersion(createVersion(nextSequence));
+ }
+
+ // TODO update collections - change only when needed rather than
+ // reinserting from scratch
+ for (final CollectionMapper collectionMapper : collectionMappers) {
+ collectionMapper.saveInternalCollection(connector, adapter);
+ }
+ }
+
+ @Override
+ public boolean saveCollection(final DatabaseConnector connection, final ObjectAdapter parent, final String fieldName) {
+ int i = 0;
+ for (final String collectionFieldName : collectionMapperFields) {
+ if (collectionFieldName.equals(fieldName)) {
+ final CollectionMapper fieldMapper = collectionMappers[i];
+ fieldMapper.saveInternalCollection(connection, parent);
+ return true;
+ }
+ i++;
+ }
+ return false;
+ }
+
+ // //////////////////////////////////////////////////////////////
+ // debugging, toString
+ // //////////////////////////////////////////////////////////////
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln("ID mapping", idMapping);
+ debug.appendln("ID mapping", versionMapping);
+ debug.appendln("ID mapping", titleMapping);
+ for (final FieldMapping mapping : fieldMappingByField.values()) {
+ mapping.debugData(debug);
+ }
+ for (final CollectionMapper collectionMapper : collectionMappers) {
+ collectionMapper.debugData(debug);
+ }
+
+ }
+
+ @Override
+ public String debugTitle() {
+ return toString();
+ }
+
+ @Override
+ public String toString() {
+ return "AutoMapper [table=" + table + ",id=" + idMapping + ",noColumns=" + fieldMappingByField.size() + ",specification=" + specification.getFullIdentifier() + "]";
+ }
+
+ // //////////////////////////////////////////////////////////////
+ // dependencies (from context)
+ // //////////////////////////////////////////////////////////////
+
+ protected OidMarshaller getOidMarshaller() {
+ return IsisContext.getOidMarshaller();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapperFactory.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapperFactory.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapperFactory.java
new file mode 100644
index 0000000..2fbc0a9
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapperFactory.java
@@ -0,0 +1,32 @@
+/*
+ * 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.isis.objectstore.sql.auto;
+
+import org.apache.isis.objectstore.sql.FieldMappingLookup;
+import org.apache.isis.objectstore.sql.ObjectMapping;
+import org.apache.isis.objectstore.sql.ObjectMappingFactory;
+import org.apache.isis.objectstore.sql.ObjectMappingLookup;
+
+public class AutoMapperFactory implements ObjectMappingFactory {
+ @Override
+ public ObjectMapping createMapper(final String className, final String propertiesBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup) {
+ return new AutoMapper(className, propertiesBase, lookup, objectMapperLookup);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java
new file mode 100644
index 0000000..c5fa9d5
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java
@@ -0,0 +1,388 @@
+/*
+ * 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.isis.objectstore.sql.auto;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.persistence.PersistorUtil;
+import org.apache.isis.objectstore.sql.CollectionMapper;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.FieldMappingLookup;
+import org.apache.isis.objectstore.sql.IdMapping;
+import org.apache.isis.objectstore.sql.IdMappingAbstract;
+import org.apache.isis.objectstore.sql.ObjectMapping;
+import org.apache.isis.objectstore.sql.ObjectMappingLookup;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.VersionMapping;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
+
+/**
+ * Stores 1-to-many collections by creating a foreign-key column in the table for the incoming objectAssociation class.
+ * This assumes this the class is only ever in 1 collection parent.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ForeignKeyCollectionMapper extends AbstractAutoMapper implements CollectionMapper {
+ private static final Logger LOG = LoggerFactory.getLogger(ForeignKeyCollectionMapper.class);
+ private final ObjectAssociation field;
+ private final IdMapping idMapping;
+ private final VersionMapping versionMapping;
+ private final ObjectReferenceMapping foreignKeyMapping;
+ private String foreignKeyName;
+ private String columnName;
+ private final ObjectMappingLookup objectMapperLookup2;
+
+ private ObjectMapping originalMapping = null;
+
+ public ForeignKeyCollectionMapper(final ObjectAssociation objectAssociation, final String parameterBase,
+ final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup) {
+ super(objectAssociation.getSpecification().getFullIdentifier(), parameterBase, lookup, objectMapperLookup);
+
+ this.field = objectAssociation;
+
+ objectMapperLookup2 = objectMapperLookup;
+
+ idMapping = lookup.createIdMapping();
+ versionMapping = lookup.createVersionMapping();
+
+ setColumnName(determineColumnName(objectAssociation));
+ foreignKeyName = Sql.sqlName("fk_" + getColumnName());
+
+ foreignKeyName = Sql.identifier(foreignKeyName);
+ foreignKeyMapping = lookup.createMapping(columnName, specification);
+ }
+
+ protected ForeignKeyCollectionMapper(final FieldMappingLookup lookup, final AbstractAutoMapper abstractAutoMapper,
+ final ObjectAssociation field) {
+ super(lookup, abstractAutoMapper, field.getSpecification().getFullIdentifier());
+
+ this.field = field;
+ objectMapperLookup2 = null;
+
+ idMapping = lookup.createIdMapping();
+ versionMapping = lookup.createVersionMapping();
+
+ setColumnName(determineColumnName(field));
+ foreignKeyName = Sql.sqlName("fk_" + getColumnName());
+
+ foreignKeyName = Sql.identifier(foreignKeyName);
+ foreignKeyMapping = lookup.createMapping(columnName, specification);
+ }
+
+ protected String determineColumnName(final ObjectAssociation objectAssociation) {
+ return objectAssociation.getSpecification().getShortIdentifier();
+ }
+
+ public String getColumnName() {
+ return columnName;
+ }
+
+ public void setColumnName(final String columnName) {
+ this.columnName = columnName;
+ }
+
+ protected VersionMapping getVersionMapping() {
+ return versionMapping;
+ }
+
+ protected ObjectReferenceMapping getForeignKeyMapping() {
+ return foreignKeyMapping;
+ }
+
+ protected String getForeignKeyName() {
+ return foreignKeyName;
+ }
+
+ @Override
+ public void startup(final DatabaseConnector connector) {
+ if (originalMapping == null) {
+ originalMapping = objectMappingLookup.getMapping(specification, null);
+ }
+ originalMapping.startup(connector, objectMapperLookup2);
+ super.startup(connector);
+ }
+
+ @Override
+ public boolean needsTables(final DatabaseConnector connection) {
+ return !connection.hasColumn(table, foreignKeyName);
+ }
+
+ @Override
+ public void createTables(final DatabaseConnector connection) {
+ if (connection.hasTable(table)) {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("alter table ");
+ sql.append(table);
+ sql.append(" add ");
+ appendColumnDefinitions(sql);
+ connection.update(sql.toString());
+ } else {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("create table ");
+ sql.append(table);
+ sql.append(" (");
+ idMapping.appendCreateColumnDefinitions(sql);
+ sql.append(", ");
+
+ appendColumnDefinitions(sql);
+
+ // for (final FieldMapping mapping : fieldMappings) {
+ // mapping.appendColumnDefinitions(sql);
+ // sql.append(",");
+ // }
+ // sql.append(versionMapping.appendColumnDefinitions());
+ sql.append(")");
+ connection.update(sql.toString());
+ }
+ }
+
+ public IdMappingAbstract getIdMapping() {
+ return idMapping;
+ }
+
+ protected void appendCollectionUpdateColumnsToNull(final StringBuffer sql) {
+ sql.append(foreignKeyName + "=NULL ");
+ }
+
+ protected void appendCollectionWhereValues(final DatabaseConnector connector, final ObjectAdapter parent,
+ final StringBuffer sql) {
+ foreignKeyMapping.appendUpdateValues(connector, sql, parent);
+ }
+
+ protected void appendCollectionUpdateValues(final DatabaseConnector connector, final ObjectAdapter parent,
+ final StringBuffer sql) {
+ appendCollectionWhereValues(connector, parent, sql);
+ }
+
+ protected void appendColumnDefinitions(final StringBuffer sql) {
+ foreignKeyMapping.appendColumnDefinitions(sql);
+ }
+
+ @Override
+ public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter parentAdapter) {
+
+ final ObjectAdapter collectionAdapter = field.get(parentAdapter);
+ if (!collectionAdapter.canTransitionToResolving()) {
+ return;
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("loading internal collection " + field);
+ }
+ final List<ObjectAdapter> list = new ArrayList<ObjectAdapter>();
+ try {
+ PersistorUtil.startResolving(collectionAdapter);
+
+ loadCollectionIntoList(connector, parentAdapter, table, specification, getIdMapping(), fieldMappingByField,
+ versionMapping, list);
+
+ final CollectionFacet collectionFacet =
+ collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
+ collectionFacet.init(collectionAdapter, list.toArray(new ObjectAdapter[list.size()]));
+
+ } finally {
+ PersistorUtil.toEndState(collectionAdapter);
+ }
+
+ // TODO: Need to finalise this behaviour. At the moment, all
+ // collections will get infinitely resolved. I
+ // don't think this is desirable.
+ for (final ObjectAdapter field : list) {
+ // final ObjectMapping mapping =
+ // objectMappingLookup.getMapping(field, connector);
+ if (field.getSpecification().isOfType(parentAdapter.getSpecification())) {
+ loadInternalCollection(connector, field);
+ }
+ }
+ }
+
+ protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent,
+ final String table, final ObjectSpecification specification, final IdMappingAbstract idMappingAbstract,
+ final Map<ObjectAssociation, FieldMapping> fieldMappingByField, final VersionMapping versionMapping,
+ final List<ObjectAdapter> list) {
+
+ final StringBuffer sql = new StringBuffer();
+ sql.append("select ");
+ idMappingAbstract.appendColumnNames(sql);
+
+ sql.append(", ");
+ final String columnList = columnList(fieldMappingByField);
+ if (columnList.length() > 0) {
+ sql.append(columnList);
+ sql.append(", ");
+ }
+ sql.append(versionMapping.appendColumnNames());
+ sql.append(" from ");
+ sql.append(table);
+ sql.append(" where ");
+ appendCollectionWhereValues(connector, parent, sql);
+
+ final Results rs = connector.select(sql.toString());
+ while (rs.next()) {
+ final Oid oid = idMappingAbstract.recreateOid(rs, specification);
+ final ObjectAdapter element = getAdapter(specification, oid);
+ loadFields(element, rs, fieldMappingByField);
+ LOG.debug(" element " + element.getOid());
+ list.add(element);
+ }
+ rs.close();
+ }
+
+ protected void loadFields(final ObjectAdapter adapter, final Results rs,
+ final Map<ObjectAssociation, FieldMapping> fieldMappingByField) {
+ if (!adapter.canTransitionToResolving()) {
+ return;
+ }
+
+ try {
+ PersistorUtil.startResolving(adapter);
+ for (final FieldMapping mapping : fieldMappingByField.values()) {
+ mapping.initializeField(adapter, rs);
+ }
+ adapter.setVersion(versionMapping.getLock(rs));
+ } finally {
+ PersistorUtil.toEndState(adapter);
+ }
+ }
+
+ /**
+ * Override this in the Polymorphic case to return just the elements that are appropriate for the subclass currently
+ * being handled.
+ *
+ * @param collection
+ * @return those elements that ought to be used.
+ */
+ protected Iterator<ObjectAdapter> getElementsForCollectionAsIterator(final ObjectAdapter collection) {
+ final CollectionFacet collectionFacet = collection.getSpecification().getFacet(CollectionFacet.class);
+ final Iterable<ObjectAdapter> elements = collectionFacet.iterable(collection);
+ return elements.iterator();
+ }
+
+ @Override
+ public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent) {
+ final ObjectAdapter collection = field.get(parent);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Saving internal collection " + collection);
+ }
+
+ final Iterator<ObjectAdapter> elements = getElementsForCollectionAsIterator(collection);
+
+ // TODO What is needed to allow a collection update (add/remove) to mark
+ // the collection as dirty?
+ // checkIfDirty(collection);
+
+ if (elements.hasNext() == false) {
+ return;
+ }
+
+ clearCollectionParent(connector, parent);
+
+ resetCollectionParent(connector, parent, elements);
+ }
+
+ protected void clearCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent) {
+ // Delete collection parent
+ final StringBuffer sql = new StringBuffer();
+ sql.append("update ");
+ sql.append(table);
+ sql.append(" set ");
+ appendCollectionUpdateColumnsToNull(sql);
+ sql.append(" where ");
+ appendCollectionWhereValues(connector, parent, sql);
+ connector.update(sql.toString());
+ }
+
+ protected void resetCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent,
+ final Iterator<ObjectAdapter> elements) {
+ // Reinstall collection parent
+ final StringBuffer update = new StringBuffer();
+ update.append("update ");
+ update.append(table);
+ update.append(" set ");
+ appendCollectionUpdateValues(connector, parent, update);
+ update.append(" where ");
+
+ idMapping.appendColumnNames(update);
+
+ update.append(" IN (");
+
+ int count = 0;
+ for (final Iterator<ObjectAdapter> iterator = elements; iterator.hasNext();) {
+ final ObjectAdapter element = iterator.next();
+
+ if (count++ > 0) {
+ update.append(",");
+ }
+ final RootOid elementOid = (RootOid) element.getOid();
+ idMapping.appendObjectId(connector, update, elementOid);
+ }
+ update.append(")");
+ if (count > 0) {
+ connector.insert(update.toString());
+ }
+ }
+
+ protected void checkIfDirty(final ObjectAdapter collection) {
+ // Test: is dirty?
+ final ObjectSpecification collectionSpecification = collection.getSpecification();
+ if (collectionSpecification.isDirty(collection)) {
+ LOG.debug(collection.getOid() + " is dirty");
+ } else {
+ LOG.debug(collection.getOid() + " is clean");
+ }
+
+ final CollectionFacet collectionFacetD = collection.getSpecification().getFacet(CollectionFacet.class);
+ for (final ObjectAdapter element : collectionFacetD.iterable(collection)) {
+ if (collectionSpecification.isDirty(element)) {
+ LOG.debug(element.getOid() + " is dirty");
+ } else {
+ LOG.debug(element.getOid() + " is clean");
+ }
+ }
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln(field.getName(), "collection");
+ debug.indent();
+ debug.appendln("Foreign key name", foreignKeyName);
+ debug.appendln("Foreign key mapping", foreignKeyMapping);
+ debug.appendln("ID mapping", idMapping);
+ debug.appendln("Version mapping", versionMapping);
+ debug.appendln("Original mapping", originalMapping);
+ debug.unindent();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyInChildCollectionMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyInChildCollectionMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyInChildCollectionMapper.java
new file mode 100644
index 0000000..b289450
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyInChildCollectionMapper.java
@@ -0,0 +1,89 @@
+/*
+ * 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.isis.objectstore.sql.auto;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.specloader.specimpl.OneToManyAssociationImpl;
+import org.apache.isis.objectstore.sql.FieldMappingLookup;
+import org.apache.isis.objectstore.sql.ObjectMappingLookup;
+
+/**
+ * Used to map 1-to-many collections by creating, in the child table, 1 column
+ * per parent collection. The column is named by combining the final part of the
+ * parent class name and the collection variable name.
+ *
+ * @author Kevin
+ */
+public class ForeignKeyInChildCollectionMapper extends ForeignKeyCollectionMapper {
+ private static final Logger LOG = LoggerFactory.getLogger(ForeignKeyCollectionMapper.class);
+
+ protected final ObjectAssociation priorField; // prevents recursion
+ protected final List<ObjectAssociation> priorFields;
+
+ public ForeignKeyInChildCollectionMapper(final ObjectAssociation objectAssociation, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup, final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) {
+ super(objectAssociation, parameterBase, lookup, objectMapperLookup);
+
+ priorFields = abstractAutoMapper.fields;
+ priorField = field;
+
+ setUpFieldMappers();
+ }
+
+ protected ForeignKeyInChildCollectionMapper(final FieldMappingLookup lookup, final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) {
+ super(lookup, abstractAutoMapper, field);
+ priorFields = null;
+ priorField = null;
+ }
+
+ @Override
+ protected void getExtraFields(final List<ObjectAssociation> existingFields) {
+ if (priorFields != null) {
+ for (final ObjectAssociation priorField1 : priorFields) {
+ if (existingFields.contains(priorField1) == false) {
+ existingFields.add(priorField1);
+ } else {
+ LOG.debug("Skipping prior field: " + priorField1.getName());
+ }
+ }
+ }
+ }
+
+ @Override
+ protected String determineColumnName(final ObjectAssociation objectAssociation) {
+ if (objectAssociation instanceof OneToManyAssociationImpl) {
+ final OneToManyAssociationImpl fkAssoc = (OneToManyAssociationImpl) objectAssociation;
+ final FacetedMethod peer = fkAssoc.getFacetedMethod();
+ final String fullClassName = peer.getIdentifier().getClassName();
+ final int lastPos = fullClassName.lastIndexOf('.');
+ return fullClassName.substring(lastPos + 1) + "_" + fkAssoc.getId();
+ } else {
+ return objectAssociation.getSpecification().getShortIdentifier();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java
new file mode 100755
index 0000000..359a44d
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java
@@ -0,0 +1,237 @@
+/*
+ * 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.isis.objectstore.sql.auto;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.OidGenerator;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.FieldMappingLookup;
+import org.apache.isis.objectstore.sql.IdMappingAbstract;
+import org.apache.isis.objectstore.sql.ObjectMapping;
+import org.apache.isis.objectstore.sql.ObjectMappingLookup;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.VersionMapping;
+import org.apache.isis.objectstore.sql.jdbc.JdbcPolymorphicObjectReferenceMapping;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+/**
+ * Used to map 1-to-many collections by creating, in the collection child table (which may be an interface or abstract
+ * class), 2 columns per parent collection. The first column is the class type, the second is the entity ID. The columns
+ * are named by combining the final part of the parent class name and the collection variable name.
+ *
+ * You have a choice between this class and {@link PolymorphicForeignKeyInChildCollectionMapper}
+ *
+ * @author Kevin
+ */
+public class PolymorphicForeignKeyInChildCollectionBaseMapper extends ForeignKeyInChildCollectionMapper {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PolymorphicForeignKeyInChildCollectionBaseMapper.class);
+
+ private final String classColumnName;
+ private final String itemIdColumnName;
+ private final IdMappingAbstract polyIdMapper;
+
+ private final OidGenerator oidGenerator;
+
+ public PolymorphicForeignKeyInChildCollectionBaseMapper(final ObjectAssociation objectAssociation,
+ final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup,
+ final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) {
+
+ super(objectAssociation, parameterBase, lookup, objectMapperLookup, abstractAutoMapper, field);
+
+ classColumnName = Sql.identifier(Sql.sqlName(getForeignKeyName() + "_cls"));
+ itemIdColumnName = Sql.identifier("item_id");
+
+ polyIdMapper = new JdbcPolymorphicObjectReferenceMapping(itemIdColumnName);
+ oidGenerator = IsisContext.getPersistenceSession().getOidGenerator();
+ }
+
+ @Override
+ public boolean needsTables(final DatabaseConnector connection) {
+ return super.needsTables(connection) || !connection.hasColumn(table, classColumnName);
+ }
+
+ @Override
+ public void createTables(final DatabaseConnector connection) {
+ if (super.needsTables(connection)) {
+ super.createTables(connection);
+ }
+
+ if (!connection.hasColumn(table, classColumnName)) {
+ addColumn(connection, classColumnName, Defaults.TYPE_LONG_STRING());
+ addColumn(connection, itemIdColumnName, Defaults.TYPE_PK());
+ }
+ }
+
+ protected void addColumn(final DatabaseConnector connection, final String columnName, final String columnType) {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("alter table ");
+ sql.append(table);
+ sql.append(" add ");
+ sql.append(columnName);
+ sql.append(" ");
+ sql.append(columnType);
+ connection.update(sql.toString());
+ }
+
+ @Override
+ protected void appendCollectionUpdateColumnsToNull(final StringBuffer sql) {
+ super.appendCollectionUpdateColumnsToNull(sql);
+ sql.append(", " + classColumnName + "=NULL ");
+ }
+
+ @Override
+ protected void appendCollectionUpdateValues(final DatabaseConnector connector, final ObjectAdapter parent,
+ final StringBuffer sql) {
+ super.appendCollectionUpdateValues(connector, parent, sql);
+ }
+
+ @Override
+ protected void appendColumnDefinitions(final StringBuffer sql) {
+ super.appendColumnDefinitions(sql);
+ }
+
+ @Override
+ protected void clearCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent) {
+ // Delete collection parent
+ final StringBuffer sql = new StringBuffer();
+ sql.append("DELETE FROM ");
+ sql.append(table);
+ sql.append(" WHERE ");
+ appendCollectionWhereValues(connector, parent, sql);
+ connector.update(sql.toString());
+ }
+
+ @Override
+ protected void resetCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent,
+ final Iterator<ObjectAdapter> elements) {
+ LOG.debug("Saving polymorphic list");
+
+ ObjectSpecification elementSpecification;
+ while (elements.hasNext()) {
+ final ObjectAdapter thisAdapter = elements.next();
+ elementSpecification = thisAdapter.getSpecification();
+
+ // Reinstall collection parent
+ final StringBuffer update = new StringBuffer();
+ update.append("INSERT INTO ");
+ update.append(table);
+ update.append(" (");
+ // list of column names
+ super.getIdMapping().appendColumnNames(update);
+ update.append("," + getForeignKeyName());
+ update.append(", " + itemIdColumnName);
+ update.append("," + classColumnName);
+ update.append(") VALUES (");
+
+ // Row ID column
+ final Object pojo = thisAdapter.getObject();
+ final RootOid transientRootOid = oidGenerator.createTransientOid(pojo);
+
+ final RootOid persistentRootOid = oidGenerator.createPersistent(pojo, transientRootOid);
+
+ polyIdMapper.appendObjectId(connector, update, persistentRootOid);
+
+ // polyIdMapper.appendObjectId(connector, update,
+ // thisAdapter.getOid());
+ update.append(",");
+
+ // Foreign key ID column
+ getForeignKeyMapping().appendInsertValues(connector, update, parent);
+ update.append(",");
+
+ // item Id column
+ final RootOid oid = (RootOid) thisAdapter.getOid();
+ getIdMapping().appendObjectId(connector, update, oid);
+
+ // Class name column
+ update.append(",?)");
+ connector.addToQueryValues(elementSpecification.getFullIdentifier());
+
+ connector.insert(update.toString());
+ }
+ }
+
+ @Override
+ public IdMappingAbstract getIdMapping() {
+ return polyIdMapper;
+ }
+
+ @Override
+ protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent,
+ final String table, final ObjectSpecification specification, final IdMappingAbstract idMappingAbstract,
+ final Map<ObjectAssociation, FieldMapping> fieldMappingByField, final VersionMapping versionMapping,
+ final List<ObjectAdapter> list) {
+ LOG.debug("Loading polymorphic list");
+
+ final StringBuffer sql = new StringBuffer();
+ sql.append("select ");
+ super.getIdMapping().appendColumnNames(sql);
+
+ sql.append("," + getForeignKeyName());
+ sql.append("," + classColumnName);
+ sql.append("," + itemIdColumnName);
+
+ sql.append(" from ");
+ sql.append(table);
+ sql.append(" where ");
+ appendCollectionWhereValues(connector, parent, sql);
+
+ final Results rs = connector.select(sql.toString());
+
+ final SpecificationLoaderSpi reflector = IsisContext.getSpecificationLoader();
+ final JdbcPolymorphicObjectReferenceMapping idMapping =
+ (JdbcPolymorphicObjectReferenceMapping) idMappingAbstract;
+
+ while (rs.next()) {
+ final ObjectSpecification itemSpecification = reflector.loadSpecification(rs.getString(classColumnName));
+ idMapping.setObjectSpecification(itemSpecification);
+
+ // Load new recordSet for the actual class
+ final ObjectMapping itemMapper = objectMappingLookup.getMapping(itemSpecification, connector);
+ final TypedOid oid = idMapping.recreateOid(rs, itemSpecification);
+ final ObjectAdapter loadedObject = itemMapper.getObject(connector, oid);
+
+ LOG.debug(" element " + loadedObject.getOid());
+
+ list.add(loadedObject);
+ }
+ rs.close();
+
+ }
+}
[08/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestFixtures.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestFixtures.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestFixtures.java
deleted file mode 100644
index ada7051..0000000
--- a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestFixtures.java
+++ /dev/null
@@ -1,230 +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.isis.objectstore.sql.common;
-
-import java.io.FileInputStream;
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.List;
-import java.util.Properties;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.config.IsisConfigurationDefault;
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
-import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures.Fixtures.Initialization;
-import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
-import org.apache.isis.core.tck.dom.poly.ReferencingPolyTypesEntity;
-import org.apache.isis.core.tck.dom.scalars.PrimitiveValuedEntity;
-import org.apache.isis.core.tck.dom.sqlos.SqlDomainObjectRepository;
-import org.apache.isis.core.tck.dom.sqlos.data.SimpleClass;
-import org.apache.isis.core.tck.dom.sqlos.data.SimpleClassTwo;
-import org.apache.isis.core.tck.dom.sqlos.data.SqlDataClass;
-import org.apache.isis.objectstore.sql.SqlObjectStore;
-
-/**
- * @author Kevin
- *
- */
-public class SqlIntegrationTestFixtures {
-
- static SqlIntegrationTestFixtures instance;
-
- public static SqlIntegrationTestFixtures getInstance() {
- if (instance == null) {
- instance = new SqlIntegrationTestFixtures();
- }
- return instance;
- }
-
- public static void recreate() {
- instance = new SqlIntegrationTestFixtures();
- }
-
- public enum State {
- INITIALIZE, DONT_INITIALIZE;
-
- public boolean isInitialize() {
- return this == INITIALIZE;
- }
- }
-
- private State state = State.INITIALIZE;
-
- public State getState() {
- return state;
- }
-
- public void setState(final State state) {
- this.state = state;
- }
-
- // /////////////////////////////////////////////////////////////////////////
- //
- // /////////////////////////////////////////////////////////////////////////
-
- private IsisSystemWithFixtures system;
-
- // JDBC
- private Connection conn = null;
- private Statement stmt = null;
-
- public void initSystem(final String propertiesDirectory, final String propertiesFileName) throws Exception {
-
- final Properties properties = new Properties();
- properties.load(new FileInputStream(propertiesDirectory + "/" + propertiesFileName));
-
- initSystem(properties);
- }
-
- public void initSystem(final Properties properties) throws Exception {
- final IsisConfigurationDefault configuration = new IsisConfigurationDefault();
- configuration.add(properties);
-
- sqlDomainObjectRepository = new SqlDomainObjectRepository();
- if (system != null) {
- system.tearDownSystem();
- }
-
- final PersistenceMechanismInstallerAbstract persistorInstaller = Utils.createPersistorInstaller(configuration);
- system =
- IsisSystemWithFixtures.builder().with(configuration).withServices(sqlDomainObjectRepository)
- .with(Initialization.NO_INIT).with(persistorInstaller).build();
-
- system.setUpSystem();
-
- registerDriverAndConnect(configuration);
- }
-
- public void shutDown() throws Exception {
- if (system != null) {
- system.tearDownSystem();
- }
- }
-
- // /////////////////////////////////////////////////////////////////////////
- //
- // /////////////////////////////////////////////////////////////////////////
-
- @SuppressWarnings("unchecked")
- private void registerDriverAndConnect(final IsisConfiguration isisConfiguration) throws SQLException,
- ClassNotFoundException, InstantiationException, IllegalAccessException {
- final String jdbcClassName = isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.driver");
- if (jdbcClassName == null) {
- conn = null;
- stmt = null;
- return;
- }
- final Class<Driver> driverClass = (Class<Driver>) Class.forName(jdbcClassName);
- final Driver driver = driverClass.newInstance();
- DriverManager.registerDriver(driver);
-
- // jdbc - connect to DB and drop tables.
- conn =
- DriverManager.getConnection(isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.connection"),
- isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.user"),
- isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.password"));
- stmt = conn.createStatement();
- }
-
- public void dropTable(final String tableName) {
- if (stmt == null) {
- if (tableName.equalsIgnoreCase("sqldataclass")) {
- final List<SqlDataClass> list = sqlDomainObjectRepository.allDataClasses();
- for (final SqlDataClass sqlDataClass : list) {
- sqlDomainObjectRepository.delete(sqlDataClass);
- }
- return;
- }
- if (tableName.equalsIgnoreCase("simpleclass")) {
- final List<SimpleClass> list = sqlDomainObjectRepository.allSimpleClasses();
- for (final SimpleClass sqlClass : list) {
- sqlDomainObjectRepository.delete(sqlClass);
- }
- return;
- }
- if (tableName.equalsIgnoreCase("simpleclasstwo")) {
- final List<SimpleClassTwo> list = sqlDomainObjectRepository.allSimpleClassTwos();
- for (final SimpleClassTwo sqlClass : list) {
- sqlDomainObjectRepository.delete(sqlClass);
- }
- return;
- }
- if (tableName.equalsIgnoreCase("primitivevaluedentity")) {
- final List<PrimitiveValuedEntity> list = sqlDomainObjectRepository.allPrimitiveValueEntities();
- for (final PrimitiveValuedEntity pve : list) {
- sqlDomainObjectRepository.delete(pve);
- }
- return;
- }
- throw new IsisException("Unknown table: " + tableName);
- }
-
- try {
- String tableIdentifier = Utils.tableIdentifierFor(tableName);
- stmt.executeUpdate("DROP TABLE " + tableIdentifier);
- } catch (final SQLException e) {
- // this can happen, not a problem.
- // e.printStackTrace();
- }
- }
-
- public void sqlExecute(final String sqlString) throws SQLException {
- if (stmt != null) {
- stmt.executeUpdate(sqlString);
- }
- }
-
- // /////////////////////////////////////////////////////////////////////////
- //
- // /////////////////////////////////////////////////////////////////////////
-
- private SqlDomainObjectRepository sqlDomainObjectRepository = null;
-
- private SqlDataClass sqlDataClass;
- private ReferencingPolyTypesEntity referencingPolyTypesEntity;
-
- public SqlDomainObjectRepository getSqlDataClassFactory() {
- return sqlDomainObjectRepository;
- }
-
- public SqlDataClass getSqlDataClass() {
- return sqlDataClass;
- }
-
- public void setSqlDataClass(SqlDataClass sqlDataClass) {
- this.sqlDataClass = sqlDataClass;
- }
-
- public ReferencingPolyTypesEntity getPolyTestClass() {
- return referencingPolyTypesEntity;
- }
-
- public void setPolyTestClass(final ReferencingPolyTypesEntity referencingPolyTypesEntity) {
- this.referencingPolyTypesEntity = referencingPolyTypesEntity;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Utils.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Utils.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Utils.java
deleted file mode 100644
index c037e61..0000000
--- a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Utils.java
+++ /dev/null
@@ -1,61 +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.isis.objectstore.sql.common;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.objectstore.InMemoryPersistenceMechanismInstaller;
-import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.SqlObjectStore;
-import org.apache.isis.objectstore.sql.SqlPersistorInstaller;
-import org.apache.isis.objectstore.xml.XmlPersistenceMechanismInstaller;
-
-public class Utils {
-
- static PersistenceMechanismInstallerAbstract createPersistorInstaller(final IsisConfiguration configuration) {
-
- final String jdbcDriver = configuration.getString(SqlObjectStore.BASE_NAME + ".jdbc.driver");
- if (jdbcDriver != null) {
- return new SqlPersistorInstaller();
- }
-
- final String persistor = configuration.getString("isis.persistor");
- if (persistor.equals(InMemoryPersistenceMechanismInstaller.NAME)) {
- return new InMemoryPersistenceMechanismInstaller();
- }
- if (persistor.equals(XmlPersistenceMechanismInstaller.NAME)) {
- return new XmlPersistenceMechanismInstaller();
- }
- if (persistor.equals(SqlPersistorInstaller.NAME)) {
- return new SqlPersistorInstaller();
- }
- return new InMemoryPersistenceMechanismInstaller();
- }
-
- static String tableIdentifierFor(final String tableName) {
- if (tableName.substring(0, 4).toUpperCase().equals("ISIS")) {
- return Sql.tableIdentifier(tableName);
- } else {
- return Sql.tableIdentifier("isis_" + tableName);
- }
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties b/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties
deleted file mode 100644
index b36337f..0000000
--- a/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,39 +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.
-# apache's log4j is used to provide system logging.
-log4j.rootCategory=DEBUG, File
-log4j.rootCategory=INFO, Console
-
-
-# The console appender
-log4j.appender.Console=org.apache.log4j.ConsoleAppender
-log4j.appender.Console.target=System.out
-log4j.appender.Console.layout=org.apache.log4j.PatternLayout
-log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} [%-20c{1} %-10t %-5p] %m%n
-
-
-log4j.appender.File=org.apache.log4j.RollingFileAppender
-log4j.appender.File.file=isis.log
-log4j.appender.File.append=false
-#log4j.appender.File.maxFileSize=500KB
-#log4j.appender.File.maxBackupIndex=1
-log4j.appender.File.layout=org.apache.log4j.PatternLayout
-log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
-
-
-
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt b/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt
deleted file mode 100644
index 025703e..0000000
--- a/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt
+++ /dev/null
@@ -1,28 +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.
-
-
-
-SQL ObjectStore Integration Tests
-
- This module holds the integration tests for the {{{../index.html}SQL ObjectStore}}.
-
-Further Info
-
- See this module's {{{./apidocs/index.html}Javadoc}} and {{{../docbkx/html/guide/isis-sql-objectstore.html}User Guide}} for more information.
-
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt b/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt
deleted file mode 100644
index c5d1200..0000000
--- a/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt
+++ /dev/null
@@ -1,24 +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.
-
-
-
-Jottings
-
- This page is to capture any random jottings relating to this module prior
- to being moved into formal documentation.
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/site/site.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/site/site.xml b/component/objectstore/sql/sql-tests-common/src/site/site.xml
deleted file mode 100644
index 9aa405b..0000000
--- a/component/objectstore/sql/sql-tests-common/src/site/site.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project>
-
- <body>
- <breadcrumbs>
- <item name="Tests" href="index.html"/>
- </breadcrumbs>
-
- <menu name="SQL Objectstore Tests">
- <item name="About" href="index.html" />
- </menu>
-
- <menu name="SQL OS Modules">
- <item name="Implementation" href="../sql-impl/index.html" />
- <item name="Tests" href="../sql-tests-common/index.html" />
- <item name="Integration Tests" href="../sql-tests-served/index.html" />
- </menu>
-
- <menu name="Maven Reports" ref="reports" />
- </body>
-</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties b/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties
deleted file mode 100644
index cd5ea6e..0000000
--- a/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties
+++ /dev/null
@@ -1,29 +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.
-isis.persistor=sql
-
-isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver
-isis.persistor.sql.jdbc.connection=jdbc:hsqldb:file:hsql-db/polytests
-isis.persistor.sql.jdbc.user=sa
-isis.persistor.sql.jdbc.password=
-
-# testing
-isis.logging.objectstore=on
-isis.persistor.sql.default.command.beginTransaction=
-isis.persistor.sql.default.command.commitTransaction=
-isis.persistor.sql.default.command.abortTransaction=
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties b/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties
deleted file mode 100644
index 22c9758..0000000
--- a/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties
+++ /dev/null
@@ -1,33 +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.
-isis.persistor=sql
-
-isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver
-isis.persistor.sql.jdbc.connection=jdbc:hsqldb:file:hsql-db/tests
-isis.persistor.sql.jdbc.user=sa
-isis.persistor.sql.jdbc.password=
-
-# testing
-isis.persistor.sql.datatypes.string=VARCHAR(70)
-isis.persistor.sql.default.password.seed=gfkhgdf76453fhgj#$
-isis.persistor.sql.default.command.beginTransaction=
-isis.persistor.sql.default.command.commitTransaction=
-isis.persistor.sql.default.command.abortTransaction=
-
-isis.persistor.sql.datatypes.blob=BLOB(1000)
-
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java
deleted file mode 100644
index 17b9bfc..0000000
--- a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java
+++ /dev/null
@@ -1,72 +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.isis.objectstore.sql;
-
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.runners.MethodSorters;
-
-import org.apache.isis.core.unittestsupport.files.Files;
-import org.apache.isis.core.unittestsupport.files.Files.Recursion;
-import org.apache.isis.objectstore.sql.common.Data;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestData;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures;
-
-/**
- * @author Kevin kevin@kmz.co.za
- *
- * This test implementation uses the HyperSQL database engine to perform "serverless" tests of data creation and
- * reloading.
- *
- *
- * @version $Rev$ $Date$
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class HsqlTest extends SqlIntegrationTestData {
-
- @BeforeClass
- public static void deleteHsqlDbFiles() {
- Files.deleteFilesWithPrefix("hsql-db", "tests", Recursion.DONT_RECURSE);
- }
-
- @Override
- protected void testCreate() throws Exception {
- final SqlIntegrationTestFixtures sqlIntegrationTestFixtures = getSqlIntegrationTestFixtures();
- for (final String tableName : Data.getTableNames()) {
- sqlIntegrationTestFixtures.dropTable(tableName);
- }
- super.testCreate();
- }
-
- // @Override
- // protected String getSqlSetupString() {
- // return "COMMIT;";
- // }
-
- @Override
- public String getPropertiesFilename() {
- return "hsql.properties";
- }
-
- @Override
- public String getSqlTeardownString() {
- return "SHUTDOWN;";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java
deleted file mode 100755
index 49039e5..0000000
--- a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java
+++ /dev/null
@@ -1,374 +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.isis.objectstore.sql;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.tck.dom.poly.Empty;
-import org.apache.isis.core.tck.dom.poly.EmptyEntityWithOwnProperty;
-import org.apache.isis.core.tck.dom.poly.ReferencingPolyTypesEntity;
-import org.apache.isis.core.tck.dom.poly.SelfReferencingEntity;
-import org.apache.isis.core.tck.dom.poly.StringBaseEntity;
-import org.apache.isis.core.tck.dom.poly.StringBaseEntitySub;
-import org.apache.isis.core.tck.dom.poly.StringBaseEntitySubThree;
-import org.apache.isis.core.tck.dom.poly.StringBaseEntitySubTwo;
-import org.apache.isis.core.tck.dom.poly.Stringable;
-import org.apache.isis.core.tck.dom.poly.StringableEntityWithOwnDerivedProperty;
-import org.apache.isis.core.tck.dom.poly.StringableEntityWithOwnProperties;
-import org.apache.isis.core.tck.dom.poly.StringableEntityWithOwnProperty;
-import org.apache.isis.core.unittestsupport.files.Files;
-import org.apache.isis.core.unittestsupport.files.Files.Recursion;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestCommonBase;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures.State;
-
-/**
- * @author Kevin kevin@kmz.co.za
- *
- * This test implementation uses the HyperSQL database engine to perform "serverless" tests of polymorphic class
- * object creation and reloading.
- *
- * The sql object store thus allows your domain objects to have properties referenced via interface or
- * superclass. Both single reference properties and property collections are supported.
- *
- *
- * @version $Rev$ $Date$
- */
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class PolymorphismTest extends SqlIntegrationTestCommonBase {
-
- private static final String IMPL_A_STRING = "Impl A String";
- private static final String IMPL_B_STRING = "Impl B String";
- private static final String CHILD_1 = "Child 1";
-
- private static StringableEntityWithOwnProperty polyIntImpA;
- private static StringableEntityWithOwnProperties polyIntImpB;
-
- @Override
- public String getPropertiesFilename() {
- return "hsql-poly.properties";
- }
-
- @BeforeClass
- public static void deleteHsqlDbFiles() {
- Files.deleteFilesWithPrefix("hsql-db", "poly", Recursion.DONT_RECURSE);
- }
-
- @Override
- public void resetPersistenceStoreDirectlyIfRequired() {
- getSqlIntegrationTestFixtures();
- }
-
- @Override
- public String getSqlTeardownString() {
- return "SHUTDOWN;";
- }
-
- // Order is important. The next three "tests" must be executed in the correct sequential order.
- @Test
- /**
- * Sets up the database connection and tells the test framework to create an instance of the
- * Isis framework for the next "test".
- */
- public void test1SetupStoreAndDatabaseConnection() throws Exception {
- testSetup();
- }
-
- @Before
- public void setUpXactn() throws Exception {
- IsisContext.getTransactionManager().startTransaction();
- }
-
- @After
- public void tearDownXactn() throws Exception {
- IsisContext.getTransactionManager().endTransaction();
- assertThat(IsisContext.getTransactionManager().getTransaction().getState().isComplete(), is(true));
-
- }
-
- @Test
- /**
- * Uses the database connection to drop database tables related to these tests.
- * This forces (and exercises the ability of) the object store to re-create the tables.
- *
- * Also uses factory methods within the Isis framework to create the test data,
- * thus exercising the "create data" portion of the object store.
- *
- * The Isis framework will be again be re-created in the next test unless the
- * object store is "in-memory" (this is required since "in-memory" has to be
- * left alone for created data to still be present in the next test).
- */
- public void test2SetupDataWithDatabaseConnection() throws Exception {
- final SqlIntegrationTestFixtures sqlIntegrationTestFixtures = getSqlIntegrationTestFixtures();
- sqlIntegrationTestFixtures.dropTable("ISIS_SELFREFERENCINGENTITY");
- sqlIntegrationTestFixtures.dropTable("ISIS_STRINGABLEENTITYWITHOWNPROPERTY");
- sqlIntegrationTestFixtures.dropTable("ISIS_STRINGABLEENTITYWITHOWNPROPERTIES");
- sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITYSUB");
- sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITYSUBTWO");
- sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITYSUBTHREE");
- sqlIntegrationTestFixtures.dropTable("ISIS_REFERENCINGPOLYTYPESENTITY");
- sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITY");
- sqlIntegrationTestFixtures.dropTable("ISIS_STRINGABLE");
-
- final ReferencingPolyTypesEntity referencingPolyTypesEntity = factory.newPolyTestClass();
- referencingPolyTypesEntity.setString("polyTestClassString");
-
- // Setup self-referencing collection
- final SelfReferencingEntity polySelfRefClassParent = factory.newPolySelfRefClass();
- polySelfRefClassParent.setString("Parent");
-
- final SelfReferencingEntity polySelfRefClassChild1 = factory.newPolySelfRefClass();
- polySelfRefClassChild1.setString(CHILD_1);
- polySelfRefClassParent.addToPolySelfRefClasses(polySelfRefClassChild1);
-
- final SelfReferencingEntity polySelfRefClassChild2 = factory.newPolySelfRefClass();
- polySelfRefClassChild2.setString("Child 2");
- polySelfRefClassParent.addToPolySelfRefClasses(polySelfRefClassChild2);
- factory.save(polySelfRefClassChild2);
-
- final SelfReferencingEntity polySelfRefClassChild3 = factory.newPolySelfRefClass();
- polySelfRefClassChild3.setString("Child 1 of Child 1");
- polySelfRefClassChild1.addToPolySelfRefClasses(polySelfRefClassChild3);
-
- factory.save(polySelfRefClassChild3);
- factory.save(polySelfRefClassChild1);
-
- factory.save(polySelfRefClassParent);
- referencingPolyTypesEntity.setPolySelfRefClass(polySelfRefClassParent);
-
- // polyTestClass.setPolyTestInterface(polyTestClass);
-
- polyIntImpA = factory.newPolyInterfaceImplA();
- polyIntImpA.setString(IMPL_A_STRING);
- polyIntImpA.setSpecial("special");
- factory.save(polyIntImpA);
-
- referencingPolyTypesEntity.setPolyInterfaceType(polyIntImpA);
- referencingPolyTypesEntity.getPolyInterfaces().add(polyIntImpA);
-
- // setup the polyTestClass
- final StringBaseEntitySub stringBaseEntitySub = factory.newPolySubClassOne();
- stringBaseEntitySub.setStringBase("PolySubClassOne 1");
- stringBaseEntitySub.setStringClassOne("Class 1");
-
- final StringBaseEntitySubTwo stringBaseEntitySubTwo = factory.newPolySubClassTwo();
- stringBaseEntitySubTwo.setStringBase("PolySubClassTwo 1");
- stringBaseEntitySubTwo.setStringClassTwo("Class 2");
-
- final StringBaseEntitySubThree stringBaseEntitySubThree = factory.newPolySubClassThree();
- stringBaseEntitySubThree.setStringBase("PolySubClassThree 1");
- stringBaseEntitySubThree.setStringClassThree("Another String");
- stringBaseEntitySubThree.setStringClassTwo("Class 3");
-
- referencingPolyTypesEntity.getPolyBaseClasses().add(stringBaseEntitySub);
- referencingPolyTypesEntity.getPolyBaseClasses().add(stringBaseEntitySubTwo);
- referencingPolyTypesEntity.getPolyBaseClasses().add(stringBaseEntitySubThree);
-
- factory.save(stringBaseEntitySub);
- factory.save(stringBaseEntitySubTwo);
- factory.save(stringBaseEntitySubThree);
-
- // store it and step the state engine
- factory.save(referencingPolyTypesEntity);
-
- setFixtureInitializationState(State.DONT_INITIALIZE, "in-memory");
- }
-
- /**
- * The actual "tests". Unless the test is using the "in-memory" object store
- * the Isis framework is re-created, thus ensuring that no domain objects are
- * left over from the previous "create" step, forcing the objects to be created
- * via the object store.
- *
- * Exercises the "restore data" portion of the object store.
- *
- * Confirms that polymorphic classes are loaded as expected (via interface,
- * via super-class, etc.)
- */
- @Test
- public void test3All() throws Exception {
- load();
-
- setUpFactory();
-
- polymorphicLoad();
- interfaceLoad();
- loadSelfReferencingCollection();
- interfaceLoadProperty();
- interfaceLoadCollection();
- interfaceEditSave();
- interfaceEditLoad();
- allInterfacesInstancesLoaded();
- interfacesLoadedByQuery();
- interfacesLoadedByQuerySpecial();
- findByMatchPartialEntity();
- cannotFindByMatchWithWrongValue();
-
- // Must be here so that the Isis framework is initialised for the next test package.
- setFixtureInitializationState(State.INITIALIZE);
- }
-
- private void load() {
- final List<ReferencingPolyTypesEntity> dataClasses = factory.allPolyTestClasses();
- assertEquals(1, dataClasses.size());
- final ReferencingPolyTypesEntity referencingPolyTypesEntity = dataClasses.get(0);
-
- getSqlIntegrationTestFixtures().setPolyTestClass(referencingPolyTypesEntity);
-
- setFixtureInitializationState(State.DONT_INITIALIZE);
- }
-
- private void polymorphicLoad() {
- final List<StringBaseEntity> polyBaseClasses = referencingPolyTypesEntity.getPolyBaseClasses();
- assertEquals(3, polyBaseClasses.size());
-
- StringBaseEntity polyClassBase = polyBaseClasses.get(0);
- assertTrue(polyClassBase instanceof StringBaseEntitySub);
- assertEquals("PolySubClassOne 1", polyClassBase.getStringBase());
- final StringBaseEntitySub stringBaseEntitySub = (StringBaseEntitySub) polyClassBase;
- assertEquals("Class 1", stringBaseEntitySub.getStringClassOne());
-
- polyClassBase = polyBaseClasses.get(1);
- assertTrue(polyClassBase instanceof StringBaseEntitySubTwo);
- final StringBaseEntitySubTwo stringBaseEntitySubTwo = (StringBaseEntitySubTwo) polyClassBase;
- assertEquals("Class 2", stringBaseEntitySubTwo.getStringClassTwo());
-
- polyClassBase = polyBaseClasses.get(2);
- assertTrue(polyClassBase instanceof StringBaseEntitySubThree);
- final StringBaseEntitySubThree stringBaseEntitySubThree = (StringBaseEntitySubThree) polyClassBase;
- assertEquals("Class 3", stringBaseEntitySubThree.getStringClassTwo());
- assertEquals("Another String", stringBaseEntitySubThree.getStringClassThree());
- }
-
- private void interfaceLoad() {
- final Stringable loaded = referencingPolyTypesEntity.getPolyInterfaceType();
- factory.resolve(loaded);
- assertEquals(polyIntImpA.getString(), loaded.getString());
- }
-
- private void loadSelfReferencingCollection() {
- final SelfReferencingEntity polySelfRefParent = referencingPolyTypesEntity.getPolySelfRefClass();
- final List<SelfReferencingEntity> list = polySelfRefParent.getPolySelfRefClasses();
- assertEquals(2, list.size());
-
- SelfReferencingEntity polySelfRefChild1 = null;
- for (final SelfReferencingEntity selfReferencingEntity : list) {
- if (selfReferencingEntity.getString().equals(CHILD_1)) {
- polySelfRefChild1 = selfReferencingEntity;
- }
- }
- assertNotNull(polySelfRefChild1);
-
- assertEquals(CHILD_1, polySelfRefChild1.title());
-
- List<SelfReferencingEntity> list2 = polySelfRefChild1.getPolySelfRefClasses();
- factory.resolve(polySelfRefChild1);
- list2 = polySelfRefChild1.getPolySelfRefClasses();
- assertEquals(1, list2.size());
- }
-
- private void interfaceLoadProperty() {
- final Stringable loaded = referencingPolyTypesEntity.getPolyInterfaceType();
- assertEquals(polyIntImpA.getString(), loaded.getString());
- }
-
- private void interfaceLoadCollection() {
- final List<Stringable> list = referencingPolyTypesEntity.getPolyInterfaces();
-
- assertEquals(1, list.size());
- final Stringable loaded = list.get(0);
-
- assertEquals(polyIntImpA.getString(), loaded.getString());
- }
-
- private void interfaceEditSave() {
- polyIntImpB = factory.newPolyInterfaceImplB();
- polyIntImpB.setString(IMPL_B_STRING);
- polyIntImpB.setSpecial("special");
- polyIntImpB.setInteger(1);
-
- factory.save(polyIntImpB);
-
- referencingPolyTypesEntity.setPolyInterfaceType(polyIntImpB);
-
- setFixtureInitializationState(State.INITIALIZE);
- }
-
- private void interfaceEditLoad() {
- load(); // reload data
-
- final Stringable loaded = referencingPolyTypesEntity.getPolyInterfaceType();
- assertEquals(polyIntImpB.getString(), loaded.getString());
- }
-
- private void allInterfacesInstancesLoaded() {
- final List<Stringable> list = factory.allPolyInterfaces();
- assertEquals(2, list.size());
- }
-
- private void interfacesLoadedByQuery() {
- // PolyInterface query = polyIntImpA;
-
- final StringableEntityWithOwnDerivedProperty query = new StringableEntityWithOwnDerivedProperty();
- query.setString(IMPL_A_STRING);
-
- final List<Stringable> list = factory.queryPolyInterfaces(query);
- assertEquals(1, list.size());
- }
-
- private void interfacesLoadedByQuerySpecial() {
-
- final StringableEntityWithOwnDerivedProperty query = new StringableEntityWithOwnDerivedProperty();
-
- final List<Stringable> list = factory.queryPolyInterfaces(query);
- assertEquals(2, list.size());
- }
-
- private void findByMatchPartialEntity() {
- final Empty match = new EmptyEntityWithOwnProperty();
- final List<Empty> matches = factory.allEmptyInterfacesThatMatch(match);
- assertEquals(1, matches.size());
-
- final Empty empty = matches.get(0);
- final StringableEntityWithOwnProperties imp = (StringableEntityWithOwnProperties) empty;
- assertEquals(IMPL_B_STRING, imp.getString());
- }
-
- private void cannotFindByMatchWithWrongValue() {
- final StringableEntityWithOwnProperties match = new StringableEntityWithOwnProperties();
- match.setInteger(0);
- final List<Empty> matches = factory.allEmptyInterfacesThatMatch(match);
- assertEquals(0, matches.size());
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/InMemoryPersistenceTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/InMemoryPersistenceTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/InMemoryPersistenceTest.java
deleted file mode 100644
index 4885b77..0000000
--- a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/InMemoryPersistenceTest.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.isis.objectstore.sql.crosscheck;
-
-import java.util.Properties;
-
-import org.junit.FixMethodOrder;
-import org.junit.runners.MethodSorters;
-
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestData;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures.State;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class InMemoryPersistenceTest extends SqlIntegrationTestData {
-
- @Override
- public Properties getProperties() {
- final Properties properties = new Properties();
- properties.put("isis.persistor", "in-memory");
- properties.put("isis.logging.objectstore", "off");
- return properties;
- }
-
- @Override
- protected void testSetup() {
- resetPersistenceStoreDirectlyIfRequired();
- SqlIntegrationTestFixtures.recreate();
- try {
- SqlIntegrationTestFixtures.getInstance().initSystem(getProperties());
- } catch (Exception e) {
- e.printStackTrace();
- }
- getSqlIntegrationTestFixtures().setState(State.INITIALIZE);
- }
-
- @Override
- public String getPropertiesFilename() {
- return "inmemory.properties";
- }
-
- @Override
- public String getSqlTeardownString() {
- return "SHUTDOWN;";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/XmlPersistenceTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/XmlPersistenceTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/XmlPersistenceTest.java
deleted file mode 100644
index 1916a95..0000000
--- a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/crosscheck/XmlPersistenceTest.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.isis.objectstore.sql.crosscheck;
-
-import java.util.Properties;
-
-import org.apache.isis.core.unittestsupport.files.Files;
-import org.apache.isis.core.unittestsupport.files.Files.Recursion;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestData;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures.State;
-
-public class XmlPersistenceTest extends SqlIntegrationTestData {
-
- @Override
- public void resetPersistenceStoreDirectlyIfRequired() {
- Files.deleteFiles("xml/objects", ".xml", Recursion.DO_RECURSE);
- }
-
- @Override
- protected void testSetup() {
- resetPersistenceStoreDirectlyIfRequired();
- SqlIntegrationTestFixtures.recreate();
- try {
- SqlIntegrationTestFixtures.getInstance().initSystem(getProperties());
- } catch (Exception e) {
- e.printStackTrace();
- }
- getSqlIntegrationTestFixtures().setState(State.INITIALIZE);
- }
-
- @Override
- public Properties getProperties() {
- final Properties properties = new Properties();
- properties.put("isis.persistor", "xml");
- properties.put("isis.logging.objectstore", "off");
- return properties;
- }
-
- @Override
- public String getPropertiesFilename() {
- return "xml.properties";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/pom.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/pom.xml b/component/objectstore/sql/sql-tests-served/pom.xml
deleted file mode 100644
index 1fc1aef..0000000
--- a/component/objectstore/sql/sql-tests-served/pom.xml
+++ /dev/null
@@ -1,163 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-sql</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>isis-objectstore-sql-tests-served</artifactId>
-
- <name>Isis SQL ObjectStore Integration Tests - Served</name>
-
- <properties>
- <siteBaseDir>..</siteBaseDir>
- <relativeUrl>sql-tests-served/</relativeUrl>
-
- <postgresql.version>9.2-1002.jdbc4</postgresql.version>
- <mysql.version>5.1.25</mysql.version>
- </properties>
-
- <!-- used in Site generation for relative references. -->
- <url>http://isis.apache.org/${relativeUrl}</url>
-
- <description>Runs the common tests against a few server implementations.
-Just add your server implementation to org.apache.isis.extensions.sql.objectstore</description>
- <build>
- <plugins>
- <!-- TODO: currently set to ignore test failures -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <testFailureIgnore>true</testFailureIgnore>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <version>${maven-project-info-reports-plugin}</version>
- <inherited>false</inherited>
- <configuration>
- <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
- </configuration>
- <reportSets>
- <reportSet>
- <inherited>false</inherited>
- <reports>
- <report>dependency-management</report>
- <report>dependencies</report>
- <report>dependency-convergence</report>
- <report>plugins</report>
- <report>summary</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- </plugins>
- </reporting>
-
- <dependencyManagement>
- <dependencies>
- <!-- SQL integration tests common -->
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>isis-objectstore-sql-tests-common</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <!-- JDBC drivers -->
- <dependency>
- <groupId>postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <version>${postgresql.version}</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>${mysql.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <dependencies>
-
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-runtime</artifactId>
- </dependency>
- <!-- Required for TestProxy -->
- <!-- Isis defaults -->
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-objectstore</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-objectstore</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-bytecode-cglib</artifactId>
- <scope>test</scope>
- </dependency>
-
-
- <!-- Isis Object store -->
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>isis-objectstore-sql-impl</artifactId>
- </dependency>
-
- <!-- Test common -->
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>isis-objectstore-sql-tests-common</artifactId>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>isis-objectstore-sql-tests-common</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
-
-
- <!-- Required to support the implemented servers -->
- <dependency>
- <groupId>postgresql</groupId>
- <artifactId>postgresql</artifactId>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/src/main/resources/log4j.properties b/component/objectstore/sql/sql-tests-served/src/main/resources/log4j.properties
deleted file mode 100644
index bcafd74..0000000
--- a/component/objectstore/sql/sql-tests-served/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,39 +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.
-# apache's log4j is used to provide system logging.
-log4j.rootCategory=DEBUG, Console, File
-#log4j.rootCategory=INFO, Console, File
-
-
-# The console appender
-log4j.appender.Console=org.apache.log4j.ConsoleAppender
-log4j.appender.Console.target=System.out
-log4j.appender.Console.layout=org.apache.log4j.PatternLayout
-log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} [%-20c{1} %-10t %-5p] %m%n
-
-
-log4j.appender.File=org.apache.log4j.RollingFileAppender
-log4j.appender.File.file=isis.log
-log4j.appender.File.append=false
-#log4j.appender.File.maxFileSize=500KB
-#log4j.appender.File.maxBackupIndex=1
-log4j.appender.File.layout=org.apache.log4j.PatternLayout
-log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
-
-
-
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/src/site/apt/index.apt b/component/objectstore/sql/sql-tests-served/src/site/apt/index.apt
deleted file mode 100644
index 1668418..0000000
--- a/component/objectstore/sql/sql-tests-served/src/site/apt/index.apt
+++ /dev/null
@@ -1,29 +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.
-
-
-
-SQL ObjectStore Integration Tests
-
- This module runs tests against a few common database servers.
-
- It will need to be configured for your server environment.
-
-Further Info
-
- See this module's {{{./apidocs/index.html}Javadoc}} and {{{../docbkx/html/guide/isis-sql-objectstore.html}User Guide}} for more information.
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/src/site/apt/jottings.apt b/component/objectstore/sql/sql-tests-served/src/site/apt/jottings.apt
deleted file mode 100644
index c5d1200..0000000
--- a/component/objectstore/sql/sql-tests-served/src/site/apt/jottings.apt
+++ /dev/null
@@ -1,24 +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.
-
-
-
-Jottings
-
- This page is to capture any random jottings relating to this module prior
- to being moved into formal documentation.
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/src/site/site.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/src/site/site.xml b/component/objectstore/sql/sql-tests-served/src/site/site.xml
deleted file mode 100644
index 521d3ce..0000000
--- a/component/objectstore/sql/sql-tests-served/src/site/site.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project>
-
- <body>
- <breadcrumbs>
- <item name="Integration Tests" href="index.html"/>
- </breadcrumbs>
-
- <menu name="SQL ObjectStore Tests">
- <item name="About" href="index.html" />
- </menu>
-
- <menu name="SQL OS Modules">
- <item name="Implementation" href="../sql-impl/index.html" />
- <item name="Common Tests" href="../sql-tests-common/index.html" />
- <item name="Integration Tests" href="../sql-tests-served/index.html" />
- </menu>
-
- <menu name="Maven Reports" ref="reports" />
- </body>
-</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/src/test/config/db2.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/src/test/config/db2.properties b/component/objectstore/sql/sql-tests-served/src/test/config/db2.properties
deleted file mode 100644
index 4e5195d..0000000
--- a/component/objectstore/sql/sql-tests-served/src/test/config/db2.properties
+++ /dev/null
@@ -1,27 +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.
-
-
-
-# Sample configuration
-# Edit this file with your server and authentication details.
-
-# DB2 test
-isis.persistence.sql.jdbc.driver=com.ibm.db2.jcc.DB2Driver
-isis.persistence.sql.jdbc.connection=jdbc:db2://gtd-dev:50000/proddb
-isis.persistence.sql.jdbc.user=db2admin
-isis.persistence.sql.jdbc.password=db2srvtest
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/src/test/config/mssqlserver.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/src/test/config/mssqlserver.properties b/component/objectstore/sql/sql-tests-served/src/test/config/mssqlserver.properties
deleted file mode 100644
index b1db3b7..0000000
--- a/component/objectstore/sql/sql-tests-served/src/test/config/mssqlserver.properties
+++ /dev/null
@@ -1,32 +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.
-
-
-
-# Sample configuration
-# Edit this file with your server and authentication details.
-
-
-# SQL Server
-#isis.persistence.sql.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
-#isis.persistence.sql.jdbc.connection=jdbc:sqlserver://SPRSRMS21;databaseName=AnalyticalData
-
-isis.persistence.sql.jdbc.driver=net.sourceforge.jtds.jdbc.Driver
-isis.persistence.sql.jdbc.connection=jdbc:jtds:sqlserver://SPRSRMS21;databaseName=AnalyticalData
-
-isis.persistence.sql.jdbc.user=grip
-isis.persistence.sql.jdbc.password=grip
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/src/test/config/mysql.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/src/test/config/mysql.properties b/component/objectstore/sql/sql-tests-served/src/test/config/mysql.properties
deleted file mode 100644
index 117c681..0000000
--- a/component/objectstore/sql/sql-tests-served/src/test/config/mysql.properties
+++ /dev/null
@@ -1,29 +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.
-
-
-# Sample configuration
-# Edit this file with your server and authentication details.
-#
-# If this file exists, it overrides the MySqlTest#getProperties() method
-isis.persistor.sql.jdbc.driver=com.mysql.jdbc.Driver
-isis.persistor.sql.jdbc.connection=jdbc:mysql://abacus/noftest?useTimezone=false
-#true&serverTimezone=GMT
-isis.persistor.sql.jdbc.user=nof
-isis.persistor.sql.jdbc.password=
-
-isis.persistor.sql.datatypes.double=DOUBLE PRECISION
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/src/test/config/postgresql.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/src/test/config/postgresql.properties b/component/objectstore/sql/sql-tests-served/src/test/config/postgresql.properties
deleted file mode 100644
index b9fccfb..0000000
--- a/component/objectstore/sql/sql-tests-served/src/test/config/postgresql.properties
+++ /dev/null
@@ -1,29 +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.
-
-
-# Sample configuration
-# Edit this file with your server and authentication details.
-# If this file exists, it overrides the PostreSqlTest#getProperties() method
-isis.persistor.sql.jdbc.driver=org.postgresql.Driver
-isis.persistor.sql.jdbc.connection=jdbc:postgresql://abacus/noftest
-isis.persistor.sql.jdbc.user=nof
-isis.persistor.sql.jdbc.password=
-
-isis.persistor.sql.datatypes.timestamp=TIMESTAMP
-isis.persistor.sql.datatypes.datetime=TIMESTAMP
-isis.persistor.sql.datatypes.double=DOUBLE PRECISION
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/MySqlIntegrationTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/MySqlIntegrationTest.java b/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/MySqlIntegrationTest.java
deleted file mode 100644
index 25e838a..0000000
--- a/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/MySqlIntegrationTest.java
+++ /dev/null
@@ -1,55 +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.isis.objectstore.sql;
-
-import java.util.Properties;
-
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestData;
-
-public class MySqlIntegrationTest extends SqlIntegrationTestData {
-
- /**/
- @Override
- public Properties getProperties() {
- Properties properties = super.getProperties();
- if (properties == null) {
- // Only used if *sql.properties is not found
- properties = new Properties();
- properties.put(SqlObjectStore.BASE_NAME + ".jdbc.driver", "com.mysql.jdbc.Driver");
- // properties.put(SqlObjectStore.BASE_NAME + ".jdbc.connection",
- // "jdbc:mysql://abacus/noftest&useTimezone=true&serverTimezone=GMT");
- properties.put(SqlObjectStore.BASE_NAME + ".jdbc.connection", "jdbc:mysql://abacus/noftest&useLegacyDatetimeCode=false");
- properties.put(SqlObjectStore.BASE_NAME + ".jdbc.user", "nof");
- properties.put(SqlObjectStore.BASE_NAME + ".jdbc.jdbc.password", "");
- }
- return properties;
- }
-
- /**/
-
- @Override
- public String getPropertiesFilename() {
- return "mysql.properties";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/PostgreSqlIntegrationTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/PostgreSqlIntegrationTest.java b/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/PostgreSqlIntegrationTest.java
deleted file mode 100644
index b3ca865..0000000
--- a/component/objectstore/sql/sql-tests-served/src/test/java/org/apache/isis/objectstore/sql/PostgreSqlIntegrationTest.java
+++ /dev/null
@@ -1,56 +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.isis.objectstore.sql;
-
-import java.util.Properties;
-
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestData;
-
-public class PostgreSqlIntegrationTest extends SqlIntegrationTestData {
-
- @Override
- public Properties getProperties() {
- Properties properties = super.getProperties();
- if (properties == null) {
- properties = new Properties();
- // Only used if src/test/config/postgresql.properties does not
- // exist.
- properties.put(SqlObjectStore.BASE_NAME + ".jdbc.driver", "org.postgresql.Driver");
- properties.put(SqlObjectStore.BASE_NAME + ".jdbc.connection", "jdbc:postgresql://abacus/noftest");
- properties.put(SqlObjectStore.BASE_NAME + ".jdbc.user", "nof");
- properties.put(SqlObjectStore.BASE_NAME + ".jdbc.password", "");
-
- // properties.put(SqlObjectStore.BASE_NAME + ".datatypes.timestamp",
- // "TIMESTAMP");
- // properties.put(SqlObjectStore.BASE_NAME + ".datatypes.datetime",
- // "TIMESTAMP");
- }
- return properties;
- }
-
- @Override
- public String getPropertiesFilename() {
- return "postgresql.properties";
- }
-
-}
[12/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Parameter.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Parameter.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Parameter.java
deleted file mode 100644
index aa192ff..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Parameter.java
+++ /dev/null
@@ -1,30 +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.isis.objectstore.sql;
-
-import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
-
-public interface Parameter {
- void setupParameter(int parameter, StoredProcedure procedure) throws ObjectPersistenceException;
-
- // String getRestoreString();
-
- void retrieve(int parameter, StoredProcedure procedure) throws ObjectPersistenceException;
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Results.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Results.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Results.java
deleted file mode 100644
index 2361447..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Results.java
+++ /dev/null
@@ -1,63 +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.isis.objectstore.sql;
-
-import java.io.InputStream;
-import java.sql.Time;
-import java.util.Calendar;
-import java.util.Date;
-
-public interface Results {
-
- void close();
-
- int getInt(String columnName);
-
- long getLong(String columnName);
-
- double getDouble(String columnName);
-
- String getString(String columnName);
-
- Float getFloat(String columnName);
-
- Object getShort(String columnName);
-
- Object getBoolean(String columnName);
-
- boolean next();
-
- Date getJavaDateOnly(String dateColumn);
-
- Time getJavaTimeOnly(String timeColumn);
-
- Date getJavaDateTime(String lastActivityDateColumn, Calendar calendar);
-
- org.apache.isis.applib.value.Date getDate(String columnName);
-
- org.apache.isis.applib.value.Time getTime(String columnName);
-
- Object getObject(String column);
-
- Object getAsType(String columnName, Class<?> clazz);
-
- InputStream getStream(String column);
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Sql.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Sql.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Sql.java
deleted file mode 100644
index eb26a1f..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Sql.java
+++ /dev/null
@@ -1,108 +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.isis.objectstore.sql;
-
-/**
- * SQL functions, commands, names that are database dependent
- */
-public class Sql {
- private Sql() {
- }
-
- private static SqlMetaData metadata;
-
- // public static String timestamp = "CURRENT_TIMESTAMP";
-
- public static void setMetaData(final SqlMetaData metadata) {
- Sql.metadata = metadata;
- }
-
- public static String escapeAndQuoteValue(final String encodedString) {
- if (encodedString == null || encodedString.equals("NULL")) {
- return "NULL";
- }
- // StringBuffer buffer = new StringBuffer("'");
- final StringBuffer buffer = new StringBuffer(metadata.getQuoteString());
- for (int i = 0; i < encodedString.length(); i++) {
- final char c = encodedString.charAt(i);
- if (c == '\'') {
- buffer.append("\\'");
- } else if (c == '\\') {
- buffer.append("\\\\");
- } else {
- buffer.append(c);
- }
- }
- // buffer.append("'");
- buffer.append(metadata.getQuoteString());
- final String string = buffer.toString();
- return string;
- }
-
- public static String sqlName(final String name) {
- // TODO need to deal with non-ascii (ie unicode characters)
- return name.replace(' ', '_').toLowerCase();
-
- /*
- * int length = name.length(); StringBuffer convertedName = new
- * StringBuffer(length); for (int i = 0; i < length; i++) { char ch =
- * name.charAt(i); if (ch == ' ') { i++; //ch = name.charAt(i);
- * //Character.toUpperCase(ch); ch = '_'; } convertedName.append(ch); }
- * return convertedName.toString();
- */
- }
-
- public static String sqlFieldName(final String name) {
- final int length = name.length();
- final StringBuffer convertedName = new StringBuffer(length);
- boolean lastWasLowerCase = false;
- for (int i = 0; i < length; i++) {
- final char ch = name.charAt(i);
- if (Character.isUpperCase(ch)) {
- if (lastWasLowerCase) {
- convertedName.append('_');
- }
- lastWasLowerCase = false;
- } else {
- lastWasLowerCase = true;
- }
- convertedName.append(ch);
- }
- return sqlName(convertedName.toString());
- }
-
- public static String identifier(final String name) {
- // return metadata.quoteIdentifier(name);
- return tableIdentifier(name);
- }
-
- public static String tableIdentifier(final String name) {
- if (metadata.isStoresMixedCaseIdentifiers()) {
- return name;
- } else if (metadata.isStoresLowerCaseIdentifiers()) {
- return name.toLowerCase();
- } else if (metadata.isStoresUpperCaseIdentifiers()) {
- return name.toUpperCase();
- } else {
- throw new SqlObjectStoreException("No case preference set up: " + name);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlExecutionContext.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlExecutionContext.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlExecutionContext.java
deleted file mode 100644
index 63196ab..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlExecutionContext.java
+++ /dev/null
@@ -1,46 +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.isis.objectstore.sql;
-
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
-import org.apache.isis.core.runtime.system.transaction.MessageBroker;
-import org.apache.isis.core.runtime.system.transaction.UpdateNotifier;
-
-public class SqlExecutionContext implements PersistenceCommandContext {
- private final DatabaseConnector connection;
-
- public SqlExecutionContext(final DatabaseConnector connection, final IsisTransactionManager transactionManager, final MessageBroker messageBroker, final UpdateNotifier updateNotifier) {
- this.connection = connection;
- }
-
- public DatabaseConnector getConnection() {
- return connection;
- }
-
- @Override
- public void start() {
- }
-
- @Override
- public void end() {
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlIdentifierGenerator.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlIdentifierGenerator.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlIdentifierGenerator.java
deleted file mode 100644
index f2ef52c..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlIdentifierGenerator.java
+++ /dev/null
@@ -1,148 +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.isis.objectstore.sql;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.commons.ensure.Assert;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
-import org.apache.isis.core.runtime.system.persistence.IdentifierGenerator;
-
-public class SqlIdentifierGenerator implements IdentifierGenerator {
-
- private final DatabaseConnectorPool connectionPool;
- private final IdNumbers ids = new IdNumbers();
-
- //////////////////////////////////////////////////////////////////
- // constructor
- //////////////////////////////////////////////////////////////////
-
- public SqlIdentifierGenerator(final DatabaseConnectorPool connectionPool) {
- this.connectionPool = connectionPool;
- }
-
- ///////////////////////////////////////////////////////
- // API
- ///////////////////////////////////////////////////////
-
- @Override
- public String createAggregateLocalId(ObjectSpecId objectSpecId, final Object pojo, final ObjectAdapter parentAdapter) {
- throw new SqlObjectStoreException("Aggregated objects are not supported in this store");
- }
-
- @Override
- public String createTransientIdentifierFor(ObjectSpecId objectSpecId, final Object pojo) {
- return ""+ids.nextTransientId();
- }
-
- @Override
- public String createPersistentIdentifierFor(ObjectSpecId objectSpecId, Object pojo, RootOid transientRootOid) {
- Assert.assertNotNull("No connection set up", connectionPool);
- return "" + (int) ids.nextPersistentId(connectionPool);
- }
-
-
- ///////////////////////////////////////////////////////
- // Debug
- ///////////////////////////////////////////////////////
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln(this.toString());
- debug.indent();
- ids.debugData(debug);
- debug.unindent();
- }
-
- @Override
- public String debugTitle() {
- return "Sql Identifier Generator";
- }
-}
-
-
-
-class IdNumbers {
-
- private static final Logger LOG = LoggerFactory.getLogger(IdNumbers.class);
-
- private static final String NUMBER_COLUMN = "number";
- private static final String TABLE_NAME = "isis_admin_serial_id";
- private static int BATCH_SIZE = 50;
- private long transientNumber = -9999999;
- private long lastId = 0;
- private long newBatchAt = 0;
-
- public synchronized long nextTransientId() {
- return transientNumber++;
- }
-
- public synchronized long nextPersistentId(final DatabaseConnectorPool connectionPool) {
- if (lastId > newBatchAt) {
- throw new SqlObjectStoreException("ID exception, last id (" + lastId + ") past new batch boundary (" + newBatchAt + ")");
- }
- if (lastId == newBatchAt) {
- prepareNewBatch(connectionPool);
- }
- lastId++;
- return lastId;
- }
-
- private void prepareNewBatch(final DatabaseConnectorPool connectionPool) {
- final DatabaseConnector db = connectionPool.acquire();
- try {
- final String tableName = Sql.tableIdentifier(TABLE_NAME);
- final String numberColumn = Sql.identifier(NUMBER_COLUMN);
- if (!db.hasTable(tableName)) {
- lastId = 1;
- newBatchAt = BATCH_SIZE;
- db.update("create table " + tableName + " (" + numberColumn + " INTEGER)");
- db.update("insert into " + tableName + " values (" + newBatchAt + ")");
- LOG.debug("Initial ID batch created, from " + lastId + " to " + newBatchAt);
- } else {
- if (db.update("update " + tableName + " set " + numberColumn + " = " + numberColumn + " + " + BATCH_SIZE) != 1) {
- throw new SqlObjectStoreException("failed to update serial id table; no rows updated");
- }
- final Results rs = db.select("select " + numberColumn + " from " + tableName);
- rs.next();
- newBatchAt = rs.getLong(NUMBER_COLUMN); // TODO here
- lastId = newBatchAt - BATCH_SIZE;
- LOG.debug("New ID batch created, from " + lastId + " to " + newBatchAt);
- rs.close();
- }
- } catch (final ObjectPersistenceException e) {
- throw e;
- } finally {
- connectionPool.release(db);
- }
- }
-
- public void debugData(final DebugBuilder debug) {
- debug.appendln("id", lastId);
- debug.appendln("transient id", transientNumber);
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlMetaData.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlMetaData.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlMetaData.java
deleted file mode 100644
index 5e0b718..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlMetaData.java
+++ /dev/null
@@ -1,36 +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.isis.objectstore.sql;
-
-public interface SqlMetaData {
- String getKeywords();
-
- String getTimeDateFunctions();
-
- boolean isStoresLowerCaseIdentifiers();
-
- boolean isStoresMixedCaseIdentifiers();
-
- boolean isStoresUpperCaseIdentifiers();
-
- String getQuoteString();
-
- String quoteIdentifier(String identifier);
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStore.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStore.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStore.java
deleted file mode 100644
index 98695e6..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStore.java
+++ /dev/null
@@ -1,508 +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.isis.objectstore.sql;
-
-import java.util.List;
-import java.util.Vector;
-
-import com.google.common.collect.Lists;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.commons.debug.DebugString;
-import org.apache.isis.core.commons.ensure.IsisAssertException;
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.oid.CollectionOid;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
-import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.SpecificationLoader;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.persistence.objectstore.ObjectStoreSpi;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.CreateObjectCommand;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.SaveObjectCommand;
-import org.apache.isis.core.runtime.persistence.query.PersistenceQueryBuiltInAbstract;
-import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindAllInstances;
-import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByPattern;
-import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByTitle;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.PersistenceQuery;
-import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
-import org.apache.isis.core.runtime.system.transaction.MessageBroker;
-import org.apache.isis.core.runtime.system.transaction.UpdateNotifier;
-
-public final class SqlObjectStore implements ObjectStoreSpi {
-
- private static final String TABLE_NAME = "isis_admin_services";
- // private static final String ID_COLUMN = "id";
- // private static final String PRIMARYKEY_COLUMN = "pk_id";
- public static final String BASE_NAME = "isis.persistor.sql";
- private static final Logger LOG = LoggerFactory.getLogger(SqlObjectStore.class);
- private DatabaseConnectorPool connectionPool;
- private ObjectMappingLookup objectMappingLookup;
- private boolean isInitialized;
-
- @Override
- public String name() {
- return "SQL Object Store";
- }
-
- @Override
- public void open() {
- Sql.setMetaData(connectionPool.acquire().getMetaData());
-
- if (!isInitialized) {
- Defaults.initialise(BASE_NAME, IsisContext.getConfiguration());
- Defaults.setPkIdLabel(Sql.identifier(Defaults.getPkIdLabel()));
- Defaults.setIdColumn(Sql.identifier(Defaults.getIdColumn()));
- }
-
- final DebugBuilder debug = new DebugString();
- connectionPool.debug(debug);
- LOG.info("Database: " + debug);
-
- objectMappingLookup.init();
-
- final DatabaseConnector connector = connectionPool.acquire();
- final String tableIdentifier = Sql.tableIdentifier(TABLE_NAME);
- isInitialized = connector.hasColumn(tableIdentifier, Defaults.getPkIdLabel());
- if (!isInitialized) {
- if (connector.hasTable(tableIdentifier)) {
- final StringBuffer sql = new StringBuffer();
- sql.append("drop table ");
- sql.append(tableIdentifier);
- connector.update(sql.toString());
- }
- final StringBuffer sql = new StringBuffer();
- sql.append("create table ");
- sql.append(tableIdentifier);
- sql.append(" (");
- sql.append(Defaults.getPkIdLabel());
- sql.append(" int, ");
- sql.append(Defaults.getIdColumn());
- sql.append(" varchar(255)");
- sql.append(")");
- connector.update(sql.toString());
- }
- }
-
- @Override
- public boolean isFixturesInstalled() {
- return isInitialized;
- }
-
- @Override
- public void registerService(final RootOid rootOid) {
- final DatabaseConnector connector = connectionPool.acquire();
-
- final StringBuffer sql = new StringBuffer();
- sql.append("insert into ");
- sql.append(Sql.tableIdentifier(TABLE_NAME));
- sql.append(" (");
- sql.append(Defaults.getPkIdLabel());
- sql.append(", ");
- sql.append(Defaults.getIdColumn());
- sql.append(") values (?,?)");
-
- final RootOidDefault sqlOid = (RootOidDefault) rootOid;
- connector.addToQueryValues(sqlOid.getIdentifier());
- connector.addToQueryValues(rootOid.getObjectSpecId().asString());
-
- connector.insert(sql.toString());
- connectionPool.release(connector);
- }
-
- @Override
- public void reset() {
- }
-
- @Override
- public void close() {
- objectMappingLookup.shutdown();
- connectionPool.shutdown();
- }
-
- @Override
- public void startTransaction() {
- executeSql(Defaults.START_TRANSACTION());
- }
-
- @Override
- public void abortTransaction() {
- executeSql(Defaults.ABORT_TRANSACTION());
- }
-
- @Override
- public void endTransaction() {
- executeSql(Defaults.COMMIT_TRANSACTION());
- }
-
- private void executeSql(String sql) {
- final DatabaseConnector connector = connectionPool.acquire();
- try {
- connector.begin();
- connector.update(sql);
- connector.commit();
- // connector.close();
- } finally {
- connectionPool.release(connector);
- }
- }
-
- @Override
- public CreateObjectCommand createCreateObjectCommand(final ObjectAdapter object) {
- return new CreateObjectCommand() {
- @Override
- public void execute(final PersistenceCommandContext context) {
- final DatabaseConnector connection = ((SqlExecutionContext) context).getConnection();
- LOG.debug(" create object " + object);
- final ObjectMapping mapping = objectMappingLookup.getMapping(object, connection);
- mapping.createObject(connection, object);
- }
-
- @Override
- public ObjectAdapter onAdapter() {
- return object;
- }
-
- @Override
- public String toString() {
- return "CreateObjectCommand [object=" + object + "]";
- }
- };
- }
-
- @Override
- public DestroyObjectCommand createDestroyObjectCommand(final ObjectAdapter object) {
- return new DestroyObjectCommand() {
- @Override
- public void execute(final PersistenceCommandContext context) {
- final DatabaseConnector connection = ((SqlExecutionContext) context).getConnection();
- LOG.debug(" destroy object " + object);
- final ObjectMapping mapping = objectMappingLookup.getMapping(object, connection);
- mapping.destroyObject(connection, object);
- }
-
- @Override
- public ObjectAdapter onAdapter() {
- return object;
- }
-
- @Override
- public String toString() {
- return "DestroyObjectCommand [object=" + object + "]";
- }
- };
- }
-
- @Override
- public SaveObjectCommand createSaveObjectCommand(final ObjectAdapter adapter) {
- return new SaveObjectCommand() {
- @Override
- public void execute(final PersistenceCommandContext context) {
- final DatabaseConnector connection = ((SqlExecutionContext) context).getConnection();
- LOG.debug(" save object " + adapter.toString());
-
- try {
- final ObjectSpecification adapterSpec = adapter.getSpecification();
- if (!adapterSpec.isParented()) {
- saveRootAdapter(adapter, connection);
- } else if (adapterSpec.isParentedOrFreeCollection()) {
- saveParentedCollectionAdapter(adapter, connection);
- } else {
- throw new NotYetImplementedException("cannot yet persist aggregated objects: "
- + adapter.toString());
- }
- } finally {
- connectionPool.release(connection);
- }
- }
-
- private void saveRootAdapter(final ObjectAdapter adapter, final DatabaseConnector connection) {
- final ObjectMapping mapping = objectMappingLookup.getMapping(adapter, connection);
- mapping.save(connection, adapter);
- }
-
- private void saveParentedCollectionAdapter(final ObjectAdapter collectionAdapter,
- final DatabaseConnector connection) {
- final ObjectAdapter parent = collectionAdapter.getAggregateRoot();
- LOG.debug("change to internal collection being persisted through parent");
-
- final Oid oid = collectionAdapter.getOid();
- final CollectionOid collectionOid = (CollectionOid) oid;
- if (!(oid instanceof CollectionOid)) {
- throw new IsisAssertException("object should have a CollectionOid");
- }
-
- final ObjectMapping mapping = objectMappingLookup.getMapping(parent, connection);
- if (!mapping.saveCollection(connection, parent, collectionOid.getName())) {
- final ObjectMapping parentMapping = objectMappingLookup.getMapping(parent, connection);
- parentMapping.save(connection, collectionAdapter);
- }
- }
-
- @Override
- public ObjectAdapter onAdapter() {
- return adapter;
- }
-
- @Override
- public String toString() {
- return "SaveObjectCommand [object=" + adapter + "]";
- }
-
- };
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln("initialised", isInitialized);
- debug.appendln("connection pool", connectionPool);
- debug.appendln("Database:");
- debug.indent();
- connectionPool.debug(debug);
- debug.unindent();
- objectMappingLookup.debugData(debug);
- }
-
- @Override
- public String debugTitle() {
- return null;
- }
-
- @Override
- public void execute(final List<PersistenceCommand> commands) {
- final DatabaseConnector connector = connectionPool.acquire();
- connector.begin();
-
- final IsisTransactionManager transactionManager = IsisContext.getTransactionManager();
- final MessageBroker messageBroker = IsisContext.getMessageBroker();
- final UpdateNotifier updateNotifier = IsisContext.getUpdateNotifier();
- final SqlExecutionContext context =
- new SqlExecutionContext(connector, transactionManager, messageBroker, updateNotifier);
- try {
- for (final PersistenceCommand command : commands) {
- command.execute(context);
- }
- connector.commit();
- } catch (final IsisException e) {
- LOG.warn("Failure during execution", e);
- connector.rollback();
- throw e;
- } finally {
- connectionPool.release(connector);
- }
- }
-
- public boolean flush(final PersistenceCommand[] commands) {
- return false;
- }
-
- @Override
- public List<ObjectAdapter> loadInstancesAndAdapt(final PersistenceQuery query) {
- if (query instanceof PersistenceQueryFindByTitle) {
- return findByTitle((PersistenceQueryFindByTitle) query, query.getStart(), query.getCount());
- } else if (query instanceof PersistenceQueryFindAllInstances) {
- return getAllInstances((PersistenceQueryFindAllInstances) query, query.getStart(), query.getCount());
- } else if (query instanceof PersistenceQueryFindByPattern) {
- return findByPattern((PersistenceQueryFindByPattern) query, query.getStart(), query.getCount());
- } else {
- throw new SqlObjectStoreException("Query type not supported: " + query);
- }
- }
-
- private List<ObjectAdapter> findByPattern(final PersistenceQueryFindByPattern query, final long startIndex, final long rowCount) {
- final ObjectSpecification specification = query.getSpecification();// query.getPattern().getSpecification();//
- // getSpecification();
- final DatabaseConnector connector = connectionPool.acquire();
- try {
- final List<ObjectAdapter> matchingInstances = Lists.newArrayList();
-
- addSpecQueryInstances(specification, connector, query, matchingInstances, startIndex, rowCount);
- return matchingInstances;
-
- } finally {
- connectionPool.release(connector);
- }
- }
-
- private void addSpecQueryInstances(final ObjectSpecification specification, final DatabaseConnector connector,
- final PersistenceQueryFindByPattern query, final List<ObjectAdapter> matchingInstances, long startIndex, long rowCount) {
-
- if (specification.isAbstract() == false) {
- final ObjectMapping mapper = objectMappingLookup.getMapping(specification, connector);
- final Vector<ObjectAdapter> instances = mapper.getInstances(connector, specification, query);
- matchingInstances.addAll(instances);
-
- }
- if (specification.hasSubclasses()) {
- final List<ObjectSpecification> subclasses = specification.subclasses();
- for (final ObjectSpecification subclassSpec : subclasses) {
- addSpecQueryInstances(subclassSpec, connector, query, matchingInstances, startIndex, rowCount);
- }
- }
- }
-
- private List<ObjectAdapter> getAllInstances(final PersistenceQueryBuiltInAbstract criteria, final long startIndex, final long rowCount) {
- final ObjectSpecification spec = criteria.getSpecification();
- return allInstances(spec, startIndex, rowCount);
- }
-
- private List<ObjectAdapter> allInstances(final ObjectSpecification spec, long startIndex, long rowCount) {
- final DatabaseConnector connector = connectionPool.acquire();
- final List<ObjectAdapter> matchingInstances = Lists.newArrayList();
-
- addSpecInstances(spec, connector, matchingInstances, startIndex, rowCount);
-
- connectionPool.release(connector);
- return matchingInstances;
- }
-
- private void addSpecInstances(final ObjectSpecification spec, final DatabaseConnector connector,
- final List<ObjectAdapter> matchingInstances, final long startIndex, final long rowCount) {
-
- if (!spec.isAbstract()) {
- final ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
- final List<ObjectAdapter> instances = mapper.getInstances(connector, spec, startIndex, rowCount);
- matchingInstances.addAll(instances);
- }
-
- if (spec.hasSubclasses()) {
- final List<ObjectSpecification> subclasses = spec.subclasses();
- for (final ObjectSpecification subclassSpec : subclasses) {
- addSpecInstances(subclassSpec, connector, matchingInstances, startIndex, rowCount);
- }
- }
-
- }
-
- private List<ObjectAdapter> findByTitle(final PersistenceQueryFindByTitle criteria, final long startIndex, final long rowCount) {
- final ObjectSpecification spec = criteria.getSpecification();
- final DatabaseConnector connector = connectionPool.acquire();
- final ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
-
- final Vector<ObjectAdapter> instances = mapper.getInstances(connector, spec, criteria.getTitle(), startIndex, rowCount);
- connectionPool.release(connector);
-
- return instances;
- }
-
- @Override
- public ObjectAdapter loadInstanceAndAdapt(final TypedOid oid) {
- final DatabaseConnector connection = connectionPool.acquire();
- final ObjectSpecification objectSpec = getSpecificationLookup().lookupBySpecId(oid.getObjectSpecId());
- final ObjectMapping mapper = objectMappingLookup.getMapping(objectSpec, connection);
- final ObjectAdapter object = mapper.getObject(connection, oid);
- connectionPool.release(connection);
- return object;
- }
-
- @Override
- public RootOid getOidForService(ObjectSpecification serviceSpec) {
-
- final DatabaseConnector connector = connectionPool.acquire();
- try {
- final StringBuffer sql = new StringBuffer();
- sql.append("select ");
- sql.append(Defaults.getPkIdLabel());
- sql.append(" from ");
- sql.append(Sql.tableIdentifier(TABLE_NAME));
- sql.append(" where ");
- sql.append(Defaults.getIdColumn());
- sql.append(" = ?");
- connector.addToQueryValues(serviceSpec.getSpecId().asString());
-
- final Results results = connector.select(sql.toString());
- if (!results.next()) {
- return null;
- }
- final int id = results.getInt(Defaults.getPkIdLabel());
- return RootOidDefault.create(serviceSpec.getSpecId(), "" + id);
-
- } finally {
- connectionPool.release(connector);
- }
- }
-
- @Override
- public boolean hasInstances(final ObjectSpecification spec) {
- final DatabaseConnector connection = connectionPool.acquire();
- final ObjectMapping mapper = objectMappingLookup.getMapping(spec, connection);
- final boolean hasInstances = mapper.hasInstances(connection, spec);
- connectionPool.release(connection);
- return hasInstances;
- }
-
- @Override
- public void resolveField(final ObjectAdapter object, final ObjectAssociation field) {
- if (field.isOneToManyAssociation()) {
- final DatabaseConnector connection = connectionPool.acquire();
- final ObjectSpecification spec = object.getSpecification();
- final ObjectMapping mapper = objectMappingLookup.getMapping(spec, connection);
- mapper.resolveCollection(connection, object, field);
- connectionPool.release(connection);
- } else {
- resolveImmediately(field.get(object));
- }
- }
-
- @Override
- public void resolveImmediately(final ObjectAdapter object) {
- final DatabaseConnector connector = connectionPool.acquire();
- final ObjectMapping mapping = objectMappingLookup.getMapping(object, connector);
- mapping.resolve(connector, object);
- connectionPool.release(connector);
- }
-
- // /////////////////////////////////////////////////////////
- // Dependencies (injected)
- // /////////////////////////////////////////////////////////
-
- public void setConnectionPool(final DatabaseConnectorPool connectionPool) {
- this.connectionPool = connectionPool;
- }
-
- public void setMapperLookup(final ObjectMappingLookup mapperLookup) {
- this.objectMappingLookup = mapperLookup;
- }
-
- // /////////////////////////////////////////////////////////
- // Dependencies (from context)
- // /////////////////////////////////////////////////////////
-
- protected AdapterManager getAdapterManager() {
- return IsisContext.getPersistenceSession().getAdapterManager();
- }
-
- protected SpecificationLoader getSpecificationLookup() {
- return IsisContext.getSpecificationLoader();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStoreException.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStoreException.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStoreException.java
deleted file mode 100644
index d2be600..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlObjectStoreException.java
+++ /dev/null
@@ -1,42 +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.isis.objectstore.sql;
-
-import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
-
-public class SqlObjectStoreException extends ObjectPersistenceException {
- private static final long serialVersionUID = 1L;
-
- public SqlObjectStoreException() {
- super();
- }
-
- public SqlObjectStoreException(final String s) {
- super(s);
- }
-
- public SqlObjectStoreException(final String s, final Throwable cause) {
- super(s, cause);
- }
-
- public SqlObjectStoreException(final Throwable cause) {
- super(cause);
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlPersistorInstaller.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlPersistorInstaller.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlPersistorInstaller.java
deleted file mode 100644
index 9fa2090..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/SqlPersistorInstaller.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.isis.objectstore.sql;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapterFactory;
-import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
-import org.apache.isis.core.runtime.persistence.objectstore.ObjectStoreSpi;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.AdapterManagerSpi;
-import org.apache.isis.core.runtime.system.persistence.IdentifierGenerator;
-import org.apache.isis.objectstore.sql.auto.AutoMapperFactory;
-import org.apache.isis.objectstore.sql.jdbc.JdbcConnectorFactory;
-import org.apache.isis.objectstore.sql.jdbc.installer.JdbcFieldMappingFactoryInstaller;
-
-public class SqlPersistorInstaller extends PersistenceMechanismInstallerAbstract {
-
- public static final String NAME = "sql";
-
- private SqlObjectStore objectStore;
- private DatabaseConnectorPool connectionPool;
-
- public SqlPersistorInstaller() {
- super(NAME);
- }
-
- @Override
- protected ObjectStoreSpi createObjectStore(final IsisConfiguration configuration, final ObjectAdapterFactory objectFactory, final AdapterManagerSpi adapterManager) {
-
- if (objectStore == null) {
- final FieldMappingLookup fieldMappingLookup = new FieldMappingLookup();
- final JdbcFieldMappingFactoryInstaller installer = new JdbcFieldMappingFactoryInstaller();
-
- Defaults.initialise(SqlObjectStore.BASE_NAME, IsisContext.getConfiguration());
-
- installer.load(fieldMappingLookup);
- // fieldMappingLookup.setValueMappingFactory(new
- // JdbcFieldMappingFactoryInstaller());
-
- final ObjectMappingLookup objectMappingLookup = new ObjectMappingLookup();
- objectMappingLookup.setValueMappingLookup(fieldMappingLookup);
- objectMappingLookup.setObjectMappingFactory(new AutoMapperFactory());
- objectMappingLookup.setConnectionPool(connectionPool);
-
- final SqlObjectStore objectStore = new SqlObjectStore();
- objectStore.setMapperLookup(objectMappingLookup);
- objectStore.setConnectionPool(connectionPool);
- this.objectStore = objectStore;
- }
- return objectStore;
- }
-
- public SqlObjectStore getObjectStore() {
- return objectStore;
- }
-
- @Override
- public IdentifierGenerator createIdentifierGenerator(final IsisConfiguration configuration) {
- final DatabaseConnectorFactory connectorFactory = new JdbcConnectorFactory();
- connectionPool = new DatabaseConnectorPool(connectorFactory, 1);
-
- return new SqlIdentifierGenerator(connectionPool);
- }
-
- /*
- *
- *
- * @Override protected AdapterManagerExtended createAdapterManager(final
- * IsisConfiguration configuration) { return new XmlAdapterManager(); }
- */
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/StoredProcedure.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/StoredProcedure.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/StoredProcedure.java
deleted file mode 100644
index ba02c91..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/StoredProcedure.java
+++ /dev/null
@@ -1,26 +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.isis.objectstore.sql;
-
-public interface StoredProcedure {
-
- boolean getBoolean(int i);
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/TitleMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/TitleMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/TitleMapping.java
deleted file mode 100644
index 65bb24d..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/TitleMapping.java
+++ /dev/null
@@ -1,71 +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.isis.objectstore.sql;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-
-public class TitleMapping {
- private final String column = Sql.identifier("NO_title");
-
- protected String getColumn() {
- return column;
- }
-
- public void appendWhereClause(final StringBuffer sql, final String title) {
- appendAssignment(sql, title);
- }
-
- private void appendAssignment(final StringBuffer sql, final String title) {
- sql.append(column);
- sql.append(" = ");
- appendTitle(sql, title);
- }
-
- public void appendColumnDefinitions(final StringBuffer sql) {
- sql.append(column);
- sql.append(" ");
- sql.append("varchar(200)");
- }
-
- public void appendColumnNames(final StringBuffer sql) {
- sql.append(column);
- }
-
- public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- if (object == null) {
- sql.append("NULL");
- } else {
- connector.addToQueryValues(object.titleString().toLowerCase());
- }
- sql.append("?");
- }
-
- private void appendTitle(final StringBuffer sql, final String title) {
- final String titleString = title.toLowerCase();
- sql.append(Sql.escapeAndQuoteValue(titleString));
- }
-
- public void appendUpdateAssignment(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- sql.append(column);
- sql.append(" = ");
- appendInsertValues(connector, sql, object);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/VersionMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/VersionMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/VersionMapping.java
deleted file mode 100644
index 768c485..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/VersionMapping.java
+++ /dev/null
@@ -1,106 +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.isis.objectstore.sql;
-
-import java.sql.Timestamp;
-import java.util.Date;
-
-import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-
-public class VersionMapping {
- private String lastActivityDateColumn;
- private String lastActivityUserColumn;
- private String versionColumn;
-
- public void init() {
- lastActivityDateColumn = Sql.identifier("MODIFIED_ON");
- lastActivityUserColumn = Sql.identifier("MODIFIED_BY");
- versionColumn = Sql.identifier("VERSION");
- }
-
- public String insertColumns() {
- return versionColumn + ", " + lastActivityUserColumn + ", " + lastActivityDateColumn;
- }
-
- public String insertValues(final DatabaseConnector connector, final Version version) {
- connector.addToQueryValues(version.getSequence());
- IsisContext.getSession().getAuthenticationSession().getUserName();
- String user = IsisContext.getSession().getAuthenticationSession().getUserName();// version.getUser();
- if (user == "") {
- user = "unknown";
- }
- connector.addToQueryValues(user);
- connector.addToQueryValues(new Timestamp(new Date().getTime()));
- return "?,?,?";
- }
-
- public String whereClause(final DatabaseConnector connector, final Version version) {
- connector.addToQueryValues(version.getSequence());
- return versionColumn + " = ?";
- }
-
- public String updateAssigment(final DatabaseConnector connector, final long nextSequence) {
- connector.addToQueryValues(nextSequence);
- return versionColumn + " = ?";
- }
-
- public String appendColumnNames() {
- final StringBuffer sql = new StringBuffer();
- sql.append(versionColumn);
- sql.append(",");
- sql.append(lastActivityUserColumn);
- sql.append(",");
- sql.append(lastActivityDateColumn);
- return sql.toString();
- }
-
- public String appendColumnDefinitions() {
- final StringBuffer sql = new StringBuffer();
-
- sql.append(versionColumn);
- sql.append(" bigint");
-
- sql.append(",");
- sql.append(lastActivityUserColumn);
- sql.append(" varchar(32)");
-
- sql.append(",");
- sql.append(lastActivityDateColumn);
- sql.append(" " + Defaults.TYPE_TIMESTAMP());
-
- return sql.toString();
- }
-
- public Object appendUpdateValues(final DatabaseConnector connector, final long versionSequence) {
- connector.addToQueryValues(versionSequence);
- return versionColumn + "= ?";
- }
-
- public Version getLock(final Results rs) {
- final long number = rs.getLong(versionColumn);
- final String user = rs.getString(lastActivityUserColumn);
- final Date time = rs.getJavaDateTime(lastActivityDateColumn, Defaults.getCalendar());
- final Version version = SerialNumberVersion.create(number, user, time);
- return version;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java
deleted file mode 100644
index c5ae7ef..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java
+++ /dev/null
@@ -1,357 +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.isis.objectstore.sql.auto;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.collect.Maps;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
-import org.apache.isis.core.metamodel.spec.feature.Contributed;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-import org.apache.isis.objectstore.sql.AbstractMapper;
-import org.apache.isis.objectstore.sql.CollectionMapper;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.FieldMappingLookup;
-import org.apache.isis.objectstore.sql.ObjectMappingLookup;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.SqlObjectStoreException;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-public abstract class AbstractAutoMapper extends AbstractMapper {
-
- private static final Logger LOG = LoggerFactory.getLogger(AbstractAutoMapper.class);
-
- protected final Map<ObjectAssociation, FieldMapping> fieldMappingByField = Maps.newLinkedHashMap();
-
- protected CollectionMapper collectionMappers[];
- protected String collectionMapperFields[];
- protected boolean dbCreatesId;
-
- protected ObjectSpecification specification;
- protected String table;
-
- final String className;
- final String parameterBase;
- final FieldMappingLookup lookup;
- final ObjectMappingLookup objectMappingLookup;
-
- protected AbstractAutoMapper(final String className, final String parameterBase, final FieldMappingLookup lookup,
- final ObjectMappingLookup objectMappingLookup) {
- this.specification = specificationFor(className);
- this.className = className;
- this.parameterBase = parameterBase;
- this.lookup = lookup;
- this.objectMappingLookup = objectMappingLookup;
- }
-
- protected AbstractAutoMapper(final FieldMappingLookup lookup, final AbstractAutoMapper abstractAutoMapper,
- final String className) {
-
- this.specification = getSpecificationLoader().loadSpecification(className);
- this.className = className;
-
- this.parameterBase = null;
- this.lookup = null;
- this.objectMappingLookup = null;
- }
-
- private static ObjectSpecification specificationFor(final String className) {
- ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(className);
- List<OneToOneAssociation> properties = specification.getProperties(Contributed.EXCLUDED);
- if (isNullOrEmpty(properties) && !specification.isAbstract()) {
- throw new SqlObjectStoreException(specification.getFullIdentifier() + " has no fields: " + specification);
- }
- return specification;
- }
-
- protected void setUpFieldMappers() {
- setUpFieldMappers(lookup, objectMappingLookup, className, parameterBase);
- }
-
- private void setUpFieldMappers(final FieldMappingLookup lookup, final ObjectMappingLookup objectMappingLookup,
- final String className, final String parameterBase) {
- final IsisConfiguration configParameters = getConfiguration();
- table = configParameters.getString(parameterBase + ".table." + className);
- if (table == null) {
- final String name = getTableNameFromSpecification(specification);
- table = name;
- } else {
- table = Sql.tableIdentifier(table);
- }
-
- dbCreatesId = configParameters.getBoolean(parameterBase + "db-ids", false);
- if (configParameters.getBoolean(parameterBase + "all-fields", true)) {
- setupFullMapping(lookup, objectMappingLookup, className, configParameters, parameterBase);
- } else {
- // setupSpecifiedMapping(specification, configParameters,
- // parameterBase);
- }
-
- LOG.info("table mapping: " + table + " (" + columnList(fieldMappingByField) + ")");
- }
-
- protected String getTableNameFromSpecification(final ObjectSpecification objectSpecification) {
- return Sql.tableIdentifier(Sql.sqlName(Defaults.getTablePrefix() + objectSpecification.getShortIdentifier()));
- }
-
- protected List<ObjectAssociation> fields = new ArrayList<ObjectAssociation>();
-
- protected void getExtraFields(final List<ObjectAssociation> fields) {
- }
-
- private void setupFullMapping(final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup,
- final String className, final IsisConfiguration configParameters, final String parameterBase) {
-
- fields.addAll(specification.getAssociations(Contributed.EXCLUDED));
-
- int simpleFieldCount = 0;
- int collectionFieldCount = 0;
- for (int i = 0; i < fields.size(); i++) {
- if (fields.get(i).isNotPersisted()) {
- continue;
- } else if (fields.get(i).isOneToManyAssociation()) {
- collectionFieldCount++;
- } else {
- simpleFieldCount++;
- }
- }
-
- final ObjectAssociation[] oneToOneProperties = new ObjectAssociation[simpleFieldCount];
- final ObjectAssociation[] oneToManyProperties = new ObjectAssociation[collectionFieldCount];
- collectionMappers = new CollectionMapper[collectionFieldCount];
- collectionMapperFields = new String[collectionFieldCount];
- final IsisConfiguration subset = getConfiguration().createSubset(parameterBase + ".mapper.");
-
- for (int i = 0, simpleFieldNo = 0, collectionFieldNo = 0; i < fields.size(); i++) {
- final ObjectAssociation field = fields.get(i);
- if (field.isNotPersisted()) {
- continue;
- } else if (field.isOneToManyAssociation()) {
- oneToManyProperties[collectionFieldNo] = field;
-
- // TODO: Replace "new ForeignKeyCollectionMapper" with a factory
- // method(?) to allow a different
- // default CollectionMapper
-
- // TODO: I think the default order should be changed - and I
- // think I (KAM) have dropped support for the
- // original "association-table" implementation. This means the
- // current checks are misleading.
- final String type = subset.getString(field.getId());
- if (type == null || type.equals("association-table")) {
- // collectionMappers[collectionFieldNo] = new
- // AutoCollectionMapper(specification,
- // oneToManyProperties[collectionFieldNo], lookup);
- // collectionMappers[collectionFieldNo] = new
- // ForeignKeyCollectionMapper(oneToManyProperties[collectionFieldNo],
- // parameterBase, lookup,
- // objectMapperLookup);
-
- CollectionMapper collectionMapper = null;
-
- // Trying to detect recursion, here.
- // Let ForeignKeyInChildCollectionMapper find itself when a
- // field is a collection of the current
- // field type.
- if (this instanceof ForeignKeyInChildCollectionMapper) {
- final ForeignKeyInChildCollectionMapper mc = (ForeignKeyInChildCollectionMapper) this;
-
- if (mc.priorField == field) {
- collectionMapper = mc;
- }
- }
-
- if (collectionMapper == null) {
- // TODO: Polymorphism - is it sufficient for the
- // collectionMapper to handle the subclasses?
- final ObjectSpecification fieldSpecification = field.getSpecification();
- if (fieldSpecification.hasSubclasses() || fieldSpecification.isAbstract()) {
- // PolymorphicForeignKeyInChildCollectionBaseMapper
- // Or PolymorphicForeignKeyInChildCollectionMapper
- collectionMapper =
- new PolymorphicForeignKeyInChildCollectionBaseMapper(
- oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup,
- this, field);
- } else {
- final ForeignKeyInChildCollectionMapper mapper =
- new ForeignKeyInChildCollectionMapper(oneToManyProperties[collectionFieldNo],
- parameterBase, lookup, objectMapperLookup, this, field);
- mapper.setUpFieldMappers();
- collectionMapper = mapper;
- }
- }
-
- collectionMappers[collectionFieldNo] = collectionMapper;
- collectionMapperFields[collectionFieldNo] = field.getId();
-
- } else if (type.equals("fk-table")) {
- final String property = parameterBase + field.getId() + ".element-type";
- final String elementType = configParameters.getString(property);
- if (elementType == null) {
- throw new SqlObjectStoreException("Expected property " + property);
- }
- /*
- * collectionMappers[collectionFieldNo] = new ForeignKeyCollectionMapper(elementType,
- * oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup);
- */
- } else {
- // TODO use other mappers where necessary
- throw new NotYetImplementedException("for " + type);
- }
-
- collectionFieldNo++;
- } else if (field.isOneToOneAssociation()) {
- oneToOneProperties[simpleFieldNo] = field;
- simpleFieldNo++;
- } else {
- oneToOneProperties[simpleFieldNo] = field;
- simpleFieldNo++;
- }
- }
-
- for (final ObjectAssociation field : oneToOneProperties) {
- if (fieldMappingByField.containsKey(field)) {
- continue;
- }
- final FieldMapping mapping = lookup.createMapping(specification, field);
- fieldMappingByField.put(field, mapping);
- }
- }
-
- protected String columnList(final Map<ObjectAssociation, FieldMapping> fieldMappingByField) {
- return columnList(fieldMappingByField.values());
- }
-
- /*
- * private void setupSpecifiedMapping( final ObjectSpecification specification, final IsisConfiguration
- * configParameters, final String parameterBase) { IsisConfiguration columnMappings =
- * IsisContext.getConfiguration().createSubset(parameterBase + "column"); int columnsSize = columnMappings.size();
- * // columnNames = new String[columnsSize]; oneToOneProperties = new ObjectAssociation[columnsSize];
- *
- * int i = 0; for (Enumeration names = columnMappings.propertyNames(); names.hasMoreElements(); i++) { String
- * columnName = (String) names.nextElement(); String fieldName = columnMappings.getString(columnName);
- * oneToOneProperties[i] = specification.getAssociation(fieldName); // columnNames[i] = columnName; }
- *
- * IsisConfiguration collectionMappings = IsisContext.getConfiguration().createSubset( parameterBase +
- * "collection"); int collectionsSize = collectionMappings.size(); collectionMappers = new
- * AutoCollectionMapper[collectionsSize]; oneToManyProperties = new ObjectAssociation[collectionsSize];
- *
- * int j = 0; for (Enumeration names = collectionMappings.propertyNames(); names.hasMoreElements(); j++) { String
- * propertyName = (String) names.nextElement(); String collectionName = collectionMappings.getString(propertyName);
- * String type = collectionMappings.getString(collectionName);
- *
- * oneToManyProperties[j] = specification.getAssociation(collectionName); if (type.equals("auto")) {
- * collectionMappers[j] = new AutoCollectionMapper(this, specification, oneToManyProperties[j], getLookup()); } else
- * { // TODO use other mappers where necessary // new ReversedAutoAssociationMapper(specification, collectionName,
- * parameterBase);
- *
- * throw new NotYetImplementedException(); } } }
- */
- protected String columnList(final Collection<FieldMapping> fieldMappings) {
- final StringBuffer sql = new StringBuffer();
- for (final FieldMapping mapping : fieldMappings) {
- if (sql.length() > 0) {
- sql.append(",");
- }
- mapping.appendColumnNames(sql);
- }
- return sql.toString();
- }
-
- protected ObjectAdapter getAdapter(final ObjectSpecification spec, final Oid oid) {
- final ObjectAdapter adapter = getAdapterManager().getAdapterFor(oid);
- if (adapter != null) {
- return adapter;
- }
-
- // REVIEW: where the oid is a TypedOid, the following two lines could be replaced by
- // getPersistenceSession().recreatePersistentAdapter(oid)
- // is preferable, since then reuses the PojoRecreator impl defined within SqlPersistorInstaller
- final Object recreatedPojo = spec.createObject();
- return getPersistenceSession().mapRecreatedPojo(oid, recreatedPojo);
- }
-
- protected FieldMapping fieldMappingFor(final ObjectAssociation field) {
- return fieldMappingByField.get(field);
- }
-
- @Override
- public boolean needsTables(final DatabaseConnector connection) {
- for (int i = 0; collectionMappers != null && i < collectionMappers.length; i++) {
- if (collectionMappers[i].needsTables(connection)) {
- return true;
- }
- }
- return !connection.hasTable(table);
- }
-
- protected String values(final DatabaseConnector connector, final ObjectAdapter object) {
- final StringBuffer sql = new StringBuffer();
- for (final FieldMapping mapping : fieldMappingByField.values()) {
- mapping.appendInsertValues(connector, sql, object);
- sql.append(",");
- }
- return sql.toString();
- }
-
- private static boolean isNullOrEmpty(List<?> list) {
- return list == null || list.size() == 0;
- }
-
- @Override
- public String toString() {
- return "AbstractAutoMapper [table=" + table + ",noColumns=" + fieldMappingByField.size() + ",specification="
- + specification.getFullIdentifier() + "]";
- }
-
- protected SpecificationLoaderSpi getSpecificationLoader() {
- return IsisContext.getSpecificationLoader();
- }
-
- protected IsisConfiguration getConfiguration() {
- return IsisContext.getConfiguration();
- }
-
- protected PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- protected AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java
deleted file mode 100644
index c76cc15..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java
+++ /dev/null
@@ -1,172 +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.isis.objectstore.sql.auto;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
-import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacet;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.persistence.PersistorUtil;
-import org.apache.isis.objectstore.sql.AbstractMapper;
-import org.apache.isis.objectstore.sql.CollectionMapper;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.FieldMappingLookup;
-import org.apache.isis.objectstore.sql.IdMapping;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.jdbc.JdbcObjectReferenceMapping;
-import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
-
-public class AutoCollectionMapper extends AbstractMapper implements CollectionMapper {
- private static final Logger LOG = LoggerFactory.getLogger(AutoCollectionMapper.class);
- private String tableName;
- private final ObjectAssociation field;
- private final ObjectReferenceMapping elementMapping;
- private final IdMapping idMapping;
-
- public AutoCollectionMapper(final ObjectSpecification specification, final ObjectAssociation field,
- final FieldMappingLookup lookup) {
- this.field = field;
-
- final ObjectSpecification spec = field.getFacet(TypeOfFacet.class).valueSpec();
- idMapping = lookup.createIdMapping();
- elementMapping = lookup.createMapping(spec);
-
- final String className = specification.getShortIdentifier();
- final String columnName = field.getId();
- tableName = Sql.sqlName(className) + "_" + asSqlName(columnName);
- tableName = Sql.identifier(tableName);
- }
-
- @Override
- public void createTables(final DatabaseConnector connector) {
- if (!connector.hasTable(tableName)) {
- final StringBuffer sql = new StringBuffer();
- sql.append("create table ");
- sql.append(tableName);
- sql.append(" (");
-
- idMapping.appendColumnDefinitions(sql);
- sql.append(", ");
- elementMapping.appendColumnDefinitions(sql);
-
- sql.append(")");
-
- connector.update(sql.toString());
- }
- }
-
- @Override
- public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter parentAdapter) {
- final ObjectAdapter collectionAdapter = field.get(parentAdapter);
- if (!collectionAdapter.canTransitionToResolving()) {
- return;
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("loading internal collection " + field);
- }
-
- try {
- PersistorUtil.startResolving(collectionAdapter);
-
- final StringBuffer sql = new StringBuffer();
- sql.append("select ");
- idMapping.appendColumnNames(sql);
- sql.append(", ");
- elementMapping.appendColumnNames(sql);
- sql.append(" from ");
- sql.append(tableName);
-
- final Results rs = connector.select(sql.toString());
- final List<ObjectAdapter> list = new ArrayList<ObjectAdapter>();
- while (rs.next()) {
- final ObjectAdapter element = ((JdbcObjectReferenceMapping) elementMapping).initializeField(rs);
- if (LOG.isDebugEnabled()) {
- LOG.debug(" element " + element.getOid());
- }
- list.add(element);
- }
- final CollectionFacet collectionFacet =
- collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
- collectionFacet.init(collectionAdapter, list.toArray(new ObjectAdapter[list.size()]));
- rs.close();
- } finally {
- PersistorUtil.toEndState(collectionAdapter);
- }
- }
-
- @Override
- public boolean needsTables(final DatabaseConnector connector) {
- return !connector.hasTable(tableName);
- }
-
- @Override
- public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent) {
- final ObjectAdapter collection = field.get(parent);
- LOG.debug("saving internal collection " + collection);
-
- StringBuffer sql = new StringBuffer();
- sql.append("delete from ");
- sql.append(tableName);
- sql.append(" where ");
- final RootOid oid = (RootOid) parent.getOid();
- idMapping.appendWhereClause(connector, sql, oid);
- connector.update(sql.toString());
-
- sql = new StringBuffer();
- sql.append("insert into ");
- sql.append(tableName);
- sql.append(" (");
- idMapping.appendColumnNames(sql);
- sql.append(", ");
- elementMapping.appendColumnNames(sql);
- sql.append(" ) values (");
- idMapping.appendInsertValues(connector, sql, parent);
- sql.append(", ");
-
- final CollectionFacet collectionFacet = collection.getSpecification().getFacet(CollectionFacet.class);
- for (final ObjectAdapter element : collectionFacet.iterable(collection)) {
- final StringBuffer values = new StringBuffer();
- elementMapping.appendInsertValues(connector, values, element);
- connector.update(sql.toString() + values + ")");
- }
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln(field.getName(), "collection");
- debug.indent();
- debug.appendln("Table", tableName);
- debug.appendln("ID mapping", idMapping);
- debug.appendln("Element mapping", elementMapping);
- debug.unindent();
- }
-
-}
[07/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/src/docbkx/guide/isis-sql-objectstore.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/src/docbkx/guide/isis-sql-objectstore.xml b/component/objectstore/sql/src/docbkx/guide/isis-sql-objectstore.xml
deleted file mode 100644
index 6858fe9..0000000
--- a/component/objectstore/sql/src/docbkx/guide/isis-sql-objectstore.xml
+++ /dev/null
@@ -1,886 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
-"file:./src/docbkx/dtd-4.5/docbookx.dtd">
-<book>
- <bookinfo>
- <title><?eval ${docbkxGuideTitle}?></title>
-
- <subtitle><?eval ${docbkxGuideSubTitle}?></subtitle>
-
- <releaseinfo><?eval ${project.version}?></releaseinfo>
-
- <authorgroup>
- <author>
- <firstname>Kevin</firstname>
-
- <surname>Meyer</surname>
- </author>
-
- <author>
- <firstname>Robert</firstname>
-
- <surname>Matthews</surname>
- </author>
- </authorgroup>
-
- <legalnotice>
- <para>Permission is granted to make and distribute verbatim copies of
- this manual provided that the copyright notice and this permission
- notice are preserved on all copies.</para>
- </legalnotice>
- </bookinfo>
-
- <!-- front matter -->
-
- <toc></toc>
-
- <preface id="preface">
- <title>Preface</title>
-
- <para><emphasis>Apache Isis</emphasis> is designed to allow programmers
- rapidly develop domain-driven applications following the <ulink
- url="http://en.wikipedia.org/wiki/Naked_Objects">Naked Objects</ulink>
- pattern. It is made up of a core framework plus a number of alternate
- implementations, and supports various viewers and object stores. Apache
- Isis is hosted at the <ulink url="http://incubator.apache.org/isis">Apache
- Foundation</ulink>, and is licensed under <ulink
- url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software
- License v2</ulink>.</para>
-
- <para>This guide is written for programmers who want to use the
- <emphasis>SQL Object Store</emphasis> to persist domain objects running
- within the <emphasis>Apache Isis</emphasis> framework. Specifically, it
- covers how to write repository implementations, how to configure the
- object store, and how to deploy your applications using the object
- store.</para>
- </preface>
-
- <!--main content -->
-
- <chapter id="chp.Intro">
- <title>Operation</title>
-
- <abstract>
- <para>What's it all about?</para>
- </abstract>
-
- <sect1>
- <title>Background</title>
-
- <para>The SQL objectstore provides a fully-automatic object store that
- uses a jdbc SQL-compatible database server.</para>
-
- <para>All domain objects (entities) are introspected during
- initialisation, and have a 1-to-1 mapping onto a database table. All
- properties (values) are mapped onto one or more columns with each
- database table.</para>
-
- <para>Domain object classes are introspected and all properties
- recursively introspected to value types. Thus, if a property stores a
- reference to a class, that class's properties are introspected,
- etc.</para>
- </sect1>
-
- <sect1>
- <title>Setup</title>
-
- <sect2>
- <title>Properties</title>
-
- <para>The SQL objectstore is setup via the
- <code>isis.properties</code> file. The required variables are given
- below:</para>
-
- <blockquote>
- <para><property>isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver</property></para>
-
- <para><property>isis.persistor.sql.jdbc.connection=jdbc:hsqldb:file:hsql-db/tests</property></para>
-
- <para><property>isis.persistor.sql.jdbc.user=sa</property></para>
-
- <para><property>isis.persistor.sql.jdbc.password=</property></para>
- </blockquote>
-
- <para>The driver property must contain the name of the jdbc driver
- class that provides access to your SQL server. Known examples are
- given below in <xref linkend="sec.servers.tested" />.</para>
- </sect2>
-
- <sect2>
- <title>Table Creation</title>
-
- <para>Missing database tables are automatically created when the SQL
- objectstore is initialised.</para>
-
- <para>Please note that changes to domain classes such as renaming
- fields (properties) or the classes themselves, are
- <emphasis>not</emphasis> automatically detected. If you rename a
- property after a table has been created, you should use the
- appropriate database administration tool to rename the column in the
- containing table.</para>
-
- <para>If you rename a domain class (entity), you must also rename the
- appropriate table.</para>
- </sect2>
- </sect1>
-
- <sect1>
- <title>Mappers</title>
-
- <para>The mappers take care of mapping a value type onto a SQL data
- type. Default mappers are provided by
- JdbcFieldMappingFactoryInstaller.</para>
-
- <sect2>
- <title id="sec.mappers.modifiable-values">Modifiable values</title>
-
- <para>The following SQL datatypes can be overridden, if specified in
- the properties file (the default value is given in parenthesis), [the
- mapped value classes are given in square brackets]:<simplelist>
- <member>isis.persistor.sql.datatypes.timestamp (DATETIME)
- [TimeStamp, java.sql.Timestamp]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.datetime (DATETIME)
- [DateTime]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.date (DATE) [Date,
- java.sql.Date, java.util.Date]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.time (TIME) [Time]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.double (FLOAT)
- [double]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.float (FLOAT)
- [float]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.short (INT) [short]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.long (INT) [long,
- Color]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.int (INT) [int]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.boolean (CHAR(1))
- [boolean]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.string (VARCHAR(65))
- [String]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.longstring (VARCHAR(128))
- [String]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.password (VARCHAR(120))
- [Password]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.default (VARCHAR(65))
- [Everything else, e.g. Image]</member>
- </simplelist></para>
-
- <para><simplelist>
- <member>isis.persistor.sql.datatypes.primarykey (INTEGER)
- [IdMappingAbstract -> JdbcObjectReferenceMapping ->
- JdbcObjectReferenceFieldMapping]</member>
- </simplelist></para>
-
- <para>The final value, primarykey, is a special value.</para>
-
- <para>In general, be very careful about changing the SQL data type, as
- the default value mappers are written assuming the default values.
- Data parsing uses prepared statements and reads/writes values as
- objects.</para>
-
- <para>The datatype longstring is used to store classnames, required
- for polymorphism.</para>
- </sect2>
-
- <sect2>
- <title>Floating Point Value Limits</title>
-
- <para><emphasis>Caution:</emphasis> Testing on certain database
- servers (MySQL and PostgreSQL) has shown that <code>float</code>s and
- <code>double</code>s (stored as <code>FLOAT</code> or <code>DOUBLE
- PRECISION</code> respectively) are not stored to the same resolution
- as supported by Java. The tested range of float is 1E-37 to 1E38, and
- the tested range of double is 1E-307 to 1E308.</para>
- </sect2>
-
- <sect2>
- <title>Fixed values</title>
-
- <para>The following classes are not modifiable:</para>
-
- <para>[char] is set to CHAR(1)</para>
-
- <para>[Money] value is FLOAT, currency is VARCHAR(3)</para>
-
- <para>[Percentage] is FLOAT</para>
- </sect2>
-
- <sect2>
- <title>Modifying individual property types</title>
-
- <para>By default, all property types will use the SQL datatype, as
- determined above (see <xref
- linkend="sec.mappers.modifiable-values" />), but it is possible to
- override these values for individual object properties, by specifying
- the following override in the properties file:</para>
-
- <para><property>isis.persistor.sql.automapper.type.<object>.<property>=<SQL
- data type></property></para>
-
- <para>where</para>
-
- <itemizedlist>
- <listitem>
- <para>object is the final part of the domain object name (e.g. in
- my.domain.Member, it'll be Member)</para>
- </listitem>
-
- <listitem>
- <para>property is the lower case property name (e.g. in getName(),
- it'll be name)</para>
- </listitem>
-
- <listitem>
- <para>SQL data type is an acceptable datatype (e.g. VARCHAR(255)
- )</para>
- </listitem>
- </itemizedlist>
-
- <para>Again, please be very careful about changing the defaults as the
- value mappers make assumptions about the underlying data type.</para>
-
- <para>It is safe to change the size of VARCHAR() types, e.g. when you
- know only a partcular field requires more that 65 characters, the
- default String length.</para>
- </sect2>
- </sect1>
-
- <sect1>
- <title>Naming Conventions</title>
-
- <para>While case is determined by the capabilities of the database
- driver, all SQL names will be written in UPPER CASE, below.</para>
-
- <sect2>
- <title>Tables</title>
-
- <para>By default, all Isis tables are preceded with "ISIS_". This
- behaviour can be altered by specifying a replacement table prefix. See
- <xref linkend="sec.defaults.tableprefix" />.</para>
-
- <sect3>
- <title>Internal Tables</title>
-
- <para>ISIS_ADMIN_SERIAL_ID ISIS_ADMIN_SERVICES</para>
- </sect3>
-
- <sect3>
- <title>Domain Tables</title>
-
- <para>Only the "class" part of the package name is used. Thus a
- domain class called "some.package.Client", will be mapped onto a
- table "ISIS_CLIENT" (assuming that the default table prefix has not
- been changed).</para>
- </sect3>
- </sect2>
-
- <sect2>
- <title>Columns</title>
-
- <sect3>
- <title>Internal column: pk_id</title>
-
- <para>ID column: PK_ID</para>
-
- <para>VERSION BIGINT,</para>
-
- <para>MODIFIED_BY VARCHAR(32),</para>
-
- <para>MODIFIED_ON TIMESTAMP</para>
-
- <para>The default ID column name is "PK_ID", but this can be
- over-ridden by specifying the new name in the properties
- file:</para>
-
- <para><property>isis.persistor.sql.pk_id=id</property></para>
-
- <para><property>ID column: ID</property></para>
-
- <para><property>Used internally by Isis to record services, in the
- table "ISIS_ADMIN_SERVICES".</property></para>
- </sect3>
-
- <sect3>
- <title>Properties</title>
-
- <para>Most properties are named as per the class property. This
- means you must take care not to use SQL reserved labels are property
- names. The exceptions are collections and multi-field values (e.g.
- Money).</para>
- </sect3>
-
- <sect3>
- <title>Collections</title>
-
- <para>Collections are mapped onto the child class:</para>
-
- <para>If a parent class (some.package.Parent) has a collection of
- (some.other.package.Child) named "children", the child table
- (ISIS_CHILD) gets a column labeled "FK_PARENT_CHILDREN" of type
- primarykey. The child property is assigned the ID of the parent
- class.</para>
-
- <para>This means that a given child can only appear in one parent's
- collection of the same name.</para>
- </sect3>
-
- <sect3>
- <title>Multi-field values</title>
-
- <para>Some value types need more than 1 field to store their values,
- e.g. Money - some.package.class#price.</para>
-
- <para>In this case, the SQL objectstore creates 2 fields, price1 and
- price2.</para>
-
- <para>See "<code>JdbcMoneyValueMapper</code>", which extends
- "<code>AbstractJdbcMultiFieldMapping</code>".</para>
- </sect3>
- </sect2>
- </sect1>
-
- <sect1>
- <title>Number of instances returned by queries</title>
-
- <para>By default, only up to 100 object instances are returned by
- queries. This value can be changed by specifying:</para>
-
- <para><property>isis.persistor.sql.maxinstances=100</property></para>
- </sect1>
-
- <sect1>
- <title>Versioning</title>
-
- <para>Isis uses a version number to assist in detecting concurrency
- conflicts.</para>
-
- <para>However, if you need to turn off versioning completely, or for a
- particular table, you can control it with:</para>
-
- <para><property>isis.persistor.sql.default.versioning=false</property></para>
-
- <para>for global control, or by table:</para>
-
- <para><property>isis.persistor.sql.default.versioning.members=false</property></para>
- </sect1>
-
- <sect1>
- <title>Password values</title>
-
- <para>The <code>JdbcPasswordValueMapper</code> value mapper has the
- ability to (weakly) encode the password value strings stored in the
- database tables.</para>
-
- <para>By adding the following property values:</para>
-
- <blockquote>
- <para><property>isis.persistor.sql.default.password.seed=<random
- string></property></para>
-
- <para><property>isis.persistor.sql.default.password.length=<integer
- length></property></para>
- </blockquote>
-
- <para>You can enable a weak password encoding/decoding scheme that will
- obscure password values from casual browsers of your database
- tables.</para>
-
- <para>The length of all stored passwords is the same, and determined by
- the <property>isis.persistor.sql.default.password.length</property>
- property. This length must not exceed the SQL storage, as defined in
- <xref linkend="sec.mappers.modifiable-values" />.</para>
-
- <para>The passwords are convolved with the value of the string given by
- the <property>isis.persistor.sql.default.password.seed</property>
- property, and the resulting string is stored in the database
- table.</para>
-
- <para>If <property>isis.persistor.sql.default.password.seed</property>
- is undefined (null), the passwords are stored as plain text.</para>
- </sect1>
- </chapter>
-
- <chapter id="ch.supported.dbs">
- <title>Supported Database Servers</title>
-
- <abstract>
- <para>Which SQL database servers have been used?</para>
- </abstract>
-
- <sect1>
- <!--content: List of database servers tested.-->
-
- <title id="sec.servers.tested">Tested</title>
-
- <para>The following database servers are tested in the object store
- integration tests:<itemizedlist>
- <listitem>
- <para>HSQLDB (tested against 1.8.0.10)</para>
- </listitem>
-
- <listitem>
- <para>Postgresql (tested on 8.3.12-ubuntu9.04)</para>
- </listitem>
-
- <listitem>
- <para>MySQL (tested on 5.1.31-1ubuntu2)</para>
- </listitem>
-
- <listitem>
- <para>Microsoft SQL Server 2008 (Only from 2008 is DATE and TIME
- supported)</para>
- </listitem>
- </itemizedlist></para>
-
- <sect2>
- <title>HSQLDB</title>
-
- <para></para>
- </sect2>
-
- <sect2>
- <title>Postgresql</title>
-
- <para><blockquote>
- <para><property>isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver</property></para>
-
- <para><property>isis.persistor.sql.jdbc.connection=jdbc:hsqldb:file:hsql-db/tests</property></para>
-
- <para><property>isis.persistor.sql.jdbc.user=sa</property></para>
-
- <para><property>isis.persistor.sql.jdbc.password=</property></para>
- </blockquote>The default <classname>TimeStamp</classname> and
- <classname>DateTime</classname> SQL data class is DATETIME, which does
- not work on Postgresql. Here, the default must be replaced with the
- following properties file entries:</para>
-
- <blockquote>
- <para>isis.persistor.sql.datatypes.timestamp=TIMESTAMP</para>
-
- <para>isis.persistor.sql.datatypes.datetme=TIMESTAMP</para>
-
- <para>isis.persistor.sql.datatypes.double=DOUBLE PRECISION</para>
- </blockquote>
-
- <para></para>
- </sect2>
-
- <sect2>
- <title>MySQL</title>
-
- <para>There was an issue with storing and correctly retrieving date
- (time) values - a special "try .. catch" has been used to ensure that
- UTC temporal values are correctly retrieved.</para>
-
- <para>The following data type overrides may be required:</para>
-
- <blockquote>
- <para>isis.persistor.sql.datatypes.double=DOUBLE PRECISION</para>
- </blockquote>
-
- <para></para>
- </sect2>
-
- <sect2>
- <title>Microsoft SQL Server 2008</title>
-
- <para>The sourceforge driver seemed to work well enough for
- testing.</para>
-
- <para>The tested connection parameters were:</para>
-
- <para><blockquote>
- <para># SQL Server </para>
-
- <para>#isis.persistence.sql.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver</para>
-
- <para>isis.persistence.sql.jdbc.driver=net.sourceforge.jtds.jdbc.Driver</para>
-
- <para>isis.persistence.sql.jdbc.connection=jdbc:jtds:sqlserver://<server>;databaseName=<database></para>
-
- <para>isis.persistence.sql.jdbc.user=<user></para>
-
- <para>isis.persistence.sql.jdbc.password=<password></para>
- </blockquote></para>
-
- <para></para>
- </sect2>
-
- <sect2>
- <title>IBM DB2 (v8)</title>
-
- <para>Beware! This version of DB2 has a very small limit on table and
- column names. You will have to keep your domain class and property
- names short to suit, especially collections!</para>
-
- <para>The tested connection parameters were:</para>
-
- <blockquote>
- <para># DB2 test</para>
-
- <para>
- isis.persistence.sql.jdbc.driver=com.ibm.db2.jcc.DB2Driver</para>
-
- <para>
- isis.persistence.sql.jdbc.connection=jdbc:db2://<host>:50000/<database></para>
-
- <para> isis.persistence.sql.jdbc.user=<user></para>
-
- <para> isis.persistence.sql.jdbc.password=<password></para>
- </blockquote>
- </sect2>
- </sect1>
-
- <sect1>
- <title>Tested values</title>
-
- <para>The following value types have been tested (stored and
- retrieved):</para>
-
- <itemizedlist>
- <listitem>
- <para>standard values: integer, short, long (INT), float, double
- (FLOAT), char (CHAR(2)).</para>
- </listitem>
-
- <listitem>
- <para>standard classes: Money (FLOAT and VARCHAR(3)), Percentage
- (FLOAT), Password (VARCHAR(12)), Color (INT), String (VARCHAR
- (65)).</para>
- </listitem>
-
- <listitem>
- <para>Special value mappers:</para>
-
- <itemizedlist>
- <listitem>
- <para><code>org.apache.isis.applib.value.date</code> and
- <code>java.sql.date</code> (DATE, via
- <code>org.apache.isis.alternatives.objectstore.sql.jdbc.JdbcDateMapper</code>)</para>
- </listitem>
-
- <listitem>
- <para>Time, DateTime (DATETIME), java.sql.Time, java.util.Date,
- java.sql.Timestamp (DATETIME), TimeStamp (DATETIME) blah</para>
- </listitem>
- </itemizedlist>
- </listitem>
-
- <listitem>
- <para></para>
- </listitem>
- </itemizedlist>
-
- <para>Default automapper is installed by
- <code>org.apache.isis.alternatives.objectstore.sql.FieldMappingFactoryInstaller</code>
- ..</para>
-
- <para>Default automapper is
- <code>org.apache.isis.objectstore.sql.jdbc.installer.JdbcFieldMappingFactoryInstaller</code></para>
-
- <para></para>
- </sect1>
- </chapter>
-
- <chapter>
- <title id="sec.defaults">Defaults</title>
-
- <para>The SQL objectstore exposes several defaults that can be replaced
- either in configuration or at runtime.</para>
-
- <para>The class
- <code>org.apache.isis.objectstore.sql.Defaults</code>
- contains the following:</para>
-
- <para>Programmatic, at runtime:</para>
-
- <itemizedlist>
- <listitem>
- <para>TimeZone: <code>setTimeZone(DateTimeZone.UTC)</code></para>
- </listitem>
- </itemizedlist>
-
- <para>Configuration, e.g. in isis.properties:</para>
-
- <para><itemizedlist>
- <listitem>
- <para>Primary key column:</para>
-
- <para><property>isis.persistor.sql.default.pk_id=pk_id</property></para>
- </listitem>
-
- <listitem>
- <para>Service ID column:</para>
-
- <para><property>isis.persistor.sql.default.id=id</property></para>
- </listitem>
-
- <listitem>
- <para>Maximum records returned by objectstore methods that return a
- list/collection, such as <code>allMatches()</code>, etc:</para>
-
- <para><property><property>isis.persistor.sql.default.maxinstances=100</property></property></para>
- </listitem>
-
- <listitem>
- <para id="sec.defaults.tableprefix" xreflabel="Table Prefix">Table
- prefix. The default prefix "isis_" is added to all table created by
- the object store. This prefix can be replaced, or left off entirely
- by specifying an empty value, e.g.:</para>
-
- <para><property>isis.persistor.sql.default.tableprefix=</property></para>
- </listitem>
-
- <listitem>
- <para>See "Modifiable values", <link
- linkend="sec.mappers.modifiable-values">above</link>.</para>
- </listitem>
- </itemizedlist></para>
- </chapter>
-
- <chapter>
- <title>Polymorphism</title>
-
- <para>The SQL Objectstore supports polymorphic classes. Both properties
- and collections are supported.</para>
-
- <sect1>
- <title>Properties</title>
-
- <para>Polymorphic properties are handled with
- <classname>JdbcPolymorphicObjectReferenceMapping</classname>.</para>
-
- <para>Two columns are created in the class table: The actual instance
- class type, and the instance ID.</para>
- </sect1>
-
- <sect1>
- <title>Collections</title>
-
- <para>There are two implementations currently selectable by editting
- <classname>AbstractAutoMapper</classname>.</para>
-
- <para>The default implementation is
- <classname>PolymorphicForeignKeyInChildCollectionBaseMapper</classname>.</para>
-
- <sect2>
- <title>PolymorphicForeignKeyInChildCollectionBaseMapper</title>
-
- <para>Creates two columns in the child class table, to contain the
- child class type and child class ID.</para>
-
- <para>Used to map 1-to-many collections by creating, in the collection
- child table (which may be an interface or abstract class), 2 columns
- per parent collection.</para>
-
- <para>The first column is the class type, the second is the entity
- ID.</para>
-
- <para>The columns are named by combining the final part of the parent
- class name and the collection variable name.</para>
-
- <para>Collection loading is a case of iterating through all collection
- entries and adding the named class instance of the stored ID.</para>
- </sect2>
-
- <sect2>
- <title>PolymorphicForeignKeyInChildCollectionMapper</title>
-
- <para>Used to map 1-to-many collections by creating, in the child
- table, 1 column per parent collection.</para>
-
- <para>The column is named by combining the final part of the parent
- class name and the collection variable name.</para>
-
- <para>Collection loading is a case of iterating through all subclasses
- of the collection type and adding class instances of the stored ID.
- This could be problematic if different subclasses have the same
- ID.</para>
- </sect2>
- </sect1>
- </chapter>
-
- <appendix>
- <title>Example</title>
-
- <para></para>
-
- <para><property>isis.persistor.sql.jdbc.driver=com.mysql.jdbc.Driver</property></para>
-
- <para><property>isis.persistor.sql.jdbc.connection=jdbc:mysql://localhost/isis_data</property></para>
-
- <para><property>isis.persistor.sql.jdbc.user=isis</property></para>
-
- <para><property>isis.persistor.sql.jdbc.password=noneofyourbusiness</property></para>
-
- <para><property></property></para>
-
- <para><property>isis.persistor.sql.default.versioning.Member=false
- </property></para>
-
- <para><property>isis.persistor.sql.automapper.type.Member.address=VARCHAR(255)
- </property></para>
-
- <para><property>isis.persistor.sql.automapper.type.Member.comments=VARCHAR(255)
- </property></para>
- </appendix>
-
- <appendix>
- <title>Correspondence</title>
-
- <abstract>
- <para>Who said what, when?</para>
- </abstract>
-
- <sect1 id="sec.module-ui">
- <title>Email</title>
-
- <para></para>
-
- <sect2>
- <title>2011/02/01, Response by Dan Haywood</title>
-
- <para><remark>At the moment I'm just putting down whatever comes into
- my head, with a view of later editting it into a coherent document,
- but obviously there are questions of level of detail, etc. For
- example, should I really bother with describing what persistance is,
- and how the domain classes are introspected?! </remark></para>
-
- <para>I don't think so, no.</para>
-
- <para>That said, if you do find yourself writing "introductory"
- material like this, we can always move it. The place for such stuff
- should probably be the "core" documentation
- (core/src/docbkx/guide/isis-core.xml), which is what I'm chipping away
- at myself.</para>
-
- <para><remark>Yes to: what SQL data types are used by default, yes to:
- how to override the automappers and provide your own mapper, yes to:
- how collections and parent/child relatonships are handled, etc.
- </remark></para>
-
- <para>It'd be worth showing examples of all the different types of
- mappings supported, as well as those that are not supported.</para>
-
- <para>For example:</para>
-
- <itemizedlist>
- <listitem>
- <para>Id generation - how is that supported?</para>
- </listitem>
-
- <listitem>
- <para>optimistic locking - how supported?</para>
- </listitem>
-
- <listitem>
- <para>one<->many</para>
- </listitem>
-
- <listitem>
- <para>one<-many</para>
- </listitem>
-
- <listitem>
- <para>one->many</para>
- </listitem>
-
- <listitem>
- <para>two one<->many relationships between same types A and
- B (if I recall, this isn't supported?)</para>
- </listitem>
-
- <listitem>
- <para>many<->many</para>
- </listitem>
-
- <listitem>
- <para>many->many - subtype relationships (roll-up, roll-down,
- table per subtype)</para>
- </listitem>
-
- <listitem>
- <para>polymorphic relationships to interfaces</para>
- </listitem>
- </itemizedlist>
-
- <para>You could also peruse some of the Hibernate ORM docs for
- examples of mappings there; that might prompt you to consider some
- additional scenarios.</para>
-
- <para><remark>What else?</remark></para>
-
- <para>Obviously, any additional entries required in isis.properties to
- enable the SQL object store. In addition, as background it'd be worth
- explaining about the different subcomponents used by the object store:
- the OidGenerator, PersistAlgorithm, TransactionManager Also, I know
- that the JPA object store has to configure a different
- ClassSubstitutor/ObjectFactory, because it leaves the ORM to perform
- cglib proxying. I don't think you have any similar restrictions, but
- it might be worth saying so.</para>
- </sect2>
- </sect1>
-
- <sect1>
- <title>Edit History</title>
-
- <para>Last editted: Kevin, 17/10/2011.<!--dd/mm/yyyy--></para>
- </sect1>
- </appendix>
-</book>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/src/main/appended-resources/supplemental-models.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/src/main/appended-resources/supplemental-models.xml b/component/objectstore/sql/src/main/appended-resources/supplemental-models.xml
deleted file mode 100644
index ecd3906..0000000
--- a/component/objectstore/sql/src/main/appended-resources/supplemental-models.xml
+++ /dev/null
@@ -1,106 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 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. -->
-<supplementalDataModels xmlns="http://maven.apache.org/supplemental-model/1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/supplemental-model/1.0.0 http://maven.apache.org/xsd/supplemental-model-1.0.0.xsd">
-
- <supplement>
- <project>
- <groupId>aopalliance</groupId>
- <artifactId>aopalliance</artifactId>
- <version>1.0</version>
- <licenses>
- <license>
- <name>Public Domain</name>
- </license>
- </licenses>
- </project>
- </supplement>
-
- <supplement>
- <!-- not quite sure why licenses:download-license flags this, since license info seems to be in its POM -->
- <project>
- <groupId>org.datanucleus</groupId>
- <artifactId>datanucleus-jodatime</artifactId>
- <version>3.1.1</version>
- <licenses>
- <license>
- <name>The Apache Software License, Version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
- </license>
- </licenses>
- </project>
- </supplement>
-
- <supplement>
- <project>
- <groupId>org.scannotation</groupId>
- <artifactId>scannotation</artifactId>
- <version>1.0.3</version>
- <licenses>
- <license>
- <name>The Apache Software License, Version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
- <distribution>repo</distribution>
- </license>
- </licenses>
- </project>
- </supplement>
-
- <supplement>
- <project>
- <groupId>dom4j</groupId>
- <artifactId>dom4j</artifactId>
- <version>1.6.1</version>
- <licenses>
- <license>
- <name>BSD License</name>
- <url>http://dom4j.sourceforge.net/dom4j-1.6.1/license.html</url>
- <distribution>repo</distribution>
- </license>
- </licenses>
- </project>
- </supplement>
-
- <supplement>
- <project>
- <groupId>net.jcip</groupId>
- <artifactId>jcip-annotations</artifactId>
- <version>1.0</version>
- <licenses>
- <license>
- <name>Creative Commons Attribution 2.5 License</name>
- <url>http://creativecommons.org/licenses/by/2.5/</url>
- <distribution>repo</distribution>
- </license>
- </licenses>
- </project>
- </supplement>
-
-
- <supplement>
- <project>
- <groupId>xalan</groupId>
- <artifactId>xalan</artifactId>
- <version>2.7.0</version>
- <licenses>
- <license>
- <name>The Apache Software License, Version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
- <distribution>repo</distribution>
- </license>
- </licenses>
- </project>
- </supplement>
-
-
-</supplementalDataModels>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/src/site/apt/index.apt b/component/objectstore/sql/src/site/apt/index.apt
deleted file mode 100644
index fa4323b..0000000
--- a/component/objectstore/sql/src/site/apt/index.apt
+++ /dev/null
@@ -1,48 +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.
-
-
-
-SQL ObjectStore
-
- The <sql> object store module provides the ability to persist
- domain objects into an RDBMS. It has no external dependencies,
- using simply JDBC.
-
- For more information, see the
- {{{./sql-impl/index.html}Implementation}},
- {{{./sql-tests-common/index.html}Common Tests}} and
- {{{./sql-tests-served/index.html}Served Tests}}
- documentation.
-
-
-Alternatives
-
- Alternatives include:
-
- * the {{{../dflt/index.html}dflt}} in-memory object store (for prototyping only)
-
- * the {{{../xml/index.html}XML}} object store
-
- * the {{{../nosql/index.html}NoSQL}} object store
-
- []
-
- Another more sophisticated but also more complex alternative has been implemented
- using JPA. However, this is currently not part of Isis because it has a
- dependency on Hibernate (not compatible with the Apache license). One
- option under consideration is to port JPA object store to use OpenJPA.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/src/site/apt/jottings.apt b/component/objectstore/sql/src/site/apt/jottings.apt
deleted file mode 100644
index c5d1200..0000000
--- a/component/objectstore/sql/src/site/apt/jottings.apt
+++ /dev/null
@@ -1,24 +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.
-
-
-
-Jottings
-
- This page is to capture any random jottings relating to this module prior
- to being moved into formal documentation.
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/src/site/site.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/src/site/site.xml b/component/objectstore/sql/src/site/site.xml
deleted file mode 100644
index f3e4146..0000000
--- a/component/objectstore/sql/src/site/site.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project>
-
- <body>
- <breadcrumbs>
- <item name="SQL" href="index.html"/>
- </breadcrumbs>
-
- <menu name="SQL Objectstore">
- <item name="About" href="index.html" />
- <item name="Jottings" href="jottings.html" />
- </menu>
-
- <menu name="Objectstore Modules">
- <item name="Default (in-mem)" href="../dflt/index.html" />
- <item name="XML" href="../xml/index.html" />
- <item name="SQL" href="../sql/index.html" />
- <item name="NoSQL" href="../nosql/index.html" />
- </menu>
-
- <menu name="SQL OS Modules">
- <item name="Implementation" href="./sql-impl/index.html" />
- <item name="Tests" href="./sql-tests-common/index.html" />
- <item name="Integration Tests" href="./sql-tests-served/index.html" />
- </menu>
-
- <menu name="Documentation">
- <item name="${docbkxGuideTitle} (PDF)" href="docbkx/pdf/${docbkxGuideName}.pdf" />
- <item name="${docbkxGuideTitle} (HTML)" href="docbkx/html/guide/${docbkxGuideName}.html" />
- </menu>
-
- <menu name="Maven Reports" ref="reports" />
- </body>
-</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/NOTICE
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/NOTICE b/mothballed/component/objectstore/sql/NOTICE
new file mode 100644
index 0000000..ba21d0c
--- /dev/null
+++ b/mothballed/component/objectstore/sql/NOTICE
@@ -0,0 +1,7 @@
+Apache Isis
+Copyright 2010-2013 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/pom.xml
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/pom.xml b/mothballed/component/objectstore/sql/pom.xml
new file mode 100644
index 0000000..2240e6c
--- /dev/null
+++ b/mothballed/component/objectstore/sql/pom.xml
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <relativePath>../../../core/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-sql</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <name>Isis SQL ObjectStore</name>
+
+ <description>
+ Provides JDBC-based persistence.
+ </description>
+
+ <packaging>pom</packaging>
+
+ <properties>
+ <isis-objectstore-xml.version>1.0.0-SNAPSHOT</isis-objectstore-xml.version>
+
+ <siteBaseDir>.</siteBaseDir>
+ <relativeUrl/>
+
+ <docbkxGuideTitle>Apache Isis Default Runtime SQL ObjectStore</docbkxGuideTitle>
+ <docbkxGuideSubTitle>Configuration and Deployment Guide</docbkxGuideSubTitle>
+ <docbkxGuideName>isis-sql-objectstore</docbkxGuideName>
+ </properties>
+
+ <!-- used in Site generation for relative references. -->
+ <url>http://isis.apache.org/${relativeUrl}</url>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <!-- Apache Release Audit Tool -->
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>0.8</version>
+ <configuration>
+ <excludes>
+ <!--
+ overriding inherited excludes from oia.core:isis
+ with a more specific set for this component
+ -->
+ <exclude>**/target/**</exclude>
+ <exclude>**/target-ide/**</exclude>
+
+ <exclude>**/*.project</exclude>
+ <exclude>**/.classpath</exclude>
+ <exclude>**/.settings/**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>com.agilejava.docbkx</groupId>
+ <artifactId>docbkx-maven-plugin</artifactId>
+ <inherited>false</inherited>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>${maven-project-info-reports-plugin}</version>
+ <inherited>false</inherited>
+ <reportSets>
+ <reportSet>
+ <inherited>false</inherited>
+ <reports>
+ <report>dependency-management</report>
+ <report>plugins</report>
+ <report>modules</report>
+ <report>summary</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+
+
+ <modules>
+ <module>sql-impl</module>
+ <module>sql-tests-common</module>
+ <module>sql-tests-served</module>
+ </modules>
+
+ <dependencyManagement>
+ <dependencies>
+
+ <!-- for benefit of application developers, using scope=import -->
+ <dependency>
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-sql-impl</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-sql-tests-common</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-sql-tests-common</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-sql-tests-served</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <!-- Required to support the XML cross-test -->
+ <dependency>
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-xml</artifactId>
+ <version>${isis-objectstore-xml.version}</version>
+ </dependency>
+
+
+ <!-- Test environment -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
+
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/pom.xml
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/pom.xml b/mothballed/component/objectstore/sql/sql-impl/pom.xml
new file mode 100644
index 0000000..2c2cc81
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-sql</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>isis-objectstore-sql-impl</artifactId>
+ <name>Isis SQL ObjectStore Implementation</name>
+ <description>SQL Objectstire Implementation. Uses jdbc for maximum compatibility.</description>
+
+ <properties>
+ <siteBaseDir>..</siteBaseDir>
+ <relativeUrl>sql-impl/</relativeUrl>
+ </properties>
+
+ <!-- used in Site generation for relative references. -->
+ <url>http://isis.apache.org/${relativeUrl}</url>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>${maven-project-info-reports-plugin}</version>
+ <inherited>false</inherited>
+ <configuration>
+ <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <inherited>false</inherited>
+ <reports>
+ <report>dependencies</report>
+ <report>dependency-convergence</report>
+ <report>plugins</report>
+ <report>summary</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-runtime</artifactId>
+ </dependency>
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/sqlos-testing.properties
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/sqlos-testing.properties b/mothballed/component/objectstore/sql/sql-impl/sqlos-testing.properties
new file mode 100644
index 0000000..29d5a76
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/sqlos-testing.properties
@@ -0,0 +1,59 @@
+# 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.
+# run with SQL object store
+#isis.object-store=org.apache.isis.persistor.sql.SqlObjectStore
+#isis.persistor.sql.connection=org.apache.isis.persistor.sql.SimpleConnection
+#isis.persistor.sql.database=jdbc:hsqldb:tmp/hsql-db
+#isis.persistor.sql.database=jdbc:hsqldb:hsql://localhost
+#isis.persistor.sql.driver=org.hsqldb.jdbcDriver
+#isis.persistor.sql.user=sa
+#isis.persistor.sql.password=
+
+
+#isis.oidgenerator=org.apache.isis.persistor.sql.SqlOidGenerator
+
+#isis.object-store=org.apache.isis.persistor.sql.SqlObjectStore
+isis.persistor.sql.connector=org.apache.isis.persistor.sql.jdbc.JdbcConnectorFactory
+isis.persistor.sql.automapper=org.apache.isis.persistor.sql.auto.AutoMapperFactory
+
+isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver
+isis.persistor.sql.jdbc.connection=jdbc:hsqldb:tmp/hsql-db
+isis.persistor.sql.jdbc.user=sa
+isis.persistor.sql.jdbc.password=
+
+
+## log4j
+# apache's log4j is used to provide system logging.
+##
+log4j.rootCategory=OFF, Console
+
+# The console appender
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.target=System.out
+log4j.appender.Console.layout=org.apache.log4j.PatternLayout
+log4j.appender.Console.layout.ConversionPattern=%-5r [%-20c{1}] %-5p %m -- %l%n
+
+
+log4j.rootCategory=DEBUG, File
+# The file appender
+log4j.appender.File=org.apache.log4j.RollingFileAppender
+log4j.appender.File.file=isis.log
+log4j.appender.File.append=false
+#log4j.appender.File.maxFileSize=500KB
+#log4j.appender.File.maxBackupIndex=1
+log4j.appender.File.layout=org.apache.log4j.PatternLayout
+log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractDatabaseConnector.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractDatabaseConnector.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractDatabaseConnector.java
new file mode 100644
index 0000000..a993d33
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractDatabaseConnector.java
@@ -0,0 +1,46 @@
+/*
+ * 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.isis.objectstore.sql;
+
+public abstract class AbstractDatabaseConnector implements DatabaseConnector {
+ private boolean isUsed;
+
+ @Override
+ public final void setUsed(final boolean isUsed) {
+ this.isUsed = isUsed;
+ }
+
+ @Override
+ public final boolean isUsed() {
+ return isUsed;
+ }
+
+ private DatabaseConnectorPool pool;
+
+ @Override
+ public final void setConnectionPool(final DatabaseConnectorPool pool) {
+ this.pool = pool;
+ }
+
+ @Override
+ public final DatabaseConnectorPool getConnectionPool() {
+ return pool;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractFieldMappingFactory.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractFieldMappingFactory.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractFieldMappingFactory.java
new file mode 100644
index 0000000..eb3d48b
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractFieldMappingFactory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.mapping.FieldMappingFactory;
+
+public abstract class AbstractFieldMappingFactory implements FieldMappingFactory {
+
+ protected String getTypeOverride(final ObjectSpecification object, final ObjectAssociation field, final String type) {
+ // isis.persistor.sql.automapper.default
+ final IsisConfiguration configParameters = IsisContext.getConfiguration();
+ final String find = object.getShortIdentifier() + "." + field.getId();
+ final String property = SqlObjectStore.BASE_NAME + ".automapper.type." + find;
+ final String dataType = configParameters.getString(property, type);
+ return dataType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractMapper.java
new file mode 100644
index 0000000..1ec41d4
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractMapper.java
@@ -0,0 +1,53 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.util.Date;
+
+import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+
+
+public abstract class AbstractMapper {
+
+ public abstract void createTables(final DatabaseConnector connector);
+
+ protected boolean needsTables(final DatabaseConnector connector) {
+ return false;
+ }
+
+ public void startup(final DatabaseConnector connector) {
+ if (needsTables(connector)) {
+ createTables(connector);
+ }
+ }
+
+ public final void shutdown() {
+ }
+
+ protected String asSqlName(final String name) {
+ return Sql.sqlName(name);
+ }
+
+ protected Version createVersion(final long versionSequence) {
+ return SerialNumberVersion.create(versionSequence, "", new Date());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/CollectionMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/CollectionMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/CollectionMapper.java
new file mode 100644
index 0000000..9d19bbc
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/CollectionMapper.java
@@ -0,0 +1,36 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+
+public interface CollectionMapper {
+
+ public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent);
+
+ public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent);
+
+ void createTables(DatabaseConnector connection);
+
+ boolean needsTables(DatabaseConnector connection);
+
+ public void debugData(DebugBuilder debug);
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnector.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnector.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnector.java
new file mode 100644
index 0000000..602a1cb
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnector.java
@@ -0,0 +1,79 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+
+public interface DatabaseConnector {
+ /*
+ * @deprecated Results callStoredProcedure(String name, Parameter[]
+ * parameters);
+ */
+ void close();
+
+ int count(String sql);
+
+ void delete(String sql);
+
+ // MultipleResults executeStoredProcedure(String name, Parameter[]
+ // parameters);
+
+ boolean hasTable(String tableName);
+
+ boolean hasColumn(String tableName, String columnName);
+
+ void insert(String sql);
+
+ void insert(String sql, Object oid);
+
+ Results select(String sql);
+
+ /**
+ * Updates the database using the specified sql statement, and returns the
+ * number of rows affected.
+ */
+ int update(String sql);
+
+ void setUsed(boolean isUsed);
+
+ boolean isUsed();
+
+ void commit();
+
+ void rollback();
+
+ void setConnectionPool(DatabaseConnectorPool pool);
+
+ DatabaseConnectorPool getConnectionPool();
+
+ void begin();
+
+ void debug(DebugBuilder debug);
+
+ SqlMetaData getMetaData();
+
+ // Full PreparedStatement support
+ public String addToQueryValues(int i);
+
+ public String addToQueryValues(String s);
+
+ public String addToQueryValues(Object object);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorFactory.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorFactory.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorFactory.java
new file mode 100644
index 0000000..1f94c34
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorFactory.java
@@ -0,0 +1,24 @@
+/*
+ * 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.isis.objectstore.sql;
+
+public interface DatabaseConnectorFactory {
+ DatabaseConnector createConnector();
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorPool.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorPool.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorPool.java
new file mode 100644
index 0000000..89c90c9
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorPool.java
@@ -0,0 +1,109 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.util.Vector;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+
+public class DatabaseConnectorPool {
+ private static final Logger LOG = LoggerFactory.getLogger(DatabaseConnectorPool.class);
+ private static final int AVERAGE_POOL_SIZE = 5;
+
+ private final DatabaseConnectorFactory factory;
+ private final Vector<DatabaseConnector> connectorPool;
+
+ public DatabaseConnectorPool(final DatabaseConnectorFactory factory) {
+ this(factory, AVERAGE_POOL_SIZE);
+ }
+
+ public DatabaseConnectorPool(final DatabaseConnectorFactory factory, final int size) {
+ this.factory = factory;
+ connectorPool = new Vector<DatabaseConnector>();
+ for (int i = 0; i < size; i++) {
+ newConnector();
+ }
+ LOG.info("Created an intial pool of " + size + " database connections");
+
+ final DatabaseConnector connection = acquire();
+ Sql.setMetaData(connection.getMetaData());
+ release(connection);
+ }
+
+ private DatabaseConnector newConnector() {
+ final DatabaseConnector connector = factory.createConnector();
+ connector.setConnectionPool(this);
+ connectorPool.addElement(connector);
+ return connector;
+ }
+
+ public DatabaseConnector acquire() {
+ DatabaseConnector connector = findFreeConnector();
+ if (connector == null) {
+ connector = newConnector();
+ connector.setUsed(true);
+ LOG.info("Added an additional database connection; now contains " + connectorPool.size() + " connections");
+ }
+ LOG.debug("acquired connection " + connector);
+ return connector;
+ }
+
+ private DatabaseConnector findFreeConnector() {
+ for (int i = 0, no = connectorPool.size(); i < no; i++) {
+ final DatabaseConnector connector = connectorPool.elementAt(i);
+ if (!connector.isUsed()) {
+ connector.setUsed(true);
+ return connector;
+ }
+ }
+ return null;
+ }
+
+ public void release(final DatabaseConnector connector) {
+ connector.setUsed(false);
+ LOG.debug("released connection " + connector);
+ }
+
+ public void shutdown() {
+ for (int i = 0, no = connectorPool.size(); i < no; i++) {
+ final DatabaseConnector connector = connectorPool.elementAt(i);
+ try {
+ connector.close();
+ } catch (final SqlObjectStoreException e) {
+ LOG.error("Failed to release connectuion", e);
+ }
+ }
+ connectorPool.removeAllElements();
+ }
+
+ public void debug(final DebugBuilder debug) {
+ final DatabaseConnector connection = acquire();
+ connection.debug(debug);
+ release(connection);
+
+ }
+
+ public SqlMetaData getMetaData() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Defaults.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Defaults.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Defaults.java
new file mode 100755
index 0000000..1433faf
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Defaults.java
@@ -0,0 +1,370 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import java.util.Calendar;
+
+import org.joda.time.DateTimeZone;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+
+/**
+ * Provides objectstore defaults. Most significantly, maintains the object store default TimeZone, and maintains
+ * Calendar.
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class Defaults {
+ private static String propertiesBase;
+ private static IsisConfiguration isisConfiguration;
+
+ /**
+ * Initialise the Defaults internals. Called by the PersistorInstaller.
+ *
+ * @param propertiesBase
+ * by default, @link {@link SqlObjectStore#BASE_NAME}
+ * @param isisConfiguration
+ */
+ public static void initialise(final String propertiesBase, final IsisConfiguration isisConfiguration) {
+ Defaults.propertiesBase = propertiesBase; // "isis.persistor.sql"
+ setTimeZone(DateTimeZone.UTC);
+
+ Defaults.isisConfiguration = isisConfiguration;
+
+ setTablePrefix(getStringProperty(propertiesBase, isisConfiguration, "tableprefix", "isis_"));
+ setPkIdLabel(getStringProperty(propertiesBase, isisConfiguration, "pk_id"));
+ setIdColumn(getStringProperty(propertiesBase, isisConfiguration, "id"));
+ setMaxInstances(getIntProperty(propertiesBase, isisConfiguration, "maxinstances", 100));
+ final String useVersioningProperty = getStringProperty(propertiesBase, isisConfiguration, "versioning", "true");
+ final int isTrue = useVersioningProperty.compareToIgnoreCase("true");
+ useVersioning(isTrue == 0);
+
+ defineDatabaseCommands();
+
+ final String BASE_DATATYPE = propertiesBase + ".datatypes.";
+ final IsisConfiguration dataTypes = isisConfiguration.getProperties(BASE_DATATYPE);
+ populateSqlDataTypes(dataTypes, BASE_DATATYPE);
+
+ }
+
+ /**
+ * Returns a string value by looking up "isis.persistor.sql.default.XXXX"
+ *
+ * @param propertiesBase
+ * @param configParameters
+ * @param property
+ * @return
+ */
+ protected static String getStringProperty(final String propertiesBase, final IsisConfiguration configParameters,
+ final String property) {
+ return configParameters.getString(propertiesBase + ".default." + property, property);
+ }
+
+ /**
+ * Returns a string value by looking up "isis.persistor.sql.default.XXXX", returning the specified default, if no
+ * value was found.
+ *
+ * @param propertiesBase
+ * @param configParameters
+ * @param property
+ * @param defaultValue
+ * @return
+ */
+ protected static String getStringProperty(final String propertiesBase, final IsisConfiguration configParameters,
+ final String property, final String defaultValue) {
+ return configParameters.getString(propertiesBase + ".default." + property, defaultValue);
+ }
+
+ /**
+ * Returns an integer value by looking up "isis.persistor.sql.default.XXXX", returning the specified default, if no
+ * value was found.
+ *
+ * @param propertiesBase
+ * @param configParameters
+ * @param property
+ * @param defaultValue
+ * @return
+ */
+ protected static int getIntProperty(final String propertiesBase, final IsisConfiguration configParameters,
+ final String property, final int defaultValue) {
+ return configParameters.getInteger(propertiesBase + ".default." + property, defaultValue);
+ }
+
+ // {{ Calendar
+ private static Calendar calendar;
+
+ public static Calendar getCalendar() {
+ return calendar;
+ }
+
+ // }}
+
+ // {{ DateTimeZone
+ private static DateTimeZone dateTimeZone;
+
+ public static DateTimeZone getTimeZone() {
+ return dateTimeZone;
+ }
+
+ public static void setTimeZone(final DateTimeZone timezone) {
+ dateTimeZone = timezone;
+ calendar = Calendar.getInstance(timezone.toTimeZone());
+ }
+
+ // }}
+
+ // {{ Table prefix, defaults to "isis_"
+ private static String tablePrefix;
+
+ public static String getTablePrefix() {
+ return Defaults.tablePrefix;
+ }
+
+ public static void setTablePrefix(final String prefix) {
+ Defaults.tablePrefix = prefix;
+ }
+
+ // }}
+
+ // {{ Primary Key label, defaults to "pk_id"
+ private static String pkIdLabel;
+
+ public static void setPkIdLabel(final String pkIdLabel) {
+ Defaults.pkIdLabel = pkIdLabel;
+ }
+
+ public static String getPkIdLabel() {
+ return pkIdLabel;
+ }
+
+ // }}
+
+ // {{ Id Column, defaults to "id"
+ private static String idColumn;
+
+ public static void setIdColumn(final String idColumn) {
+ Defaults.idColumn = idColumn;
+ }
+
+ public static String getIdColumn() {
+ return idColumn;
+ }
+
+ // }}
+
+ // {{ MaxInstances
+ private static int maxInstances;
+
+ public static int getMaxInstances() {
+ return maxInstances;
+ }
+
+ public static void setMaxInstances(final int maxInstances) {
+ Defaults.maxInstances = maxInstances;
+ }
+
+ // }}
+
+ // {{ Default data types
+ static String TYPE_BOOLEAN;
+ static String TYPE_TIMESTAMP;
+ static String TYPE_DATETIME;
+ static String TYPE_DATE;
+ static String TYPE_TIME;
+ static String TYPE_SHORT;
+ static String TYPE_DOUBLE;
+ static String TYPE_FLOAT;
+ static String TYPE_LONG;
+ static String TYPE_INT;
+ static String TYPE_PK;
+ static String TYPE_STRING;
+ static String TYPE_LONG_STRING;
+ static String TYPE_PASSWORD;
+ static String PASSWORD_SEED;
+ static Integer PASSWORD_ENC_LENGTH;
+ static String TYPE_DEFAULT;
+ static String TYPE_BLOB;
+
+ /**
+ * Default SQL data types used to define the fields in the database. By providing this method, we allow the user an
+ * opportunity to override these types by specifying alternatives in sql.properties (or which ever). For example,
+ * Postgresql does not know about DATETIME, but can use TIMESTAMP instead.
+ *
+ * @param dataTypes
+ * @param baseName
+ */
+ private static void populateSqlDataTypes(final IsisConfiguration dataTypes, final String baseName) {
+ TYPE_BLOB = dataTypes.getString(baseName + "blob", "BLOB");
+ TYPE_TIMESTAMP = dataTypes.getString(baseName + "timestamp", "DATETIME");
+ TYPE_DATETIME = dataTypes.getString(baseName + "datetime", "DATETIME");
+ TYPE_DATE = dataTypes.getString(baseName + "date", "DATE");
+ TYPE_TIME = dataTypes.getString(baseName + "time", "TIME");
+ TYPE_DOUBLE = dataTypes.getString(baseName + "double", "DOUBLE");
+ TYPE_FLOAT = dataTypes.getString(baseName + "float", "FLOAT");
+ TYPE_SHORT = dataTypes.getString(baseName + "short", "INT");
+ TYPE_LONG = dataTypes.getString(baseName + "long", "BIGINT");
+ TYPE_INT = dataTypes.getString(baseName + "int", "INT");
+ TYPE_BOOLEAN = dataTypes.getString(baseName + "boolean", "BOOLEAN"); // CHAR(1)
+ TYPE_PK = dataTypes.getString(baseName + "primarykey", "INTEGER");
+ TYPE_STRING = dataTypes.getString(baseName + "string", "VARCHAR(65)");
+ TYPE_LONG_STRING = dataTypes.getString(baseName + "longstring", "VARCHAR(128)");
+ TYPE_PASSWORD = dataTypes.getString(baseName + "password", "VARCHAR(128)");
+ PASSWORD_ENC_LENGTH = getIntProperty(propertiesBase, isisConfiguration, "password.length", 120);
+ PASSWORD_SEED = getStringProperty(propertiesBase, isisConfiguration, "password.seed");
+ TYPE_DEFAULT = dataTypes.getString(baseName + "default", "VARCHAR(65)");
+
+ }
+
+ public static String TYPE_TIMESTAMP() {
+ return TYPE_TIMESTAMP;
+ }
+
+ public static String TYPE_SHORT() {
+ return TYPE_SHORT;
+ }
+
+ public static String TYPE_INT() {
+ return TYPE_INT;
+ }
+
+ public static String TYPE_LONG() {
+ return TYPE_LONG;
+ }
+
+ public static String TYPE_FLOAT() {
+ return TYPE_FLOAT;
+ }
+
+ public static String TYPE_DOUBLE() {
+ return TYPE_DOUBLE;
+ }
+
+ public static String TYPE_BOOLEAN() {
+ return TYPE_BOOLEAN;
+ }
+
+ public static String TYPE_PK() {
+ return TYPE_PK;
+ }
+
+ public static String TYPE_STRING() {
+ return TYPE_STRING;
+ }
+
+ public static String TYPE_LONG_STRING() {
+ return TYPE_LONG_STRING;
+ }
+
+ public static String TYPE_PASSWORD() {
+ return TYPE_PASSWORD;
+ }
+
+ public static String PASSWORD_SEED() {
+ return PASSWORD_SEED;
+ }
+
+ public static Integer PASSWORD_ENC_LENGTH() {
+ return PASSWORD_ENC_LENGTH;
+ }
+
+ public static String TYPE_DEFAULT() {
+ return TYPE_DEFAULT;
+ }
+
+ public static String TYPE_DATE() {
+ return TYPE_DATE;
+ }
+
+ public static String TYPE_DATETIME() {
+ return TYPE_DATETIME;
+ }
+
+ public static String TYPE_TIME() {
+ return TYPE_TIME;
+ }
+
+ public static String TYPE_BLOB() {
+ return TYPE_BLOB;
+ }
+
+ // }}
+
+ // {{ Versioning
+ private static boolean useVersioning;
+
+ public static void useVersioning(final boolean useVersioning) {
+ Defaults.useVersioning = useVersioning;
+ }
+
+ public static boolean useVersioning() {
+ return useVersioning;
+ }
+
+ public static boolean useVersioning(final String shortIdentifier) {
+ if (useVersioning() == false) {
+ return false;
+ }
+ final String useVersioningProperty =
+ getStringProperty(propertiesBase, isisConfiguration, "versioning." + shortIdentifier, "true");
+ return (useVersioningProperty.compareToIgnoreCase("true") == 0);
+ }
+
+ // }}
+
+ // {{ Database commands
+
+ private static String START_TRANSACTION;
+ private static String ABORT_TRANSACTION;
+ private static String COMMIT_TRANSACTION;
+
+ private static void defineDatabaseCommands() {
+ START_TRANSACTION =
+ getStringProperty(propertiesBase, isisConfiguration, "command.beginTransaction", "START TRANSACTION;");
+ ABORT_TRANSACTION =
+ getStringProperty(propertiesBase, isisConfiguration, "command.abortTransaction", "ROLLBACK;");
+ COMMIT_TRANSACTION =
+ getStringProperty(propertiesBase, isisConfiguration, "command.commitTransaction", "COMMIT;");
+ }
+
+ public static String START_TRANSACTION() {
+ return START_TRANSACTION;
+ }
+
+ public static String ABORT_TRANSACTION() {
+ return ABORT_TRANSACTION;
+ }
+
+ public static String COMMIT_TRANSACTION() {
+ return COMMIT_TRANSACTION;
+ }
+ // }}
+
+ /**
+ * Based on the database engine, return a LIMIT start, count clause.
+ *
+ * @param startIndex
+ * @param rowCount
+ */
+ public static String getLimitsClause(long startIndex, long rowCount) {
+ return String.format("LIMIT %d, %d", startIndex, rowCount);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingFactoryInstaller.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingFactoryInstaller.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingFactoryInstaller.java
new file mode 100644
index 0000000..99a6158
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingFactoryInstaller.java
@@ -0,0 +1,24 @@
+/*
+ * 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.isis.objectstore.sql;
+
+public interface FieldMappingFactoryInstaller {
+ void load(FieldMappingLookup lookup);
+}
[09/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimeMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimeMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimeMapper.java
deleted file mode 100644
index 3b76abc..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimeMapper.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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.applib.PersistFailedException;
-import org.apache.isis.applib.value.Time;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-public class JdbcTimeMapper extends AbstractJdbcFieldMapping {
-
- private final String dataType;
-
- public static class Factory extends AbstractFieldMappingFactory {
-
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- final String dataType = getTypeOverride(object, field, Defaults.TYPE_TIME());
- return new JdbcTimeMapper(field, dataType);
- }
- }
-
- protected JdbcTimeMapper(final ObjectAssociation field, final String dataType) {
- super(field);
- this.dataType = dataType;
- }
-
- @Override
- protected Object preparedStatementObject(final ObjectAdapter value) {
- final Time asTime = (Time) value.getObject();
- return asTime.asJavaTime();
- }
-
- @Override
- public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
- /*
- * Long hour = Long.decode(encodedValue.substring(0, 2)); Long minute =
- * Long.decode(encodedValue.substring(3, 5)); Long millis = (minute +
- * hour * 60) * 60 * 1000; String valueString = "T" +
- * Long.toString(millis); return
- * field.getSpecification().getFacet(EncodableFacet.class)
- * .fromEncodedString(valueString);
- */
- ObjectAdapter restoredValue;
- final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
- if (correspondingClass == Time.class) {
- final Time timeValue = results.getTime(columnName);
- restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(timeValue);
- } else {
- throw new PersistFailedException("Unhandled time type: " + correspondingClass.getCanonicalName());
- }
- return restoredValue;
-
- }
-
- @Override
- public String columnType() {
- return dataType;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimestampMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimestampMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimestampMapper.java
deleted file mode 100644
index 73e6906..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimestampMapper.java
+++ /dev/null
@@ -1,78 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.applib.PersistFailedException;
-import org.apache.isis.applib.value.TimeStamp;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-public class JdbcTimestampMapper extends AbstractJdbcFieldMapping {
-
- private final String dataType;
-
- public static class Factory extends AbstractFieldMappingFactory {
-
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- final String dataType = getTypeOverride(object, field, Defaults.TYPE_TIMESTAMP());
- return new JdbcTimestampMapper(field, dataType);
- }
- }
-
- protected JdbcTimestampMapper(final ObjectAssociation field, final String dataType) {
- super(field);
- this.dataType = dataType;
- }
-
- @Override
- protected Object preparedStatementObject(final ObjectAdapter value) {
- final TimeStamp asDate = (TimeStamp) value.getObject();
- final java.sql.Timestamp timeStamp = new java.sql.Timestamp(asDate.longValue());
- return timeStamp;
- }
-
- @Override
- public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
-
- ObjectAdapter restoredValue;
- final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
- if (correspondingClass == TimeStamp.class) {
- final java.sql.Timestamp o = (java.sql.Timestamp) results.getObject(columnName);
- final TimeStamp timeValue = new TimeStamp(o.getTime());
- restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(timeValue);
- } else {
- throw new PersistFailedException("Unhandled time type: " + correspondingClass.getCanonicalName());
- }
- return restoredValue;
- }
-
- @Override
- public String columnType() {
- return dataType;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoder.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoder.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoder.java
deleted file mode 100644
index 8f6c797..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoder.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.isis.objectstore.sql.jdbc.helpers;
-
-/**
- *
- *
- * @version $Rev$ $Date$
- */
-public class SimplePasswordEncoderDecoder {
- private final String passwordSeed;
- private final int seedLength;
- private final Integer valueOfZero = Integer.valueOf('0');
- private final int dbLength;
-
- public SimplePasswordEncoderDecoder(String passwordSeed, Integer encLength) {
- this.passwordSeed = passwordSeed;
- if (passwordSeed == null) {
- seedLength = 0;
- } else {
- seedLength = passwordSeed.length();
- }
- dbLength = encLength;
- }
-
- /**
- * Use a simple algorithm to encode the given value into an encoded String
- *
- * @param String
- * raw value
- * @return encoded String
- */
- public final String encodeRawValueIntoEncodedString(final String value) {
- if (passwordSeed == null) {
- return value;
- }
- final int rawLength = value.length();
- String length = Integer.toHexString(rawLength);
- if (length.length() == 1) {
- length = "0" + length;
- }
- String encodePart1 = length + value;
- String encoded = "";
- for (int i = 0; i < rawLength + 2; i++) {
- int thisSeed = passwordSeed.charAt(i % seedLength);
- int thisPassword = encodePart1.charAt(i);
- int nextValue = (thisSeed + thisPassword) % 255;
- encoded = encoded.concat(String.format("%2h", nextValue));
-
- }
- for (int i = rawLength; i < (dbLength / 2) - 2; i++) {
- int thisSeed = passwordSeed.charAt(i % seedLength);
- int thisPassword = passwordSeed.charAt((i - 2) % seedLength);
- int nextValue = (thisSeed + thisPassword + i) % 255;
- encoded = encoded.concat(String.format("%2h", nextValue));
- }
-
- return encoded;
- }
-
- /**
- * Use a simple algorithm to decode the given encoded String into a raw String
- *
- * @param String
- * encoded value
- * @return decoded raw String
- */
- public final String decodeEncodedValueIntoRawString(final String encodedValue) {
- if (passwordSeed == null) {
- return encodedValue;
- }
- int passwordLength = extractIndexedValueAsInt(encodedValue, 0);
-
- String decodedValue = "";
- for (int i = 0; i < passwordLength; i++) {
- char extracted = extractIndexedValueAsChar(encodedValue, i + 2);
- decodedValue = decodedValue + (extracted);
- }
- return decodedValue;
- }
-
- private int extractIndexedValueAsInt(final String encodedValue, int index) {
- int value1 = decodeIndexedValue(encodedValue, index) - valueOfZero;
- int value2 = decodeIndexedValue(encodedValue, index + 1) - valueOfZero;
- return value1 * 16 + value2;
- }
-
- private char extractIndexedValueAsChar(final String encodedValue, int index) {
- int value1 = decodeIndexedValue(encodedValue, index);
- return (char) value1;
- }
-
- private int decodeIndexedValue(final String encodedValue, int index) {
- String s = encodedValue.substring((index) * 2, (index) * 2 + 2);
- int hex = Integer.valueOf(s, 16);
- int thisSeed = passwordSeed.charAt(index % seedLength);
- int passwordValue = hex - thisSeed;
- return passwordValue;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java
deleted file mode 100644
index 62391bf..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java
+++ /dev/null
@@ -1,93 +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.isis.objectstore.sql.jdbc.installer;
-
-import org.apache.isis.applib.value.Color;
-import org.apache.isis.applib.value.Date;
-import org.apache.isis.applib.value.DateTime;
-import org.apache.isis.applib.value.Image;
-import org.apache.isis.applib.value.Money;
-import org.apache.isis.applib.value.Password;
-import org.apache.isis.applib.value.Percentage;
-import org.apache.isis.applib.value.Time;
-import org.apache.isis.applib.value.TimeStamp;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.FieldMappingFactoryInstaller;
-import org.apache.isis.objectstore.sql.FieldMappingLookup;
-import org.apache.isis.objectstore.sql.jdbc.JdbcBinaryValueMapper;
-import org.apache.isis.objectstore.sql.jdbc.JdbcColorValueMapper;
-import org.apache.isis.objectstore.sql.jdbc.JdbcDateMapper;
-import org.apache.isis.objectstore.sql.jdbc.JdbcDateTimeMapper;
-import org.apache.isis.objectstore.sql.jdbc.JdbcGeneralValueMapper;
-import org.apache.isis.objectstore.sql.jdbc.JdbcImageValueMapper;
-import org.apache.isis.objectstore.sql.jdbc.JdbcMoneyValueMapper;
-import org.apache.isis.objectstore.sql.jdbc.JdbcObjectReferenceFieldMapping;
-import org.apache.isis.objectstore.sql.jdbc.JdbcObjectReferenceMappingFactory;
-import org.apache.isis.objectstore.sql.jdbc.JdbcPasswordValueMapper;
-import org.apache.isis.objectstore.sql.jdbc.JdbcTimeMapper;
-import org.apache.isis.objectstore.sql.jdbc.JdbcTimestampMapper;
-
-public class JdbcFieldMappingFactoryInstaller implements FieldMappingFactoryInstaller {
-
- @Override
- public void load(final FieldMappingLookup lookup) {
-
- lookup.addFieldMappingFactory(Image.class,
- new JdbcImageValueMapper.Factory(Defaults.TYPE_STRING(), Defaults.TYPE_BLOB()));
-
- lookup.addFieldMappingFactory(Boolean.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_BOOLEAN()));
- lookup.addFieldMappingFactory(Short.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_SHORT()));
- lookup.addFieldMappingFactory(Integer.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_INT()));
- lookup.addFieldMappingFactory(Long.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_LONG()));
- lookup.addFieldMappingFactory(Float.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_FLOAT()));
- lookup.addFieldMappingFactory(Double.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_DOUBLE()));
- lookup.addFieldMappingFactory(char.class, new JdbcGeneralValueMapper.Factory("CHAR(2)"));
-
- lookup.addFieldMappingFactory(Money.class, new JdbcMoneyValueMapper.Factory("FLOAT", "VARCHAR(3)"));
- lookup.addFieldMappingFactory(Percentage.class, new JdbcGeneralValueMapper.Factory("FLOAT"));
- lookup.addFieldMappingFactory(Password.class, new JdbcPasswordValueMapper.Factory(Defaults.TYPE_PASSWORD(),
- Defaults.PASSWORD_SEED(), Defaults.PASSWORD_ENC_LENGTH()));
- lookup.addFieldMappingFactory(Color.class, new JdbcColorValueMapper.Factory(Defaults.TYPE_LONG()));
- lookup.addFieldMappingFactory(String.class, new JdbcGeneralValueMapper.Factory(Defaults.TYPE_STRING()));
-
- lookup.addFieldMappingFactory(Date.class, new JdbcDateMapper.Factory());
- lookup.addFieldMappingFactory(Time.class, new JdbcTimeMapper.Factory());
- lookup.addFieldMappingFactory(DateTime.class, new JdbcDateTimeMapper.Factory());
- lookup.addFieldMappingFactory(TimeStamp.class, new JdbcTimestampMapper.Factory());
-
- lookup.addFieldMappingFactory(java.sql.Date.class, new JdbcDateMapper.Factory());
- lookup.addFieldMappingFactory(java.sql.Time.class, new JdbcTimeMapper.Factory());
- lookup.addFieldMappingFactory(java.util.Date.class, new JdbcDateTimeMapper.Factory());
- lookup.addFieldMappingFactory(java.sql.Timestamp.class, new JdbcTimestampMapper.Factory());
-
- lookup.addFieldMappingFactory(boolean.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_BOOLEAN()));
- lookup.addFieldMappingFactory(short.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_SHORT()));
- lookup.addFieldMappingFactory(int.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_INT()));
- lookup.addFieldMappingFactory(long.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_LONG()));
- lookup.addFieldMappingFactory(float.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_FLOAT()));
- lookup.addFieldMappingFactory(double.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_DOUBLE()));
-
- lookup.setReferenceFieldMappingFactory(new JdbcObjectReferenceFieldMapping.Factory());
-
- lookup.setObjectReferenceMappingfactory(new JdbcObjectReferenceMappingFactory());
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMapping.java
deleted file mode 100644
index 0cc664e..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMapping.java
+++ /dev/null
@@ -1,48 +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.isis.objectstore.sql.mapping;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.Results;
-
-public interface FieldMapping {
-
- public ObjectAssociation getField();
-
- void appendColumnDefinitions(StringBuffer sql);
-
- void appendColumnNames(StringBuffer sql);
-
- void appendInsertValues(DatabaseConnector connector, StringBuffer sql, ObjectAdapter object);
-
- void appendUpdateValues(DatabaseConnector connector, StringBuffer sql, ObjectAdapter object);
-
- void initializeField(ObjectAdapter object, Results rs);
-
- void appendWhereClause(DatabaseConnector connector, StringBuffer sql, ObjectAdapter object);
-
- void debugData(DebugBuilder debug);
-
- void appendWhereObject(DatabaseConnector connector, ObjectAdapter objectAdapter);
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMappingFactory.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMappingFactory.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMappingFactory.java
deleted file mode 100644
index 4a139cf..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMappingFactory.java
+++ /dev/null
@@ -1,27 +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.isis.objectstore.sql.mapping;
-
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-
-public interface FieldMappingFactory {
- FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field);
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMapping.java
deleted file mode 100644
index e064cbe..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMapping.java
+++ /dev/null
@@ -1,40 +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.isis.objectstore.sql.mapping;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.Results;
-
-public interface ObjectReferenceMapping {
-
- void appendColumnDefinitions(StringBuffer sql);
-
- void appendInsertValues(DatabaseConnector connector, StringBuffer sb, ObjectAdapter value);
-
- void appendColumnNames(StringBuffer sql);
-
- void appendUpdateValues(DatabaseConnector connector, StringBuffer sql, ObjectAdapter object);
-
- Oid recreateOid(final Results rs, final ObjectSpecification specification);
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMappingFactory.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMappingFactory.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMappingFactory.java
deleted file mode 100644
index 6a13d63..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMappingFactory.java
+++ /dev/null
@@ -1,26 +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.isis.objectstore.sql.mapping;
-
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-
-public interface ObjectReferenceMappingFactory {
- ObjectReferenceMapping createReferenceMapping(String columnName, ObjectSpecification specification);
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/site/apt/index.apt b/component/objectstore/sql/sql-impl/src/site/apt/index.apt
deleted file mode 100644
index 891352a..0000000
--- a/component/objectstore/sql/sql-impl/src/site/apt/index.apt
+++ /dev/null
@@ -1,27 +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.
-
-
-
-SQL ObjectStore Implementation
-
- This module holds the implementation of the {{{../index.html}SQL ObjectStore}}.
-
-Further Info
-
- See this module's {{{./apidocs/index.html}Javadoc}} and {{{../docbkx/html/guide/isis-sql-objectstore.html}User Guide}} for more information.
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/site/apt/jottings.apt b/component/objectstore/sql/sql-impl/src/site/apt/jottings.apt
deleted file mode 100644
index c5d1200..0000000
--- a/component/objectstore/sql/sql-impl/src/site/apt/jottings.apt
+++ /dev/null
@@ -1,24 +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.
-
-
-
-Jottings
-
- This page is to capture any random jottings relating to this module prior
- to being moved into formal documentation.
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/site/site.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/site/site.xml b/component/objectstore/sql/sql-impl/src/site/site.xml
deleted file mode 100644
index fea0aec..0000000
--- a/component/objectstore/sql/sql-impl/src/site/site.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project>
-
- <body>
- <breadcrumbs>
- <item name="Implementation" href="index.html"/>
- </breadcrumbs>
-
- <menu name="SQL Objectstore Implementation">
- <item name="About" href="index.html" />
- <item name="Jottings" href="jottings.html" />
- </menu>
-
- <menu name="SQL OS Modules">
- <item name="Implementation" href="../sql-impl/index.html" />
- <item name="Tests" href="../sql-tests-common/index.html" />
- <item name="Integration Tests" href="../sql-tests-served/index.html" />
- </menu>
-
- <menu name="Maven Reports" ref="reports" />
- </body>
-</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/DefaultsTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/DefaultsTest.java b/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/DefaultsTest.java
deleted file mode 100644
index 86b5db4..0000000
--- a/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/DefaultsTest.java
+++ /dev/null
@@ -1,60 +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.isis.objectstore.sql;
-
-import static org.hamcrest.Matchers.is;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.config.IsisConfigurationDefault;
-
-public class DefaultsTest {
- @Test
- public void tablePrefixDefaultsTo_Isis() {
- final String prefix = "isis.persistor.sql";
- final IsisConfiguration config = new IsisConfigurationDefault();
- Defaults.initialise(prefix, config);
- Assert.assertThat(Defaults.getTablePrefix(), is("isis_"));
- }
-
- @Test
- public void tablePrefixCanBeReplaced() {
- final String prefix = "isis.persistor.sql";
- final String key = "isis.persistor.sql.default.tableprefix";
- final IsisConfigurationDefault config = new IsisConfigurationDefault();
- config.add(key, "");
- Defaults.initialise(prefix, config);
- Assert.assertThat(Defaults.getTablePrefix(), is(""));
- }
-
- @Test
- public void checkLimitStatement(){
- final String prefix = "isis.persistor.sql";
- final IsisConfigurationDefault config = new IsisConfigurationDefault();
- Defaults.initialise(prefix, config);
-
- final long startIndex=0;
- final long rowCount=0;
-
- Assert.assertThat(Defaults.getLimitsClause(startIndex, rowCount), is("LIMIT 0, 0"));
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoderTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoderTest.java b/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoderTest.java
deleted file mode 100644
index e2a976a..0000000
--- a/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoderTest.java
+++ /dev/null
@@ -1,66 +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.isis.objectstore.sql.jdbc.helpers;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- *
- * @version $Rev$ $Date$
- */
-public class SimplePasswordEncoderDecoderTest {
-
- private static final String testSeed = "randomString12345";
- private static final Integer encLength = 120;
-
- @Test
- public void testEncodingValueFromString() {
- SimplePasswordEncoderDecoder encdec = new SimplePasswordEncoderDecoder(testSeed, encLength);
- String input = "password";
- String encoded = encdec.encodeRawValueIntoEncodedString(input);
- Assert.assertThat(encoded, is(not(input)));
- Assert.assertThat(encoded.length(), is(120));
- }
-
- @Test
- public void testDecodingEncodedValue() {
- SimplePasswordEncoderDecoder encdec = new SimplePasswordEncoderDecoder(testSeed, encLength);
- String input = "password";
- String encoded = encdec.encodeRawValueIntoEncodedString(input);
- Assert.assertThat(encoded, is(not(input)));
-
- String decoded = encdec.decodeEncodedValueIntoRawString(encoded);
- Assert.assertThat(decoded, is(input));
- }
-
- @Test
- public void testNoSeedDoesNothing() {
- SimplePasswordEncoderDecoder encdec = new SimplePasswordEncoderDecoder(null, encLength);
- String input = "password";
- String encoded = encdec.encodeRawValueIntoEncodedString(input);
- Assert.assertThat(encoded, is(input));
-
- String decoded = encdec.decodeEncodedValueIntoRawString(encoded);
- Assert.assertThat(decoded, is(input));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/pom.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/pom.xml b/component/objectstore/sql/sql-tests-common/pom.xml
deleted file mode 100644
index 829c1e4..0000000
--- a/component/objectstore/sql/sql-tests-common/pom.xml
+++ /dev/null
@@ -1,166 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-sql</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>isis-objectstore-sql-tests-common</artifactId>
-
- <name>Isis SQL ObjectStore Integration Tests - Common</name>
-
- <properties>
- <siteBaseDir>..</siteBaseDir>
- <relativeUrl>sql-tests-common/</relativeUrl>
-
- <xml-objectstore.version>1.0.0-SNAPSHOT</xml-objectstore.version>
- <hsqldb.version>2.2.9</hsqldb.version>
- </properties>
-
- <!-- used in Site generation for relative references. -->
- <url>http://isis.apache.org/${relativeUrl}</url>
-
- <description>Common code to test the sql persistor. Uses the HSQLDB for maximum compatibility.</description>
- <build>
- <plugins>
- <!-- TODO: currently set to ignore test failures -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <testFailureIgnore>false</testFailureIgnore>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <version>${maven-project-info-reports-plugin}</version>
- <inherited>false</inherited>
- <configuration>
- <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
- </configuration>
- <reportSets>
- <reportSet>
- <inherited>false</inherited>
- <reports>
- <report>dependency-management</report>
- <report>dependencies</report>
- <report>dependency-convergence</report>
- <report>plugins</report>
- <report>summary</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- </plugins>
- </reporting>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- <version>${hsqldb.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <dependencies>
-
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-unittestsupport</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-integtestsupport</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-runtime</artifactId>
- </dependency>
-
-
- <!-- Required for TestProxy -->
- <!-- Isis defaults -->
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-objectstore</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-objectstore</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-bytecode-cglib</artifactId>
- <scope>test</scope>
- </dependency>
-
- <!-- Isis Object store -->
- <dependency>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-sql-impl</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-tck-dom</artifactId>
- </dependency>
-
-
- <!-- HSQLDB -->
- <dependency>
- <groupId>org.hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- </dependency>
- <!-- Required to support the XML cross-test -->
- <dependency>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-xml</artifactId>
- </dependency>
- <!-- others -->
- <dependency>
- <groupId>org.jmock</groupId>
- <artifactId>jmock-legacy</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jmock</groupId>
- <artifactId>jmock-junit4</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Data.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Data.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Data.java
deleted file mode 100644
index f54f756..0000000
--- a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Data.java
+++ /dev/null
@@ -1,100 +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.isis.objectstore.sql.common;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.isis.applib.value.Color;
-import org.apache.isis.applib.value.Date;
-import org.apache.isis.applib.value.DateTime;
-import org.apache.isis.applib.value.Image;
-import org.apache.isis.applib.value.Money;
-import org.apache.isis.applib.value.Password;
-import org.apache.isis.applib.value.Percentage;
-import org.apache.isis.applib.value.Time;
-import org.apache.isis.applib.value.TimeStamp;
-
-public class Data {
-
- // private static final TimeZone GMTm2_TIME_ZONE;
-
- // Helper values
- static final java.sql.Date sqlDate;
- static final java.sql.Date sqlDate20100305;
-
- static {
- /*
- *
- * // For testing -ve offset timezone local regions. GMTm2_TIME_ZONE = TimeZone.getTimeZone("GMT-0200");
- * //GMTm2_TIME_ZONE = TimeZone.getTimeZone("UTC"); TimeZone.setDefault(GMTm2_TIME_ZONE);
- */
-
- /*
- * TimeZone timeZone = TimeZone.getTimeZone("Etc/UTC"); if (timeZone == null) { timeZone =
- * TimeZone.getTimeZone("UTC"); } UTC_TIME_ZONE = timeZone;
- */
-
- /*
- * There is still an issue assigning a java.sql.Date variable from a calendar. final Calendar cal =
- * Calendar.getInstance(); cal.setTimeZone(UTC_TIME_ZONE); cal.clear(); cal.set(Calendar.YEAR, 2011);
- * cal.set(Calendar.MONTH, 4-1); cal.set(Calendar.DAY_OF_MONTH, 8);
- */
- // 2011-4-8 = 1,270,684,800,000
- final Date date20100308 = new Date(2010, 4, 8);
- sqlDate = new java.sql.Date(date20100308.getMillisSinceEpoch());
-
- sqlDate20100305 = new java.sql.Date(new Date(2010, 3, 5).getMillisSinceEpoch());
- }
-
- static final Date applibDate = new Date(2010, 3, 5); // 2010-03-05 =
- // 1,267,747,200,000
- static final DateTime dateTime = new DateTime(2010, 3, 5, 1, 23); // 1,267,752,180,000
- static final TimeStamp timeStamp = new TimeStamp(dateTime.millisSinceEpoch());
- static final Time time = new Time(14, 56); // 53,760,000
-
- static final Color color = Color.WHITE;
- static final Image image = new Image(new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } });
- static final Password password = new Password("password");
- static final Percentage percentage = new Percentage(42);
- static final Money money = new Money(99.99, "ZAR");
-
- // Standard values
- static final int intMaxValue = Integer.MAX_VALUE;
- static final short shortMaxValue = Short.MAX_VALUE;
- static final long longMaxValue = Long.MAX_VALUE;
- static final double doubleMaxValue = 1e308;// Double.MAX_VALUE;
- static final float floatMaxValue = (float) 1e37;// Float.MAX_VALUE;
-
- static final int intMinValue = Integer.MIN_VALUE;
- static final short shortMinValue = Short.MIN_VALUE;
- static final long longMinValue = Long.MIN_VALUE;
- static final double doubleMinValue = 1e-307;// Double.MIN_VALUE;
- static final float floatMinValue = (float) 1e-37;// Float.MIN_VALUE;
-
- // Collection mapper tests
- static final List<String> stringList1 = Arrays.asList("Baking", "Bakery", "Canned", "Dairy");
- static final List<String> stringList2 = Arrays.asList("Fridge", "Deli", "Fresh Produce", "Frozen", "Household",
- "Other..");
-
- public static List<String> getTableNames() {
- return Arrays.asList("sqldataclass", "simpleclass", "simpleclasstwo", "primitivevaluedentity");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java
deleted file mode 100755
index 0747bcd..0000000
--- a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java
+++ /dev/null
@@ -1,190 +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.isis.objectstore.sql.common;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.util.Properties;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.FixMethodOrder;
-import org.junit.Rule;
-import org.junit.runners.MethodSorters;
-
-import org.apache.isis.core.tck.dom.poly.ReferencingPolyTypesEntity;
-import org.apache.isis.core.tck.dom.sqlos.SqlDomainObjectRepository;
-import org.apache.isis.core.tck.dom.sqlos.data.SqlDataClass;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures.State;
-
-/**
- * @author Kevin kevin@kmz.co.za
- *
- * This common test class is used by all sql objectstore tests to manage the Isis framework.
- *
- * @version $Rev$ $Date$
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public abstract class SqlIntegrationTestCommonBase {
-
- @Rule
- public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
-
- protected SqlIntegrationTestFixtures getSqlIntegrationTestFixtures() {
- return SqlIntegrationTestFixtures.getInstance();
- }
-
- protected SqlDomainObjectRepository factory;
- protected SqlDataClass sqlDataClass;
- protected ReferencingPolyTypesEntity referencingPolyTypesEntity;
-
- public Properties getProperties() {
- try {
- final Properties properties = new Properties();
- properties.load(new FileInputStream("src/test/config/" + getPropertiesFilename()));
- return properties;
- } catch (final FileNotFoundException e) {
- e.printStackTrace();
- } catch (final IOException e) {
- e.printStackTrace();
- }
-
- return null;
- }
-
- public abstract String getPropertiesFilename();
-
- protected void setFixtureInitializationStateIfNot(State state, String persistenceMechanism) {
- if (!persistenceMechanismIs(persistenceMechanism)) {
- setFixtureInitializationState(state);
- }
- }
-
- protected void setFixtureInitializationState(final State state, final String persistenceMechanism) {
- if (persistenceMechanismIs(persistenceMechanism)) {
- setFixtureInitializationState(state);
- }
- }
-
- protected void setFixtureInitializationState(final State state) {
- getSqlIntegrationTestFixtures().setState(state);
- }
-
- protected boolean persistenceMechanismIs(final String persistenceMechanism) {
- return getProperties().getProperty("isis.persistor").equals(persistenceMechanism);
- }
-
- /**
- * This method can be used to do any DB specific actions the first time the test framework is setup. e.g. In the XML
- * test, it must delete all XML files in the data store directory.
- *
- * You can also use @BeforeClass to perform pre-connection cleanup, such as deleting hsql-db data directories.
- */
- public void resetPersistenceStoreDirectlyIfRequired() {
- }
-
- protected void testSetup() {
- resetPersistenceStoreDirectlyIfRequired();
- getSqlIntegrationTestFixtures().setState(State.INITIALIZE);
- }
-
- // //////////////////////////////////////////////////////////////////////////////
- // before, after
- // //////////////////////////////////////////////////////////////////////////////
-
- @Before
- public void setUpSystem() throws Exception {
- org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
-
- if (!getSqlIntegrationTestFixtures().getState().isInitialize()) {
- return;
- }
-
- final Properties properties = getProperties();
- if (properties == null) {
- getSqlIntegrationTestFixtures().initSystem("src/test/config", getPropertiesFilename());
- } else {
- getSqlIntegrationTestFixtures().initSystem(properties);
- }
-
- final String sqlSetupString = getSqlSetupString();
- if (sqlSetupString != null) {
- getSqlIntegrationTestFixtures().sqlExecute(sqlSetupString);
- }
- }
-
- /**
- * optional hook
- */
- protected String getSqlSetupString() {
- return null;
- }
-
- @Before
- public void setUpFactory() throws Exception {
- factory = getSqlIntegrationTestFixtures().getSqlDataClassFactory();
-
- // may have been setup by previous test
- sqlDataClass = getSqlIntegrationTestFixtures().getSqlDataClass();
- referencingPolyTypesEntity = getSqlIntegrationTestFixtures().getPolyTestClass();
- }
-
-
-
- // //////////////////////////////////////////////////////////////////////////////
- // after
- // //////////////////////////////////////////////////////////////////////////////
-
-
- @After
- public void tearDown() throws Exception {
-
-
-
- if (!getSqlIntegrationTestFixtures().getState().isInitialize()) {
- return;
- }
- final String sqlTeardownString = getSqlTeardownString();
- if (sqlTeardownString != null) {
- try {
- getSqlIntegrationTestFixtures().sqlExecute(sqlTeardownString);
- } catch (final SQLException e) {
- e.printStackTrace();
- }
- }
- getSqlIntegrationTestFixtures().shutDown();
- }
-
-
- /**
- * optional hook
- */
- protected String getSqlTeardownString() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java
deleted file mode 100644
index dcb5db1..0000000
--- a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java
+++ /dev/null
@@ -1,651 +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.isis.objectstore.sql.common;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-import org.apache.isis.applib.value.Color;
-import org.apache.isis.applib.value.Date;
-import org.apache.isis.applib.value.DateTime;
-import org.apache.isis.applib.value.Image;
-import org.apache.isis.applib.value.Money;
-import org.apache.isis.applib.value.Password;
-import org.apache.isis.applib.value.Percentage;
-import org.apache.isis.applib.value.Time;
-import org.apache.isis.applib.value.TimeStamp;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.tck.dom.scalars.PrimitiveValuedEntity;
-import org.apache.isis.core.tck.dom.sqlos.SqlDomainObjectRepository;
-import org.apache.isis.core.tck.dom.sqlos.data.SimpleClass;
-import org.apache.isis.core.tck.dom.sqlos.data.SimpleClassTwo;
-import org.apache.isis.core.tck.dom.sqlos.data.SqlDataClass;
-import org.apache.isis.objectstore.sql.common.SqlIntegrationTestFixtures.State;
-
-/**
- * @author Kevin kevin@kmz.co.za
- *
- * This common class is used by the datatype tests (values, objects, collections) to ensure proper creation and
- * reloading of domain objects.
- *
- * There are two "tests", with the framework re-initialised each time (to flush any objectstore memory of any
- * created domain objects).
- *
- * The Singleton class {@link SqlIntegrationTestFixtures} is used to preserve values between tests.
- *
- * @version $Rev$ $Date$
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public abstract class SqlIntegrationTestData extends SqlIntegrationTestCommonBase {
-
- private static final Logger LOG = LoggerFactory.getLogger(SqlIntegrationTestData.class);
-
- private static List<SimpleClass> simpleClassList1 = new ArrayList<SimpleClass>();
- private static List<SimpleClass> simpleClassList2 = new ArrayList<SimpleClass>();
-
- private static SimpleClassTwo simpleClassTwoA;
- private static SimpleClassTwo simpleClassTwoB;
-
- private static PrimitiveValuedEntity pve1;
- private static PrimitiveValuedEntity pve2;
-
-
- @Before
- public void setUpXactn() throws Exception {
- IsisContext.getTransactionManager().startTransaction();
- }
-
- @After
- public void tearDownXactn() throws Exception {
- IsisContext.getTransactionManager().endTransaction();
- assertThat(IsisContext.getTransactionManager().getTransaction().getState().isComplete(), is(true));
-
- }
-
-
- /**
- * Uses factory methods within the Isis framework to create the test data,
- * thus exercising the "create data" portion of the object store.
- *
- * The Isis framework will be again be re-created in the next test unless the
- * object store is "in-memory" (this is required since "in-memory" has to be
- * left alone for created data to still be present in the next test).
- */
- @Test
- public void testSetupStore() throws Exception {
- testSetup();
- setUpFactory();
- testCreate();
- }
-
- protected void testCreate() throws Exception {
-
- sqlDataClass = factory.newDataClass();
-
- sqlDataClass.setString("Test String");
- sqlDataClass.setDate(Data.applibDate);
- sqlDataClass.setSqlDate(Data.sqlDate);
- sqlDataClass.setMoney(Data.money);
- sqlDataClass.setDateTime(Data.dateTime);
- sqlDataClass.setTimeStamp(Data.timeStamp);
- sqlDataClass.setTime(Data.time);
- sqlDataClass.setColor(Data.color);
- sqlDataClass.setImage(Data.image);
- sqlDataClass.setPassword(Data.password);
- sqlDataClass.setPercentage(Data.percentage);
-
- // Setup SimpleClassTwo
- simpleClassTwoA = factory.newSimpleClassTwo();
- simpleClassTwoA.setText("A");
- simpleClassTwoA.setIntValue(999);
- simpleClassTwoA.setBooleanValue(true);
-
- simpleClassTwoB = factory.newSimpleClassTwo();
- simpleClassTwoB.setText("B");
-
- sqlDataClass.setSimpleClassTwo(simpleClassTwoA);
-
- // NumericClasses
- // standard min types
- pve2 = factory.newPrimitiveValuedEntity();
- LOG.info( "Bits to represent Double: " + Double.SIZE);
- pve2.setIntProperty(Data.intMinValue);
- pve2.setShortProperty(Data.shortMinValue);
- pve2.setLongProperty(Data.longMinValue);
- pve2.setDoubleProperty(Data.doubleMinValue);
- pve2.setFloatProperty(Data.floatMinValue);
- pve2.setCharProperty((char) (32)); // temporary work around: See ISIS-269
-
- sqlDataClass.setPrimitiveValuedEntityMin(pve2);
-
- // standard max types
- pve1 = factory.newPrimitiveValuedEntity();
- pve1.setIntProperty(Data.intMaxValue);
- pve1.setShortProperty(Data.shortMaxValue);
- pve1.setLongProperty(Data.longMaxValue);
- pve1.setDoubleProperty(Data.doubleMaxValue);
- pve1.setFloatProperty(Data.floatMaxValue);
- pve1.setCharProperty((char) (255));
-
- sqlDataClass.setPrimitiveValuedEntityMax(pve1);
-
- // Initialise collection1
- boolean bMustAdd = false;
- if (simpleClassList1.size() == 0) {
- bMustAdd = true;
- }
- for (final String string : Data.stringList1) {
- final SimpleClass simpleClass = factory.newSimpleClass();
- simpleClass.setString(string);
- simpleClass.setSimpleClassTwoA(simpleClassTwoA);
- sqlDataClass.addToSimpleClasses1(simpleClass);
- if (bMustAdd) {
- simpleClassList1.add(simpleClass);
- }
- }
-
- // Initialise collection2
- for (final String string : Data.stringList2) {
- final SimpleClass simpleClass = factory.newSimpleClass();
- simpleClass.setString(string);
- simpleClass.setSimpleClassTwoA(simpleClassTwoB);
- sqlDataClass.addToSimpleClasses2(simpleClass);
- if (bMustAdd) {
- simpleClassList2.add(simpleClass);
- }
- }
-
- // Initialise Image
- Image image = new Image(new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } });
- sqlDataClass.setImage(image);
-
- // Save
- factory.save(sqlDataClass);
-
- setFixtureInitializationState(State.DONT_INITIALIZE, "in-memory");
- }
-
- /**
- * The actual "tests". Unless the test is using the "in-memory" object store
- * the Isis framework is re-created, thus ensuring that no domain objects are
- * left over from the previous "create" step, forcing the objects to be created
- * via the object store.
- *
- * Exercises the "restore data" portion of the object store.
- *
- * Confirms that values and objects (single and collections) are loaded as expected.
- * Especially, it confirms that dates, times, etc, do not suffer from differences in
- * time zones between the database and the Isis framework.
- */
- @Test
- public void testTestAll() throws Exception {
-
- testLoad();
-
- setUpFactory();
-
- testString();
- setStringToDifferentValue();
- testSimpleClassCollection1Lazy();
-
- testMoney();
- testColor();
- testPassword();
- testPercentage();
-
- testImage();
-
- testStandardValueTypesMaxima();
- testStandardValueTypesMinima();
-
- testSingleReferenceLazy();
- testSimpleClassTwoReferenceLazy();
-
- testSimpleClassCollection1();
- testSimpleClassCollection2();
-
- testSingleReferenceResolve();
- testSimpleClassTwoReferenceResolve();
- testSimpleClassTwo();
- testUpdate1();
- testUpdate2();
- testUpdateCollectionIsDirty();
- testFindByMatchString();
- testFindByMatchEntity();
-
- testApplibDate();
- testSqlDate();
- testTime();
- testTimeStamp();
- testDateTimezoneIssue();
- testDateTime();
-
- // Test LIMIT statement
- testLimitCount();
-
- // Must be here so that the Isis framework is initialised for the next test package.
- setFixtureInitializationState(State.INITIALIZE);
- }
-
- private void testLoad() throws Exception {
- final List<SqlDataClass> dataClasses = factory.allDataClasses();
- IsisContext.getTransactionManager().flushTransaction();
-
- assertEquals(1, dataClasses.size());
- final SqlDataClass sqlDataClass = dataClasses.get(0);
- getSqlIntegrationTestFixtures().setSqlDataClass(sqlDataClass);
-
- setFixtureInitializationState(State.DONT_INITIALIZE);
- }
-
- private void testString() {
- assertEquals("Test String", sqlDataClass.getString());
- }
-
- private void setStringToDifferentValue() {
- sqlDataClass.setString("String 2");
- }
-
- private void testSimpleClassCollection1Lazy() {
- final List<SimpleClass> collection = sqlDataClass.simpleClasses1;
-
- assertEquals("collection size is not equal!", collection.size(), simpleClassList1.size());
- }
-
- /**
- * Test {@link SqlDataClass} {@link Date} field.
- *
- * @throws Exception
- */
- private void testApplibDate() {
-
- LOG.info("Test: testDate() '2010-3-5' = 1267747200000");
-
- // 2010-3-5 = 1267747200000
- LOG.info( "applibDate.dateValue() as String: " + Data.applibDate);
- LOG.info( "applibDate.dateValue() as Long: " + Data.applibDate.getMillisSinceEpoch());
-
- // 2010-3-5 = 1267747200000
- LOG.info( "sqlDataClass.getDate() as String: " + sqlDataClass.getDate());
- LOG.info( "sqlDataClass.getDate().getTime() as Long: " + sqlDataClass.getDate().getMillisSinceEpoch());
-
- if (!Data.applibDate.isEqualTo(sqlDataClass.getDate())) {
- fail("Applib date: Test '2010-3-5', expected " + Data.applibDate.toString() + ", but got "
- + sqlDataClass.getDate().toString() + ". Check log for more info.");
- } else {
- // LOG.log(Level.INFO,
- // "SQL applib.value.date: test passed! Woohoo!");
- }
-
- }
-
- /**
- * Test {@link SqlDataClass} {@link java.sql.Date} field.
- *
- * @throws Exception
- */
- private void testSqlDate() {
-
- LOG.info( "Test: testSqlDate() '2011-4-8' == 1302220800000");
-
- // 2011-4-8 = 1302220800000
- LOG.info( "sqlDate.toString() as String:" + Data.sqlDate); // shows
- // as
- // 2011-04-07
- LOG.info( "sqlDate.getTime() as Long:" + Data.sqlDate.getTime());
-
- // 2011-4-8 = 1302220800000
- LOG.info( "sqlDataClass.getSqlDate() as String:" + sqlDataClass.getSqlDate()); // shows
- // as
- // 2011-04-07
- LOG.info( "sqlDataClass.getSqlDate().getTime() as Long:" + sqlDataClass.getSqlDate().getTime());
-
- if (Data.sqlDate.compareTo(sqlDataClass.getSqlDate()) != 0) {
- fail("SQL date: Test '2011-4-8', expected " + Data.sqlDate.toString() + ", but got "
- + sqlDataClass.getSqlDate().toString() + ". Check log for more info.");
- } else {
- // LOG.log(Level.INFO, "SQL date: test passed! Woohoo!");
- }
-
- }/**/
-
- private void testDateTimezoneIssue() {
- /*
- * At the moment, applib Date and java.sql.Date are restored from ValueSemanticsProviderAbstractTemporal with an
- * explicit hourly offset that comes from the timezone. I.e. in South Africa, with TZ +2h00, they have an
- * implicit time of 02h00 (2AM). This can potentially seriously screw up GMT-X dates, which, I suspect, will
- * actually be set to the dat BEFORE.
- *
- * This test is a simple test to confirm that date/time before and after checks work as expected.
- */
-
- DateTime dateTime = sqlDataClass.getDateTime(); // new DateTime(2010, 3, 5, 1, 23);
- Date date = sqlDataClass.getDate(); // new Date(2010, 3, 5);
-
- // java.sql.Date sqlDate = sqlDataClass.getSqlDate(); // "2010-03-05"
- // assertTrue("dateTime's value (" + dateTime.dateValue() + ") should be after java.sql.date's (" + sqlDate +
- // ")",
- // dateTime.dateValue().after(sqlDate));
-
- assertTrue("dateTime's value (" + dateTime.dateValue() + ") should be after date's (" + date + ")", dateTime
- .dateValue().after(date.dateValue()));
-
- }
-
- /**
- * Test {@link Money} type.
- */
- private void testMoney() {
- assertEquals(Data.money, sqlDataClass.getMoney());
- }
-
- /**
- * Test {@link DateTime} type.
- */
- private void testDateTime() {
-
- LOG.info( "Test: testDateTime()");
- LOG.info( "sqlDataClass.getDateTime() as String:" + sqlDataClass.getDateTime());
- LOG.info( "dateTime.toString() as String:" + Data.dateTime);
-
- LOG.info( "sqlDataClass.getDateTime().getTime() as Long:"
- + sqlDataClass.getDateTime().millisSinceEpoch());
- LOG.info( "dateTime.getTime() as Long:" + Data.dateTime.millisSinceEpoch());
-
- if (!Data.dateTime.equals(sqlDataClass.getDateTime())) {
- fail("DateTime " + Data.dateTime.toString() + " is not expected " + sqlDataClass.getDateTime().toString());
- }
- }
-
- /**
- * Test {@link TimeStamp} type.
- */
- private void testTimeStamp() {
- assertTrue(
- "TimeStamp " + sqlDataClass.getTimeStamp().toString() + " does not equal expected "
- + Data.timeStamp.toString(), Data.timeStamp.isEqualTo(sqlDataClass.getTimeStamp()));
- }
-
- /**
- * Test {@link Time} type.
- */
- /**/
- private void testTime() {
- assertNotNull("sqlDataClass is null", sqlDataClass);
- assertNotNull("getTime() is null", sqlDataClass.getTime());
- assertTrue("Time 14h56: expected " + Data.time.toString() + ", but got " + sqlDataClass.getTime().toString(),
- Data.time.isEqualTo(sqlDataClass.getTime()));
- }
-
- /**
- * Test {@link Color} type.
- */
- private void testColor() {
- assertEquals(Data.color, sqlDataClass.getColor());
- }
-
- /**
- * Test {@link Image} type.
- */
- private void testImage() {
- Image image1 = new Image(new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } });
- Image image2 = sqlDataClass.getImage();
- // REVIEW: Only XML persistor fails here...
- if (!persistenceMechanismIs("xml")) {
- assertImagesEqual(image1, image2);
- }
- }
-
- private void assertImagesEqual(Image image2, Image image3) {
- assertEquals(image2.getHeight(), image3.getHeight());
- assertEquals(image2.getWidth(), image3.getWidth());
- boolean same = true;
- int i = 0, j = 0;
- int p1 = 0, p2 = 0;
- String error = "";
- int[][] i1 = image2.getImage(), i2 = image3.getImage();
- for (i = 0; same && i < image2.getHeight(); i++) {
- int[] r1 = i1[i], r2 = i2[i];
- for (j = 0; same && j < image2.getWidth(); j++) {
- p1 = r1[j];
- p2 = r2[j];
- if (p1 != p2) {
- same = false;
- error = "Images differ at i = " + i + ", j = " + j + ", " + p1 + " is not " + p2 + "!";
- break;
- }
- }
- }
- assertTrue(error, same);
- }
-
- /**
- * Test {@link Password} type.
- */
- private void testPassword() {
- assertEquals(Data.password, sqlDataClass.getPassword());
- }
-
- /**
- * Test {@link Percentage} type.
- */
- private void testPercentage() {
- assertEquals(Data.percentage, sqlDataClass.getPercentage());
- }
-
- private void testStandardValueTypesMaxima() {
- final PrimitiveValuedEntity pveMax = sqlDataClass.getPrimitiveValuedEntityMax();
-
- assertEquals(Data.shortMaxValue, pveMax.getShortProperty());
- assertEquals(Data.intMaxValue, pveMax.getIntProperty());
- assertEquals(Data.longMaxValue, pveMax.getLongProperty());
- assertEquals(Data.doubleMaxValue, pveMax.getDoubleProperty(), 0.00001f); // fails
- // in
- assertEquals(Data.floatMaxValue, pveMax.getFloatProperty(), 0.00001f);
- }
-
- private void testStandardValueTypesMinima() {
- final PrimitiveValuedEntity pveMin = sqlDataClass.getPrimitiveValuedEntityMin();
-
- assertEquals(Data.shortMinValue, pveMin.getShortProperty());
- assertEquals(Data.intMinValue, pveMin.getIntProperty());
- assertEquals(Data.longMinValue, pveMin.getLongProperty());
- assertEquals(Data.doubleMinValue, pveMin.getDoubleProperty(), 0.00001f); // fails
- // in
- // MySQL
- // =
- // infinity
- assertEquals(Data.floatMinValue, pveMin.getFloatProperty(), 0.00001f);
- }
-
- /**
- * Test {@link StringCollection} type.
- */
- /*
- * public void testStringCollection(){ SqlDataClass sqlDataClass = SqlIntegrationTestSingleton.getPerson();
- * List<String> collection = sqlDataClass.getStringCollection(); int i = 0; for (String string : collection) {
- * assertEquals(SqlIntegrationTestCommon.stringList.get(i++), string); } }
- */
-
- private void testSingleReferenceLazy() {
- final SimpleClassTwo a = sqlDataClass.getSimpleClassTwo();
- if (!persistenceMechanismIs("in-memory")) {
- assertEquals(null, a.text); // must check direct value, as
- // framework can auto-resolve, if you use getText()
- }
- }
-
- /**
- * Test a collection of {@link SimpleClass} type.
- */
- private void testSimpleClassCollection1() {
- final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
-
- assertEquals("collection size is not equal!", simpleClassList1.size(), collection.size());
-
- int i = 0;
- for (final SimpleClass simpleClass : simpleClassList1) {
- assertEquals(simpleClass.getString(), collection.get(i++).getString());
- }
- }
-
- /**
- * Test another collection of {@link SimpleClass} type.
- */
- private void testSimpleClassCollection2() {
- final List<SimpleClass> collection = sqlDataClass.getSimpleClasses2();
-
- assertEquals("collection size is not equal!", simpleClassList2.size(), collection.size());
-
- int i = 0;
- for (final SimpleClass simpleClass : simpleClassList2) {
- assertEquals(simpleClass.getString(), collection.get(i++).getString());
- }
- }
-
- private void testSimpleClassTwoReferenceLazy() {
- final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
- if (getProperties().getProperty("isis.persistor") != "in-memory") {
- for (final SimpleClass simpleClass : collection) {
- final SimpleClassTwo a = simpleClass.getSimpleClassTwoA();
- assertEquals(null, a.text); // must check direct value, as
- // framework can auto-resolve, if
- // you use getText()
- }
- }
- }
-
- private void testSingleReferenceResolve() {
- final SimpleClassTwo a = sqlDataClass.getSimpleClassTwo();
- factory.resolve(a);
- assertEquals(simpleClassTwoA.getText(), a.getText());
- }
-
- private void testSimpleClassTwoReferenceResolve() {
- final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
- for (final SimpleClass simpleClass : collection) {
- final SimpleClassTwo a = simpleClass.getSimpleClassTwoA();
- factory.resolve(a);
- assertEquals(simpleClassTwoA.getText(), a.getText());
- assertEquals(simpleClassTwoA.getIntValue(), a.getIntValue());
- assertEquals(simpleClassTwoA.getBooleanValue(), a.getBooleanValue());
- }
- }
-
- private void testSimpleClassTwo() {
- final SqlDomainObjectRepository factory = getSqlIntegrationTestFixtures().getSqlDataClassFactory();
- final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
- assertEquals(2, classes.size());
- for (final SimpleClassTwo simpleClass : classes) {
- // assertEquals(simpleClassTwoA.getText(), simpleClass.getText());
- assertTrue("AB".contains(simpleClass.getText()));
- }
- }
-
- private void testUpdate1() {
- final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
- assertEquals(2, classes.size());
-
- final SimpleClassTwo simpleClass = classes.get(0);
- simpleClass.setText("XXX");
- simpleClass.setBooleanValue(false);
- simpleClassTwoA.setBooleanValue(false);
-
- setFixtureInitializationStateIfNot(State.INITIALIZE, "in-memory");
- }
-
- private void testUpdate2() {
- final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
- assertEquals(2, classes.size());
-
- final SimpleClassTwo simpleClass = classes.get(0);
- assertEquals("XXX", simpleClass.getText());
- assertEquals(simpleClassTwoA.getBooleanValue(), simpleClass.getBooleanValue());
-
- setFixtureInitializationState(State.DONT_INITIALIZE);
- }
-
- private void testUpdateCollectionIsDirty() {
-
- final List<SqlDataClass> sqlDataClasses = factory.allDataClasses();
- final SqlDataClass sqlDataClass = sqlDataClasses.get(0);
-
- final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
- final SimpleClass simpleClass1 = collection.get(0);
-
- collection.remove(simpleClass1);
-
- // REVIEW: I'm very doubtful about this...
- // what exactly is meant by updating an internal collection?
- if (!persistenceMechanismIs("xml")) {
- factory.update(collection);
- }
-
- factory.update(sqlDataClass);
- }
-
- private void testLimitCount() {
- final List<SimpleClass> subset = factory.someSimpleClasses(0, 2);
- assertEquals(2, subset.size());
- // TODO: This test does not confirm that the *right* 2 were returned.
- }
-
- private void testFindByMatchString() {
- final SimpleClass simpleClassMatch = new SimpleClass();
- simpleClassMatch.setString(Data.stringList1.get(1));
-
- final List<SimpleClass> classes = factory.allSimpleClassesThatMatch(simpleClassMatch);
- assertEquals(1, classes.size());
-
- }
-
- private void testFindByMatchEntity() {
- final List<SimpleClassTwo> classTwos = factory.allSimpleClassTwos();
-
- final SimpleClass simpleClassMatch = new SimpleClass();
- simpleClassMatch.setSimpleClassTwoA(classTwos.get(0));
-
- final List<SimpleClass> classes = factory.allSimpleClassesThatMatch(simpleClassMatch);
-
- // TODO: Why is this hack required?
- if (!getProperties().getProperty("isis.persistor").equals("in-memory")) {
- assertEquals(Data.stringList1.size(), classes.size());
- } else {
- assertEquals(Data.stringList1.size() + 2, classes.size());
- }
- }
-}
[04/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java
new file mode 100755
index 0000000..4bf0928
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java
@@ -0,0 +1,205 @@
+/*
+ * 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.isis.objectstore.sql.auto;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Lists;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.FieldMappingLookup;
+import org.apache.isis.objectstore.sql.IdMappingAbstract;
+import org.apache.isis.objectstore.sql.ObjectMapping;
+import org.apache.isis.objectstore.sql.ObjectMappingLookup;
+import org.apache.isis.objectstore.sql.VersionMapping;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+/**
+ * Used to map 1-to-many collections by creating, in the child table, 1 column
+ * per parent collection. The column is named by combining the final part of the
+ * parent class name and the collection variable name.
+ *
+ * You have a choice between this class and
+ * {@link PolymorphicForeignKeyInChildCollectionBaseMapper}
+ *
+ * @author Kevin
+ */
+public class PolymorphicForeignKeyInChildCollectionMapper extends ForeignKeyInChildCollectionMapper {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PolymorphicForeignKeyInChildCollectionMapper.class);
+
+ private final ObjectAssociation baseField;
+ private final List<String> tables;
+ private final List<ObjectSpecification> tableSpecifications;
+ private final List<ObjectMapping> subClassMappers;
+
+ // For iterating through the subclasses
+ private ObjectSpecification currentTableSpecification;
+ private Iterator<ObjectAdapter> currentIterator;
+ private List<ObjectAdapter> currentCollection;
+ private int currentIndexStart;
+ private int currentIndex;
+
+ // Store for passing on to other mappers
+ final String parameterBase;
+ final FieldMappingLookup lookup;
+ final ObjectMappingLookup objectMapperLookup;
+ final String fieldClassName;
+
+ public PolymorphicForeignKeyInChildCollectionMapper(final ObjectAssociation objectAssociation, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup, final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) {
+
+ super(lookup, abstractAutoMapper, field);
+
+ fieldClassName = className;
+
+ baseField = objectAssociation;
+ tables = new ArrayList<String>();
+ tableSpecifications = new ArrayList<ObjectSpecification>();
+ subClassMappers = new ArrayList<ObjectMapping>();
+
+ // Capture for use in creating subclass mappers.
+ this.parameterBase = parameterBase;
+ this.lookup = lookup;
+ this.objectMapperLookup = objectMapperLookup;
+
+ addSubSpecificationsToTable(specification);
+ }
+
+ protected void addSubSpecificationsToTable(final ObjectSpecification objectSpecification) {
+ if (objectSpecification.isAbstract() == false) {
+ final String tableNameFromSpecification = getTableNameFromSpecification(objectSpecification);
+ tables.add(tableNameFromSpecification);
+ tableSpecifications.add(objectSpecification);
+
+ final ObjectMapping autoMapper = objectMapperLookup.getMapping(objectSpecification, null);
+ subClassMappers.add(autoMapper);
+ }
+ if (objectSpecification.hasSubclasses()) {
+ for (final ObjectSpecification subSpecification : objectSpecification.subclasses()) {
+ addSubSpecificationsToTable(subSpecification);
+ }
+ }
+ }
+
+ @Override
+ public boolean needsTables(final DatabaseConnector connection) {
+ for (final String subTableName : tables) {
+ table = subTableName;
+ if (super.needsTables(connection)) {
+ // Stop on first table that is needed.
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void createTables(final DatabaseConnector connection) {
+ for (final String subTableName : tables) {
+ table = subTableName;
+ if (super.needsTables(connection)) {
+ super.createTables(connection);
+ }
+ }
+ }
+
+ @Override
+ protected Iterator<ObjectAdapter> getElementsForCollectionAsIterator(final ObjectAdapter collection) {
+ return currentIterator;
+ }
+
+ @Override
+ public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent) {
+ final ObjectAdapter collection = baseField.get(parent);
+ LOG.debug("Saving polymorphic internal collection " + collection);
+
+ currentCollection = new ArrayList<ObjectAdapter>();
+ currentIterator = super.getElementsForCollectionAsIterator(collection);
+ for (; currentIterator.hasNext();) {
+ final ObjectAdapter item = currentIterator.next();
+ currentCollection.add(item);
+ }
+
+ for (int i = 0; i < tables.size(); i++) {
+ currentTableSpecification = tableSpecifications.get(i);
+ currentIndex = 0;
+ currentIndexStart = 0;
+
+ currentIterator = new Iterator<ObjectAdapter>() {
+ @Override
+ public boolean hasNext() {
+ for (int i = currentIndexStart; i < currentCollection.size(); i++) {
+ final ObjectAdapter thisObjectAdapter = currentCollection.get(i);
+ if (thisObjectAdapter.getSpecification().isOfType(currentTableSpecification)) {
+ currentIndexStart = currentIndex = i;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public ObjectAdapter next() {
+ currentIndexStart = currentIndex + 1;
+ return currentCollection.get(currentIndex);
+ }
+
+ @Override
+ public void remove() {
+ }
+ };
+
+ // Provide replacement table and column definitions here
+ table = tables.get(i);
+ super.saveInternalCollection(connector, parent);
+ }
+ }
+
+ @Override
+ protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent, final String table, final ObjectSpecification specification, final IdMappingAbstract idMappingAbstract, final Map<ObjectAssociation, FieldMapping> fieldMappingByField, final VersionMapping versionMapping,
+ final List<ObjectAdapter> superList) {
+ final List<ObjectAdapter> list = Lists.newArrayList();
+
+ for (int i = 0; i < tables.size(); i++) {
+ currentTableSpecification = tableSpecifications.get(i);
+ final AutoMapper mapper = (AutoMapper) subClassMappers.get(i);
+ final String mapperTable = tables.get(i);
+
+ super.loadCollectionIntoList(connector, parent, mapperTable, currentTableSpecification, mapper.getIdMapping(), mapper.fieldMappingByField, mapper.getVersionMapping(), list);
+
+ superList.addAll(list);
+ list.clear();
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ReversedAutoAssociationMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ReversedAutoAssociationMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ReversedAutoAssociationMapper.java
new file mode 100644
index 0000000..7169b23
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ReversedAutoAssociationMapper.java
@@ -0,0 +1,212 @@
+/*
+ * 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.isis.objectstore.sql.auto;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.persistence.PersistorUtil;
+import org.apache.isis.objectstore.sql.CollectionMapper;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.FieldMappingLookup;
+import org.apache.isis.objectstore.sql.ObjectMappingLookup;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.VersionMapping;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
+
+/**
+ * used where there is a one to many association, and the elements are only
+ * known to parent
+ */
+public class ReversedAutoAssociationMapper extends AbstractAutoMapper implements CollectionMapper {
+ private static final Logger LOG = LoggerFactory.getLogger(ReversedAutoAssociationMapper.class);
+ private final ObjectAssociation field;
+ private final ObjectReferenceMapping idMapping;
+ private final VersionMapping versionMapping;
+
+ public ReversedAutoAssociationMapper(final String elemenType, final ObjectAssociation field, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectLookup) {
+ super(elemenType, parameterBase, lookup, objectLookup);
+
+ this.field = field;
+
+ idMapping = lookup.createMapping(field.getSpecification());
+ versionMapping = lookup.createVersionMapping();
+
+ setUpFieldMappers();
+ }
+
+ @Override
+ public void createTables(final DatabaseConnector connection) {
+ if (!connection.hasTable(table)) {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("create table ");
+ sql.append(table);
+ sql.append(" (");
+ idMapping.appendColumnDefinitions(sql);
+ sql.append(", ");
+ for (final FieldMapping mapping : fieldMappingByField.values()) {
+ mapping.appendColumnDefinitions(sql);
+ sql.append(",");
+ }
+ sql.append(versionMapping.appendColumnDefinitions());
+ sql.append(")");
+ connection.update(sql.toString());
+ }
+ for (int i = 0; collectionMappers != null && i < collectionMappers.length; i++) {
+ if (collectionMappers[i].needsTables(connection)) {
+ collectionMappers[i].createTables(connection);
+ }
+ }
+ }
+
+ @Override
+ public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter parentAdapter) {
+ final ObjectAdapter collectionAdapter = field.get(parentAdapter);
+ if (!collectionAdapter.canTransitionToResolving()) {
+ return;
+ }
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("loading internal collection " + field);
+ }
+
+ try {
+ // added, since was missing (presumably an error given similarity with other 'Mapper' impls?)
+ PersistorUtil.startResolving(collectionAdapter);
+
+ final StringBuffer sql = new StringBuffer();
+ sql.append("select ");
+ idMapping.appendColumnNames(sql);
+ sql.append(", ");
+ sql.append(columnList(fieldMappingByField));
+ sql.append(" from ");
+ sql.append(table);
+ sql.append(" where ");
+ idMapping.appendUpdateValues(connector, sql, parentAdapter);
+
+ final Results rs = connector.select(sql.toString());
+ final List<ObjectAdapter> list = new ArrayList<ObjectAdapter>();
+ while (rs.next()) {
+ final Oid oid = idMapping.recreateOid(rs, specification);
+ final ObjectAdapter element = getAdapter(specification, oid);
+ loadFields(element, rs);
+ if(LOG.isDebugEnabled()) {
+ LOG.debug(" element " + element.getOid());
+ }
+ list.add(element);
+ }
+ final CollectionFacet collectionFacet = collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
+ collectionFacet.init(collectionAdapter, list.toArray(new ObjectAdapter[list.size()]));
+ rs.close();
+ } finally {
+ PersistorUtil.toEndState(collectionAdapter);
+ }
+
+ }
+
+ protected void loadFields(final ObjectAdapter object, final Results rs) {
+ try {
+ PersistorUtil.startResolving(object);
+ for (final FieldMapping mapping : fieldMappingByField.values()) {
+ mapping.initializeField(object, rs);
+ }
+ /*
+ * for (int i = 0; i < oneToManyProperties.length; i++) { /* Need to set
+ * up collection to be a ghost before we access as below
+ */
+ // CollectionAdapter collection = (CollectionAdapter)
+ /*
+ * oneToManyProperties[i].get(object); }
+ */
+
+ object.setVersion(versionMapping.getLock(rs));
+
+ } finally {
+ PersistorUtil.toEndState(object);
+ }
+ }
+
+ @Override
+ public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent) {
+ final ObjectAdapter collection = field.get(parent);
+ LOG.debug("Saving internal collection " + collection);
+
+ deleteAllElments(connector, parent);
+ reinsertElements(connector, parent, collection);
+ }
+
+ private void reinsertElements(final DatabaseConnector connector, final ObjectAdapter parent, final ObjectAdapter collection) {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("insert into " + table + " (");
+ idMapping.appendColumnNames(sql);
+ sql.append(", ");
+ final String columnList = columnList(fieldMappingByField);
+ if (columnList.length() > 0) {
+ sql.append(columnList);
+ sql.append(", ");
+ }
+ sql.append(versionMapping.insertColumns());
+ sql.append(") values (");
+ idMapping.appendInsertValues(connector, sql, parent);
+ sql.append(", ");
+
+ final CollectionFacet collectionFacet = field.getFacet(CollectionFacet.class);
+ for (final ObjectAdapter element : collectionFacet.iterable(collection)) {
+ final StringBuffer insert = new StringBuffer(sql);
+ insert.append(values(connector, element));
+ final Version version = SerialNumberVersion.create(0, "", new Date());
+ insert.append(versionMapping.insertValues(connector, version));
+ insert.append(") ");
+
+ connector.insert(insert.toString());
+ element.setVersion(version);
+ }
+ }
+
+ private void deleteAllElments(final DatabaseConnector connector, final ObjectAdapter parent) {
+ final StringBuffer sql = new StringBuffer();
+ sql.append("delete from ");
+ sql.append(table);
+ sql.append(" where ");
+ idMapping.appendUpdateValues(connector, sql, parent);
+ connector.update(sql.toString());
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln(field.getName(), "collection");
+ debug.indent();
+ debug.appendln("ID mapping", idMapping);
+ debug.appendln("Version mapping", versionMapping);
+ debug.unindent();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcFieldMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcFieldMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcFieldMapping.java
new file mode 100644
index 0000000..068a314
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcFieldMapping.java
@@ -0,0 +1,111 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+public abstract class AbstractJdbcFieldMapping implements FieldMapping {
+
+ private final String columnName;
+ protected final ObjectAssociation field;
+
+ public AbstractJdbcFieldMapping(final ObjectAssociation field) {
+ this.field = field;
+ columnName = Sql.sqlFieldName(field.getId());
+ }
+
+ @Override
+ public ObjectAssociation getField() {
+ return field;
+ }
+
+ @Override
+ public void appendColumnDefinitions(final StringBuffer sql) {
+ sql.append(columnName);
+ sql.append(" ");
+ sql.append(columnType());
+ }
+
+ @Override
+ public void appendColumnNames(final StringBuffer sql) {
+ sql.append(columnName);
+ }
+
+ @Override
+ public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ final ObjectAdapter fieldValue = field.get(object);
+ if (fieldValue == null) {
+ sql.append("NULL");
+ } else {
+ sql.append("?");
+ connector.addToQueryValues(preparedStatementObject(fieldValue));
+ }
+ }
+
+ @Override
+ public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ appendEqualsClause(connector, sql, object, "=");
+ }
+
+ @Override
+ public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ appendEqualsClause(connector, sql, object, "=");
+ }
+
+ protected void appendEqualsClause(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object, final String condition) {
+ sql.append(Sql.sqlFieldName(field.getId()));
+ sql.append(condition);
+ final ObjectAdapter fieldValue = field.get(object);
+ sql.append("?");
+ connector.addToQueryValues(preparedStatementObject(fieldValue));
+ }
+
+ @Override
+ public void initializeField(final ObjectAdapter object, final Results rs) {
+ final String columnName = Sql.sqlFieldName(field.getId());
+ final ObjectAdapter restoredValue = setFromDBColumn(rs, columnName, field);
+ ((OneToOneAssociation) field).initAssociation(object, restoredValue);
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln(field.getId(), columnName + "/" + columnType());
+ }
+
+ @Override
+ public void appendWhereObject(final DatabaseConnector connector, final ObjectAdapter objectAdapter) {
+ final Object object = preparedStatementObject(objectAdapter);
+ connector.addToQueryValues(object);
+ }
+
+ protected abstract String columnType();
+
+ protected abstract Object preparedStatementObject(ObjectAdapter value);
+
+ protected abstract ObjectAdapter setFromDBColumn(Results results, String columnName, ObjectAssociation field);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcMultiFieldMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcMultiFieldMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcMultiFieldMapping.java
new file mode 100755
index 0000000..adfd00e
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcMultiFieldMapping.java
@@ -0,0 +1,195 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.applib.ApplicationException;
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.Sql;
+
+public abstract class AbstractJdbcMultiFieldMapping extends AbstractJdbcFieldMapping {
+ private final int columnCount;
+ private final String[] types;
+ private final String[] columnNames;
+ private final AdapterManager adapterManager;
+
+ /**
+ *
+ * @param field
+ * the field object association.
+ * @param columnCount
+ * the number of columns required to store this field. See the
+ * abstract methods ,
+ * {@link AbstractJdbcFieldMapping#preparedStatementObject(int i, ObjectAdapter fieldValue)}
+ * ,
+ * {@link AbstractJdbcFieldMapping#getObjectFromResults(Results results)}
+ * ,
+ * @param types
+ * the list of SQL data types, 1 per columnCount, to represent
+ * the value type.
+ */
+ public AbstractJdbcMultiFieldMapping(final ObjectAssociation field, final int columnCount, final String... types) {
+ super(field);
+ this.columnCount = columnCount;
+
+ this.types = new String[columnCount];
+ for (int i = 0; i < types.length; i++) {
+ this.types[i] = types[i];
+ }
+
+ final String fieldName = field.getId();
+ columnNames = new String[columnCount];
+ columnNames[0] = Sql.sqlFieldName(fieldName + "1");
+ columnNames[1] = Sql.sqlFieldName(fieldName + "2");
+
+ adapterManager = IsisContext.getPersistenceSession().getAdapterManager();
+
+ }
+
+ @Override
+ public void appendColumnDefinitions(final StringBuffer sql) {
+ for (int i = 0; i < columnCount; i++) {
+ sql.append(columnName(i) + " " + columnType(i));
+ if (i < columnCount - 1) {
+ sql.append(", ");
+ }
+ }
+ }
+
+ @Override
+ public void appendColumnNames(final StringBuffer sql) {
+ for (int i = 0; i < columnCount; i++) {
+ sql.append(columnName(i));
+ if (i < columnCount - 1) {
+ sql.append(", ");
+ }
+ }
+ }
+
+ @Override
+ public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ final ObjectAdapter fieldValue = field.get(object);
+ final Object o = (fieldValue == null) ? null : fieldValue.getObject();
+
+ for (int i = 0; i < columnCount; i++) {
+ if (fieldValue == null) {
+ sql.append("NULL");
+ } else {
+ sql.append("?");
+ if (i < columnCount - 1) {
+ sql.append(", ");
+ }
+
+ connector.addToQueryValues(preparedStatementObject(i, o));
+ }
+ }
+ }
+
+ @Override
+ public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ final ObjectAdapter fieldValue = field.get(object);
+ final Object o = (fieldValue == null) ? null : fieldValue.getObject();
+ for (int i = 0; i < columnCount; i++) {
+ appendEqualsClause(connector, i, sql, o, "=");
+ }
+ }
+
+ @Override
+ public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ appendUpdateValues(connector, sql, object);
+ }
+
+ private void appendEqualsClause(final DatabaseConnector connector, final int index, final StringBuffer sql, final Object object, final String condition) {
+
+ final Object oPart = preparedStatementObject(index, object);
+
+ sql.append(columnName(index) + condition + "?");
+ if (index < columnCount - 1) {
+ sql.append(", ");
+ }
+
+ connector.addToQueryValues(oPart);
+ }
+
+ @Override
+ public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
+ ObjectAdapter restoredValue;
+ final Object objectValue = getObjectFromResults(results);
+ restoredValue = adapterManager.adapterFor(objectValue); // NOTE: If this
+ // fails, then
+ // fetch back
+ // the
+ // declaration
+ // from the
+ // constructor
+ // to here.
+ return restoredValue;
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ for (int i = 0; i < columnCount; i++) {
+ debug.appendln(field.getId(), columnName(i) + "/" + columnType(i));
+ }
+ }
+
+ @Override
+ protected String columnType() {
+ throw new ApplicationException("Should never be called");
+ }
+
+ @Override
+ protected Object preparedStatementObject(final ObjectAdapter value) {
+ throw new ApplicationException("Should never be called");
+ }
+
+ protected String columnType(final int index) {
+ return types[index];
+ }
+
+ protected String columnName(final int index) {
+ return columnNames[index];
+ }
+
+ /**
+ * Return an object suitable for passing to the SQL prepared statement
+ * constructor, to handle field "index". Will be called "columnCount" times.
+ *
+ * @param index
+ * 0 based index
+ * @param fieldObject
+ * the value type currently being
+ * @return a JDBC-compatible object.
+ */
+ protected abstract Object preparedStatementObject(int index, Object o);
+
+ /**
+ * Return an applib object represented by the results set.
+ *
+ * @param results
+ * the current record row from the underlying table
+ * @return a fully initialised value object.
+ */
+ protected abstract Object getObjectFromResults(Results results);
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcAbstractReferenceFieldMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcAbstractReferenceFieldMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcAbstractReferenceFieldMapping.java
new file mode 100755
index 0000000..a09048f
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcAbstractReferenceFieldMapping.java
@@ -0,0 +1,150 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+/**
+ * Provides support for persisting abstract classes and interfaces.
+ *
+ * Provides two columns: the first is the standard property field. The second is
+ * initialised only when the field is "saved", and contains the actual classname
+ * of the persisted concrete class.
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class JdbcAbstractReferenceFieldMapping extends JdbcObjectReferenceFieldMapping {
+ private final String classnameColumn;
+ private final String dataType;
+
+ public static class Factory extends AbstractFieldMappingFactory {
+
+ public Factory(final String type) {
+ super();
+ }
+
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ final String dataType = getTypeOverride(object, field, Defaults.TYPE_LONG_STRING());
+ return new JdbcAbstractReferenceFieldMapping(field, dataType);
+ }
+ }
+
+ public JdbcAbstractReferenceFieldMapping(final ObjectAssociation field, final String dataType) {
+ super(field);
+ this.dataType = dataType;
+ classnameColumn = Sql.identifier(getColumn() + "_cls");
+ }
+
+ @Override
+ public void appendColumnDefinitions(final StringBuffer sql) {
+ super.appendColumnDefinitions(sql);
+
+ sql.append(", ");
+ sql.append(classnameColumn);
+ sql.append(" ");
+ sql.append(dataType);
+ }
+
+ @Override
+ public void appendCreateColumnDefinitions(final StringBuffer sql) {
+ super.appendCreateColumnDefinitions(sql);
+ sql.append(classnameColumn);
+ sql.append(" ");
+ sql.append(dataType);
+ }
+
+ @Override
+ public void appendColumnNames(final StringBuffer sql) {
+ super.appendColumnNames(sql);
+ sql.append(", ");
+ sql.append(classnameColumn);
+ }
+
+ @Override
+ public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ super.appendWhereClause(connector, sql, object);
+ }
+
+ @Override
+ public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ super.appendInsertValues(connector, sql, object);
+ sql.append(",?");
+
+ final ObjectAdapter objectAdapter = field.get(object);
+ if (objectAdapter != null) {
+ connector.addToQueryValues(objectAdapter.getSpecification().getFullIdentifier());
+ } else {
+ connector.addToQueryValues(null);
+ }
+ }
+
+ @Override
+ public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ super.appendUpdateValues(connector, sql, object);
+
+ sql.append(",");
+ sql.append(classnameColumn);
+ sql.append(" = ?");
+
+ final ObjectAdapter objectAdapter = field.get(object);
+ if (objectAdapter != null) {
+ connector.addToQueryValues(objectAdapter.getSpecification().getFullIdentifier());
+ } else {
+ connector.addToQueryValues(null);
+ }
+ }
+
+ @Override
+ public void initializeField(final ObjectAdapter object, final Results rs) {
+ final String className = rs.getString(classnameColumn);
+ if (className != null) {
+ final ObjectSpecification specification = getReflector().loadSpecification(className);
+
+ final Oid oid = recreateOid(rs, specification);
+
+ final ObjectAdapter reference = getAdapter(specification, oid);
+ ((OneToOneAssociation) field).initAssociation(object, reference);
+ }
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln(field.getId(), getColumn());
+ }
+
+ private SpecificationLoaderSpi getReflector() {
+ return IsisContext.getSpecificationLoader();
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcBinaryValueMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcBinaryValueMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcBinaryValueMapper.java
new file mode 100755
index 0000000..16366b4
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcBinaryValueMapper.java
@@ -0,0 +1,132 @@
+/**
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.core.commons.exceptions.IsisApplicationException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class JdbcBinaryValueMapper extends AbstractJdbcFieldMapping {
+
+ public static class Factory extends AbstractFieldMappingFactory {
+ private final String type;
+
+ public Factory(final String type) {
+ super();
+ this.type = type;
+ }
+
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ final String dataType = getTypeOverride(object, field, type);
+ return new JdbcBinaryValueMapper(field, dataType);
+ }
+ }
+
+ private final String type;
+
+ public JdbcBinaryValueMapper(final ObjectAssociation field, final String type) {
+ super(field);
+ this.type = type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
+ * #columnType()
+ */
+ @Override
+ protected String columnType() {
+ return type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
+ * #preparedStatementObject(org.apache
+ * .isis.core.metamodel.adapter.ObjectAdapter)
+ */
+ @Override
+ protected Object preparedStatementObject(final ObjectAdapter value) {
+ if (value == null) {
+ return null;
+ }
+ final Object o = value.getObject();
+ return o;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
+ * #setFromDBColumn(org.apache.isis. runtimes.dflt.objectstores.sql.Results,
+ * java.lang.String,
+ * org.apache.isis.core.metamodel.spec.feature.ObjectAssociation)
+ */
+ @Override
+ protected ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
+ ObjectAdapter restoredValue;
+
+ final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
+ Object resultObject = results.getObject(columnName);
+ if (resultObject == null) {
+ return null;
+ }
+
+ if (resultObject.getClass() != correspondingClass) {
+ if (checkIfIsClass(correspondingClass, Integer.class, int.class)) {
+ resultObject = results.getInt(columnName);
+ } else if (checkIfIsClass(correspondingClass, Double.class, double.class)) {
+ resultObject = results.getDouble(columnName);
+ } else if (checkIfIsClass(correspondingClass, Float.class, float.class)) {
+ resultObject = results.getFloat(columnName);
+ } else if (checkIfIsClass(correspondingClass, Short.class, short.class)) {
+ resultObject = results.getShort(columnName);
+ } else if (checkIfIsClass(correspondingClass, Long.class, long.class)) {
+ resultObject = results.getLong(columnName);
+ } else if (checkIfIsClass(correspondingClass, Boolean.class, boolean.class)) {
+ resultObject = results.getBoolean(columnName);
+ } else {
+ throw new IsisApplicationException("Unhandled type: " + correspondingClass.getCanonicalName());
+ }
+ }
+
+ restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(resultObject);
+
+ return restoredValue;
+
+ }
+
+ private boolean checkIfIsClass(final Class<?> expected, final Class<?> couldBe1, final Class<?> couldBe2) {
+ return (expected == couldBe1 || expected == couldBe2);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcColorValueMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcColorValueMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcColorValueMapper.java
new file mode 100755
index 0000000..e36c14a
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcColorValueMapper.java
@@ -0,0 +1,101 @@
+/**
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.applib.value.Color;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class JdbcColorValueMapper extends AbstractJdbcFieldMapping {
+
+ public static class Factory extends AbstractFieldMappingFactory {
+ private final String type;
+
+ public Factory(final String type) {
+ super();
+ this.type = type;
+ }
+
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ final String dataType = getTypeOverride(object, field, type);
+ return new JdbcColorValueMapper(field, dataType);
+ }
+ }
+
+ private final String type;
+
+ public JdbcColorValueMapper(final ObjectAssociation field, final String type) {
+ super(field);
+ this.type = type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
+ * #columnType()
+ */
+ @Override
+ protected String columnType() {
+ return type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
+ * #preparedStatementObject(org.apache
+ * .isis.core.metamodel.adapter.ObjectAdapter)
+ */
+ @Override
+ protected Object preparedStatementObject(final ObjectAdapter value) {
+ final Object o = value.getObject();
+ return ((Color) o).intValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
+ * #setFromDBColumn(org.apache.isis. runtimes.dflt.objectstores.sql.Results,
+ * java.lang.String,
+ * org.apache.isis.core.metamodel.spec.feature.ObjectAssociation)
+ */
+ @Override
+ protected ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
+ ObjectAdapter restoredValue;
+ final int intValue = results.getInt(columnName);
+ final Color colorValue = new Color(intValue);
+ restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(colorValue);
+ return restoredValue;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnector.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnector.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnector.java
new file mode 100644
index 0000000..9c3523e
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnector.java
@@ -0,0 +1,404 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.joda.time.DateTimeZone;
+import org.joda.time.LocalDate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.AbstractDatabaseConnector;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.SqlMetaData;
+import org.apache.isis.objectstore.sql.SqlObjectStore;
+import org.apache.isis.objectstore.sql.SqlObjectStoreException;
+
+public class JdbcConnector extends AbstractDatabaseConnector {
+ private static final Logger LOG = LoggerFactory.getLogger(JdbcConnector.class);
+ private Connection connection;
+ private final String baseName;
+
+ public JdbcConnector() {
+ baseName = SqlObjectStore.BASE_NAME;
+ }
+
+ public JdbcConnector(final String propertyBase) {
+ baseName = propertyBase;
+ }
+
+ @Override
+ public void close() {
+ try {
+ if (connection != null) {
+ LOG.info("close");
+ connection.close();
+ connection = null;
+
+ }
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException("Failed to close", e);
+ }
+ }
+
+ @Override
+ public int count(final String sql) {
+ LOG.debug("SQL: " + sql);
+ PreparedStatement statement;
+ try {
+ statement = connection.prepareStatement(sql);
+ final ResultSet result = statement.executeQuery();
+ result.next();
+ final int count = result.getInt(1);
+ statement.close();
+ return count;
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException("Failed count", e);
+ }
+ }
+
+ @Override
+ public void delete(final String sql) {
+ update(sql);
+ }
+
+ public void open() {
+ final String BASE = baseName + ".jdbc.";
+ final IsisConfiguration params = IsisContext.getConfiguration().getProperties(BASE);
+
+ try {
+ final String driver = params.getString(BASE + "driver");
+ final String url = params.getString(BASE + "connection");
+ final String user = params.getString(BASE + "user");
+ final String password = params.getString(BASE + "password");
+
+ if (connection != null) {
+ throw new SqlObjectStoreException("Connection already established");
+ }
+
+ if (driver == null) {
+ throw new SqlObjectStoreException("No driver specified for database connection");
+ }
+ if (url == null) {
+ throw new SqlObjectStoreException("No connection URL specified to database");
+ }
+ if (user == null) {
+ LOG.info("No user specified; will attempt to login with no credentials");
+ } else {
+ if (password == null) {
+ throw new SqlObjectStoreException("No password specified for database connection");
+ }
+ }
+
+ Class.forName(driver);
+ connection = getConnection(url, user, password);
+ if (connection == null) {
+ throw new SqlObjectStoreException("No connection established to " + url);
+ }
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException("Failed to start", e);
+ } catch (final ClassNotFoundException e) {
+ throw new SqlObjectStoreException("Could not find database driver", e);
+ }
+
+ }
+
+ private static Connection getConnection(final String url, final String user, final String password)
+ throws SQLException {
+ if (user != null) {
+ LOG.info("Connecting to " + url + " as " + user);
+ return DriverManager.getConnection(url, user, password);
+ } else {
+ LOG.info("Connecting to " + url + " with no credentials");
+ return DriverManager.getConnection(url);
+ }
+ }
+
+ /*
+ * public void executeStoredProcedure(final StoredProcedure storedProcedure) { Parameter[] parameters =
+ * storedProcedure.getParameters(); StringBuffer sql = new StringBuffer("{call ");
+ * sql.append(storedProcedure.getName()); sql.append(" ("); for (int i = 0, no = parameters.length; i < no; i++) {
+ * sql.append(i == 0 ? "?" : ",?"); } sql.append(")}"); LOG.debug("SQL: " + sql);
+ *
+ * CallableStatement statement; try { statement = connection.prepareCall(sql.toString());
+ *
+ * for (int i = 0; i < parameters.length; i++) { LOG.debug(" setup param " + i + " " + parameters[i]);
+ * parameters[i].setupParameter(i + 1, parameters[i].getName(), storedProcedure); } LOG.debug(" execute ");
+ * statement.execute(); for (int i = 0; i < parameters.length; i++) { parameters[i].retrieve(i + 1,
+ * parameters[i].getName(), storedProcedure); LOG.debug(" retrieve param " + i + " " + parameters[i]); } } catch
+ * (SQLException e) { throw new ObjectAdapterRuntimeException(e); }
+ *
+ * }
+ *
+ *
+ * public MultipleResults executeStoredProcedure(final String name, final Parameter[] parameters) { StringBuffer sql
+ * = new StringBuffer("{call "); sql.append(name); sql.append(" ("); for (int i = 0; i < parameters.length; i++) {
+ * sql.append(i == 0 ? "?" : ",?"); } sql.append(")}"); LOG.debug("SQL: " + sql);
+ *
+ * CallableStatement statement; try { statement = connection.prepareCall(sql.toString());
+ *
+ * StoredProcedure storedProcedure = new JdbcStoredProcedure(statement);
+ *
+ * for (int i = 0; i < parameters.length; i++) { LOG.debug(" setup param " + i + " " + parameters[i]);
+ * parameters[i].setupParameter(i + 1, parameters[i].getName(), storedProcedure); } LOG.debug(" execute ");
+ * statement.execute(); for (int i = 0; i < parameters.length; i++) { parameters[i].retrieve(i + 1,
+ * parameters[i].getName(), storedProcedure); LOG.debug(" retrieve param " + i + " " + parameters[i]); }
+ *
+ * return new JdbcResults(statement); } catch (SQLException e) { throw new ObjectAdapterRuntimeException(e); } }
+ */
+
+ @Override
+ public Results select(final String sql) {
+ LOG.debug("SQL: " + sql);
+ PreparedStatement statement;
+ try {
+ statement = connection.prepareStatement(sql);
+ addPreparedValues(statement);
+ return new JdbcResults(statement.executeQuery());
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ } finally {
+ clearPreparedValues();
+ }
+ }
+
+ @Override
+ public int update(final String sql) {
+ if (sql.length() == 0) {
+ return 0;
+ }
+ LOG.debug("SQL: " + sql);
+ PreparedStatement statement;
+ try {
+ statement = connection.prepareStatement(sql);
+ addPreparedValues(statement);
+ final int updateCount = statement.executeUpdate();
+ statement.close();
+ return updateCount;
+ } catch (final SQLException e) {
+ LOG.error("failed to execute " + sql, e);
+ throw new SqlObjectStoreException("SQL error: " + e.toString(), e);
+ } finally {
+ clearPreparedValues();
+ }
+ }
+
+ private void clearPreparedValues() {
+ queryValues.clear();
+ }
+
+ private void addPreparedValues(final PreparedStatement statement) throws SQLException {
+ if (queryValues.size() > 0) {
+ int i = 1;
+ try {
+ for (final Object value : queryValues) {
+ if (value instanceof LocalDate) {
+ try {
+ statement.setObject(i, value, java.sql.Types.DATE);
+ } catch (final SQLException e) {
+ // TODO This daft catch is required my MySQL, which
+ // also requires the TimeZone offset to be
+ // "undone"
+ final LocalDate localDate = (LocalDate) value;
+ final int millisOffset = -DateTimeZone.getDefault().getOffset(null);
+ final java.util.Date javaDate =
+ localDate.toDateTimeAtStartOfDay(DateTimeZone.forOffsetMillis(millisOffset)).toDate();
+
+ statement.setObject(i, javaDate, java.sql.Types.DATE);
+ }
+ } else if (value instanceof InputStream) {
+ statement.setBlob(i, (InputStream) value);
+ } else {
+ statement.setObject(i, value);
+ }
+ i++;
+ }
+ } catch (final SQLException e) {
+ LOG.error("Error adding prepared value " + i + " of type "
+ + queryValues.get(i - 1).getClass().getSimpleName(), e);
+ throw e;
+ }
+ }
+ }
+
+ @Override
+ public boolean hasTable(final String tableName) {
+ try {
+ final ResultSet set = connection.getMetaData().getTables(null, null, tableName, null);
+ if (set.next()) {
+ LOG.debug("Found " + set.getString("TABLE_NAME"));
+ set.close();
+ return true;
+ } else {
+ set.close();
+ return false;
+ }
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public boolean hasColumn(final String tableName, final String columnName) {
+ try {
+ final ResultSet set = connection.getMetaData().getColumns(null, null, tableName, columnName);
+ if (set.next()) {
+ LOG.debug("Found " + set.getString("COLUMN_NAME") + " in " + set.getString("TABLE_NAME"));
+ set.close();
+ return true;
+ } else {
+ set.close();
+ return false;
+ }
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public void insert(final String sql) {
+ update(sql);
+ }
+
+ @Override
+ public void insert(final String sql, final Object oid) {
+ LOG.debug("SQL: " + sql);
+ PreparedStatement statement;
+ try {
+ statement = connection.prepareStatement(sql);
+ statement.executeUpdate();
+ /*
+ * require 3.0 ResultSet rs = statement.getGeneratedKeys(); if(rs.next()) { int id = rs.getInt(1); }
+ */statement.close();
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException("SQL error", e);
+ }
+ }
+
+ public Connection getConnection() {
+ return connection;
+ }
+
+ @Override
+ public void commit() {
+ try {
+ LOG.debug("commit");
+ connection.commit();
+ connection.setAutoCommit(true);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException("Commit error", e);
+ }
+ }
+
+ @Override
+ public void begin() {
+ try {
+ LOG.debug("begin transaction");
+ connection.setAutoCommit(false);
+ clearPreparedValues();
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException("Rollback error", e);
+ }
+
+ }
+
+ @Override
+ public void rollback() {
+ try {
+ LOG.debug("rollback");
+ connection.rollback();
+ connection.setAutoCommit(true);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException("Rollback error", e);
+ }
+ }
+
+ @Override
+ public SqlMetaData getMetaData() {
+ try {
+ final DatabaseMetaData metaData = connection.getMetaData();
+ return new JdbcSqlMetaData(metaData);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException("Metadata error", e);
+ }
+ }
+
+ @Override
+ public void debug(final DebugBuilder debug) {
+ try {
+ final DatabaseMetaData metaData = connection.getMetaData();
+ debug.appendln("Product", metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion());
+ try {
+ debug.appendln("Product Version",
+ metaData.getDatabaseMajorVersion() + "." + metaData.getDatabaseMinorVersion());
+ } catch (final AbstractMethodError ignore) {
+ }
+ debug.appendln("Drive", metaData.getDriverName() + " " + metaData.getDriverVersion());
+ debug.appendln("Driver Version", metaData.getDriverMajorVersion() + "." + metaData.getDriverMinorVersion());
+ debug.appendln("Keywords", metaData.getSQLKeywords());
+ debug.appendln("Date/Time functions", metaData.getTimeDateFunctions());
+ debug.appendln("Mixed case identifiers", metaData.supportsMixedCaseIdentifiers());
+ debug.appendln("Lower case identifiers", metaData.storesLowerCaseIdentifiers());
+ debug.appendln("Lower case quoted", metaData.storesLowerCaseQuotedIdentifiers());
+ debug.appendln("Mixed case identifiers", metaData.storesMixedCaseIdentifiers());
+ debug.appendln("Mixed case quoted", metaData.storesMixedCaseQuotedIdentifiers());
+ debug.appendln("Upper case identifiers", metaData.storesUpperCaseIdentifiers());
+ debug.appendln("Upper case quoted", metaData.storesUpperCaseQuotedIdentifiers());
+ debug.appendln("Max table name length", metaData.getMaxTableNameLength());
+ debug.appendln("Max column name length", metaData.getMaxColumnNameLength());
+
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException("Metadata error", e);
+ }
+ }
+
+ private final List<Object> queryValues = new ArrayList<Object>();
+
+ @Override
+ public String addToQueryValues(final int i) {
+ queryValues.add(i);
+ return "?";
+ }
+
+ @Override
+ public String addToQueryValues(final String s) {
+ queryValues.add(s);
+ return "?";
+ }
+
+ @Override
+ public String addToQueryValues(final Object o) {
+ queryValues.add(o);
+ return "?";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnectorFactory.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnectorFactory.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnectorFactory.java
new file mode 100644
index 0000000..fcb6a72
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnectorFactory.java
@@ -0,0 +1,34 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.DatabaseConnectorFactory;
+
+public class JdbcConnectorFactory implements DatabaseConnectorFactory {
+
+ @Override
+ public DatabaseConnector createConnector() {
+ final JdbcConnector connection = new JdbcConnector();
+ connection.open();
+ return connection;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateMapper.java
new file mode 100644
index 0000000..20592b3
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateMapper.java
@@ -0,0 +1,108 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.joda.time.LocalDate;
+
+import org.apache.isis.applib.PersistFailedException;
+import org.apache.isis.applib.value.Date;
+import org.apache.isis.core.commons.exceptions.IsisApplicationException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+/**
+ * Handles reading and writing java.sql.Date and org.apache.isis.applib.value.Date values to and from the data store.
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class JdbcDateMapper extends AbstractJdbcFieldMapping {
+
+ private final String dataType;
+
+ public static class Factory extends AbstractFieldMappingFactory {
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ final String dataType = getTypeOverride(object, field, Defaults.TYPE_DATE());
+ return new JdbcDateMapper(field, dataType);
+ }
+ }
+
+ protected JdbcDateMapper(final ObjectAssociation field, final String dataType) {
+ super(field);
+ this.dataType = dataType;
+ }
+
+ @Override
+ protected Object preparedStatementObject(final ObjectAdapter value) {
+ final Object o = value.getObject();
+ if (o instanceof java.sql.Date) {
+ final java.sql.Date javaSqlDate = (java.sql.Date) value.getObject();
+ final long millisSinceEpoch = javaSqlDate.getTime();
+ return new LocalDate(millisSinceEpoch);
+ } else if (o instanceof Date) {
+ final Date asDate = (Date) value.getObject();
+ return new LocalDate(asDate.getMillisSinceEpoch());
+ } else {
+ throw new IsisApplicationException("Unimplemented JdbcDateMapper instance type: "
+ + value.getClass().toString());
+ }
+ }
+
+ @Override
+ public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
+ ObjectAdapter restoredValue;
+ final java.util.Date javaDateValue = results.getJavaDateOnly(columnName);
+ final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
+ if (correspondingClass == java.util.Date.class || correspondingClass == java.sql.Date.class) {
+ // 2011-04-08 = 1270684800000
+ restoredValue = getAdapterManager().adapterFor(javaDateValue);
+ } else if (correspondingClass == Date.class) {
+ // 2010-03-05 = 1267747200000
+ Date dateValue;
+ dateValue = new Date(javaDateValue);
+ restoredValue = getAdapterManager().adapterFor(dateValue);
+ } else {
+ throw new PersistFailedException("Unhandled date type: " + correspondingClass.getCanonicalName());
+ }
+ return restoredValue;
+ }
+
+ @Override
+ public String columnType() {
+ return dataType;
+ }
+
+ protected PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+ protected AdapterManager getAdapterManager() {
+ return getPersistenceSession().getAdapterManager();
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateTimeMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateTimeMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateTimeMapper.java
new file mode 100644
index 0000000..19c2c96
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateTimeMapper.java
@@ -0,0 +1,77 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.applib.PersistFailedException;
+import org.apache.isis.applib.value.DateTime;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+public class JdbcDateTimeMapper extends AbstractJdbcFieldMapping {
+
+ private final String dataType;
+
+ public static class Factory extends AbstractFieldMappingFactory {
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ final String dataType = getTypeOverride(object, field, Defaults.TYPE_DATETIME());
+ return new JdbcDateTimeMapper(field, dataType);
+ }
+ }
+
+ protected JdbcDateTimeMapper(final ObjectAssociation field, final String dataType) {
+ super(field);
+ this.dataType = dataType;
+ }
+
+ @Override
+ protected Object preparedStatementObject(final ObjectAdapter value) {
+ final DateTime asDate = (DateTime) value.getObject();
+ final java.sql.Timestamp dateTime = new java.sql.Timestamp(asDate.millisSinceEpoch());
+ return dateTime;
+ }
+
+ @Override
+ public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
+
+ ObjectAdapter restoredValue;
+ final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
+ if (correspondingClass == DateTime.class) {
+ final java.sql.Timestamp o = (java.sql.Timestamp) results.getObject(columnName);
+ final DateTime timeValue = new DateTime(o.getTime());
+ restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(timeValue);
+ } else {
+ throw new PersistFailedException("Unhandled time type: " + correspondingClass.getCanonicalName());
+ }
+ return restoredValue;
+ }
+
+ @Override
+ public String columnType() {
+ return dataType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcGeneralValueMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcGeneralValueMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcGeneralValueMapper.java
new file mode 100644
index 0000000..0129ddc
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcGeneralValueMapper.java
@@ -0,0 +1,101 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.applib.value.Money;
+import org.apache.isis.applib.value.Password;
+import org.apache.isis.applib.value.Percentage;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+public class JdbcGeneralValueMapper extends AbstractJdbcFieldMapping {
+
+ public static class Factory extends AbstractFieldMappingFactory {
+ private final String type;
+
+ public Factory(final String type) {
+ super();
+ this.type = type;
+ }
+
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ final String dataType = getTypeOverride(object, field, type);
+ return new JdbcGeneralValueMapper(field, dataType);
+ }
+ }
+
+ private final String type;
+
+ public JdbcGeneralValueMapper(final ObjectAssociation field, final String type) {
+ super(field);
+ this.type = type;
+ }
+
+ @Override
+ protected Object preparedStatementObject(final ObjectAdapter value) {
+ if (value == null) {
+ return null;
+ }
+
+ final Object o = value.getObject();
+
+ if (o instanceof Money) {
+ return ((Money) o).floatValue();
+ } else if (o instanceof Percentage) {
+ return ((Percentage) o).floatValue();
+ } else if (o instanceof Password) {
+ return ((Password) o).getPassword();
+ } else if (o instanceof String) {
+ return o;
+ } else if (o instanceof Boolean) {
+ return o;
+ } else {
+ if (columnType().contains("CHAR")) {
+ final EncodableFacet facet = value.getSpecification().getFacet(EncodableFacet.class);
+ final String encodedString = facet.toEncodedString(value);
+ return encodedString;
+ } else {
+ return o;
+ }
+ }
+ }
+
+ @Override
+ public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
+ final String encodedValue = results.getString(columnName);
+ if (encodedValue == null) {
+ return null;
+ }
+ final EncodableFacet facet = field.getSpecification().getFacet(EncodableFacet.class);
+ return facet.fromEncodedString(encodedValue);
+ }
+
+ @Override
+ public String columnType() {
+ return type;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcImageValueMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcImageValueMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcImageValueMapper.java
new file mode 100644
index 0000000..f64bf24
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcImageValueMapper.java
@@ -0,0 +1,116 @@
+/**
+ * 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.isis.objectstore.sql.jdbc;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.isis.applib.PersistFailedException;
+import org.apache.isis.applib.value.Image;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+import org.apache.isis.objectstore.sql.mapping.FieldMappingFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class JdbcImageValueMapper extends AbstractJdbcMultiFieldMapping {
+
+ public static class Factory implements FieldMappingFactory {
+ private final String type_string; // A reference, e.g. file name
+ private final String type_blob; // The BLOB data
+
+ public Factory(final String string_type, final String type_blob) {
+ this.type_string = string_type;
+ this.type_blob = type_blob;
+ }
+
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ return new JdbcImageValueMapper(field, type_string, type_blob);
+ }
+ }
+
+ public JdbcImageValueMapper(final ObjectAssociation field, final String type1, final String type2) {
+ super(field, 2, type1, type2);
+ }
+
+ @Override
+ protected Object preparedStatementObject(int index, Object o) {
+ if (o instanceof Image) {
+ if (index == 0) {
+ return "Image";
+ } else {
+ return getOutputStreamFromImage((Image) o);
+ }
+ } else {
+ throw new PersistFailedException("Invalid object type " + o.getClass().getCanonicalName()
+ + " for JdbcImageValueMapper");
+ }
+ }
+
+ private Object getOutputStreamFromImage(Image o) {
+ int[][] intArray = o.getImage();
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ final int height = o.getHeight();
+ final int width = o.getWidth();
+
+ stream.write(height);
+ stream.write(width);
+ for (int j = 0; j < height; j++) {
+ for (int i = 0; i < width; i++) {
+ // stream.write(o.getImage());
+ stream.write(intArray[j][i]);
+ }
+ }
+ return new ByteArrayInputStream(stream.toByteArray());
+ }
+
+ @Override
+ protected Object getObjectFromResults(Results results) {
+ // final String name = results.getString(columnName(0));
+ InputStream binaryStream = results.getStream(columnName(1));
+
+ int[][] intArray;
+ try {
+ int width = binaryStream.read();
+ int height = binaryStream.read();
+
+ intArray = new int[height][width];
+ for (int j = 0; j < height; j++) {
+ for (int i = 0; i < width; i++) {
+ intArray[j][i] = binaryStream.read();
+ }
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ intArray = new int[0][0];
+ }
+
+ final Image object = new Image(intArray);
+
+ return object;
+ }
+
+}
[13/13] git commit: ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
ISIS-522: mothballing SQL OS.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/40561609
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/40561609
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/40561609
Branch: refs/heads/master
Commit: 405616090d76b10ebc0c35220cd234e134749ede
Parents: f807fab
Author: Dan Haywood <da...@apache.org>
Authored: Mon Sep 9 16:07:14 2013 +0100
Committer: Dan Haywood <da...@apache.org>
Committed: Mon Sep 9 16:07:14 2013 +0100
----------------------------------------------------------------------
.gitignore | 5 +-
component/objectstore/sql/NOTICE | 7 -
component/objectstore/sql/pom.xml | 158 ----
component/objectstore/sql/sql-impl/pom.xml | 73 --
.../sql/sql-impl/sqlos-testing.properties | 59 --
.../sql/AbstractDatabaseConnector.java | 46 -
.../sql/AbstractFieldMappingFactory.java | 38 -
.../isis/objectstore/sql/AbstractMapper.java | 53 --
.../isis/objectstore/sql/CollectionMapper.java | 36 -
.../isis/objectstore/sql/DatabaseConnector.java | 79 --
.../sql/DatabaseConnectorFactory.java | 24 -
.../objectstore/sql/DatabaseConnectorPool.java | 109 ---
.../apache/isis/objectstore/sql/Defaults.java | 370 --------
.../sql/FieldMappingFactoryInstaller.java | 24 -
.../objectstore/sql/FieldMappingLookup.java | 131 ---
.../apache/isis/objectstore/sql/IdMapping.java | 40 -
.../isis/objectstore/sql/IdMappingAbstract.java | 112 ---
.../isis/objectstore/sql/MappingLookup.java | 26 -
.../isis/objectstore/sql/MultipleResults.java | 24 -
.../isis/objectstore/sql/ObjectMapping.java | 57 --
.../objectstore/sql/ObjectMappingFactory.java | 24 -
.../objectstore/sql/ObjectMappingLookup.java | 153 ----
.../apache/isis/objectstore/sql/Parameter.java | 30 -
.../apache/isis/objectstore/sql/Results.java | 63 --
.../org/apache/isis/objectstore/sql/Sql.java | 108 ---
.../objectstore/sql/SqlExecutionContext.java | 46 -
.../objectstore/sql/SqlIdentifierGenerator.java | 148 ----
.../isis/objectstore/sql/SqlMetaData.java | 36 -
.../isis/objectstore/sql/SqlObjectStore.java | 508 -----------
.../sql/SqlObjectStoreException.java | 42 -
.../objectstore/sql/SqlPersistorInstaller.java | 88 --
.../isis/objectstore/sql/StoredProcedure.java | 26 -
.../isis/objectstore/sql/TitleMapping.java | 71 --
.../isis/objectstore/sql/VersionMapping.java | 106 ---
.../sql/auto/AbstractAutoMapper.java | 357 --------
.../sql/auto/AutoCollectionMapper.java | 172 ----
.../isis/objectstore/sql/auto/AutoMapper.java | 514 -----------
.../objectstore/sql/auto/AutoMapperFactory.java | 32 -
.../sql/auto/ForeignKeyCollectionMapper.java | 388 --------
.../auto/ForeignKeyInChildCollectionMapper.java | 89 --
...icForeignKeyInChildCollectionBaseMapper.java | 237 -----
...orphicForeignKeyInChildCollectionMapper.java | 205 -----
.../sql/auto/ReversedAutoAssociationMapper.java | 212 -----
.../sql/jdbc/AbstractJdbcFieldMapping.java | 111 ---
.../sql/jdbc/AbstractJdbcMultiFieldMapping.java | 195 ----
.../jdbc/JdbcAbstractReferenceFieldMapping.java | 150 ----
.../sql/jdbc/JdbcBinaryValueMapper.java | 132 ---
.../sql/jdbc/JdbcColorValueMapper.java | 101 ---
.../objectstore/sql/jdbc/JdbcConnector.java | 404 ---------
.../sql/jdbc/JdbcConnectorFactory.java | 34 -
.../objectstore/sql/jdbc/JdbcDateMapper.java | 108 ---
.../sql/jdbc/JdbcDateTimeMapper.java | 77 --
.../sql/jdbc/JdbcGeneralValueMapper.java | 101 ---
.../sql/jdbc/JdbcImageValueMapper.java | 116 ---
.../sql/jdbc/JdbcMoneyValueMapper.java | 81 --
.../jdbc/JdbcObjectReferenceFieldMapping.java | 101 ---
.../sql/jdbc/JdbcObjectReferenceMapping.java | 68 --
.../jdbc/JdbcObjectReferenceMappingFactory.java | 33 -
.../sql/jdbc/JdbcPasswordValueMapper.java | 106 ---
.../JdbcPolymorphicObjectReferenceMapping.java | 71 --
.../isis/objectstore/sql/jdbc/JdbcResults.java | 232 -----
.../objectstore/sql/jdbc/JdbcSqlMetaData.java | 86 --
.../objectstore/sql/jdbc/JdbcTimeMapper.java | 84 --
.../sql/jdbc/JdbcTimestampMapper.java | 78 --
.../helpers/SimplePasswordEncoderDecoder.java | 115 ---
.../JdbcFieldMappingFactoryInstaller.java | 93 --
.../objectstore/sql/mapping/FieldMapping.java | 48 -
.../sql/mapping/FieldMappingFactory.java | 27 -
.../sql/mapping/ObjectReferenceMapping.java | 40 -
.../mapping/ObjectReferenceMappingFactory.java | 26 -
.../sql/sql-impl/src/site/apt/index.apt | 27 -
.../sql/sql-impl/src/site/apt/jottings.apt | 24 -
.../objectstore/sql/sql-impl/src/site/site.xml | 40 -
.../isis/objectstore/sql/DefaultsTest.java | 60 --
.../SimplePasswordEncoderDecoderTest.java | 66 --
.../objectstore/sql/sql-tests-common/pom.xml | 166 ----
.../isis/objectstore/sql/common/Data.java | 100 ---
.../common/SqlIntegrationTestCommonBase.java | 190 ----
.../sql/common/SqlIntegrationTestData.java | 651 --------------
.../sql/common/SqlIntegrationTestFixtures.java | 230 -----
.../isis/objectstore/sql/common/Utils.java | 61 --
.../src/main/resources/log4j.properties | 39 -
.../sql/sql-tests-common/src/site/apt/index.apt | 28 -
.../sql-tests-common/src/site/apt/jottings.apt | 24 -
.../sql/sql-tests-common/src/site/site.xml | 39 -
.../src/test/config/hsql-poly.properties | 29 -
.../src/test/config/hsql.properties | 33 -
.../apache/isis/objectstore/sql/HsqlTest.java | 72 --
.../isis/objectstore/sql/PolymorphismTest.java | 374 --------
.../sql/crosscheck/InMemoryPersistenceTest.java | 67 --
.../sql/crosscheck/XmlPersistenceTest.java | 65 --
.../objectstore/sql/sql-tests-served/pom.xml | 163 ----
.../src/main/resources/log4j.properties | 39 -
.../sql/sql-tests-served/src/site/apt/index.apt | 29 -
.../sql-tests-served/src/site/apt/jottings.apt | 24 -
.../sql/sql-tests-served/src/site/site.xml | 39 -
.../src/test/config/db2.properties | 27 -
.../src/test/config/mssqlserver.properties | 32 -
.../src/test/config/mysql.properties | 29 -
.../src/test/config/postgresql.properties | 29 -
.../objectstore/sql/MySqlIntegrationTest.java | 55 --
.../sql/PostgreSqlIntegrationTest.java | 56 --
.../src/docbkx/guide/isis-sql-objectstore.xml | 886 -------------------
.../appended-resources/supplemental-models.xml | 106 ---
.../objectstore/sql/src/site/apt/index.apt | 48 -
.../objectstore/sql/src/site/apt/jottings.apt | 24 -
component/objectstore/sql/src/site/site.xml | 52 --
mothballed/component/objectstore/sql/NOTICE | 7 +
mothballed/component/objectstore/sql/pom.xml | 158 ++++
.../component/objectstore/sql/sql-impl/pom.xml | 73 ++
.../sql/sql-impl/sqlos-testing.properties | 59 ++
.../sql/AbstractDatabaseConnector.java | 46 +
.../sql/AbstractFieldMappingFactory.java | 38 +
.../isis/objectstore/sql/AbstractMapper.java | 53 ++
.../isis/objectstore/sql/CollectionMapper.java | 36 +
.../isis/objectstore/sql/DatabaseConnector.java | 79 ++
.../sql/DatabaseConnectorFactory.java | 24 +
.../objectstore/sql/DatabaseConnectorPool.java | 109 +++
.../apache/isis/objectstore/sql/Defaults.java | 370 ++++++++
.../sql/FieldMappingFactoryInstaller.java | 24 +
.../objectstore/sql/FieldMappingLookup.java | 131 +++
.../apache/isis/objectstore/sql/IdMapping.java | 40 +
.../isis/objectstore/sql/IdMappingAbstract.java | 112 +++
.../isis/objectstore/sql/MappingLookup.java | 26 +
.../isis/objectstore/sql/MultipleResults.java | 24 +
.../isis/objectstore/sql/ObjectMapping.java | 57 ++
.../objectstore/sql/ObjectMappingFactory.java | 24 +
.../objectstore/sql/ObjectMappingLookup.java | 153 ++++
.../apache/isis/objectstore/sql/Parameter.java | 30 +
.../apache/isis/objectstore/sql/Results.java | 63 ++
.../org/apache/isis/objectstore/sql/Sql.java | 108 +++
.../objectstore/sql/SqlExecutionContext.java | 46 +
.../objectstore/sql/SqlIdentifierGenerator.java | 148 ++++
.../isis/objectstore/sql/SqlMetaData.java | 36 +
.../isis/objectstore/sql/SqlObjectStore.java | 508 +++++++++++
.../sql/SqlObjectStoreException.java | 42 +
.../objectstore/sql/SqlPersistorInstaller.java | 88 ++
.../isis/objectstore/sql/StoredProcedure.java | 26 +
.../isis/objectstore/sql/TitleMapping.java | 71 ++
.../isis/objectstore/sql/VersionMapping.java | 106 +++
.../sql/auto/AbstractAutoMapper.java | 357 ++++++++
.../sql/auto/AutoCollectionMapper.java | 172 ++++
.../isis/objectstore/sql/auto/AutoMapper.java | 514 +++++++++++
.../objectstore/sql/auto/AutoMapperFactory.java | 32 +
.../sql/auto/ForeignKeyCollectionMapper.java | 388 ++++++++
.../auto/ForeignKeyInChildCollectionMapper.java | 89 ++
...icForeignKeyInChildCollectionBaseMapper.java | 237 +++++
...orphicForeignKeyInChildCollectionMapper.java | 205 +++++
.../sql/auto/ReversedAutoAssociationMapper.java | 212 +++++
.../sql/jdbc/AbstractJdbcFieldMapping.java | 111 +++
.../sql/jdbc/AbstractJdbcMultiFieldMapping.java | 195 ++++
.../jdbc/JdbcAbstractReferenceFieldMapping.java | 150 ++++
.../sql/jdbc/JdbcBinaryValueMapper.java | 132 +++
.../sql/jdbc/JdbcColorValueMapper.java | 101 +++
.../objectstore/sql/jdbc/JdbcConnector.java | 404 +++++++++
.../sql/jdbc/JdbcConnectorFactory.java | 34 +
.../objectstore/sql/jdbc/JdbcDateMapper.java | 108 +++
.../sql/jdbc/JdbcDateTimeMapper.java | 77 ++
.../sql/jdbc/JdbcGeneralValueMapper.java | 101 +++
.../sql/jdbc/JdbcImageValueMapper.java | 116 +++
.../sql/jdbc/JdbcMoneyValueMapper.java | 81 ++
.../jdbc/JdbcObjectReferenceFieldMapping.java | 101 +++
.../sql/jdbc/JdbcObjectReferenceMapping.java | 68 ++
.../jdbc/JdbcObjectReferenceMappingFactory.java | 33 +
.../sql/jdbc/JdbcPasswordValueMapper.java | 106 +++
.../JdbcPolymorphicObjectReferenceMapping.java | 71 ++
.../isis/objectstore/sql/jdbc/JdbcResults.java | 232 +++++
.../objectstore/sql/jdbc/JdbcSqlMetaData.java | 86 ++
.../objectstore/sql/jdbc/JdbcTimeMapper.java | 84 ++
.../sql/jdbc/JdbcTimestampMapper.java | 78 ++
.../helpers/SimplePasswordEncoderDecoder.java | 115 +++
.../JdbcFieldMappingFactoryInstaller.java | 93 ++
.../objectstore/sql/mapping/FieldMapping.java | 48 +
.../sql/mapping/FieldMappingFactory.java | 27 +
.../sql/mapping/ObjectReferenceMapping.java | 40 +
.../mapping/ObjectReferenceMappingFactory.java | 26 +
.../sql/sql-impl/src/site/apt/index.apt | 27 +
.../sql/sql-impl/src/site/apt/jottings.apt | 24 +
.../objectstore/sql/sql-impl/src/site/site.xml | 40 +
.../isis/objectstore/sql/DefaultsTest.java | 60 ++
.../SimplePasswordEncoderDecoderTest.java | 66 ++
.../objectstore/sql/sql-tests-common/pom.xml | 166 ++++
.../isis/objectstore/sql/common/Data.java | 100 +++
.../common/SqlIntegrationTestCommonBase.java | 190 ++++
.../sql/common/SqlIntegrationTestData.java | 651 ++++++++++++++
.../sql/common/SqlIntegrationTestFixtures.java | 230 +++++
.../isis/objectstore/sql/common/Utils.java | 61 ++
.../src/main/resources/log4j.properties | 39 +
.../sql/sql-tests-common/src/site/apt/index.apt | 28 +
.../sql-tests-common/src/site/apt/jottings.apt | 24 +
.../sql/sql-tests-common/src/site/site.xml | 39 +
.../src/test/config/hsql-poly.properties | 29 +
.../src/test/config/hsql.properties | 33 +
.../apache/isis/objectstore/sql/HsqlTest.java | 72 ++
.../isis/objectstore/sql/PolymorphismTest.java | 374 ++++++++
.../sql/crosscheck/InMemoryPersistenceTest.java | 67 ++
.../sql/crosscheck/XmlPersistenceTest.java | 65 ++
.../objectstore/sql/sql-tests-served/pom.xml | 163 ++++
.../src/main/resources/log4j.properties | 39 +
.../sql/sql-tests-served/src/site/apt/index.apt | 29 +
.../sql-tests-served/src/site/apt/jottings.apt | 24 +
.../sql/sql-tests-served/src/site/site.xml | 39 +
.../src/test/config/db2.properties | 27 +
.../src/test/config/mssqlserver.properties | 32 +
.../src/test/config/mysql.properties | 29 +
.../src/test/config/postgresql.properties | 29 +
.../objectstore/sql/MySqlIntegrationTest.java | 55 ++
.../sql/PostgreSqlIntegrationTest.java | 56 ++
.../src/docbkx/guide/isis-sql-objectstore.xml | 886 +++++++++++++++++++
.../appended-resources/supplemental-models.xml | 106 +++
.../objectstore/sql/src/site/apt/index.apt | 48 +
.../objectstore/sql/src/site/apt/jottings.apt | 24 +
.../component/objectstore/sql/src/site/site.xml | 52 ++
pom.xml | 1 -
214 files changed, 11964 insertions(+), 11966 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 05c67dc..a597ec3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,12 +14,11 @@ logs/
JArchitectOut/
*.jdproj
-component/objectstore/sql/sql-tests-common/hsql-db/
-component/objectstore/sql/sql-tests-common/xml/
+mothballed/component/objectstore/sql/sql-tests-common/hsql-db/
+mothballed/component/objectstore/sql/sql-tests-common/xml/
component/objectstore/xml/tmp/objects/
component/objectstore/xml/xml/objects/
component/objectstore/xml/tmp/tests/
-component/security/sql/hsql-db/
# log files
datanucleus.log
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/NOTICE
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/NOTICE b/component/objectstore/sql/NOTICE
deleted file mode 100644
index ba21d0c..0000000
--- a/component/objectstore/sql/NOTICE
+++ /dev/null
@@ -1,7 +0,0 @@
-Apache Isis
-Copyright 2010-2013 The Apache Software Foundation
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
-
-
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/pom.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/pom.xml b/component/objectstore/sql/pom.xml
deleted file mode 100644
index 2240e6c..0000000
--- a/component/objectstore/sql/pom.xml
+++ /dev/null
@@ -1,158 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 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. -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis</artifactId>
- <version>1.3.0-SNAPSHOT</version>
- <relativePath>../../../core/pom.xml</relativePath>
- </parent>
-
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-sql</artifactId>
- <version>1.0.0-SNAPSHOT</version>
-
- <name>Isis SQL ObjectStore</name>
-
- <description>
- Provides JDBC-based persistence.
- </description>
-
- <packaging>pom</packaging>
-
- <properties>
- <isis-objectstore-xml.version>1.0.0-SNAPSHOT</isis-objectstore-xml.version>
-
- <siteBaseDir>.</siteBaseDir>
- <relativeUrl/>
-
- <docbkxGuideTitle>Apache Isis Default Runtime SQL ObjectStore</docbkxGuideTitle>
- <docbkxGuideSubTitle>Configuration and Deployment Guide</docbkxGuideSubTitle>
- <docbkxGuideName>isis-sql-objectstore</docbkxGuideName>
- </properties>
-
- <!-- used in Site generation for relative references. -->
- <url>http://isis.apache.org/${relativeUrl}</url>
-
- <build>
- <pluginManagement>
- <plugins>
- <!-- Apache Release Audit Tool -->
- <plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <version>0.8</version>
- <configuration>
- <excludes>
- <!--
- overriding inherited excludes from oia.core:isis
- with a more specific set for this component
- -->
- <exclude>**/target/**</exclude>
- <exclude>**/target-ide/**</exclude>
-
- <exclude>**/*.project</exclude>
- <exclude>**/.classpath</exclude>
- <exclude>**/.settings/**</exclude>
- </excludes>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- <plugins>
- <plugin>
- <groupId>com.agilejava.docbkx</groupId>
- <artifactId>docbkx-maven-plugin</artifactId>
- <inherited>false</inherited>
- </plugin>
- </plugins>
- </build>
-
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <version>${maven-project-info-reports-plugin}</version>
- <inherited>false</inherited>
- <reportSets>
- <reportSet>
- <inherited>false</inherited>
- <reports>
- <report>dependency-management</report>
- <report>plugins</report>
- <report>modules</report>
- <report>summary</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- </plugins>
- </reporting>
-
-
- <modules>
- <module>sql-impl</module>
- <module>sql-tests-common</module>
- <module>sql-tests-served</module>
- </modules>
-
- <dependencyManagement>
- <dependencies>
-
- <!-- for benefit of application developers, using scope=import -->
- <dependency>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-sql-impl</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-sql-tests-common</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-sql-tests-common</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-sql-tests-served</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </dependency>
-
- <!-- Required to support the XML cross-test -->
- <dependency>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-xml</artifactId>
- <version>${isis-objectstore-xml.version}</version>
- </dependency>
-
-
- <!-- Test environment -->
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <version>1.9.5</version>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
- </dependencyManagement>
-
-
-</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/pom.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/pom.xml b/component/objectstore/sql/sql-impl/pom.xml
deleted file mode 100644
index 2c2cc81..0000000
--- a/component/objectstore/sql/sql-impl/pom.xml
+++ /dev/null
@@ -1,73 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 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. -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-sql</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>isis-objectstore-sql-impl</artifactId>
- <name>Isis SQL ObjectStore Implementation</name>
- <description>SQL Objectstire Implementation. Uses jdbc for maximum compatibility.</description>
-
- <properties>
- <siteBaseDir>..</siteBaseDir>
- <relativeUrl>sql-impl/</relativeUrl>
- </properties>
-
- <!-- used in Site generation for relative references. -->
- <url>http://isis.apache.org/${relativeUrl}</url>
-
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <version>${maven-project-info-reports-plugin}</version>
- <inherited>false</inherited>
- <configuration>
- <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
- </configuration>
- <reportSets>
- <reportSet>
- <inherited>false</inherited>
- <reports>
- <report>dependencies</report>
- <report>dependency-convergence</report>
- <report>plugins</report>
- <report>summary</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- </plugins>
- </reporting>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-runtime</artifactId>
- </dependency>
-
- <!-- Test dependencies -->
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/sqlos-testing.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/sqlos-testing.properties b/component/objectstore/sql/sql-impl/sqlos-testing.properties
deleted file mode 100644
index 29d5a76..0000000
--- a/component/objectstore/sql/sql-impl/sqlos-testing.properties
+++ /dev/null
@@ -1,59 +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.
-# run with SQL object store
-#isis.object-store=org.apache.isis.persistor.sql.SqlObjectStore
-#isis.persistor.sql.connection=org.apache.isis.persistor.sql.SimpleConnection
-#isis.persistor.sql.database=jdbc:hsqldb:tmp/hsql-db
-#isis.persistor.sql.database=jdbc:hsqldb:hsql://localhost
-#isis.persistor.sql.driver=org.hsqldb.jdbcDriver
-#isis.persistor.sql.user=sa
-#isis.persistor.sql.password=
-
-
-#isis.oidgenerator=org.apache.isis.persistor.sql.SqlOidGenerator
-
-#isis.object-store=org.apache.isis.persistor.sql.SqlObjectStore
-isis.persistor.sql.connector=org.apache.isis.persistor.sql.jdbc.JdbcConnectorFactory
-isis.persistor.sql.automapper=org.apache.isis.persistor.sql.auto.AutoMapperFactory
-
-isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver
-isis.persistor.sql.jdbc.connection=jdbc:hsqldb:tmp/hsql-db
-isis.persistor.sql.jdbc.user=sa
-isis.persistor.sql.jdbc.password=
-
-
-## log4j
-# apache's log4j is used to provide system logging.
-##
-log4j.rootCategory=OFF, Console
-
-# The console appender
-log4j.appender.Console=org.apache.log4j.ConsoleAppender
-log4j.appender.Console.target=System.out
-log4j.appender.Console.layout=org.apache.log4j.PatternLayout
-log4j.appender.Console.layout.ConversionPattern=%-5r [%-20c{1}] %-5p %m -- %l%n
-
-
-log4j.rootCategory=DEBUG, File
-# The file appender
-log4j.appender.File=org.apache.log4j.RollingFileAppender
-log4j.appender.File.file=isis.log
-log4j.appender.File.append=false
-#log4j.appender.File.maxFileSize=500KB
-#log4j.appender.File.maxBackupIndex=1
-log4j.appender.File.layout=org.apache.log4j.PatternLayout
-log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractDatabaseConnector.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractDatabaseConnector.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractDatabaseConnector.java
deleted file mode 100644
index a993d33..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractDatabaseConnector.java
+++ /dev/null
@@ -1,46 +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.isis.objectstore.sql;
-
-public abstract class AbstractDatabaseConnector implements DatabaseConnector {
- private boolean isUsed;
-
- @Override
- public final void setUsed(final boolean isUsed) {
- this.isUsed = isUsed;
- }
-
- @Override
- public final boolean isUsed() {
- return isUsed;
- }
-
- private DatabaseConnectorPool pool;
-
- @Override
- public final void setConnectionPool(final DatabaseConnectorPool pool) {
- this.pool = pool;
- }
-
- @Override
- public final DatabaseConnectorPool getConnectionPool() {
- return pool;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractFieldMappingFactory.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractFieldMappingFactory.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractFieldMappingFactory.java
deleted file mode 100644
index eb3d48b..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractFieldMappingFactory.java
+++ /dev/null
@@ -1,38 +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.isis.objectstore.sql;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.mapping.FieldMappingFactory;
-
-public abstract class AbstractFieldMappingFactory implements FieldMappingFactory {
-
- protected String getTypeOverride(final ObjectSpecification object, final ObjectAssociation field, final String type) {
- // isis.persistor.sql.automapper.default
- final IsisConfiguration configParameters = IsisContext.getConfiguration();
- final String find = object.getShortIdentifier() + "." + field.getId();
- final String property = SqlObjectStore.BASE_NAME + ".automapper.type." + find;
- final String dataType = configParameters.getString(property, type);
- return dataType;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractMapper.java
deleted file mode 100644
index 1ec41d4..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/AbstractMapper.java
+++ /dev/null
@@ -1,53 +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.isis.objectstore.sql;
-
-import java.util.Date;
-
-import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-
-
-public abstract class AbstractMapper {
-
- public abstract void createTables(final DatabaseConnector connector);
-
- protected boolean needsTables(final DatabaseConnector connector) {
- return false;
- }
-
- public void startup(final DatabaseConnector connector) {
- if (needsTables(connector)) {
- createTables(connector);
- }
- }
-
- public final void shutdown() {
- }
-
- protected String asSqlName(final String name) {
- return Sql.sqlName(name);
- }
-
- protected Version createVersion(final long versionSequence) {
- return SerialNumberVersion.create(versionSequence, "", new Date());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/CollectionMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/CollectionMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/CollectionMapper.java
deleted file mode 100644
index 9d19bbc..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/CollectionMapper.java
+++ /dev/null
@@ -1,36 +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.isis.objectstore.sql;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-
-public interface CollectionMapper {
-
- public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent);
-
- public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent);
-
- void createTables(DatabaseConnector connection);
-
- boolean needsTables(DatabaseConnector connection);
-
- public void debugData(DebugBuilder debug);
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnector.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnector.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnector.java
deleted file mode 100644
index 602a1cb..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnector.java
+++ /dev/null
@@ -1,79 +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.isis.objectstore.sql;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-
-public interface DatabaseConnector {
- /*
- * @deprecated Results callStoredProcedure(String name, Parameter[]
- * parameters);
- */
- void close();
-
- int count(String sql);
-
- void delete(String sql);
-
- // MultipleResults executeStoredProcedure(String name, Parameter[]
- // parameters);
-
- boolean hasTable(String tableName);
-
- boolean hasColumn(String tableName, String columnName);
-
- void insert(String sql);
-
- void insert(String sql, Object oid);
-
- Results select(String sql);
-
- /**
- * Updates the database using the specified sql statement, and returns the
- * number of rows affected.
- */
- int update(String sql);
-
- void setUsed(boolean isUsed);
-
- boolean isUsed();
-
- void commit();
-
- void rollback();
-
- void setConnectionPool(DatabaseConnectorPool pool);
-
- DatabaseConnectorPool getConnectionPool();
-
- void begin();
-
- void debug(DebugBuilder debug);
-
- SqlMetaData getMetaData();
-
- // Full PreparedStatement support
- public String addToQueryValues(int i);
-
- public String addToQueryValues(String s);
-
- public String addToQueryValues(Object object);
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorFactory.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorFactory.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorFactory.java
deleted file mode 100644
index 1f94c34..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorFactory.java
+++ /dev/null
@@ -1,24 +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.isis.objectstore.sql;
-
-public interface DatabaseConnectorFactory {
- DatabaseConnector createConnector();
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorPool.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorPool.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorPool.java
deleted file mode 100644
index 89c90c9..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/DatabaseConnectorPool.java
+++ /dev/null
@@ -1,109 +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.isis.objectstore.sql;
-
-import java.util.Vector;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-
-public class DatabaseConnectorPool {
- private static final Logger LOG = LoggerFactory.getLogger(DatabaseConnectorPool.class);
- private static final int AVERAGE_POOL_SIZE = 5;
-
- private final DatabaseConnectorFactory factory;
- private final Vector<DatabaseConnector> connectorPool;
-
- public DatabaseConnectorPool(final DatabaseConnectorFactory factory) {
- this(factory, AVERAGE_POOL_SIZE);
- }
-
- public DatabaseConnectorPool(final DatabaseConnectorFactory factory, final int size) {
- this.factory = factory;
- connectorPool = new Vector<DatabaseConnector>();
- for (int i = 0; i < size; i++) {
- newConnector();
- }
- LOG.info("Created an intial pool of " + size + " database connections");
-
- final DatabaseConnector connection = acquire();
- Sql.setMetaData(connection.getMetaData());
- release(connection);
- }
-
- private DatabaseConnector newConnector() {
- final DatabaseConnector connector = factory.createConnector();
- connector.setConnectionPool(this);
- connectorPool.addElement(connector);
- return connector;
- }
-
- public DatabaseConnector acquire() {
- DatabaseConnector connector = findFreeConnector();
- if (connector == null) {
- connector = newConnector();
- connector.setUsed(true);
- LOG.info("Added an additional database connection; now contains " + connectorPool.size() + " connections");
- }
- LOG.debug("acquired connection " + connector);
- return connector;
- }
-
- private DatabaseConnector findFreeConnector() {
- for (int i = 0, no = connectorPool.size(); i < no; i++) {
- final DatabaseConnector connector = connectorPool.elementAt(i);
- if (!connector.isUsed()) {
- connector.setUsed(true);
- return connector;
- }
- }
- return null;
- }
-
- public void release(final DatabaseConnector connector) {
- connector.setUsed(false);
- LOG.debug("released connection " + connector);
- }
-
- public void shutdown() {
- for (int i = 0, no = connectorPool.size(); i < no; i++) {
- final DatabaseConnector connector = connectorPool.elementAt(i);
- try {
- connector.close();
- } catch (final SqlObjectStoreException e) {
- LOG.error("Failed to release connectuion", e);
- }
- }
- connectorPool.removeAllElements();
- }
-
- public void debug(final DebugBuilder debug) {
- final DatabaseConnector connection = acquire();
- connection.debug(debug);
- release(connection);
-
- }
-
- public SqlMetaData getMetaData() {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Defaults.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Defaults.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Defaults.java
deleted file mode 100755
index 1433faf..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/Defaults.java
+++ /dev/null
@@ -1,370 +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.isis.objectstore.sql;
-
-import java.util.Calendar;
-
-import org.joda.time.DateTimeZone;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-
-/**
- * Provides objectstore defaults. Most significantly, maintains the object store default TimeZone, and maintains
- * Calendar.
- *
- *
- * @version $Rev$ $Date$
- */
-public class Defaults {
- private static String propertiesBase;
- private static IsisConfiguration isisConfiguration;
-
- /**
- * Initialise the Defaults internals. Called by the PersistorInstaller.
- *
- * @param propertiesBase
- * by default, @link {@link SqlObjectStore#BASE_NAME}
- * @param isisConfiguration
- */
- public static void initialise(final String propertiesBase, final IsisConfiguration isisConfiguration) {
- Defaults.propertiesBase = propertiesBase; // "isis.persistor.sql"
- setTimeZone(DateTimeZone.UTC);
-
- Defaults.isisConfiguration = isisConfiguration;
-
- setTablePrefix(getStringProperty(propertiesBase, isisConfiguration, "tableprefix", "isis_"));
- setPkIdLabel(getStringProperty(propertiesBase, isisConfiguration, "pk_id"));
- setIdColumn(getStringProperty(propertiesBase, isisConfiguration, "id"));
- setMaxInstances(getIntProperty(propertiesBase, isisConfiguration, "maxinstances", 100));
- final String useVersioningProperty = getStringProperty(propertiesBase, isisConfiguration, "versioning", "true");
- final int isTrue = useVersioningProperty.compareToIgnoreCase("true");
- useVersioning(isTrue == 0);
-
- defineDatabaseCommands();
-
- final String BASE_DATATYPE = propertiesBase + ".datatypes.";
- final IsisConfiguration dataTypes = isisConfiguration.getProperties(BASE_DATATYPE);
- populateSqlDataTypes(dataTypes, BASE_DATATYPE);
-
- }
-
- /**
- * Returns a string value by looking up "isis.persistor.sql.default.XXXX"
- *
- * @param propertiesBase
- * @param configParameters
- * @param property
- * @return
- */
- protected static String getStringProperty(final String propertiesBase, final IsisConfiguration configParameters,
- final String property) {
- return configParameters.getString(propertiesBase + ".default." + property, property);
- }
-
- /**
- * Returns a string value by looking up "isis.persistor.sql.default.XXXX", returning the specified default, if no
- * value was found.
- *
- * @param propertiesBase
- * @param configParameters
- * @param property
- * @param defaultValue
- * @return
- */
- protected static String getStringProperty(final String propertiesBase, final IsisConfiguration configParameters,
- final String property, final String defaultValue) {
- return configParameters.getString(propertiesBase + ".default." + property, defaultValue);
- }
-
- /**
- * Returns an integer value by looking up "isis.persistor.sql.default.XXXX", returning the specified default, if no
- * value was found.
- *
- * @param propertiesBase
- * @param configParameters
- * @param property
- * @param defaultValue
- * @return
- */
- protected static int getIntProperty(final String propertiesBase, final IsisConfiguration configParameters,
- final String property, final int defaultValue) {
- return configParameters.getInteger(propertiesBase + ".default." + property, defaultValue);
- }
-
- // {{ Calendar
- private static Calendar calendar;
-
- public static Calendar getCalendar() {
- return calendar;
- }
-
- // }}
-
- // {{ DateTimeZone
- private static DateTimeZone dateTimeZone;
-
- public static DateTimeZone getTimeZone() {
- return dateTimeZone;
- }
-
- public static void setTimeZone(final DateTimeZone timezone) {
- dateTimeZone = timezone;
- calendar = Calendar.getInstance(timezone.toTimeZone());
- }
-
- // }}
-
- // {{ Table prefix, defaults to "isis_"
- private static String tablePrefix;
-
- public static String getTablePrefix() {
- return Defaults.tablePrefix;
- }
-
- public static void setTablePrefix(final String prefix) {
- Defaults.tablePrefix = prefix;
- }
-
- // }}
-
- // {{ Primary Key label, defaults to "pk_id"
- private static String pkIdLabel;
-
- public static void setPkIdLabel(final String pkIdLabel) {
- Defaults.pkIdLabel = pkIdLabel;
- }
-
- public static String getPkIdLabel() {
- return pkIdLabel;
- }
-
- // }}
-
- // {{ Id Column, defaults to "id"
- private static String idColumn;
-
- public static void setIdColumn(final String idColumn) {
- Defaults.idColumn = idColumn;
- }
-
- public static String getIdColumn() {
- return idColumn;
- }
-
- // }}
-
- // {{ MaxInstances
- private static int maxInstances;
-
- public static int getMaxInstances() {
- return maxInstances;
- }
-
- public static void setMaxInstances(final int maxInstances) {
- Defaults.maxInstances = maxInstances;
- }
-
- // }}
-
- // {{ Default data types
- static String TYPE_BOOLEAN;
- static String TYPE_TIMESTAMP;
- static String TYPE_DATETIME;
- static String TYPE_DATE;
- static String TYPE_TIME;
- static String TYPE_SHORT;
- static String TYPE_DOUBLE;
- static String TYPE_FLOAT;
- static String TYPE_LONG;
- static String TYPE_INT;
- static String TYPE_PK;
- static String TYPE_STRING;
- static String TYPE_LONG_STRING;
- static String TYPE_PASSWORD;
- static String PASSWORD_SEED;
- static Integer PASSWORD_ENC_LENGTH;
- static String TYPE_DEFAULT;
- static String TYPE_BLOB;
-
- /**
- * Default SQL data types used to define the fields in the database. By providing this method, we allow the user an
- * opportunity to override these types by specifying alternatives in sql.properties (or which ever). For example,
- * Postgresql does not know about DATETIME, but can use TIMESTAMP instead.
- *
- * @param dataTypes
- * @param baseName
- */
- private static void populateSqlDataTypes(final IsisConfiguration dataTypes, final String baseName) {
- TYPE_BLOB = dataTypes.getString(baseName + "blob", "BLOB");
- TYPE_TIMESTAMP = dataTypes.getString(baseName + "timestamp", "DATETIME");
- TYPE_DATETIME = dataTypes.getString(baseName + "datetime", "DATETIME");
- TYPE_DATE = dataTypes.getString(baseName + "date", "DATE");
- TYPE_TIME = dataTypes.getString(baseName + "time", "TIME");
- TYPE_DOUBLE = dataTypes.getString(baseName + "double", "DOUBLE");
- TYPE_FLOAT = dataTypes.getString(baseName + "float", "FLOAT");
- TYPE_SHORT = dataTypes.getString(baseName + "short", "INT");
- TYPE_LONG = dataTypes.getString(baseName + "long", "BIGINT");
- TYPE_INT = dataTypes.getString(baseName + "int", "INT");
- TYPE_BOOLEAN = dataTypes.getString(baseName + "boolean", "BOOLEAN"); // CHAR(1)
- TYPE_PK = dataTypes.getString(baseName + "primarykey", "INTEGER");
- TYPE_STRING = dataTypes.getString(baseName + "string", "VARCHAR(65)");
- TYPE_LONG_STRING = dataTypes.getString(baseName + "longstring", "VARCHAR(128)");
- TYPE_PASSWORD = dataTypes.getString(baseName + "password", "VARCHAR(128)");
- PASSWORD_ENC_LENGTH = getIntProperty(propertiesBase, isisConfiguration, "password.length", 120);
- PASSWORD_SEED = getStringProperty(propertiesBase, isisConfiguration, "password.seed");
- TYPE_DEFAULT = dataTypes.getString(baseName + "default", "VARCHAR(65)");
-
- }
-
- public static String TYPE_TIMESTAMP() {
- return TYPE_TIMESTAMP;
- }
-
- public static String TYPE_SHORT() {
- return TYPE_SHORT;
- }
-
- public static String TYPE_INT() {
- return TYPE_INT;
- }
-
- public static String TYPE_LONG() {
- return TYPE_LONG;
- }
-
- public static String TYPE_FLOAT() {
- return TYPE_FLOAT;
- }
-
- public static String TYPE_DOUBLE() {
- return TYPE_DOUBLE;
- }
-
- public static String TYPE_BOOLEAN() {
- return TYPE_BOOLEAN;
- }
-
- public static String TYPE_PK() {
- return TYPE_PK;
- }
-
- public static String TYPE_STRING() {
- return TYPE_STRING;
- }
-
- public static String TYPE_LONG_STRING() {
- return TYPE_LONG_STRING;
- }
-
- public static String TYPE_PASSWORD() {
- return TYPE_PASSWORD;
- }
-
- public static String PASSWORD_SEED() {
- return PASSWORD_SEED;
- }
-
- public static Integer PASSWORD_ENC_LENGTH() {
- return PASSWORD_ENC_LENGTH;
- }
-
- public static String TYPE_DEFAULT() {
- return TYPE_DEFAULT;
- }
-
- public static String TYPE_DATE() {
- return TYPE_DATE;
- }
-
- public static String TYPE_DATETIME() {
- return TYPE_DATETIME;
- }
-
- public static String TYPE_TIME() {
- return TYPE_TIME;
- }
-
- public static String TYPE_BLOB() {
- return TYPE_BLOB;
- }
-
- // }}
-
- // {{ Versioning
- private static boolean useVersioning;
-
- public static void useVersioning(final boolean useVersioning) {
- Defaults.useVersioning = useVersioning;
- }
-
- public static boolean useVersioning() {
- return useVersioning;
- }
-
- public static boolean useVersioning(final String shortIdentifier) {
- if (useVersioning() == false) {
- return false;
- }
- final String useVersioningProperty =
- getStringProperty(propertiesBase, isisConfiguration, "versioning." + shortIdentifier, "true");
- return (useVersioningProperty.compareToIgnoreCase("true") == 0);
- }
-
- // }}
-
- // {{ Database commands
-
- private static String START_TRANSACTION;
- private static String ABORT_TRANSACTION;
- private static String COMMIT_TRANSACTION;
-
- private static void defineDatabaseCommands() {
- START_TRANSACTION =
- getStringProperty(propertiesBase, isisConfiguration, "command.beginTransaction", "START TRANSACTION;");
- ABORT_TRANSACTION =
- getStringProperty(propertiesBase, isisConfiguration, "command.abortTransaction", "ROLLBACK;");
- COMMIT_TRANSACTION =
- getStringProperty(propertiesBase, isisConfiguration, "command.commitTransaction", "COMMIT;");
- }
-
- public static String START_TRANSACTION() {
- return START_TRANSACTION;
- }
-
- public static String ABORT_TRANSACTION() {
- return ABORT_TRANSACTION;
- }
-
- public static String COMMIT_TRANSACTION() {
- return COMMIT_TRANSACTION;
- }
- // }}
-
- /**
- * Based on the database engine, return a LIMIT start, count clause.
- *
- * @param startIndex
- * @param rowCount
- */
- public static String getLimitsClause(long startIndex, long rowCount) {
- return String.format("LIMIT %d, %d", startIndex, rowCount);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingFactoryInstaller.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingFactoryInstaller.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingFactoryInstaller.java
deleted file mode 100644
index 99a6158..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingFactoryInstaller.java
+++ /dev/null
@@ -1,24 +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.isis.objectstore.sql;
-
-public interface FieldMappingFactoryInstaller {
- void load(FieldMappingLookup lookup);
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingLookup.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingLookup.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingLookup.java
deleted file mode 100644
index 32ca76c..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/FieldMappingLookup.java
+++ /dev/null
@@ -1,131 +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.isis.objectstore.sql;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.jdbc.JdbcGeneralValueMapper;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-import org.apache.isis.objectstore.sql.mapping.FieldMappingFactory;
-import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
-import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMappingFactory;
-
-public class FieldMappingLookup {
- private static final Logger LOG = LoggerFactory.getLogger(FieldMappingLookup.class);
- private final Map<ObjectSpecification, FieldMappingFactory> fieldMappings = new HashMap<ObjectSpecification, FieldMappingFactory>();
- private final Map<ObjectSpecification, ObjectReferenceMappingFactory> referenceMappings = new HashMap<ObjectSpecification, ObjectReferenceMappingFactory>();
- private FieldMappingFactory referenceFieldMappingfactory;
- private ObjectReferenceMappingFactory objectReferenceMappingfactory;
-
- public FieldMapping createMapping(final ObjectSpecification object, final ObjectAssociation field) {
- final ObjectSpecification spec = field.getSpecification();
- FieldMappingFactory factory = fieldMappings.get(spec);
- if (factory != null) {
- return factory.createFieldMapping(object, field);
- } else if (spec.isEncodeable()) {
- factory = new JdbcGeneralValueMapper.Factory(Defaults.TYPE_DEFAULT());
- addFieldMappingFactory(spec, factory);
- return factory.createFieldMapping(object, field);
- } else {// if (true /* TODO test for reference */) {
- factory = referenceFieldMappingfactory;
- addFieldMappingFactory(spec, factory);
- return factory.createFieldMapping(object, field);
- // } else {
- // throw new IsisException("No mapper for " + spec +
- // " (no default mapper)");
- }
- }
-
- public ObjectReferenceMapping createMapping(final ObjectSpecification spec) {
- return createMapping(spec.getShortIdentifier(), spec);
- }
-
- public ObjectReferenceMapping createMapping(final String columnName, final ObjectSpecification spec) {
- ObjectReferenceMappingFactory factory = referenceMappings.get(spec);
- if (factory != null) {
- return factory.createReferenceMapping(columnName, spec);
- } else if (spec.isEncodeable()) {
- // TODO add generic encodeable mapping
- throw new NotYetImplementedException();
- } else {// if (true /* TODO test for reference */) {
- factory = objectReferenceMappingfactory;
- // add(spec, factory);
- return factory.createReferenceMapping(columnName, spec); // TODO:
- // here
- // } else {
- // throw new IsisException("No mapper for " + spec +
- // " (no default mapper)");
- }
- }
-
- public void addFieldMappingFactory(final Class<?> valueType, final FieldMappingFactory mapper) {
- final ObjectSpecification spec = IsisContext.getSpecificationLoader().loadSpecification(valueType);
- addFieldMappingFactory(spec, mapper);
- }
-
- private void addFieldMappingFactory(final ObjectSpecification specification, final FieldMappingFactory mapper) {
- LOG.debug("add mapper " + mapper + " for " + specification);
- fieldMappings.put(specification, mapper);
- }
-
- public void addReferenceMappingFactory(final ObjectSpecification specification, final ObjectReferenceMappingFactory mapper) {
- LOG.debug("add mapper " + mapper + " for " + specification);
- referenceMappings.put(specification, mapper);
- }
-
- public void init() {
- // fieldMappingFactory.load(this);
- }
-
- public IdMapping createIdMapping() {
- // TODO inject and use external factory
- final IdMapping idMapping = new IdMapping();
- idMapping.init();
- return idMapping;
- }
-
- public VersionMapping createVersionMapping() {
- // TODO inject and use external factory
- final VersionMapping versionMapping = new VersionMapping();
- versionMapping.init();
- return versionMapping;
- }
-
- public void setReferenceFieldMappingFactory(final FieldMappingFactory referenceMappingfactory) {
- this.referenceFieldMappingfactory = referenceMappingfactory;
- }
-
- public void setObjectReferenceMappingfactory(final ObjectReferenceMappingFactory objectReferenceMappingfactory) {
- this.objectReferenceMappingfactory = objectReferenceMappingfactory;
- }
-
- public TitleMapping createTitleMapping() {
- // TODO inject and use external factory
- return new TitleMapping();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMapping.java
deleted file mode 100644
index 544da36..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMapping.java
+++ /dev/null
@@ -1,40 +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.isis.objectstore.sql;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-
-public class IdMapping extends IdMappingAbstract {
-
- public void init() {
- String idColumn = null;
- // idColumn = configParameters.getString(parameterBase + "id");
- if (idColumn == null) {
- idColumn = Defaults.getPkIdLabel();
- }
- setColumn(idColumn);
- }
-
- public void appendUpdateValues(final StringBuffer sql, final ObjectAdapter object) {
- }
-
- public void initializeField(final ObjectAdapter object, final Results rs) {
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMappingAbstract.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMappingAbstract.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMappingAbstract.java
deleted file mode 100644
index 8d6a2a4..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/IdMappingAbstract.java
+++ /dev/null
@@ -1,112 +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.isis.objectstore.sql;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
-import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-
-public class IdMappingAbstract {
- private String column;
-
- protected void setColumn(final String column) {
- this.column = Sql.identifier(column);
- }
-
- protected String getColumn() {
- return column;
- }
-
- public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final RootOid oid) {
- sql.append(column);
- sql.append(" = ");
- appendObjectId(connector, sql, oid);
- }
-
- public void appendObjectId(final DatabaseConnector connector, final StringBuffer sql, final RootOid oid) {
- sql.append("?");
- connector.addToQueryValues(primaryKey(oid));
- }
-
- public void appendCreateColumnDefinitions(final StringBuffer sql) {
- sql.append(column);
- sql.append(" ");
- sql.append(Defaults.TYPE_PK() + " NOT NULL PRIMARY KEY");
- }
-
- public void appendColumnDefinitions(final StringBuffer sql) {
- sql.append(column);
- sql.append(" ");
- sql.append(Defaults.TYPE_PK());
- }
-
- public void appendColumnNames(final StringBuffer sql) {
- sql.append(column);
- }
-
- public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- if (object == null) {
- sql.append("NULL");
- } else {
- appendObjectId(connector, sql, (RootOid) object.getOid());
- // sql.append(connector.addToQueryValues(primaryKeyAsObject(object.getOid())));
- }
- }
-
- public String primaryKey(final RootOid oid) {
- return oid.getIdentifier();
- }
-
- public TypedOid recreateOid(final Results rs, final ObjectSpecification specification) {
- final Object object = rs.getObject(column);
- if (object == null) {
- return null;
- }
- final int id = ((Integer) object).intValue();
- return new RootOidDefault(specification.getSpecId(), "" + id, Oid.State.PERSISTENT);
- }
-
- protected ObjectAdapter getAdapter(final ObjectSpecification spec, final Oid oid) {
- final ObjectAdapter adapter = getAdapterManager().getAdapterFor(oid);
- if (adapter != null) {
- return adapter;
- }
- // REVIEW: where the oid is a TypedOid, the following two lines could be replaced by
- // getPersistenceSession().recreatePersistentAdapter(oid)
- // is preferable, since then reuses the PojoRecreator impl defined within SqlPersistorInstaller
- final Object recreatedPojo = spec.createObject();
- return getPersistenceSession().mapRecreatedPojo(oid, recreatedPojo);
- }
-
- protected AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-
- protected PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MappingLookup.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MappingLookup.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MappingLookup.java
deleted file mode 100644
index 92a0af2..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MappingLookup.java
+++ /dev/null
@@ -1,26 +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.isis.objectstore.sql;
-
-public class MappingLookup {
- // private ObjectMappingLookup classMappingLookup;
- // private FieldMappingLookup fieldMappingLookup;
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MultipleResults.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MultipleResults.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MultipleResults.java
deleted file mode 100644
index 35dafe4..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/MultipleResults.java
+++ /dev/null
@@ -1,24 +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.isis.objectstore.sql;
-
-public interface MultipleResults {
- Results nextResults();
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMapping.java
deleted file mode 100644
index 64034e5..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMapping.java
+++ /dev/null
@@ -1,57 +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.isis.objectstore.sql;
-
-import java.util.Vector;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByPattern;
-
-public interface ObjectMapping {
- void createObject(DatabaseConnector connector, ObjectAdapter object);
-
- void destroyObject(DatabaseConnector connector, ObjectAdapter object);
-
- Vector<ObjectAdapter> getInstances(DatabaseConnector connector, ObjectSpecification spec, long startIndex, long rowCount);
-
- Vector<ObjectAdapter> getInstances(DatabaseConnector connector, ObjectSpecification spec, String title, long startIndex, long rowCount);
-
- Vector<ObjectAdapter> getInstances(DatabaseConnector connector, ObjectSpecification spec, PersistenceQueryFindByPattern query);
-
- ObjectAdapter getObject(DatabaseConnector connector, TypedOid typedOid);
-
- boolean hasInstances(DatabaseConnector connector, ObjectSpecification cls);
-
- void resolve(DatabaseConnector connector, ObjectAdapter object);
-
- void resolveCollection(DatabaseConnector connector, ObjectAdapter object, ObjectAssociation field);
-
- void save(DatabaseConnector connector, ObjectAdapter object);
-
- void shutdown();
-
- void startup(DatabaseConnector connection, ObjectMappingLookup objectMapperLookup);
-
- boolean saveCollection(DatabaseConnector connection, ObjectAdapter parent, String fieldName);
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingFactory.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingFactory.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingFactory.java
deleted file mode 100644
index 0a5976b..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingFactory.java
+++ /dev/null
@@ -1,24 +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.isis.objectstore.sql;
-
-public interface ObjectMappingFactory {
- ObjectMapping createMapper(String className, String propertiesBase, FieldMappingLookup fieldMapperLookup, ObjectMappingLookup objectMapperLookup);
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingLookup.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingLookup.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingLookup.java
deleted file mode 100644
index 3535b5f..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/ObjectMappingLookup.java
+++ /dev/null
@@ -1,153 +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.isis.objectstore.sql;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.commons.debug.DebuggableWithTitle;
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.commons.factory.InstanceCreationException;
-import org.apache.isis.core.commons.factory.InstanceUtil;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.Contributed;
-import org.apache.isis.core.runtime.persistence.ObjectPersistenceException;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-
-public class ObjectMappingLookup implements DebuggableWithTitle {
- private static final Logger LOG = LoggerFactory.getLogger(ObjectMappingLookup.class);
- private DatabaseConnectorPool connectionPool;
- private final Map<ObjectSpecification, ObjectMapping> mappings = new HashMap<ObjectSpecification, ObjectMapping>();
- private ObjectMappingFactory objectMappingFactory;
- private FieldMappingLookup fieldMappingLookup;
-
- public ObjectMapping getMapping(final ObjectSpecification spec, final DatabaseConnector connection) {
- String fullName = spec.getFullIdentifier();
- ObjectMapping mapping = mappings.get(spec);
- if (mapping == null) {
- final String propertiesBase = SqlObjectStore.BASE_NAME + ".automapper.default";
- mapping = objectMappingFactory.createMapper(fullName, propertiesBase, fieldMappingLookup, this);
- add(spec, mapping, connection);
- }
- LOG.debug(" mapper for " + spec.getSingularName() + " -> " + mapping);
- if (mapping == null) {
- throw new IsisException("No mapper for " + spec + " (no default mapper)");
- }
- return mapping;
- }
-
- public ObjectMapping getMapping(final ObjectAdapter object, final DatabaseConnector connection) {
- return getMapping(object.getSpecification(), connection);
- }
-
- public void setConnectionPool(final DatabaseConnectorPool connectionPool) {
- this.connectionPool = connectionPool;
- }
-
- // / ???
- public void setObjectMappingFactory(final ObjectMappingFactory mapperFactory) {
- this.objectMappingFactory = mapperFactory;
- }
-
- public void setValueMappingLookup(final FieldMappingLookup fieldMappingLookup) {
- this.fieldMappingLookup = fieldMappingLookup;
- }
-
- private void add(final String className, final ObjectMapping mapper) {
- final ObjectSpecification spec = IsisContext.getSpecificationLoader().loadSpecification(className);
- if (spec.getProperties(Contributed.EXCLUDED).size() == 0) {
- throw new SqlObjectStoreException(spec.getFullIdentifier() + " has no fields to persist: " + spec);
- }
- add(spec, mapper, null);
- }
-
- public void add(final ObjectSpecification specification, final ObjectMapping mapper, DatabaseConnector connection) {
- LOG.debug("add mapper " + mapper + " for " + specification);
- if (connection == null) {
- connection = connectionPool.acquire();
- }
- mapper.startup(connection, this);
- connectionPool.release(connection);
- mappings.put(specification, mapper);
- }
-
- public void init() {
- fieldMappingLookup.init();
-
- final String prefix = SqlObjectStore.BASE_NAME + ".mapper.";
- final IsisConfiguration subset = IsisContext.getConfiguration().createSubset(prefix);
- for (final String className : subset) {
- final String value = subset.getString(className);
-
- if (value.startsWith("auto.")) {
- final String propertiesBase = SqlObjectStore.BASE_NAME + ".automapper." + value.substring(5) + ".";
- add(className, objectMappingFactory.createMapper(className, propertiesBase, fieldMappingLookup, this));
- } else if (value.trim().equals("auto")) {
- final String propertiesBase = SqlObjectStore.BASE_NAME + ".automapper.default";
- add(className, objectMappingFactory.createMapper(className, propertiesBase, fieldMappingLookup, this));
- } else {
- LOG.debug("mapper " + className + "=" + value);
-
- try {
- add(className, InstanceUtil.createInstance(value, ObjectMapping.class));
- } catch (final ObjectPersistenceException ex) {
- throw new InstanceCreationException("Failed to set up mapper for " + className, ex);
- }
- }
- }
- }
-
- public void shutdown() {
- for (final ObjectMapping mapping : mappings.values()) {
- try {
- mapping.shutdown();
- } catch (final ObjectPersistenceException ex) {
- LOG.error("Shutdown mapper " + mapping, ex);
- }
- }
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln("field mapping lookup", fieldMappingLookup);
- debug.appendln("object mapping factory", objectMappingFactory);
- debug.appendTitle("Mappings");
- int i = 1;
- for (final ObjectSpecification specification : mappings.keySet()) {
- debug.appendln(i++ + ". " + specification.getShortIdentifier());
- final ObjectMapping mapper = mappings.get(specification);
- debug.indent();
- debug.append(mapper);
- debug.unindent();
- }
- }
-
- @Override
- public String debugTitle() {
- return "Object Mapping Lookup";
- }
-
-}
[03/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcMoneyValueMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcMoneyValueMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcMoneyValueMapper.java
new file mode 100755
index 0000000..1821795
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcMoneyValueMapper.java
@@ -0,0 +1,81 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.applib.PersistFailedException;
+import org.apache.isis.applib.value.Money;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+import org.apache.isis.objectstore.sql.mapping.FieldMappingFactory;
+
+/**
+ * Money needs to implement a two-column persistence, 1 for amount, 1 for
+ * 3-digit currency
+ *
+ * @version $Rev$ $Date$
+ */
+public class JdbcMoneyValueMapper extends AbstractJdbcMultiFieldMapping {
+
+ public static class Factory implements FieldMappingFactory {
+ private final String type1;
+ private final String type2;
+
+ public Factory(final String type1, final String type2) {
+ this.type1 = type1;
+ this.type2 = type2;
+ }
+
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ return new JdbcMoneyValueMapper(field, type1, type2);
+ }
+ }
+
+ public JdbcMoneyValueMapper(final ObjectAssociation field, final String type1, final String type2) {
+ super(field, 2, type1, type2);
+ }
+
+ @Override
+ protected Object preparedStatementObject(final int index, final Object o) {
+
+ if (o instanceof Money) {
+ if (index == 0) {
+ return ((Money) o).doubleValue();
+ } else {
+ return ((Money) o).getCurrency();
+ }
+ } else {
+ throw new PersistFailedException("Invalid object type " + o.getClass().getCanonicalName() + " for MoneyValueMapper");
+ }
+ }
+
+ @Override
+ protected Object getObjectFromResults(final Results results) {
+ final double doubleValue = results.getDouble(columnName(0));
+ final String currencyValue = results.getString(columnName(1));
+
+ final Money moneyObject = new Money(doubleValue, currencyValue);
+
+ return moneyObject;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceFieldMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceFieldMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceFieldMapping.java
new file mode 100644
index 0000000..db826c4
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceFieldMapping.java
@@ -0,0 +1,101 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+public class JdbcObjectReferenceFieldMapping extends JdbcObjectReferenceMapping implements FieldMapping {
+
+ public static class Factory extends AbstractFieldMappingFactory {
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ if (field.getSpecification().isAbstract()) {
+ final String dataType = getTypeOverride(object, field, Defaults.TYPE_LONG_STRING());
+ return new JdbcAbstractReferenceFieldMapping(field, dataType);
+ }
+ return new JdbcObjectReferenceFieldMapping(field);
+ }
+ }
+
+ protected final ObjectAssociation field;
+
+ @Override
+ public ObjectAssociation getField() {
+ return field;
+ }
+
+ @Override
+ public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ final ObjectAdapter fieldValue = field.get(object);
+ final RootOid oid = (RootOid) fieldValue.getOid();
+ appendWhereClause(connector, sql, oid);
+ }
+
+ @Override
+ public void appendWhereObject(final DatabaseConnector connector, final ObjectAdapter objectAdapter) {
+ final ObjectAdapter fieldValue = field.get(objectAdapter);
+ final RootOid oid = (RootOid) fieldValue.getOid();
+ connector.addToQueryValues(primaryKey(oid));
+ }
+
+ public JdbcObjectReferenceFieldMapping(final ObjectAssociation field) {
+ super(columnName(field), field.getSpecification());
+ this.field = field;
+ }
+
+ private static String columnName(final ObjectAssociation field) {
+ return Sql.sqlFieldName(field.getId());
+ }
+
+ @Override
+ public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sb, final ObjectAdapter object) {
+ final ObjectAdapter fieldValue = field.get(object);
+ super.appendInsertValues(connector, sb, fieldValue);
+ }
+
+ @Override
+ public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
+ final ObjectAdapter fieldValue = field.get(object);
+ super.appendUpdateValues(connector, sql, fieldValue);
+ }
+
+ @Override
+ public void initializeField(final ObjectAdapter object, final Results rs) {
+ final ObjectAdapter reference = initializeField(rs);
+ ((OneToOneAssociation) field).initAssociation(object, reference);
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ debug.appendln(field.getId(), getColumn());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMapping.java
new file mode 100644
index 0000000..95a02b5
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMapping.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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.IdMappingAbstract;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.SqlObjectStoreException;
+import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
+
+public class JdbcObjectReferenceMapping extends IdMappingAbstract implements ObjectReferenceMapping {
+ private final ObjectSpecification specification;
+
+ public JdbcObjectReferenceMapping(final String columnName, final ObjectSpecification specification) {
+ this.specification = specification;
+ final String idColumn = Sql.sqlName("fk_" + columnName);
+ setColumn(idColumn);
+ }
+
+ @Override
+ public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter adapter) {
+ sql.append(getColumn());
+ if (adapter == null) {
+ sql.append("= NULL ");
+ } else {
+ sql.append("= ?");
+ // sql.append(primaryKey(object.getOid()));
+ final RootOid oid = (RootOid) adapter.getOid();
+ connector.addToQueryValues(primaryKey(oid));
+ }
+ }
+
+ public ObjectAdapter initializeField(final Results rs) {
+ final Oid oid = recreateOid(rs, specification);
+ if (oid != null) {
+ if (specification.isAbstract()) {
+ throw new SqlObjectStoreException("NOT DEALING WITH POLYMORPHIC ASSOCIATIONS");
+ } else {
+ return getAdapter(specification, oid);
+ }
+ } else {
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMappingFactory.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMappingFactory.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMappingFactory.java
new file mode 100644
index 0000000..e2e1d23
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMappingFactory.java
@@ -0,0 +1,33 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
+import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMappingFactory;
+
+public class JdbcObjectReferenceMappingFactory implements ObjectReferenceMappingFactory {
+
+ @Override
+ public ObjectReferenceMapping createReferenceMapping(final String columnName, final ObjectSpecification specification) {
+ return new JdbcObjectReferenceMapping(columnName, specification);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPasswordValueMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPasswordValueMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPasswordValueMapper.java
new file mode 100644
index 0000000..0c2bd4e
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPasswordValueMapper.java
@@ -0,0 +1,106 @@
+/**
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.applib.value.Password;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.jdbc.helpers.SimplePasswordEncoderDecoder;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+/**
+ * Implements a Password string type that stores the passwords with a simple encoding in the database.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JdbcPasswordValueMapper extends AbstractJdbcFieldMapping {
+
+ public static class Factory extends AbstractFieldMappingFactory {
+ private final String type;
+ private final String passwordSeed;
+ private final Integer encLength;
+
+ public Factory(final String type, final String passwordSeed, final Integer encLength) {
+ super();
+ this.type = type;
+ this.passwordSeed = passwordSeed;
+ this.encLength = encLength;
+ }
+
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ final String dataType = getTypeOverride(object, field, type);
+ return new JdbcPasswordValueMapper(field, dataType, passwordSeed, encLength);
+ }
+ }
+
+ private final String type;
+
+ private final SimplePasswordEncoderDecoder simplePasswordEncoderDecoder;
+
+ public JdbcPasswordValueMapper(final ObjectAssociation field, final String type, final String passwordSeed,
+ final Integer encLength) {
+ super(field);
+ this.type = type;
+
+ simplePasswordEncoderDecoder = new SimplePasswordEncoderDecoder(passwordSeed, encLength);
+ }
+
+ /*
+ * @see org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping#columnType()
+ */
+ @Override
+ protected String columnType() {
+ return type;
+ }
+
+ /*
+ * @see
+ * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping#preparedStatementObject(org.apache
+ * .isis.core.metamodel.adapter.ObjectAdapter)
+ */
+ @Override
+ protected Object preparedStatementObject(ObjectAdapter value) {
+ if (value == null) {
+ return null;
+ }
+ final Object o = value.getObject();
+ final String rawPassword = ((Password) o).getPassword();
+ return simplePasswordEncoderDecoder.encodeRawValueIntoEncodedString(rawPassword);
+ }
+
+ /*
+ * @see
+ * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping#setFromDBColumn(org.apache.isis.
+ * runtimes.dflt.objectstores.sql.Results, java.lang.String,
+ * org.apache.isis.core.metamodel.spec.feature.ObjectAssociation)
+ */
+ @Override
+ protected ObjectAdapter setFromDBColumn(Results results, String columnName, ObjectAssociation field) {
+ final String encodedValue = results.getString(columnName);
+ if (encodedValue == null) {
+ return null;
+ }
+ final EncodableFacet facet = field.getSpecification().getFacet(EncodableFacet.class);
+ return facet.fromEncodedString(simplePasswordEncoderDecoder.decodeEncodedValueIntoRawString(encodedValue));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java
new file mode 100755
index 0000000..cf6c419
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java
@@ -0,0 +1,71 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.IdMappingAbstract;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.Sql;
+import org.apache.isis.objectstore.sql.SqlObjectStoreException;
+import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
+
+public class JdbcPolymorphicObjectReferenceMapping extends IdMappingAbstract implements ObjectReferenceMapping {
+ private ObjectSpecification specification;
+
+ public JdbcPolymorphicObjectReferenceMapping(final String columnName) {
+ final String idColumn = Sql.sqlName(columnName);
+ setColumn(idColumn);
+ }
+
+ public void setObjectSpecification(final ObjectSpecification specification) {
+ this.specification = specification;
+ }
+
+ @Override
+ public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter adapter) {
+ sql.append(getColumn());
+ if (adapter == null) {
+ sql.append("= NULL ");
+ } else {
+ sql.append("= ?");
+ // sql.append(primaryKey(object.getOid()));
+ final RootOid oid = (RootOid) adapter.getOid();
+ connector.addToQueryValues(primaryKey(oid));
+ }
+ }
+
+ public ObjectAdapter initializeField(final Results rs) {
+ final Oid oid = recreateOid(rs, specification);
+ if (oid != null) {
+ if (specification.isAbstract()) {
+ throw new SqlObjectStoreException("NOT DEALING WITH POLYMORPHIC ASSOCIATIONS");
+ } else {
+ return getAdapter(specification, oid);
+ }
+ } else {
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcResults.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcResults.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcResults.java
new file mode 100644
index 0000000..8fb81a8
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcResults.java
@@ -0,0 +1,232 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import java.io.InputStream;
+import java.sql.CallableStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Calendar;
+import java.util.HashMap;
+
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import org.apache.isis.applib.value.Date;
+import org.apache.isis.applib.value.Time;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.SqlObjectStoreException;
+
+public class JdbcResults implements Results {
+ ResultSet set;
+
+ public JdbcResults(final CallableStatement statement) {
+ }
+
+ public JdbcResults(final ResultSet set) {
+ this.set = set;
+ }
+
+ @Override
+ public void close() {
+ try {
+ set.close();
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public int getInt(final String columnName) {
+ try {
+ return set.getInt(columnName);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public long getLong(final String columnName) {
+ try {
+ return set.getLong(columnName);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public String getString(final String columnName) {
+ try {
+ return set.getString(columnName);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public boolean next() {
+ try {
+ return set.next();
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public java.sql.Date getJavaDateOnly(final String columnName) {
+ try {
+ // 2010-03-05 = 1267747200000
+ // 2010-04-08 = 1270684800000
+ // This is really painful! Java refuses to create java.util.Date in
+ // UTC!
+ // It creates java.util.Dates in Local time-zone, but assumes the DB
+ // date is UTC.
+ final String string = set.getString(columnName);
+ final DateTime utcDate = new DateTime(string, Defaults.getTimeZone());
+ final java.sql.Date date = new java.sql.Date(utcDate.getMillis());
+ return date;
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public java.sql.Time getJavaTimeOnly(final String columnName) {
+ try {
+ final String string = set.getString(columnName);
+
+ final DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss");
+
+ final DateTime utcDate = formatter.withZone(Defaults.getTimeZone()).parseDateTime(string);
+ final java.sql.Time time = new java.sql.Time(utcDate.getMillis());
+
+ return time;
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public java.util.Date getJavaDateTime(final String columnName, final Calendar calendar) {
+ try {
+ return set.getDate(columnName, calendar);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public Object getObject(final String columnName) {
+ try {
+ return set.getObject(columnName);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public Date getDate(final String columnName) {
+ try {
+ // 2010-03-05 = 1267747200000
+ // 2010-04-08 = 1270684800000
+ // This is really painful! Java refuses to create java.util.Date in
+ // UTC!
+ // It creates java.util.Dates in Local time-zone, but assumes the DB
+ // date is UTC.
+ final String string = set.getString(columnName);
+ final DateTime utcDate = new DateTime(string, Defaults.getTimeZone());
+ return new Date(utcDate);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public Time getTime(final String columnName) {
+ try {
+ final String string = set.getString(columnName);
+ final DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss");
+ final DateTimeZone defaultTimeZone = Defaults.getTimeZone();
+ final DateTime utcDate = formatter.withZone(defaultTimeZone).parseDateTime(string);
+ return new Time(utcDate);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public double getDouble(final String columnName) {
+ try {
+ return set.getDouble(columnName);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public Object getAsType(final String columnName, final Class<?> clazz) {
+ try {
+ final HashMap<String, Class<?>> map = new HashMap<String, Class<?>>();
+ map.put("FLOAT", float.class);
+ return set.getObject(columnName, map);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public Float getFloat(final String columnName) {
+ try {
+ return set.getFloat(columnName);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public Short getShort(final String columnName) {
+ try {
+ return set.getShort(columnName);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public Boolean getBoolean(final String columnName) {
+ try {
+ return set.getBoolean(columnName);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+
+ @Override
+ public InputStream getStream(String column) {
+ try {
+ return set.getBinaryStream(column);
+ } catch (final SQLException e) {
+ throw new SqlObjectStoreException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcSqlMetaData.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcSqlMetaData.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcSqlMetaData.java
new file mode 100644
index 0000000..0efd9fe
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcSqlMetaData.java
@@ -0,0 +1,86 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+
+import org.apache.isis.objectstore.sql.SqlMetaData;
+
+public class JdbcSqlMetaData implements SqlMetaData {
+
+ private final boolean hasQuoteString;
+ private final String quoteString;
+ private final String keywords;
+ private final String timeDateFunctions;
+ private final boolean storesLowerCaseIdentifiers;
+ private final boolean storesMixedCaseIdentifiers;
+ private final boolean storesUpperCaseIdentifiers;
+
+ public JdbcSqlMetaData(final DatabaseMetaData metaData) throws SQLException {
+ keywords = metaData.getSQLKeywords();
+ timeDateFunctions = metaData.getTimeDateFunctions();
+ quoteString = metaData.getIdentifierQuoteString();
+ hasQuoteString = (quoteString != " ");
+ storesLowerCaseIdentifiers = metaData.storesLowerCaseIdentifiers();
+ storesMixedCaseIdentifiers = metaData.storesMixedCaseIdentifiers();
+ storesUpperCaseIdentifiers = metaData.storesUpperCaseIdentifiers();
+
+ }
+
+ @Override
+ public String getKeywords() {
+ return keywords;
+ }
+
+ @Override
+ public String getTimeDateFunctions() {
+ return timeDateFunctions;
+ }
+
+ @Override
+ public String getQuoteString() {
+ return quoteString;
+ }
+
+ @Override
+ public boolean isStoresLowerCaseIdentifiers() {
+ return storesLowerCaseIdentifiers;
+ }
+
+ @Override
+ public boolean isStoresMixedCaseIdentifiers() {
+ return storesMixedCaseIdentifiers;
+ }
+
+ @Override
+ public boolean isStoresUpperCaseIdentifiers() {
+ return storesUpperCaseIdentifiers;
+ }
+
+ @Override
+ public String quoteIdentifier(final String identifier) {
+ if (hasQuoteString) {
+ return quoteString + identifier + quoteString;
+ } else {
+ return identifier;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimeMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimeMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimeMapper.java
new file mode 100644
index 0000000..3b76abc
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimeMapper.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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.applib.PersistFailedException;
+import org.apache.isis.applib.value.Time;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+public class JdbcTimeMapper extends AbstractJdbcFieldMapping {
+
+ private final String dataType;
+
+ public static class Factory extends AbstractFieldMappingFactory {
+
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ final String dataType = getTypeOverride(object, field, Defaults.TYPE_TIME());
+ return new JdbcTimeMapper(field, dataType);
+ }
+ }
+
+ protected JdbcTimeMapper(final ObjectAssociation field, final String dataType) {
+ super(field);
+ this.dataType = dataType;
+ }
+
+ @Override
+ protected Object preparedStatementObject(final ObjectAdapter value) {
+ final Time asTime = (Time) value.getObject();
+ return asTime.asJavaTime();
+ }
+
+ @Override
+ public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
+ /*
+ * Long hour = Long.decode(encodedValue.substring(0, 2)); Long minute =
+ * Long.decode(encodedValue.substring(3, 5)); Long millis = (minute +
+ * hour * 60) * 60 * 1000; String valueString = "T" +
+ * Long.toString(millis); return
+ * field.getSpecification().getFacet(EncodableFacet.class)
+ * .fromEncodedString(valueString);
+ */
+ ObjectAdapter restoredValue;
+ final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
+ if (correspondingClass == Time.class) {
+ final Time timeValue = results.getTime(columnName);
+ restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(timeValue);
+ } else {
+ throw new PersistFailedException("Unhandled time type: " + correspondingClass.getCanonicalName());
+ }
+ return restoredValue;
+
+ }
+
+ @Override
+ public String columnType() {
+ return dataType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimestampMapper.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimestampMapper.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimestampMapper.java
new file mode 100644
index 0000000..73e6906
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcTimestampMapper.java
@@ -0,0 +1,78 @@
+/*
+ * 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.isis.objectstore.sql.jdbc;
+
+import org.apache.isis.applib.PersistFailedException;
+import org.apache.isis.applib.value.TimeStamp;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.Results;
+import org.apache.isis.objectstore.sql.mapping.FieldMapping;
+
+public class JdbcTimestampMapper extends AbstractJdbcFieldMapping {
+
+ private final String dataType;
+
+ public static class Factory extends AbstractFieldMappingFactory {
+
+ @Override
+ public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
+ final String dataType = getTypeOverride(object, field, Defaults.TYPE_TIMESTAMP());
+ return new JdbcTimestampMapper(field, dataType);
+ }
+ }
+
+ protected JdbcTimestampMapper(final ObjectAssociation field, final String dataType) {
+ super(field);
+ this.dataType = dataType;
+ }
+
+ @Override
+ protected Object preparedStatementObject(final ObjectAdapter value) {
+ final TimeStamp asDate = (TimeStamp) value.getObject();
+ final java.sql.Timestamp timeStamp = new java.sql.Timestamp(asDate.longValue());
+ return timeStamp;
+ }
+
+ @Override
+ public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
+
+ ObjectAdapter restoredValue;
+ final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
+ if (correspondingClass == TimeStamp.class) {
+ final java.sql.Timestamp o = (java.sql.Timestamp) results.getObject(columnName);
+ final TimeStamp timeValue = new TimeStamp(o.getTime());
+ restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(timeValue);
+ } else {
+ throw new PersistFailedException("Unhandled time type: " + correspondingClass.getCanonicalName());
+ }
+ return restoredValue;
+ }
+
+ @Override
+ public String columnType() {
+ return dataType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoder.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoder.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoder.java
new file mode 100644
index 0000000..8f6c797
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoder.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.isis.objectstore.sql.jdbc.helpers;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class SimplePasswordEncoderDecoder {
+ private final String passwordSeed;
+ private final int seedLength;
+ private final Integer valueOfZero = Integer.valueOf('0');
+ private final int dbLength;
+
+ public SimplePasswordEncoderDecoder(String passwordSeed, Integer encLength) {
+ this.passwordSeed = passwordSeed;
+ if (passwordSeed == null) {
+ seedLength = 0;
+ } else {
+ seedLength = passwordSeed.length();
+ }
+ dbLength = encLength;
+ }
+
+ /**
+ * Use a simple algorithm to encode the given value into an encoded String
+ *
+ * @param String
+ * raw value
+ * @return encoded String
+ */
+ public final String encodeRawValueIntoEncodedString(final String value) {
+ if (passwordSeed == null) {
+ return value;
+ }
+ final int rawLength = value.length();
+ String length = Integer.toHexString(rawLength);
+ if (length.length() == 1) {
+ length = "0" + length;
+ }
+ String encodePart1 = length + value;
+ String encoded = "";
+ for (int i = 0; i < rawLength + 2; i++) {
+ int thisSeed = passwordSeed.charAt(i % seedLength);
+ int thisPassword = encodePart1.charAt(i);
+ int nextValue = (thisSeed + thisPassword) % 255;
+ encoded = encoded.concat(String.format("%2h", nextValue));
+
+ }
+ for (int i = rawLength; i < (dbLength / 2) - 2; i++) {
+ int thisSeed = passwordSeed.charAt(i % seedLength);
+ int thisPassword = passwordSeed.charAt((i - 2) % seedLength);
+ int nextValue = (thisSeed + thisPassword + i) % 255;
+ encoded = encoded.concat(String.format("%2h", nextValue));
+ }
+
+ return encoded;
+ }
+
+ /**
+ * Use a simple algorithm to decode the given encoded String into a raw String
+ *
+ * @param String
+ * encoded value
+ * @return decoded raw String
+ */
+ public final String decodeEncodedValueIntoRawString(final String encodedValue) {
+ if (passwordSeed == null) {
+ return encodedValue;
+ }
+ int passwordLength = extractIndexedValueAsInt(encodedValue, 0);
+
+ String decodedValue = "";
+ for (int i = 0; i < passwordLength; i++) {
+ char extracted = extractIndexedValueAsChar(encodedValue, i + 2);
+ decodedValue = decodedValue + (extracted);
+ }
+ return decodedValue;
+ }
+
+ private int extractIndexedValueAsInt(final String encodedValue, int index) {
+ int value1 = decodeIndexedValue(encodedValue, index) - valueOfZero;
+ int value2 = decodeIndexedValue(encodedValue, index + 1) - valueOfZero;
+ return value1 * 16 + value2;
+ }
+
+ private char extractIndexedValueAsChar(final String encodedValue, int index) {
+ int value1 = decodeIndexedValue(encodedValue, index);
+ return (char) value1;
+ }
+
+ private int decodeIndexedValue(final String encodedValue, int index) {
+ String s = encodedValue.substring((index) * 2, (index) * 2 + 2);
+ int hex = Integer.valueOf(s, 16);
+ int thisSeed = passwordSeed.charAt(index % seedLength);
+ int passwordValue = hex - thisSeed;
+ return passwordValue;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java
new file mode 100644
index 0000000..62391bf
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java
@@ -0,0 +1,93 @@
+/*
+ * 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.isis.objectstore.sql.jdbc.installer;
+
+import org.apache.isis.applib.value.Color;
+import org.apache.isis.applib.value.Date;
+import org.apache.isis.applib.value.DateTime;
+import org.apache.isis.applib.value.Image;
+import org.apache.isis.applib.value.Money;
+import org.apache.isis.applib.value.Password;
+import org.apache.isis.applib.value.Percentage;
+import org.apache.isis.applib.value.Time;
+import org.apache.isis.applib.value.TimeStamp;
+import org.apache.isis.objectstore.sql.Defaults;
+import org.apache.isis.objectstore.sql.FieldMappingFactoryInstaller;
+import org.apache.isis.objectstore.sql.FieldMappingLookup;
+import org.apache.isis.objectstore.sql.jdbc.JdbcBinaryValueMapper;
+import org.apache.isis.objectstore.sql.jdbc.JdbcColorValueMapper;
+import org.apache.isis.objectstore.sql.jdbc.JdbcDateMapper;
+import org.apache.isis.objectstore.sql.jdbc.JdbcDateTimeMapper;
+import org.apache.isis.objectstore.sql.jdbc.JdbcGeneralValueMapper;
+import org.apache.isis.objectstore.sql.jdbc.JdbcImageValueMapper;
+import org.apache.isis.objectstore.sql.jdbc.JdbcMoneyValueMapper;
+import org.apache.isis.objectstore.sql.jdbc.JdbcObjectReferenceFieldMapping;
+import org.apache.isis.objectstore.sql.jdbc.JdbcObjectReferenceMappingFactory;
+import org.apache.isis.objectstore.sql.jdbc.JdbcPasswordValueMapper;
+import org.apache.isis.objectstore.sql.jdbc.JdbcTimeMapper;
+import org.apache.isis.objectstore.sql.jdbc.JdbcTimestampMapper;
+
+public class JdbcFieldMappingFactoryInstaller implements FieldMappingFactoryInstaller {
+
+ @Override
+ public void load(final FieldMappingLookup lookup) {
+
+ lookup.addFieldMappingFactory(Image.class,
+ new JdbcImageValueMapper.Factory(Defaults.TYPE_STRING(), Defaults.TYPE_BLOB()));
+
+ lookup.addFieldMappingFactory(Boolean.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_BOOLEAN()));
+ lookup.addFieldMappingFactory(Short.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_SHORT()));
+ lookup.addFieldMappingFactory(Integer.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_INT()));
+ lookup.addFieldMappingFactory(Long.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_LONG()));
+ lookup.addFieldMappingFactory(Float.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_FLOAT()));
+ lookup.addFieldMappingFactory(Double.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_DOUBLE()));
+ lookup.addFieldMappingFactory(char.class, new JdbcGeneralValueMapper.Factory("CHAR(2)"));
+
+ lookup.addFieldMappingFactory(Money.class, new JdbcMoneyValueMapper.Factory("FLOAT", "VARCHAR(3)"));
+ lookup.addFieldMappingFactory(Percentage.class, new JdbcGeneralValueMapper.Factory("FLOAT"));
+ lookup.addFieldMappingFactory(Password.class, new JdbcPasswordValueMapper.Factory(Defaults.TYPE_PASSWORD(),
+ Defaults.PASSWORD_SEED(), Defaults.PASSWORD_ENC_LENGTH()));
+ lookup.addFieldMappingFactory(Color.class, new JdbcColorValueMapper.Factory(Defaults.TYPE_LONG()));
+ lookup.addFieldMappingFactory(String.class, new JdbcGeneralValueMapper.Factory(Defaults.TYPE_STRING()));
+
+ lookup.addFieldMappingFactory(Date.class, new JdbcDateMapper.Factory());
+ lookup.addFieldMappingFactory(Time.class, new JdbcTimeMapper.Factory());
+ lookup.addFieldMappingFactory(DateTime.class, new JdbcDateTimeMapper.Factory());
+ lookup.addFieldMappingFactory(TimeStamp.class, new JdbcTimestampMapper.Factory());
+
+ lookup.addFieldMappingFactory(java.sql.Date.class, new JdbcDateMapper.Factory());
+ lookup.addFieldMappingFactory(java.sql.Time.class, new JdbcTimeMapper.Factory());
+ lookup.addFieldMappingFactory(java.util.Date.class, new JdbcDateTimeMapper.Factory());
+ lookup.addFieldMappingFactory(java.sql.Timestamp.class, new JdbcTimestampMapper.Factory());
+
+ lookup.addFieldMappingFactory(boolean.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_BOOLEAN()));
+ lookup.addFieldMappingFactory(short.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_SHORT()));
+ lookup.addFieldMappingFactory(int.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_INT()));
+ lookup.addFieldMappingFactory(long.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_LONG()));
+ lookup.addFieldMappingFactory(float.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_FLOAT()));
+ lookup.addFieldMappingFactory(double.class, new JdbcBinaryValueMapper.Factory(Defaults.TYPE_DOUBLE()));
+
+ lookup.setReferenceFieldMappingFactory(new JdbcObjectReferenceFieldMapping.Factory());
+
+ lookup.setObjectReferenceMappingfactory(new JdbcObjectReferenceMappingFactory());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMapping.java
new file mode 100644
index 0000000..0cc664e
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMapping.java
@@ -0,0 +1,48 @@
+/*
+ * 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.isis.objectstore.sql.mapping;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.Results;
+
+public interface FieldMapping {
+
+ public ObjectAssociation getField();
+
+ void appendColumnDefinitions(StringBuffer sql);
+
+ void appendColumnNames(StringBuffer sql);
+
+ void appendInsertValues(DatabaseConnector connector, StringBuffer sql, ObjectAdapter object);
+
+ void appendUpdateValues(DatabaseConnector connector, StringBuffer sql, ObjectAdapter object);
+
+ void initializeField(ObjectAdapter object, Results rs);
+
+ void appendWhereClause(DatabaseConnector connector, StringBuffer sql, ObjectAdapter object);
+
+ void debugData(DebugBuilder debug);
+
+ void appendWhereObject(DatabaseConnector connector, ObjectAdapter objectAdapter);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMappingFactory.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMappingFactory.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMappingFactory.java
new file mode 100644
index 0000000..4a139cf
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/FieldMappingFactory.java
@@ -0,0 +1,27 @@
+/*
+ * 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.isis.objectstore.sql.mapping;
+
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+
+public interface FieldMappingFactory {
+ FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field);
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMapping.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMapping.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMapping.java
new file mode 100644
index 0000000..e064cbe
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMapping.java
@@ -0,0 +1,40 @@
+/*
+ * 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.isis.objectstore.sql.mapping;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.objectstore.sql.DatabaseConnector;
+import org.apache.isis.objectstore.sql.Results;
+
+public interface ObjectReferenceMapping {
+
+ void appendColumnDefinitions(StringBuffer sql);
+
+ void appendInsertValues(DatabaseConnector connector, StringBuffer sb, ObjectAdapter value);
+
+ void appendColumnNames(StringBuffer sql);
+
+ void appendUpdateValues(DatabaseConnector connector, StringBuffer sql, ObjectAdapter object);
+
+ Oid recreateOid(final Results rs, final ObjectSpecification specification);
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMappingFactory.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMappingFactory.java b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMappingFactory.java
new file mode 100644
index 0000000..6a13d63
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/mapping/ObjectReferenceMappingFactory.java
@@ -0,0 +1,26 @@
+/*
+ * 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.isis.objectstore.sql.mapping;
+
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+public interface ObjectReferenceMappingFactory {
+ ObjectReferenceMapping createReferenceMapping(String columnName, ObjectSpecification specification);
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/site/apt/index.apt b/mothballed/component/objectstore/sql/sql-impl/src/site/apt/index.apt
new file mode 100644
index 0000000..891352a
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/site/apt/index.apt
@@ -0,0 +1,27 @@
+~~ 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.
+
+
+
+SQL ObjectStore Implementation
+
+ This module holds the implementation of the {{{../index.html}SQL ObjectStore}}.
+
+Further Info
+
+ See this module's {{{./apidocs/index.html}Javadoc}} and {{{../docbkx/html/guide/isis-sql-objectstore.html}User Guide}} for more information.
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/site/apt/jottings.apt b/mothballed/component/objectstore/sql/sql-impl/src/site/apt/jottings.apt
new file mode 100644
index 0000000..c5d1200
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/site/apt/jottings.apt
@@ -0,0 +1,24 @@
+~~ 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.
+
+
+
+Jottings
+
+ This page is to capture any random jottings relating to this module prior
+ to being moved into formal documentation.
+
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/site/site.xml
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/site/site.xml b/mothballed/component/objectstore/sql/sql-impl/src/site/site.xml
new file mode 100644
index 0000000..fea0aec
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/site/site.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project>
+
+ <body>
+ <breadcrumbs>
+ <item name="Implementation" href="index.html"/>
+ </breadcrumbs>
+
+ <menu name="SQL Objectstore Implementation">
+ <item name="About" href="index.html" />
+ <item name="Jottings" href="jottings.html" />
+ </menu>
+
+ <menu name="SQL OS Modules">
+ <item name="Implementation" href="../sql-impl/index.html" />
+ <item name="Tests" href="../sql-tests-common/index.html" />
+ <item name="Integration Tests" href="../sql-tests-served/index.html" />
+ </menu>
+
+ <menu name="Maven Reports" ref="reports" />
+ </body>
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/DefaultsTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/DefaultsTest.java b/mothballed/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/DefaultsTest.java
new file mode 100644
index 0000000..86b5db4
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/DefaultsTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.isis.objectstore.sql;
+
+import static org.hamcrest.Matchers.is;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+
+public class DefaultsTest {
+ @Test
+ public void tablePrefixDefaultsTo_Isis() {
+ final String prefix = "isis.persistor.sql";
+ final IsisConfiguration config = new IsisConfigurationDefault();
+ Defaults.initialise(prefix, config);
+ Assert.assertThat(Defaults.getTablePrefix(), is("isis_"));
+ }
+
+ @Test
+ public void tablePrefixCanBeReplaced() {
+ final String prefix = "isis.persistor.sql";
+ final String key = "isis.persistor.sql.default.tableprefix";
+ final IsisConfigurationDefault config = new IsisConfigurationDefault();
+ config.add(key, "");
+ Defaults.initialise(prefix, config);
+ Assert.assertThat(Defaults.getTablePrefix(), is(""));
+ }
+
+ @Test
+ public void checkLimitStatement(){
+ final String prefix = "isis.persistor.sql";
+ final IsisConfigurationDefault config = new IsisConfigurationDefault();
+ Defaults.initialise(prefix, config);
+
+ final long startIndex=0;
+ final long rowCount=0;
+
+ Assert.assertThat(Defaults.getLimitsClause(startIndex, rowCount), is("LIMIT 0, 0"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoderTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoderTest.java b/mothballed/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoderTest.java
new file mode 100644
index 0000000..e2a976a
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-impl/src/test/java/org/apache/isis/objectstore/sql/jdbc/helpers/SimplePasswordEncoderDecoderTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.isis.objectstore.sql.jdbc.helpers;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class SimplePasswordEncoderDecoderTest {
+
+ private static final String testSeed = "randomString12345";
+ private static final Integer encLength = 120;
+
+ @Test
+ public void testEncodingValueFromString() {
+ SimplePasswordEncoderDecoder encdec = new SimplePasswordEncoderDecoder(testSeed, encLength);
+ String input = "password";
+ String encoded = encdec.encodeRawValueIntoEncodedString(input);
+ Assert.assertThat(encoded, is(not(input)));
+ Assert.assertThat(encoded.length(), is(120));
+ }
+
+ @Test
+ public void testDecodingEncodedValue() {
+ SimplePasswordEncoderDecoder encdec = new SimplePasswordEncoderDecoder(testSeed, encLength);
+ String input = "password";
+ String encoded = encdec.encodeRawValueIntoEncodedString(input);
+ Assert.assertThat(encoded, is(not(input)));
+
+ String decoded = encdec.decodeEncodedValueIntoRawString(encoded);
+ Assert.assertThat(decoded, is(input));
+ }
+
+ @Test
+ public void testNoSeedDoesNothing() {
+ SimplePasswordEncoderDecoder encdec = new SimplePasswordEncoderDecoder(null, encLength);
+ String input = "password";
+ String encoded = encdec.encodeRawValueIntoEncodedString(input);
+ Assert.assertThat(encoded, is(input));
+
+ String decoded = encdec.decodeEncodedValueIntoRawString(encoded);
+ Assert.assertThat(decoded, is(input));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/pom.xml
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/pom.xml b/mothballed/component/objectstore/sql/sql-tests-common/pom.xml
new file mode 100644
index 0000000..829c1e4
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/pom.xml
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-sql</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>isis-objectstore-sql-tests-common</artifactId>
+
+ <name>Isis SQL ObjectStore Integration Tests - Common</name>
+
+ <properties>
+ <siteBaseDir>..</siteBaseDir>
+ <relativeUrl>sql-tests-common/</relativeUrl>
+
+ <xml-objectstore.version>1.0.0-SNAPSHOT</xml-objectstore.version>
+ <hsqldb.version>2.2.9</hsqldb.version>
+ </properties>
+
+ <!-- used in Site generation for relative references. -->
+ <url>http://isis.apache.org/${relativeUrl}</url>
+
+ <description>Common code to test the sql persistor. Uses the HSQLDB for maximum compatibility.</description>
+ <build>
+ <plugins>
+ <!-- TODO: currently set to ignore test failures -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <testFailureIgnore>false</testFailureIgnore>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>${maven-project-info-reports-plugin}</version>
+ <inherited>false</inherited>
+ <configuration>
+ <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <inherited>false</inherited>
+ <reports>
+ <report>dependency-management</report>
+ <report>dependencies</report>
+ <report>dependency-convergence</report>
+ <report>plugins</report>
+ <report>summary</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>${hsqldb.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-unittestsupport</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-integtestsupport</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-runtime</artifactId>
+ </dependency>
+
+
+ <!-- Required for TestProxy -->
+ <!-- Isis defaults -->
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-objectstore</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-objectstore</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-bytecode-cglib</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Isis Object store -->
+ <dependency>
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-sql-impl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-tck-dom</artifactId>
+ </dependency>
+
+
+ <!-- HSQLDB -->
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ </dependency>
+ <!-- Required to support the XML cross-test -->
+ <dependency>
+ <groupId>org.apache.isis.objectstore</groupId>
+ <artifactId>isis-objectstore-xml</artifactId>
+ </dependency>
+ <!-- others -->
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock-legacy</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock-junit4</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Data.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Data.java b/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Data.java
new file mode 100644
index 0000000..f54f756
--- /dev/null
+++ b/mothballed/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/Data.java
@@ -0,0 +1,100 @@
+/*
+ * 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.isis.objectstore.sql.common;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.isis.applib.value.Color;
+import org.apache.isis.applib.value.Date;
+import org.apache.isis.applib.value.DateTime;
+import org.apache.isis.applib.value.Image;
+import org.apache.isis.applib.value.Money;
+import org.apache.isis.applib.value.Password;
+import org.apache.isis.applib.value.Percentage;
+import org.apache.isis.applib.value.Time;
+import org.apache.isis.applib.value.TimeStamp;
+
+public class Data {
+
+ // private static final TimeZone GMTm2_TIME_ZONE;
+
+ // Helper values
+ static final java.sql.Date sqlDate;
+ static final java.sql.Date sqlDate20100305;
+
+ static {
+ /*
+ *
+ * // For testing -ve offset timezone local regions. GMTm2_TIME_ZONE = TimeZone.getTimeZone("GMT-0200");
+ * //GMTm2_TIME_ZONE = TimeZone.getTimeZone("UTC"); TimeZone.setDefault(GMTm2_TIME_ZONE);
+ */
+
+ /*
+ * TimeZone timeZone = TimeZone.getTimeZone("Etc/UTC"); if (timeZone == null) { timeZone =
+ * TimeZone.getTimeZone("UTC"); } UTC_TIME_ZONE = timeZone;
+ */
+
+ /*
+ * There is still an issue assigning a java.sql.Date variable from a calendar. final Calendar cal =
+ * Calendar.getInstance(); cal.setTimeZone(UTC_TIME_ZONE); cal.clear(); cal.set(Calendar.YEAR, 2011);
+ * cal.set(Calendar.MONTH, 4-1); cal.set(Calendar.DAY_OF_MONTH, 8);
+ */
+ // 2011-4-8 = 1,270,684,800,000
+ final Date date20100308 = new Date(2010, 4, 8);
+ sqlDate = new java.sql.Date(date20100308.getMillisSinceEpoch());
+
+ sqlDate20100305 = new java.sql.Date(new Date(2010, 3, 5).getMillisSinceEpoch());
+ }
+
+ static final Date applibDate = new Date(2010, 3, 5); // 2010-03-05 =
+ // 1,267,747,200,000
+ static final DateTime dateTime = new DateTime(2010, 3, 5, 1, 23); // 1,267,752,180,000
+ static final TimeStamp timeStamp = new TimeStamp(dateTime.millisSinceEpoch());
+ static final Time time = new Time(14, 56); // 53,760,000
+
+ static final Color color = Color.WHITE;
+ static final Image image = new Image(new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } });
+ static final Password password = new Password("password");
+ static final Percentage percentage = new Percentage(42);
+ static final Money money = new Money(99.99, "ZAR");
+
+ // Standard values
+ static final int intMaxValue = Integer.MAX_VALUE;
+ static final short shortMaxValue = Short.MAX_VALUE;
+ static final long longMaxValue = Long.MAX_VALUE;
+ static final double doubleMaxValue = 1e308;// Double.MAX_VALUE;
+ static final float floatMaxValue = (float) 1e37;// Float.MAX_VALUE;
+
+ static final int intMinValue = Integer.MIN_VALUE;
+ static final short shortMinValue = Short.MIN_VALUE;
+ static final long longMinValue = Long.MIN_VALUE;
+ static final double doubleMinValue = 1e-307;// Double.MIN_VALUE;
+ static final float floatMinValue = (float) 1e-37;// Float.MIN_VALUE;
+
+ // Collection mapper tests
+ static final List<String> stringList1 = Arrays.asList("Baking", "Bakery", "Canned", "Dairy");
+ static final List<String> stringList2 = Arrays.asList("Fridge", "Deli", "Fresh Produce", "Frozen", "Household",
+ "Other..");
+
+ public static List<String> getTableNames() {
+ return Arrays.asList("sqldataclass", "simpleclass", "simpleclasstwo", "primitivevaluedentity");
+ }
+
+}
[10/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcAbstractReferenceFieldMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcAbstractReferenceFieldMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcAbstractReferenceFieldMapping.java
deleted file mode 100755
index a09048f..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcAbstractReferenceFieldMapping.java
+++ /dev/null
@@ -1,150 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-/**
- * Provides support for persisting abstract classes and interfaces.
- *
- * Provides two columns: the first is the standard property field. The second is
- * initialised only when the field is "saved", and contains the actual classname
- * of the persisted concrete class.
- *
- *
- * @version $Rev$ $Date$
- */
-public class JdbcAbstractReferenceFieldMapping extends JdbcObjectReferenceFieldMapping {
- private final String classnameColumn;
- private final String dataType;
-
- public static class Factory extends AbstractFieldMappingFactory {
-
- public Factory(final String type) {
- super();
- }
-
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- final String dataType = getTypeOverride(object, field, Defaults.TYPE_LONG_STRING());
- return new JdbcAbstractReferenceFieldMapping(field, dataType);
- }
- }
-
- public JdbcAbstractReferenceFieldMapping(final ObjectAssociation field, final String dataType) {
- super(field);
- this.dataType = dataType;
- classnameColumn = Sql.identifier(getColumn() + "_cls");
- }
-
- @Override
- public void appendColumnDefinitions(final StringBuffer sql) {
- super.appendColumnDefinitions(sql);
-
- sql.append(", ");
- sql.append(classnameColumn);
- sql.append(" ");
- sql.append(dataType);
- }
-
- @Override
- public void appendCreateColumnDefinitions(final StringBuffer sql) {
- super.appendCreateColumnDefinitions(sql);
- sql.append(classnameColumn);
- sql.append(" ");
- sql.append(dataType);
- }
-
- @Override
- public void appendColumnNames(final StringBuffer sql) {
- super.appendColumnNames(sql);
- sql.append(", ");
- sql.append(classnameColumn);
- }
-
- @Override
- public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- super.appendWhereClause(connector, sql, object);
- }
-
- @Override
- public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- super.appendInsertValues(connector, sql, object);
- sql.append(",?");
-
- final ObjectAdapter objectAdapter = field.get(object);
- if (objectAdapter != null) {
- connector.addToQueryValues(objectAdapter.getSpecification().getFullIdentifier());
- } else {
- connector.addToQueryValues(null);
- }
- }
-
- @Override
- public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- super.appendUpdateValues(connector, sql, object);
-
- sql.append(",");
- sql.append(classnameColumn);
- sql.append(" = ?");
-
- final ObjectAdapter objectAdapter = field.get(object);
- if (objectAdapter != null) {
- connector.addToQueryValues(objectAdapter.getSpecification().getFullIdentifier());
- } else {
- connector.addToQueryValues(null);
- }
- }
-
- @Override
- public void initializeField(final ObjectAdapter object, final Results rs) {
- final String className = rs.getString(classnameColumn);
- if (className != null) {
- final ObjectSpecification specification = getReflector().loadSpecification(className);
-
- final Oid oid = recreateOid(rs, specification);
-
- final ObjectAdapter reference = getAdapter(specification, oid);
- ((OneToOneAssociation) field).initAssociation(object, reference);
- }
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln(field.getId(), getColumn());
- }
-
- private SpecificationLoaderSpi getReflector() {
- return IsisContext.getSpecificationLoader();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcBinaryValueMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcBinaryValueMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcBinaryValueMapper.java
deleted file mode 100755
index 16366b4..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcBinaryValueMapper.java
+++ /dev/null
@@ -1,132 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.core.commons.exceptions.IsisApplicationException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-/**
- *
- *
- * @version $Rev$ $Date$
- */
-public class JdbcBinaryValueMapper extends AbstractJdbcFieldMapping {
-
- public static class Factory extends AbstractFieldMappingFactory {
- private final String type;
-
- public Factory(final String type) {
- super();
- this.type = type;
- }
-
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- final String dataType = getTypeOverride(object, field, type);
- return new JdbcBinaryValueMapper(field, dataType);
- }
- }
-
- private final String type;
-
- public JdbcBinaryValueMapper(final ObjectAssociation field, final String type) {
- super(field);
- this.type = type;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
- * #columnType()
- */
- @Override
- protected String columnType() {
- return type;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
- * #preparedStatementObject(org.apache
- * .isis.core.metamodel.adapter.ObjectAdapter)
- */
- @Override
- protected Object preparedStatementObject(final ObjectAdapter value) {
- if (value == null) {
- return null;
- }
- final Object o = value.getObject();
- return o;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
- * #setFromDBColumn(org.apache.isis. runtimes.dflt.objectstores.sql.Results,
- * java.lang.String,
- * org.apache.isis.core.metamodel.spec.feature.ObjectAssociation)
- */
- @Override
- protected ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
- ObjectAdapter restoredValue;
-
- final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
- Object resultObject = results.getObject(columnName);
- if (resultObject == null) {
- return null;
- }
-
- if (resultObject.getClass() != correspondingClass) {
- if (checkIfIsClass(correspondingClass, Integer.class, int.class)) {
- resultObject = results.getInt(columnName);
- } else if (checkIfIsClass(correspondingClass, Double.class, double.class)) {
- resultObject = results.getDouble(columnName);
- } else if (checkIfIsClass(correspondingClass, Float.class, float.class)) {
- resultObject = results.getFloat(columnName);
- } else if (checkIfIsClass(correspondingClass, Short.class, short.class)) {
- resultObject = results.getShort(columnName);
- } else if (checkIfIsClass(correspondingClass, Long.class, long.class)) {
- resultObject = results.getLong(columnName);
- } else if (checkIfIsClass(correspondingClass, Boolean.class, boolean.class)) {
- resultObject = results.getBoolean(columnName);
- } else {
- throw new IsisApplicationException("Unhandled type: " + correspondingClass.getCanonicalName());
- }
- }
-
- restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(resultObject);
-
- return restoredValue;
-
- }
-
- private boolean checkIfIsClass(final Class<?> expected, final Class<?> couldBe1, final Class<?> couldBe2) {
- return (expected == couldBe1 || expected == couldBe2);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcColorValueMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcColorValueMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcColorValueMapper.java
deleted file mode 100755
index e36c14a..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcColorValueMapper.java
+++ /dev/null
@@ -1,101 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.applib.value.Color;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-/**
- *
- *
- * @version $Rev$ $Date$
- */
-public class JdbcColorValueMapper extends AbstractJdbcFieldMapping {
-
- public static class Factory extends AbstractFieldMappingFactory {
- private final String type;
-
- public Factory(final String type) {
- super();
- this.type = type;
- }
-
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- final String dataType = getTypeOverride(object, field, type);
- return new JdbcColorValueMapper(field, dataType);
- }
- }
-
- private final String type;
-
- public JdbcColorValueMapper(final ObjectAssociation field, final String type) {
- super(field);
- this.type = type;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
- * #columnType()
- */
- @Override
- protected String columnType() {
- return type;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
- * #preparedStatementObject(org.apache
- * .isis.core.metamodel.adapter.ObjectAdapter)
- */
- @Override
- protected Object preparedStatementObject(final ObjectAdapter value) {
- final Object o = value.getObject();
- return ((Color) o).intValue();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping
- * #setFromDBColumn(org.apache.isis. runtimes.dflt.objectstores.sql.Results,
- * java.lang.String,
- * org.apache.isis.core.metamodel.spec.feature.ObjectAssociation)
- */
- @Override
- protected ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
- ObjectAdapter restoredValue;
- final int intValue = results.getInt(columnName);
- final Color colorValue = new Color(intValue);
- restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(colorValue);
- return restoredValue;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnector.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnector.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnector.java
deleted file mode 100644
index 9c3523e..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnector.java
+++ /dev/null
@@ -1,404 +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.isis.objectstore.sql.jdbc;
-
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.joda.time.DateTimeZone;
-import org.joda.time.LocalDate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.AbstractDatabaseConnector;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.SqlMetaData;
-import org.apache.isis.objectstore.sql.SqlObjectStore;
-import org.apache.isis.objectstore.sql.SqlObjectStoreException;
-
-public class JdbcConnector extends AbstractDatabaseConnector {
- private static final Logger LOG = LoggerFactory.getLogger(JdbcConnector.class);
- private Connection connection;
- private final String baseName;
-
- public JdbcConnector() {
- baseName = SqlObjectStore.BASE_NAME;
- }
-
- public JdbcConnector(final String propertyBase) {
- baseName = propertyBase;
- }
-
- @Override
- public void close() {
- try {
- if (connection != null) {
- LOG.info("close");
- connection.close();
- connection = null;
-
- }
- } catch (final SQLException e) {
- throw new SqlObjectStoreException("Failed to close", e);
- }
- }
-
- @Override
- public int count(final String sql) {
- LOG.debug("SQL: " + sql);
- PreparedStatement statement;
- try {
- statement = connection.prepareStatement(sql);
- final ResultSet result = statement.executeQuery();
- result.next();
- final int count = result.getInt(1);
- statement.close();
- return count;
- } catch (final SQLException e) {
- throw new SqlObjectStoreException("Failed count", e);
- }
- }
-
- @Override
- public void delete(final String sql) {
- update(sql);
- }
-
- public void open() {
- final String BASE = baseName + ".jdbc.";
- final IsisConfiguration params = IsisContext.getConfiguration().getProperties(BASE);
-
- try {
- final String driver = params.getString(BASE + "driver");
- final String url = params.getString(BASE + "connection");
- final String user = params.getString(BASE + "user");
- final String password = params.getString(BASE + "password");
-
- if (connection != null) {
- throw new SqlObjectStoreException("Connection already established");
- }
-
- if (driver == null) {
- throw new SqlObjectStoreException("No driver specified for database connection");
- }
- if (url == null) {
- throw new SqlObjectStoreException("No connection URL specified to database");
- }
- if (user == null) {
- LOG.info("No user specified; will attempt to login with no credentials");
- } else {
- if (password == null) {
- throw new SqlObjectStoreException("No password specified for database connection");
- }
- }
-
- Class.forName(driver);
- connection = getConnection(url, user, password);
- if (connection == null) {
- throw new SqlObjectStoreException("No connection established to " + url);
- }
- } catch (final SQLException e) {
- throw new SqlObjectStoreException("Failed to start", e);
- } catch (final ClassNotFoundException e) {
- throw new SqlObjectStoreException("Could not find database driver", e);
- }
-
- }
-
- private static Connection getConnection(final String url, final String user, final String password)
- throws SQLException {
- if (user != null) {
- LOG.info("Connecting to " + url + " as " + user);
- return DriverManager.getConnection(url, user, password);
- } else {
- LOG.info("Connecting to " + url + " with no credentials");
- return DriverManager.getConnection(url);
- }
- }
-
- /*
- * public void executeStoredProcedure(final StoredProcedure storedProcedure) { Parameter[] parameters =
- * storedProcedure.getParameters(); StringBuffer sql = new StringBuffer("{call ");
- * sql.append(storedProcedure.getName()); sql.append(" ("); for (int i = 0, no = parameters.length; i < no; i++) {
- * sql.append(i == 0 ? "?" : ",?"); } sql.append(")}"); LOG.debug("SQL: " + sql);
- *
- * CallableStatement statement; try { statement = connection.prepareCall(sql.toString());
- *
- * for (int i = 0; i < parameters.length; i++) { LOG.debug(" setup param " + i + " " + parameters[i]);
- * parameters[i].setupParameter(i + 1, parameters[i].getName(), storedProcedure); } LOG.debug(" execute ");
- * statement.execute(); for (int i = 0; i < parameters.length; i++) { parameters[i].retrieve(i + 1,
- * parameters[i].getName(), storedProcedure); LOG.debug(" retrieve param " + i + " " + parameters[i]); } } catch
- * (SQLException e) { throw new ObjectAdapterRuntimeException(e); }
- *
- * }
- *
- *
- * public MultipleResults executeStoredProcedure(final String name, final Parameter[] parameters) { StringBuffer sql
- * = new StringBuffer("{call "); sql.append(name); sql.append(" ("); for (int i = 0; i < parameters.length; i++) {
- * sql.append(i == 0 ? "?" : ",?"); } sql.append(")}"); LOG.debug("SQL: " + sql);
- *
- * CallableStatement statement; try { statement = connection.prepareCall(sql.toString());
- *
- * StoredProcedure storedProcedure = new JdbcStoredProcedure(statement);
- *
- * for (int i = 0; i < parameters.length; i++) { LOG.debug(" setup param " + i + " " + parameters[i]);
- * parameters[i].setupParameter(i + 1, parameters[i].getName(), storedProcedure); } LOG.debug(" execute ");
- * statement.execute(); for (int i = 0; i < parameters.length; i++) { parameters[i].retrieve(i + 1,
- * parameters[i].getName(), storedProcedure); LOG.debug(" retrieve param " + i + " " + parameters[i]); }
- *
- * return new JdbcResults(statement); } catch (SQLException e) { throw new ObjectAdapterRuntimeException(e); } }
- */
-
- @Override
- public Results select(final String sql) {
- LOG.debug("SQL: " + sql);
- PreparedStatement statement;
- try {
- statement = connection.prepareStatement(sql);
- addPreparedValues(statement);
- return new JdbcResults(statement.executeQuery());
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- } finally {
- clearPreparedValues();
- }
- }
-
- @Override
- public int update(final String sql) {
- if (sql.length() == 0) {
- return 0;
- }
- LOG.debug("SQL: " + sql);
- PreparedStatement statement;
- try {
- statement = connection.prepareStatement(sql);
- addPreparedValues(statement);
- final int updateCount = statement.executeUpdate();
- statement.close();
- return updateCount;
- } catch (final SQLException e) {
- LOG.error("failed to execute " + sql, e);
- throw new SqlObjectStoreException("SQL error: " + e.toString(), e);
- } finally {
- clearPreparedValues();
- }
- }
-
- private void clearPreparedValues() {
- queryValues.clear();
- }
-
- private void addPreparedValues(final PreparedStatement statement) throws SQLException {
- if (queryValues.size() > 0) {
- int i = 1;
- try {
- for (final Object value : queryValues) {
- if (value instanceof LocalDate) {
- try {
- statement.setObject(i, value, java.sql.Types.DATE);
- } catch (final SQLException e) {
- // TODO This daft catch is required my MySQL, which
- // also requires the TimeZone offset to be
- // "undone"
- final LocalDate localDate = (LocalDate) value;
- final int millisOffset = -DateTimeZone.getDefault().getOffset(null);
- final java.util.Date javaDate =
- localDate.toDateTimeAtStartOfDay(DateTimeZone.forOffsetMillis(millisOffset)).toDate();
-
- statement.setObject(i, javaDate, java.sql.Types.DATE);
- }
- } else if (value instanceof InputStream) {
- statement.setBlob(i, (InputStream) value);
- } else {
- statement.setObject(i, value);
- }
- i++;
- }
- } catch (final SQLException e) {
- LOG.error("Error adding prepared value " + i + " of type "
- + queryValues.get(i - 1).getClass().getSimpleName(), e);
- throw e;
- }
- }
- }
-
- @Override
- public boolean hasTable(final String tableName) {
- try {
- final ResultSet set = connection.getMetaData().getTables(null, null, tableName, null);
- if (set.next()) {
- LOG.debug("Found " + set.getString("TABLE_NAME"));
- set.close();
- return true;
- } else {
- set.close();
- return false;
- }
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public boolean hasColumn(final String tableName, final String columnName) {
- try {
- final ResultSet set = connection.getMetaData().getColumns(null, null, tableName, columnName);
- if (set.next()) {
- LOG.debug("Found " + set.getString("COLUMN_NAME") + " in " + set.getString("TABLE_NAME"));
- set.close();
- return true;
- } else {
- set.close();
- return false;
- }
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public void insert(final String sql) {
- update(sql);
- }
-
- @Override
- public void insert(final String sql, final Object oid) {
- LOG.debug("SQL: " + sql);
- PreparedStatement statement;
- try {
- statement = connection.prepareStatement(sql);
- statement.executeUpdate();
- /*
- * require 3.0 ResultSet rs = statement.getGeneratedKeys(); if(rs.next()) { int id = rs.getInt(1); }
- */statement.close();
- } catch (final SQLException e) {
- throw new SqlObjectStoreException("SQL error", e);
- }
- }
-
- public Connection getConnection() {
- return connection;
- }
-
- @Override
- public void commit() {
- try {
- LOG.debug("commit");
- connection.commit();
- connection.setAutoCommit(true);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException("Commit error", e);
- }
- }
-
- @Override
- public void begin() {
- try {
- LOG.debug("begin transaction");
- connection.setAutoCommit(false);
- clearPreparedValues();
- } catch (final SQLException e) {
- throw new SqlObjectStoreException("Rollback error", e);
- }
-
- }
-
- @Override
- public void rollback() {
- try {
- LOG.debug("rollback");
- connection.rollback();
- connection.setAutoCommit(true);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException("Rollback error", e);
- }
- }
-
- @Override
- public SqlMetaData getMetaData() {
- try {
- final DatabaseMetaData metaData = connection.getMetaData();
- return new JdbcSqlMetaData(metaData);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException("Metadata error", e);
- }
- }
-
- @Override
- public void debug(final DebugBuilder debug) {
- try {
- final DatabaseMetaData metaData = connection.getMetaData();
- debug.appendln("Product", metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion());
- try {
- debug.appendln("Product Version",
- metaData.getDatabaseMajorVersion() + "." + metaData.getDatabaseMinorVersion());
- } catch (final AbstractMethodError ignore) {
- }
- debug.appendln("Drive", metaData.getDriverName() + " " + metaData.getDriverVersion());
- debug.appendln("Driver Version", metaData.getDriverMajorVersion() + "." + metaData.getDriverMinorVersion());
- debug.appendln("Keywords", metaData.getSQLKeywords());
- debug.appendln("Date/Time functions", metaData.getTimeDateFunctions());
- debug.appendln("Mixed case identifiers", metaData.supportsMixedCaseIdentifiers());
- debug.appendln("Lower case identifiers", metaData.storesLowerCaseIdentifiers());
- debug.appendln("Lower case quoted", metaData.storesLowerCaseQuotedIdentifiers());
- debug.appendln("Mixed case identifiers", metaData.storesMixedCaseIdentifiers());
- debug.appendln("Mixed case quoted", metaData.storesMixedCaseQuotedIdentifiers());
- debug.appendln("Upper case identifiers", metaData.storesUpperCaseIdentifiers());
- debug.appendln("Upper case quoted", metaData.storesUpperCaseQuotedIdentifiers());
- debug.appendln("Max table name length", metaData.getMaxTableNameLength());
- debug.appendln("Max column name length", metaData.getMaxColumnNameLength());
-
- } catch (final SQLException e) {
- throw new SqlObjectStoreException("Metadata error", e);
- }
- }
-
- private final List<Object> queryValues = new ArrayList<Object>();
-
- @Override
- public String addToQueryValues(final int i) {
- queryValues.add(i);
- return "?";
- }
-
- @Override
- public String addToQueryValues(final String s) {
- queryValues.add(s);
- return "?";
- }
-
- @Override
- public String addToQueryValues(final Object o) {
- queryValues.add(o);
- return "?";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnectorFactory.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnectorFactory.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnectorFactory.java
deleted file mode 100644
index fcb6a72..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcConnectorFactory.java
+++ /dev/null
@@ -1,34 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.DatabaseConnectorFactory;
-
-public class JdbcConnectorFactory implements DatabaseConnectorFactory {
-
- @Override
- public DatabaseConnector createConnector() {
- final JdbcConnector connection = new JdbcConnector();
- connection.open();
- return connection;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateMapper.java
deleted file mode 100644
index 20592b3..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateMapper.java
+++ /dev/null
@@ -1,108 +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.isis.objectstore.sql.jdbc;
-
-import org.joda.time.LocalDate;
-
-import org.apache.isis.applib.PersistFailedException;
-import org.apache.isis.applib.value.Date;
-import org.apache.isis.core.commons.exceptions.IsisApplicationException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
-import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-/**
- * Handles reading and writing java.sql.Date and org.apache.isis.applib.value.Date values to and from the data store.
- *
- *
- * @version $Rev$ $Date$
- */
-public class JdbcDateMapper extends AbstractJdbcFieldMapping {
-
- private final String dataType;
-
- public static class Factory extends AbstractFieldMappingFactory {
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- final String dataType = getTypeOverride(object, field, Defaults.TYPE_DATE());
- return new JdbcDateMapper(field, dataType);
- }
- }
-
- protected JdbcDateMapper(final ObjectAssociation field, final String dataType) {
- super(field);
- this.dataType = dataType;
- }
-
- @Override
- protected Object preparedStatementObject(final ObjectAdapter value) {
- final Object o = value.getObject();
- if (o instanceof java.sql.Date) {
- final java.sql.Date javaSqlDate = (java.sql.Date) value.getObject();
- final long millisSinceEpoch = javaSqlDate.getTime();
- return new LocalDate(millisSinceEpoch);
- } else if (o instanceof Date) {
- final Date asDate = (Date) value.getObject();
- return new LocalDate(asDate.getMillisSinceEpoch());
- } else {
- throw new IsisApplicationException("Unimplemented JdbcDateMapper instance type: "
- + value.getClass().toString());
- }
- }
-
- @Override
- public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
- ObjectAdapter restoredValue;
- final java.util.Date javaDateValue = results.getJavaDateOnly(columnName);
- final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
- if (correspondingClass == java.util.Date.class || correspondingClass == java.sql.Date.class) {
- // 2011-04-08 = 1270684800000
- restoredValue = getAdapterManager().adapterFor(javaDateValue);
- } else if (correspondingClass == Date.class) {
- // 2010-03-05 = 1267747200000
- Date dateValue;
- dateValue = new Date(javaDateValue);
- restoredValue = getAdapterManager().adapterFor(dateValue);
- } else {
- throw new PersistFailedException("Unhandled date type: " + correspondingClass.getCanonicalName());
- }
- return restoredValue;
- }
-
- @Override
- public String columnType() {
- return dataType;
- }
-
- protected PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- protected AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateTimeMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateTimeMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateTimeMapper.java
deleted file mode 100644
index 19c2c96..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcDateTimeMapper.java
+++ /dev/null
@@ -1,77 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.applib.PersistFailedException;
-import org.apache.isis.applib.value.DateTime;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-public class JdbcDateTimeMapper extends AbstractJdbcFieldMapping {
-
- private final String dataType;
-
- public static class Factory extends AbstractFieldMappingFactory {
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- final String dataType = getTypeOverride(object, field, Defaults.TYPE_DATETIME());
- return new JdbcDateTimeMapper(field, dataType);
- }
- }
-
- protected JdbcDateTimeMapper(final ObjectAssociation field, final String dataType) {
- super(field);
- this.dataType = dataType;
- }
-
- @Override
- protected Object preparedStatementObject(final ObjectAdapter value) {
- final DateTime asDate = (DateTime) value.getObject();
- final java.sql.Timestamp dateTime = new java.sql.Timestamp(asDate.millisSinceEpoch());
- return dateTime;
- }
-
- @Override
- public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
-
- ObjectAdapter restoredValue;
- final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
- if (correspondingClass == DateTime.class) {
- final java.sql.Timestamp o = (java.sql.Timestamp) results.getObject(columnName);
- final DateTime timeValue = new DateTime(o.getTime());
- restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(timeValue);
- } else {
- throw new PersistFailedException("Unhandled time type: " + correspondingClass.getCanonicalName());
- }
- return restoredValue;
- }
-
- @Override
- public String columnType() {
- return dataType;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcGeneralValueMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcGeneralValueMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcGeneralValueMapper.java
deleted file mode 100644
index 0129ddc..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcGeneralValueMapper.java
+++ /dev/null
@@ -1,101 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.applib.value.Money;
-import org.apache.isis.applib.value.Password;
-import org.apache.isis.applib.value.Percentage;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-public class JdbcGeneralValueMapper extends AbstractJdbcFieldMapping {
-
- public static class Factory extends AbstractFieldMappingFactory {
- private final String type;
-
- public Factory(final String type) {
- super();
- this.type = type;
- }
-
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- final String dataType = getTypeOverride(object, field, type);
- return new JdbcGeneralValueMapper(field, dataType);
- }
- }
-
- private final String type;
-
- public JdbcGeneralValueMapper(final ObjectAssociation field, final String type) {
- super(field);
- this.type = type;
- }
-
- @Override
- protected Object preparedStatementObject(final ObjectAdapter value) {
- if (value == null) {
- return null;
- }
-
- final Object o = value.getObject();
-
- if (o instanceof Money) {
- return ((Money) o).floatValue();
- } else if (o instanceof Percentage) {
- return ((Percentage) o).floatValue();
- } else if (o instanceof Password) {
- return ((Password) o).getPassword();
- } else if (o instanceof String) {
- return o;
- } else if (o instanceof Boolean) {
- return o;
- } else {
- if (columnType().contains("CHAR")) {
- final EncodableFacet facet = value.getSpecification().getFacet(EncodableFacet.class);
- final String encodedString = facet.toEncodedString(value);
- return encodedString;
- } else {
- return o;
- }
- }
- }
-
- @Override
- public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
- final String encodedValue = results.getString(columnName);
- if (encodedValue == null) {
- return null;
- }
- final EncodableFacet facet = field.getSpecification().getFacet(EncodableFacet.class);
- return facet.fromEncodedString(encodedValue);
- }
-
- @Override
- public String columnType() {
- return type;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcImageValueMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcImageValueMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcImageValueMapper.java
deleted file mode 100644
index f64bf24..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcImageValueMapper.java
+++ /dev/null
@@ -1,116 +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.isis.objectstore.sql.jdbc;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.isis.applib.PersistFailedException;
-import org.apache.isis.applib.value.Image;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-import org.apache.isis.objectstore.sql.mapping.FieldMappingFactory;
-
-/**
- *
- *
- * @version $Rev$ $Date$
- */
-public class JdbcImageValueMapper extends AbstractJdbcMultiFieldMapping {
-
- public static class Factory implements FieldMappingFactory {
- private final String type_string; // A reference, e.g. file name
- private final String type_blob; // The BLOB data
-
- public Factory(final String string_type, final String type_blob) {
- this.type_string = string_type;
- this.type_blob = type_blob;
- }
-
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- return new JdbcImageValueMapper(field, type_string, type_blob);
- }
- }
-
- public JdbcImageValueMapper(final ObjectAssociation field, final String type1, final String type2) {
- super(field, 2, type1, type2);
- }
-
- @Override
- protected Object preparedStatementObject(int index, Object o) {
- if (o instanceof Image) {
- if (index == 0) {
- return "Image";
- } else {
- return getOutputStreamFromImage((Image) o);
- }
- } else {
- throw new PersistFailedException("Invalid object type " + o.getClass().getCanonicalName()
- + " for JdbcImageValueMapper");
- }
- }
-
- private Object getOutputStreamFromImage(Image o) {
- int[][] intArray = o.getImage();
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- final int height = o.getHeight();
- final int width = o.getWidth();
-
- stream.write(height);
- stream.write(width);
- for (int j = 0; j < height; j++) {
- for (int i = 0; i < width; i++) {
- // stream.write(o.getImage());
- stream.write(intArray[j][i]);
- }
- }
- return new ByteArrayInputStream(stream.toByteArray());
- }
-
- @Override
- protected Object getObjectFromResults(Results results) {
- // final String name = results.getString(columnName(0));
- InputStream binaryStream = results.getStream(columnName(1));
-
- int[][] intArray;
- try {
- int width = binaryStream.read();
- int height = binaryStream.read();
-
- intArray = new int[height][width];
- for (int j = 0; j < height; j++) {
- for (int i = 0; i < width; i++) {
- intArray[j][i] = binaryStream.read();
- }
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- intArray = new int[0][0];
- }
-
- final Image object = new Image(intArray);
-
- return object;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcMoneyValueMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcMoneyValueMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcMoneyValueMapper.java
deleted file mode 100755
index 1821795..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcMoneyValueMapper.java
+++ /dev/null
@@ -1,81 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.applib.PersistFailedException;
-import org.apache.isis.applib.value.Money;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-import org.apache.isis.objectstore.sql.mapping.FieldMappingFactory;
-
-/**
- * Money needs to implement a two-column persistence, 1 for amount, 1 for
- * 3-digit currency
- *
- * @version $Rev$ $Date$
- */
-public class JdbcMoneyValueMapper extends AbstractJdbcMultiFieldMapping {
-
- public static class Factory implements FieldMappingFactory {
- private final String type1;
- private final String type2;
-
- public Factory(final String type1, final String type2) {
- this.type1 = type1;
- this.type2 = type2;
- }
-
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- return new JdbcMoneyValueMapper(field, type1, type2);
- }
- }
-
- public JdbcMoneyValueMapper(final ObjectAssociation field, final String type1, final String type2) {
- super(field, 2, type1, type2);
- }
-
- @Override
- protected Object preparedStatementObject(final int index, final Object o) {
-
- if (o instanceof Money) {
- if (index == 0) {
- return ((Money) o).doubleValue();
- } else {
- return ((Money) o).getCurrency();
- }
- } else {
- throw new PersistFailedException("Invalid object type " + o.getClass().getCanonicalName() + " for MoneyValueMapper");
- }
- }
-
- @Override
- protected Object getObjectFromResults(final Results results) {
- final double doubleValue = results.getDouble(columnName(0));
- final String currencyValue = results.getString(columnName(1));
-
- final Money moneyObject = new Money(doubleValue, currencyValue);
-
- return moneyObject;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceFieldMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceFieldMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceFieldMapping.java
deleted file mode 100644
index db826c4..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceFieldMapping.java
+++ /dev/null
@@ -1,101 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-public class JdbcObjectReferenceFieldMapping extends JdbcObjectReferenceMapping implements FieldMapping {
-
- public static class Factory extends AbstractFieldMappingFactory {
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- if (field.getSpecification().isAbstract()) {
- final String dataType = getTypeOverride(object, field, Defaults.TYPE_LONG_STRING());
- return new JdbcAbstractReferenceFieldMapping(field, dataType);
- }
- return new JdbcObjectReferenceFieldMapping(field);
- }
- }
-
- protected final ObjectAssociation field;
-
- @Override
- public ObjectAssociation getField() {
- return field;
- }
-
- @Override
- public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- final ObjectAdapter fieldValue = field.get(object);
- final RootOid oid = (RootOid) fieldValue.getOid();
- appendWhereClause(connector, sql, oid);
- }
-
- @Override
- public void appendWhereObject(final DatabaseConnector connector, final ObjectAdapter objectAdapter) {
- final ObjectAdapter fieldValue = field.get(objectAdapter);
- final RootOid oid = (RootOid) fieldValue.getOid();
- connector.addToQueryValues(primaryKey(oid));
- }
-
- public JdbcObjectReferenceFieldMapping(final ObjectAssociation field) {
- super(columnName(field), field.getSpecification());
- this.field = field;
- }
-
- private static String columnName(final ObjectAssociation field) {
- return Sql.sqlFieldName(field.getId());
- }
-
- @Override
- public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sb, final ObjectAdapter object) {
- final ObjectAdapter fieldValue = field.get(object);
- super.appendInsertValues(connector, sb, fieldValue);
- }
-
- @Override
- public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- final ObjectAdapter fieldValue = field.get(object);
- super.appendUpdateValues(connector, sql, fieldValue);
- }
-
- @Override
- public void initializeField(final ObjectAdapter object, final Results rs) {
- final ObjectAdapter reference = initializeField(rs);
- ((OneToOneAssociation) field).initAssociation(object, reference);
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln(field.getId(), getColumn());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMapping.java
deleted file mode 100644
index 95a02b5..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMapping.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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.IdMappingAbstract;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.SqlObjectStoreException;
-import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
-
-public class JdbcObjectReferenceMapping extends IdMappingAbstract implements ObjectReferenceMapping {
- private final ObjectSpecification specification;
-
- public JdbcObjectReferenceMapping(final String columnName, final ObjectSpecification specification) {
- this.specification = specification;
- final String idColumn = Sql.sqlName("fk_" + columnName);
- setColumn(idColumn);
- }
-
- @Override
- public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter adapter) {
- sql.append(getColumn());
- if (adapter == null) {
- sql.append("= NULL ");
- } else {
- sql.append("= ?");
- // sql.append(primaryKey(object.getOid()));
- final RootOid oid = (RootOid) adapter.getOid();
- connector.addToQueryValues(primaryKey(oid));
- }
- }
-
- public ObjectAdapter initializeField(final Results rs) {
- final Oid oid = recreateOid(rs, specification);
- if (oid != null) {
- if (specification.isAbstract()) {
- throw new SqlObjectStoreException("NOT DEALING WITH POLYMORPHIC ASSOCIATIONS");
- } else {
- return getAdapter(specification, oid);
- }
- } else {
- return null;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMappingFactory.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMappingFactory.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMappingFactory.java
deleted file mode 100644
index e2e1d23..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcObjectReferenceMappingFactory.java
+++ /dev/null
@@ -1,33 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
-import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMappingFactory;
-
-public class JdbcObjectReferenceMappingFactory implements ObjectReferenceMappingFactory {
-
- @Override
- public ObjectReferenceMapping createReferenceMapping(final String columnName, final ObjectSpecification specification) {
- return new JdbcObjectReferenceMapping(columnName, specification);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPasswordValueMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPasswordValueMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPasswordValueMapper.java
deleted file mode 100644
index 0c2bd4e..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPasswordValueMapper.java
+++ /dev/null
@@ -1,106 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.applib.value.Password;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.objectstore.sql.AbstractFieldMappingFactory;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.jdbc.helpers.SimplePasswordEncoderDecoder;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-/**
- * Implements a Password string type that stores the passwords with a simple encoding in the database.
- *
- * @version $Rev$ $Date$
- */
-public class JdbcPasswordValueMapper extends AbstractJdbcFieldMapping {
-
- public static class Factory extends AbstractFieldMappingFactory {
- private final String type;
- private final String passwordSeed;
- private final Integer encLength;
-
- public Factory(final String type, final String passwordSeed, final Integer encLength) {
- super();
- this.type = type;
- this.passwordSeed = passwordSeed;
- this.encLength = encLength;
- }
-
- @Override
- public FieldMapping createFieldMapping(final ObjectSpecification object, final ObjectAssociation field) {
- final String dataType = getTypeOverride(object, field, type);
- return new JdbcPasswordValueMapper(field, dataType, passwordSeed, encLength);
- }
- }
-
- private final String type;
-
- private final SimplePasswordEncoderDecoder simplePasswordEncoderDecoder;
-
- public JdbcPasswordValueMapper(final ObjectAssociation field, final String type, final String passwordSeed,
- final Integer encLength) {
- super(field);
- this.type = type;
-
- simplePasswordEncoderDecoder = new SimplePasswordEncoderDecoder(passwordSeed, encLength);
- }
-
- /*
- * @see org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping#columnType()
- */
- @Override
- protected String columnType() {
- return type;
- }
-
- /*
- * @see
- * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping#preparedStatementObject(org.apache
- * .isis.core.metamodel.adapter.ObjectAdapter)
- */
- @Override
- protected Object preparedStatementObject(ObjectAdapter value) {
- if (value == null) {
- return null;
- }
- final Object o = value.getObject();
- final String rawPassword = ((Password) o).getPassword();
- return simplePasswordEncoderDecoder.encodeRawValueIntoEncodedString(rawPassword);
- }
-
- /*
- * @see
- * org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.AbstractJdbcFieldMapping#setFromDBColumn(org.apache.isis.
- * runtimes.dflt.objectstores.sql.Results, java.lang.String,
- * org.apache.isis.core.metamodel.spec.feature.ObjectAssociation)
- */
- @Override
- protected ObjectAdapter setFromDBColumn(Results results, String columnName, ObjectAssociation field) {
- final String encodedValue = results.getString(columnName);
- if (encodedValue == null) {
- return null;
- }
- final EncodableFacet facet = field.getSpecification().getFacet(EncodableFacet.class);
- return facet.fromEncodedString(simplePasswordEncoderDecoder.decodeEncodedValueIntoRawString(encodedValue));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java
deleted file mode 100755
index cf6c419..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java
+++ /dev/null
@@ -1,71 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.IdMappingAbstract;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.SqlObjectStoreException;
-import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
-
-public class JdbcPolymorphicObjectReferenceMapping extends IdMappingAbstract implements ObjectReferenceMapping {
- private ObjectSpecification specification;
-
- public JdbcPolymorphicObjectReferenceMapping(final String columnName) {
- final String idColumn = Sql.sqlName(columnName);
- setColumn(idColumn);
- }
-
- public void setObjectSpecification(final ObjectSpecification specification) {
- this.specification = specification;
- }
-
- @Override
- public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter adapter) {
- sql.append(getColumn());
- if (adapter == null) {
- sql.append("= NULL ");
- } else {
- sql.append("= ?");
- // sql.append(primaryKey(object.getOid()));
- final RootOid oid = (RootOid) adapter.getOid();
- connector.addToQueryValues(primaryKey(oid));
- }
- }
-
- public ObjectAdapter initializeField(final Results rs) {
- final Oid oid = recreateOid(rs, specification);
- if (oid != null) {
- if (specification.isAbstract()) {
- throw new SqlObjectStoreException("NOT DEALING WITH POLYMORPHIC ASSOCIATIONS");
- } else {
- return getAdapter(specification, oid);
- }
- } else {
- return null;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcResults.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcResults.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcResults.java
deleted file mode 100644
index 8fb81a8..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcResults.java
+++ /dev/null
@@ -1,232 +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.isis.objectstore.sql.jdbc;
-
-import java.io.InputStream;
-import java.sql.CallableStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Calendar;
-import java.util.HashMap;
-
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.format.DateTimeFormat;
-import org.joda.time.format.DateTimeFormatter;
-
-import org.apache.isis.applib.value.Date;
-import org.apache.isis.applib.value.Time;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.SqlObjectStoreException;
-
-public class JdbcResults implements Results {
- ResultSet set;
-
- public JdbcResults(final CallableStatement statement) {
- }
-
- public JdbcResults(final ResultSet set) {
- this.set = set;
- }
-
- @Override
- public void close() {
- try {
- set.close();
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public int getInt(final String columnName) {
- try {
- return set.getInt(columnName);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public long getLong(final String columnName) {
- try {
- return set.getLong(columnName);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public String getString(final String columnName) {
- try {
- return set.getString(columnName);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public boolean next() {
- try {
- return set.next();
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public java.sql.Date getJavaDateOnly(final String columnName) {
- try {
- // 2010-03-05 = 1267747200000
- // 2010-04-08 = 1270684800000
- // This is really painful! Java refuses to create java.util.Date in
- // UTC!
- // It creates java.util.Dates in Local time-zone, but assumes the DB
- // date is UTC.
- final String string = set.getString(columnName);
- final DateTime utcDate = new DateTime(string, Defaults.getTimeZone());
- final java.sql.Date date = new java.sql.Date(utcDate.getMillis());
- return date;
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public java.sql.Time getJavaTimeOnly(final String columnName) {
- try {
- final String string = set.getString(columnName);
-
- final DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss");
-
- final DateTime utcDate = formatter.withZone(Defaults.getTimeZone()).parseDateTime(string);
- final java.sql.Time time = new java.sql.Time(utcDate.getMillis());
-
- return time;
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public java.util.Date getJavaDateTime(final String columnName, final Calendar calendar) {
- try {
- return set.getDate(columnName, calendar);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public Object getObject(final String columnName) {
- try {
- return set.getObject(columnName);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public Date getDate(final String columnName) {
- try {
- // 2010-03-05 = 1267747200000
- // 2010-04-08 = 1270684800000
- // This is really painful! Java refuses to create java.util.Date in
- // UTC!
- // It creates java.util.Dates in Local time-zone, but assumes the DB
- // date is UTC.
- final String string = set.getString(columnName);
- final DateTime utcDate = new DateTime(string, Defaults.getTimeZone());
- return new Date(utcDate);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public Time getTime(final String columnName) {
- try {
- final String string = set.getString(columnName);
- final DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss");
- final DateTimeZone defaultTimeZone = Defaults.getTimeZone();
- final DateTime utcDate = formatter.withZone(defaultTimeZone).parseDateTime(string);
- return new Time(utcDate);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public double getDouble(final String columnName) {
- try {
- return set.getDouble(columnName);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public Object getAsType(final String columnName, final Class<?> clazz) {
- try {
- final HashMap<String, Class<?>> map = new HashMap<String, Class<?>>();
- map.put("FLOAT", float.class);
- return set.getObject(columnName, map);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public Float getFloat(final String columnName) {
- try {
- return set.getFloat(columnName);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public Short getShort(final String columnName) {
- try {
- return set.getShort(columnName);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public Boolean getBoolean(final String columnName) {
- try {
- return set.getBoolean(columnName);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-
- @Override
- public InputStream getStream(String column) {
- try {
- return set.getBinaryStream(column);
- } catch (final SQLException e) {
- throw new SqlObjectStoreException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcSqlMetaData.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcSqlMetaData.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcSqlMetaData.java
deleted file mode 100644
index 0efd9fe..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/JdbcSqlMetaData.java
+++ /dev/null
@@ -1,86 +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.isis.objectstore.sql.jdbc;
-
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
-
-import org.apache.isis.objectstore.sql.SqlMetaData;
-
-public class JdbcSqlMetaData implements SqlMetaData {
-
- private final boolean hasQuoteString;
- private final String quoteString;
- private final String keywords;
- private final String timeDateFunctions;
- private final boolean storesLowerCaseIdentifiers;
- private final boolean storesMixedCaseIdentifiers;
- private final boolean storesUpperCaseIdentifiers;
-
- public JdbcSqlMetaData(final DatabaseMetaData metaData) throws SQLException {
- keywords = metaData.getSQLKeywords();
- timeDateFunctions = metaData.getTimeDateFunctions();
- quoteString = metaData.getIdentifierQuoteString();
- hasQuoteString = (quoteString != " ");
- storesLowerCaseIdentifiers = metaData.storesLowerCaseIdentifiers();
- storesMixedCaseIdentifiers = metaData.storesMixedCaseIdentifiers();
- storesUpperCaseIdentifiers = metaData.storesUpperCaseIdentifiers();
-
- }
-
- @Override
- public String getKeywords() {
- return keywords;
- }
-
- @Override
- public String getTimeDateFunctions() {
- return timeDateFunctions;
- }
-
- @Override
- public String getQuoteString() {
- return quoteString;
- }
-
- @Override
- public boolean isStoresLowerCaseIdentifiers() {
- return storesLowerCaseIdentifiers;
- }
-
- @Override
- public boolean isStoresMixedCaseIdentifiers() {
- return storesMixedCaseIdentifiers;
- }
-
- @Override
- public boolean isStoresUpperCaseIdentifiers() {
- return storesUpperCaseIdentifiers;
- }
-
- @Override
- public String quoteIdentifier(final String identifier) {
- if (hasQuoteString) {
- return quoteString + identifier + quoteString;
- } else {
- return identifier;
- }
- }
-}
[11/13] ISIS-522: mothballing SQL OS.
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapper.java
deleted file mode 100644
index 54efdec..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapper.java
+++ /dev/null
@@ -1,514 +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.isis.objectstore.sql.auto;
-
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.Vector;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.applib.Identifier;
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.commons.debug.DebuggableWithTitle;
-import org.apache.isis.core.commons.lang.MethodExtensions;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
-import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-import org.apache.isis.core.metamodel.facets.notpersisted.NotPersistedFacet;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.ObjectSpecificationException;
-import org.apache.isis.core.metamodel.spec.feature.Contributed;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
-import org.apache.isis.core.runtime.persistence.PersistorUtil;
-import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByPattern;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.CollectionMapper;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.FieldMappingLookup;
-import org.apache.isis.objectstore.sql.IdMapping;
-import org.apache.isis.objectstore.sql.ObjectMapping;
-import org.apache.isis.objectstore.sql.ObjectMappingLookup;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.SqlObjectStoreException;
-import org.apache.isis.objectstore.sql.TitleMapping;
-import org.apache.isis.objectstore.sql.VersionMapping;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-public class AutoMapper extends AbstractAutoMapper implements ObjectMapping, DebuggableWithTitle {
-
- private static final Logger LOG = LoggerFactory.getLogger(AutoMapper.class);
- private final IdMapping idMapping;
- private final VersionMapping versionMapping;
- private final TitleMapping titleMapping;
- private final boolean useVersioning;
-
- public AutoMapper(final String className, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup) {
- super(className, parameterBase, lookup, objectMapperLookup);
- idMapping = lookup.createIdMapping();
- versionMapping = lookup.createVersionMapping();
- titleMapping = lookup.createTitleMapping();
-
- useVersioning = Defaults.useVersioning(specification.getShortIdentifier());
-
- setUpFieldMappers();
- }
-
- protected VersionMapping getVersionMapping() {
- return versionMapping;
- }
-
- protected IdMapping getIdMapping() {
- return idMapping;
- }
-
- @Override
- public void createTables(final DatabaseConnector connection) {
- if (!connection.hasTable(table)) {
- final StringBuffer sql = new StringBuffer();
- sql.append("create table ");
- sql.append(table);
- sql.append(" (");
- idMapping.appendCreateColumnDefinitions(sql);
- sql.append(", ");
- for (final FieldMapping mapping : fieldMappingByField.values()) {
- mapping.appendColumnDefinitions(sql);
- sql.append(",");
- }
- titleMapping.appendColumnDefinitions(sql);
- sql.append(", ");
- sql.append(versionMapping.appendColumnDefinitions());
- sql.append(")");
- connection.update(sql.toString());
- }
- for (int i = 0; collectionMappers != null && i < collectionMappers.length; i++) {
- if (collectionMappers[i].needsTables(connection)) {
- collectionMappers[i].createTables(connection);
- }
- }
- }
-
- @Override
- public void createObject(final DatabaseConnector connector, final ObjectAdapter object) {
- final int versionSequence = 1;
- final Version version = createVersion(versionSequence);
-
- final StringBuffer sql = new StringBuffer();
- sql.append("insert into " + table + " (");
- idMapping.appendColumnNames(sql);
- sql.append(", ");
- final String columnList = columnList(fieldMappingByField);
- if (columnList.length() > 0) {
- sql.append(columnList);
- sql.append(", ");
- }
- titleMapping.appendColumnNames(sql);
- sql.append(", ");
- sql.append(versionMapping.insertColumns());
- sql.append(") values (");
- idMapping.appendInsertValues(connector, sql, object);
- sql.append(", ");
- sql.append(values(connector, object));
- titleMapping.appendInsertValues(connector, sql, object);
- sql.append(", ");
- sql.append(versionMapping.insertValues(connector, version));
- sql.append(") ");
-
- connector.insert(sql.toString());
- object.setVersion(version);
-
- for (final CollectionMapper collectionMapper : collectionMappers) {
- collectionMapper.saveInternalCollection(connector, object);
- }
- }
-
- @Override
- public void destroyObject(final DatabaseConnector connector, final ObjectAdapter adapter) {
- final StringBuffer sql = new StringBuffer();
- sql.append("delete from " + table + " WHERE ");
- final RootOid oid = (RootOid) adapter.getOid();
- idMapping.appendWhereClause(connector, sql, oid);
- sql.append(" AND ");
- sql.append(versionMapping.whereClause(connector, adapter.getVersion()));
- final int updateCount = connector.update(sql.toString());
- if (updateCount == 0) {
- LOG.info("concurrency conflict object " + this + "; no deletion performed");
- throw new ConcurrencyException("", adapter.getOid());
- }
- }
-
- @Override
- public Vector<ObjectAdapter> getInstances(final DatabaseConnector connector, final ObjectSpecification spec,
- final long startIndex, final long rowCount) {
- final StringBuffer sql = createSelectStatement();
- final Vector<ObjectAdapter> instances = new Vector<ObjectAdapter>();
- loadInstancesToVector(connector, spec, completeSelectStatement(sql, startIndex, rowCount), instances);
- return instances;
- }
-
- @Override
- public Vector<ObjectAdapter> getInstances(final DatabaseConnector connector, final ObjectSpecification spec,
- final PersistenceQueryFindByPattern query) {
- final Vector<ObjectAdapter> instances = new Vector<ObjectAdapter>();
-
- final StringBuffer sql = createSelectStatement();
- int initialLength = 0;
-
- int foundFields = 0;
- final ObjectAdapter pattern = query.getPattern();
-
- // for all fields in the query.getPattern, build a SQL select clause for
- // this spec.
- final Object o = pattern.getObject();
- final ObjectSpecification patternSpec = pattern.getSpecification();
- final List<ObjectAssociation> patternAssociations = patternSpec.getAssociations(Contributed.EXCLUDED);
- for (final ObjectAssociation patternAssoc : patternAssociations) {
- final Method method;
- final Identifier identifier = patternAssoc.getIdentifier();
- final String memberName = identifier.getMemberName();
- final String methodName = memberName.substring(0, 1).toUpperCase() + memberName.substring(1);
-
- try {
- if (true) {
- final ObjectAdapter field = patternAssoc.get(pattern);
- if (field != null) {
- final String id = patternAssoc.getId();
- try {
- final ObjectAssociation oa = spec.getAssociation(id);
- final NotPersistedFacet fc = oa.getFacet(NotPersistedFacet.class);
- if (fc != null) {
- continue;
- }
- } catch (final ObjectSpecificationException e) {
- // this is OK
- }
-
- if (foundFields == 0) {
- sql.append(" WHERE ");
- initialLength = sql.length();
- }
-
- if (sql.length() > initialLength) {
- sql.append(" AND ");
- }
-
- final FieldMapping fieldMapping = fieldMappingFor(patternAssoc);
- if (fieldMapping != null) {
- fieldMapping.appendWhereClause(connector, sql, pattern);
- } else {
- // Have to use getXXX method if the fieldMapping is
- // null..
- final ObjectSpecification specification = patternAssoc.getSpecification();
-
- method = o.getClass().getMethod("get" + methodName, (Class<?>[]) null);
- final Object res = MethodExtensions.invoke(method, o);
-
- if (specification.isValue()) {
- // If the property (memberName) is a value type,
- // use the value.
- final String fieldName = Sql.sqlFieldName(identifier.getMemberName());
- sql.append(fieldName + "=?");
- connector.addToQueryValues(res);
- } else {
- throw new SqlObjectStoreException("Unhandled combination!");
- }
- }
- foundFields++;
- }
- }
- } catch (final SecurityException e) {
- LOG.debug(e.getMessage());
- } catch (final NoSuchMethodException e) {
- LOG.info("Unable to invode method: get" + methodName + " in getInstances");
- LOG.debug(e.getMessage());
- }
- }
- // if (foundFields > 0) {
- loadInstancesToVector(connector, spec, completeSelectStatement(sql, query.getStart(), query.getCount()), instances);
- // }
- return instances;
- }
-
- @Override
- public Vector<ObjectAdapter> getInstances(final DatabaseConnector connector, final ObjectSpecification spec,
- final String title, final long startIndex, final long rowCount) {
- final Vector<ObjectAdapter> instances = new Vector<ObjectAdapter>();
-
- final StringBuffer sql = createSelectStatement();
- sql.append(" WHERE ");
- titleMapping.appendWhereClause(sql, title);
- loadInstancesToVector(connector, spec, completeSelectStatement(sql, startIndex, rowCount), instances);
- return instances;
- }
-
- @Override
- public ObjectAdapter getObject(final DatabaseConnector connector, final TypedOid typedOid) {
- final StringBuffer sql = createSelectStatement();
- sql.append(" WHERE ");
- idMapping.appendWhereClause(connector, sql, (RootOid) typedOid);
- final Results rs = connector.select(completeSelectStatement(sql, 0, 0));
- final ObjectSpecification objectSpec = getSpecificationLoader().lookupBySpecId(typedOid.getObjectSpecId());
- if (rs.next()) {
- return loadMappedObject(connector, objectSpec, rs);
- } else {
- throw new ObjectNotFoundException("No object with with " + typedOid + " in table " + table);
- }
- }
-
- @Override
- public boolean hasInstances(final DatabaseConnector connector, final ObjectSpecification cls) {
- final String statement = "select count(*) from " + table;
- final int instances = connector.count(statement);
- return instances > 0;
- }
-
- private StringBuffer createSelectStatement() {
- final StringBuffer sql = new StringBuffer();
- sql.append("select ");
- idMapping.appendColumnNames(sql);
- sql.append(", ");
- final String columnList = columnList(fieldMappingByField);
- if (columnList.length() > 0) {
- sql.append(columnList);
- sql.append(", ");
- }
- sql.append(versionMapping.insertColumns());
- sql.append(" from " + table);
- return sql;
- } /*
- * if (whereClause != null) { sql.append(" WHERE ");
- * sql.append(whereClause); } else if (whereClause != null) {
- * sql.append(" WHERE "); idMapping.appendWhereClause(sql, oid); }
- */
-
- private String completeSelectStatement(final StringBuffer sql, final long startIndex, final long rowCount) {
- sql.append(" order by ");
- idMapping.appendColumnNames(sql);
-
- if ((startIndex != 0) || (rowCount != 0)) {
- sql.append(" ");
- sql.append(Defaults.getLimitsClause(startIndex, rowCount));
- }
-
- return sql.toString();
- }
-
- protected void loadFields(final ObjectAdapter adapter, final Results rs) {
- PersistorUtil.startResolving(adapter);
- try {
- for (final FieldMapping mapping : fieldMappingByField.values()) {
- mapping.initializeField(adapter, rs);
- }
- /*
- * for (int i = 0; i < oneToManyProperties.length; i++) { /* Need to
- * set up collection to be a ghost before we access as below
- */
- // CollectionAdapter collection = (CollectionAdapter)
- /*
- * oneToManyProperties[i].get(object); }
- */
- adapter.setVersion(versionMapping.getLock(rs));
- } finally {
- PersistorUtil.toEndState(adapter);
- }
- }
-
- // KAM
- private void loadCollections(final DatabaseConnector connector, final ObjectAdapter instance) {
-
- for (final CollectionMapper mapper : collectionMappers) {
- mapper.loadInternalCollection(connector, instance);
- }
- }
-
- private void loadInstancesToVector(final DatabaseConnector connector, final ObjectSpecification cls, final String selectStatment, final Vector<ObjectAdapter> instances) {
- LOG.debug("loading instances from SQL " + table);
-
- try {
- final Results rs = connector.select(selectStatment);
- final int maxInstances = Defaults.getMaxInstances();
- for (int count = 0; rs.next() && count < maxInstances; count++) {
- final ObjectAdapter instance = loadMappedObject(connector, cls, rs);
- LOG.debug(" instance " + instance);
- instances.addElement(instance);
- }
- rs.close();
- } catch (final SqlObjectStoreException e) {
- // Invalid SELECT means no object found.. don't worry about it,
- // here.
- }
- }
-
- private ObjectAdapter loadMappedObject(final DatabaseConnector connector, final ObjectSpecification cls, final Results rs) {
- final Oid oid = idMapping.recreateOid(rs, specification);
- final ObjectAdapter adapter = getAdapter(cls, oid);
-
- if (adapter.canTransitionToResolving()) {
- loadFields(adapter, rs);
- loadCollections(connector, adapter); // KAM
- }
- return adapter;
- }
-
- @Override
- public void resolve(final DatabaseConnector connector, final ObjectAdapter object) {
- LOG.debug("loading data from SQL " + table + " for " + object);
- final StringBuffer sql = new StringBuffer();
- sql.append("select ");
- sql.append(columnList(fieldMappingByField));
- sql.append(",");
- sql.append(versionMapping.appendColumnNames());
- sql.append(" from " + table + " WHERE ");
- final RootOid oid = (RootOid) object.getOid();
- idMapping.appendWhereClause(connector, sql, oid);
-
- final Results rs = connector.select(sql.toString());
- if (rs.next()) {
- loadFields(object, rs);
- rs.close();
-
- for (final CollectionMapper collectionMapper : collectionMappers) {
- collectionMapper.loadInternalCollection(connector, object);
- }
- } else {
- rs.close();
- throw new SqlObjectStoreException("Unable to load data from " + table + " with id " + object.getOid().enString(getOidMarshaller()));
- }
- }
-
- @Override
- public void resolveCollection(final DatabaseConnector connector, final ObjectAdapter object, final ObjectAssociation field) {
- if (collectionMappers.length > 0) {
- final DatabaseConnector secondConnector = connector.getConnectionPool().acquire();
- for (final CollectionMapper collectionMapper : collectionMappers) {
- collectionMapper.loadInternalCollection(secondConnector, object);
- }
- connector.getConnectionPool().release(secondConnector);
- }
- }
-
- @Override
- public void startup(final DatabaseConnector connector, final ObjectMappingLookup objectMapperLookup) {
- if (needsTables(connector)) {
- createTables(connector);
- }
- }
-
- @Override
- public void save(final DatabaseConnector connector, final ObjectAdapter adapter) {
- final Version version = adapter.getVersion();
- final long nextSequence;
- if (useVersioning) {
- nextSequence = version.getSequence() + 1;
- } else {
- nextSequence = version.getSequence();
- }
-
- final StringBuffer sql = new StringBuffer();
- sql.append("UPDATE " + table + " SET ");
- for (final FieldMapping mapping : fieldMappingByField.values()) {
- mapping.appendUpdateValues(connector, sql, adapter);
- sql.append(", ");
- }
- sql.append(versionMapping.updateAssigment(connector, nextSequence));
- sql.append(", ");
- titleMapping.appendUpdateAssignment(connector, sql, adapter);
- sql.append(" WHERE ");
- final RootOid oid = (RootOid) adapter.getOid();
- idMapping.appendWhereClause(connector, sql, oid);
- if (useVersioning) {
- sql.append(" AND ");
- sql.append(versionMapping.whereClause(connector, adapter.getVersion()));
- }
-
- final int updateCount = connector.update(sql.toString());
- if (updateCount == 0) {
- LOG.info("concurrency conflict object " + this + "; no update performed");
- throw new ConcurrencyException("", adapter.getOid());
- } else {
- adapter.setVersion(createVersion(nextSequence));
- }
-
- // TODO update collections - change only when needed rather than
- // reinserting from scratch
- for (final CollectionMapper collectionMapper : collectionMappers) {
- collectionMapper.saveInternalCollection(connector, adapter);
- }
- }
-
- @Override
- public boolean saveCollection(final DatabaseConnector connection, final ObjectAdapter parent, final String fieldName) {
- int i = 0;
- for (final String collectionFieldName : collectionMapperFields) {
- if (collectionFieldName.equals(fieldName)) {
- final CollectionMapper fieldMapper = collectionMappers[i];
- fieldMapper.saveInternalCollection(connection, parent);
- return true;
- }
- i++;
- }
- return false;
- }
-
- // //////////////////////////////////////////////////////////////
- // debugging, toString
- // //////////////////////////////////////////////////////////////
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln("ID mapping", idMapping);
- debug.appendln("ID mapping", versionMapping);
- debug.appendln("ID mapping", titleMapping);
- for (final FieldMapping mapping : fieldMappingByField.values()) {
- mapping.debugData(debug);
- }
- for (final CollectionMapper collectionMapper : collectionMappers) {
- collectionMapper.debugData(debug);
- }
-
- }
-
- @Override
- public String debugTitle() {
- return toString();
- }
-
- @Override
- public String toString() {
- return "AutoMapper [table=" + table + ",id=" + idMapping + ",noColumns=" + fieldMappingByField.size() + ",specification=" + specification.getFullIdentifier() + "]";
- }
-
- // //////////////////////////////////////////////////////////////
- // dependencies (from context)
- // //////////////////////////////////////////////////////////////
-
- protected OidMarshaller getOidMarshaller() {
- return IsisContext.getOidMarshaller();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapperFactory.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapperFactory.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapperFactory.java
deleted file mode 100644
index 2fbc0a9..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoMapperFactory.java
+++ /dev/null
@@ -1,32 +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.isis.objectstore.sql.auto;
-
-import org.apache.isis.objectstore.sql.FieldMappingLookup;
-import org.apache.isis.objectstore.sql.ObjectMapping;
-import org.apache.isis.objectstore.sql.ObjectMappingFactory;
-import org.apache.isis.objectstore.sql.ObjectMappingLookup;
-
-public class AutoMapperFactory implements ObjectMappingFactory {
- @Override
- public ObjectMapping createMapper(final String className, final String propertiesBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup) {
- return new AutoMapper(className, propertiesBase, lookup, objectMapperLookup);
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java
deleted file mode 100644
index c5fa9d5..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java
+++ /dev/null
@@ -1,388 +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.isis.objectstore.sql.auto;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.persistence.PersistorUtil;
-import org.apache.isis.objectstore.sql.CollectionMapper;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.FieldMappingLookup;
-import org.apache.isis.objectstore.sql.IdMapping;
-import org.apache.isis.objectstore.sql.IdMappingAbstract;
-import org.apache.isis.objectstore.sql.ObjectMapping;
-import org.apache.isis.objectstore.sql.ObjectMappingLookup;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.VersionMapping;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
-
-/**
- * Stores 1-to-many collections by creating a foreign-key column in the table for the incoming objectAssociation class.
- * This assumes this the class is only ever in 1 collection parent.
- *
- * @version $Rev$ $Date$
- */
-public class ForeignKeyCollectionMapper extends AbstractAutoMapper implements CollectionMapper {
- private static final Logger LOG = LoggerFactory.getLogger(ForeignKeyCollectionMapper.class);
- private final ObjectAssociation field;
- private final IdMapping idMapping;
- private final VersionMapping versionMapping;
- private final ObjectReferenceMapping foreignKeyMapping;
- private String foreignKeyName;
- private String columnName;
- private final ObjectMappingLookup objectMapperLookup2;
-
- private ObjectMapping originalMapping = null;
-
- public ForeignKeyCollectionMapper(final ObjectAssociation objectAssociation, final String parameterBase,
- final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup) {
- super(objectAssociation.getSpecification().getFullIdentifier(), parameterBase, lookup, objectMapperLookup);
-
- this.field = objectAssociation;
-
- objectMapperLookup2 = objectMapperLookup;
-
- idMapping = lookup.createIdMapping();
- versionMapping = lookup.createVersionMapping();
-
- setColumnName(determineColumnName(objectAssociation));
- foreignKeyName = Sql.sqlName("fk_" + getColumnName());
-
- foreignKeyName = Sql.identifier(foreignKeyName);
- foreignKeyMapping = lookup.createMapping(columnName, specification);
- }
-
- protected ForeignKeyCollectionMapper(final FieldMappingLookup lookup, final AbstractAutoMapper abstractAutoMapper,
- final ObjectAssociation field) {
- super(lookup, abstractAutoMapper, field.getSpecification().getFullIdentifier());
-
- this.field = field;
- objectMapperLookup2 = null;
-
- idMapping = lookup.createIdMapping();
- versionMapping = lookup.createVersionMapping();
-
- setColumnName(determineColumnName(field));
- foreignKeyName = Sql.sqlName("fk_" + getColumnName());
-
- foreignKeyName = Sql.identifier(foreignKeyName);
- foreignKeyMapping = lookup.createMapping(columnName, specification);
- }
-
- protected String determineColumnName(final ObjectAssociation objectAssociation) {
- return objectAssociation.getSpecification().getShortIdentifier();
- }
-
- public String getColumnName() {
- return columnName;
- }
-
- public void setColumnName(final String columnName) {
- this.columnName = columnName;
- }
-
- protected VersionMapping getVersionMapping() {
- return versionMapping;
- }
-
- protected ObjectReferenceMapping getForeignKeyMapping() {
- return foreignKeyMapping;
- }
-
- protected String getForeignKeyName() {
- return foreignKeyName;
- }
-
- @Override
- public void startup(final DatabaseConnector connector) {
- if (originalMapping == null) {
- originalMapping = objectMappingLookup.getMapping(specification, null);
- }
- originalMapping.startup(connector, objectMapperLookup2);
- super.startup(connector);
- }
-
- @Override
- public boolean needsTables(final DatabaseConnector connection) {
- return !connection.hasColumn(table, foreignKeyName);
- }
-
- @Override
- public void createTables(final DatabaseConnector connection) {
- if (connection.hasTable(table)) {
- final StringBuffer sql = new StringBuffer();
- sql.append("alter table ");
- sql.append(table);
- sql.append(" add ");
- appendColumnDefinitions(sql);
- connection.update(sql.toString());
- } else {
- final StringBuffer sql = new StringBuffer();
- sql.append("create table ");
- sql.append(table);
- sql.append(" (");
- idMapping.appendCreateColumnDefinitions(sql);
- sql.append(", ");
-
- appendColumnDefinitions(sql);
-
- // for (final FieldMapping mapping : fieldMappings) {
- // mapping.appendColumnDefinitions(sql);
- // sql.append(",");
- // }
- // sql.append(versionMapping.appendColumnDefinitions());
- sql.append(")");
- connection.update(sql.toString());
- }
- }
-
- public IdMappingAbstract getIdMapping() {
- return idMapping;
- }
-
- protected void appendCollectionUpdateColumnsToNull(final StringBuffer sql) {
- sql.append(foreignKeyName + "=NULL ");
- }
-
- protected void appendCollectionWhereValues(final DatabaseConnector connector, final ObjectAdapter parent,
- final StringBuffer sql) {
- foreignKeyMapping.appendUpdateValues(connector, sql, parent);
- }
-
- protected void appendCollectionUpdateValues(final DatabaseConnector connector, final ObjectAdapter parent,
- final StringBuffer sql) {
- appendCollectionWhereValues(connector, parent, sql);
- }
-
- protected void appendColumnDefinitions(final StringBuffer sql) {
- foreignKeyMapping.appendColumnDefinitions(sql);
- }
-
- @Override
- public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter parentAdapter) {
-
- final ObjectAdapter collectionAdapter = field.get(parentAdapter);
- if (!collectionAdapter.canTransitionToResolving()) {
- return;
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("loading internal collection " + field);
- }
- final List<ObjectAdapter> list = new ArrayList<ObjectAdapter>();
- try {
- PersistorUtil.startResolving(collectionAdapter);
-
- loadCollectionIntoList(connector, parentAdapter, table, specification, getIdMapping(), fieldMappingByField,
- versionMapping, list);
-
- final CollectionFacet collectionFacet =
- collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
- collectionFacet.init(collectionAdapter, list.toArray(new ObjectAdapter[list.size()]));
-
- } finally {
- PersistorUtil.toEndState(collectionAdapter);
- }
-
- // TODO: Need to finalise this behaviour. At the moment, all
- // collections will get infinitely resolved. I
- // don't think this is desirable.
- for (final ObjectAdapter field : list) {
- // final ObjectMapping mapping =
- // objectMappingLookup.getMapping(field, connector);
- if (field.getSpecification().isOfType(parentAdapter.getSpecification())) {
- loadInternalCollection(connector, field);
- }
- }
- }
-
- protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent,
- final String table, final ObjectSpecification specification, final IdMappingAbstract idMappingAbstract,
- final Map<ObjectAssociation, FieldMapping> fieldMappingByField, final VersionMapping versionMapping,
- final List<ObjectAdapter> list) {
-
- final StringBuffer sql = new StringBuffer();
- sql.append("select ");
- idMappingAbstract.appendColumnNames(sql);
-
- sql.append(", ");
- final String columnList = columnList(fieldMappingByField);
- if (columnList.length() > 0) {
- sql.append(columnList);
- sql.append(", ");
- }
- sql.append(versionMapping.appendColumnNames());
- sql.append(" from ");
- sql.append(table);
- sql.append(" where ");
- appendCollectionWhereValues(connector, parent, sql);
-
- final Results rs = connector.select(sql.toString());
- while (rs.next()) {
- final Oid oid = idMappingAbstract.recreateOid(rs, specification);
- final ObjectAdapter element = getAdapter(specification, oid);
- loadFields(element, rs, fieldMappingByField);
- LOG.debug(" element " + element.getOid());
- list.add(element);
- }
- rs.close();
- }
-
- protected void loadFields(final ObjectAdapter adapter, final Results rs,
- final Map<ObjectAssociation, FieldMapping> fieldMappingByField) {
- if (!adapter.canTransitionToResolving()) {
- return;
- }
-
- try {
- PersistorUtil.startResolving(adapter);
- for (final FieldMapping mapping : fieldMappingByField.values()) {
- mapping.initializeField(adapter, rs);
- }
- adapter.setVersion(versionMapping.getLock(rs));
- } finally {
- PersistorUtil.toEndState(adapter);
- }
- }
-
- /**
- * Override this in the Polymorphic case to return just the elements that are appropriate for the subclass currently
- * being handled.
- *
- * @param collection
- * @return those elements that ought to be used.
- */
- protected Iterator<ObjectAdapter> getElementsForCollectionAsIterator(final ObjectAdapter collection) {
- final CollectionFacet collectionFacet = collection.getSpecification().getFacet(CollectionFacet.class);
- final Iterable<ObjectAdapter> elements = collectionFacet.iterable(collection);
- return elements.iterator();
- }
-
- @Override
- public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent) {
- final ObjectAdapter collection = field.get(parent);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Saving internal collection " + collection);
- }
-
- final Iterator<ObjectAdapter> elements = getElementsForCollectionAsIterator(collection);
-
- // TODO What is needed to allow a collection update (add/remove) to mark
- // the collection as dirty?
- // checkIfDirty(collection);
-
- if (elements.hasNext() == false) {
- return;
- }
-
- clearCollectionParent(connector, parent);
-
- resetCollectionParent(connector, parent, elements);
- }
-
- protected void clearCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent) {
- // Delete collection parent
- final StringBuffer sql = new StringBuffer();
- sql.append("update ");
- sql.append(table);
- sql.append(" set ");
- appendCollectionUpdateColumnsToNull(sql);
- sql.append(" where ");
- appendCollectionWhereValues(connector, parent, sql);
- connector.update(sql.toString());
- }
-
- protected void resetCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent,
- final Iterator<ObjectAdapter> elements) {
- // Reinstall collection parent
- final StringBuffer update = new StringBuffer();
- update.append("update ");
- update.append(table);
- update.append(" set ");
- appendCollectionUpdateValues(connector, parent, update);
- update.append(" where ");
-
- idMapping.appendColumnNames(update);
-
- update.append(" IN (");
-
- int count = 0;
- for (final Iterator<ObjectAdapter> iterator = elements; iterator.hasNext();) {
- final ObjectAdapter element = iterator.next();
-
- if (count++ > 0) {
- update.append(",");
- }
- final RootOid elementOid = (RootOid) element.getOid();
- idMapping.appendObjectId(connector, update, elementOid);
- }
- update.append(")");
- if (count > 0) {
- connector.insert(update.toString());
- }
- }
-
- protected void checkIfDirty(final ObjectAdapter collection) {
- // Test: is dirty?
- final ObjectSpecification collectionSpecification = collection.getSpecification();
- if (collectionSpecification.isDirty(collection)) {
- LOG.debug(collection.getOid() + " is dirty");
- } else {
- LOG.debug(collection.getOid() + " is clean");
- }
-
- final CollectionFacet collectionFacetD = collection.getSpecification().getFacet(CollectionFacet.class);
- for (final ObjectAdapter element : collectionFacetD.iterable(collection)) {
- if (collectionSpecification.isDirty(element)) {
- LOG.debug(element.getOid() + " is dirty");
- } else {
- LOG.debug(element.getOid() + " is clean");
- }
- }
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln(field.getName(), "collection");
- debug.indent();
- debug.appendln("Foreign key name", foreignKeyName);
- debug.appendln("Foreign key mapping", foreignKeyMapping);
- debug.appendln("ID mapping", idMapping);
- debug.appendln("Version mapping", versionMapping);
- debug.appendln("Original mapping", originalMapping);
- debug.unindent();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyInChildCollectionMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyInChildCollectionMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyInChildCollectionMapper.java
deleted file mode 100644
index b289450..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyInChildCollectionMapper.java
+++ /dev/null
@@ -1,89 +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.isis.objectstore.sql.auto;
-
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.metamodel.facets.FacetedMethod;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.specloader.specimpl.OneToManyAssociationImpl;
-import org.apache.isis.objectstore.sql.FieldMappingLookup;
-import org.apache.isis.objectstore.sql.ObjectMappingLookup;
-
-/**
- * Used to map 1-to-many collections by creating, in the child table, 1 column
- * per parent collection. The column is named by combining the final part of the
- * parent class name and the collection variable name.
- *
- * @author Kevin
- */
-public class ForeignKeyInChildCollectionMapper extends ForeignKeyCollectionMapper {
- private static final Logger LOG = LoggerFactory.getLogger(ForeignKeyCollectionMapper.class);
-
- protected final ObjectAssociation priorField; // prevents recursion
- protected final List<ObjectAssociation> priorFields;
-
- public ForeignKeyInChildCollectionMapper(final ObjectAssociation objectAssociation, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup, final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) {
- super(objectAssociation, parameterBase, lookup, objectMapperLookup);
-
- priorFields = abstractAutoMapper.fields;
- priorField = field;
-
- setUpFieldMappers();
- }
-
- protected ForeignKeyInChildCollectionMapper(final FieldMappingLookup lookup, final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) {
- super(lookup, abstractAutoMapper, field);
- priorFields = null;
- priorField = null;
- }
-
- @Override
- protected void getExtraFields(final List<ObjectAssociation> existingFields) {
- if (priorFields != null) {
- for (final ObjectAssociation priorField1 : priorFields) {
- if (existingFields.contains(priorField1) == false) {
- existingFields.add(priorField1);
- } else {
- LOG.debug("Skipping prior field: " + priorField1.getName());
- }
- }
- }
- }
-
- @Override
- protected String determineColumnName(final ObjectAssociation objectAssociation) {
- if (objectAssociation instanceof OneToManyAssociationImpl) {
- final OneToManyAssociationImpl fkAssoc = (OneToManyAssociationImpl) objectAssociation;
- final FacetedMethod peer = fkAssoc.getFacetedMethod();
- final String fullClassName = peer.getIdentifier().getClassName();
- final int lastPos = fullClassName.lastIndexOf('.');
- return fullClassName.substring(lastPos + 1) + "_" + fkAssoc.getId();
- } else {
- return objectAssociation.getSpecification().getShortIdentifier();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java
deleted file mode 100755
index 359a44d..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java
+++ /dev/null
@@ -1,237 +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.isis.objectstore.sql.auto;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.OidGenerator;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.Defaults;
-import org.apache.isis.objectstore.sql.FieldMappingLookup;
-import org.apache.isis.objectstore.sql.IdMappingAbstract;
-import org.apache.isis.objectstore.sql.ObjectMapping;
-import org.apache.isis.objectstore.sql.ObjectMappingLookup;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.VersionMapping;
-import org.apache.isis.objectstore.sql.jdbc.JdbcPolymorphicObjectReferenceMapping;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-/**
- * Used to map 1-to-many collections by creating, in the collection child table (which may be an interface or abstract
- * class), 2 columns per parent collection. The first column is the class type, the second is the entity ID. The columns
- * are named by combining the final part of the parent class name and the collection variable name.
- *
- * You have a choice between this class and {@link PolymorphicForeignKeyInChildCollectionMapper}
- *
- * @author Kevin
- */
-public class PolymorphicForeignKeyInChildCollectionBaseMapper extends ForeignKeyInChildCollectionMapper {
-
- private static final Logger LOG = LoggerFactory.getLogger(PolymorphicForeignKeyInChildCollectionBaseMapper.class);
-
- private final String classColumnName;
- private final String itemIdColumnName;
- private final IdMappingAbstract polyIdMapper;
-
- private final OidGenerator oidGenerator;
-
- public PolymorphicForeignKeyInChildCollectionBaseMapper(final ObjectAssociation objectAssociation,
- final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup,
- final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) {
-
- super(objectAssociation, parameterBase, lookup, objectMapperLookup, abstractAutoMapper, field);
-
- classColumnName = Sql.identifier(Sql.sqlName(getForeignKeyName() + "_cls"));
- itemIdColumnName = Sql.identifier("item_id");
-
- polyIdMapper = new JdbcPolymorphicObjectReferenceMapping(itemIdColumnName);
- oidGenerator = IsisContext.getPersistenceSession().getOidGenerator();
- }
-
- @Override
- public boolean needsTables(final DatabaseConnector connection) {
- return super.needsTables(connection) || !connection.hasColumn(table, classColumnName);
- }
-
- @Override
- public void createTables(final DatabaseConnector connection) {
- if (super.needsTables(connection)) {
- super.createTables(connection);
- }
-
- if (!connection.hasColumn(table, classColumnName)) {
- addColumn(connection, classColumnName, Defaults.TYPE_LONG_STRING());
- addColumn(connection, itemIdColumnName, Defaults.TYPE_PK());
- }
- }
-
- protected void addColumn(final DatabaseConnector connection, final String columnName, final String columnType) {
- final StringBuffer sql = new StringBuffer();
- sql.append("alter table ");
- sql.append(table);
- sql.append(" add ");
- sql.append(columnName);
- sql.append(" ");
- sql.append(columnType);
- connection.update(sql.toString());
- }
-
- @Override
- protected void appendCollectionUpdateColumnsToNull(final StringBuffer sql) {
- super.appendCollectionUpdateColumnsToNull(sql);
- sql.append(", " + classColumnName + "=NULL ");
- }
-
- @Override
- protected void appendCollectionUpdateValues(final DatabaseConnector connector, final ObjectAdapter parent,
- final StringBuffer sql) {
- super.appendCollectionUpdateValues(connector, parent, sql);
- }
-
- @Override
- protected void appendColumnDefinitions(final StringBuffer sql) {
- super.appendColumnDefinitions(sql);
- }
-
- @Override
- protected void clearCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent) {
- // Delete collection parent
- final StringBuffer sql = new StringBuffer();
- sql.append("DELETE FROM ");
- sql.append(table);
- sql.append(" WHERE ");
- appendCollectionWhereValues(connector, parent, sql);
- connector.update(sql.toString());
- }
-
- @Override
- protected void resetCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent,
- final Iterator<ObjectAdapter> elements) {
- LOG.debug("Saving polymorphic list");
-
- ObjectSpecification elementSpecification;
- while (elements.hasNext()) {
- final ObjectAdapter thisAdapter = elements.next();
- elementSpecification = thisAdapter.getSpecification();
-
- // Reinstall collection parent
- final StringBuffer update = new StringBuffer();
- update.append("INSERT INTO ");
- update.append(table);
- update.append(" (");
- // list of column names
- super.getIdMapping().appendColumnNames(update);
- update.append("," + getForeignKeyName());
- update.append(", " + itemIdColumnName);
- update.append("," + classColumnName);
- update.append(") VALUES (");
-
- // Row ID column
- final Object pojo = thisAdapter.getObject();
- final RootOid transientRootOid = oidGenerator.createTransientOid(pojo);
-
- final RootOid persistentRootOid = oidGenerator.createPersistent(pojo, transientRootOid);
-
- polyIdMapper.appendObjectId(connector, update, persistentRootOid);
-
- // polyIdMapper.appendObjectId(connector, update,
- // thisAdapter.getOid());
- update.append(",");
-
- // Foreign key ID column
- getForeignKeyMapping().appendInsertValues(connector, update, parent);
- update.append(",");
-
- // item Id column
- final RootOid oid = (RootOid) thisAdapter.getOid();
- getIdMapping().appendObjectId(connector, update, oid);
-
- // Class name column
- update.append(",?)");
- connector.addToQueryValues(elementSpecification.getFullIdentifier());
-
- connector.insert(update.toString());
- }
- }
-
- @Override
- public IdMappingAbstract getIdMapping() {
- return polyIdMapper;
- }
-
- @Override
- protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent,
- final String table, final ObjectSpecification specification, final IdMappingAbstract idMappingAbstract,
- final Map<ObjectAssociation, FieldMapping> fieldMappingByField, final VersionMapping versionMapping,
- final List<ObjectAdapter> list) {
- LOG.debug("Loading polymorphic list");
-
- final StringBuffer sql = new StringBuffer();
- sql.append("select ");
- super.getIdMapping().appendColumnNames(sql);
-
- sql.append("," + getForeignKeyName());
- sql.append("," + classColumnName);
- sql.append("," + itemIdColumnName);
-
- sql.append(" from ");
- sql.append(table);
- sql.append(" where ");
- appendCollectionWhereValues(connector, parent, sql);
-
- final Results rs = connector.select(sql.toString());
-
- final SpecificationLoaderSpi reflector = IsisContext.getSpecificationLoader();
- final JdbcPolymorphicObjectReferenceMapping idMapping =
- (JdbcPolymorphicObjectReferenceMapping) idMappingAbstract;
-
- while (rs.next()) {
- final ObjectSpecification itemSpecification = reflector.loadSpecification(rs.getString(classColumnName));
- idMapping.setObjectSpecification(itemSpecification);
-
- // Load new recordSet for the actual class
- final ObjectMapping itemMapper = objectMappingLookup.getMapping(itemSpecification, connector);
- final TypedOid oid = idMapping.recreateOid(rs, itemSpecification);
- final ObjectAdapter loadedObject = itemMapper.getObject(connector, oid);
-
- LOG.debug(" element " + loadedObject.getOid());
-
- list.add(loadedObject);
- }
- rs.close();
-
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java
deleted file mode 100755
index 4bf0928..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java
+++ /dev/null
@@ -1,205 +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.isis.objectstore.sql.auto;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.collect.Lists;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.FieldMappingLookup;
-import org.apache.isis.objectstore.sql.IdMappingAbstract;
-import org.apache.isis.objectstore.sql.ObjectMapping;
-import org.apache.isis.objectstore.sql.ObjectMappingLookup;
-import org.apache.isis.objectstore.sql.VersionMapping;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-/**
- * Used to map 1-to-many collections by creating, in the child table, 1 column
- * per parent collection. The column is named by combining the final part of the
- * parent class name and the collection variable name.
- *
- * You have a choice between this class and
- * {@link PolymorphicForeignKeyInChildCollectionBaseMapper}
- *
- * @author Kevin
- */
-public class PolymorphicForeignKeyInChildCollectionMapper extends ForeignKeyInChildCollectionMapper {
-
- private static final Logger LOG = LoggerFactory.getLogger(PolymorphicForeignKeyInChildCollectionMapper.class);
-
- private final ObjectAssociation baseField;
- private final List<String> tables;
- private final List<ObjectSpecification> tableSpecifications;
- private final List<ObjectMapping> subClassMappers;
-
- // For iterating through the subclasses
- private ObjectSpecification currentTableSpecification;
- private Iterator<ObjectAdapter> currentIterator;
- private List<ObjectAdapter> currentCollection;
- private int currentIndexStart;
- private int currentIndex;
-
- // Store for passing on to other mappers
- final String parameterBase;
- final FieldMappingLookup lookup;
- final ObjectMappingLookup objectMapperLookup;
- final String fieldClassName;
-
- public PolymorphicForeignKeyInChildCollectionMapper(final ObjectAssociation objectAssociation, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup, final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) {
-
- super(lookup, abstractAutoMapper, field);
-
- fieldClassName = className;
-
- baseField = objectAssociation;
- tables = new ArrayList<String>();
- tableSpecifications = new ArrayList<ObjectSpecification>();
- subClassMappers = new ArrayList<ObjectMapping>();
-
- // Capture for use in creating subclass mappers.
- this.parameterBase = parameterBase;
- this.lookup = lookup;
- this.objectMapperLookup = objectMapperLookup;
-
- addSubSpecificationsToTable(specification);
- }
-
- protected void addSubSpecificationsToTable(final ObjectSpecification objectSpecification) {
- if (objectSpecification.isAbstract() == false) {
- final String tableNameFromSpecification = getTableNameFromSpecification(objectSpecification);
- tables.add(tableNameFromSpecification);
- tableSpecifications.add(objectSpecification);
-
- final ObjectMapping autoMapper = objectMapperLookup.getMapping(objectSpecification, null);
- subClassMappers.add(autoMapper);
- }
- if (objectSpecification.hasSubclasses()) {
- for (final ObjectSpecification subSpecification : objectSpecification.subclasses()) {
- addSubSpecificationsToTable(subSpecification);
- }
- }
- }
-
- @Override
- public boolean needsTables(final DatabaseConnector connection) {
- for (final String subTableName : tables) {
- table = subTableName;
- if (super.needsTables(connection)) {
- // Stop on first table that is needed.
- return true;
- }
- }
- return false;
- }
-
- @Override
- public void createTables(final DatabaseConnector connection) {
- for (final String subTableName : tables) {
- table = subTableName;
- if (super.needsTables(connection)) {
- super.createTables(connection);
- }
- }
- }
-
- @Override
- protected Iterator<ObjectAdapter> getElementsForCollectionAsIterator(final ObjectAdapter collection) {
- return currentIterator;
- }
-
- @Override
- public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent) {
- final ObjectAdapter collection = baseField.get(parent);
- LOG.debug("Saving polymorphic internal collection " + collection);
-
- currentCollection = new ArrayList<ObjectAdapter>();
- currentIterator = super.getElementsForCollectionAsIterator(collection);
- for (; currentIterator.hasNext();) {
- final ObjectAdapter item = currentIterator.next();
- currentCollection.add(item);
- }
-
- for (int i = 0; i < tables.size(); i++) {
- currentTableSpecification = tableSpecifications.get(i);
- currentIndex = 0;
- currentIndexStart = 0;
-
- currentIterator = new Iterator<ObjectAdapter>() {
- @Override
- public boolean hasNext() {
- for (int i = currentIndexStart; i < currentCollection.size(); i++) {
- final ObjectAdapter thisObjectAdapter = currentCollection.get(i);
- if (thisObjectAdapter.getSpecification().isOfType(currentTableSpecification)) {
- currentIndexStart = currentIndex = i;
- return true;
- }
- }
- return false;
- }
-
- @Override
- public ObjectAdapter next() {
- currentIndexStart = currentIndex + 1;
- return currentCollection.get(currentIndex);
- }
-
- @Override
- public void remove() {
- }
- };
-
- // Provide replacement table and column definitions here
- table = tables.get(i);
- super.saveInternalCollection(connector, parent);
- }
- }
-
- @Override
- protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent, final String table, final ObjectSpecification specification, final IdMappingAbstract idMappingAbstract, final Map<ObjectAssociation, FieldMapping> fieldMappingByField, final VersionMapping versionMapping,
- final List<ObjectAdapter> superList) {
- final List<ObjectAdapter> list = Lists.newArrayList();
-
- for (int i = 0; i < tables.size(); i++) {
- currentTableSpecification = tableSpecifications.get(i);
- final AutoMapper mapper = (AutoMapper) subClassMappers.get(i);
- final String mapperTable = tables.get(i);
-
- super.loadCollectionIntoList(connector, parent, mapperTable, currentTableSpecification, mapper.getIdMapping(), mapper.fieldMappingByField, mapper.getVersionMapping(), list);
-
- superList.addAll(list);
- list.clear();
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ReversedAutoAssociationMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ReversedAutoAssociationMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ReversedAutoAssociationMapper.java
deleted file mode 100644
index 7169b23..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ReversedAutoAssociationMapper.java
+++ /dev/null
@@ -1,212 +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.isis.objectstore.sql.auto;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.persistence.PersistorUtil;
-import org.apache.isis.objectstore.sql.CollectionMapper;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.FieldMappingLookup;
-import org.apache.isis.objectstore.sql.ObjectMappingLookup;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.VersionMapping;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping;
-
-/**
- * used where there is a one to many association, and the elements are only
- * known to parent
- */
-public class ReversedAutoAssociationMapper extends AbstractAutoMapper implements CollectionMapper {
- private static final Logger LOG = LoggerFactory.getLogger(ReversedAutoAssociationMapper.class);
- private final ObjectAssociation field;
- private final ObjectReferenceMapping idMapping;
- private final VersionMapping versionMapping;
-
- public ReversedAutoAssociationMapper(final String elemenType, final ObjectAssociation field, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectLookup) {
- super(elemenType, parameterBase, lookup, objectLookup);
-
- this.field = field;
-
- idMapping = lookup.createMapping(field.getSpecification());
- versionMapping = lookup.createVersionMapping();
-
- setUpFieldMappers();
- }
-
- @Override
- public void createTables(final DatabaseConnector connection) {
- if (!connection.hasTable(table)) {
- final StringBuffer sql = new StringBuffer();
- sql.append("create table ");
- sql.append(table);
- sql.append(" (");
- idMapping.appendColumnDefinitions(sql);
- sql.append(", ");
- for (final FieldMapping mapping : fieldMappingByField.values()) {
- mapping.appendColumnDefinitions(sql);
- sql.append(",");
- }
- sql.append(versionMapping.appendColumnDefinitions());
- sql.append(")");
- connection.update(sql.toString());
- }
- for (int i = 0; collectionMappers != null && i < collectionMappers.length; i++) {
- if (collectionMappers[i].needsTables(connection)) {
- collectionMappers[i].createTables(connection);
- }
- }
- }
-
- @Override
- public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter parentAdapter) {
- final ObjectAdapter collectionAdapter = field.get(parentAdapter);
- if (!collectionAdapter.canTransitionToResolving()) {
- return;
- }
- if(LOG.isDebugEnabled()) {
- LOG.debug("loading internal collection " + field);
- }
-
- try {
- // added, since was missing (presumably an error given similarity with other 'Mapper' impls?)
- PersistorUtil.startResolving(collectionAdapter);
-
- final StringBuffer sql = new StringBuffer();
- sql.append("select ");
- idMapping.appendColumnNames(sql);
- sql.append(", ");
- sql.append(columnList(fieldMappingByField));
- sql.append(" from ");
- sql.append(table);
- sql.append(" where ");
- idMapping.appendUpdateValues(connector, sql, parentAdapter);
-
- final Results rs = connector.select(sql.toString());
- final List<ObjectAdapter> list = new ArrayList<ObjectAdapter>();
- while (rs.next()) {
- final Oid oid = idMapping.recreateOid(rs, specification);
- final ObjectAdapter element = getAdapter(specification, oid);
- loadFields(element, rs);
- if(LOG.isDebugEnabled()) {
- LOG.debug(" element " + element.getOid());
- }
- list.add(element);
- }
- final CollectionFacet collectionFacet = collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
- collectionFacet.init(collectionAdapter, list.toArray(new ObjectAdapter[list.size()]));
- rs.close();
- } finally {
- PersistorUtil.toEndState(collectionAdapter);
- }
-
- }
-
- protected void loadFields(final ObjectAdapter object, final Results rs) {
- try {
- PersistorUtil.startResolving(object);
- for (final FieldMapping mapping : fieldMappingByField.values()) {
- mapping.initializeField(object, rs);
- }
- /*
- * for (int i = 0; i < oneToManyProperties.length; i++) { /* Need to set
- * up collection to be a ghost before we access as below
- */
- // CollectionAdapter collection = (CollectionAdapter)
- /*
- * oneToManyProperties[i].get(object); }
- */
-
- object.setVersion(versionMapping.getLock(rs));
-
- } finally {
- PersistorUtil.toEndState(object);
- }
- }
-
- @Override
- public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent) {
- final ObjectAdapter collection = field.get(parent);
- LOG.debug("Saving internal collection " + collection);
-
- deleteAllElments(connector, parent);
- reinsertElements(connector, parent, collection);
- }
-
- private void reinsertElements(final DatabaseConnector connector, final ObjectAdapter parent, final ObjectAdapter collection) {
- final StringBuffer sql = new StringBuffer();
- sql.append("insert into " + table + " (");
- idMapping.appendColumnNames(sql);
- sql.append(", ");
- final String columnList = columnList(fieldMappingByField);
- if (columnList.length() > 0) {
- sql.append(columnList);
- sql.append(", ");
- }
- sql.append(versionMapping.insertColumns());
- sql.append(") values (");
- idMapping.appendInsertValues(connector, sql, parent);
- sql.append(", ");
-
- final CollectionFacet collectionFacet = field.getFacet(CollectionFacet.class);
- for (final ObjectAdapter element : collectionFacet.iterable(collection)) {
- final StringBuffer insert = new StringBuffer(sql);
- insert.append(values(connector, element));
- final Version version = SerialNumberVersion.create(0, "", new Date());
- insert.append(versionMapping.insertValues(connector, version));
- insert.append(") ");
-
- connector.insert(insert.toString());
- element.setVersion(version);
- }
- }
-
- private void deleteAllElments(final DatabaseConnector connector, final ObjectAdapter parent) {
- final StringBuffer sql = new StringBuffer();
- sql.append("delete from ");
- sql.append(table);
- sql.append(" where ");
- idMapping.appendUpdateValues(connector, sql, parent);
- connector.update(sql.toString());
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln(field.getName(), "collection");
- debug.indent();
- debug.appendln("ID mapping", idMapping);
- debug.appendln("Version mapping", versionMapping);
- debug.unindent();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcFieldMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcFieldMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcFieldMapping.java
deleted file mode 100644
index 068a314..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcFieldMapping.java
+++ /dev/null
@@ -1,111 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.Sql;
-import org.apache.isis.objectstore.sql.mapping.FieldMapping;
-
-public abstract class AbstractJdbcFieldMapping implements FieldMapping {
-
- private final String columnName;
- protected final ObjectAssociation field;
-
- public AbstractJdbcFieldMapping(final ObjectAssociation field) {
- this.field = field;
- columnName = Sql.sqlFieldName(field.getId());
- }
-
- @Override
- public ObjectAssociation getField() {
- return field;
- }
-
- @Override
- public void appendColumnDefinitions(final StringBuffer sql) {
- sql.append(columnName);
- sql.append(" ");
- sql.append(columnType());
- }
-
- @Override
- public void appendColumnNames(final StringBuffer sql) {
- sql.append(columnName);
- }
-
- @Override
- public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- final ObjectAdapter fieldValue = field.get(object);
- if (fieldValue == null) {
- sql.append("NULL");
- } else {
- sql.append("?");
- connector.addToQueryValues(preparedStatementObject(fieldValue));
- }
- }
-
- @Override
- public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- appendEqualsClause(connector, sql, object, "=");
- }
-
- @Override
- public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- appendEqualsClause(connector, sql, object, "=");
- }
-
- protected void appendEqualsClause(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object, final String condition) {
- sql.append(Sql.sqlFieldName(field.getId()));
- sql.append(condition);
- final ObjectAdapter fieldValue = field.get(object);
- sql.append("?");
- connector.addToQueryValues(preparedStatementObject(fieldValue));
- }
-
- @Override
- public void initializeField(final ObjectAdapter object, final Results rs) {
- final String columnName = Sql.sqlFieldName(field.getId());
- final ObjectAdapter restoredValue = setFromDBColumn(rs, columnName, field);
- ((OneToOneAssociation) field).initAssociation(object, restoredValue);
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln(field.getId(), columnName + "/" + columnType());
- }
-
- @Override
- public void appendWhereObject(final DatabaseConnector connector, final ObjectAdapter objectAdapter) {
- final Object object = preparedStatementObject(objectAdapter);
- connector.addToQueryValues(object);
- }
-
- protected abstract String columnType();
-
- protected abstract Object preparedStatementObject(ObjectAdapter value);
-
- protected abstract ObjectAdapter setFromDBColumn(Results results, String columnName, ObjectAssociation field);
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/40561609/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcMultiFieldMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcMultiFieldMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcMultiFieldMapping.java
deleted file mode 100755
index adfd00e..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/jdbc/AbstractJdbcMultiFieldMapping.java
+++ /dev/null
@@ -1,195 +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.isis.objectstore.sql.jdbc;
-
-import org.apache.isis.applib.ApplicationException;
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.sql.DatabaseConnector;
-import org.apache.isis.objectstore.sql.Results;
-import org.apache.isis.objectstore.sql.Sql;
-
-public abstract class AbstractJdbcMultiFieldMapping extends AbstractJdbcFieldMapping {
- private final int columnCount;
- private final String[] types;
- private final String[] columnNames;
- private final AdapterManager adapterManager;
-
- /**
- *
- * @param field
- * the field object association.
- * @param columnCount
- * the number of columns required to store this field. See the
- * abstract methods ,
- * {@link AbstractJdbcFieldMapping#preparedStatementObject(int i, ObjectAdapter fieldValue)}
- * ,
- * {@link AbstractJdbcFieldMapping#getObjectFromResults(Results results)}
- * ,
- * @param types
- * the list of SQL data types, 1 per columnCount, to represent
- * the value type.
- */
- public AbstractJdbcMultiFieldMapping(final ObjectAssociation field, final int columnCount, final String... types) {
- super(field);
- this.columnCount = columnCount;
-
- this.types = new String[columnCount];
- for (int i = 0; i < types.length; i++) {
- this.types[i] = types[i];
- }
-
- final String fieldName = field.getId();
- columnNames = new String[columnCount];
- columnNames[0] = Sql.sqlFieldName(fieldName + "1");
- columnNames[1] = Sql.sqlFieldName(fieldName + "2");
-
- adapterManager = IsisContext.getPersistenceSession().getAdapterManager();
-
- }
-
- @Override
- public void appendColumnDefinitions(final StringBuffer sql) {
- for (int i = 0; i < columnCount; i++) {
- sql.append(columnName(i) + " " + columnType(i));
- if (i < columnCount - 1) {
- sql.append(", ");
- }
- }
- }
-
- @Override
- public void appendColumnNames(final StringBuffer sql) {
- for (int i = 0; i < columnCount; i++) {
- sql.append(columnName(i));
- if (i < columnCount - 1) {
- sql.append(", ");
- }
- }
- }
-
- @Override
- public void appendInsertValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- final ObjectAdapter fieldValue = field.get(object);
- final Object o = (fieldValue == null) ? null : fieldValue.getObject();
-
- for (int i = 0; i < columnCount; i++) {
- if (fieldValue == null) {
- sql.append("NULL");
- } else {
- sql.append("?");
- if (i < columnCount - 1) {
- sql.append(", ");
- }
-
- connector.addToQueryValues(preparedStatementObject(i, o));
- }
- }
- }
-
- @Override
- public void appendUpdateValues(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- final ObjectAdapter fieldValue = field.get(object);
- final Object o = (fieldValue == null) ? null : fieldValue.getObject();
- for (int i = 0; i < columnCount; i++) {
- appendEqualsClause(connector, i, sql, o, "=");
- }
- }
-
- @Override
- public void appendWhereClause(final DatabaseConnector connector, final StringBuffer sql, final ObjectAdapter object) {
- appendUpdateValues(connector, sql, object);
- }
-
- private void appendEqualsClause(final DatabaseConnector connector, final int index, final StringBuffer sql, final Object object, final String condition) {
-
- final Object oPart = preparedStatementObject(index, object);
-
- sql.append(columnName(index) + condition + "?");
- if (index < columnCount - 1) {
- sql.append(", ");
- }
-
- connector.addToQueryValues(oPart);
- }
-
- @Override
- public ObjectAdapter setFromDBColumn(final Results results, final String columnName, final ObjectAssociation field) {
- ObjectAdapter restoredValue;
- final Object objectValue = getObjectFromResults(results);
- restoredValue = adapterManager.adapterFor(objectValue); // NOTE: If this
- // fails, then
- // fetch back
- // the
- // declaration
- // from the
- // constructor
- // to here.
- return restoredValue;
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- for (int i = 0; i < columnCount; i++) {
- debug.appendln(field.getId(), columnName(i) + "/" + columnType(i));
- }
- }
-
- @Override
- protected String columnType() {
- throw new ApplicationException("Should never be called");
- }
-
- @Override
- protected Object preparedStatementObject(final ObjectAdapter value) {
- throw new ApplicationException("Should never be called");
- }
-
- protected String columnType(final int index) {
- return types[index];
- }
-
- protected String columnName(final int index) {
- return columnNames[index];
- }
-
- /**
- * Return an object suitable for passing to the SQL prepared statement
- * constructor, to handle field "index". Will be called "columnCount" times.
- *
- * @param index
- * 0 based index
- * @param fieldObject
- * the value type currently being
- * @return a JDBC-compatible object.
- */
- protected abstract Object preparedStatementObject(int index, Object o);
-
- /**
- * Return an applib object represented by the results set.
- *
- * @param results
- * the current record row from the underlying table
- * @return a fully initialised value object.
- */
- protected abstract Object getObjectFromResults(Results results);
-}