Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODE-1706 Support for extra properties #599

Merged
merged 6 commits into from
Nov 15, 2012
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions modeshape-jcr/src/main/java/org/modeshape/jcr/Connectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeTypeManager;
import org.infinispan.schematic.Schematic;
import org.infinispan.schematic.SchematicEntry;
import org.infinispan.schematic.document.Document;
import org.infinispan.schematic.document.EditableDocument;
import org.infinispan.util.ReflectionUtil;
import org.modeshape.common.SystemFailureException;
import org.modeshape.common.logging.Logger;
import org.modeshape.jcr.RepositoryConfiguration.Component;
import org.modeshape.jcr.cache.NodeKey;
import org.modeshape.jcr.cache.document.DocumentTranslator;
import org.modeshape.jcr.cache.document.LocalDocumentStore;
import org.modeshape.jcr.federation.Connector;
import org.modeshape.jcr.federation.ExtraPropertiesStore;
import org.modeshape.jcr.value.Name;
import org.modeshape.jcr.value.Property;

/**
* Class which maintains (based on the configuration) the list of available connectors for a repository.
Expand Down Expand Up @@ -193,6 +201,14 @@ protected void initializeConnector( Connector connector,
// Set the MIME type detector ...
ReflectionUtil.setValue(connector, "mimeTypeDetector", repository.mimeTypeDetector());

// Set the ExtraPropertiesStore instance, which is unique to this connector ...
LocalDocumentStore store = repository.documentStore().localStore();
String name = connector.getSourceName();
String sourceKey = NodeKey.keyForSourceName(name);
DocumentTranslator translator = getDocumentTranslator();
ExtraPropertiesStore defaultExtraPropertiesStore = new LocalDocumentStoreExtraProperties(store, sourceKey, translator);
ReflectionUtil.setValue(connector, "extraPropertiesStore", defaultExtraPropertiesStore);

connector.initialize(registry, nodeTypeManager);

// If successful, call the 'postInitialize' method reflectively (due to inability to call directly) ...
Expand Down Expand Up @@ -224,4 +240,78 @@ public DocumentTranslator getDocumentTranslator() {
public boolean hasConnectors() {
return !sourceKeyToConnectorMap.isEmpty();
}

protected static class LocalDocumentStoreExtraProperties implements ExtraPropertiesStore {
private final LocalDocumentStore localStore;
private final String sourceKey;
private final DocumentTranslator translator;

protected LocalDocumentStoreExtraProperties( LocalDocumentStore localStore,
String sourceKey,
DocumentTranslator translator ) {
this.localStore = localStore;
this.sourceKey = sourceKey;
this.translator = translator;
assert this.localStore != null;
assert this.sourceKey != null;
assert this.translator != null;
}

protected String keyFor( String id ) {
return sourceKey + ":" + id;
}

@Override
public Map<Name, Property> getProperties( String id ) {
String key = keyFor(id);
SchematicEntry entry = localStore.get(key);
if (entry == null) return NO_PROPERTIES;
Document doc = entry.getContentAsDocument();
Map<Name, Property> props = new HashMap<Name, Property>();
translator.getProperties(doc, props);
return props;
}

@Override
public boolean removeProperties( String id ) {
String key = keyFor(id);
return localStore.remove(key);
}

@Override
public void storeProperties( String id,
Map<Name, Property> properties ) {
String key = keyFor(id);
EditableDocument doc = Schematic.newDocument();
for (Map.Entry<Name, Property> entry : properties.entrySet()) {
Property property = entry.getValue();
if (property != null) {
translator.setProperty(doc, property, null);
}
}
localStore.storeDocument(key, doc);
}

@Override
public void updateProperties( String id,
Map<Name, Property> properties ) {
String key = keyFor(id);
SchematicEntry entry = localStore.get(key);
EditableDocument doc = null;
if (entry != null) {
doc = entry.editDocumentContent();
} else {
doc = Schematic.newDocument();
}
for (Map.Entry<Name, Property> propertyEntry : properties.entrySet()) {
Property property = propertyEntry.getValue();
if (property != null) {
translator.setProperty(doc, property, null);
} else {
translator.removeProperty(doc, propertyEntry.getKey(), null);
}
}
localStore.storeDocument(key, doc);
}
}
}
4 changes: 4 additions & 0 deletions modeshape-jcr/src/main/java/org/modeshape/jcr/JcrI18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public final class JcrI18n {
public static I18n fileConnectorCannotWriteToDirectory;
public static I18n fileConnectorTopLevelDirectoryMissingOrCannotBeRead;
public static I18n fileConnectorNodeIdentifierIsNotWithinScopeOfConnector;
public static I18n fileConnectorIsReadOnly;
public static I18n fileConnectorCannotStoreFileThatIsExcluded;
public static I18n couldNotStoreProperties;
public static I18n couldNotStoreProperty;

public static I18n rootNodeHasNoParent;
public static I18n rootNodeIsNotProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
/**
*
*/
public class JcrSession implements Session {
public class JcrSession implements org.modeshape.jcr.api.Session {

private static final String[] NO_ATTRIBUTES_NAMES = new String[] {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.modeshape.common.util.ObjectUtil;
import org.modeshape.common.util.StringUtil;
import org.modeshape.jcr.clustering.DefaultChannelProvider;
import org.modeshape.jcr.federation.filesystem.FileSystemConnector;
import org.modeshape.jcr.security.AnonymousProvider;
import org.modeshape.jcr.security.JaasProvider;
import org.modeshape.jcr.value.binary.AbstractBinaryStore;
Expand All @@ -82,6 +83,7 @@
import org.modeshape.jcr.value.binary.FileSystemBinaryStore;
import org.modeshape.jcr.value.binary.TransientBinaryStore;
import org.modeshape.jcr.value.binary.infinispan.InfinispanBinaryStore;
import org.modeshape.sequencer.cnd.CndSequencer;

/**
* A representation of the configuration for a {@link JcrRepository JCR Repository}.
Expand Down Expand Up @@ -601,7 +603,7 @@ public enum FileSystemAccessType {
aliases.put("servletprovider", servletProvider);
PROVIDER_ALIASES = Collections.unmodifiableMap(aliases);

String cndSequencer = "org.modeshape.sequencer.cnd.CndSequencer";
String cndSequencer = CndSequencer.class.getName();
String classfileSequencer = "org.modeshape.sequencer.classfile.ClassFileSequencer";
String ddlSequencer = "org.modeshape.sequencer.ddl.DdlSequencer";
String imageSequencer = "org.modeshape.sequencer.image.ImageMetadataSequencer";
Expand Down Expand Up @@ -655,7 +657,13 @@ public enum FileSystemAccessType {

SEQUENCER_ALIASES = Collections.unmodifiableMap(aliases);

String fileSystemConnector = FileSystemConnector.class.getName();

aliases = new HashMap<String, String>();
aliases.put("files", fileSystemConnector);
aliases.put("filesystem", fileSystemConnector);
aliases.put("filesystemconnector", fileSystemConnector);

CONNECTOR_ALIASES = Collections.unmodifiableMap(aliases);

String tikaExtractor = "org.modeshape.extractor.tika.TikaTextExtractor";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ public void updateDocument( String key,
* Remove the existing document at the given key.
*
* @param key the key or identifier for the document
* @return true if a document was removed, or false if there was no document with that key
* @throws DocumentStoreException if there is a problem removing the document
*/
public void remove( String key );
public boolean remove( String key );

/**
* Determine whether the database contains an entry with the supplied key.
Expand Down Expand Up @@ -126,9 +127,10 @@ public String createExternalProjection( String federatedNodeKey,

/**
* Returns a document representing a block of children, that has the given key.
*
* @param key a {@code non-null} String the key of the block
* @return either a {@link Document} with children and possibly a pointer to the next block, or {@code null} if there isn't
* a block with such a key.
* @return either a {@link Document} with children and possibly a pointer to the next block, or {@code null} if there isn't a
* block with such a key.
*/
public Document getChildrenBlock( String key );
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public void replace( String key,
}

@Override
public void remove( String key ) {
database.remove(key);
public boolean remove( String key ) {
return database.remove(key) != null;
}

@Override
Expand Down
Loading