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:06 UTC
[17/52] [partial] ISIS-188: renaming packages in line with
groupId:artifactId
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/encryption/none/DataEncryptionNone.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/encryption/none/DataEncryptionNone.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/encryption/none/DataEncryptionNone.java
new file mode 100644
index 0000000..2048cb5
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/encryption/none/DataEncryptionNone.java
@@ -0,0 +1,45 @@
+/*
+ * 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.nosql.encryption.none;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
+
+public class DataEncryptionNone implements DataEncryption {
+
+ @Override
+ public void init(final IsisConfiguration configuration) {
+ }
+
+ @Override
+ public String getType() {
+ return "none";
+ }
+
+ @Override
+ public String encrypt(final String plainText) {
+ return plainText;
+ }
+
+ @Override
+ public String decrypt(final String encryptedText) {
+ return encryptedText;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/encryption/rot13/Rot13Encryption.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/encryption/rot13/Rot13Encryption.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/encryption/rot13/Rot13Encryption.java
new file mode 100644
index 0000000..0551634
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/encryption/rot13/Rot13Encryption.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.nosql.encryption.rot13;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
+
+public class Rot13Encryption implements DataEncryption {
+
+ @Override
+ public String getType() {
+ return "rot13";
+ }
+
+ @Override
+ public void init(final IsisConfiguration configuration) {
+ }
+
+ @Override
+ public String encrypt(final String plainText) {
+ return encode(plainText);
+ }
+
+ @Override
+ public String decrypt(final String encryptedText) {
+ return encode(encryptedText);
+ }
+
+ private String encode(final String plainText) {
+ if (plainText == null) {
+ return plainText;
+ }
+
+ // encode plainText
+ String encodedMessage = "";
+ for (int i = 0; i < plainText.length(); i++) {
+ char c = plainText.charAt(i);
+ if (c >= 'a' && c <= 'm') {
+ c += 13;
+ } else if (c >= 'n' && c <= 'z') {
+ c -= 13;
+ } else if (c >= 'A' && c <= 'M') {
+ c += 13;
+ } else if (c >= 'N' && c <= 'Z') {
+ c -= 13;
+ }
+ encodedMessage += c;
+ }
+ return encodedMessage;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/keys/KeyCreatorDefault.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/keys/KeyCreatorDefault.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/keys/KeyCreatorDefault.java
new file mode 100644
index 0000000..8605e19
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/keys/KeyCreatorDefault.java
@@ -0,0 +1,99 @@
+/*
+ * 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.nosql.keys;
+
+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.RootOidDefault;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.objectstore.nosql.NoSqlStoreException;
+
+public class KeyCreatorDefault {
+
+ /**
+ * returns {@link RootOid#getIdentifier()} (oid must be {@link RootOid}, and must be persistent).
+ */
+ public String getIdentifierForPersistentRoot(final Oid oid) {
+ if (!(oid instanceof RootOid)) {
+ throw new NoSqlStoreException("Oid is not a RootOid: " + oid);
+ }
+ RootOid rootOid = (RootOid) oid;
+ if (rootOid.isTransient()) {
+ throw new NoSqlStoreException("Oid is not for a persistent object: " + oid);
+ }
+ return rootOid.getIdentifier();
+ }
+
+ /**
+ * Equivalent to the {@link Oid#enString(OidMarshaller)} for the adapter's Oid.
+ */
+ public String oidStrFor(final ObjectAdapter adapter) {
+ if(adapter == null) {
+ return null;
+ }
+ try {
+ //return adapter.getSpecification().getFullIdentifier() + "@" + key(adapter.getOid());
+ return adapter.getOid().enString(getOidMarshaller());
+ } catch (final NoSqlStoreException e) {
+ throw new NoSqlStoreException("Failed to create refence for " + adapter, e);
+ }
+ }
+
+ public RootOid createRootOid(ObjectSpecification objectSpecification, final String identifier) {
+ final ObjectSpecId objectSpecId = objectSpecification.getSpecId();
+ return RootOidDefault.create(objectSpecId, identifier);
+ }
+
+ public RootOid unmarshal(final String oidStr) {
+// final ObjectSpecification objectSpecification = specificationFromReference(ref);
+// final String id = ref.split("@")[1];
+// return oid(objectSpecification, id);
+ return getOidMarshaller().unmarshal(oidStr, RootOid.class);
+ }
+
+ public ObjectSpecification specificationFromOidStr(final String oidStr) {
+// final String name = ref.split("@")[0];
+// return getSpecificationLoader().loadSpecification(name);
+ final TypedOid oid = getOidMarshaller().unmarshal(oidStr, TypedOid.class);
+ return getSpecificationLoader().lookupBySpecId(oid.getObjectSpecId());
+ }
+
+
+ /////////////////////////////////////////////////
+ // dependencies (from context)
+ /////////////////////////////////////////////////
+
+
+ protected SpecificationLoaderSpi getSpecificationLoader() {
+ return IsisContext.getSpecificationLoader();
+ }
+
+ protected OidMarshaller getOidMarshaller() {
+ return IsisContext.getOidMarshaller();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/versions/VersionCreator.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/versions/VersionCreator.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/versions/VersionCreator.java
new file mode 100644
index 0000000..87719b7
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/versions/VersionCreator.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.nosql.versions;
+
+import org.apache.isis.core.metamodel.adapter.version.Version;
+
+public interface VersionCreator {
+
+ Version version(String versionString, String user, String time);
+ String versionString(Version version);
+
+ String timeString(Version version);
+
+ Version newVersion(String user);
+
+ Version nextVersion(Version version, final String user);
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/versions/VersionCreatorDefault.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/versions/VersionCreatorDefault.java b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/versions/VersionCreatorDefault.java
new file mode 100644
index 0000000..14d7f97
--- /dev/null
+++ b/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/versions/VersionCreatorDefault.java
@@ -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.
+ */
+
+package org.apache.isis.objectstore.nosql.versions;
+
+import java.util.Date;
+
+import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+
+public class VersionCreatorDefault implements VersionCreator {
+
+ @Override
+ public String versionString(final Version version) {
+ final long sequence = version.getSequence();
+ return Long.toHexString(sequence);
+ }
+
+ @Override
+ public String timeString(final Version version) {
+ final Date time = version.getTime();
+ return Long.toHexString(time.getTime());
+ }
+
+ @Override
+ public Version version(final String versionString, final String user, final String timeString) {
+ final Long sequence = Long.valueOf(versionString, 16);
+ final Long time = Long.valueOf(timeString, 16);
+ final Date date = new Date(time);
+ return SerialNumberVersion.create(sequence, user, date);
+ }
+
+ @Override
+ public Version newVersion(final String user) {
+ return SerialNumberVersion.create(1, user, new Date());
+ }
+
+ @Override
+ public Version nextVersion(final Version version, final String user) {
+ final long sequence = version.getSequence() + 1;
+ return SerialNumberVersion.create(sequence, user, new Date());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCommandContext.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCommandContext.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCommandContext.java
deleted file mode 100644
index b78c2d3..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCommandContext.java
+++ /dev/null
@@ -1,35 +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.nosql;
-
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateWriter;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-
-public interface NoSqlCommandContext extends PersistenceCommandContext {
-
- StateWriter createStateWriter(ObjectSpecId objectSpecId);
-
- void insert(StateWriter writer);
- void update(StateWriter writer);
-
- void delete(ObjectSpecId objectSpecId, String key, String version, Oid oid);
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCreateObjectCommand.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCreateObjectCommand.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCreateObjectCommand.java
deleted file mode 100644
index 403676e..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCreateObjectCommand.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.runtimes.dflt.objectstores.nosql;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.CreateObjectCommand;
-
-final class NoSqlCreateObjectCommand extends WriteObjectCommand implements CreateObjectCommand {
-
- public NoSqlCreateObjectCommand(final VersionCreator versionCreator, final DataEncryption dataEncrypter, final ObjectAdapter object) {
- super(Mode.NON_UPDATE, versionCreator, dataEncrypter, object);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlDestroyObjectCommand.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlDestroyObjectCommand.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlDestroyObjectCommand.java
deleted file mode 100644
index 5b11bd2..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlDestroyObjectCommand.java
+++ /dev/null
@@ -1,64 +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.nosql;
-
-import org.apache.isis.core.commons.lang.ToString;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.keys.KeyCreatorDefault;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-
-final class NoSqlDestroyObjectCommand implements DestroyObjectCommand {
-
- private final KeyCreatorDefault keyCreator = new KeyCreatorDefault();
-
- private final ObjectAdapter adapter;
- private final VersionCreator versionCreator;
-
- public NoSqlDestroyObjectCommand(final VersionCreator versionCreator, final ObjectAdapter adapter) {
- this.versionCreator = versionCreator;
- this.adapter = adapter;
- }
-
- @Override
- public void execute(final PersistenceCommandContext context) {
- final String key = keyCreator.getIdentifierForPersistentRoot(adapter.getOid());
- final String version = versionCreator.versionString(adapter.getVersion());
- final ObjectSpecification objectSpec = adapter.getSpecification();
-
- final NoSqlCommandContext noSqlCommandContext = (NoSqlCommandContext) context;
- noSqlCommandContext.delete(objectSpec.getSpecId(), key, version, adapter.getOid());
- }
-
- @Override
- public ObjectAdapter onAdapter() {
- return adapter;
- }
-
- @Override
- public String toString() {
- final ToString toString = new ToString(this);
- toString.append("spec", adapter.getSpecification().getFullIdentifier());
- toString.append("oid", adapter.getOid());
- return toString.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlIdentifierGenerator.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlIdentifierGenerator.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlIdentifierGenerator.java
deleted file mode 100644
index a3565f2..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlIdentifierGenerator.java
+++ /dev/null
@@ -1,147 +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.nosql;
-
-import org.apache.log4j.Logger;
-
-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.runtimes.dflt.objectstores.nosql.db.NoSqlDataDatabase;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.IdentifierGenerator;
-
-public class NoSqlIdentifierGenerator implements IdentifierGenerator {
-
- private static int INITIAL_TRANSIENT_ID = -9999999;
- private static int DEFAULT_BATCH_SIZE = 50;
-
- private final NoSqlDataDatabase database;
- private final IdNumbers ids;
-
-
- //////////////////////////////////////////////////////////////////
- // constructor
- //////////////////////////////////////////////////////////////////
-
- public NoSqlIdentifierGenerator(final NoSqlDataDatabase database) {
- this(database, INITIAL_TRANSIENT_ID, DEFAULT_BATCH_SIZE);
- }
-
- public NoSqlIdentifierGenerator(final NoSqlDataDatabase database, final int initialTransientId, final int batchSize) {
- this.database = database;
- ids = new IdNumbers(initialTransientId, batchSize);
- }
-
-
- //////////////////////////////////////////////////////////////////
- // API
- //////////////////////////////////////////////////////////////////
-
- @Override
- public String createTransientIdentifierFor(ObjectSpecId objectSpecId, Object pojo) {
- final String identifier = "" + ids.nextTransientId();
- return identifier;
- }
-
- @Override
- public String createAggregateLocalId(ObjectSpecId objectSpecId, final Object pojo, final ObjectAdapter parentAdapter) {
- Assert.assertNotNull("No connection set up", database);
- return Long.toHexString(ids.nextSubId(database));
- }
-
- @Override
- public String createPersistentIdentifierFor(ObjectSpecId objectSpecId, Object pojo, RootOid transientRootOid) {
- return "" + ids.nextPersistentId(database);
- }
-
-
- //////////////////////////////////////////////////////////////////
- // debug
- //////////////////////////////////////////////////////////////////
-
- @Override
- public void debugData(final DebugBuilder debug) {
- debug.appendln(this.toString());
- debug.indent();
- ids.debugData(debug);
- debug.unindent();
- }
-
- @Override
- public String debugTitle() {
- return "NoSql OID Generator";
- }
-}
-
-class IdNumbers {
-
- private static final Logger LOG = Logger.getLogger(IdNumbers.class);
-
- private final int batchSize;
-
- private long transientNumber;
- private long nextId = 0;
- private long newIdBatchAt = 0;
- private long nextSubId = 0;
- private long newSubIdBatchAt = 0;
-
- public IdNumbers(final int initialTransientId, final int batchSize) {
- transientNumber = initialTransientId;
- this.batchSize = batchSize;
- }
-
- public synchronized long nextTransientId() {
- return transientNumber++;
- }
-
- public synchronized long nextSubId(final NoSqlDataDatabase connectionPool) {
- if (nextSubId > newSubIdBatchAt) {
- final String message = "ID exception, last id (" + nextSubId + ") past new batch boundary (" + newSubIdBatchAt + ")";
- throw new NoSqlStoreException(message);
- }
- if (nextSubId == newSubIdBatchAt) {
- nextSubId = connectionPool.nextSerialNumberBatch(ObjectSpecId.of("_sub-id"), batchSize);
- newSubIdBatchAt = nextSubId + batchSize;
- LOG.debug("New Sub-ID batch created, from " + nextSubId + " to " + newSubIdBatchAt);
- }
- return nextSubId++;
- }
-
- public synchronized long nextPersistentId(final NoSqlDataDatabase connectionPool) {
- if (nextId > newIdBatchAt) {
- final String message = "ID exception, last id (" + nextId + ") past new batch boundary (" + newIdBatchAt + ")";
- throw new NoSqlStoreException(message);
- }
- if (nextId == newIdBatchAt) {
- nextId = connectionPool.nextSerialNumberBatch(ObjectSpecId.of("_id"), batchSize);
- newIdBatchAt = nextId + batchSize;
- LOG.debug("New ID batch created, from " + nextId + " to " + newIdBatchAt);
- }
- return nextId++;
- }
-
- public void debugData(final DebugBuilder debug) {
- debug.appendln("id", nextId);
- debug.appendln("sub-id", nextSubId);
- debug.appendln("transient id", transientNumber);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStore.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStore.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStore.java
deleted file mode 100644
index 300d679..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStore.java
+++ /dev/null
@@ -1,338 +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.nosql;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-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.adapter.oid.AggregatedOid;
-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.TypedOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-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.runtimes.dflt.objectstores.nosql.db.NoSqlDataDatabase;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateReader;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.keys.KeyCreatorDefault;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.ObjectStoreSpi;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.CreateObjectCommand;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.SaveObjectCommand;
-import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryBuiltIn;
-import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindAllInstances;
-import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByPattern;
-import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByTitle;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.IdentifierGenerator;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceQuery;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
-
-public class NoSqlObjectStore implements ObjectStoreSpi {
-
- private final KeyCreatorDefault keyCreator = new KeyCreatorDefault();
- private final Map<ObjectSpecId, RootOid> servicesByObjectSpecId = Maps.newHashMap();
-
- private final NoSqlDataDatabase database;
- private final VersionCreator versionCreator;
- private final ObjectReader objectReader = new ObjectReader();
- private final OidGenerator oidGenerator;
- private final DataEncryption wrtingDataEncrypter;
- private final Map<String, DataEncryption> availableDataEncrypters;
- private final boolean isDataLoaded;
-
- public NoSqlObjectStore(final NoSqlDataDatabase db, final OidGenerator oidGenerator, final VersionCreator versionCreator, final DataEncryption writingDataEncrypter, final Map<String, DataEncryption> availableDataEncrypters) {
- this.database = db;
- this.oidGenerator = oidGenerator;
- this.versionCreator = versionCreator;
- this.wrtingDataEncrypter = writingDataEncrypter;
- this.availableDataEncrypters = availableDataEncrypters;
-
- db.open();
- isDataLoaded = db.containsData();
- db.close();
- }
-
- public IdentifierGenerator getIdentifierGenerator() {
- return oidGenerator.getIdentifierGenerator();
- }
-
- @Override
- public CreateObjectCommand createCreateObjectCommand(final ObjectAdapter object) {
- // TODO should this be done at a higher level so it is applicable for
- // all OSes
- if (object.getSpecification().isParented()) {
- // throw new
- // UnexpectedCallException("Aggregated objects should not be created outside of their owner");
- return null;
- } else {
- return new NoSqlCreateObjectCommand(versionCreator, wrtingDataEncrypter, object);
- }
- }
-
- @Override
- public DestroyObjectCommand createDestroyObjectCommand(final ObjectAdapter adapter) {
- if (adapter.getSpecification().isParented()) {
- throw new NoSqlStoreException("Can't delete an aggregated object");
- } else {
- return new NoSqlDestroyObjectCommand(versionCreator, adapter);
- }
- }
-
- @Override
- public SaveObjectCommand createSaveObjectCommand(final ObjectAdapter adapter) {
-
- // TODO should this be done at a higher level
- // so it is applicable for all object stores?
-
- final ObjectAdapter rootAdapter = adapter.getAggregateRoot();
- if (!(rootAdapter.getOid() instanceof RootOid)) {
- throw new NoSqlStoreException("Unexpected aggregated object to save: " + rootAdapter + " (" + adapter + ")");
- }
- return new NoSqlSaveObjectCommand(versionCreator, wrtingDataEncrypter, rootAdapter);
- }
-
- @Override
- public void execute(final List<PersistenceCommand> commands) {
- database.write(commands);
- }
-
- @Override
- public List<ObjectAdapter> loadInstancesAndAdapt(final PersistenceQuery persistenceQuery) {
- if (persistenceQuery instanceof PersistenceQueryFindByTitle) {
- return getAllInstances((PersistenceQueryFindByTitle) persistenceQuery);
- } else if (persistenceQuery instanceof PersistenceQueryFindAllInstances) {
- return getAllInstances((PersistenceQueryFindAllInstances) persistenceQuery);
- } else if (persistenceQuery instanceof PersistenceQueryFindByPattern) {
- return findByPattern((PersistenceQueryFindByPattern) persistenceQuery);
- } else {
- return findDefaultr(persistenceQuery);
- }
- }
-
- private List<ObjectAdapter> findDefaultr(PersistenceQuery persistenceQuery) {
- final List<ObjectAdapter> instances = Lists.newArrayList();
- final ObjectSpecification specification = persistenceQuery.getSpecification();
- final Iterator<StateReader> instanceData = database.instancesOf(specification.getSpecId());
- while (instanceData.hasNext()) {
- final StateReader reader = instanceData.next();
- final ObjectAdapter instance = objectReader.load(reader, versionCreator, availableDataEncrypters);
- instances.add(instance);
- }
- return instances;
- }
-
- private List<ObjectAdapter> findByPattern(PersistenceQueryFindByPattern query) {
- final ObjectSpecification specification = query.getSpecification();
- final List<ObjectAdapter> instances = Lists.newArrayList();
- appendPatternInstances(query, specification, instances);
- return instances;
- }
-
- private void appendPatternInstances(final PersistenceQueryFindByPattern persistenceQuery, final ObjectSpecification specification, final List<ObjectAdapter> instances) {
- final Iterator<StateReader> instanceData = database.instancesOf(specification.getSpecId(), persistenceQuery.getPattern());
- while (instanceData.hasNext()) {
- final StateReader reader = instanceData.next();
- final ObjectAdapter instance = objectReader.load(reader, versionCreator, availableDataEncrypters);
- instances.add(instance);
- }
- for (final ObjectSpecification spec : specification.subclasses()) {
- appendPatternInstances(persistenceQuery, spec, instances);
- }
- }
-
-
- private List<ObjectAdapter> getAllInstances(PersistenceQuery query) {
- final ObjectSpecification specification = query.getSpecification();
- final List<ObjectAdapter> instances = Lists.newArrayList();
- appendInstances(query, specification, instances);
- return instances;
- }
-
- private void appendInstances(final PersistenceQuery persistenceQuery, final ObjectSpecification specification, final List<ObjectAdapter> instances) {
- final Iterator<StateReader> instanceData = database.instancesOf(specification.getSpecId());
- while (instanceData.hasNext()) {
- final StateReader reader = instanceData.next();
- final ObjectAdapter instance = objectReader.load(reader, versionCreator, availableDataEncrypters);
-
- // TODO deal with this natively
- if (persistenceQuery instanceof PersistenceQueryBuiltIn) {
- if (!((PersistenceQueryBuiltIn) persistenceQuery).matches(instance)) {
- continue;
- }
- }
- instances.add(instance);
- }
- for (final ObjectSpecification spec : specification.subclasses()) {
- appendInstances(persistenceQuery, spec, instances);
- }
- }
-
-
-
- @Override
- public ObjectAdapter loadInstanceAndAdapt(final TypedOid oid) {
- final String key = keyCreator.getIdentifierForPersistentRoot(oid);
- final ObjectSpecification objectSpec = getSpecificationLookup().lookupBySpecId(oid.getObjectSpecId());
- final StateReader reader = database.getInstance(key, objectSpec.getSpecId());
- return objectReader.load(reader, versionCreator, availableDataEncrypters);
- }
-
- @Override
- public boolean hasInstances(final ObjectSpecification specification) {
- return database.hasInstances(specification.getSpecId());
- }
-
- @Override
- public boolean isFixturesInstalled() {
- return isDataLoaded;
- }
-
- @Override
- public void reset() {
- }
-
- @Override
- public void resolveField(final ObjectAdapter object, final ObjectAssociation field) {
- final ObjectAdapter fieldValue = field.get(object);
- if (fieldValue != null && !fieldValue.isResolved() && !fieldValue.getSpecification().isParented()) {
- resolveImmediately(fieldValue);
- }
- }
-
- @Override
- public void resolveImmediately(final ObjectAdapter adapter) {
- final Oid oid = adapter.getOid();
- if (!(oid instanceof AggregatedOid)) {
- final ObjectSpecification objectSpec = adapter.getSpecification();
- final String key = keyCreator.getIdentifierForPersistentRoot(oid);
- final StateReader reader = database.getInstance(key, objectSpec.getSpecId());
- objectReader.update(reader, versionCreator, availableDataEncrypters, adapter);
- }
- }
-
- @Override
- public void debugData(final DebugBuilder debug) {
- // TODO show details
- }
-
- // ////////////////////////////////////////////////////////////////
- // open, close
- // ////////////////////////////////////////////////////////////////
-
- @Override
- public void close() {
- database.close();
- }
-
- @Override
- public void open() {
- database.open();
- }
-
- @Override
- public String name() {
- return "nosql";
- }
-
-
- // ////////////////////////////////////////////////////////////////
- // Services
- // ////////////////////////////////////////////////////////////////
-
- @Override
- public void registerService(final RootOid rootOid) {
- final String key = keyCreator.getIdentifierForPersistentRoot(rootOid);
- database.addService(rootOid.getObjectSpecId(), key);
- }
-
- @Override
- public RootOid getOidForService(ObjectSpecification serviceSpec) {
- final ObjectSpecId objectSpecId = serviceSpec.getSpecId();
- RootOid oid = servicesByObjectSpecId.get(objectSpecId);
- if (oid == null) {
- final String id = database.getService(objectSpecId);
- if (id == null) {
- oid = null;
- } else {
- oid = keyCreator.createRootOid(serviceSpec, id);
- }
- servicesByObjectSpecId.put(objectSpecId, oid);
- }
- return oid;
- }
-
-
- // ////////////////////////////////////////////////////////////////
- // Transaction Mgmt
- // ////////////////////////////////////////////////////////////////
-
- @Override
- public void abortTransaction() {
- }
-
- @Override
- public void endTransaction() {
- }
-
- @Override
- public void startTransaction() {
- }
-
-
- // ////////////////////////////////////////////////////////////////
- // debugging
- // ////////////////////////////////////////////////////////////////
-
- @Override
- public String debugTitle() {
- return "NoSql Object Store";
- }
-
-
- // ////////////////////////////////////////////////////////////////
- // Dependencies (from context)
- // ////////////////////////////////////////////////////////////////
-
- protected AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-
- protected PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- protected SpecificationLoader getSpecificationLookup() {
- return IsisContext.getSpecificationLoader();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlSaveObjectCommand.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlSaveObjectCommand.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlSaveObjectCommand.java
deleted file mode 100644
index 552f53d..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlSaveObjectCommand.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.runtimes.dflt.objectstores.nosql;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.SaveObjectCommand;
-
-final class NoSqlSaveObjectCommand extends WriteObjectCommand implements SaveObjectCommand {
-
- public NoSqlSaveObjectCommand(final VersionCreator versionCreator, final DataEncryption dataEncrypter, final ObjectAdapter object) {
- super(Mode.UPDATE, versionCreator, dataEncrypter, object);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlStoreException.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlStoreException.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlStoreException.java
deleted file mode 100644
index 74c1d0b..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlStoreException.java
+++ /dev/null
@@ -1,47 +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.nosql;
-
-import org.apache.isis.core.commons.exceptions.IsisException;
-
-public class NoSqlStoreException extends IsisException {
- private static final long serialVersionUID = 1L;
-
- public NoSqlStoreException() {
- super();
- }
-
- public NoSqlStoreException(final String messageFormat, final Object... args) {
- super(messageFormat, args);
- }
-
- public NoSqlStoreException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- public NoSqlStoreException(final String message) {
- super(message);
- }
-
- public NoSqlStoreException(final Throwable cause) {
- super(cause);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReader.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReader.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReader.java
deleted file mode 100644
index ba3fe3d..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReader.java
+++ /dev/null
@@ -1,249 +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.nosql;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.ResolveState;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.oid.AggregatedOid;
-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.Version;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
-import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
-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.ObjectAssociationContainer;
-import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateReader;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.keys.KeyCreatorDefault;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.Persistor;
-import org.apache.log4j.Logger;
-
-public class ObjectReader {
-
- private static final Logger LOG = Logger.getLogger(ObjectReader.class);
-
- private final KeyCreatorDefault keyCreator = new KeyCreatorDefault();
-
- public ObjectAdapter load(final StateReader reader, final VersionCreator versionCreator, final Map<String, DataEncryption> dataEncrypters) {
-
- final String oidStr = reader.readOid();
- final RootOid rootOid = getOidMarshaller().unmarshal(oidStr, RootOid.class);
-
- final ObjectAdapter adapter = getAdapter(rootOid);
- if (adapter.isResolved()) {
- Version version = null;
- final String versionString = reader.readVersion();
- if (!versionString.equals("")) {
- final String user = reader.readUser();
- final String time = reader.readTime();
- version = versionCreator.version(versionString, user, time);
- }
- if (version.different(adapter.getVersion())) {
- // TODO - do we need to CHECK version and update
- LOG.warn("while reading data into " + oidStr + " version was " + version + " when existing adapter was already " + adapter.getVersion());
- }
-
- } else {
-
- // TODO move lock to common method
- // object.setOptimisticLock(version);
- loadState(reader, versionCreator, dataEncrypters, adapter);
- }
-
- return adapter;
- }
-
- public void update(final StateReader reader, final VersionCreator versionCreator, final Map<String, DataEncryption> dataEncrypters, final ObjectAdapter object) {
- loadState(reader, versionCreator, dataEncrypters, object);
- }
-
- private void loadState(final StateReader reader, final VersionCreator versionCreator, final Map<String, DataEncryption> dataEncrypters, final ObjectAdapter object) {
- final ResolveState resolveState = ResolveState.RESOLVING;
- object.changeState(resolveState);
- Version version = null;
- final String versionString = reader.readVersion();
- if (!versionString.equals("")) {
- final String user = reader.readUser();
- final String time = reader.readTime();
- version = versionCreator.version(versionString, user, time);
- }
- final String encryptionType = reader.readEncrytionType();
- readFields(reader, object, dataEncrypters.get(encryptionType));
- object.setVersion(version);
- object.changeState(resolveState.getEndState());
- }
-
- private void readFields(final StateReader reader, final ObjectAdapter object, final DataEncryption dataEncrypter) {
- final ObjectAssociationContainer specification = object.getSpecification();
- final List<ObjectAssociation> associations = specification.getAssociations();
- for (final ObjectAssociation association : associations) {
- if (association.isNotPersisted()) {
- continue;
- }
- if (association.isOneToManyAssociation()) {
- readCollection(reader, dataEncrypter, (OneToManyAssociation) association, object);
- } else if (association.getSpecification().isValue()) {
- readValue(reader, dataEncrypter, (OneToOneAssociation) association, object);
- } else if (association.getSpecification().isParented()) {
- readAggregate(reader, dataEncrypter, (OneToOneAssociation) association, object);
- } else {
- readReference(reader, (OneToOneAssociation) association, object);
- }
- }
- }
-
- private void readAggregate(final StateReader reader, final DataEncryption dataEncrypter, final OneToOneAssociation association, final ObjectAdapter parentAdapter) {
- final String id = association.getId();
- final StateReader aggregateReader = reader.readAggregate(id);
-
- final ObjectAdapter fieldObject;
- if (aggregateReader != null) {
- final String oidStr = aggregateReader.readOid();
- final AggregatedOid aggregatedOid = getOidMarshaller().unmarshal(oidStr, AggregatedOid.class);
- fieldObject = restoreAggregatedObject(aggregateReader, aggregatedOid, dataEncrypter);
- } else {
- fieldObject = null;
- }
-
- association.initAssociation(parentAdapter, fieldObject);
- }
-
- private ObjectAdapter restoreAggregatedObject(final StateReader aggregateReader, final AggregatedOid aggregatedOid, final DataEncryption dataEncrypter) {
- final ObjectAdapter fieldObject = getAdapter(aggregatedOid);
- final ResolveState resolveState = ResolveState.RESOLVING;
- fieldObject.changeState(resolveState);
- readFields(aggregateReader, fieldObject, dataEncrypter);
- fieldObject.changeState(resolveState.getEndState());
-
- return fieldObject;
- }
-
- private void readValue(final StateReader reader, final DataEncryption dataEncrypter, final OneToOneAssociation association, final ObjectAdapter object) {
- final String fieldData = reader.readField(association.getId());
- if (fieldData != null) {
- if (fieldData.equals("null")) {
- association.initAssociation(object, null);
- } else {
- final EncodableFacet encodeableFacet = association.getSpecification().getFacet(EncodableFacet.class);
- final String decryptedData = dataEncrypter.decrypt(fieldData);
- final ObjectAdapter value = encodeableFacet.fromEncodedString(decryptedData);
- association.initAssociation(object, value);
- }
- }
- }
-
- private void readReference(final StateReader reader, final OneToOneAssociation association, final ObjectAdapter object) {
- ObjectAdapter fieldObject;
- final String ref = reader.readField(association.getId());
- if (ref == null || ref.equals("null")) {
- fieldObject = null;
- } else {
- if (ref.equals("")) {
- throw new NoSqlStoreException("Invalid reference field (an empty string) in data for " + association.getName() + " in " + object);
- }
- final RootOid oid = keyCreator.unmarshal(ref);
- fieldObject = getAdapter(oid);
- }
- try {
- association.initAssociation(object, fieldObject);
- } catch (IllegalArgumentException e) {
- throw new NoSqlStoreException("Failed to process field data for " + association.getName() + " in " + object + ": " + ref);
- }
- }
-
- private void readCollection(final StateReader reader, final DataEncryption dataEncrypter, final OneToManyAssociation association, final ObjectAdapter parentAdapter) {
- final ObjectAdapter collectionAdapter = association.get(parentAdapter);
-
- final CollectionFacet facet = collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
- if (association.getSpecification().isParented()) {
- // were persisted inline, so read back inline
- final List<StateReader> readers = reader.readCollection(association.getId());
- final ObjectAdapter[] elementAdapters = new ObjectAdapter[readers.size()];
- int i = 0;
- for (final StateReader elementReader : readers) {
-
- final String oidStr = elementReader.readOid();
- final AggregatedOid aggregatedOid = getOidMarshaller().unmarshal(oidStr, AggregatedOid.class);
-
- elementAdapters[i++] = restoreAggregatedObject(elementReader, aggregatedOid, dataEncrypter);
- }
- facet.init(collectionAdapter, elementAdapters);
- } else {
- // were persisted as references, so read back as references
- final String referencesList = reader.readField(association.getId());
- if (referencesList == null || referencesList.length() == 0) {
- facet.init(collectionAdapter, new ObjectAdapter[0]);
- } else {
- final ObjectAdapter[] elements = restoreElements(referencesList);
- facet.init(collectionAdapter, elements);
- }
- }
- }
-
- private ObjectAdapter[] restoreElements(final String referencesList) {
- final String[] references = referencesList.split("\\|");
- final ObjectAdapter[] elements = new ObjectAdapter[references.length];
- for (int i = 0; i < references.length; i++) {
-
- // no longer used
- //final ObjectSpecification specification = keyCreator.specificationFromOidStr(references[i]);
-
- final RootOid oid = keyCreator.unmarshal(references[i]);
- elements[i] = getAdapter(oid);
- }
- return elements;
- }
-
- protected ObjectAdapter getAdapter(final TypedOid oid) {
- return getAdapterManager().adapterFor(oid);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////
- // dependencies (from context)
- ////////////////////////////////////////////////////////////////////////////
-
- protected Persistor getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- protected AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-
- protected SpecificationLoaderSpi getSpecificationLoader() {
- return IsisContext.getSpecificationLoader();
- }
-
- protected OidMarshaller getOidMarshaller() {
- return IsisContext.getOidMarshaller();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java
deleted file mode 100644
index 58e3d4d..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java
+++ /dev/null
@@ -1,249 +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.nosql;
-
-import java.util.List;
-
-import com.google.common.collect.Lists;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.lang.ToString;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.AggregatedOid;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
-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.facets.object.encodeable.EncodableFacet;
-import org.apache.isis.core.metamodel.spec.DomainModelException;
-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.OneToManyAssociation;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateWriter;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.keys.KeyCreatorDefault;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-
-class WriteObjectCommand implements PersistenceCommand {
-
- public enum Mode {
- UPDATE,
- NON_UPDATE;
-
- public static Mode modeFor(boolean isUpdate) {
- return isUpdate?UPDATE:NON_UPDATE;
- }
-
- public boolean isUpdate() {
- return this == UPDATE;
- }
- }
-
- private final KeyCreatorDefault keyCreator = new KeyCreatorDefault();
- private final ObjectAdapter adapter;
- private final VersionCreator versionCreator;
- private final DataEncryption dataEncrypter;
- private final Mode mode;
-
- WriteObjectCommand(final Mode mode, final VersionCreator versionCreator, final DataEncryption dataEncrypter, final ObjectAdapter adapter) {
- this.mode = mode;
- this.versionCreator = versionCreator;
- this.dataEncrypter = dataEncrypter;
- this.adapter = adapter;
- }
-
- @Override
- public void execute(final PersistenceCommandContext context) {
- final NoSqlCommandContext noSqlCommandContext = (NoSqlCommandContext) context;
-
- final ObjectSpecification objectSpec = adapter.getSpecification();
- //final String specName = objectSpec.getFullIdentifier();
- final StateWriter writer = noSqlCommandContext.createStateWriter(objectSpec.getSpecId());
-
- //final String key = keyCreator.key(adapter.getOid());
- //writer.writeId(key);
- final TypedOid typedOid = (TypedOid) adapter.getOid();
- writer.writeOid(typedOid);
-
- writeFields(writer, adapter);
- final String user = getAuthenticationSession().getUserName();
-
- final Version currentVersion = adapter.getVersion();
-
- final Version newVersion = mode.isUpdate() ? versionCreator.nextVersion(currentVersion, user) : versionCreator.newVersion(user);
- adapter.setVersion(newVersion);
- if (newVersion != null) {
- final String version = currentVersion == null ? null : versionCreator.versionString(currentVersion);
- writer.writeVersion(version, versionCreator.versionString(newVersion));
- writer.writeUser(newVersion.getUser());
- writer.writeTime(versionCreator.timeString(newVersion));
- writer.writeEncryptionType(dataEncrypter.getType());
- }
-
- if (mode.isUpdate()) {
- noSqlCommandContext.update(writer);
- } else {
- noSqlCommandContext.insert(writer);
- }
- }
-
- private void writeFields(final StateWriter writer, final ObjectAdapter adapter) {
-
- final List<ObjectAssociation> associations = adapter.getSpecification().getAssociations();
-
-// final String specName = adapter.getSpecification().getFullIdentifier();
-// writer.writeObjectType(specName);
-
- writer.writeOid((TypedOid) adapter.getOid());
-
- for (final ObjectAssociation association : associations) {
- if (association.isNotPersisted()) {
- continue;
- }
- final ObjectAdapter fieldAdapter = association.get(adapter);
- if (association.isOneToManyAssociation()) {
- final OneToManyAssociation oneToManyAssociation = (OneToManyAssociation) association;
- final ObjectAdapter collectionAdapter = fieldAdapter; // to explain
- writeCollection(writer, oneToManyAssociation, collectionAdapter);
- } else {
- final OneToOneAssociation oneToOneAssociation = (OneToOneAssociation) association;
- final ObjectAdapter propertyAdapter = fieldAdapter; // to explain
- writeProperty(writer, oneToOneAssociation, propertyAdapter);
- }
- }
- }
-
- private void writeProperty(final StateWriter writer, final OneToOneAssociation oneToOneAssociation, final ObjectAdapter propertyAdapter) {
- if (oneToOneAssociation.getSpecification().isValue()) {
- final ObjectAdapter valueAdapter = propertyAdapter; // to explain
- writeValueProperty(writer, oneToOneAssociation, valueAdapter);
- } else {
- final ObjectAdapter referencedAdapter = propertyAdapter; // to explain
- writeReferenceProperty(writer, oneToOneAssociation, referencedAdapter);
- }
- }
-
- private void writeValueProperty(final StateWriter writer, final OneToOneAssociation otoa, final ObjectAdapter valueAdapter) {
- String data;
- if (valueAdapter == null) {
- data = null;
- } else {
- final EncodableFacet encodeableFacet = valueAdapter.getSpecification().getFacet(EncodableFacet.class);
- data = encodeableFacet.toEncodedString(valueAdapter);
- data = dataEncrypter.encrypt(data);
- }
- writer.writeField(otoa.getId(), data);
- }
-
- private void writeReferenceProperty(final StateWriter writer, final OneToOneAssociation otoa, final ObjectAdapter referencedAdapter) {
- if (otoa.getSpecification().isParented()) {
- writeReferencedAsAggregated(writer, otoa, referencedAdapter);
- } else {
- writeReference(writer, otoa, referencedAdapter);
- }
- }
-
- private void writeReferencedAsAggregated(final StateWriter writer, final OneToOneAssociation otoa, final ObjectAdapter referencedAdapter) {
- if (referencedAdapter == null) {
- writer.writeField(otoa.getId(), null);
- return;
- }
- final Oid referencedOid = referencedAdapter.getOid();
- if (!(referencedOid instanceof AggregatedOid)) {
- throw new NoSqlStoreException("Object type is inconsistent with it OID - it should have an AggregatedOid: " + referencedAdapter);
- }
- final AggregatedOid aggregatedOid = (AggregatedOid) referencedOid;
-
- final String associationId = otoa.getId();
- final StateWriter aggregateWriter = writer.addAggregate(associationId);
- //aggregateWriter.writeId(aggregatedOid.getLocalId());
- aggregateWriter.writeOid(aggregatedOid);
-
- writeFields(aggregateWriter, referencedAdapter);
- }
-
- private void writeReference(final StateWriter writer, final ObjectAssociation association, final ObjectAdapter referencedAdapter) {
- final String key = keyCreator.oidStrFor(referencedAdapter);
- writer.writeField(association.getId(), key);
- }
-
- private void writeCollection(final StateWriter writer, final OneToManyAssociation association, final ObjectAdapter collectionAdapter) {
- if (association.getSpecification().isParented()) {
- writeCollectionOfAggregated(writer, association, collectionAdapter);
- } else {
- writeCollectionOfReferences(writer, association, collectionAdapter);
- }
- }
-
- private void writeCollectionOfAggregated(final StateWriter writer, final ObjectAssociation association, final ObjectAdapter collectionAdapter) {
- final List<StateWriter> elementWriters = Lists.newArrayList();
- final CollectionFacet collectionFacet = collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
- for (final ObjectAdapter referencedAdapter : collectionFacet.iterable(collectionAdapter)) {
- final AggregatedOid elementOid = (AggregatedOid) referencedAdapter.getOid();
- final StateWriter elementWriter = writer.createElementWriter();
-
- //elementWriter.writeId(elementOid.getLocalId());
- elementWriter.writeOid(elementOid);
-
- writeFields(elementWriter, referencedAdapter);
- elementWriters.add(elementWriter);
- }
- writer.writeCollection(association.getId(), elementWriters);
- }
-
- private void writeCollectionOfReferences(final StateWriter writer, final ObjectAssociation association, final ObjectAdapter collectionAdapter) {
- final CollectionFacet collectionFacet = collectionAdapter.getSpecification().getFacet(CollectionFacet.class);
-
- final StringBuilder buf = new StringBuilder();
- for (final ObjectAdapter elementAdapter : collectionFacet.iterable(collectionAdapter)) {
- if (elementAdapter.isParented()) {
- throw new DomainModelException("Can't store an aggregated object within a collection that is not expected aggregates: " + elementAdapter + " (" + collectionAdapter + ")");
- }
- buf.append(keyCreator.oidStrFor(elementAdapter)).append("|");
- }
- if (buf.length() > 0) {
- writer.writeField(association.getId(), buf.toString());
- }
- }
-
-
- @Override
- public ObjectAdapter onAdapter() {
- return adapter;
- }
-
- @Override
- public String toString() {
- final ToString toString = new ToString(this);
- toString.append("spec", adapter.getSpecification().getFullIdentifier());
- toString.append("oid", adapter.getOid());
- return toString.toString();
- }
-
-
- protected AuthenticationSession getAuthenticationSession() {
- return IsisContext.getAuthenticationSession();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/NoSqlDataDatabase.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/NoSqlDataDatabase.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/NoSqlDataDatabase.java
deleted file mode 100644
index 4868b83..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/NoSqlDataDatabase.java
+++ /dev/null
@@ -1,47 +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.nosql.db;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
-
-public interface NoSqlDataDatabase {
-
- void open();
- void close();
-
- boolean containsData();
-
- void addService(ObjectSpecId objectSpecId, String key);
- String getService(ObjectSpecId objectSpecId);
-
- boolean hasInstances(ObjectSpecId objectSpecId);
- StateReader getInstance(String key, ObjectSpecId objectSpecId);
- Iterator<StateReader> instancesOf(ObjectSpecId objectSpecId);
- Iterator<StateReader> instancesOf(ObjectSpecId specId, ObjectAdapter pattern);
-
- long nextSerialNumberBatch(ObjectSpecId objectSpecId, int batchSize);
-
- void write(List<PersistenceCommand> commands);
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/NoSqlPersistorMechanismInstaller.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/NoSqlPersistorMechanismInstaller.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/NoSqlPersistorMechanismInstaller.java
deleted file mode 100644
index 3eefdf7..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/NoSqlPersistorMechanismInstaller.java
+++ /dev/null
@@ -1,113 +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.nosql.db;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import org.apache.isis.core.commons.config.ConfigurationConstants;
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.commons.factory.InstanceUtil;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapterFactory;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.NoSqlIdentifierGenerator;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.NoSqlObjectStore;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.none.DataEncryptionNone;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreatorDefault;
-import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.ObjectStoreSpi;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManagerSpi;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.IdentifierGenerator;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
-
-public abstract class NoSqlPersistorMechanismInstaller extends PersistenceMechanismInstallerAbstract {
-
- private static final Logger LOG = Logger.getLogger(NoSqlPersistorMechanismInstaller.class);
-
- private static final String NAKEDOBJECTS_ENCRYPTION_CLASSES = ConfigurationConstants.ROOT + "nosql.encryption";
-
- private NoSqlObjectStore objectStore;
-
- public NoSqlPersistorMechanismInstaller(final String name) {
- super(name);
- }
-
- @Override
- protected ObjectStoreSpi createObjectStore(final IsisConfiguration configuration, final ObjectAdapterFactory objectFactory, final AdapterManagerSpi adapterManager) {
- return getObjectStore(configuration);
- }
-
- @Override
- public IdentifierGenerator createIdentifierGenerator(final IsisConfiguration configuration) {
- return getObjectStore(configuration).getIdentifierGenerator();
- }
-
- private NoSqlObjectStore getObjectStore(final IsisConfiguration configuration) {
- if (objectStore == null) {
- //final KeyCreatorDefault keyCreator = createKeyCreator();
- final VersionCreator versionCreator = createVersionCreator();
- final NoSqlDataDatabase db = createNoSqlDatabase(configuration);
- final OidGenerator oidGenerator = new OidGenerator(createIdentifierGenerator(db));
-
- final Map<String, DataEncryption> availableDataEncryption = new HashMap<String, DataEncryption>();
- try {
- final String[] encryptionClasses = getConfiguration().getList(NAKEDOBJECTS_ENCRYPTION_CLASSES);
- DataEncryption writeWithEncryption = null;
- boolean encryptionSpecified = false;
- for (final String fullyQualifiedClass : encryptionClasses) {
- LOG.info(" adding encryption " + fullyQualifiedClass);
- final DataEncryption encryption = (DataEncryption) InstanceUtil.createInstance(fullyQualifiedClass);
- encryption.init(configuration);
- availableDataEncryption.put(encryption.getType(), encryption);
- if (!encryptionSpecified) {
- writeWithEncryption = encryption;
- }
- encryptionSpecified = true;
- }
- if (!encryptionSpecified) {
- LOG.warn("No encryption specified");
- final DataEncryption encryption = new DataEncryptionNone();
- availableDataEncryption.put(encryption.getType(), encryption);
- writeWithEncryption = encryption;
- }
- objectStore = new NoSqlObjectStore(db, oidGenerator, versionCreator, writeWithEncryption, availableDataEncryption);
- } catch (final IllegalArgumentException e) {
- throw new IsisException(e);
- } catch (final SecurityException e) {
- throw new IsisException(e);
- }
- }
- return objectStore;
- }
-
- protected NoSqlIdentifierGenerator createIdentifierGenerator(final NoSqlDataDatabase database) {
- return new NoSqlIdentifierGenerator(database);
- }
-
- protected abstract NoSqlDataDatabase createNoSqlDatabase(IsisConfiguration configuration);
-
- private VersionCreator createVersionCreator() {
- return new VersionCreatorDefault();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/StateReader.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/StateReader.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/StateReader.java
deleted file mode 100644
index d1986b5..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/StateReader.java
+++ /dev/null
@@ -1,64 +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.nosql.db;
-
-import java.util.List;
-
-import org.apache.isis.core.metamodel.adapter.oid.AggregatedOid;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-
-public interface StateReader {
-
- /**
- * Aggregated objects are persisted "under" a key taken from the
- * association (property or collection).
- *
- * <p>
- * This is not to be confused with the adapter's {@link AggregatedOid#getLocalId() localId},
- * which is a locally unique id for the adapter within the aggregate.
- *
- * <p>
- * The parameter passed here is the {@link OneToOneAssociation#getId() property Id}.
- *
- * @param associationId - under which the aggregate (property/collection) were persisted.
- */
- StateReader readAggregate(String propertyId);
-
- List<StateReader> readCollection(String collectionId);
-
- long readLongField(String id);
-
- String readField(String id);
-
- String readEncrytionType();
-
-// String readObjectType();
-// String readId();
-
- String readOid();
-
- String readVersion();
-
- String readUser();
-
- String readTime();
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/StateWriter.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/StateWriter.java b/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/StateWriter.java
deleted file mode 100644
index 051179d..0000000
--- a/component/objectstore/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/StateWriter.java
+++ /dev/null
@@ -1,51 +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.nosql.db;
-
-import java.util.List;
-
-import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
-
-public interface StateWriter {
-
- StateWriter addAggregate(String id);
-
-// void writeObjectType(String type);
-// void writeId(String oid);
-
- void writeOid(TypedOid typedOid);
-
- void writeEncryptionType(String type);
-
- void writeField(String id, String data);
-
- void writeField(String id, long l);
-
- void writeVersion(String currentVersion, String newVersion);
-
- void writeTime(String time);
-
- void writeUser(String user);
-
- void writeCollection(String id, List<StateWriter> elements);
-
- StateWriter createElementWriter();
-
-}