Skip to content

Commit

Permalink
Core: refactor type storage pt.3 (#340).
Browse files Browse the repository at this point in the history
Done:
    - label configuration
    - view configuration

Does not yet work.
Do not install the "child-order" branch.

In preparation of "Child Topic Order".

See ticket 340.
  • Loading branch information
jri committed Oct 23, 2012
1 parent 59cb5bf commit c577a4b
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
*/
public interface ViewConfiguration {

// ### to be dropped from public interface
Iterable<TopicModel> getConfigTopics();

// ### to be dropped from public interface
TopicModel getConfigTopic(String configTypeUri);

// ### to be dropped from public interface
void addConfigTopic(TopicModel configTopic);

// ### TODO: add a getSetting() method

void addSetting(String configTypeUri, String settingUri, Object value);

// ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public void setPartCardinalityUri(String partCardinalityUri, ClientState clientS
dms.objectFactory.storePartCardinalityUri(getId(), partCardinalityUri);
}



// === Updating ===

@Override
Expand All @@ -132,6 +134,8 @@ public void update(AssociationDefinitionModel newModel, ClientState clientState,

// ------------------------------------------------------------------------------------------------- Private Methods



// === Update ===

private void updateAssocTypeUri(AssociationDefinitionModel newModel, ClientState clientState,
Expand Down Expand Up @@ -175,10 +179,12 @@ private void updatePartCardinality(String newPartCardinalityUri, ClientState cli
}
}

// === Helper ===


// === Attached Object Cache ===

private void initViewConfig() {
RoleModel configurable = new AssociationRoleModel(getId(), "dm4.core.assoc_def");
RoleModel configurable = dms.objectFactory.createConfigurableAssocDef(getId()); // ### ID is uninitialized
this.viewConfig = new AttachedViewConfiguration(configurable, getModel().getViewConfigModel(), dms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void setLabelConfig(List<String> labelConfig) {
// update memory
getModel().setLabelConfig(labelConfig);
// update DB
storeLabelConfig();
dms.objectFactory.storeLabelConfig(labelConfig, getModel().getAssocDefs().values());
}

// === View Configuration ===
Expand Down Expand Up @@ -181,56 +181,10 @@ public TypeModel getModel() {
return (TypeModel) super.getModel();
}



// ----------------------------------------------------------------------------------------- Package Private Methods

// ### to be dropped
void store(ClientState clientState) {
// 1) store the base-topic parts ### FIXME: call super.store() instead?
dms.storage.createTopic(getModel());
dms.associateWithTopicType(getModel());
setSimpleValue(getSimpleValue());
// Note: if no URI is set a default URI is generated
if (getUri().equals("")) {
setUri(DEFAULT_URI_PREFIX + getId());
}
// Note: the attached object cache must be initialized *after* storing the base-topic parts because
// initViewConfig() relies on the type's ID (unknown before stored) or URI (possibly unknown before stored).
// ### FIXME: this requirment must be dropped. Storage must be performed outside of this object.
//
// init attached object cache ### FIXME: to be dropped
initAssocDefs();
initViewConfig();
//
// Note: the attached object cache must be initialized *before* storing the type-specific parts because
// storeAssocDefs() relies on the association definitions.
// ### FIXME: this requirment must be dropped. Storage must rely solely on the model.
//
// 2) store the type-specific parts
// ### associateDataType();
// ### storeIndexModes();
// ### storeAssocDefs();
storeLabelConfig();
getViewConfig().store(clientState);
}

// ------------------------------------------------------------------------------------------------- Private Methods



// === Store ===

private void storeLabelConfig() {
List<String> labelConfig = getLabelConfig();
for (AssociationDefinition assocDef : getAssocDefs().values()) {
boolean includeInLabel = labelConfig.contains(assocDef.getUri());
assocDef.setChildTopicValue("dm4.core.include_in_label", new SimpleValue(includeInLabel));
}
}



// === Helper ===

/**
Expand Down Expand Up @@ -277,7 +231,7 @@ private AttachedAssociationDefinition _removeAssocDef(String assocDefUri) {
// ---

private void initViewConfig() {
RoleModel configurable = new TopicRoleModel(getId(), "dm4.core.type");
RoleModel configurable = dms.objectFactory.createConfigurableType(getId()); // ### type ID is uninitialized
this.viewConfig = new AttachedViewConfiguration(configurable, getModel().getViewConfigModel(), dms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ public void addConfigTopic(TopicModel configTopic) {
// update memory
model.addConfigTopic(configTopic);
// update DB
storeConfigTopic(configTopic, null); // ### FIXME: clientState=null. addConfigTopic() is not uesd anyway.
// ### storeConfigTopic(..., configTopic); // ### FIXME: a view config doesn't know its parent
throw new RuntimeException("not yet implemented"); // addConfigTopic() is currently not used
}

@Override
public void addSetting(String configTypeUri, String settingUri, Object value) {
// update memory
boolean configTopicCreated = model.addSetting(configTypeUri, settingUri, value);
model.addSetting(configTypeUri, settingUri, value);
// update DB
storeSetting(configTopicCreated, configTypeUri, settingUri, value);
dms.objectFactory.storeViewConfigSetting(configurable, configTypeUri, settingUri, value);
}

// ---
Expand All @@ -66,36 +67,4 @@ public void addSetting(String configTypeUri, String settingUri, Object value) {
public ViewConfigurationModel getModel() {
return model;
}

// ----------------------------------------------------------------------------------------- Package Private Methods

void store(ClientState clientState) {
try {
for (TopicModel configTopic : getConfigTopics()) {
storeConfigTopic(configTopic, clientState);
}
} catch (Exception e) {
throw new RuntimeException("Storing view configuration failed (configurable=" + configurable + ")", e);
}
}

// ----------------------------------------------------------------------------------------- Package Private Methods

private void storeConfigTopic(TopicModel configTopic, ClientState clientState) {
Topic topic = dms.createTopic(configTopic, clientState);
dms.createAssociation("dm4.core.aggregation", configurable,
new TopicRoleModel(topic.getId(), "dm4.core.view_config"));
}

private void storeSetting(boolean configTopicCreated, String configTypeUri, String settingUri, Object value) {
TopicModel configTopic = getConfigTopic(configTypeUri);
if (configTopicCreated) {
// Note: null is passed as clientState.
// addSetting() is called from a migration and in a migration we have no clientState anyway.
storeConfigTopic(configTopic, null);
} else {
Topic topic = new AttachedTopic(configTopic, dms);
topic.setChildTopicValue(settingUri, new SimpleValue(value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@ public Set<TopicType> getAllTopicTypes(ClientState clientState) {
public TopicType createTopicType(TopicTypeModel model, ClientState clientState) {
DeepaMehtaTransaction tx = beginTx();
try {
objectFactory.storeType(model);
AttachedTopicType topicType = new AttachedTopicType(model, this);
// ### Note: the topic type is put in type cache *before* it is stored. See createAssociationType().
// Note: the topic type is put in type cache *before* it is stored. See createAssociationType().
typeCache.put(topicType);
objectFactory.storeType(model);
//
fireEvent(CoreEvent.INTRODUCE_TOPIC_TYPE, topicType, clientState);
//
Expand Down Expand Up @@ -553,12 +553,12 @@ public Set<AssociationType> getAllAssociationTypes(ClientState clientState) {
public AssociationType createAssociationType(AssociationTypeModel model, ClientState clientState) {
DeepaMehtaTransaction tx = beginTx();
try {
objectFactory.storeType(model);
AttachedAssociationType assocType = new AttachedAssociationType(model, this);
// Note: the association type must be put in type cache *before* it is stored.
// Storing an object requires its data type to be known. See AttachedDeepaMehtaObject.store()
// Consider creation of association type "Composition Definition": it has a composition definition itself.
typeCache.put(assocType);
objectFactory.storeType(model);
//
tx.success();
return assocType;
Expand Down
Loading

0 comments on commit c577a4b

Please sign in to comment.