Tuesday, August 25, 2009

SQL Server Empty All Tables

The other day I had to empty a database from all its data.
I found this link which did my job. It has a little stored procedure that I created in my database and just executed it.
I slightly modified the stored procedure to exclude some reference tables.

What I recommend after emptying the database is to compact it.
In SQL Server Management Studio one can select the database, right click choose
Tasks -> Shrink -> Database

That's all!

Friday, August 21, 2009

JAX-WS "Two classes have the same XML type name"

When generating the Java classes using wsgen from a WSDL I was getting the following error:

Two classes have the same XML type name "{http://myservice/}foo". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:

As suggested by the exception I tried changing @XmlType but that was fine for me.
This link offers the same solution and it also suggests to change Response classes which I think its an extreme solution.

Anyway in my case the problem was that I generated the classes and I wanted to change the package name.
Everything worked fine, compiled and the webservice deployed successfully.
When viewing the WSDL I got the above error.
In my case the solution was just to update the new namespace in the Webmethod attribute.

@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "foo", targetNamespace = "http://fooservice/", className = "com.foo.service.generated.foo")
@ResponseWrapper(localName = "fooResponse", targetNamespace = "http://fooservice/", className = "com.foo.service.generated.FooResponse")

The attribute className had to be updated :(

Tuesday, August 4, 2009

Java FileWriter UTF-8 encoding

Not possible to specify encoding for a FileWriter object.
The documentation states that FileWriter is a convenient class depending on the underlying platform.
The easiest solution is to use an OutputStreamWriter. Something as follows, in my case I am exporting to CSVWriter:

FileOutputStream fos = new FileOutputStream(new File(fileName));
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
CSVWriter writer = new CSVWriter(osw, CSV_DELIMITER);