Least Impact Design


General J2EE: Least Impact Design

  1. Least Impact Design (1 messages)

    Hi Java Guru's,

    I am looking for least possible redesign of my java code.

    The database has gone for a major change. Prior to this, my java program uses single primary key to identify the entity and on the basis of this key, I create the sets of java object (Which actually represent the tables in database). So logically each table is identifiable from the other by respective primary key (which is in fact one and only one).

    The same key server as a foreign key for the other table, which has its own primary key. And so on. Each table is represented as java object.

    But now the database tables have been given a different look. Each table is representation of a huge 5-6 fields serving as primary key (instead of old model of having just one primary key).

    This model is not very different from the old one except each table has a combination of fields serving as primary key and referential integrity is served the same way as earlier.


    My problem is huge code has been written out by considering one unique key. I need to know, how can I generate unique key from combinations of keys and use them with least possible java code modification. Can it be possible ..

    You feedback will be a great help
  2. Least Impact Design[ Go to top ]

    Ugh. I hate to tell you this, but you are probably in for a huge amount of pain. Here are a few suggestions that might help things easier.

    First, you should will probably want to treat your joint keys as objects. You can probably simplify you code by coming up with a generic key interface implemented by all your keys, so you can deal with them polymorphically.

    public interface PrimaryKey {}

    public class ExampleKey implements PrimaryKey {
      public String field1;
      public double field2;

    For key generation, you probably want to set up some key generator factory, based on the type of object you are working with:

    public class PKFactory {
      public static PKFactory getInstance(Class entityClass) {
        return Class.forName(entityClass.getName() + "PKFactory").newInstance();

      public abstract PrimaryKey newKey(Object entity) {

    public class ExampleBeanPKFactory extends PKFactory {
      public PrimaryKey newKey(Object entity) {
        ExampleBean bean = (ExampleBean) entity;
        // Generate a key for the ExampleBean

    // In the Entity:
    PrimaryKey pk = PKFactory.getInstance(ExampleBean.class).newKey(this);

    My expectation is that you will need a different algorithm to generate keys for each Entity/Table. The above skeleton should give you enough flexibility to do that.

    All in all, though, this will probably be a lot of work.