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 2012/12/13 01:01:07 UTC
[30/52] [partial] ISIS-188: renaming packages in line with
groupId:artifactId
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcConnector.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcConnector.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcConnector.java
deleted file mode 100644
index 6421e3b..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcConnector.java
+++ /dev/null
@@ -1,405 +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.runtimes.dflt.objectstores.sql.jdbc;
-
-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.apache.log4j.Logger;
-import org.joda.time.DateTimeZone;
-import org.joda.time.LocalDate;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.debug.DebugBuilder;
-import org.apache.isis.runtimes.dflt.objectstores.sql.AbstractDatabaseConnector;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.SqlMetaData;
-import org.apache.isis.runtimes.dflt.objectstores.sql.SqlObjectStore;
-import org.apache.isis.runtimes.dflt.objectstores.sql.SqlObjectStoreException;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-
-public class JdbcConnector extends AbstractDatabaseConnector {
- private static final Logger LOG = Logger.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) {
- 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 {
- 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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcConnectorFactory.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcConnectorFactory.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcConnectorFactory.java
deleted file mode 100644
index c4c4c00..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.sql.jdbc;
-
-import org.apache.isis.runtimes.dflt.objectstores.sql.DatabaseConnector;
-import org.apache.isis.runtimes.dflt.objectstores.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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateMapper.java
deleted file mode 100644
index 8cc6653..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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.runtimes.dflt.objectstores.sql.AbstractFieldMappingFactory;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Defaults;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMapping;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
-
-/**
- * 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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java
deleted file mode 100644
index e0e0f80..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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.runtimes.dflt.objectstores.sql.AbstractFieldMappingFactory;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Defaults;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMapping;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-
-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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcGeneralValueMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcGeneralValueMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcGeneralValueMapper.java
deleted file mode 100644
index 6f00712..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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.runtimes.dflt.objectstores.sql.AbstractFieldMappingFactory;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcMoneyValueMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcMoneyValueMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcMoneyValueMapper.java
deleted file mode 100755
index 730d47b..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMapping;
-import org.apache.isis.runtimes.dflt.objectstores.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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceFieldMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceFieldMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceFieldMapping.java
deleted file mode 100644
index 35d504e..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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.runtimes.dflt.objectstores.sql.AbstractFieldMappingFactory;
-import org.apache.isis.runtimes.dflt.objectstores.sql.DatabaseConnector;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Defaults;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Sql;
-import org.apache.isis.runtimes.dflt.objectstores.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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceMapping.java
deleted file mode 100644
index f0da8cb..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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.runtimes.dflt.objectstores.sql.DatabaseConnector;
-import org.apache.isis.runtimes.dflt.objectstores.sql.IdMappingAbstract;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Sql;
-import org.apache.isis.runtimes.dflt.objectstores.sql.SqlObjectStoreException;
-import org.apache.isis.runtimes.dflt.objectstores.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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceMappingFactory.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceMappingFactory.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceMappingFactory.java
deleted file mode 100644
index 804f630..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.sql.jdbc;
-
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.ObjectReferenceMapping;
-import org.apache.isis.runtimes.dflt.objectstores.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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcPasswordValueMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcPasswordValueMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcPasswordValueMapper.java
deleted file mode 100644
index b2764d1..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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.runtimes.dflt.objectstores.sql.AbstractFieldMappingFactory;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.helpers.SimplePasswordEncoderDecoder;
-import org.apache.isis.runtimes.dflt.objectstores.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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcPolymorphicObjectReferenceMapping.java
deleted file mode 100755
index 5ca45bd..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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.runtimes.dflt.objectstores.sql.DatabaseConnector;
-import org.apache.isis.runtimes.dflt.objectstores.sql.IdMappingAbstract;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Sql;
-import org.apache.isis.runtimes.dflt.objectstores.sql.SqlObjectStoreException;
-import org.apache.isis.runtimes.dflt.objectstores.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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcResults.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcResults.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcResults.java
deleted file mode 100644
index ab7b674..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcResults.java
+++ /dev/null
@@ -1,222 +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.runtimes.dflt.objectstores.sql.jdbc;
-
-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.runtimes.dflt.objectstores.sql.Defaults;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.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);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcSqlMetaData.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcSqlMetaData.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcSqlMetaData.java
deleted file mode 100644
index 9443c1a..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.sql.jdbc;
-
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
-
-import org.apache.isis.runtimes.dflt.objectstores.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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimeMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimeMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimeMapper.java
deleted file mode 100644
index 78a040e..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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.runtimes.dflt.objectstores.sql.AbstractFieldMappingFactory;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Defaults;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMapping;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-
-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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimestampMapper.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimestampMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimestampMapper.java
deleted file mode 100644
index c81aa83..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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.runtimes.dflt.objectstores.sql.AbstractFieldMappingFactory;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Defaults;
-import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMapping;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-
-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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/helpers/SimplePasswordEncoderDecoder.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/helpers/SimplePasswordEncoderDecoder.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/helpers/SimplePasswordEncoderDecoder.java
deleted file mode 100644
index c1a79f0..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/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.runtimes.dflt.objectstores.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/951a0fe4/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java
deleted file mode 100644
index 562076e..0000000
--- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/installer/JdbcFieldMappingFactoryInstaller.java
+++ /dev/null
@@ -1,87 +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.runtimes.dflt.objectstores.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.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.runtimes.dflt.objectstores.sql.Defaults;
-import org.apache.isis.runtimes.dflt.objectstores.sql.FieldMappingFactoryInstaller;
-import org.apache.isis.runtimes.dflt.objectstores.sql.FieldMappingLookup;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcBinaryValueMapper;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcColorValueMapper;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcDateMapper;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcDateTimeMapper;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcGeneralValueMapper;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcMoneyValueMapper;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcObjectReferenceFieldMapping;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcObjectReferenceMappingFactory;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcPasswordValueMapper;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcTimeMapper;
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcTimestampMapper;
-
-public class JdbcFieldMappingFactoryInstaller implements FieldMappingFactoryInstaller {
-
- @Override
- public void load(final FieldMappingLookup lookup) {
- 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());
-
- }
-
-}