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!
Tuesday, August 25, 2009
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 :(
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);
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);
Tuesday, July 21, 2009
HttpClient uploading large files
When using HTTPClient to upload large files I was getting the following exception:
org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: socket write error
org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
java.lang.Exception: Unbuffered entity enclosing request can not be repeated.
I had the following code:
PutMethod method = new PutMethod(url + "/" + file.getName());
RequestEntity requestEntity = new InputStreamRequestEntity(new FileInputStream(file));
method.setRequestEntity(requestEntity);
client.executeMethod(method);
I replaced the code as follows:
String filename = url + "/" + file.getName();
PutMethod method = new PutMethod(filename);
method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
Part[] parts = { new FilePart(file.getName(), file) };
method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
client.executeMethod(method);
In my case I am uploading (PUTMETHOD) to a WebDAV folder. But I noticed that this issue is happening for other protocols too.
Basically using MultiPart and setting the parameter USE_EXPECT_CONTINUE to true solved the problem.
The problem is due to the authentication. When the post has a big file it opens the transfer multiple times. And I guess the socket will be closed or not authenticated when there is the second transfer.
org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: socket write error
org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
java.lang.Exception: Unbuffered entity enclosing request can not be repeated.
I had the following code:
PutMethod method = new PutMethod(url + "/" + file.getName());
RequestEntity requestEntity = new InputStreamRequestEntity(new FileInputStream(file));
method.setRequestEntity(requestEntity);
client.executeMethod(method);
I replaced the code as follows:
String filename = url + "/" + file.getName();
PutMethod method = new PutMethod(filename);
method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
Part[] parts = { new FilePart(file.getName(), file) };
method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
client.executeMethod(method);
In my case I am uploading (PUTMETHOD) to a WebDAV folder. But I noticed that this issue is happening for other protocols too.
Basically using MultiPart and setting the parameter USE_EXPECT_CONTINUE to true solved the problem.
The problem is due to the authentication. When the post has a big file it opens the transfer multiple times. And I guess the socket will be closed or not authenticated when there is the second transfer.
Monday, July 20, 2009
Find empty tables in SQL Server 2005
To find all the empty tables in your SQL Server 2005 you can use the following query:
SELECT o.name, sum(s.row_count)
FROM sys.objects o
JOIN sys.dm_db_partition_stats s
ON o.object_id=s.object_id
WHERE o.type='U'
GROUP BY o.name
HAVING sum(s.row_count) = 0
ORDER BY sum(s.row_count) desc
where 'U' stands for User Table
Just in case one wants to find out if a table is used in stored procedures, triggers and so on... one can use the following SQL:
SELECT o.name,o.xtype,m.definition
FROM sys.sql_modules m
INNER JOIN sysobjects o ON m.object_id=o.id
WHERE [definition] LIKE '%TABLE_NAME%'
SELECT o.name, sum(s.row_count)
FROM sys.objects o
JOIN sys.dm_db_partition_stats s
ON o.object_id=s.object_id
WHERE o.type='U'
GROUP BY o.name
HAVING sum(s.row_count) = 0
ORDER BY sum(s.row_count) desc
where 'U' stands for User Table
Just in case one wants to find out if a table is used in stored procedures, triggers and so on... one can use the following SQL:
SELECT o.name,o.xtype,m.definition
FROM sys.sql_modules m
INNER JOIN sysobjects o ON m.object_id=o.id
WHERE [definition] LIKE '%TABLE_NAME%'
Thursday, July 16, 2009
WebDAV problems
If you have problems with WebDAV this is a great link to troubleshoot WebDAV problems
Wednesday, July 15, 2009
Problem with AspectJ and Eclipse using maven
Having problems with AspectJ dependencies missing in the generated Eclipse .classpath file (mvn eclipse:eclipse) . The solution is to set:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<ajdtVersion>none</ajdtVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>org.thirdparty</groupId>
<artifactId>jar-containing-external-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<weaveDependencies>
<weaveDependency>
<groupId>org.mycompany</groupId>
<artifactId>jar-to-weave-with-aspects-in-this-library</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
</plugin>
ajdtVersion to "none"Here is how to set it in the POM file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<ajdtVersion>none</ajdtVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>org.thirdparty</groupId>
<artifactId>jar-containing-external-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<weaveDependencies>
<weaveDependency>
<groupId>org.mycompany</groupId>
<artifactId>jar-to-weave-with-aspects-in-this-library</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
</plugin>
Subscribe to:
Posts (Atom)