Cloning of variable in eWam - ewam

To clone an object there is a method of Motor module named ‘CloneVarsExceptFOFrom’. But if we don’t want to copy a variable or a refto of that object in the cloned object, then is there any method to do so? If no, then how is it possible to do so?

Use Prepare clone method normally to clone.
Normally, as per the cloning concept in Wynsure, all the owned relationships of the object are cloned. Whereas, all the (P,A) relationships objects are shared.
If the developer overrides the functionality to skip some object from the cloning process, it may lead to an unexpected behavior if an owned relationship object is skipped from cloning.
In case, there is a need to implement this, it may be a good idea to revisit the data model of the existing implementation for the class in question.

Related

Calling classes from different projects without causing a Circular Reference

I have a solution, with multiple projects. The ones that concern us here are the Website project and the Models project.
The models have a lot of models in Request/Response mode. E.g. If I have a method called GetCustomers, it will be declared like this public GetCustomersResponse GetCustomers(GetCustomersRequest req). This will make sure that if more params are added in the future, I just need to update the model. Hope you get the idea.
All the req/res models are inheriting a baseReq and baseRes respectively. One of the properties included here is called Header, which includes a number of common properties (e.g. SiteId, Currency).
For each Request, I have to call an Initialize method to fill these properties for me (located in the Website project (due to HttpRequest info required). Would it be possible to call this method from the Model project itself (in the constructor), so as to avoid calling the initialize (code repetition) each time? As it is, since the Website referencing the Models, it is not possible to go back due to Circular reference. Is there a way around it, or is it just not possible?
I have tried to look at different articles on the web, but most say that this is just not possible. Others suggested to have a third project, where both projects reference it, but not sure if this works, since I need the HttpContext object.
Any ideas please? Alternatively would I be able to access the HttpContext from within the Models project?

Use of 'Unit of Work' when using a single generic repository?

I am currently looking into the repository patterns and read that repository patterns can be implement in 2 way:-
One repository per entity (non-generic) : This type of implementation
involves the use of one repository class for each entity. For example,
if you have two entities Order and Customer, each entity will have its
own repository.
and
Generic repository : A generic repository is the one that can be used
for all the entities, in other words it can be either used for Order
or Customer or any other entity.
Then I read about the Unit of Work concept and how it can relieve us from database inconsistencies that can be cause by the first way.
My confusion is regarding the second way.
Why would I be needing to use 'Unit of work' when I have created a generic repository?
Since there is no way for any inconsistency to occur.
One way to minimize redundant code is to use a generic repository, and
one way to ensure that all repositories use the same database context
(and thus coordinate all updates) is to use a unit of work class.
But since I am going to have a single generic repository then what is the need?
Usualy You don't have "single" generic repository.
In complex applications, sometimes you have to use many instances in a controller
(for example
var productsRepo = new Repository<Products>();
var userRepo = new Repository<Users>();
This are two different instances of generic repository, and they can cause inconsistent in db (or even Exceptions, if both have different dbContext and you try to modify entities in both repositories).
Thats why You have to manage dbContext properly, and Unit Of Work is one of many ways to accomplish it.

Complex initialization in Custom QML type

I am creating a C++ class that will be registered as a QML type. I want to run some non-trivial logic when the object is initialized. I don't want to put this logic in the constructor because that is bad practice. In a standard C++ class I would usually create a Startup() function with this logic and call it just after initializing the object, but I have no control over this as objects are initialized in QML.
How should I implement this custom initialization logic for a custom QML type?
For those who want the details. I am making a QAbstractListModel that keeps track of all .txt files in a directory. When it is created it will scan the directory (passed in via property) and update its internal collection with the names of all .txt files in that directory.
Edit1: After looking at Qt's example projects I found that many of them actually do all initialization logic in the constructor, including things like setting up DB connections and doing an initial DB query and query parsing. One need only search for "database" from the Qt Creator Welcom->Examples screen to see these samples. I would appreciate it if someone found and explained a better way.

Do asp.net application variables pass by reference or value?

I've discovered recently that when using the Session or Application objects within an ASP.net application, that it passes the values by reference.
This works great most of the time, but now I'm in a place where I truly need a copy of the data, and not a reference to it, since I will discard any changes to it when done processing.
I'm also aware of setting variables in the root of the application, effectively creating global application variables that have a bit better performance and eliminate all the casting craziness of the Session/Application objects.
Does anybody know if the application variables pass by reference or value? I can't seem to dig up any data on the topic and would like to eliminate the code I currently have to "copy" the data from the Application object into a new variable for processing.
This is not an ASP.NET phenomenon per se... it is inherent to the CLI in all of .NET framework. You should take a look at Jon Skeet's classic article on Parameter passing.
Assuming you are dealing with reference types, if you want to clone an object rather than simply copying a reference to the object, you will need to manually clone it. Here's a good article that explains how to deep copy an object and why the MemberwiseClone method creates only a shallow copy of the object.
Actually, what happens by default (assuming you have a reference type rather than a value type) is that it passes a copy of the reference.
So you have a different variable but it's pointing at the same object.
An "Application" variable is just a regular member variable. It works just like any other variable, it's only it's scope that is larger than most.
If the value of the variable is copied or not depends on whether the variable is a value type or not.
If it's a value type, for example int, the value is always copied.
If it's a reference type, for example a List<int> you get a copy of the reference to the object. The object itself is not copied.
So, if what you need to copy is a reference type, you have to explicitly create the copy.

Is there a tool to capture an objects state to disk?

What I would like to do is capture an object that's in memory to disk for testing purposes. Since it takes many steps to get to this state, I would like to capture it once and skip the steps.
I realize that I could mock these objects up manually but I'd rather "record" and "replay" real objects because I think this would be faster.
Edit: The question is regarding this entire process, not just the serialization of the object (also file operations) and my hope that a tool exists to do this process on standard objects.
I am interested in Actionscript specifically for this is application but...
Are there examples of this in other
programming languages?
What is this process commonly called?
How would this be done in
Actionscript?
Edit:
Are there tools that make serialization and file operations automatic (i.e. no special interfaces)?
Would anybody else find the proposed tool useful (if it doesn't exist)?
Use case of what I am thinking of:
ObjectSaver.save(objZombie,"zombie"); //save the object
var zombieClone:Zombie = ObjectSaver.get("zombie"); // get the object
and the disk location being configurable somewhere.
Converting objects to bytes (so that they can be saved to disk or transmitted over network etc.) is called serialization.
But in your case, I don't think that serialization is that useful for testing purposes. When the test creates all its test data every time that the test is run, then you can always trust that the test data is what you expect it to be, and that there are no side-effect leaking from previous test runs.
I asked the same question for Flex a few days ago. ActionScript specifically doesn't have much support for serialization, though the JSON libraries mentioned in one of the responses looked promising.
Serialize Flex Objects to Save Restore Application State
I think you are talking about "object serialization".
It's called Serialization
Perl uses the Storable module to do this, I'm not sure about Actionscript.
This used to be called "checkpointing" (although that usually means saving the state of the entire system). Have you considered serializing your object to some intermediate format, and then creating a constructor that can accept an object in that format and re-create the object based on that? That might be a more straightforward way to go.
What is this process commonly called?
Serializing / deserializing
Marshalling / unmarshalling
Deflating / inflating
Check out the flash.utils.IExternalizable interface. It can be used to serialize ActionScript objects into a ByteArray. The resulting data could easily be written to disk or used to clone objects.
Note that this is not "automatic". You have to manually implement the interface and write the readExternal() and writeExternal() functions for each class you want to serialize. You'll be hard pressed to find a way to serialize custom classes "automatically" because private members are only accessible within the class itself. You'll need to make everything that you need serialized public if you want to create an external serialization method.
The closest I've come to this is using the appcorelib ClassUtil to create XML objects from existing objects (saving the xml manually) and create objects from this xml. For objects with arrays of custom types it takes configuring ArrayElementType Metadata tags and compiler options correctly as described in the docs.
ClassUtil.createXMLfromObject(obj);
CreateClassFromXMLObject(obj,targetClass);
If you're using AIR, you can store Objects in the included local database.
Here's a simple example using local SQLite database on the Adobe site, and more info on how data is stored in the database.

Resources