Month: September 2003

Teensy bugettes

I discovered that the doReplace function in my utilities library had a small bug, where if the to string contained the from string it would loop forever. I also put in a guard variable to stop it doing more than a certain number of replacements, not sure about this when you’re not debugging. Definitely thinking moving to 1.4 and using the replace functions provided might have helped, but on the other hand this works with most current VMs. The changed version of the function is below, the whole utilities package (which has been debugged some more) is here:

  /**
   * Does replace in source string of all occurrences of <i>from</i> with <i>to</i>,
   * Used by the {@link #replaceStrings replaceStrings} function to do the work
   * @param source string to do substitution on
   * @param from string to replace
   * @param to string to insert
   * @param replaceAll replace all occurrences
   * @return source string with all or one occurences of from replaced with to
   */
  public static String doReplace
    ( final String source
    , final String from
    , final String to
    , final boolean replaceAll
    )
  {
    String retString = source ;
    int start = -1 ;
    final int MAX_REPLACES = 50 ;
    int iteration = 0 ;
    int offset = 0;
    while ( ( start = retString.indexOf(from, start + offset) )  != -1 )
    {
      retString = retString.substring(0,start) + to + retString.substring(start+from.length()) ;
      System.out.println(retString);
      iteration ++ ;
      offset = to.length() ;
      if ( (! replaceAll ) || iteration > MAX_REPLACES) break ;
    }
    return retString ;
  }

Progress

Using the utilities package given below I’ve now managed to generate all of the implementation beans for my data model. I created a template that creates the guts of the code and then iterates through the columns using a different template to put in the getter/setter methods. The next job is to set up the many:many relationships and my own tagging system (that allows you to tag rows with extra data). Once this is done the rest should be easy, just change the template and the output target and leave the rest of the code alone.

Bean Managed vs Container Managed Persistence

I’m beginning to think I made a mistake here, going for BMP, because I can’t see how you can have a transaction across more than one bean method call with BMP. The only way I can conceive it is that you get some kind of transaction ID, which reserves you a database connection, and then pass that through to the beans. Then you’ll have to set up a getConnection() method that you pass the transaction ID to so you have the same one throughout. This would allow you to rollback the whole transaction if you had to. How then do you manage fail over between machines? I need to do some more reading I think. My system is low volume so it should be OK. I think I’ll need to implement some kind of optimistic locking strategy (cue Bee Gees Stradegy, when things go wrong and you can’t go on, Stradegy – sorry, that always happens to me whenever someone says that word, I think it’s all the years working for big corp IT, raddles the brain).

BT Voyager modem

Yes it’s still for sale. Someone left a message here but no email address. Contact me direct on francis (d0t) fish (aT) macmail (d0t)com if you want to buy it.

Regards all.

Writing code properly – good programmers are lazy

Currently generating out my ejb-jar.xml file and I’ve got code that looks like this:

    currentTable = initCap (att.getValue(“name”));
    os.println(“tt<entity>”);
    os.println(“ttt<descriptio>Entity Bean ( BMP )</descriptio>”);
    os.println(“ttt<display-name>” + currentTable + “</display-name>”);
    os.println(“ttt<ejb-name>” + currentTable + “</ejb-name>”);
    os.println(“ttt<home>com.pharmarketeer.ejb.entity.” + currentTable + “Home</home>”);
    os.println(“ttt<remote>com.pharmarketeer.ejb.entity.” + currentTable + “</remote>”);
    os.println(“ttt<local-home>com.pharmarketeer.ejb.entity.” + currentTable + “LocalHome</local-home>”);
    os.println(“ttt<local>com.pharmarketeer.ejb.entity.” + currentTable + “Local</local>”);
    os.println(“ttt<ejb-class>com.pharmarketeer.ejb.entity.impl.” + currentTable + “Bea</ejb-class>”);
    os.println(“ttt<persistence-type>Bea</persistence-type>”);
    os.println(“ttt<prim-key-class>” + currentTable + “PK</prim-key-class>”);
    os.println(“ttt<reentrant>False</reentrant>”);
    os.println(“tt</entity>”);

Ugly, isn’t it? It’s the naive way of doing it. I’m going to write a little utility that allows me to specify a template and then put tags in it (a la Bentley’s little languages bit in Programming Pearls). What I’d really like is a Java Stream search and replace like PHP has, where I could use regular expressions and useful stuff like that, as far as I can make out the Java RegExp stuff just gives you some kind of true/false reading. Will post it here when I’m done, use or abuse but no warranty!

Hogs and Quiches compadres.

The Bardo, Pain and Renunciation

The Bardo

Well, the Bardo is just a place or state where things change. A lot of westerners mistakenly think that it only relates to death, because of the Tibetan Book of the Dead (Bardo Thodol). In fact we are always in a state of change throughout or lives and death is just another one. I’ve been thinking about this a lot because my irritable bowel thing flared up again in the night and I don’t feel like I’ve had much sleep. Pain is interesting, we feel it as a warning, but it can also be transformative. The IBS flared up because I am upset, no job, no interviews on the horizon. I also realised that at least partly it came because I was feeling for the people where I used to work because they are really up against it and I am helpless to help them.

Pain

I have discovered that I can meditate away pain at least some of the time. First you acknowledges that the pain reminds you of how others suffer, then you try to draw their pain into your own as well to reduce their suffering, then take the medicine – no point in being a fool about it! I wrote a poem about this (see The Macro and the Micro), where I tried to show that we can only feel compassion by relating what happens to others to what happens in our own little world. If you don’t have insight into how your own struggles make you the same as everybody else you can’t rise above it and help others the way they need to be helped.

Renunciation

I’ve just been reading The Marvellous Companion, which is a series of stories about the Buddha’s lives before he became the Buddha. You can treat them as metaphor or the literal truth, it doesn’t matter. One of the themes is giving to others, as in everything, including your own body if that’s all you have to give. Finding others’ suffering so unbearable that you will do anything to ameliorate it, giving everything you have even if you starve. I aspire to this, but am bound by the ties that bind and cannot abandon my family, nor do I want to. I know too well what it’s like to grow up without a father and I will not do that to anyone else. The interesting thing I have discovered is that now I have acknowledged the ties and seen them for what they are, temporary but enduring, I love them all even more than I ever have, and their presence in my life is even more precious and I couldn’t resent them at all (well when I’m being perfect anyway).

Buddha said that the end of all meeting is parting, which is another way of expressing the ineluctable truth of impermanence of all things, but this makes the time during the meeting even more important and beautiful because of its transience. The important thing is to not be caught up in the past when things are gone and only look to the moment. This is the hardest thing of all, renouncing your clinging to the stupid past and its tiny comforts.

(The full quote is the end of all gathering is dispersion; the end of all building is ruin; the end of all meeting is parting; the end of all birth is death.)

Blessings to you all.

JBOSS driving me nuts

  1. Download JBOSS, get latest version, why not? (not knowing that DR on the end means Developer Release, so stay away if you aren’t testing it or coding to new features).
  2. Download quick start, only for version 3, download v 3.2, Find webpage that gives all of the missing bits from the supplied quick start PDF at http://jmvanel.free.fr/jboss3-howto.html (thanks Jean-Marc).
  3. Template example will not deploy, gives a bs error about names in the ejb-xml file.
  4. Google leads me to the JBOSS forum page where I find out that the examples are for 3.0, but that you can get them going if you edit the generated files (erm, and lose the changes every time you rebuild). 3.2 is apparently more EJB compliant so it’s more pedantic about stuff generated by xdoclet. I could probably fix this if I knew enough about Xdoclet (or whatever Ant is feeding it) but don’t have the time.
  5. In the mean time I discover that the CMP2 project (which doesn’t use xdoclet to generate the ejb home and remote interfaces or the deploy file, it’s been hand coded) does work.
  6. Fine says I, let’s use this project. Let’s see if the 4.0 DR will work so that I won’t have to migrate to 4 when it becomes production.
  7. It won’t deploy.
  8. OK OK, I give up, I will stick to the 3.2 release, not use xdoclet (I’m writing my own XML generation stuff from a description of my schema, so I can do the interfaces myself anyway).

All I can say is that the supplied stuff does use JUnit and I think JUnit looks OK (but don’t get me started on testing for testing’s sake or you’ll have to kill me). 2 days down the toilet. Lesson : if stuck go to google straight away, do not pass go, just do it. Now adding to my generation code, got the schema, got the drop schema, now to do the bit that generates the ejb-jar.xml.

Next question : do I want to used Container or Bean managed persistence? Container might insulate me even more from the datbase, but bean will give me far more control.