Creating Objects

You can use the new operator to create a persistent or transient instance of an exposed class. The constructor to use is determined by whether the exposed JADE class has a create method with parameters.

For an exposed class where the create method has no parameters, the new operator is used together with the no‑parameters constructor for the class or the constructor with a ClassPersistence enumeration value of Persistent or Transient; for example:

Agent agent = new Agent(); 
Agent agent = new Agent(ClassPersistence.Persistent);

Alternatively, you can use the CreateInstance method of the JoobContext class.

JoobContext context = JoobContext.CurrentContext;
Agent agent = context.CreateInstance<Agent>(ClassPersistence.Persistent);

For an exposed class where the create method has parameters, the new operation is used together with the constructor with the matching parameters as the create method or the constructor with matching parameters and a ClassPersistence enumeration value of Persistent or Transient; for example:

Customer customer = new Customer("Wilbur", "wilbur@jadeworld.com"); 
Customer customer = new Customer(ClassPersistence.Persistent, "Wilbur", 
                    "wilbur@jadeworld.com");

Attempting to use the no‑parameters constructor on a class requiring parameters raises exception 4027 (Method called with incorrect number of parameters).

Alternatively, you can create an instance of an exposed class by using the JoobContext extension methods generated in JoobContextExtensions.cs. Each exposed class that has a create method with parameters generates a JoobContext extension method with the signature CreateXXInstance, with the XX value being the name of the exposed class; for example:

JoobContext context = JoobContext.CurrentContext; 
Customer customer = context.CreateCustomerInstance(ClassPersistence.Persistent, 
                    "Wilbur", "wilbur@jadeworld.com");

Transient objects belong to the process that created them and are not accessible by any other process. The transient objects for a process are retained until explicitly deleted or when the process is disposed of (typically when the .NET application terminates).

Because the transient objects for each process are retained, they are available the next time a JoobContext instance is created and associated with that process. However, the associated process may be any of the processes in the pool.

To create, modify, or delete a persistent object, you must be in transaction state. For details, see "Transactions", later in this chapter.