Skip to content

Conversation

@andi-huber
Copy link
Contributor

Key changes so far ...

Interface AdapterManger which allowed read/write access to the ObjectAdapter - cache/map is now gone.

This is replaced by new interface ObjectAdapterProvider, which does not expose the (if any) ObjectAdapter - cache/map.

This affects a lot of facet classes within the metamodel.

@Override
public Oid getOid() {
return oid;
}

@Override
public void replaceOid(Oid persistedOid) {
Copy link
Contributor Author

@andi-huber andi-huber Sep 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

field oid in ObjectAdapter is now final
oid replacement no longer allowed, so we intoduced ObjectAdapter withOid(RootOid newOid) to create a copy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 This looks like it's the main significant change in this PR... with the replaceOid stuff now removed.

protected final ObjectAdapter adapterFor(final RootOid rootOid) {
return getPersistenceSession().adapterFor(rootOid);
}
//TODO[ISIS-1976] not used !?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly changes behavior, need to investigate

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractIsisSessionTemplate is public API, so while it might not be used within the framework, it's possible that it's used by application code. However, let's remove it for now, see if we can simplify. If we do need an API like this, it should probably take Bookmark (from the applib) rather than RootOid. Also, should probably return just an Object (the domain object) rather than an ObjectAdapter - ie let's keep ObjectAdapter as an internal implementation detail and not in any of our APIs.

*
* @since 2.0.0-M2
*/
public class ObjectAdapterContext {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class is a product of refactoring, needs refinement later on; but is sane so far

return mementoSupportMixin;
}

// ------------------------------------------------------------------------------------------------
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from here downward: code is work in progress

*
* @since 2.0.0-M2
*/
class ObjectAdapterContext_AdapterManager {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package private mixin for ObjectAdapterContext: responsibility AdapterManager 'legacy' support

*
* @since 2.0.0-M2
*/
class ObjectAdapterContext_Consistency {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package private mixin for ObjectAdapterContext: responsibility Cache/Map consistency

*
* @since 2.0.0-M2
*/
class ObjectAdapterContext_Factories implements ObjectAdapterFactories {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package private mixin for ObjectAdapterContext: responsibility provides ObjectAdapter factories

*
* @since 2.0.0-M2
*/
class ObjectAdapterContext_MementoSupport implements MementoRecreateObjectSupport {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package private mixin for ObjectAdapterContext: responsibility provide object recreation to mementos

*
* @since 2.0.0-M2
*/
class ObjectAdapterContext_ObjectAdapterProvider implements ObjectAdapterProvider {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package private mixin for ObjectAdapterContext: responsibility provides ObjectAdapterProvider implementation

final Oid oid = RootOid.deStringEncoded(value);
final ObjectAdapter adapter = getPersistenceSession().getAdapterFor(oid);
return ObjectAdapterMemento.createOrNull(adapter);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method appears not used to me, but not really sure!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure either.

IConverter is part of Wicket's SPI, to convert strings that are input in forms to underlying objects. So this one seems to convert a string representation of an object (eg "cust.Customer:123", like a Bookmark#toString() would return) into an ObjectAdapterMemento, which is basically the Wicket UI's serializable model for an ObjectAdapter (more or less the same as a RootOid).

So, my guess is that it isn't used, because I can't think of anywhere that we have this abiliity for a user to enter "cust.Customer:123" and have the framework look up the corresponding object reference.

Therefore, let's not worry about it too much. Perhaps add a TODO to see about removing this entire class.

andi-huber and others added 17 commits September 4, 2018 20:57
@andi-huber andi-huber force-pushed the ISIS-1976-rethink-object-adapters branch from 074cecf to 2c70410 Compare September 4, 2018 20:25
final ObjectAdapter element = getAdapterManager().getAdapterFor(element2);
objectCollection.add(element);
for (final Object element : array) {
final ObjectAdapter elementAdapter = getObjectAdapterProvider().adapterFor(element);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change in behavior:
BEFORE: only a map lookup, which would not trigger ObjectAdapter creation
AFTER: triggers ObjectAdapter creation if required

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok.

I presume that if element == null then this implies that elementAdapter == null ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, pojo is nullable in ObjectAdapterContext_ObjectAdapterProvider ...

public ObjectAdapter adapterFor(Object pojo) {
        
        if(pojo == null) {
            return null;
        }
...
}

if(isEmpty(array)) {
return null;
}
return array.length > 0 ? getObjectAdapterProvider().adapterFor(array[0]) : null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change in behavior:
BEFORE: only a map lookup, which would not trigger ObjectAdapter creation
AFTER: triggers ObjectAdapter creation if required

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok.

// or if a copy is sufficient
return Collections2.transform(collectionOfUnderlying,
ObjectAdapter.Functions.adapter_ForUsing(getAdapterManager()));
return Collections2.transform(pojoCollection,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no change in behavior, but ...
Is this live-view actually required?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably would be fine to be a copy, but is there any need to change the behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to change behavior yet; just a standing question, that prevents removal of guava's class Collections2

}
}

// -- CACHING
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we do still have our caches, for the moment at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the point of merging this current state is to reduce the scope of java classes that are involved with coming changes with ISIS-1976

* FIXME[ISIS-1976] Note: whether or not 'bypassing mapping' should not be exposed by the API.
* So this further needs refactoring.
*/
ObjectAdapter specificationForViewModel(final Object viewModelPojo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name seems strange, as compared to the "adapterForViewModel" method below, because it returns an ObjectAdapter, not an ObjectSpecification.

My guess of what you're doing here is that the returned ObjectAdapter is ok to call "getSpecification()" on, but is in some sense incomplete because it has bypassed mapping?

Having these "incomplete" ObjectAdapters around seems dangerous though. Your comment does indeed have a FIXME. Is this code used elsewhere? What calls it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code, had me fooled, because it exploited a side-effect. So I had to quick fix this late last night.
2c70410

The interface for ObjectAdapterProvider will definitely change with further refactoring step.

@danhaywood
Copy link
Contributor

I think this PR is fine to merge.

To me it seems that mostly this is just moving functionality about ... the OidAdapterMap and PojoAdapterMap are still present, but relocated to ObjectAdapterContext.

The most significant change is that ObjectAdapter#rootOid is now final, and so the replacePojo stuff has gone, instead the ObjectAdapter is copied if the rootOid changes. This seems ok to me - or at least will be once we get to the stage where ObjectAdapters are instantiated as required and then discarded immediately afterwards.

The ObjectAdapterProvider#specificationForViewModel(...) - which returns an ObjectAdapter - looks a bit odd; I've created a separate comment for that. I suspect this is work in progress so happy to see how it plays out, but this code does look weird at the moment.

Copy link
Contributor

@danhaywood danhaywood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to merge, though I've added some comments above and elsewhere on the PR.

Main query re: the naming and responsibiliities of ObjectAdapterContext#specificationForViewModel(...)

this.transactionManager = new IsisTransactionManager(this, /*authenticationSession,*/ servicesInjector);

this.state = State.NOT_INITIALIZED;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this configuration property get removed? Or was the code just moved elsewhere? I'd prefer to keep it than lose it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andi-huber andi-huber merged commit 3d49fc7 into master Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants