Realm Query - RealmResults<SuperclassType> - realm

Quite new to Realm, but off the bat I like it.
With that said, since progging in Java, I'm using inheritance/polymorphism extensively.
Does anyone know if Realm supports querying for saved data by using a superclass type that extends realm object?
eg:
final RealmResults result = iRealm.where(SuperclassType.class).findAll();
Thanks Kindly

It is not supported right now. You can follow https://github.com/realm/realm-java/issues/761 for that. Until then you need to use composition over inheritance: https://en.wikipedia.org/wiki/Composition_over_inheritance

Related

How to serialize and deserialize DynamoDB Stream Record object

We are planning to use DynamoDB Stream, part of stream processing we need com.amazonaws.services.dynamodbv2.model.Record object to be serialized and deserialized. I know we can do java ObjectOutputStream and ObjectInputStream, but this does not suffice our needs.
The need is we have to manage versions in deserializer and serializer because if there is a change in Record structure or new version, we can not upgrade all the services which use deserializer to upgrade at one shot.
Is there a way to do this?
I think I found a solution.
Serialize : new RecordAdapter(record).getData
Deserialize: new RecordObjectMapper().readValue(new String(bytes), Record.class)
Thank you, Jason
For anyone coming back to this in 2022, the classes are here:
https://javadoc.io/static/com.amazonaws/dynamodb-streams-kinesis-adapter/1.5.0/index.html?com/amazonaws/services/dynamodbv2/streamsadapter/model/RecordAdapter.html
in the dynamodb-streams-kinesis-adapter library
project is here: https://github.com/awslabs/dynamodb-streams-kinesis-adapter

How to create a new Project using the 'project.edit' Conduit API call

Using Conduit, I would like to create a new project.
However, the Conduit documentation is rather cryptic, and the Transaction Types of 'project.edit' don't really give a clue on what transaction(s) are required/optional, to establish this.
I realize that there is a 'project.create' but is marked as to be deprecated.
Could any of you help me out here?
Basically if you don't specify an objectIdentifier, project.edit will create a new project. Probably the name is mandatory, I don't think that anything else is for projects.

Alfresco Java backed web-script lookup by cmis:objectId

I am writing my first java-backed webscript for Alfresco community edition. I am implementing document properties / preview service, and I take a parameter which is the cmis:objectId of the document in question. I'm having trouble getting started because I haven't been able to access the document based on the cmis id.
What is the best way to get a document (NodeRef?) based on the cmis:objectId when operating server-side in a web-script controller? I see Jeff Potts' great examples on how to implement web scripts, but the mixing of the Java API and CMIS concepts has me stuck. Should I just use the search service and find the object based on the cmis:objectId property? Any pointers appreciated.
Well, the answer is a little ugly, but hopefully this helps someone...
A good way to look up the NodeRef using an 'opaque' objectId should be to use CMISServices, obtained from the registry in your java backed web script, i.e.
docRef = registry.getCMISService().getLatestVersion(docIdStr, false);
Unfortunately, there's a bug in the Alfresco code (or so it seems to me, admittedly a bit of a newbie). The alfresco CMISServicesImpl.getLatestVersion() uses a getObject() method under the covers. That method takes an objectId String as a parameter, but then strips off the version information at the end (i.e. the ";1.0" part of the objectId) and then checks to see if the remaining string is a valid NodeRef. In doing so, it checks it against this pattern (in NodeRef.java):
private static final Pattern nodeRefPattern = Pattern.compile(".+://.+/.+");
If the validation fails, you get a CMISInvalidArgumentException, with a message that xxxxx "is not an object ID".
So, to make a long story short, when I call the web script using a parameter for the objectId like this:
29ea5a16-12a8-497d-aad3-f43969e8a672;1.0
I get the CMIS exception. But, if I call the method with an objectId parameter that looks like this:
workspace://SpacesStore/29ea5a16-12a8-497d-aad3-f43969e8a672;1.0
... then, the "CMIS" lookup succeeds and I get my desired NodeRef back. Of course, all that the CMIS services are doing under the covers is stripping off the ";1.0" from the object ID, treating it as a NodeRef string, and doing the lookup using that.
In other words, you can't do it the right way in 4.2. The best thing to do is as #Gagravarr says and tweak your own objectId string to turn it into a NodeRef. Hopefully it's fixed in 5.x.

How to know such classes like XmlWriter type and its sytnax?

Might seems silly question and can learn from google but I am new to C# and trying to figure out possible future clarifications. So here is best places to ask.
For example:
Why do not we write;
XmlWriter writer = new XmlWriter("C:\\1.xml",settings);
instead writing;
XmlWriter writer = XmlWriter.Create("C:\\1.xml",settings);
(No new keyword and .Create method.)
What is XmlWriter fully named as a class?
Also how do I know in BCL which class to instantiate how? Like how do I know its syntax if I do not know. What is the ieasy way? How can intelligence help me?
Because this is a factory method, it creates one of the derived classes like XmlWellFormedWriter, XmlAsyncCheckWriter, etc. which depend on settings.

LINQ to SQL repository - caching data

I have built my first MVC solution and used the repository pattern for retrieving/inserting/updating my database.
I am now in the process of refactoring and I've noticed that a lot of (in fact all) the methods within my repository are hitting the database everytime. This seems overkill and what I'd ideally like is to do is 'cache' the main data object e.g. 'GetAllAdverts' from the database and to then query against this cached object for things like 'FindAdvert(id), AddAdvert(), DeleteAdvert() etc..'
I'd also need to consider updating/deleting/adding records to this cache object and the database.
What is the best apporoach for something like this?
My knowledge of this type of things is minimal and really looking for advice/guidance/tutorial to point me in the right direction.
Thanks in advance.
This just hit my radar, and I assume you have already solved the issue by now. But if not, I would look into Pre-Compiled LINQ Queries. Something like this:
private static Func<SomeDataContext, int, PersonDto> _getPersonByIdQuery =
CompiledQuery.Compile<SomeDataContext, int, PersonDto>(
(dataContext, personId) =>
dataContext.PersonDtos.where(c => c.PersonId == personId).FirstOrDefault()
);
Put something like that inside of your datacontext, then add an internal method in there to call it call it. Your retriever/saver will then call the internal method. Does that make sense? I can post more code if necessary..
Best of luck,
Justin

Resources