Tuesday, 26 August 2008

AmbiguousTableNameException in dbUnit

There is plenty of documentation on AmbiguousTableNameException in dbunit but I was unable to find a clear example showing the problem and the solution.

We have an application that needs to work on Oracle & SQLServer. The integration tests make extensive use of dbunits dataset classes to populate test databases. The tests clear out various tables & populate the tables as required. Previous to me being involved there would be only one database that had to be populated for use and cleaned out to run the tests. I found this a pain so I created a test database for the integration test use only.

SQL Server continued to work fine however when running the Oracle tests I got lots of AmbiguousTableNameExceptions being thrown. It took me a good while to make the connection as to the cause despite it being written in black & white.

Our code was creating the DatabaseConnection as follows:
DataSource ds = (DataSource) applicationContext.getBean(getDataSourceName());
DatabaseConnection mDbConnection = new DatabaseConnection(getConnection(ds));

Logically this should be absolutely fine. First off it all worked before. The Datasource fully describes the connection. In the debugger I could see the username, password and connection url. Accessing the database from the command line using the same parameters all looked cool. Upgrading to dbunit 2.2 proved fruitless.

So why would the connection come up with an AmbiguousTableNameException when that user has no privileges to see any other schema? The long answer to that defeats me.
However as I said the solution is there on the dbunit website.

Despite the fact that the connection has everything defined you still need to tell the DatabaseConnection object the schema name. In the constructor pass in the Schema name and all will be fine.


DatabaseConnection mDatabaseConnection = new DatabaseConnection(connection, getSchemaName());

This all appears to be a bug in dbunit and potentially a security flaw as it implies a connection with limited access can see other schemas.


Thursday, 21 August 2008

jar search tool

How often do you want to search a directory structure to see which jar a particular class is in.

I always end up doing the following:

list=`find . -name "*jar"`
for file in $list
do
echo $file
jar tvf $file grep Somepattern
done


I have done this long hand so many times that I have decided to script it.
Use this script jar_search like this.
jar_search ObjectPool
or
jar_search ObjectPool comm

The second parameter is optional and allows you to restrict what jars you will search through.

Here is the jar_search script:

#
# search a list of jar files for a pattern
# the jar pattern is optional
# By Bill Comer, August 2008
#

if [ $# -lt 1 ]
then
echo "Usage: jar_search [searchPattern] [jarPattern]"
exit -1
fi

searchPattern=$1
jarpattern=$2

list=`find . -name "*$jarpattern*.jar"`

for file in $list
do
found=`jar tvf $file | grep $searchPattern`
if [ ! -z "$found" ]
then
echo $file
echo $found
fi
done

Tuesday, 19 August 2008

Understanding Kaminsky's DNS Bug

See the linux journal for a very good explanation

If you are impatient or do not want to read the explanation
just go to doxpara.com and select the 'Check My DNS' button.

Friday, 15 August 2008

importing oracle dumps using imp or impdp

Using Oracle Enterprise Manager I was trying to import a DMP file into an oracle database & I got the error:
Import Submit Failed
There is a problem reading from the import files: ORA-39143: dump file "c:\temp\case9_0.DMP" may be an original export dump file .

There appears to be two import tools and Enterprise Manager only knows about 'impdp'. There is the old import tool 'imp' that is needed if the dump file was created using 'exp' as opposed to 'expdp' or via Enterprise Manager.

The solution.
Simply run:

imp user/password
where user & password are for the user in the dump file and it will prompt you for all the answers.

Friday, 25 July 2008

OutOfMemory Error from eclipse

I know there are hundreds of blog entries covering this. Here is another.

I followed the general scriptures and set the values in my eclipse.ini file. Currently mine looks like this:

-showsplash
com.genuitec.myeclipse.product
--launcher.XXMaxPermSize 256m
-vmargs
-Xms128m
-Xmx1024m
-Duser.language=en
-XX:PermSize=128M
-Xss2m
-XX:MaxPermSize=256M

However I was still getting OutOfMemory errors when trying to run an ant test coverage task. Why ?

I solved the problem, or should I say I have not seen the problem since I did the following:

In eclipse go to:
Window->Preferences->Java->Installed JREs.

Select the JRE that you are using and select 'Edit'.

Then add the following to the 'Default VM Aguments'
-Xms128m -Xmx1024m -XX:MaxPermSize=256m

Thursday, 26 June 2008

Friendly if/then constructs in ant

Sometimes I wonder if a post is interesting to me because it is new to me but everyone else already knows about it.

Anyway, here goes. I wanted to do an If/else test in my build file and the < condition> construct produced some unbelievably ugly code. After considerable hunting I found ant-contrib.sourceforge.net


This has got a range of new constructs. The manual pages are here
My problem was that I wanted to test if a property had been set and to one of two specific values. This is what I ended up with.

Wednesday, 11 June 2008

In line searching in Eclipse & IE7

I hate the search pop up window you get when you type Ctrl-F in many applications.

I searched for an add-on but eventually found that Eclipse already provide it but under the odd title of 'Incremental Find'

Type Ctrl-J and the words 'Incremental Find' will appear at the bottom of your window.

Simply type away with the text you want to search for.
The cursor will automatically jump to the next occurance of that string.

Ctrl-J will then make the cursor jump too the next.
Shift-Ctrl-J will jump backwards.

And I have just discoverred this. If you type the search word
all in lower case then the search is case insensitive. If you mix case then the search is case specific.

It had been bugging me that IE7 was the same.
Then I found this add-on
After a quick try it appears to do the job.