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 2016/05/21 07:10:50 UTC
[49/56] [abbrv] [partial] isis git commit: ISIS-1335: deleting the
mothballed directory.
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/ObjectReader.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/ObjectReader.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/ObjectReader.java
deleted file mode 100644
index 03ea9d9..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/ObjectReader.java
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql;
-
-import java.util.List;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.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.SpecificationLoader;
-import org.apache.isis.core.metamodel.spec.feature.Contributed;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociationContainer;
-import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
-import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.Persistor;
-import org.apache.isis.objectstore.nosql.db.StateReader;
-import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
-import org.apache.isis.objectstore.nosql.keys.KeyCreatorDefault;
-import org.apache.isis.objectstore.nosql.versions.VersionCreator;
-
-public class ObjectReader {
-
- private static final Logger LOG = LoggerFactory.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(Contributed.EXCLUDED);
- 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 SpecificationLoader getSpecificationLoader() {
- return IsisContext.getSpecificationLoader();
- }
-
- protected OidMarshaller getOidMarshaller() {
- return IsisContext.getOidMarshaller();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/WriteObjectCommand.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/WriteObjectCommand.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/WriteObjectCommand.java
deleted file mode 100644
index 844d129..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/WriteObjectCommand.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.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.util.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.Contributed;
-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.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.nosql.db.StateWriter;
-import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
-import org.apache.isis.objectstore.nosql.keys.KeyCreatorDefault;
-import org.apache.isis.objectstore.nosql.versions.VersionCreator;
-
-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(Contributed.EXCLUDED);
-
-// 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/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlDataDatabase.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlDataDatabase.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlDataDatabase.java
deleted file mode 100644
index a6e283b..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/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.objectstore.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.core.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/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlPersistorMechanismInstaller.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlPersistorMechanismInstaller.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlPersistorMechanismInstaller.java
deleted file mode 100644
index 05e94ae..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/NoSqlPersistorMechanismInstaller.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-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.core.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
-import org.apache.isis.core.runtime.persistence.objectstore.ObjectStoreSpi;
-import org.apache.isis.core.runtime.system.persistence.AdapterManagerSpi;
-import org.apache.isis.core.runtime.system.persistence.IdentifierGenerator;
-import org.apache.isis.core.runtime.system.persistence.OidGenerator;
-import org.apache.isis.objectstore.nosql.NoSqlIdentifierGenerator;
-import org.apache.isis.objectstore.nosql.NoSqlObjectStore;
-import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
-import org.apache.isis.objectstore.nosql.encryption.none.DataEncryptionNone;
-import org.apache.isis.objectstore.nosql.versions.VersionCreator;
-import org.apache.isis.objectstore.nosql.versions.VersionCreatorDefault;
-
-public abstract class NoSqlPersistorMechanismInstaller extends PersistenceMechanismInstallerAbstract {
-
- private static final Logger LOG = LoggerFactory.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/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateReader.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateReader.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateReader.java
deleted file mode 100644
index c7a3770..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/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.objectstore.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/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateWriter.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateWriter.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/StateWriter.java
deleted file mode 100644
index e605a56..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/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.objectstore.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();
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/ClientConnection.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/ClientConnection.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/ClientConnection.java
deleted file mode 100644
index cf19cf2..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/ClientConnection.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
-import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
-import org.apache.isis.objectstore.nosql.NoSqlStoreException;
-import org.apache.isis.objectstore.nosql.db.file.server.Util;
-
-public class ClientConnection {
-
- private static final Logger LOG = LoggerFactory.getLogger(ClientConnection.class);
-
- private final InputStream inputStream;
- private final OutputStream outputStream;
- private final PrintWriter writer;
- private final BufferedReader reader;
- private String[] headers;
- private int header;
-
- public ClientConnection(final InputStream input, final OutputStream output) {
- outputStream = Util.trace(output, true);
- writer = new PrintWriter(new OutputStreamWriter(outputStream, Util.ENCODING));
- inputStream = Util.trace(input, true);
- reader = new BufferedReader(new InputStreamReader(inputStream, Util.ENCODING));
- }
-
- public void close() {
- try {
- reader.close();
- } catch (final IOException e) {
- LOG.error("Failed to close connection", e);
- }
- writer.close();
- }
-
- void logComplete() {
- LOG.debug("request complete: " + outputStream);
- LOG.debug("response complete: " + inputStream);
- }
-
- void logFailure() {
- LOG.info("request failed: " + outputStream);
- LOG.info("response failed: " + inputStream);
- }
-
- public void request(final char command, final String request) {
- LOG.debug("request: " + command + request);
- write(command + request);
- }
-
- public void validateRequest() {
- writer.print('\n');
- writer.flush();
- getReponseHeader();
- final String status = readNext();
- if (status.equals("error")) {
- final String message = getResponseData();
- throw new RemotingException(message);
- } else if (status.equals("not-found")) {
- final String message = getResponseData();
- throw new ObjectNotFoundException(message);
- } else if (status.equals("concurrency")) {
- final String data = getResponseData();
- // TODO create better exceptions (requires way to restore
- // object/version)
- if (data.startsWith("{")) {
- throw new ConcurrencyException(data, null);
-
- } else {
- throw new ConcurrencyException(data, null);
-
- }
- } else if (!status.equals("ok")) {
- throw new RemotingException("Invalid status in response: " + status);
- }
- }
-
- public void requestData(final String data) {
- write(data);
- }
-
- public void endRequestSection() {
- writer.print('\n');
- }
-
- private void write(final String req) {
- writer.print(req);
- writer.print('\n');
- }
-
- public void getReponseHeader() {
- try {
- final String response = reader.readLine();
- LOG.debug("response: " + response);
- headers = response.split(" ");
- } catch (final IOException e) {
- throw new NoSqlStoreException(e);
- }
- }
-
- public String getResponse() {
- return readNext();
- }
-
- public boolean getResponseAsBoolean() {
- final String response = readNext();
- return response.equals("true") ? true : false;
- }
-
- public long getResponseAsLong() {
- final String response = readNext();
- return Long.valueOf(response).longValue();
- }
-
- /**
- * Read all the data until the next blank line
- */
- public String getResponseData() {
- try {
- final StringBuffer buffer = new StringBuffer();
- String line;
- while ((line = reader.readLine()) != null && line.length() > 0) {
- buffer.append(line);
- buffer.append('\n');
- }
- return buffer.toString();
- } catch (final Exception e) {
- logFailure();
- LOG.error(e.getMessage(), e);
- throw new RemotingException(e);
- }
- }
-
- private String readNext() {
- if (header >= headers.length) {
- throw new RemotingException("attempting to reader header property (index) " + header + " when there are only " + headers.length);
- }
- return headers[header++];
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileClientCommandContext.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileClientCommandContext.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileClientCommandContext.java
deleted file mode 100644
index df5357a..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileClientCommandContext.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file;
-
-import java.util.zip.CRC32;
-
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.objectstore.nosql.NoSqlCommandContext;
-import org.apache.isis.objectstore.nosql.db.StateWriter;
-
-class FileClientCommandContext implements NoSqlCommandContext {
-
- private final ClientConnection connection;
-
- public FileClientCommandContext(final ClientConnection connection) {
- this.connection = connection;
- }
-
- @Override
- public void start() {
- }
-
- @Override
- public void end() {
- }
-
- @Override
- public StateWriter createStateWriter(final ObjectSpecId specificationName) {
- return new JsonStateWriter();
- }
-
- @Override
- public void delete(final ObjectSpecId objectSpecId, final String key, final String version, final Oid oid) {
- connection.request('D', objectSpecId + " " + key + " " + version + " null");
- connection.endRequestSection();
- }
-
- @Override
- public void insert(final StateWriter writer) {
- write('I', (JsonStateWriter) writer);
- }
-
- @Override
- public void update(final StateWriter writer) {
- write('U', (JsonStateWriter) writer);
- }
-
- private void write(final char command, final JsonStateWriter writer) {
- connection.request(command, writer.getRequest());
- final String data = writer.getData();
-
- final CRC32 inputChecksum = new CRC32();
- inputChecksum.update(data.getBytes());
- inputChecksum.update('\n');
- final long checksum = inputChecksum.getValue();
- final String code = Long.toHexString(checksum);
-
- connection.requestData("00000000".substring(0, 8 - code.length()) + code + data);
- connection.endRequestSection();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileServerDb.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileServerDb.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileServerDb.java
deleted file mode 100644
index a3f32b1..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileServerDb.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file;
-
-import java.io.IOException;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.zip.CRC32;
-
-import org.apache.commons.lang.NotImplementedException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
-import org.apache.isis.objectstore.nosql.NoSqlCommandContext;
-import org.apache.isis.objectstore.nosql.NoSqlStoreException;
-import org.apache.isis.objectstore.nosql.db.NoSqlDataDatabase;
-import org.apache.isis.objectstore.nosql.db.StateReader;
-
-public class FileServerDb implements NoSqlDataDatabase {
-
- private static final Logger LOG = LoggerFactory.getLogger(FileServerDb.class);
-
- private final String host;
- private final int port;
-
- private final int timeout;
-
- public FileServerDb(final String host, final int port, final int timeout) {
- this.host = host;
- this.port = port == 0 ? 9012 : port;
- this.timeout = timeout;
- }
-
- // TODO pool connection and reuse
- private ClientConnection getConnection() {
- try {
- final Socket socket;
- socket = new Socket(host, port);
- socket.setSoTimeout(timeout);
- return new ClientConnection(socket.getInputStream(), socket.getOutputStream());
- } catch (final UnknownHostException e) {
- throw new NoSqlStoreException("Unknow host " + host, e);
- } catch (final IOException e) {
- throw new NoSqlStoreException("Failed to connect to " + host + ":" + port, e);
- }
-
- }
-
- // TODO pool connection and reuse
- private void returnConnection(final ClientConnection connection) {
- connection.logComplete();
- connection.close();
- }
-
- // TODO pool connection and reuse - probably need to replace the connection
- private void abortConnection(final ClientConnection connection) {
- connection.logFailure();
- connection.close();
- }
-
- @Override
- public StateReader getInstance(final String key, final ObjectSpecId objectSpecId) {
- final ClientConnection connection = getConnection();
- String data;
- try {
- final String request = objectSpecId + " " + key;
- connection.request('R', request);
- connection.validateRequest();
- data = connection.getResponseData();
- } catch (final RuntimeException e) {
- LOG.error("aborting getInstance", e);
- abortConnection(connection);
- throw e;
- }
- data = checkData(data);
- final JsonStateReader reader = new JsonStateReader(data);
- returnConnection(connection);
- return reader;
- }
-
- @Override
- public Iterator<StateReader> instancesOf(final ObjectSpecId objectSpecId) {
- final ClientConnection connection = getConnection();
- List<StateReader> instances;
- try {
- instances = new ArrayList<StateReader>();
- connection.request('L', objectSpecId + " 0");
- connection.validateRequest();
- String data;
- while ((data = connection.getResponseData()).length() > 0) {
- data = checkData(data);
- final JsonStateReader reader = new JsonStateReader(data);
- instances.add(reader);
- }
- } catch (final RuntimeException e) {
- LOG.error("aborting instancesOf", e);
- abortConnection(connection);
- throw e;
- }
- returnConnection(connection);
- return instances.iterator();
-
- }
-
- private String checkData(final String data) {
- final String objectData = data.substring(8);
-
- final CRC32 inputChecksum = new CRC32();
- inputChecksum.update(objectData.getBytes());
- final long actualChecksum = inputChecksum.getValue();
-
- final String encodedChecksum = data.substring(0, 8);
- final long expectedChecksum = Long.valueOf(encodedChecksum, 16);
-
- if (actualChecksum != expectedChecksum) {
- throw new NoSqlStoreException("Data integrity error; checksums different");
- }
-
- return objectData;
- }
-
- @Override
- public void write(final List<PersistenceCommand> commands) {
- final ClientConnection connection = getConnection();
- PersistenceCommand currentCommand = null;
- try {
- connection.request('W', "");
- final NoSqlCommandContext context = new FileClientCommandContext(connection);
- for (final PersistenceCommand command : commands) {
- currentCommand = command;
- command.execute(context);
- }
- connection.validateRequest();
-
- } catch (final ConcurrencyException e) {
- throw e;
- } catch (final RuntimeException e) {
- LOG.error("aborting write, command: " + currentCommand, e);
- abortConnection(connection);
- throw e;
- }
- returnConnection(connection);
- }
-
- @Override
- public void close() {
- }
-
- @Override
- public void open() {
- }
-
- @Override
- public boolean containsData() {
- final ClientConnection connection = getConnection();
- boolean flag;
- try {
- connection.request('X', "contains-data");
- connection.validateRequest();
- flag = connection.getResponseAsBoolean();
- } catch (final RuntimeException e) {
- LOG.error("aborting containsData", e);
- abortConnection(connection);
- throw e;
- }
- returnConnection(connection);
- return flag;
- }
-
- @Override
- public long nextSerialNumberBatch(final ObjectSpecId name, final int batchSize) {
- final ClientConnection connection = getConnection();
- long serialNumber;
- try {
- connection.request('N', name + " " + Integer.toString(batchSize));
- connection.validateRequest();
- serialNumber = connection.getResponseAsLong();
- } catch (final RuntimeException e) {
- LOG.error("aborting nextSerialNumberBatch", e);
- abortConnection(connection);
- throw e;
- }
- returnConnection(connection);
- return serialNumber;
- }
-
- @Override
- public void addService(final ObjectSpecId objectSpecId, final String key) {
- final ClientConnection connection = getConnection();
- try {
- connection.request('T', objectSpecId.asString() + " " + key);
- connection.validateRequest();
- } catch (final RuntimeException e) {
- LOG.error("aborting addService", e);
- abortConnection(connection);
- throw e;
- }
- returnConnection(connection);
- }
-
- @Override
- public String getService(final ObjectSpecId objectSpecId) {
- final ClientConnection connection = getConnection();
- String response;
- try {
- connection.request('S', objectSpecId.asString());
- connection.validateRequest();
- response = connection.getResponse();
- } catch (final RuntimeException e) {
- LOG.error("aborting getServices", e);
- abortConnection(connection);
- throw e;
- }
- returnConnection(connection);
- return response.equals("null") ? null : response;
- }
-
- @Override
- public boolean hasInstances(final ObjectSpecId objectSpecId) {
- final ClientConnection connection = getConnection();
- boolean hasInstances;
- try {
- connection.request('I', objectSpecId.asString());
- connection.validateRequest();
- hasInstances = connection.getResponseAsBoolean();
- } catch (final RuntimeException e) {
- LOG.error("aborting hasInstances", e);
- abortConnection(connection);
- throw e;
- }
- returnConnection(connection);
- return hasInstances;
- }
-
- public Iterator<StateReader> instancesOf(ObjectSpecId specId, ObjectAdapter pattern) {
- // TODO implement
- throw new NotImplementedException();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileServerPersistorMechanismInstaller.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileServerPersistorMechanismInstaller.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileServerPersistorMechanismInstaller.java
deleted file mode 100644
index 28e7a07..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/FileServerPersistorMechanismInstaller.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file;
-
-import org.apache.isis.core.commons.config.ConfigurationConstants;
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.objectstore.nosql.db.NoSqlDataDatabase;
-import org.apache.isis.objectstore.nosql.db.NoSqlPersistorMechanismInstaller;
-
-public class FileServerPersistorMechanismInstaller extends NoSqlPersistorMechanismInstaller {
-
- private static final String ROOT = ConfigurationConstants.ROOT + "nosql.fileserver.";
- private static final String DB_HOST = ROOT + "host";
- private static final String DB_PORT = ROOT + "port";
- private static final String DB_TIMEMOUT = ROOT + "timeout";
-
- public FileServerPersistorMechanismInstaller() {
- super("fileserver");
- }
-
- @Override
- protected NoSqlDataDatabase createNoSqlDatabase(final IsisConfiguration configuration) {
- NoSqlDataDatabase db;
- final String host = configuration.getString(DB_HOST, "localhost");
- final int port = configuration.getInteger(DB_PORT, 0);
- final int timeout = configuration.getInteger(DB_TIMEMOUT, 5000);
- db = new FileServerDb(host, port, timeout);
- return db;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/JsonStateReader.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/JsonStateReader.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/JsonStateReader.java
deleted file mode 100644
index e471b2c..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/JsonStateReader.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import org.apache.isis.objectstore.nosql.NoSqlStoreException;
-import org.apache.isis.objectstore.nosql.db.StateReader;
-
-public class JsonStateReader implements StateReader {
-
- // private static final Logger LOG = LoggerFactory.getLogger(FileStateReader.class);
-
- private JSONObject instance;
-
- public JsonStateReader(final String data) {
- try {
- final JSONObject instance = new JSONObject(data);
- this.instance = instance;
- } catch (final JSONException e) {
- throw new NoSqlStoreException("failed initialise JSON object for text form: " + data, e);
- }
- }
-
- private JsonStateReader(final JSONObject aggregatedObject) {
- instance = aggregatedObject;
- }
-
- @Override
- public StateReader readAggregate(final String name) {
- if (instance.has(name)) {
- final JSONObject aggregatedObject = instance.optJSONObject(name);
- if (aggregatedObject == null) {
- return null;
- } else {
- return new JsonStateReader(aggregatedObject);
- }
- } else {
- return null;
- }
- }
-
- @Override
- public long readLongField(final String id) {
- final Object value = instance.opt(id);
- if (value == null) {
- return 0;
- } else {
- return Long.valueOf((String) value);
- }
- }
-
- @Override
- public String readField(final String name) {
- if (instance.has(name)) {
- final Object value = instance.optString(name);
- if (value == null) {
- return null;
- } else {
- return (String) value;
- }
- } else {
- return null;
- }
- }
-
-// @Override
-// public String readObjectType() {
-// return readRequiredField("_type");
-// }
-//
-// @Override
-// public String readId() {
-// return readRequiredField("_id");
-// }
-
- @Override
- public String readOid() {
- return readRequiredField(PropertyNames.OID);
- }
-
- @Override
- public String readVersion() {
- return readRequiredField(PropertyNames.VERSION);
- }
-
- @Override
- public String readEncrytionType() {
- try {
- String encryptionType;
- if (instance.has("_encrypt")) {
- encryptionType = instance.getString("_encrypt");
- } else {
- encryptionType = "none";
- }
- return encryptionType;
- } catch (final JSONException e) {
- throw new NoSqlStoreException("failed to read field _encrypt", e);
- }
- }
-
- @Override
- public String readUser() {
- return readRequiredField(PropertyNames.USER);
- }
-
- @Override
- public String readTime() {
- return readRequiredField(PropertyNames.TIME);
- }
-
- private String readRequiredField(final String name) {
- try {
- final Object value = instance.get(name);
- return (String) value;
- } catch (final JSONException e) {
- throw new NoSqlStoreException("failed to read field " + name, e);
- }
- }
-
- @Override
- public List<StateReader> readCollection(final String id) {
- final JSONArray array = instance.optJSONArray(id);
- final List<StateReader> readers = new ArrayList<StateReader>();
- if (array != null) {
- final int size = array.length();
- for (int i = 0; i < size; i++) {
- readers.add(new JsonStateReader(array.optJSONObject(i)));
- }
- }
- return readers;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/JsonStateWriter.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/JsonStateWriter.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/JsonStateWriter.java
deleted file mode 100644
index b63c079..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/JsonStateWriter.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file;
-
-import java.util.List;
-
-import com.google.common.collect.Lists;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
-import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.nosql.NoSqlStoreException;
-import org.apache.isis.objectstore.nosql.db.StateWriter;
-
-public class JsonStateWriter implements StateWriter {
-
- private final JSONObject dbObject = new JSONObject();
-
- private TypedOid oid;
- private String currentVersion;
- private String newVersion;
-
-
- @Override
- public StateWriter addAggregate(final String id) {
- final JsonStateWriter jsonStateWriter = new JsonStateWriter();
- try {
- dbObject.put(id, jsonStateWriter.dbObject);
- } catch (final JSONException e) {
- throw new NoSqlStoreException(e);
- }
- return jsonStateWriter;
- }
-
- @Override
- public void writeOid(final TypedOid typedOid) {
- this.oid = typedOid;
- writeField(PropertyNames.OID, typedOid.enString(getOidMarshaller()));
- }
-
- @Override
- public void writeEncryptionType(final String type) {
- writeField(PropertyNames.ENCRYPT, type);
- }
-
- @Override
- public void writeVersion(final String currentVersion, final String newVersion) {
- this.currentVersion = currentVersion;
- this.newVersion = newVersion;
- writeField(PropertyNames.VERSION, newVersion);
- }
-
- @Override
- public void writeTime(final String time) {
- writeField(PropertyNames.TIME, time);
- }
-
- @Override
- public void writeUser(final String user) {
- writeField(PropertyNames.USER, user);
- }
-
- @Override
- public void writeField(final String id, final String data) {
- try {
- dbObject.put(id, data == null ? JSONObject.NULL : data);
- } catch (final JSONException e) {
- throw new NoSqlStoreException(e);
- }
- }
-
- @Override
- public void writeField(final String id, final long l) {
- try {
- dbObject.put(id, Long.toString(l));
- } catch (final JSONException e) {
- throw new NoSqlStoreException(e);
- }
- }
-
- public String getRequest() {
- return oid.enString(getOidMarshaller()) + " " + currentVersion + " " + newVersion;
- }
-
- public String getData() {
- try {
- return dbObject.toString(4);
- } catch (final JSONException e) {
- throw new NoSqlStoreException(e);
- }
- }
-
- @Override
- public StateWriter createElementWriter() {
- return new JsonStateWriter();
- }
-
- @Override
- public void writeCollection(final String id, final List<StateWriter> elements) {
- final List<JSONObject> collection = Lists.newArrayList();
- for (final StateWriter writer : elements) {
- collection.add(((JsonStateWriter) writer).dbObject);
- }
- try {
- dbObject.put(id, collection);
- } catch (final JSONException e) {
- throw new NoSqlStoreException(e);
- }
- }
-
-
- ///////////////////////////////////////////////////////
- // dependencies (from context)
- ///////////////////////////////////////////////////////
-
- protected OidMarshaller getOidMarshaller() {
- return IsisContext.getOidMarshaller();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/PropertyNames.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/PropertyNames.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/PropertyNames.java
deleted file mode 100644
index ac4e282..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/PropertyNames.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file;
-
-interface PropertyNames {
- static final String ENCRYPT = "_encrypt";
-
-// static final String TYPE = "_type";
-// static final String ID = "_id";
-
- static final String OID = "_oid";
- static final String VERSION = "_version";
- static final String TIME = "_time";
- static final String USER = "_user";
-}
-
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/RemotingException.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/RemotingException.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/RemotingException.java
deleted file mode 100644
index e76d5f6..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/RemotingException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file;
-
-import org.apache.isis.core.commons.exceptions.IsisException;
-
-public class RemotingException extends IsisException {
-
- private static final long serialVersionUID = 1L;
-
- public RemotingException(final String message) {
- super(message);
- }
-
- public RemotingException(final Exception e) {
- super(e);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/DataFileReader.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/DataFileReader.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/DataFileReader.java
deleted file mode 100644
index b10163d..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/DataFileReader.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file.server;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class DataFileReader {
- private static final Logger LOG = LoggerFactory.getLogger(DataFileReader.class);
-
- private final BufferedReader reader;
- private final String id;
- private final String version;
-
- /**
- * Opens the file for the specified id. The top line contains: type id
- * version newline The remainder contains the data.
- */
- public DataFileReader(final String type, final String id) throws IOException {
- final File file = Util.dataFile(type, id);
- reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
- final String line = reader.readLine();
- if (line == null || line.length() == 0) {
- throw new FileServerException("No data in file: " + file.getAbsolutePath());
- }
- final String[] split = line.split(" ");
- this.id = split[1];
- if (!id.equals(id)) {
- throw new FileServerException("Id in file (" + this.id + ") not the same as the file name: " + file.getAbsolutePath());
- }
- version = split[2];
- }
-
- public void close() {
- if (reader != null) {
- try {
- reader.close();
- } catch (final IOException e) {
- LOG.error("Failed to close reader " + reader, e);
- }
- }
- }
-
- public String getId() {
- return id;
- }
-
- public String getVersion() {
- return version;
- }
-
- public String getData() {
- try {
- final StringBuffer buffer = new StringBuffer();
- String line;
- while ((line = reader.readLine()) != null) {
- buffer.append(line);
- buffer.append("\n");
- }
- return buffer.toString();
- } catch (final IOException e) {
- throw new FileServerException("Failed to read data for " + id, e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/DataFileWriter.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/DataFileWriter.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/DataFileWriter.java
deleted file mode 100644
index ac13b5e..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/DataFileWriter.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file.server;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.List;
-
-public class DataFileWriter {
-
- // private static final Logger LOG = LoggerFactory.getLogger(DataWriter.class);
-
- private final List<FileContent> files;
-
- public DataFileWriter(final List<FileContent> files) {
- this.files = files;
- }
-
- public void writeData() throws IOException {
- for (final FileContent content : files) {
- if (Util.isDelete(content.command)) {
- final File f = Util.dataFile(content.type, content.id);
- f.delete();
- } else {
- writeFile(content);
- }
- }
- }
-
- // TODO to be consistent use PrintWriter
- private void writeFile(final FileContent content) throws IOException {
- FileOutputStream output = null;
- final File file = Util.dataFile(content.type, content.id);
- if (!file.getParentFile().exists()) {
- file.getParentFile().mkdir();
- }
- try {
- output = new FileOutputStream(file);
- content.write(output);
- } finally {
- Util.closeSafely(output);
- }
- }
-
- public void close() {
- // TODO Auto-generated method stub
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a43dbdd9/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/FileContent.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/FileContent.java b/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/FileContent.java
deleted file mode 100644
index c794dbf..0000000
--- a/mothballed/component/objectstore/nosql/src/main/java/org/apache/isis/objectstore/nosql/db/file/server/FileContent.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.objectstore.nosql.db.file.server;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-class FileContent {
-
- private static final String ENCODING = "utf-8";
-
- final char command;
- final String id;
- final String currentVersion;
- final String newVersion;
- final String data;
- final String type;
-
- public FileContent(final char command, final String id, final String currentVersion, final String newVersion, final String type, final String buf) {
- this.command = command;
- this.id = id;
- this.currentVersion = currentVersion;
- this.newVersion = newVersion;
- this.type = type;
- this.data = buf;
- }
-
- public void write(final OutputStream output) throws IOException {
- output.write(type.getBytes(ENCODING));
- output.write(' ');
- output.write(id.getBytes(ENCODING));
- output.write(' ');
- output.write(newVersion.getBytes(ENCODING));
- output.write('\n');
- output.write(data.getBytes(ENCODING));
- }
-
-}