Create a simple application

Now that we have an Eclipse project with the right dependencies, we'll create a simple transactional application.

  1. In the File menu, select New -> Package. Name the new package quickstart, and then click the Finish button.

    Create quickstart package

    Figure 2.3. Create quickstart package


  2. In the Package Explorer, right-click on the new quickstart package and select New -> Class. Set the class name to QuickStartObject. This will be our ActiveSpaces® Transactions managed type. Click the Finish button.

    Create QuickStartObject class

    Figure 2.4. Create QuickStartObject class


  3. Now edit QuickStartObject.java in the edit pane. We will add an @Managed annotation to the class, and define a package-private String field named message. The class should look like the following:

    package quickstart;
    
    import com.kabira.platform.annotation.Managed;
    
    @Managed
    public class QuickStartObject 
    {
        String message;
    }

    As a Managed type, any instance of this object we create will be stored in ActiveSpaces® Transactions shared memory.

  4. Now we'll create another public class with a main() method. As before, right-click on the quickstart package and select New -> Class. Set the class name to Main, and let Eclipse generate the method stub for us:

    Create the Main class

    Figure 2.5. Create the Main class


  5. Replace the empty main() method body with some transactional code. We'll create and update an instance of the Managed QuickStartObject class we defined:

    package quickstart;
    
    import com.kabira.platform.Transaction;
    
    public class Main 
    {
        public static void main(String[] args) 
        {
            new Transaction() 
            {
                @Override
                public void run() throws Rollback
                {
                    String message = "Welcome to ActiveSpaces® Transactions
    !";
                    System.out.println(message);
                    
                    QuickStartObject quickStartObject = new QuickStartObject();
                    quickStartObject.message = message;
                }
            }.execute();
        }
    }
  6. Take a moment to check for any source errors identified by Eclipse. Under the File menu, select Save all.