I honestly have no idea where to begin. The repository aspect is relatively simple but I cannot seem to find any information on how to delete an aggregate root via the CommandGateway.
Any directions and/or documentation on how to achieve this would be greatly appreciated.
Putting this here for future reference for anyone else that might be as lost as I was initially.
When using the Event Sourcing Aggregate, one can make use of the markDeleted() static method on the Aggregate in question. I placed mine in the #EventSourcingHandler
import static org.axonframework.modelling.command.AggregateLifecycle.markDeleted;
#EventSourcingHandler
public void on(DeletedEvent event){
markDeleted();
}
Further information can be found at: https://docs.axoniq.io/reference-guide/implementing-domain-logic/command-handling/aggregate#aggregate-lifecycle-operations
To delete the view data associated with the aggregate I used an external #EventHandler:
#EventHandler
public void on(DeletedEvent event, ReplayStatus status){
entityRepo.deleteById(event.getId());
}
Thanks to Allard for engaging me in the comments section.
Related
Just a short question here...
by using Axon, we know that AggregateLifecycle#apply(Object) will be doing the event-sourced for us which under the hood going to persist our event into our event-store.
With regards to that matter, how to get the event-identifier (not the aggregate identifier) once we call that particular apply method ?
Thanks
Based on your another answer, let me suggest you a way to follow.
The MessageIdentifier as used by AxonFramework (AF) is nothing more than an UUID generated for each Message you create.
Since you only need to reuse that info, you can pretty much get it from the Message while handling it. To make things easier for you, Axon provides a MessageIdentifierParameterResolver meaning you can simply use it in any #MessageHandler of you (of course, I am assuming you are using Spring as well).
Example:
#EventHandler
public void handle(Event eventToBeForwarded, #MessageIdentifier String messageIdentifier) {
// forward the event to another broker using the given `messageIdentifier`
}
Hope that helps you and make things clear!
In unity multiplayer the player prefab spawns after the scene loads, what is the best way to declare scripts that are needed and avoid the NullReferenceException error?
I'm not that familiar with multiplayer myself, but I believe this could be done through GameObject.Find("") and GetComponent.
I also stumbled across FindObjectOfType. I'm not sure if that's what you're looking for, but it doesn't hurt to post it. Good luck.
Instead of letting a script look for when the prefabs have spawned why not letting the prefabs tell the script it has spawned?
It's really hard to give any kind of example when the use-case is not specified.
Really basic example (and since you're going to use it for networking you might have to redo this a lot so you don't trust the client too much):
class ScriptA : Monobehaviour () {
List<GameObject> prefabs;
public void AddPrefab (GameObject Prefab) {
prefabs.Add (Prefab)
}
}
class Prefab : Monobehaviour () {
void Start () {
FindObjectOfType(ScriptA).AddPrefab(gameObject);
}
}
It's not the best example but the point is, you might need to rethink the architecture
I know, that to create a new path in Qt from a given absolute path, you use QDir::makepath() as dir.makepath(path), as it is suggested in this question. I do not have any trouble in using it and it works fine. My question is directed, as to why the developers would not provide a static function to call in a way like QDir::makepath("/Users/me/somepath/");. Needing to create a new QDir instance seems unnecessary to me.
I can only think of two possible reasons:
1. The developers were "lazy" or did not have time so they did not add one as it is not absolutely necessary.
2. The instance of QDir on which mkpath(path) is called, will be set to path as well, so it would be convenient for further usage - but I can not seem to find any hints that this is the actual behaviour within the docs.
I know I repeat myself, but again, I do not need help as of how to do it, but I am much interested as of why one has to do it that way.
Thanks for any reason I might have missed.
Let's have a look at the code of said method:
bool QDir::mkdir(const QString &dirName) const
{
const QDirPrivate* d = d_ptr.constData();
if (dirName.isEmpty()) {
qWarning("QDir::mkdir: Empty or null file name");
return false;
}
QString fn = filePath(dirName);
if (d->fileEngine.isNull())
return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);
return d->fileEngine->mkdir(fn, false);
}
Source: http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/io/qdir.cpp#n1381
As we can see, a static version would be simple to implement:
bool QDir::mkdir(const QString &dirName) const
{
if (dirName.isEmpty()) {
qWarning("QDir::mkdir: Empty or null file name");
return false;
}
return QFileSystemEngine::createDirectory(QFileSystemEntry(dirName), false);
}
(see also http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/io/qdir.cpp#n681)
First, the non-static method comes with a few advantages. Obviously there is something to using the object's existing file engine. But also, I would imagine the use-case of creating several directories under a specific directory (that the QDir already points to).
So why not provide both?
Verdict (tl/dr): I think the reason is simple code hygiene. When you use the API, the difference between QDir::makepath(path); and QDir().makepath(path); is slim. The performance hit of creating the object is also negligible, as you would reuse the same object if you happen to perform the operation more often. But on the side of the code maintainers, it is arguably much more convenient (less work and less error prone) to not maintain two versions of the same method.
I need to create a job with a for loop (I think) that goes through all available companies and checks for a specific value. I'm just not familiar with how I would get it to select each individual company.
Does anyone know the syntax for that?
I use the following technique in a job:
static void CountIt(Args _args)
{
DataArea DataArea;
void doIt()
{;
info(int2str((select Count(RecId) from CustTable).RecId));
}
setPrefix("Counting");
while select DataArea where !DataArea.isVirtual
{
print(DataArea.Id);
setPrefix(DataArea.Id);
changecompany (DataArea.Id)
{
doIt();
}
}
}
Please bear in mind to reset your table variables in the changecompany scope, otherwise you will get strange or no result at all.
A colleague was to do a task as yours and he got absolutely no results for the code inside the changecompany scope. I googled and found this blogpost: http://dynamics-ax-live.blogspot.se/2011/10/what-not-to-forget-when-using.html
The functionality you're looking for is called "Cross Company" data access. MSDN has a great bit of code samples here:
X++ code:
http://msdn.microsoft.com/en-us/library/cc518738.aspx
Main article:
http://msdn.microsoft.com/en-us/library/cc634544.aspx
I am developing an application in GWT as my Bachelor's Thesis and I am fairly new to this. I have researched asynchronous callbacks on the internet. What I want to do is this: I want to handle the login of a user and display different data if they are an admin or a plain user.
My call looks like this:
serverCall.isAdmin(new AsyncCallback<Boolean>() {
public void onFailure(Throwable caught) {
//display error
}
public void onSuccess(Boolean admin) {
if (!admin){
//do something
}
else{
//do something else
}
}
});
Now, the code examples I have seen handle the data in the //do something// part directly. We discussed this with the person who is supervising me and I had the idea that I could fire an event upon success and when this event is fired load the page accordingly. Is this a good idea? Or should I stick with loading everything in the inner function? What confuses me about async callbacks is the fact that I can only use final variables inside the onSuccess function so I would rather not handle things in there - insight would be appreciated.
Thanks!
Since the inner-class/ anonymous function it is generated at runtime it needs a static memory reference to the variables it accesses. Putting final to a variable makes its memory address static, putting it to a safe memory region. The same happens if you reference a class field.
Its just standard java why you can only use Final variables inside an inner-class. Here is a great discussion discussing this topic.
When I use the AsyncCallback I do exactly what you suggested, I fire an event though GWT's EventBus. This allows several different parts of my application to respond when a user does log in.