Wednesday, August 23, 2006

Women at the top?

IBM has recently announced that it is lowering the entry criteria for women, so that more women can get employed and help balance the sex ratio within the company.

What IBM wants: Women at the top

I am not sure what the motives are, but I am assuming that IBM is looking at creating cross functional teams with diverse mindsets, a team building approach much preached by the management gurus of all ages. However, I am not sure if lowering the bar is going to help better the culture and team spirit in the company. Unless the merits and motives of a gender balanced workforce are understood by the majority of the employees, it is going to irk the existing workforce. The life of deserving female candidates is going to get tougher, as they will be under constant scrutiny and judgement by their male colleagues. They may have to prove each career advancement far more, and carry the brunt of the disgruntled workforce.

I personally feel that women in engineering (and other professionas where they are outnumbered by the men) face a daunting challenge of constant assessment by everyone around. I just hope things do not get tough for the truly deserving female candidates and they do not have to prove at every step of their employment tenure that they deserve to be in. I hope the organization has educated its employees on the need for a diverse group and they do not develop a negative mindset towards their female counterparts.

Having said that, I really feel that lowering the bar is not the solution. It is more like a quick fix. It discourages merit, and promotes inequality. Encouragement has to happen in terms of a better culture and work-life balance for female employees.

Labels: , ,

Monday, August 14, 2006

FLWOR with Berkeley DB XML

FLWOR (pronounced Flower) stands for "for let while order by return" and is and XQuery expression. FLWOR enables advanced querying. More details about
FLWOR can be found at http://www.w3schools.com/xquery/xquery_flwor.asp

Sleepycat's Berkeley's XML Database, DB XML the native XML database supports XQuery. I have tried to create a small example here to demonstrate how to read XQuery with FLWOR expressions from a file, and run them against the database of Berkeley DBs dbxml container.(the one built in the 'gettingStarted' section) It is assumed that the xml sample data from the getting started kit has been loaded.

Set your classpath to include the Berkley DB jars under jar folder
(db.jar, dbxml.jar, dbexamples.jar)

The code can be found here.

1. query.txt file, which holds the query.



for $doc in collection(\'simpleExampleData.dbxml\')

where $doc/product/item[text()=\"Lemon Grass\"]

return $doc/product



2. FLWOR.java file, which holds the code.



import java.io.*;

import com.sleepycat.dbxml.*;

import com.sleepycat.db.*;

import dbxml.gettingStarted.*;



public class FLWOR {

 private static void usage() {

String usageMessage = \"\\nThis program performs queries against a DBXML container.\\n\";

usageMessage += \"You should run exampleLoadContainer before running this example.\\n\";

usageMessage += \"You are only required to pass this command the path location of the database\\n\";

usageMessage += \"environment that you specified when you loaded the examples data:\\n\";

usageMessage += \" and the query file which holds the query\\n\";

usageMessage += \"\\t-h <dbenv directory> -q <queryFile>\\n\";



usageMessage += \"For example:\\n\";

usageMessage += \"\\tjava ch.inform.bdb.FLWOR -h examplesEnvironment -q query.txt\\n\";



System.out.println(usageMessage);

System.exit( -1 );

 }



 

 //Utility function to clean up objects, exceptions or not,

 // containers and environments must be closed.

 private static void cleanup(myDbEnv env, XmlContainer openedContainer) {

try {

    if (openedContainer != null)

openedContainer.close();

    if (env != null)

env.cleanup();

} catch (Exception e) {

    // ignore exceptions on close

}

 }



 public static void main(String args[])

throws Throwable {

String theContainer = null;

File path2DbEnv = null;

File queryFile = null;

for(int i = 0; i < args.length; ++i) {

         if (args[i].startsWith(\"-\")) {

          switch(args[i].charAt(1)) {

           case \'h\':

           path2DbEnv = new File(args[++i]);

           break;

           case \'q\':

           queryFile = new File(args[++i]);

           break;

           default:

           usage();

           }//switch

         }//if

}//for



if (path2DbEnv == null || ! path2DbEnv.isDirectory()) {

         usage();

}



if (queryFile == null || queryFile.isDirectory()) {

System.out.println(\"queryFile is \" + queryFile);

usage();

}



//Stream to read file

BufferedReader fin;

String query = \"\";

try

{

fin = 

            new BufferedReader(new FileReader(queryFile));

String line;

    while ((line = fin.readLine()) != null ) {

     query += \"\\n\" + line;

    }



    // Close our input stream

    fin.close();

}

// Catches any error conditions

catch (IOException e)

{

System.err.println (\"Unable to read from file\");

System.exit(-1);

}



System.out.println(\"Query is \" + query);



myDbEnv env = null;

XmlTransaction txn = null;

XmlContainer openedContainer = null;

try {

    env = new myDbEnv(path2DbEnv);

    XmlManager theMgr = env.getManager();

    String containerMark = \"\\\'\";

    theContainer = query.substring(

     query.indexOf(containerMark)+1, 

     query.lastIndexOf(containerMark));

    System.out.println(\"Container is \" + theContainer);

    //Open a non-transactional container

    openedContainer =

     theMgr.openContainer(theContainer);

    XmlQueryContext resultsContext = theMgr.createQueryContext();



        XmlResults results = theMgr.query(query.trim(),

      resultsContext);

    XmlValue value = results.next();

    while (value != null) {

    //Pull the value out of the document query result set.

    System.out.println(value.asString());

    }



} catch (Exception e) {

         System.err.println(\"Error performing query against \" + theContainer);

         System.err.println(\"   Message: \" + e.getMessage());

         throw e;

    }

    finally {

   cleanup(env, openedContainer);

    }

 } //End main

}



I am assuming you have already run the examples. So after that, please compile and
say the following at the command line at test folder:
java FLWOR -h -q query.txt

Labels: , ,