SourceForge.net Logo
Main Overview Wiki Issues Forum Build Fisheye
Issue Details (XML | Word | Printable)

Key: CMP-500
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Shay Banon
Reporter: Aleksei Valikov
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Compass

Add saveResource() method to ComassOperations and implementing classes

Created: 08/Jan/08 01:59 AM   Updated: 14/Jan/08 11:31 AM
Component/s: Compass::Core
Affects Version/s: 1.2 GA
Fix Version/s: 2.0 M1


 Description  « Hide
CompassOperations provide a range of methods to work with the Resource directly:

createResource(...)
getResource(...)
loadResource(...)

However there are no saveResource(...) methods.

Could you please add these? Should be trivial.
Right now I have to cast to a DefaultCompassSession and use the getSearchEngine() for this operation (isn't nice).

Thanks.



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Shay Banon added a comment - 08/Jan/08 05:30 AM
You can call CompassSession#save and pass it a resource.

Aleksei Valikov added a comment - 08/Jan/08 05:50 AM
Did not worked for me in 1.2.M2...

Aleksei Valikov added a comment - 08/Jan/08 05:53 AM
ps. In any case a special-purpose method like saveResource(...) would be nice to have. It has a clear name (hard to be mistaken) - and it's just three lines of code to implement it.

Shay Banon added a comment - 08/Jan/08 11:14 AM
Does it work for you in 1.2 GA?

Aleksei Valikov added a comment - 14/Jan/08 08:23 AM
I'll check that and report back.

Aleksei Valikov added a comment - 14/Jan/08 09:50 AM
Sorry, it did not work out.

final Resource resource = session.getResource(recordClass,
recordDescription.getId());
if (resource != null) {
resource.removeProperties("status");
resource.addProperty("status", status);
session.save(resource);
}

SEVERE: Servlet.service() for servlet faces threw exception
java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.compass.core.accessor.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:128)
at org.compass.core.converter.mapping.osem.ClassMappingConverter$IdsAliasesObjectKey.<init>(ClassMappingConverter.java:476)
at org.compass.core.converter.mapping.osem.ClassMappingConverter.doMarshall(ClassMappingConverter.java:121)
at org.compass.core.converter.mapping.osem.ClassMappingConverter.marshall(ClassMappingConverter.java:63)
at org.compass.core.marshall.DefaultMarshallingStrategy.marshall(DefaultMarshallingStrategy.java:137)
at org.compass.core.marshall.DefaultMarshallingStrategy.marshall(DefaultMarshallingStrategy.java:143)
at org.compass.core.impl.DefaultCompassSession.save(DefaultCompassSession.java:307)

This however works allright:

final Resource resource = session.getResource(recordClass,
recordDescription.getId());
if (resource != null) {
resource.removeProperties("status");
resource.addProperty("status", status);
// session.save(resource);
if (session instanceof DefaultCompassSession) { ((DefaultCompassSession) session).getSearchEngine() .save(resource); }
}


Shay Banon added a comment - 14/Jan/08 10:51 AM
I see what you are trying to do now..., you basically have OSEM mappings, and you wish to save the underlying resource that represents it. Quite an advance usage of Compass, as special care needs to be taken with regards to unmarshalling of that resource afterwards, but it make sense. I will add it.

Aleksei Valikov added a comment - 14/Jan/08 10:57 AM
Thanks.
The scenario is: I have rather large documents in the database and compass index. In this very component I just need to update a single field of the object ("status"). Loading and saving the whole object is too much overhead so I prefer direct operations on the resource.
Thanks again.