The Artima Developer Community
Sponsored Link

Java Buzz Forum
Dreaming of AOP transactions

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Carlos Villela

Posts: 116
Nickname: cvillela
Registered: Jun, 2003

Carlos Villela is a Java developer working mostly with web technologies and AOP.
Dreaming of AOP transactions Posted: Jul 3, 2003 2:33 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Carlos Villela.
Original Post: Dreaming of AOP transactions
Feed Title: That's sooo '82!
Feed URL: http://www.jroller.com/rss/cv?catname=Technical
Feed Description: Carlos Villela's weblog. Everyday life, everyday software development, everyday musings.
Latest Java Buzz Posts
Latest Java Buzz Posts by Carlos Villela
Latest Posts From That's sooo '82!

Advertisement
Another dream with transactions and AOP today. And boy, this one was gooooood. I wrote about it, but Roller ate my post. Well, shit happens. Here's what I could recover from it.

What we have today to make this possible:
  • Most RDBMSs today support nested transactions
  • AspectWerkz supports transparent persistence for objects, advices and introductions using Prevayler and JISP
  • Hibernate handles almost-transparent persistence for objects on RDBMSs
  • AspectWerkz supports definition of aspects and introductions using meta-data attributes (xdoclet-like tags)
  • There are lots of other cool features on AspectWerkz I haven't been able to play with in this area (PersistenceManagers, etc)
  • Lots of people interested in AOP willing to get their hands dirty on some hardcore AOP aspects
Ok. Throw it all on a blender. Here's what you have:

/**
 * @persistent
 */
public class Customer {
  private String name;
  private String id;
  private Address address;

  /** @transaction useExistent
  public void setName(String name) { this.name = name; }
 
  //...
}

/**
 * @persistent
 */
public class CustomerManager {
  private List customers = new ArrayList();

  /**
   * @transaction createNew rollbackOnException
   */
  public Customer addCustomer(String name, String id, Address address) {
    Customer c = new Customer();
    c.setName(name);
    c.setId(id);
    c.setAddress(address);
    customers.add(c);
    return c;
  }
}

Then, this is what should happen at startup:

The PersistenceManager connects to the database and checks for the existence of the tables Customer, Address and CustomerManager. As they don't exist yet, it creates them:

CREATE TABLE "Customer" (
  "uuid" VARCHAR(32) NOT NULL PRIMARY KEY,
  "name" TEXT,
  "id" TEXT,
  "address_uuid" VARCHAR(32)
);

CREATE TABLE "Address" (
  ...
);

CREATE TABLE "CustomerManager" (
  "uuid" VARCHAR(32) NOT NULL PRIMARY KEY,
  "customers_uuid" VARCHAR(32) NOT NULL
);

The application starts up normally. Then, somewhere, somehow, CustomerManager is instantiated. The AOP framework know about it, and has an advice to help filling that customers ArrayList with data from the database. As there's no data in there yet, execution proceeds. The addCustomer method is called. The AOP framework knows about it too, and it sees the @transaction tag, and starts doing its job. It asks the persistence manager to create a new transaction, and execution starts.

Suddenly, hey! We're creating a new instance of a customer! The persistence manager creates a new nested transaction, and INSERTs it, with a newly created UUID, into the Customer table. Everything goes well, so it commits the nested transaction, and execution proceeds.

Ah, now we're setting some properties. Cool. The setName, setId and setAddress methods are marked with @transaction useExistent, so no new transactions are created. Fields name, id and address are set, and the persistence manager UPDATEs the table accordingly.

Then, the new, fresh, beautiful Customer object is being added to a List. The AOP framework sees that, too, and asks the persistence manager to do something about it. "Piece of cake!", the persistence manager says, and INSERTs a new row into the CustomerManager table.

Oh, the method is returning. So soon, already? "Ok", says the persistence manager, "let's commit this transaction."

Want to re-read the same story using another syntax? Okay, here you go:

SELECT COUNT(*) FROM "CustomerManager";

BEGIN CustomerManager_addCustomer

BEGIN Customer_ctor
INSERT INTO "Customer" VALUES ('168c129ac3be239d91a0a834432c27a9',NULL,NULL,NULL);
COMMIT Customer_ctor

UPDATE "Customer" SET "name"='Carlos Villela' WHERE "uuid"='168c129ac3be239d91a0a834432c27a9';

UPDATE "Customer" SET "id"='cv' WHERE "uuid"='168c129ac3be239d91a0a834432c27a9';

UPDATE "Customer" SET "address"='9572c81ec1b149121926bacd39678ffe' WHERE "uuid"='168c129ac3be239d91a0a834432c27a9';

BEGIN CustomerManager_customers_add
INSERT INTO "CustomerManager" VALUES ('f39cab12831bc1d39f33012dee19237a','168c129ac3be239d91a0a834432c27a9');
COMMIT CustomerManager_customers_add

COMMIT CustomerManager_addCustomer

Is this already possible, is it already viable, is it something we can build today, or is there a missing piece in this puzzle? Is it just a dream, or we just need someone to put it all together in a weekend sprint and be forever called a genius?

Read: Dreaming of AOP transactions

Topic: Re: Separate HTML "designers" from "real" programmers? Previous Topic   Next Topic Topic: J2ME Articles For Beginners

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use