JShell: Accessing Objects Created by Snippets - jshell

I am very confused about something and I would appreciate some insight here.
Say I want to build a GUI that visualizes what is going on inside JShell, i.e. how the, by snippets created objects reference each other and what, by Snippets created objects are contained inside my running instance of JShell. How do I access these objects, and most of all, how do I access how they reference each other?
A concrete example: I create a JShell instance, pass it a few snippets created by the user, which cause the creation of, for example, an ArrayList, a few objects, and add said objects to said ArrayList.
How do I access this ArrayList and the objects contained within it to visualize this in a GUI?
To clarify further:
//say I create a Jshell:
JShell jShell = JShell.create();
//Which then evauletes user code passed from the GUI:
jShell.eval(userCode)
//userCode could be following lines each passed as separate Strings:
“ArrayList<TestObject> allObj = new ArrayList<TestObject>();”
“TestObject tst = new TestObject();”
“TestObject tst2 = new TestObject();”
“allObj.add(tst);”
“allObj.add(tst2);”
How do I access “allObj”?
How do I access “tst” and the object it points to? (the “TestObject”instance that “tst” points to);
I know eval() returns a list of SnippetEvents which contain the changed/added snippets, however, I can’t get my head around how to access the objects created by those snippets.

Assuming your classpath has access to the TestObj you could implement Serializable on that object. Upon completion of the eval run another method automatically that serializes the output. Then you can deserialize that object inside your code.

Related

Looping through list of objects created by createEntry() and editing their properties before doing submitChange()

Good afternoon fellow developers,
I have come across a scenario where I found myself needing to retrieve the list of pending changes from my model and editing a specific property of those entries before sending them to my back-end.
These are new entities I created using the createEntry() method of the OData model v2. But, at the time of creation of said entities, I do not possess the value I need to add to them yet. This is the list of entities I retrieve by using the getPendingChanges() method on my model:
What I need to do is to loop through each of these newly created entities and set a specific property into them before actually sending them to my back-end with the submitChanges() method. Bare in mind that these are entry objects created by the createEntry() method and exist only in my front-end until I am able to submit them with success.
Any ideas that might point me in the right direction? I look forward to reading from you!
I was able to solve this issue in the following way:
var oPendingChanges = this.model.getPendingChanges();
var aPathsPendingChanges = $.map(oPendingChanges, function(value, index) { return [index];});
aPathsPendingChanges.forEach(sPath => oModel.setProperty("/" + sPath + "/PropertyX","valueFGO"));
The first two instructions retrieve the entire list of pendingChanges objects and then builds an array of paths to each individual entry. I then use that array of paths to loop through my list of pending changes and edit into the property I want in each iteration of the loop. Special thanks to the folks at answers.sap for the guidance!

How to create an empty Results<T> object?

I'm trying to create a MutableProperty which holds a Results received from Realm.objects(_:).
To create the property I need to give it an initial value; hence an 'empty' Results.
I've tried creating one using:
var someThings = Results<SomeObject>()
MutableProperty(someThings)
But the compiler gives me the error: Cannot invoke initializer for type 'Results<SomeObject>' with no arguments.
While I understand the error, I'm not really sure how to create a Results object in this context.
Looking at the source of Results I couldn't find an init either.
So my question is; how can I create a Results myself to use in a MutableProperty?
Edit:
I've seen this question...but that doesn't really help (unless I'm going to create a "wrapper" for the MutableProperty or something).
With help of the comments on my OP; I created a mutable property with an empty set of results by fetching objects with an 'invalid' filter.
E.g. MutableProperty(realm.objects(SomeObject.self).filer("EMPTY SET")).

Why DAC class is not saved in Acumatica?

Let's say I have following code:
DacClass cl = new DacClass();
//init fields of DacClass()
this.Persist();
but when I run this code in any graph, I'm getting different errors. Why?
You can't create DAC item in db in current graph. As mentioned in T200 manual you should create instance of graph and in created instance to call method persist. Another option is to use method PXDataBase.Insert. The first option is preferable for case if you need insertion with graph logic. The second option is preferable for cases if you need perfomance.

Can't access one model's instance variables from another model) (self.ruby)

I have two models, Draft and Pick. Draft creates an array of available Players in an instance variable named 'available_players'. This is done using the 'before_save' callback. The callback runs the instance method 'start' which in turn runs 'set_active_players'. I've tested all of this in my Draft_spec and I have no problems loading players and having them returned in the available_players array. All my draft specs pass.
The problem is that when I try to access the 'available_players' instance variable from Pick.rb, it returns nil. If I call 'draft.start' (the instance method that should run before Draft.rb saves), I can suddenly access the 'available_players' array... it's like the Draft object is not creating the available_players array even though I have the before_save method in place.
Here is the code that fails inside of Pick.rb:
def available_players_returns_nil
#draft_object.available_players
end
Here is the code that works inside of Pick.rb:
def available_players_working
#draft_object.start
#draft_object.available_players
end
I don't want to have to call start every time I call the method because available_players should not need to reload ALL Players. Please help me access available_players!
Links: failing Pick specs, Pick.rb
EDIT:
I should add that #draft_object is found using
#draft_object = Draft.find(self.draft_id)
For a start, this is wrong:
#draft_object = Draft.find(self.draft_id)
You have an association set up, so use it. You can simply use draft within your Pick object to access the Draft it belongs to. No need to assign it to an instance variable called #draft_object.
Same story with player.
Incidentally, your set_available_players method in Draft is just looping through all of the players and adding them to an instance variable. Why are you doing this? Why don't you simply grab the players directly if you need them in Pick? Like this:
#players = Player.all
Also ... I'm somewhat concerned that pretty much all of your tests are commented out. I hope that's not by design?

Creating new Objects With SPRING.Net

I'm new on spring.net, and I'm tring to create an List<> of objects.
The list is initialized by a loop that calls:
IObj obj= (IObj)ContextRegistry.GetContext().GetObject("obj")
change object properties....
add it to the list...
the problem is : I keep getting the same object every step of the loop
so I get a list of the same object
If your object definitions are not singletons, then you will get a new object each time. Note, by default, singleton is set to true, so you have to explicitly set it to false.
For example, if you are using xml files to configure your objects, set the singleton attribute to false:
<object name="name" type="..." singleton="false"/>
It is not clear what you are trying to achieve by looping over the "GetObject("obj")" method. Maybe you can post the loop-code?
What "GetObject("obj")" does is to ask the Container for the Object with the name "obj". You stated that want to change the object's properties and add it to a list. This is something the container can do for you:
Set the properties of an Object:
http://www.springframework.net/doc-latest/reference/html/objects.html#objects-simple-values
Create a list:
http://www.springframework.net/doc-latest/reference/html/objects.html#objects-collections-values
This list can be injected into an Object you choose.
If you just want non-singleton objects of your IObj, naders answer is correct. Spring calls these non-singleton objects "prototypes". An overview of available Scopes can be found here: http://www.springframework.net/doc-latest/reference/html/objects.html#objects-factory-scopes

Resources