You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
(39) |
Dec
(10) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(19) |
Feb
(150) |
Mar
(10) |
Apr
|
May
(8) |
Jun
(11) |
Jul
(27) |
Aug
(52) |
Sep
(35) |
Oct
(30) |
Nov
(18) |
Dec
(4) |
2008 |
Jan
(76) |
Feb
(121) |
Mar
(39) |
Apr
(55) |
May
(18) |
Jun
(49) |
Jul
(32) |
Aug
(4) |
Sep
(10) |
Oct
|
Nov
(3) |
Dec
(33) |
2009 |
Jan
(19) |
Feb
(87) |
Mar
(69) |
Apr
(38) |
May
(47) |
Jun
(20) |
Jul
(5) |
Aug
(76) |
Sep
(145) |
Oct
(34) |
Nov
(8) |
Dec
(68) |
2010 |
Jan
(150) |
Feb
(379) |
Mar
(191) |
Apr
(100) |
May
(525) |
Jun
(269) |
Jul
(127) |
Aug
(190) |
Sep
(190) |
Oct
(29) |
Nov
(147) |
Dec
(83) |
2011 |
Jan
(188) |
Feb
(81) |
Mar
(43) |
Apr
(97) |
May
(63) |
Jun
(129) |
Jul
(17) |
Aug
(124) |
Sep
(6) |
Oct
(20) |
Nov
(67) |
Dec
(23) |
2012 |
Jan
(6) |
Feb
(14) |
Mar
(181) |
Apr
(64) |
May
(102) |
Jun
(47) |
Jul
(26) |
Aug
(3) |
Sep
(1) |
Oct
(14) |
Nov
(13) |
Dec
(23) |
2013 |
Jan
(4) |
Feb
(14) |
Mar
(18) |
Apr
(14) |
May
(27) |
Jun
(27) |
Jul
(5) |
Aug
(2) |
Sep
(74) |
Oct
(79) |
Nov
(21) |
Dec
(97) |
2014 |
Jan
(6) |
Feb
(3) |
Mar
(8) |
Apr
|
May
(5) |
Jun
|
Jul
(9) |
Aug
(6) |
Sep
(3) |
Oct
(10) |
Nov
(6) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
(1) |
Apr
(25) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fg...@us...> - 2007-06-30 15:32:30
|
Revision: 345 http://svn.sourceforge.net/openutils/?rev=345&view=rev Author: fgiust Date: 2007-06-30 08:32:32 -0700 (Sat, 30 Jun 2007) Log Message: ----------- [maven-release-plugin] prepare release openutils-mgnlspring-0.1 Modified Paths: -------------- trunk/openutils-mgnlspring/pom.xml Modified: trunk/openutils-mgnlspring/pom.xml =================================================================== --- trunk/openutils-mgnlspring/pom.xml 2007-06-30 15:31:28 UTC (rev 344) +++ trunk/openutils-mgnlspring/pom.xml 2007-06-30 15:32:32 UTC (rev 345) @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <groupId>net.sourceforge.openutils</groupId> <artifactId>openutils</artifactId> @@ -12,7 +11,7 @@ <groupId>it.openmindonline.magnolia</groupId> <artifactId>openutils-mgnlspring</artifactId> <name>openutils-mgnlspring</name> - <version>1.0-SNAPSHOT</version> + <version>0.1</version> <dependencies> <dependency> <groupId>org.slf4j</groupId> @@ -80,4 +79,10 @@ </exclusions> </dependency> </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlspring-0.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlspring-0.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-mgnlspring-0.1</url> + </scm> </project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-06-30 15:31:27
|
Revision: 344 http://svn.sourceforge.net/openutils/?rev=344&view=rev Author: fgiust Date: 2007-06-30 08:31:28 -0700 (Sat, 30 Jun 2007) Log Message: ----------- rename package Modified Paths: -------------- trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/ContentBridgeTag.java trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/MagnoliaMultipartResolver.java trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/RewriteVarsThreadLocal.java trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/UrlFunctions.java trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/WrappedResponse.java trunk/openutils-mgnlspring/src/main/resources/META-INF/magnolia-bridge-tags.tld trunk/openutils-mgnlspring/src/test/java/it/openutils/mgnlspring/ContentBridgeTagTest.java Added Paths: ----------- trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/ trunk/openutils-mgnlspring/src/test/java/it/openutils/mgnlspring/ Removed Paths: ------------- trunk/openutils-mgnlspring/src/main/java/it/openutils/mvcbridge/ trunk/openutils-mgnlspring/src/test/java/it/openutils/mvcbridge/ Copied: trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring (from rev 343, trunk/openutils-mgnlspring/src/main/java/it/openutils/mvcbridge) Modified: trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/ContentBridgeTag.java =================================================================== --- trunk/openutils-mgnlspring/src/main/java/it/openutils/mvcbridge/ContentBridgeTag.java 2007-06-30 15:23:43 UTC (rev 343) +++ trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/ContentBridgeTag.java 2007-06-30 15:31:28 UTC (rev 344) @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package it.openutils.mvcbridge; +package it.openutils.mgnlspring; import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.cms.security.AccessManager; Modified: trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/MagnoliaMultipartResolver.java =================================================================== --- trunk/openutils-mgnlspring/src/main/java/it/openutils/mvcbridge/MagnoliaMultipartResolver.java 2007-06-30 15:23:43 UTC (rev 343) +++ trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/MagnoliaMultipartResolver.java 2007-06-30 15:31:28 UTC (rev 344) @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package it.openutils.mvcbridge; +package it.openutils.mgnlspring; import info.magnolia.cms.beans.runtime.Document; import info.magnolia.cms.beans.runtime.MultipartForm; Modified: trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/RewriteVarsThreadLocal.java =================================================================== --- trunk/openutils-mgnlspring/src/main/java/it/openutils/mvcbridge/RewriteVarsThreadLocal.java 2007-06-30 15:23:43 UTC (rev 343) +++ trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/RewriteVarsThreadLocal.java 2007-06-30 15:31:28 UTC (rev 344) @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package it.openutils.mvcbridge; +package it.openutils.mgnlspring; /** * @author fgiust Modified: trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/UrlFunctions.java =================================================================== --- trunk/openutils-mgnlspring/src/main/java/it/openutils/mvcbridge/UrlFunctions.java 2007-06-30 15:23:43 UTC (rev 343) +++ trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/UrlFunctions.java 2007-06-30 15:31:28 UTC (rev 344) @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package it.openutils.mvcbridge; +package it.openutils.mgnlspring; import info.magnolia.context.MgnlContext; Modified: trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/WrappedResponse.java =================================================================== --- trunk/openutils-mgnlspring/src/main/java/it/openutils/mvcbridge/WrappedResponse.java 2007-06-30 15:23:43 UTC (rev 343) +++ trunk/openutils-mgnlspring/src/main/java/it/openutils/mgnlspring/WrappedResponse.java 2007-06-30 15:31:28 UTC (rev 344) @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package it.openutils.mvcbridge; +package it.openutils.mgnlspring; import java.io.ByteArrayOutputStream; import java.io.CharArrayWriter; Modified: trunk/openutils-mgnlspring/src/main/resources/META-INF/magnolia-bridge-tags.tld =================================================================== --- trunk/openutils-mgnlspring/src/main/resources/META-INF/magnolia-bridge-tags.tld 2007-06-30 15:23:43 UTC (rev 343) +++ trunk/openutils-mgnlspring/src/main/resources/META-INF/magnolia-bridge-tags.tld 2007-06-30 15:31:28 UTC (rev 344) @@ -9,7 +9,7 @@ <tag> <description>spring</description> <name>spring</name> - <tag-class>it.openutils.mvcbridge.ContentBridgeTag</tag-class> + <tag-class>it.openutils.mgnlspring.ContentBridgeTag</tag-class> <body-content>empty</body-content> <attribute> <name>url</name> @@ -19,12 +19,12 @@ </tag> <function> <name>url</name> - <function-class>it.openutils.mvcbridge.UrlFunctions</function-class> + <function-class>it.openutils.mgnlspring.UrlFunctions</function-class> <function-signature>java.lang.String url(java.lang.String)</function-signature> </function> <function> <name>urlto</name> - <function-class>it.openutils.mvcbridge.UrlFunctions</function-class> + <function-class>it.openutils.mgnlspring.UrlFunctions</function-class> <function-signature>java.lang.String urlWithDestination(java.lang.String, java.lang.String)</function-signature> </function> </taglib> \ No newline at end of file Copied: trunk/openutils-mgnlspring/src/test/java/it/openutils/mgnlspring (from rev 343, trunk/openutils-mgnlspring/src/test/java/it/openutils/mvcbridge) Modified: trunk/openutils-mgnlspring/src/test/java/it/openutils/mgnlspring/ContentBridgeTagTest.java =================================================================== --- trunk/openutils-mgnlspring/src/test/java/it/openutils/mvcbridge/ContentBridgeTagTest.java 2007-06-30 15:23:43 UTC (rev 343) +++ trunk/openutils-mgnlspring/src/test/java/it/openutils/mgnlspring/ContentBridgeTagTest.java 2007-06-30 15:31:28 UTC (rev 344) @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package it.openutils.mvcbridge; +package it.openutils.mgnlspring; import info.magnolia.context.MgnlContext; import info.magnolia.context.SystemContextImpl; -import it.openutils.mvcbridge.ContentBridgeTag; -import it.openutils.mvcbridge.RewriteVarsThreadLocal; -import it.openutils.mvcbridge.UrlFunctions; +import it.openutils.mgnlspring.ContentBridgeTag; +import it.openutils.mgnlspring.RewriteVarsThreadLocal; +import it.openutils.mgnlspring.UrlFunctions; import org.testng.Assert; import org.testng.annotations.Test; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-06-30 15:23:41
|
Revision: 343 http://svn.sourceforge.net/openutils/?rev=343&view=rev Author: fgiust Date: 2007-06-30 08:23:43 -0700 (Sat, 30 Jun 2007) Log Message: ----------- moved to mgnlspring Modified Paths: -------------- trunk/openutils-mgnlspring/src/main/java/it/openutils/mvcbridge/MagnoliaMultipartResolver.java Added Paths: ----------- trunk/openutils-mgnlspring/ trunk/openutils-mgnlspring/pom.xml trunk/openutils-mgnlspring/src/ Removed Paths: ------------- trunk/openutils-magnolia2mvcbridge/ trunk/openutils-mgnlspring/pom.xml trunk/openutils-mgnlspring/src/ Copied: trunk/openutils-mgnlspring (from rev 341, trunk/openutils-magnolia2mvcbridge) Deleted: trunk/openutils-mgnlspring/pom.xml =================================================================== --- trunk/openutils-magnolia2mvcbridge/pom.xml 2007-06-30 15:04:52 UTC (rev 341) +++ trunk/openutils-mgnlspring/pom.xml 2007-06-30 15:23:43 UTC (rev 343) @@ -1,71 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <modelVersion>4.0.0</modelVersion> - <packaging>jar</packaging> - <groupId>it.openmindonline.magnolia</groupId> - <artifactId>openutils-magnolia2mvcbridge</artifactId> - <name>openutils-magnolia2mvcbridge</name> - <version>1.0-SNAPSHOT</version> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.3.0</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>2.0.6</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>2.0.6</version> - </dependency> - <dependency> - <groupId>info.magnolia</groupId> - <artifactId>magnolia-core</artifactId> - <version>3.0.2</version> - </dependency> - <dependency> - <groupId>info.magnolia</groupId> - <artifactId>magnolia-jaas</artifactId> - <version>3.0.2</version> - </dependency> - <dependency> - <groupId>opensymphony</groupId> - <artifactId>sitemesh</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>jsp-api</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> -</project> Copied: trunk/openutils-mgnlspring/pom.xml (from rev 342, trunk/openutils-magnolia2mvcbridge/pom.xml) =================================================================== --- trunk/openutils-mgnlspring/pom.xml (rev 0) +++ trunk/openutils-mgnlspring/pom.xml 2007-06-30 15:23:43 UTC (rev 343) @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + <packaging>jar</packaging> + <groupId>it.openmindonline.magnolia</groupId> + <artifactId>openutils-mgnlspring</artifactId> + <name>openutils-mgnlspring</name> + <version>1.0-SNAPSHOT</version> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.3.0</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>2.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>2.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-core</artifactId> + <version>3.0.2</version> + </dependency> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-jaas</artifactId> + <version>3.0.2</version> + </dependency> + <dependency> + <groupId>opensymphony</groupId> + <artifactId>sitemesh</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jsp-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> +</project> Copied: trunk/openutils-mgnlspring/src (from rev 342, trunk/openutils-magnolia2mvcbridge/src) Modified: trunk/openutils-mgnlspring/src/main/java/it/openutils/mvcbridge/MagnoliaMultipartResolver.java =================================================================== --- trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/MagnoliaMultipartResolver.java 2007-06-30 15:21:31 UTC (rev 342) +++ trunk/openutils-mgnlspring/src/main/java/it/openutils/mvcbridge/MagnoliaMultipartResolver.java 2007-06-30 15:23:43 UTC (rev 343) @@ -48,7 +48,7 @@ /** * Spring MagnoliaMultipartResolver which interacts with magnolia. * @author fgiust - * @version $Id: $ + * @version $Id$ */ public class MagnoliaMultipartResolver extends CommonsFileUploadSupport implements This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-06-30 15:21:30
|
Revision: 342 http://svn.sourceforge.net/openutils/?rev=342&view=rev Author: fgiust Date: 2007-06-30 08:21:31 -0700 (Sat, 30 Jun 2007) Log Message: ----------- change artifact name Modified Paths: -------------- trunk/openutils-magnolia2mvcbridge/pom.xml Modified: trunk/openutils-magnolia2mvcbridge/pom.xml =================================================================== --- trunk/openutils-magnolia2mvcbridge/pom.xml 2007-06-30 15:04:52 UTC (rev 341) +++ trunk/openutils-magnolia2mvcbridge/pom.xml 2007-06-30 15:21:31 UTC (rev 342) @@ -10,8 +10,8 @@ <modelVersion>4.0.0</modelVersion> <packaging>jar</packaging> <groupId>it.openmindonline.magnolia</groupId> - <artifactId>openutils-magnolia2mvcbridge</artifactId> - <name>openutils-magnolia2mvcbridge</name> + <artifactId>openutils-mgnlspring</artifactId> + <name>openutils-mgnlspring</name> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> @@ -23,11 +23,23 @@ <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>2.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>2.0.6</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>info.magnolia</groupId> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-06-30 15:04:54
|
Revision: 341 http://svn.sourceforge.net/openutils/?rev=341&view=rev Author: fgiust Date: 2007-06-30 08:04:52 -0700 (Sat, 30 Jun 2007) Log Message: ----------- initial import Added Paths: ----------- trunk/openutils-magnolia2mvcbridge/ trunk/openutils-magnolia2mvcbridge/pom.xml trunk/openutils-magnolia2mvcbridge/src/ trunk/openutils-magnolia2mvcbridge/src/main/ trunk/openutils-magnolia2mvcbridge/src/main/java/ trunk/openutils-magnolia2mvcbridge/src/main/java/it/ trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/ trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/ trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/ContentBridgeTag.java trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/MagnoliaMultipartResolver.java trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/RewriteVarsThreadLocal.java trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/UrlFunctions.java trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/WrappedResponse.java trunk/openutils-magnolia2mvcbridge/src/main/resources/ trunk/openutils-magnolia2mvcbridge/src/main/resources/META-INF/ trunk/openutils-magnolia2mvcbridge/src/main/resources/META-INF/magnolia-bridge-tags.tld trunk/openutils-magnolia2mvcbridge/src/test/ trunk/openutils-magnolia2mvcbridge/src/test/java/ trunk/openutils-magnolia2mvcbridge/src/test/java/it/ trunk/openutils-magnolia2mvcbridge/src/test/java/it/openutils/ trunk/openutils-magnolia2mvcbridge/src/test/java/it/openutils/mvcbridge/ trunk/openutils-magnolia2mvcbridge/src/test/java/it/openutils/mvcbridge/ContentBridgeTagTest.java Property changes on: trunk/openutils-magnolia2mvcbridge ___________________________________________________________________ Name: svn:ignore + target .checkstyle .classpath .project .settings Added: trunk/openutils-magnolia2mvcbridge/pom.xml =================================================================== --- trunk/openutils-magnolia2mvcbridge/pom.xml (rev 0) +++ trunk/openutils-magnolia2mvcbridge/pom.xml 2007-06-30 15:04:52 UTC (rev 341) @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + <packaging>jar</packaging> + <groupId>it.openmindonline.magnolia</groupId> + <artifactId>openutils-magnolia2mvcbridge</artifactId> + <name>openutils-magnolia2mvcbridge</name> + <version>1.0-SNAPSHOT</version> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.3.0</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>2.0.6</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>2.0.6</version> + </dependency> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-core</artifactId> + <version>3.0.2</version> + </dependency> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-jaas</artifactId> + <version>3.0.2</version> + </dependency> + <dependency> + <groupId>opensymphony</groupId> + <artifactId>sitemesh</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jsp-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> +</project> Property changes on: trunk/openutils-magnolia2mvcbridge/pom.xml ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/ContentBridgeTag.java =================================================================== --- trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/ContentBridgeTag.java (rev 0) +++ trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/ContentBridgeTag.java 2007-06-30 15:04:52 UTC (rev 341) @@ -0,0 +1,193 @@ +/* + * Copyright 2007 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.mvcbridge; + +import info.magnolia.cms.beans.config.ContentRepository; +import info.magnolia.cms.security.AccessManager; +import info.magnolia.cms.security.Authenticator; +import info.magnolia.cms.security.Permission; +import info.magnolia.cms.security.SecureURI; +import info.magnolia.context.MgnlContext; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.opensymphony.module.sitemesh.Page; +import com.opensymphony.module.sitemesh.parser.FastPageParser; + + +/** + * @author fgiust + * @version $Id$ + */ +public class ContentBridgeTag extends TagSupport +{ + + /** + * Stable serialVersionUID. + */ + private static final long serialVersionUID = 42L; + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(ContentBridgeTag.class); + + /** + * Url to be included. + */ + private String url; + + /** + * Sets the url. + * @param url the url to set + */ + public void setUrl(String url) + { + this.url = url; + } + + protected String makeUrl(String contextPath, String requestURI, String actionParam, String baseActionUrl) + { + + StringBuffer currentUrl = new StringBuffer(); + currentUrl.append(requestURI); + + String actionUrl = actionParam; + + if (actionUrl != null && !actionUrl.startsWith("/")) + { + + if (!StringUtils.equals(actionUrl, baseActionUrl) && StringUtils.contains(baseActionUrl, "/")) + { + actionUrl = StringUtils.substringBeforeLast(baseActionUrl, "/") + "/" + actionUrl; + } + + if (!actionUrl.startsWith("/")) + { + actionUrl = "/" + actionUrl; + } + } + + RewriteVarsThreadLocal.setContextPath(contextPath); + RewriteVarsThreadLocal.setCurrentPageUrl(currentUrl.toString()); + + return actionUrl; + + } + + /** + * {@inheritDoc} + */ + @Override + public int doStartTag() throws JspException + { + + HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); + HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); + + String requestURI = (String) request.getAttribute("javax.servlet.forward.request_uri"); + + if (requestURI == null) + { + requestURI = request.getRequestURI(); + } + + String actionParam = url; + + if (request.getParameter("_action") != null) + { + actionParam = request.getParameter("_action"); + } + + if (requestURI.startsWith("//")) // buggy url set in javax.servlet.forward.request_uri? + { + requestURI = requestURI.substring(1); + } + + String actionUrl = makeUrl(request.getContextPath(), requestURI, actionParam, url); + + if (!StringUtils.contains(actionUrl, "?")) + { + actionUrl = StringUtils.replaceOnce(actionUrl, "&", "?"); + } + + if (SecureURI.isProtected(actionUrl)) + { + AccessManager am = MgnlContext.getAccessManager(ContentRepository.WEBSITE); + if (!Authenticator.isAuthenticated(request) || !am.isGranted(actionUrl, Permission.READ)) + { + log.info("User not allowed to read path {}", actionUrl); + return super.doStartTag(); + } + } + + RequestDispatcher rd = pageContext.getServletConfig().getServletContext().getRequestDispatcher(actionUrl); + + WrappedResponse wresponse = new WrappedResponse(response); + JspWriter out = pageContext.getOut(); + try + { + rd.include(request, wresponse); + } + catch (ServletException e) + { + log.error("error including " + actionUrl + ": " + e.getMessage(), e); + e.printStackTrace(new PrintWriter(out)); + } + catch (IOException e) + { + log.error("error including " + actionUrl + ": " + e.getMessage(), e); + e.printStackTrace(new PrintWriter(out)); + } + finally + { + RewriteVarsThreadLocal.setCurrentPageUrl(null); + RewriteVarsThreadLocal.setContextPath(null); + } + + char[] content = wresponse.getContent(); + + if (content != null && content.length > 0) + { + FastPageParser parser = new FastPageParser(); + try + { + Page page = parser.parse(content); + page.writeBody(out); + } + catch (IOException e) + { + log.error("error parsing " + actionUrl + ": " + e.getMessage(), e); + e.printStackTrace(new PrintWriter(out)); + } + } + + return super.doStartTag(); + } +} Property changes on: trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/ContentBridgeTag.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/MagnoliaMultipartResolver.java =================================================================== --- trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/MagnoliaMultipartResolver.java (rev 0) +++ trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/MagnoliaMultipartResolver.java 2007-06-30 15:04:52 UTC (rev 341) @@ -0,0 +1,219 @@ +/* + * Copyright 2007 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.mvcbridge; + +import info.magnolia.cms.beans.runtime.Document; +import info.magnolia.cms.beans.runtime.MultipartForm; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.fileupload.FileItemFactory; +import org.apache.commons.fileupload.FileUpload; +import org.apache.commons.fileupload.FileUploadBase; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.fileupload.servlet.ServletRequestContext; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.springframework.web.context.ServletContextAware; +import org.springframework.web.multipart.MultipartException; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.springframework.web.multipart.MultipartResolver; +import org.springframework.web.multipart.commons.CommonsFileUploadSupport; +import org.springframework.web.multipart.commons.CommonsMultipartFile; +import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest; +import org.springframework.web.util.WebUtils; + + +/** + * Spring MagnoliaMultipartResolver which interacts with magnolia. + * @author fgiust + * @version $Id: $ + */ +public class MagnoliaMultipartResolver extends CommonsFileUploadSupport + implements + MultipartResolver, + ServletContextAware +{ + + /** + * Constructor for use as bean. Determines the servlet container's temporary directory via the ServletContext passed + * in as through the ServletContextAware interface (typically by a WebApplicationContext). + * @see #setServletContext + * @see org.springframework.web.context.ServletContextAware + * @see org.springframework.web.context.WebApplicationContext + */ + public MagnoliaMultipartResolver() + { + super(); + } + + /** + * Constructor for standalone usage. Determines the servlet container's temporary directory via the given + * ServletContext. + * @param servletContext the ServletContext to use + */ + public MagnoliaMultipartResolver(ServletContext servletContext) + { + this(); + setServletContext(servletContext); + } + + /** + * Initialize the underlying <code>org.apache.commons.fileupload.servlet.ServletFileUpload</code> instance. Can be + * overridden to use a custom subclass, e.g. for testing purposes. + * @param fileItemFactory the Commons FileItemFactory to use + * @return the new ServletFileUpload instance + */ + @Override + protected FileUpload newFileUpload(FileItemFactory fileItemFactory) + { + return new ServletFileUpload(fileItemFactory); + } + + public void setServletContext(ServletContext servletContext) + { + if (!isUploadTempDirSpecified()) + { + getFileItemFactory().setRepository(WebUtils.getTempDir(servletContext)); + } + } + + public boolean isMultipart(HttpServletRequest request) + { + return FileUploadBase.isMultipartContent(new ServletRequestContext(request)); + } + + @SuppressWarnings("unchecked") + public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException + { + // already parsed by magnolia + MultipartForm form = (MultipartForm) request.getAttribute("multipartform"); + + Map<String, Document> documents = form.getDocuments(); + Map<String, MultipartFile> files = new HashMap<String, MultipartFile>(); + + for (String key : documents.keySet()) + { + Document doc = documents.get(key); + files.put(key, new DocWrapperMultipartFile(doc)); + } + + Map<String, String> singleParamters = form.getParameters(); + Map<String, String[]> multiParamters = new HashMap<String, String[]>(); + + for (String key : singleParamters.keySet()) + { + multiParamters.put(key, new String[]{singleParamters.get(key) }); + } + + return new DefaultMultipartHttpServletRequest(request, files, multiParamters); + + } + + public static class DocWrapperMultipartFile implements MultipartFile + { + + Document document; + + public DocWrapperMultipartFile(Document document) + { + this.document = document; + } + + /** + * {@inheritDoc} + */ + public byte[] getBytes() throws IOException + { + return IOUtils.toByteArray(getInputStream()); + } + + /** + * {@inheritDoc} + */ + public String getContentType() + { + return document.getType(); + } + + /** + * {@inheritDoc} + */ + public InputStream getInputStream() throws IOException + { + return document.getStream(); + } + + /** + * {@inheritDoc} + */ + public String getName() + { + return document.getFileNameWithExtension(); + } + + /** + * {@inheritDoc} + */ + public String getOriginalFilename() + { + return document.getFileNameWithExtension(); + } + + /** + * {@inheritDoc} + */ + public long getSize() + { + return document.getLength(); + } + + /** + * {@inheritDoc} + */ + public boolean isEmpty() + { + return document.getLength() == 0; + } + + /** + * {@inheritDoc} + */ + public void transferTo(File dest) throws IOException, IllegalStateException + { + FileUtils.copyFile(document.getFile(), dest); + } + + } + + /** + * {@inheritDoc} + */ + public void cleanupMultipart(MultipartHttpServletRequest request) + { + // nothing to do + + } + +} Property changes on: trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/MagnoliaMultipartResolver.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/RewriteVarsThreadLocal.java =================================================================== --- trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/RewriteVarsThreadLocal.java (rev 0) +++ trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/RewriteVarsThreadLocal.java 2007-06-30 15:04:52 UTC (rev 341) @@ -0,0 +1,73 @@ +/* + * Copyright 2007 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.mvcbridge; + +/** + * @author fgiust + * @version $Id$ + */ +public final class RewriteVarsThreadLocal +{ + + private static ThreadLocal<String> currentPageUrl = new ThreadLocal<String>(); + + private static ThreadLocal<String> contextPath = new ThreadLocal<String>(); + + /** + * Don't instantiate. + */ + private RewriteVarsThreadLocal() + { + // unused + } + + /** + * Returns the currentPageUrl. + * @return the currentPageUrl + */ + public static String getCurrentPageUrl() + { + return currentPageUrl.get(); + } + + /** + * Sets the currentPageUrl. + * @param url the currentPageUrl to set + */ + public static void setCurrentPageUrl(String url) + { + currentPageUrl.set(url); + } + + /** + * Returns the contextPath. + * @return the contextPath + */ + public static String getContextPath() + { + return contextPath.get(); + } + + /** + * Sets the contextPath. + * @param context the contextPath to set + */ + public static void setContextPath(String context) + { + contextPath.set(context); + } + +} Property changes on: trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/RewriteVarsThreadLocal.java ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/UrlFunctions.java =================================================================== --- trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/UrlFunctions.java (rev 0) +++ trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/UrlFunctions.java 2007-06-30 15:04:52 UTC (rev 341) @@ -0,0 +1,105 @@ +/* + * Copyright 2007 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.mvcbridge; + +import info.magnolia.context.MgnlContext; + +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; + + +/** + * @author fgiust + * @version $Id$ + */ +public final class UrlFunctions +{ + + /** + * Don't instantiate. + */ + private UrlFunctions() + { + // unused + } + + public static String url(String url) + { + return encodeUrl(RewriteVarsThreadLocal.getCurrentPageUrl(), url); + } + + public static String urlWithDestination(String url, String destination) + { + // check RewriteVarsThreadLocal because if not running under magnolia we should not replace urls + if (RewriteVarsThreadLocal.getCurrentPageUrl() == null || destination == null) + { + return url(url); + } + + return encodeUrl(RewriteVarsThreadLocal.getContextPath() + destination, url); + } + + /** + * @param baseUrl + * @param actionUrl + * @return + */ + private static String encodeUrl(final String baseUrl, String actionUrl) + { + String contextPath = MgnlContext.getContextPath(); + if (StringUtils.isNotEmpty(contextPath) && actionUrl != null && actionUrl.startsWith(contextPath)) + { + actionUrl = StringUtils.substringAfter(actionUrl, contextPath); + } + + if (baseUrl == null) + { + if (actionUrl.startsWith("/")) + { + return contextPath + actionUrl; + } + + return actionUrl; + } + + int paramIndex = baseUrl.indexOf('?'); + String page = baseUrl; + String params = null; + if (paramIndex != -1) + { + page = StringUtils.substring(baseUrl, 0, paramIndex + 1); + params = StringUtils.substring(baseUrl, paramIndex + 1); + } + + StringBuffer outUrl = new StringBuffer(); + outUrl.append(page); + outUrl.append("?"); + + if (params != null) + { + outUrl.append(params); + outUrl.append("&"); + } + + outUrl.append("_action="); + outUrl.append(StringUtils.replace(actionUrl, "?", "&")); + + String encodedUrl = StringEscapeUtils.escapeXml(outUrl.toString()); + + return encodedUrl; + } + +} Property changes on: trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/UrlFunctions.java ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/WrappedResponse.java =================================================================== --- trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/WrappedResponse.java (rev 0) +++ trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/WrappedResponse.java 2007-06-30 15:04:52 UTC (rev 341) @@ -0,0 +1,130 @@ +/* + * Copyright 2007 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.mvcbridge; + +import java.io.ByteArrayOutputStream; +import java.io.CharArrayWriter; +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; + + +/** + * @author fgiust + * @version $Id$ + */ +public class WrappedResponse extends HttpServletResponseWrapper +{ + + /** + * The buffered response. + */ + private CharArrayWriter outputWriter; + + /** + * The outputWriter stream. + */ + private SimpleServletOutputStream servletOutputStream; + + /** + * @param httpServletResponse the response to wrap + */ + public WrappedResponse(HttpServletResponse httpServletResponse) + { + super(httpServletResponse); + this.outputWriter = new CharArrayWriter(); + this.servletOutputStream = new SimpleServletOutputStream(); + } + + /** + * {@inheritDoc} + */ + @Override + public PrintWriter getWriter() throws IOException + { + return new PrintWriter(this.outputWriter); + } + + /** + * Flush the buffer, not the response. + * @throws IOException if encountered when flushing + */ + @Override + public void flushBuffer() throws IOException + { + if (outputWriter != null) + { + this.outputWriter.flush(); + this.servletOutputStream.outputStream.reset(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public ServletOutputStream getOutputStream() throws IOException + { + return this.servletOutputStream; + } + + /** + * @return buffered response + */ + public char[] getContent() + { + return this.outputWriter.toCharArray(); + } + + class SimpleServletOutputStream extends ServletOutputStream + { + + /** + * My outputWriter stream, a buffer. + */ + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + + /** + * {@inheritDoc} + */ + @Override + public void write(int b) + { + this.outputStream.write(b); + } + + /** + * {@inheritDoc} Get the contents of the outputStream. + * @return contents of the outputStream + */ + @Override + public String toString() + { + return this.outputStream.toString(); + } + + /** + * Reset the wrapped ByteArrayOutputStream. + */ + public void reset() + { + outputStream.reset(); + } + } +} \ No newline at end of file Property changes on: trunk/openutils-magnolia2mvcbridge/src/main/java/it/openutils/mvcbridge/WrappedResponse.java ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-magnolia2mvcbridge/src/main/resources/META-INF/magnolia-bridge-tags.tld =================================================================== --- trunk/openutils-magnolia2mvcbridge/src/main/resources/META-INF/magnolia-bridge-tags.tld (rev 0) +++ trunk/openutils-magnolia2mvcbridge/src/main/resources/META-INF/magnolia-bridge-tags.tld 2007-06-30 15:04:52 UTC (rev 341) @@ -0,0 +1,30 @@ +<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" + version="2.0"> + <description>magnolia-bridge</description> + <display-name>magnolia-bridge</display-name> + <tlib-version>1.2</tlib-version> + <short-name>magnolia-bridge</short-name> + <uri>magnolia-bridge</uri> + <tag> + <description>spring</description> + <name>spring</name> + <tag-class>it.openutils.mvcbridge.ContentBridgeTag</tag-class> + <body-content>empty</body-content> + <attribute> + <name>url</name> + <required>true</required> + <rtexprvalue>true</rtexprvalue> + </attribute> + </tag> + <function> + <name>url</name> + <function-class>it.openutils.mvcbridge.UrlFunctions</function-class> + <function-signature>java.lang.String url(java.lang.String)</function-signature> + </function> + <function> + <name>urlto</name> + <function-class>it.openutils.mvcbridge.UrlFunctions</function-class> + <function-signature>java.lang.String urlWithDestination(java.lang.String, java.lang.String)</function-signature> + </function> +</taglib> \ No newline at end of file Property changes on: trunk/openutils-magnolia2mvcbridge/src/main/resources/META-INF/magnolia-bridge-tags.tld ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + text/xml Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-magnolia2mvcbridge/src/test/java/it/openutils/mvcbridge/ContentBridgeTagTest.java =================================================================== --- trunk/openutils-magnolia2mvcbridge/src/test/java/it/openutils/mvcbridge/ContentBridgeTagTest.java (rev 0) +++ trunk/openutils-magnolia2mvcbridge/src/test/java/it/openutils/mvcbridge/ContentBridgeTagTest.java 2007-06-30 15:04:52 UTC (rev 341) @@ -0,0 +1,97 @@ +/* + * Copyright 2007 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.mvcbridge; + +import info.magnolia.context.MgnlContext; +import info.magnolia.context.SystemContextImpl; +import it.openutils.mvcbridge.ContentBridgeTag; +import it.openutils.mvcbridge.RewriteVarsThreadLocal; +import it.openutils.mvcbridge.UrlFunctions; + +import org.testng.Assert; +import org.testng.annotations.Test; + + +/** + * @author fgiust + * @version $Id$ + */ +public class ContentBridgeTagTest +{ + + private ContentBridgeTag tag = new ContentBridgeTag(); + + @Test + public void testRewriteSimple() + { + MgnlContext.setInstance(new SystemContextImpl()); + + String action = tag.makeUrl("", "/test/it.html", "/spring/myaction.do", "/spring/start.do"); + Assert.assertEquals(action, "/spring/myaction.do"); // <!-- include this + + String pageUrl = RewriteVarsThreadLocal.getCurrentPageUrl(); + Assert.assertEquals(pageUrl, "/test/it.html"); + + String finalUrl = UrlFunctions.url("/spring/pippo.do"); + Assert.assertEquals(finalUrl, "/test/it.html?_action=/spring/pippo.do"); + } + + @Test + public void testRewriteNoPath() + { + MgnlContext.setInstance(new SystemContextImpl()); + + String action = tag.makeUrl("", "/test/it.html", "myaction.do", "/spring/start.do"); + Assert.assertEquals(action, "/spring/myaction.do"); // <!-- include this + + String pageUrl = RewriteVarsThreadLocal.getCurrentPageUrl(); + Assert.assertEquals(pageUrl, "/test/it.html"); + + String finalUrl = UrlFunctions.url("/spring/pippo.do"); + Assert.assertEquals(finalUrl, "/test/it.html?_action=/spring/pippo.do"); + } + + @Test + public void testRewriteParams() + { + MgnlContext.setInstance(new SystemContextImpl()); + + String action = tag.makeUrl("", "/test/it.html", "myaction.do", "/spring/start.do"); + Assert.assertEquals(action, "/spring/myaction.do"); // <!-- include this + + String pageUrl = RewriteVarsThreadLocal.getCurrentPageUrl(); + Assert.assertEquals(pageUrl, "/test/it.html"); + + String finalUrl = UrlFunctions.url("/spring/pippo.do?new=1&old=2"); + Assert.assertEquals(finalUrl, "/test/it.html?_action=/spring/pippo.do&new=1&old=2"); + } + + @Test + public void testRewriteActionParams() + { + MgnlContext.setInstance(new SystemContextImpl()); + + String action = tag.makeUrl("", "/mac/it/index.html", "iscrizioneEvento.do?idEvento=2", "/spring/start.do"); + Assert.assertEquals(action, "/spring/iscrizioneEvento.do?idEvento=2"); // <!-- include this + + String pageUrl = RewriteVarsThreadLocal.getCurrentPageUrl(); + Assert.assertEquals(pageUrl, "/mac/it/index.html"); + + String finalUrl = UrlFunctions.url("iscrizioneEvento.do?idEvento=2"); + Assert.assertEquals(finalUrl, "/mac/it/index.html?_action=iscrizioneEvento.do&idEvento=2"); + } + +} Property changes on: trunk/openutils-magnolia2mvcbridge/src/test/java/it/openutils/mvcbridge/ContentBridgeTagTest.java ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mol...@us...> - 2007-06-15 15:50:13
|
Revision: 340 http://svn.sourceforge.net/openutils/?rev=340&view=rev Author: molaschi Date: 2007-06-15 08:50:14 -0700 (Fri, 15 Jun 2007) Log Message: ----------- spring exporter for enabling bean to be called by http request and to return results in JSON protocol Modified Paths: -------------- trunk/openutils-spring/pom.xml Added Paths: ----------- trunk/openutils-spring/src/main/java/it/openutils/spring/remoting/ trunk/openutils-spring/src/main/java/it/openutils/spring/remoting/exporters/ trunk/openutils-spring/src/main/java/it/openutils/spring/remoting/exporters/JSONServiceExporter.java Modified: trunk/openutils-spring/pom.xml =================================================================== --- trunk/openutils-spring/pom.xml 2007-06-14 09:02:24 UTC (rev 339) +++ trunk/openutils-spring/pom.xml 2007-06-15 15:50:14 UTC (rev 340) @@ -1,4 +1,5 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>net.sourceforge.openutils</groupId> @@ -44,6 +45,17 @@ </exclusions> </dependency> <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-remoting</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>net.sf.json-lib</groupId> + <artifactId>json-lib</artifactId> + <version>1.1</version> + <classifier>jdk15</classifier> + </dependency> + <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.3</version> Added: trunk/openutils-spring/src/main/java/it/openutils/spring/remoting/exporters/JSONServiceExporter.java =================================================================== --- trunk/openutils-spring/src/main/java/it/openutils/spring/remoting/exporters/JSONServiceExporter.java (rev 0) +++ trunk/openutils-spring/src/main/java/it/openutils/spring/remoting/exporters/JSONServiceExporter.java 2007-06-15 15:50:14 UTC (rev 340) @@ -0,0 +1,112 @@ +package it.openutils.spring.remoting.exporters; + +import java.lang.reflect.Method; +import java.lang.reflect.TypeVariable; +import java.util.Enumeration; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sf.json.JSONObject; + +import org.apache.commons.beanutils.ConvertUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.math.NumberUtils; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.remoting.support.RemoteInvocation; +import org.springframework.remoting.support.RemoteInvocationBasedExporter; +import org.springframework.remoting.support.RemoteInvocationResult; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.Controller; + + +/** + * @author mmolaschi + * @version $Id: $ + */ +public class JSONServiceExporter extends RemoteInvocationBasedExporter implements Controller +{ + private static final String METHOD = "__method__"; + + private static final String PARAM_PREFIX = "param"; + + private static final String CONTENT_TYPE = "text/x-json"; + + /** + * {@inheritDoc} + */ + public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception + { + if (request.getParameter(METHOD) != null) + { + String methodRequest = request.getParameter(METHOD); + Method[] methods = this.getServiceInterface().getMethods(); + for (Method method : methods) + { + if (method.getName().equals(methodRequest)) + { + Class[] types = method.getParameterTypes(); + Object[] values = new Object[types.length]; + if (values.length > 0) + { + int i = 0; + Enumeration<String> names = request.getParameterNames(); + while (names.hasMoreElements()) + { + String name = names.nextElement(); + if (name != null && name.startsWith(PARAM_PREFIX)) + { + String posStr = StringUtils.substringAfter(name, PARAM_PREFIX); + int pos = NumberUtils.toInt(posStr); + + String[] reqValues = request.getParameterValues(name); + if (reqValues != null && reqValues.length > 0) + { + if (types[pos].isArray()) + { + values[pos] = ConvertUtils.convert(reqValues, types[pos]); + } + else + { + values[pos] = ConvertUtils.convert(reqValues[0], types[pos]); + } + } + else + { + values[pos] = null; + } + + } + } + } + + RemoteInvocation invocation = new RemoteInvocation(); + invocation.setArguments(values); + invocation.setParameterTypes(types); + invocation.setMethodName(methodRequest); + + RemoteInvocationResult result = invokeAndCreateResult(invocation, this.getProxyForService()); + + JSONObject obj = null; + if (result.hasException()) + { + obj = JSONObject.fromBean(result.getException()); + obj.put("exception", true); + } + else + { + obj = JSONObject.fromBean(result.getValue()); + obj.put("exception", false); + } + + response.setContentType(CONTENT_TYPE); + obj.write(response.getWriter()); + + break; + } + } + + } + return null; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-06-06 16:42:42
|
Revision: 337 http://svn.sourceforge.net/openutils/?rev=337&view=rev Author: fgiust Date: 2007-06-06 09:42:44 -0700 (Wed, 06 Jun 2007) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/openutils-dbmigration/pom.xml Modified: trunk/openutils-dbmigration/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2007-06-06 16:42:13 UTC (rev 336) +++ trunk/openutils-dbmigration/pom.xml 2007-06-06 16:42:44 UTC (rev 337) @@ -8,7 +8,7 @@ </parent> <artifactId>openutils-dbmigration</artifactId> <name>openutils db migration framework</name> - <version>0.6</version> + <version>0.7-SNAPSHOT</version> <description /> <dependencies> <dependency> @@ -84,10 +84,4 @@ <scope>test</scope> </dependency> </dependencies> - - <scm> - <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.6</connection> - <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.6</developerConnection> - <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-0.6</url> - </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-06-06 16:42:12
|
Revision: 336 http://svn.sourceforge.net/openutils/?rev=336&view=rev Author: fgiust Date: 2007-06-06 09:42:13 -0700 (Wed, 06 Jun 2007) Log Message: ----------- [maven-release-plugin] copy for tag openutils-dbmigration-0.6 Added Paths: ----------- tags/openutils-dbmigration-0.6/ tags/openutils-dbmigration-0.6/pom.xml Removed Paths: ------------- tags/openutils-dbmigration-0.6/pom.xml Copied: tags/openutils-dbmigration-0.6 (from rev 334, trunk/openutils-dbmigration) Deleted: tags/openutils-dbmigration-0.6/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2007-05-23 18:06:03 UTC (rev 334) +++ tags/openutils-dbmigration-0.6/pom.xml 2007-06-06 16:42:13 UTC (rev 336) @@ -1,87 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-dbmigration</artifactId> - <name>openutils db migration framework</name> - <version>0.6-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.2</version> - </dependency> - <dependency> - <groupId>poi</groupId> - <artifactId>poi</artifactId> - <version>2.5.1-final-20040804</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.0</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-dbmigration-0.6/pom.xml (from rev 335, trunk/openutils-dbmigration/pom.xml) =================================================================== --- tags/openutils-dbmigration-0.6/pom.xml (rev 0) +++ tags/openutils-dbmigration-0.6/pom.xml 2007-06-06 16:42:13 UTC (rev 336) @@ -0,0 +1,93 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-dbmigration</artifactId> + <name>openutils db migration framework</name> + <version>0.6</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>poi</groupId> + <artifactId>poi</artifactId> + <version>2.5.1-final-20040804</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.0</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.6</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.6</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-0.6</url> + </scm> +</project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-06-06 16:41:11
|
Revision: 335 http://svn.sourceforge.net/openutils/?rev=335&view=rev Author: fgiust Date: 2007-06-06 09:41:13 -0700 (Wed, 06 Jun 2007) Log Message: ----------- [maven-release-plugin] prepare release openutils-dbmigration-0.6 Modified Paths: -------------- trunk/openutils-dbmigration/pom.xml Modified: trunk/openutils-dbmigration/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2007-05-23 18:06:03 UTC (rev 334) +++ trunk/openutils-dbmigration/pom.xml 2007-06-06 16:41:13 UTC (rev 335) @@ -8,7 +8,7 @@ </parent> <artifactId>openutils-dbmigration</artifactId> <name>openutils db migration framework</name> - <version>0.6-SNAPSHOT</version> + <version>0.6</version> <description /> <dependencies> <dependency> @@ -84,4 +84,10 @@ <scope>test</scope> </dependency> </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.6</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.6</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-0.6</url> + </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-05-23 18:06:02
|
Revision: 334 http://svn.sourceforge.net/openutils/?rev=334&view=rev Author: fgiust Date: 2007-05-23 11:06:03 -0700 (Wed, 23 May 2007) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/openutils-testing-junit/pom.xml Modified: trunk/openutils-testing-junit/pom.xml =================================================================== --- trunk/openutils-testing-junit/pom.xml 2007-05-23 18:05:56 UTC (rev 333) +++ trunk/openutils-testing-junit/pom.xml 2007-05-23 18:06:03 UTC (rev 334) @@ -8,7 +8,7 @@ </parent> <artifactId>openutils-testing-junit</artifactId> <name>openutils test utils (junit)</name> - <version>1.1.1</version> + <version>1.1.2-SNAPSHOT</version> <description>openutils test utils</description> <dependencies> <dependency> @@ -55,10 +55,4 @@ <version>3.8.1</version> </dependency> </dependencies> - - <scm> - <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-1.1.1</connection> - <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-1.1.1</developerConnection> - <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-junit-1.1.1</url> - </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-05-23 18:05:56
|
Revision: 333 http://svn.sourceforge.net/openutils/?rev=333&view=rev Author: fgiust Date: 2007-05-23 11:05:56 -0700 (Wed, 23 May 2007) Log Message: ----------- [maven-release-plugin] copy for tag openutils-testing-junit-1.1.1 Added Paths: ----------- tags/openutils-testing-junit-1.1.1/ tags/openutils-testing-junit-1.1.1/pom.xml tags/openutils-testing-junit-1.1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java Removed Paths: ------------- tags/openutils-testing-junit-1.1.1/pom.xml tags/openutils-testing-junit-1.1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java Copied: tags/openutils-testing-junit-1.1.1 (from rev 327, trunk/openutils-testing-junit) Deleted: tags/openutils-testing-junit-1.1.1/pom.xml =================================================================== --- trunk/openutils-testing-junit/pom.xml 2007-05-04 16:49:46 UTC (rev 327) +++ tags/openutils-testing-junit-1.1.1/pom.xml 2007-05-23 18:05:56 UTC (rev 333) @@ -1,58 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-testing-junit</artifactId> - <name>openutils test utils (junit)</name> - <version>1.1.1-SNAPSHOT</version> - <description>openutils test utils</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.2</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-hibernate3</artifactId> - <version>2.0.1</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.2</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-testing-junit-1.1.1/pom.xml (from rev 332, trunk/openutils-testing-junit/pom.xml) =================================================================== --- tags/openutils-testing-junit-1.1.1/pom.xml (rev 0) +++ tags/openutils-testing-junit-1.1.1/pom.xml 2007-05-23 18:05:56 UTC (rev 333) @@ -0,0 +1,64 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-testing-junit</artifactId> + <name>openutils test utils (junit)</name> + <version>1.1.1</version> + <description>openutils test utils</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-hibernate3</artifactId> + <version>2.0.1</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>org.dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.2</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-1.1.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-1.1.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-junit-1.1.1</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-testing-junit-1.1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java =================================================================== --- trunk/openutils-testing-junit/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-05-04 16:49:46 UTC (rev 327) +++ tags/openutils-testing-junit-1.1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-05-23 18:05:56 UTC (rev 333) @@ -1,223 +0,0 @@ -/* - * Copyright 2005 Fabrizio Giustina. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.testing.junit; - -import java.io.InputStream; -import java.util.Map; - -import javax.sql.DataSource; - -import org.apache.commons.lang.ClassUtils; -import org.dbunit.database.DatabaseConnection; -import org.dbunit.database.DatabaseSequenceFilter; -import org.dbunit.database.IDatabaseConnection; -import org.dbunit.dataset.FilteredDataSet; -import org.dbunit.dataset.IDataSet; -import org.dbunit.dataset.excel.XlsDataSet; -import org.dbunit.dataset.filter.ITableFilter; -import org.dbunit.dataset.filter.SequenceTableFilter; -import org.dbunit.dataset.xml.XmlDataSet; -import org.dbunit.ext.mssql.InsertIdentityOperation; -import org.dbunit.operation.DatabaseOperation; -import org.hibernate.SessionFactory; -import org.springframework.orm.hibernate3.SessionFactoryUtils; - - -/** - * Base class for running DAO tests. - * @author fgiust - * @version $Revision $ ($Author $) - */ -public abstract class DbUnitTestCase extends SpringTestCase -{ - - /** - * Hibernate session factory. - */ - private SessionFactory sessionFactory; - - private static final String BASETEST_DELETE = "/_BaseDAOTest-delete.xml"; - - protected static IDataSet truncateDataSet; - - /** - * Should use deferred close emulating the spring OpenSessionInView filter? Default is <code>true</code> - * @return <code>true</code> if deferred close should be used - */ - protected boolean mimicSessionFilter() - { - return true; - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - @Override - protected void setUp() throws Exception - { - super.setUp(); - - // insert values - IDataSet dataSet = null; - - String datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xml"; - InputStream testData = getClass().getResourceAsStream(datesetFileName); - - if (testData != null) - { - if (log.isDebugEnabled()) - { - log.debug("loading dataset {}", datesetFileName); - } - - dataSet = new XmlDataSet(testData); - } - else - { - // check for excel - datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xls"; - testData = getClass().getResourceAsStream(datesetFileName); - - if (testData != null) - { - if (log.isDebugEnabled()) - { - log.debug("loading dataset {}", datesetFileName); - } - - dataSet = new XlsDataSet(testData); - } - } - - if (dataSet == null) - { - log.debug("No test data found with name [{}]", datesetFileName); - } - else - { - - DataSource dataSource = (DataSource) ctx.getBean("dataSource"); - IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); - - // truncate common tables - if (truncateDataSet == null) - { - log.debug("Generating sorted dataset for initial cleanup"); - IDataSet unsortedTruncateDataSet = connection.createDataSet(); - ITableFilter filter = new DatabaseSequenceFilter(connection); - truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet); - log.debug("Sorted dataset generated"); - } - - IDataSet orderedDataset = dataSet; - - // if a sorted dataset is available, use table sequence for sorting - if (truncateDataSet == null) - { - ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames()); - orderedDataset = new FilteredDataSet(filter, dataSet); - } - - try - { - if (truncateDataSet != null) - { - DatabaseOperation.DELETE_ALL.execute(connection, truncateDataSet); - } - if (dataSet != null) - { - InsertIdentityOperation.INSERT.execute(connection, orderedDataset); - } - } - finally - { - connection.close(); - } - } - - // mimic the Spring OpenSessionInViewFilter - if (mimicSessionFilter()) - { - Map<String, SessionFactory> sfbeans = ctx.getBeansOfType(SessionFactory.class); - if (sfbeans.isEmpty()) - { - fail("No bean of type org.hibernate.SessionFactory found in spring context"); - } - this.sessionFactory = sfbeans.get(sfbeans.keySet().iterator().next()); - - SessionFactoryUtils.initDeferredClose(this.sessionFactory); - } - - } - - /** - * {@inheritDoc} - */ - @Override - protected void tearDown() throws Exception - { - if (mimicSessionFilter()) - { - // close open hibernate sessions, mimic the OpenSessionInViewFilter - SessionFactoryUtils.processDeferredClose(this.sessionFactory); - } - - // regenerate db initial state - String datesetFileName = "/initial-load.xml"; - InputStream testData = getClass().getResourceAsStream(datesetFileName); - - if (testData != null) - { - log.debug("Restoring db state"); - - IDataSet dataSet = new XmlDataSet(testData); - - DataSource dataSource = (DataSource) ctx.getBean("dataSource"); - IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); - - try - { - DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet); - } - finally - { - connection.close(); - } - } - - super.tearDown(); - } - - /** - * Returns the full test name. - * @see junit.framework.TestCase#getName() - */ - @Override - public String getName() - { - return ClassUtils.getShortClassName(this.getClass()) + "::" + super.getName(); - } - - /** - * return the current Hibernate SessionFactory - * @return SessionFactory object - */ - protected SessionFactory getSessionFactory() - { - return sessionFactory; - } -} \ No newline at end of file Copied: tags/openutils-testing-junit-1.1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java (from rev 328, trunk/openutils-testing-junit/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java) =================================================================== --- tags/openutils-testing-junit-1.1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java (rev 0) +++ tags/openutils-testing-junit-1.1.1/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-05-23 18:05:56 UTC (rev 333) @@ -0,0 +1,251 @@ +/* + * Copyright 2005 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.testing.junit; + +import java.io.InputStream; +import java.util.Map; + +import javax.sql.DataSource; + +import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.StringUtils; +import org.dbunit.database.DatabaseConnection; +import org.dbunit.database.DatabaseSequenceFilter; +import org.dbunit.database.IDatabaseConnection; +import org.dbunit.dataset.DataSetException; +import org.dbunit.dataset.FilteredDataSet; +import org.dbunit.dataset.IDataSet; +import org.dbunit.dataset.excel.XlsDataSet; +import org.dbunit.dataset.filter.AbstractTableFilter; +import org.dbunit.dataset.filter.ITableFilter; +import org.dbunit.dataset.filter.SequenceTableFilter; +import org.dbunit.dataset.xml.XmlDataSet; +import org.dbunit.ext.mssql.InsertIdentityOperation; +import org.dbunit.operation.DatabaseOperation; +import org.hibernate.SessionFactory; +import org.springframework.orm.hibernate3.SessionFactoryUtils; + + +/** + * Base class for running DAO tests. + * @author fgiust + * @version $Revision $ ($Author $) + */ +public abstract class DbUnitTestCase extends SpringTestCase +{ + + /** + * Hibernate session factory. + */ + private SessionFactory sessionFactory; + + private static final String BASETEST_DELETE = "/_BaseDAOTest-delete.xml"; + + protected static IDataSet truncateDataSet; + + /** + * Should use deferred close emulating the spring OpenSessionInView filter? Default is <code>true</code> + * @return <code>true</code> if deferred close should be used + */ + protected boolean mimicSessionFilter() + { + return true; + } + + /** + * Returns the table filter that will be used to exclude certain tables from sort/deletion. This may be overridden + * by subclasses, and is needed when tables have circular references (not handled by dbunit DatabaseSequenceFilter) + * @return an <code>ITableFilter</code> + */ + protected ITableFilter getTableFilter() + { + return new AbstractTableFilter() + { + + @Override + public boolean isValidName(String tableName) throws DataSetException + { + // default excludes: + // $ = oracle recycle bin tables + // JBPM = jbpm tables, with circular references + return !StringUtils.contains(tableName, "$") && !StringUtils.contains(tableName, "JBPM"); + } + }; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + protected void setUp() throws Exception + { + super.setUp(); + + // insert values + IDataSet dataSet = null; + + String datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xml"; + InputStream testData = getClass().getResourceAsStream(datesetFileName); + + if (testData != null) + { + if (log.isDebugEnabled()) + { + log.debug("loading dataset {}", datesetFileName); + } + + dataSet = new XmlDataSet(testData); + } + else + { + // check for excel + datesetFileName = "/" + ClassUtils.getShortClassName(getClass()) + "-load.xls"; + testData = getClass().getResourceAsStream(datesetFileName); + + if (testData != null) + { + if (log.isDebugEnabled()) + { + log.debug("loading dataset {}", datesetFileName); + } + + dataSet = new XlsDataSet(testData); + } + } + + if (dataSet == null) + { + log.debug("No test data found with name [{}]", datesetFileName); + } + else + { + + DataSource dataSource = (DataSource) ctx.getBean("dataSource"); + IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); + + // truncate common tables + if (truncateDataSet == null) + { + log.debug("Generating sorted dataset for initial cleanup"); + IDataSet unsortedTruncateDataSet = connection.createDataSet(); + + ITableFilter filter = new DatabaseSequenceFilter(connection, new FilteredDataSet( + getTableFilter(), + unsortedTruncateDataSet).getTableNames()); + truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet); + truncateDataSet = new FilteredDataSet(getTableFilter(), truncateDataSet); + log.debug("Sorted dataset generated"); + } + + IDataSet orderedDataset = dataSet; + + // if a sorted dataset is available, use table sequence for sorting + if (truncateDataSet == null) + { + ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames()); + orderedDataset = new FilteredDataSet(filter, dataSet); + } + + try + { + if (truncateDataSet != null) + { + DatabaseOperation.DELETE_ALL.execute(connection, truncateDataSet); + } + if (dataSet != null) + { + InsertIdentityOperation.INSERT.execute(connection, orderedDataset); + } + } + finally + { + connection.close(); + } + } + + // mimic the Spring OpenSessionInViewFilter + if (mimicSessionFilter()) + { + Map<String, SessionFactory> sfbeans = ctx.getBeansOfType(SessionFactory.class); + if (sfbeans.isEmpty()) + { + fail("No bean of type org.hibernate.SessionFactory found in spring context"); + } + this.sessionFactory = sfbeans.get(sfbeans.keySet().iterator().next()); + + SessionFactoryUtils.initDeferredClose(this.sessionFactory); + } + + } + + /** + * {@inheritDoc} + */ + @Override + protected void tearDown() throws Exception + { + if (mimicSessionFilter()) + { + // close open hibernate sessions, mimic the OpenSessionInViewFilter + SessionFactoryUtils.processDeferredClose(this.sessionFactory); + } + + // regenerate db initial state + String datesetFileName = "/initial-load.xml"; + InputStream testData = getClass().getResourceAsStream(datesetFileName); + + if (testData != null) + { + log.debug("Restoring db state"); + + IDataSet dataSet = new XmlDataSet(testData); + + DataSource dataSource = (DataSource) ctx.getBean("dataSource"); + IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); + + try + { + DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet); + } + finally + { + connection.close(); + } + } + + super.tearDown(); + } + + /** + * Returns the full test name. + * @see junit.framework.TestCase#getName() + */ + @Override + public String getName() + { + return ClassUtils.getShortClassName(this.getClass()) + "::" + super.getName(); + } + + /** + * return the current Hibernate SessionFactory + * @return SessionFactory object + */ + protected SessionFactory getSessionFactory() + { + return sessionFactory; + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-05-23 18:05:45
|
Revision: 332 http://svn.sourceforge.net/openutils/?rev=332&view=rev Author: fgiust Date: 2007-05-23 11:05:47 -0700 (Wed, 23 May 2007) Log Message: ----------- [maven-release-plugin] prepare release openutils-testing-junit-1.1.1 Modified Paths: -------------- trunk/openutils-testing-junit/pom.xml Modified: trunk/openutils-testing-junit/pom.xml =================================================================== --- trunk/openutils-testing-junit/pom.xml 2007-05-23 18:04:11 UTC (rev 331) +++ trunk/openutils-testing-junit/pom.xml 2007-05-23 18:05:47 UTC (rev 332) @@ -8,7 +8,7 @@ </parent> <artifactId>openutils-testing-junit</artifactId> <name>openutils test utils (junit)</name> - <version>1.1.1-SNAPSHOT</version> + <version>1.1.1</version> <description>openutils test utils</description> <dependencies> <dependency> @@ -55,4 +55,10 @@ <version>3.8.1</version> </dependency> </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-1.1.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-junit-1.1.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-junit-1.1.1</url> + </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-05-23 18:04:10
|
Revision: 331 http://svn.sourceforge.net/openutils/?rev=331&view=rev Author: fgiust Date: 2007-05-23 11:04:11 -0700 (Wed, 23 May 2007) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/openutils-testing-testng/pom.xml Modified: trunk/openutils-testing-testng/pom.xml =================================================================== --- trunk/openutils-testing-testng/pom.xml 2007-05-23 18:04:05 UTC (rev 330) +++ trunk/openutils-testing-testng/pom.xml 2007-05-23 18:04:11 UTC (rev 331) @@ -8,7 +8,7 @@ </parent> <artifactId>openutils-testing-testng</artifactId> <name>openutils test utils (testng)</name> - <version>1.1.1</version> + <version>1.1.2-SNAPSHOT</version> <description>openutils test utils</description> <dependencies> <dependency> @@ -56,10 +56,4 @@ <version>5.1</version> </dependency> </dependencies> - - <scm> - <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-testng-1.1.1</connection> - <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-testng-1.1.1</developerConnection> - <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-testng-1.1.1</url> - </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-05-23 18:04:05
|
Revision: 330 http://svn.sourceforge.net/openutils/?rev=330&view=rev Author: fgiust Date: 2007-05-23 11:04:05 -0700 (Wed, 23 May 2007) Log Message: ----------- [maven-release-plugin] copy for tag openutils-testing-testng-1.1.1 Added Paths: ----------- tags/openutils-testing-testng-1.1.1/ tags/openutils-testing-testng-1.1.1/pom.xml tags/openutils-testing-testng-1.1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java Removed Paths: ------------- tags/openutils-testing-testng-1.1.1/pom.xml tags/openutils-testing-testng-1.1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java Copied: tags/openutils-testing-testng-1.1.1 (from rev 327, trunk/openutils-testing-testng) Deleted: tags/openutils-testing-testng-1.1.1/pom.xml =================================================================== --- trunk/openutils-testing-testng/pom.xml 2007-05-04 16:49:46 UTC (rev 327) +++ tags/openutils-testing-testng-1.1.1/pom.xml 2007-05-23 18:04:05 UTC (rev 330) @@ -1,59 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-testing-testng</artifactId> - <name>openutils test utils (testng)</name> - <version>1.1.1-SNAPSHOT</version> - <description>openutils test utils</description> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.2</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-hibernate3</artifactId> - <version>2.0.1</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> - <version>2.2</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.1</version> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-testing-testng-1.1.1/pom.xml (from rev 329, trunk/openutils-testing-testng/pom.xml) =================================================================== --- tags/openutils-testing-testng-1.1.1/pom.xml (rev 0) +++ tags/openutils-testing-testng-1.1.1/pom.xml 2007-05-23 18:04:05 UTC (rev 330) @@ -0,0 +1,65 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-testing-testng</artifactId> + <name>openutils test utils (testng)</name> + <version>1.1.1</version> + <description>openutils test utils</description> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-hibernate3</artifactId> + <version>2.0.1</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>org.dbunit</groupId> + <artifactId>dbunit</artifactId> + <version>2.2</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.1</version> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-testng-1.1.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-testng-1.1.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-testng-1.1.1</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-testing-testng-1.1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java =================================================================== --- trunk/openutils-testing-testng/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java 2007-05-04 16:49:46 UTC (rev 327) +++ tags/openutils-testing-testng-1.1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java 2007-05-23 18:04:05 UTC (rev 330) @@ -1,285 +0,0 @@ -/* - * Copyright 2005 Fabrizio Giustina. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package it.openutils.testing.testng; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.sql.SQLException; -import java.text.MessageFormat; -import java.util.Map; - -import javax.sql.DataSource; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.ClassUtils; -import org.apache.commons.lang.StringUtils; -import org.dbunit.DatabaseUnitException; -import org.dbunit.database.DatabaseConnection; -import org.dbunit.database.DatabaseSequenceFilter; -import org.dbunit.database.IDatabaseConnection; -import org.dbunit.dataset.DataSetException; -import org.dbunit.dataset.FilteredDataSet; -import org.dbunit.dataset.IDataSet; -import org.dbunit.dataset.excel.XlsDataSet; -import org.dbunit.dataset.filter.AbstractTableFilter; -import org.dbunit.dataset.filter.ITableFilter; -import org.dbunit.dataset.filter.SequenceTableFilter; -import org.dbunit.dataset.xml.XmlDataSet; -import org.dbunit.operation.DatabaseOperation; -import org.hibernate.SessionFactory; -import org.springframework.orm.hibernate3.SessionFactoryUtils; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - - -/** - * @author fgiust - * @version $Id$ - */ -@Test -public class DbUnitTestCase extends SpringTestCase -{ - - /** - * name for the dataSource bean in Spring context. - */ - private static final String DATASOURCE_BEAN_NAME = "dataSource"; - - /** - * Pattern for dbunit file loaded before a test. MessageFormat format with two placeholders: class name and - * extension. - */ - private static final String DATAFILE_PATTERN = "/{0}-load.{1}"; - - protected static IDataSet truncateDataSet; - - /** - * Hibernate session factory. - */ - private SessionFactory sessionFactory; - - /** - * Optional schema (needed for ORACLE). - * @return <code>null</code> - */ - protected String getSchema() - { - return null; - } - - /** - * Should use deferred close emulating the spring OpenSessionInView filter? Default is <code>true</code> - * @return <code>true</code> if deferred close should be used - */ - protected boolean mimicSessionFilter() - { - return true; - } - - /** - * Setup the Database before running the test method. - * @throws Exception Any exception. - */ - @SuppressWarnings("unchecked") - @BeforeMethod - protected void setUpDbUnit() throws Exception - { - // mimic the Spring OpenSessionInViewFilter - if (mimicSessionFilter()) - { - Map<String, SessionFactory> sfbeans = ctx.getBeansOfType(SessionFactory.class); - if (sfbeans.isEmpty()) - { - Assert.fail("No bean of type org.hibernate.SessionFactory found in spring context"); - } - this.sessionFactory = sfbeans.get(sfbeans.keySet().iterator().next()); - - SessionFactoryUtils.initDeferredClose(this.sessionFactory); - } - - // check for xml - IDataSet dataSet = loadDataSet(getDataFileName("xml")); - - if (dataSet == null) - { - // check for excel - dataSet = loadDataSet(getDataFileName("xls")); - } - - if (dataSet != null) - { - importDataSet(dataSet); - } - else - { - log.debug("No test data found with name [{}]", getDataFileName("xml/xls")); - } - } - - /** - * Exports a database to an Excel file - * @param fileName The file name we save the Excel dump to. - * @throws IOException An IO Exception. - * @throws DataSetException A dataset exception. - * @throws SQLException A SQL Exception. - */ - protected void exportDbToXls(String fileName) throws IOException, DataSetException, SQLException - { - IDatabaseConnection connection = getDbUnitConnection(); - - IDataSet fullDataSet = connection.createDataSet(); - - File outFile = new File(fileName); - OutputStream fos = new FileOutputStream(outFile); - XlsDataSet.write(fullDataSet, fos); - fos.close(); - } - - /** - * Cleans the database after we run the tests. - * @throws Exception Any exception. - */ - @AfterMethod - protected void tearDownDbUnit() throws Exception - { - if (mimicSessionFilter()) - { - // close open hibernate sessions, mimic the OpenSessionInViewFilter - SessionFactoryUtils.processDeferredClose(this.sessionFactory); - } - - // regenerate db initial state - String datesetFileName = "/initial-load.xml"; - InputStream testData = getClass().getResourceAsStream(datesetFileName); - - if (testData != null) - { - log.debug("Restoring db state"); - - IDataSet dataSet = new XmlDataSet(testData); - - IDatabaseConnection connection = getDbUnitConnection(); - - try - { - DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet); - } - finally - { - connection.close(); - } - } - } - - private void importDataSet(IDataSet dataSet) throws SQLException, DataSetException, DatabaseUnitException - { - IDatabaseConnection connection = getDbUnitConnection(); - - if (truncateDataSet == null) - { - log.debug("Generating sorted dataset for initial cleanup"); - IDataSet unsortedTruncateDataSet = connection.createDataSet(); - - ITableFilter filter = new DatabaseSequenceFilter(connection); - truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet); - - truncateDataSet = new FilteredDataSet(new AbstractTableFilter() - { - - @Override - public boolean isValidName(String tableName) throws DataSetException - { - return !StringUtils.contains(tableName, "$"); - } - }, truncateDataSet); - - log.debug("Sorted dataset generated"); - } - - IDataSet orderedDataset = new FilteredDataSet(new AbstractTableFilter() - { - - @Override - public boolean isValidName(String tableName) throws DataSetException - { - return !StringUtils.contains(tableName, "$"); - } - }, dataSet); - - log.debug("Tables: {}", ArrayUtils.toString(orderedDataset.getTableNames())); - log.debug("Tables truncateDataSet: {}", ArrayUtils.toString(truncateDataSet.getTableNames())); - - // if a sorted dataset is available, use table sequence for sorting - if (truncateDataSet != null) - { - ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames()); - orderedDataset = new FilteredDataSet(filter, dataSet); - } - - try - { - - if (truncateDataSet != null) - { - DatabaseOperation.DELETE_ALL.execute(connection, truncateDataSet); - } - if (dataSet != null) - { - DatabaseOperation.INSERT.execute(connection, orderedDataset); - } - } - finally - { - connection.close(); - } - } - - /** - * @return - * @throws SQLException - */ - private IDatabaseConnection getDbUnitConnection() throws SQLException - { - DataSource dataSource = (DataSource) ctx.getBean(DATASOURCE_BEAN_NAME); - IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection(), getSchema()); - return connection; - } - - private String getDataFileName(String extension) - { - return MessageFormat.format(DATAFILE_PATTERN, ClassUtils.getShortClassName(getClass()), extension); - } - - private IDataSet loadDataSet(String datesetFile) throws IOException, DataSetException - { - InputStream is = getClass().getResourceAsStream(datesetFile); - IDataSet dataSet = null; - - if (is != null) - { - log.debug("loading dataset {}", datesetFile); - dataSet = datesetFile.endsWith(".xls") ? new XlsDataSet(is) : new XmlDataSet(is); - is.close(); - } - - return dataSet; - } -} Copied: tags/openutils-testing-testng-1.1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java (from rev 328, trunk/openutils-testing-testng/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java) =================================================================== --- tags/openutils-testing-testng-1.1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java (rev 0) +++ tags/openutils-testing-testng-1.1.1/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java 2007-05-23 18:04:05 UTC (rev 330) @@ -0,0 +1,298 @@ +/* + * Copyright 2005 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.openutils.testing.testng; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.sql.SQLException; +import java.text.MessageFormat; +import java.util.Map; + +import javax.sql.DataSource; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.StringUtils; +import org.dbunit.DatabaseUnitException; +import org.dbunit.database.DatabaseConnection; +import org.dbunit.database.DatabaseSequenceFilter; +import org.dbunit.database.IDatabaseConnection; +import org.dbunit.dataset.DataSetException; +import org.dbunit.dataset.FilteredDataSet; +import org.dbunit.dataset.IDataSet; +import org.dbunit.dataset.excel.XlsDataSet; +import org.dbunit.dataset.filter.AbstractTableFilter; +import org.dbunit.dataset.filter.ITableFilter; +import org.dbunit.dataset.filter.SequenceTableFilter; +import org.dbunit.dataset.xml.XmlDataSet; +import org.dbunit.operation.DatabaseOperation; +import org.hibernate.SessionFactory; +import org.springframework.orm.hibernate3.SessionFactoryUtils; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + + +/** + * @author fgiust + * @version $Id$ + */ +@Test +public class DbUnitTestCase extends SpringTestCase +{ + + /** + * name for the dataSource bean in Spring context. + */ + private static final String DATASOURCE_BEAN_NAME = "dataSource"; + + /** + * Pattern for dbunit file loaded before a test. MessageFormat format with two placeholders: class name and + * extension. + */ + private static final String DATAFILE_PATTERN = "/{0}-load.{1}"; + + protected static IDataSet truncateDataSet; + + /** + * Hibernate session factory. + */ + private SessionFactory sessionFactory; + + /** + * Optional schema (needed for ORACLE). + * @return <code>null</code> + */ + protected String getSchema() + { + return null; + } + + /** + * Should use deferred close emulating the spring OpenSessionInView filter? Default is <code>true</code> + * @return <code>true</code> if deferred close should be used + */ + protected boolean mimicSessionFilter() + { + return true; + } + + /** + * Returns the table filter that will be used to exclude certain tables from sort/deletion. This may be overridden + * by subclasses, and is needed when tables have circular references (not handled by dbunit DatabaseSequenceFilter) + * @return an <code>ITableFilter</code> + */ + protected ITableFilter getTableFilter() + { + return new AbstractTableFilter() + { + + @Override + public boolean isValidName(String tableName) throws DataSetException + { + // default excludes: + // $ = oracle recycle bin tables + // JBPM = jbpm tables, with circular references + return !StringUtils.contains(tableName, "$") && !StringUtils.contains(tableName, "JBPM"); + } + }; + } + + /** + * Setup the Database before running the test method. + * @throws Exception Any exception. + */ + @SuppressWarnings("unchecked") + @BeforeMethod + protected void setUpDbUnit() throws Exception + { + // mimic the Spring OpenSessionInViewFilter + if (mimicSessionFilter()) + { + Map<String, SessionFactory> sfbeans = ctx.getBeansOfType(SessionFactory.class); + if (sfbeans.isEmpty()) + { + Assert.fail("No bean of type org.hibernate.SessionFactory found in spring context"); + } + this.sessionFactory = sfbeans.get(sfbeans.keySet().iterator().next()); + + SessionFactoryUtils.initDeferredClose(this.sessionFactory); + } + + // check for xml + IDataSet dataSet = loadDataSet(getDataFileName("xml")); + + if (dataSet == null) + { + // check for excel + dataSet = loadDataSet(getDataFileName("xls")); + } + + if (dataSet != null) + { + importDataSet(dataSet); + } + else + { + log.debug("No test data found with name [{}]", getDataFileName("xml/xls")); + } + } + + /** + * Exports a database to an Excel file + * @param fileName The file name we save the Excel dump to. + * @throws IOException An IO Exception. + * @throws DataSetException A dataset exception. + * @throws SQLException A SQL Exception. + */ + protected void exportDbToXls(String fileName) throws IOException, DataSetException, SQLException + { + IDatabaseConnection connection = getDbUnitConnection(); + + IDataSet fullDataSet = connection.createDataSet(); + + File outFile = new File(fileName); + OutputStream fos = new FileOutputStream(outFile); + XlsDataSet.write(fullDataSet, fos); + fos.close(); + } + + /** + * Cleans the database after we run the tests. + * @throws Exception Any exception. + */ + @AfterMethod + protected void tearDownDbUnit() throws Exception + { + if (mimicSessionFilter()) + { + // close open hibernate sessions, mimic the OpenSessionInViewFilter + SessionFactoryUtils.processDeferredClose(this.sessionFactory); + } + + // regenerate db initial state + String datesetFileName = "/initial-load.xml"; + InputStream testData = getClass().getResourceAsStream(datesetFileName); + + if (testData != null) + { + log.debug("Restoring db state"); + + IDataSet dataSet = new XmlDataSet(testData); + + IDatabaseConnection connection = getDbUnitConnection(); + + try + { + DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet); + } + finally + { + connection.close(); + } + } + } + + private void importDataSet(IDataSet dataSet) throws SQLException, DataSetException, DatabaseUnitException + { + IDatabaseConnection connection = getDbUnitConnection(); + + if (truncateDataSet == null) + { + log.debug("Generating sorted dataset for initial cleanup"); + IDataSet unsortedTruncateDataSet = connection.createDataSet(); + + ITableFilter filter = new DatabaseSequenceFilter(connection, new FilteredDataSet( + getTableFilter(), + unsortedTruncateDataSet).getTableNames()); + truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet); + truncateDataSet = new FilteredDataSet(getTableFilter(), truncateDataSet); + log.debug("Sorted dataset generated"); + } + + IDataSet orderedDataset = new FilteredDataSet(new AbstractTableFilter() + { + + @Override + public boolean isValidName(String tableName) throws DataSetException + { + return !StringUtils.contains(tableName, "$"); + } + }, dataSet); + + log.debug("Tables: {}", ArrayUtils.toString(orderedDataset.getTableNames())); + log.debug("Tables truncateDataSet: {}", ArrayUtils.toString(truncateDataSet.getTableNames())); + + // if a sorted dataset is available, use table sequence for sorting + if (truncateDataSet != null) + { + ITableFilter filter = new SequenceTableFilter(truncateDataSet.getTableNames()); + orderedDataset = new FilteredDataSet(filter, dataSet); + } + + try + { + + if (truncateDataSet != null) + { + DatabaseOperation.DELETE_ALL.execute(connection, truncateDataSet); + } + if (dataSet != null) + { + DatabaseOperation.INSERT.execute(connection, orderedDataset); + } + } + finally + { + connection.close(); + } + } + + /** + * @return + * @throws SQLException + */ + private IDatabaseConnection getDbUnitConnection() throws SQLException + { + DataSource dataSource = (DataSource) ctx.getBean(DATASOURCE_BEAN_NAME); + IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection(), getSchema()); + return connection; + } + + private String getDataFileName(String extension) + { + return MessageFormat.format(DATAFILE_PATTERN, ClassUtils.getShortClassName(getClass()), extension); + } + + private IDataSet loadDataSet(String datesetFile) throws IOException, DataSetException + { + InputStream is = getClass().getResourceAsStream(datesetFile); + IDataSet dataSet = null; + + if (is != null) + { + log.debug("loading dataset {}", datesetFile); + dataSet = datesetFile.endsWith(".xls") ? new XlsDataSet(is) : new XmlDataSet(is); + is.close(); + } + + return dataSet; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-05-23 18:03:47
|
Revision: 329 http://svn.sourceforge.net/openutils/?rev=329&view=rev Author: fgiust Date: 2007-05-23 11:03:48 -0700 (Wed, 23 May 2007) Log Message: ----------- test commit Modified Paths: -------------- trunk/openutils-testing-testng/pom.xml Modified: trunk/openutils-testing-testng/pom.xml =================================================================== --- trunk/openutils-testing-testng/pom.xml 2007-05-23 17:59:52 UTC (rev 328) +++ trunk/openutils-testing-testng/pom.xml 2007-05-23 18:03:48 UTC (rev 329) @@ -8,7 +8,7 @@ </parent> <artifactId>openutils-testing-testng</artifactId> <name>openutils test utils (testng)</name> - <version>1.1.1-SNAPSHOT</version> + <version>1.1.1</version> <description>openutils test utils</description> <dependencies> <dependency> @@ -56,4 +56,10 @@ <version>5.1</version> </dependency> </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-testng-1.1.1</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-testing-testng-1.1.1</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-testing-testng-1.1.1</url> + </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-05-23 17:59:53
|
Revision: 328 http://svn.sourceforge.net/openutils/?rev=328&view=rev Author: fgiust Date: 2007-05-23 10:59:52 -0700 (Wed, 23 May 2007) Log Message: ----------- make default table filter overridable Modified Paths: -------------- trunk/openutils-testing-junit/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java trunk/openutils-testing-testng/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java Modified: trunk/openutils-testing-junit/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java =================================================================== --- trunk/openutils-testing-junit/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-05-04 16:49:46 UTC (rev 327) +++ trunk/openutils-testing-junit/src/main/java/it/openutils/testing/junit/DbUnitTestCase.java 2007-05-23 17:59:52 UTC (rev 328) @@ -21,12 +21,15 @@ import javax.sql.DataSource; import org.apache.commons.lang.ClassUtils; +import org.apache.commons.lang.StringUtils; import org.dbunit.database.DatabaseConnection; import org.dbunit.database.DatabaseSequenceFilter; import org.dbunit.database.IDatabaseConnection; +import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.FilteredDataSet; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.excel.XlsDataSet; +import org.dbunit.dataset.filter.AbstractTableFilter; import org.dbunit.dataset.filter.ITableFilter; import org.dbunit.dataset.filter.SequenceTableFilter; import org.dbunit.dataset.xml.XmlDataSet; @@ -63,6 +66,27 @@ } /** + * Returns the table filter that will be used to exclude certain tables from sort/deletion. This may be overridden + * by subclasses, and is needed when tables have circular references (not handled by dbunit DatabaseSequenceFilter) + * @return an <code>ITableFilter</code> + */ + protected ITableFilter getTableFilter() + { + return new AbstractTableFilter() + { + + @Override + public boolean isValidName(String tableName) throws DataSetException + { + // default excludes: + // $ = oracle recycle bin tables + // JBPM = jbpm tables, with circular references + return !StringUtils.contains(tableName, "$") && !StringUtils.contains(tableName, "JBPM"); + } + }; + } + + /** * {@inheritDoc} */ @SuppressWarnings("unchecked") @@ -118,8 +142,12 @@ { log.debug("Generating sorted dataset for initial cleanup"); IDataSet unsortedTruncateDataSet = connection.createDataSet(); - ITableFilter filter = new DatabaseSequenceFilter(connection); + + ITableFilter filter = new DatabaseSequenceFilter(connection, new FilteredDataSet( + getTableFilter(), + unsortedTruncateDataSet).getTableNames()); truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet); + truncateDataSet = new FilteredDataSet(getTableFilter(), truncateDataSet); log.debug("Sorted dataset generated"); } Modified: trunk/openutils-testing-testng/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java =================================================================== --- trunk/openutils-testing-testng/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java 2007-05-04 16:49:46 UTC (rev 327) +++ trunk/openutils-testing-testng/src/main/java/it/openutils/testing/testng/DbUnitTestCase.java 2007-05-23 17:59:52 UTC (rev 328) @@ -95,6 +95,27 @@ } /** + * Returns the table filter that will be used to exclude certain tables from sort/deletion. This may be overridden + * by subclasses, and is needed when tables have circular references (not handled by dbunit DatabaseSequenceFilter) + * @return an <code>ITableFilter</code> + */ + protected ITableFilter getTableFilter() + { + return new AbstractTableFilter() + { + + @Override + public boolean isValidName(String tableName) throws DataSetException + { + // default excludes: + // $ = oracle recycle bin tables + // JBPM = jbpm tables, with circular references + return !StringUtils.contains(tableName, "$") && !StringUtils.contains(tableName, "JBPM"); + } + }; + } + + /** * Setup the Database before running the test method. * @throws Exception Any exception. */ @@ -198,19 +219,11 @@ log.debug("Generating sorted dataset for initial cleanup"); IDataSet unsortedTruncateDataSet = connection.createDataSet(); - ITableFilter filter = new DatabaseSequenceFilter(connection); + ITableFilter filter = new DatabaseSequenceFilter(connection, new FilteredDataSet( + getTableFilter(), + unsortedTruncateDataSet).getTableNames()); truncateDataSet = new FilteredDataSet(filter, unsortedTruncateDataSet); - - truncateDataSet = new FilteredDataSet(new AbstractTableFilter() - { - - @Override - public boolean isValidName(String tableName) throws DataSetException - { - return !StringUtils.contains(tableName, "$"); - } - }, truncateDataSet); - + truncateDataSet = new FilteredDataSet(getTableFilter(), truncateDataSet); log.debug("Sorted dataset generated"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-05-04 16:56:00
|
Revision: 327 http://svn.sourceforge.net/openutils/?rev=327&view=rev Author: fgiust Date: 2007-05-04 09:49:46 -0700 (Fri, 04 May 2007) Log Message: ----------- updateEnabled property added Modified Paths: -------------- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java Modified: trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-04-04 11:12:36 UTC (rev 326) +++ trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-05-04 16:49:46 UTC (rev 327) @@ -53,6 +53,12 @@ private Map<String, ExcelConfigurationTask.QueryConfig> config; /** + * If true, when a record already exists and an updated query is defined it will be updated. Set it to false to only + * insert new records. + */ + private boolean updateEnabled = true; + + /** * Sets the script. * @param script the script to set */ @@ -71,6 +77,15 @@ } /** + * Sets the updateEnabled. + * @param updateEnabled the updateEnabled to set + */ + public void setUpdateEnabled(boolean updateEnabled) + { + this.updateEnabled = updateEnabled; + } + + /** * {@inheritDoc} */ public void execute(DataSource dataSource) @@ -316,7 +331,9 @@ continue; } } - else if (StringUtils.isNotBlank(updateStatement) && StringUtils.isNotBlank(selectStatement)) + else if (updateEnabled + && StringUtils.isNotBlank(updateStatement) + && StringUtils.isNotBlank(selectStatement)) { try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-03-11 21:47:11
|
Revision: 322 http://svn.sourceforge.net/openutils/?rev=322&view=rev Author: fgiust Date: 2007-03-11 14:47:12 -0700 (Sun, 11 Mar 2007) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/openutils-dbmigration/pom.xml Modified: trunk/openutils-dbmigration/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2007-03-11 21:47:06 UTC (rev 321) +++ trunk/openutils-dbmigration/pom.xml 2007-03-11 21:47:12 UTC (rev 322) @@ -8,7 +8,7 @@ </parent> <artifactId>openutils-dbmigration</artifactId> <name>openutils db migration framework</name> - <version>0.5</version> + <version>0.6-SNAPSHOT</version> <description /> <dependencies> <dependency> @@ -84,10 +84,4 @@ <scope>test</scope> </dependency> </dependencies> - - <scm> - <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.5</connection> - <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.5</developerConnection> - <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-0.5</url> - </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-03-11 21:47:07
|
Revision: 321 http://svn.sourceforge.net/openutils/?rev=321&view=rev Author: fgiust Date: 2007-03-11 14:47:06 -0700 (Sun, 11 Mar 2007) Log Message: ----------- [maven-scm] copy for tag openutils-dbmigration-0.5 Added Paths: ----------- tags/openutils-dbmigration-0.5/ tags/openutils-dbmigration-0.5/pom.xml tags/openutils-dbmigration-0.5/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java Removed Paths: ------------- tags/openutils-dbmigration-0.5/pom.xml tags/openutils-dbmigration-0.5/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java Copied: tags/openutils-dbmigration-0.5 (from rev 314, trunk/openutils-dbmigration) Deleted: tags/openutils-dbmigration-0.5/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2007-03-05 10:59:55 UTC (rev 314) +++ tags/openutils-dbmigration-0.5/pom.xml 2007-03-11 21:47:06 UTC (rev 321) @@ -1,87 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-dbmigration</artifactId> - <name>openutils db migration framework</name> - <version>0.4-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.2</version> - </dependency> - <dependency> - <groupId>poi</groupId> - <artifactId>poi</artifactId> - <version>2.5.1-final-20040804</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.0</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-dbmigration-0.5/pom.xml (from rev 320, trunk/openutils-dbmigration/pom.xml) =================================================================== --- tags/openutils-dbmigration-0.5/pom.xml (rev 0) +++ tags/openutils-dbmigration-0.5/pom.xml 2007-03-11 21:47:06 UTC (rev 321) @@ -0,0 +1,93 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-dbmigration</artifactId> + <name>openutils db migration framework</name> + <version>0.5</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>poi</groupId> + <artifactId>poi</artifactId> + <version>2.5.1-final-20040804</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.0</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.5</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.5</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-0.5</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-dbmigration-0.5/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-03-05 10:59:55 UTC (rev 314) +++ tags/openutils-dbmigration-0.5/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-03-11 21:47:06 UTC (rev 321) @@ -1,359 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.migration.task.setup; - -import java.io.IOException; -import java.io.InputStream; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.sql.DataSource; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.poi.hssf.usermodel.HSSFCell; -import org.apache.poi.hssf.usermodel.HSSFRow; -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; -import org.springframework.dao.DataAccessException; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.jdbc.BadSqlGrammarException; -import org.springframework.jdbc.core.ConnectionCallback; -import org.springframework.jdbc.core.JdbcTemplate; - - -/** - * @author fgiust - * @version $Id$ - */ -public class ExcelConfigurationTask extends BaseDbTask implements DbTask -{ - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(ScriptBasedUnconditionalTask.class); - - private Resource script; - - private Map<String, ExcelConfigurationTask.QueryConfig> config; - - /** - * Sets the script. - * @param script the script to set - */ - public void setScript(Resource script) - { - this.script = script; - } - - /** - * Sets the config. - * @param config the config to set - */ - public void setConfig(Map<String, ExcelConfigurationTask.QueryConfig> config) - { - this.config = config; - } - - /** - * {@inheritDoc} - */ - public void execute(DataSource dataSource) - { - if (script == null || !script.exists()) - { - log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); - return; - } - - InputStream is = null; - try - { - is = script.getInputStream(); - POIFSFileSystem fs = new POIFSFileSystem(is); - HSSFWorkbook hssfworkbook = new HSSFWorkbook(fs); - int sheetNums = hssfworkbook.getNumberOfSheets(); - for (int j = 0; j < sheetNums; j++) - { - HSSFSheet sheet = hssfworkbook.getSheetAt(j); - String tableName = hssfworkbook.getSheetName(j); - - QueryConfig conf = config.get(tableName); - if (conf == null) - { - log.error("Unable to handle table {}", tableName); - continue; - } - processSheet(sheet, tableName, conf, dataSource); - - } - - } - catch (IOException e) - { - log.error(e.getMessage(), e); - } - finally - { - IOUtils.closeQuietly(is); - } - - } - - /** - * @param sheet - * @param tableName - */ - private void processSheet(HSSFSheet sheet, final String tableName, QueryConfig con, DataSource dataSource) - { - final List<String> columns = new ArrayList<String>(); - - HSSFRow row = sheet.getRow(0); - for (short k = 0; k < row.getLastCellNum(); k++) - { - HSSFCell cell = row.getCell(k); - if (cell != null) - { - String columnName = cell.getStringCellValue(); - if (StringUtils.isNotBlank(columnName)) - { - columns.add(StringUtils.trim(columnName)); - } - else - { - break; - } - } - } - - log.debug("Table: {}, Columns: {}", tableName, columns); - - final List<Integer> types = new ArrayList<Integer>(); - - boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() - { - - public Object doInConnection(Connection con) throws SQLException, DataAccessException - { - for (String column : columns) - { - ResultSet res = con.getMetaData().getColumns(null, null, tableName, column); - if (res.next()) - { - types.add(res.getInt("DATA_TYPE")); - } - else - { - log.warn("Unable to determine type for column '{}' in table '{}'", column, tableName); - return false; - } - res.close(); - } - return true; - } - }); - - if (!result) - { - log.warn("Skipping sheet {} ", tableName); - } - - String checkStatement = StringUtils.remove(StringUtils.trim(con.getCheckQuery()), "\n"); - String insertStatement = StringUtils.remove(StringUtils.trim(con.getInsertQuery()), "\n"); - - processRecords( - sheet, - columns, - ArrayUtils.toPrimitive(types.toArray(new Integer[types.size()]), Types.NULL), - checkStatement, - insertStatement, - dataSource, - tableName); - } - - /** - * @param sheet - * @param columns - * @param checkStatement - * @param insertStatement - */ - private void processRecords(HSSFSheet sheet, List<String> columns, int[] types, String checkStatement, - String insertStatement, DataSource dataSource, String tableName) - { - JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); - int checkNum = StringUtils.countMatches(checkStatement, "?"); - int insertNum = StringUtils.countMatches(insertStatement, "?"); - - HSSFRow row; - for (short rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) - { - row = sheet.getRow(rowNum); - if (row == null) - { - return; - } - - List<String> values = new ArrayList<String>(); - - for (short k = 0; k < columns.size() && k <= row.getLastCellNum(); k++) - { - HSSFCell cell = row.getCell(k); - String value = null; - - if (cell == null) - { - value = StringUtils.EMPTY; - } - else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) - { - value = cell.getStringCellValue(); - } - else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) - { - double valueDouble = cell.getNumericCellValue(); - // when need to really check if it is a double or an int - double fraction = valueDouble % 1; - if (fraction == 0) - { - value = Integer.toString((int) valueDouble); - } - else - { - value = Double.toString(valueDouble); - } - } - - if (StringUtils.isEmpty(value)) - { - value = StringUtils.EMPTY; - } - - if ("<NULL>".equalsIgnoreCase(value)) - { - value = null; - } - - values.add(value); - } - - Object[] checkParams = ArrayUtils.subarray(values.toArray(), 0, checkNum); - for (int i = 0; i < checkParams.length; i++) - { - if (StringUtils.isEmpty((String) checkParams[i])) - { - return; - } - } - - int existing; - try - { - existing = jdbcTemplate.queryForInt(checkStatement, checkParams); - } - catch (BadSqlGrammarException bsge) - { - log.error("Error executing check query, current sheet will be skipped. {} Query in error: {}", bsge - .getMessage(), checkStatement); - return; - } - - if (existing == 0) - { - Object[] insertParams = ArrayUtils.subarray(values.toArray(), 0, insertNum); - int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); - if (log.isDebugEnabled()) - { - log.debug("Missing record with key {}; inserting {}", ArrayUtils.toString(checkParams), ArrayUtils - .toString(insertParams)); - } - - if (insertParams.length != insertTypes.length) - { - log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ - tableName, - insertParams.length, - insertTypes.length }); - } - - try - { - jdbcTemplate.update(insertStatement, insertParams, insertTypes); - } - catch (DataIntegrityViolationException bsge) - { - log - .error( - "Error executing insert, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", - new Object[]{ - tableName, - rowNum + 1, - insertStatement, - ArrayUtils.toString(insertParams), - bsge.getMessage() }); - continue; - } - } - - } - } - - /** - * @author fgiust - * @version $Id$ - */ - public static class QueryConfig - { - - private String checkQuery; - - private String insertQuery; - - /** - * Returns the checkQuery. - * @return the checkQuery - */ - public String getCheckQuery() - { - return checkQuery; - } - - /** - * Sets the checkQuery. - * @param checkQuery the checkQuery to set - */ - public void setCheckQuery(String checkQuery) - { - this.checkQuery = checkQuery; - } - - /** - * Returns the insertQuery. - * @return the insertQuery - */ - public String getInsertQuery() - { - return insertQuery; - } - - /** - * Sets the insertQuery. - * @param insertQuery the insertQuery to set - */ - public void setInsertQuery(String insertQuery) - { - this.insertQuery = insertQuery; - } - } -} Copied: tags/openutils-dbmigration-0.5/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java (from rev 319, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java) =================================================================== --- tags/openutils-dbmigration-0.5/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java (rev 0) +++ tags/openutils-dbmigration-0.5/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-03-11 21:47:06 UTC (rev 321) @@ -0,0 +1,494 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.migration.task.setup; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.sql.DataSource; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.Resource; +import org.springframework.dao.DataAccessException; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.jdbc.BadSqlGrammarException; +import org.springframework.jdbc.core.ColumnMapRowMapper; +import org.springframework.jdbc.core.ConnectionCallback; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + + +/** + * @author fgiust + * @version $Id$ + */ +public class ExcelConfigurationTask extends BaseDbTask implements DbTask +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(ScriptBasedUnconditionalTask.class); + + private Resource script; + + private Map<String, ExcelConfigurationTask.QueryConfig> config; + + /** + * Sets the script. + * @param script the script to set + */ + public void setScript(Resource script) + { + this.script = script; + } + + /** + * Sets the config. + * @param config the config to set + */ + public void setConfig(Map<String, ExcelConfigurationTask.QueryConfig> config) + { + this.config = config; + } + + /** + * {@inheritDoc} + */ + public void execute(DataSource dataSource) + { + if (script == null || !script.exists()) + { + log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); + return; + } + + InputStream is = null; + try + { + is = script.getInputStream(); + POIFSFileSystem fs = new POIFSFileSystem(is); + HSSFWorkbook hssfworkbook = new HSSFWorkbook(fs); + int sheetNums = hssfworkbook.getNumberOfSheets(); + for (int j = 0; j < sheetNums; j++) + { + HSSFSheet sheet = hssfworkbook.getSheetAt(j); + String tableName = hssfworkbook.getSheetName(j); + + QueryConfig conf = config.get(tableName); + if (conf == null) + { + log.error("Unable to handle table {}", tableName); + continue; + } + processSheet(sheet, tableName, conf, dataSource); + + } + + } + catch (IOException e) + { + log.error(e.getMessage(), e); + } + finally + { + IOUtils.closeQuietly(is); + } + + } + + /** + * @param sheet + * @param tableName + */ + private void processSheet(HSSFSheet sheet, final String tableName, QueryConfig con, DataSource dataSource) + { + final List<String> columns = new ArrayList<String>(); + + HSSFRow row = sheet.getRow(0); + for (short k = 0; k < row.getLastCellNum(); k++) + { + HSSFCell cell = row.getCell(k); + if (cell != null) + { + String columnName = cell.getStringCellValue(); + if (StringUtils.isNotBlank(columnName)) + { + columns.add(StringUtils.trim(columnName)); + } + else + { + break; + } + } + } + + log.debug("Table: {}, Columns: {}", tableName, columns); + + final List<Integer> types = new ArrayList<Integer>(); + + boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() + { + + public Object doInConnection(Connection con) throws SQLException, DataAccessException + { + for (String column : columns) + { + ResultSet res = con.getMetaData().getColumns(null, null, tableName, column); + if (res.next()) + { + types.add(res.getInt("DATA_TYPE")); + } + else + { + log.warn("Unable to determine type for column '{}' in table '{}'", column, tableName); + return false; + } + res.close(); + } + return true; + } + }); + + if (!result) + { + log.warn("Skipping sheet {} ", tableName); + } + + String checkStatement = StringUtils.remove(StringUtils.trim(con.getCheckQuery()), "\n"); + String insertStatement = StringUtils.remove(StringUtils.trim(con.getInsertQuery()), "\n"); + String selectStatement = StringUtils.remove(StringUtils.trim(con.getSelectQuery()), "\n"); + String updateStatement = StringUtils.remove(StringUtils.trim(con.getUpdateQuery()), "\n"); + + processRecords( + sheet, + columns, + ArrayUtils.toPrimitive(types.toArray(new Integer[types.size()]), Types.NULL), + checkStatement, + insertStatement, + selectStatement, + updateStatement, + dataSource, + tableName); + } + + /** + * @param sheet + * @param columns + * @param checkStatement + * @param insertStatement + * @param updateStatement + * @param selectStatement + */ + private void processRecords(HSSFSheet sheet, List<String> columns, int[] types, String checkStatement, + String insertStatement, String selectStatement, String updateStatement, DataSource dataSource, String tableName) + { + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + int checkNum = StringUtils.countMatches(checkStatement, "?"); + int insertNum = StringUtils.countMatches(insertStatement, "?"); + int selectNum = StringUtils.countMatches(selectStatement, "?"); + int updateNum = StringUtils.countMatches(updateStatement, "?"); + + HSSFRow row; + for (short rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) + { + row = sheet.getRow(rowNum); + if (row == null) + { + return; + } + + List<String> values = new ArrayList<String>(); + + for (short k = 0; k < columns.size() && k <= row.getLastCellNum(); k++) + { + HSSFCell cell = row.getCell(k); + String value = null; + + if (cell == null) + { + value = StringUtils.EMPTY; + } + else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) + { + value = cell.getStringCellValue(); + } + else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) + { + double valueDouble = cell.getNumericCellValue(); + // when need to really check if it is a double or an int + double fraction = valueDouble % 1; + if (fraction == 0) + { + value = Integer.toString((int) valueDouble); + } + else + { + value = Double.toString(valueDouble); + } + } + + if (StringUtils.isEmpty(value)) + { + value = StringUtils.EMPTY; + } + + if ("<NULL>".equalsIgnoreCase(value)) + { + value = null; + } + + values.add(value); + } + + Object[] checkParams = ArrayUtils.subarray(values.toArray(), 0, checkNum); + for (int i = 0; i < checkParams.length; i++) + { + if (StringUtils.isEmpty((String) checkParams[i])) + { + return; + } + } + + int existing; + try + { + existing = jdbcTemplate.queryForInt(checkStatement, checkParams); + } + catch (BadSqlGrammarException bsge) + { + log.error("Error executing check query, current sheet will be skipped. {} Query in error: {}", bsge + .getMessage(), checkStatement); + return; + } + + if (existing == 0) + { + Object[] insertParams = ArrayUtils.subarray(values.toArray(), 0, insertNum); + int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); + if (log.isDebugEnabled()) + { + log.debug("Missing record with key {}; inserting {}", ArrayUtils.toString(checkParams), ArrayUtils + .toString(insertParams)); + } + + if (insertParams.length != insertTypes.length) + { + log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ + tableName, + insertParams.length, + insertTypes.length }); + } + + try + { + jdbcTemplate.update(insertStatement, insertParams, insertTypes); + } + catch (DataIntegrityViolationException bsge) + { + log + .error( + "Error executing update, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", + new Object[]{ + tableName, + rowNum + 1, + insertStatement, + ArrayUtils.toString(insertParams), + bsge.getMessage() }); + continue; + } + } + else if (StringUtils.isNotBlank(updateStatement) && StringUtils.isNotBlank(selectStatement)) + { + try + { + RowMapper rowMapper = new ColumnMapRowMapper(); + Object[] selectParams = ArrayUtils.subarray(values.toArray(), 0, selectNum); + List selectResult = jdbcTemplate.query(selectStatement, selectParams, rowMapper); + Map<String, Object> fetchedColumns = (Map<String, Object>) selectResult.get(0); + int i = 0; + boolean updateNeeded = false; + for (String columnName : columns) + { + Object columnObject = fetchedColumns.get(columnName); + if (columnObject == null) + { + continue; + } + String columnValue = ObjectUtils.toString(fetchedColumns.get(columnName)); + if (!StringUtils.equals(columnValue, values.get(i))) + { + updateNeeded = true; + break; + } + i++; + } + if (updateNeeded) + { + Object[] updateParams = ArrayUtils.subarray(values.toArray(), 0, updateNum); + int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); + if (log.isDebugEnabled()) + { + log.debug( + "Missing record with key {}; updating {}", + ArrayUtils.toString(checkParams), + ArrayUtils.toString(updateParams)); + } + + if (updateParams.length != insertTypes.length) + { + log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ + tableName, + updateParams.length, + insertTypes.length }); + } + + try + { + Object[] compoundUpdateParams = new Object[checkParams.length + updateParams.length]; + System.arraycopy(updateParams, 0, compoundUpdateParams, 0, updateParams.length); + System.arraycopy( + checkParams, + 0, + compoundUpdateParams, + compoundUpdateParams.length - 1, + checkParams.length); + jdbcTemplate.update(updateStatement, compoundUpdateParams); + } + catch (DataIntegrityViolationException bsge) + { + log + .error( + "Error executing insert, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", + new Object[]{ + tableName, + rowNum + 1, + insertStatement, + ArrayUtils.toString(updateParams), + bsge.getMessage() }); + continue; + } + } + } + catch (BadSqlGrammarException bsge) + { + log + .error( + "Error executing query to load row values, current possible update of row will be skipped. {} Query in error: {}", + bsge.getMessage(), + checkStatement); + return; + } + // 1 check if it is the same + // 2 update only if they differ + } + + } + } + + /** + * @author fgiust + * @version $Id$ + */ + public static class QueryConfig + { + + private String checkQuery; + + private String insertQuery; + + private String selectQuery; + + private String updateQuery; + + /** + * Returns the selectQuery. + * @return the selectQuery + */ + public String getSelectQuery() + { + return selectQuery; + } + + /** + * Sets the selectQuery. + * @param selectQuery the selectQuery to set + */ + public void setSelectQuery(String selectQuery) + { + this.selectQuery = selectQuery; + } + + /** + * Returns the checkQuery. + * @return the checkQuery + */ + public String getCheckQuery() + { + return checkQuery; + } + + /** + * Sets the checkQuery. + * @param checkQuery the checkQuery to set + */ + public void setCheckQuery(String checkQuery) + { + this.checkQuery = checkQuery; + } + + /** + * Returns the insertQuery. + * @return the insertQuery + */ + public String getInsertQuery() + { + return insertQuery; + } + + /** + * Sets the insertQuery. + * @param insertQuery the insertQuery to set + */ + public void setInsertQuery(String insertQuery) + { + this.insertQuery = insertQuery; + } + + /** + * Returns the updateQuery. + * @return the updateQuery + */ + public String getUpdateQuery() + { + return updateQuery; + } + + /** + * Sets the updateQuery. + * @param updateQuery the updateQuery to set + */ + public void setUpdateQuery(String updateQuery) + { + this.updateQuery = updateQuery; + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-03-11 21:46:55
|
Revision: 320 http://svn.sourceforge.net/openutils/?rev=320&view=rev Author: fgiust Date: 2007-03-11 14:46:56 -0700 (Sun, 11 Mar 2007) Log Message: ----------- [maven-release-plugin] prepare release openutils-dbmigration-0.5 Modified Paths: -------------- trunk/openutils-dbmigration/pom.xml Modified: trunk/openutils-dbmigration/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2007-03-11 21:45:50 UTC (rev 319) +++ trunk/openutils-dbmigration/pom.xml 2007-03-11 21:46:56 UTC (rev 320) @@ -8,7 +8,7 @@ </parent> <artifactId>openutils-dbmigration</artifactId> <name>openutils db migration framework</name> - <version>0.5-SNAPSHOT</version> + <version>0.5</version> <description /> <dependencies> <dependency> @@ -84,4 +84,10 @@ <scope>test</scope> </dependency> </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.5</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.5</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-0.5</url> + </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-03-11 21:45:50
|
Revision: 319 http://svn.sourceforge.net/openutils/?rev=319&view=rev Author: fgiust Date: 2007-03-11 14:45:50 -0700 (Sun, 11 Mar 2007) Log Message: ----------- wrong statement used on insert Modified Paths: -------------- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java Modified: trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-03-11 17:46:51 UTC (rev 318) +++ trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-03-11 21:45:50 UTC (rev 319) @@ -300,7 +300,7 @@ try { - jdbcTemplate.update(updateStatement, insertParams, insertTypes); + jdbcTemplate.update(insertStatement, insertParams, insertTypes); } catch (DataIntegrityViolationException bsge) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-03-11 17:46:57
|
Revision: 318 http://svn.sourceforge.net/openutils/?rev=318&view=rev Author: fgiust Date: 2007-03-11 10:46:51 -0700 (Sun, 11 Mar 2007) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/openutils-dbmigration/pom.xml Modified: trunk/openutils-dbmigration/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2007-03-11 17:46:46 UTC (rev 317) +++ trunk/openutils-dbmigration/pom.xml 2007-03-11 17:46:51 UTC (rev 318) @@ -8,7 +8,7 @@ </parent> <artifactId>openutils-dbmigration</artifactId> <name>openutils db migration framework</name> - <version>0.4</version> + <version>0.5-SNAPSHOT</version> <description /> <dependencies> <dependency> @@ -84,10 +84,4 @@ <scope>test</scope> </dependency> </dependencies> - - <scm> - <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.4</connection> - <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.4</developerConnection> - <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-0.4</url> - </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-03-11 17:46:55
|
Revision: 317 http://svn.sourceforge.net/openutils/?rev=317&view=rev Author: fgiust Date: 2007-03-11 10:46:46 -0700 (Sun, 11 Mar 2007) Log Message: ----------- [maven-scm] copy for tag openutils-dbmigration-0.4 Added Paths: ----------- tags/openutils-dbmigration-0.4/ tags/openutils-dbmigration-0.4/pom.xml tags/openutils-dbmigration-0.4/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java Removed Paths: ------------- tags/openutils-dbmigration-0.4/pom.xml tags/openutils-dbmigration-0.4/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java Copied: tags/openutils-dbmigration-0.4 (from rev 314, trunk/openutils-dbmigration) Deleted: tags/openutils-dbmigration-0.4/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2007-03-05 10:59:55 UTC (rev 314) +++ tags/openutils-dbmigration-0.4/pom.xml 2007-03-11 17:46:46 UTC (rev 317) @@ -1,87 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-dbmigration</artifactId> - <name>openutils db migration framework</name> - <version>0.4-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>2.0.1</version> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.2</version> - </dependency> - <dependency> - <groupId>poi</groupId> - <artifactId>poi</artifactId> - <version>2.5.1-final-20040804</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.0</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-dbmigration-0.4/pom.xml (from rev 316, trunk/openutils-dbmigration/pom.xml) =================================================================== --- tags/openutils-dbmigration-0.4/pom.xml (rev 0) +++ tags/openutils-dbmigration-0.4/pom.xml 2007-03-11 17:46:46 UTC (rev 317) @@ -0,0 +1,93 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-dbmigration</artifactId> + <name>openutils db migration framework</name> + <version>0.4</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>2.0.1</version> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>poi</groupId> + <artifactId>poi</artifactId> + <version>2.5.1-final-20040804</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.0</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.4</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.4</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-0.4</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-dbmigration-0.4/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-03-05 10:59:55 UTC (rev 314) +++ tags/openutils-dbmigration-0.4/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-03-11 17:46:46 UTC (rev 317) @@ -1,359 +0,0 @@ -/* - * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it - */ -package it.openutils.migration.task.setup; - -import java.io.IOException; -import java.io.InputStream; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.sql.DataSource; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.poi.hssf.usermodel.HSSFCell; -import org.apache.poi.hssf.usermodel.HSSFRow; -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; -import org.springframework.dao.DataAccessException; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.jdbc.BadSqlGrammarException; -import org.springframework.jdbc.core.ConnectionCallback; -import org.springframework.jdbc.core.JdbcTemplate; - - -/** - * @author fgiust - * @version $Id$ - */ -public class ExcelConfigurationTask extends BaseDbTask implements DbTask -{ - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(ScriptBasedUnconditionalTask.class); - - private Resource script; - - private Map<String, ExcelConfigurationTask.QueryConfig> config; - - /** - * Sets the script. - * @param script the script to set - */ - public void setScript(Resource script) - { - this.script = script; - } - - /** - * Sets the config. - * @param config the config to set - */ - public void setConfig(Map<String, ExcelConfigurationTask.QueryConfig> config) - { - this.config = config; - } - - /** - * {@inheritDoc} - */ - public void execute(DataSource dataSource) - { - if (script == null || !script.exists()) - { - log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); - return; - } - - InputStream is = null; - try - { - is = script.getInputStream(); - POIFSFileSystem fs = new POIFSFileSystem(is); - HSSFWorkbook hssfworkbook = new HSSFWorkbook(fs); - int sheetNums = hssfworkbook.getNumberOfSheets(); - for (int j = 0; j < sheetNums; j++) - { - HSSFSheet sheet = hssfworkbook.getSheetAt(j); - String tableName = hssfworkbook.getSheetName(j); - - QueryConfig conf = config.get(tableName); - if (conf == null) - { - log.error("Unable to handle table {}", tableName); - continue; - } - processSheet(sheet, tableName, conf, dataSource); - - } - - } - catch (IOException e) - { - log.error(e.getMessage(), e); - } - finally - { - IOUtils.closeQuietly(is); - } - - } - - /** - * @param sheet - * @param tableName - */ - private void processSheet(HSSFSheet sheet, final String tableName, QueryConfig con, DataSource dataSource) - { - final List<String> columns = new ArrayList<String>(); - - HSSFRow row = sheet.getRow(0); - for (short k = 0; k < row.getLastCellNum(); k++) - { - HSSFCell cell = row.getCell(k); - if (cell != null) - { - String columnName = cell.getStringCellValue(); - if (StringUtils.isNotBlank(columnName)) - { - columns.add(StringUtils.trim(columnName)); - } - else - { - break; - } - } - } - - log.debug("Table: {}, Columns: {}", tableName, columns); - - final List<Integer> types = new ArrayList<Integer>(); - - boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() - { - - public Object doInConnection(Connection con) throws SQLException, DataAccessException - { - for (String column : columns) - { - ResultSet res = con.getMetaData().getColumns(null, null, tableName, column); - if (res.next()) - { - types.add(res.getInt("DATA_TYPE")); - } - else - { - log.warn("Unable to determine type for column '{}' in table '{}'", column, tableName); - return false; - } - res.close(); - } - return true; - } - }); - - if (!result) - { - log.warn("Skipping sheet {} ", tableName); - } - - String checkStatement = StringUtils.remove(StringUtils.trim(con.getCheckQuery()), "\n"); - String insertStatement = StringUtils.remove(StringUtils.trim(con.getInsertQuery()), "\n"); - - processRecords( - sheet, - columns, - ArrayUtils.toPrimitive(types.toArray(new Integer[types.size()]), Types.NULL), - checkStatement, - insertStatement, - dataSource, - tableName); - } - - /** - * @param sheet - * @param columns - * @param checkStatement - * @param insertStatement - */ - private void processRecords(HSSFSheet sheet, List<String> columns, int[] types, String checkStatement, - String insertStatement, DataSource dataSource, String tableName) - { - JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); - int checkNum = StringUtils.countMatches(checkStatement, "?"); - int insertNum = StringUtils.countMatches(insertStatement, "?"); - - HSSFRow row; - for (short rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) - { - row = sheet.getRow(rowNum); - if (row == null) - { - return; - } - - List<String> values = new ArrayList<String>(); - - for (short k = 0; k < columns.size() && k <= row.getLastCellNum(); k++) - { - HSSFCell cell = row.getCell(k); - String value = null; - - if (cell == null) - { - value = StringUtils.EMPTY; - } - else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) - { - value = cell.getStringCellValue(); - } - else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) - { - double valueDouble = cell.getNumericCellValue(); - // when need to really check if it is a double or an int - double fraction = valueDouble % 1; - if (fraction == 0) - { - value = Integer.toString((int) valueDouble); - } - else - { - value = Double.toString(valueDouble); - } - } - - if (StringUtils.isEmpty(value)) - { - value = StringUtils.EMPTY; - } - - if ("<NULL>".equalsIgnoreCase(value)) - { - value = null; - } - - values.add(value); - } - - Object[] checkParams = ArrayUtils.subarray(values.toArray(), 0, checkNum); - for (int i = 0; i < checkParams.length; i++) - { - if (StringUtils.isEmpty((String) checkParams[i])) - { - return; - } - } - - int existing; - try - { - existing = jdbcTemplate.queryForInt(checkStatement, checkParams); - } - catch (BadSqlGrammarException bsge) - { - log.error("Error executing check query, current sheet will be skipped. {} Query in error: {}", bsge - .getMessage(), checkStatement); - return; - } - - if (existing == 0) - { - Object[] insertParams = ArrayUtils.subarray(values.toArray(), 0, insertNum); - int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); - if (log.isDebugEnabled()) - { - log.debug("Missing record with key {}; inserting {}", ArrayUtils.toString(checkParams), ArrayUtils - .toString(insertParams)); - } - - if (insertParams.length != insertTypes.length) - { - log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ - tableName, - insertParams.length, - insertTypes.length }); - } - - try - { - jdbcTemplate.update(insertStatement, insertParams, insertTypes); - } - catch (DataIntegrityViolationException bsge) - { - log - .error( - "Error executing insert, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", - new Object[]{ - tableName, - rowNum + 1, - insertStatement, - ArrayUtils.toString(insertParams), - bsge.getMessage() }); - continue; - } - } - - } - } - - /** - * @author fgiust - * @version $Id$ - */ - public static class QueryConfig - { - - private String checkQuery; - - private String insertQuery; - - /** - * Returns the checkQuery. - * @return the checkQuery - */ - public String getCheckQuery() - { - return checkQuery; - } - - /** - * Sets the checkQuery. - * @param checkQuery the checkQuery to set - */ - public void setCheckQuery(String checkQuery) - { - this.checkQuery = checkQuery; - } - - /** - * Returns the insertQuery. - * @return the insertQuery - */ - public String getInsertQuery() - { - return insertQuery; - } - - /** - * Sets the insertQuery. - * @param insertQuery the insertQuery to set - */ - public void setInsertQuery(String insertQuery) - { - this.insertQuery = insertQuery; - } - } -} Copied: tags/openutils-dbmigration-0.4/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java (from rev 315, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java) =================================================================== --- tags/openutils-dbmigration-0.4/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java (rev 0) +++ tags/openutils-dbmigration-0.4/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-03-11 17:46:46 UTC (rev 317) @@ -0,0 +1,494 @@ +/* + * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it + */ +package it.openutils.migration.task.setup; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.sql.DataSource; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.Resource; +import org.springframework.dao.DataAccessException; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.jdbc.BadSqlGrammarException; +import org.springframework.jdbc.core.ColumnMapRowMapper; +import org.springframework.jdbc.core.ConnectionCallback; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + + +/** + * @author fgiust + * @version $Id$ + */ +public class ExcelConfigurationTask extends BaseDbTask implements DbTask +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(ScriptBasedUnconditionalTask.class); + + private Resource script; + + private Map<String, ExcelConfigurationTask.QueryConfig> config; + + /** + * Sets the script. + * @param script the script to set + */ + public void setScript(Resource script) + { + this.script = script; + } + + /** + * Sets the config. + * @param config the config to set + */ + public void setConfig(Map<String, ExcelConfigurationTask.QueryConfig> config) + { + this.config = config; + } + + /** + * {@inheritDoc} + */ + public void execute(DataSource dataSource) + { + if (script == null || !script.exists()) + { + log.error("Unable to execute db task \"{}\", script \"{}\" not found.", getDescription(), script); + return; + } + + InputStream is = null; + try + { + is = script.getInputStream(); + POIFSFileSystem fs = new POIFSFileSystem(is); + HSSFWorkbook hssfworkbook = new HSSFWorkbook(fs); + int sheetNums = hssfworkbook.getNumberOfSheets(); + for (int j = 0; j < sheetNums; j++) + { + HSSFSheet sheet = hssfworkbook.getSheetAt(j); + String tableName = hssfworkbook.getSheetName(j); + + QueryConfig conf = config.get(tableName); + if (conf == null) + { + log.error("Unable to handle table {}", tableName); + continue; + } + processSheet(sheet, tableName, conf, dataSource); + + } + + } + catch (IOException e) + { + log.error(e.getMessage(), e); + } + finally + { + IOUtils.closeQuietly(is); + } + + } + + /** + * @param sheet + * @param tableName + */ + private void processSheet(HSSFSheet sheet, final String tableName, QueryConfig con, DataSource dataSource) + { + final List<String> columns = new ArrayList<String>(); + + HSSFRow row = sheet.getRow(0); + for (short k = 0; k < row.getLastCellNum(); k++) + { + HSSFCell cell = row.getCell(k); + if (cell != null) + { + String columnName = cell.getStringCellValue(); + if (StringUtils.isNotBlank(columnName)) + { + columns.add(StringUtils.trim(columnName)); + } + else + { + break; + } + } + } + + log.debug("Table: {}, Columns: {}", tableName, columns); + + final List<Integer> types = new ArrayList<Integer>(); + + boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() + { + + public Object doInConnection(Connection con) throws SQLException, DataAccessException + { + for (String column : columns) + { + ResultSet res = con.getMetaData().getColumns(null, null, tableName, column); + if (res.next()) + { + types.add(res.getInt("DATA_TYPE")); + } + else + { + log.warn("Unable to determine type for column '{}' in table '{}'", column, tableName); + return false; + } + res.close(); + } + return true; + } + }); + + if (!result) + { + log.warn("Skipping sheet {} ", tableName); + } + + String checkStatement = StringUtils.remove(StringUtils.trim(con.getCheckQuery()), "\n"); + String insertStatement = StringUtils.remove(StringUtils.trim(con.getInsertQuery()), "\n"); + String selectStatement = StringUtils.remove(StringUtils.trim(con.getSelectQuery()), "\n"); + String updateStatement = StringUtils.remove(StringUtils.trim(con.getUpdateQuery()), "\n"); + + processRecords( + sheet, + columns, + ArrayUtils.toPrimitive(types.toArray(new Integer[types.size()]), Types.NULL), + checkStatement, + insertStatement, + selectStatement, + updateStatement, + dataSource, + tableName); + } + + /** + * @param sheet + * @param columns + * @param checkStatement + * @param insertStatement + * @param updateStatement + * @param selectStatement + */ + private void processRecords(HSSFSheet sheet, List<String> columns, int[] types, String checkStatement, + String insertStatement, String selectStatement, String updateStatement, DataSource dataSource, String tableName) + { + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + int checkNum = StringUtils.countMatches(checkStatement, "?"); + int insertNum = StringUtils.countMatches(insertStatement, "?"); + int selectNum = StringUtils.countMatches(selectStatement, "?"); + int updateNum = StringUtils.countMatches(updateStatement, "?"); + + HSSFRow row; + for (short rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) + { + row = sheet.getRow(rowNum); + if (row == null) + { + return; + } + + List<String> values = new ArrayList<String>(); + + for (short k = 0; k < columns.size() && k <= row.getLastCellNum(); k++) + { + HSSFCell cell = row.getCell(k); + String value = null; + + if (cell == null) + { + value = StringUtils.EMPTY; + } + else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) + { + value = cell.getStringCellValue(); + } + else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) + { + double valueDouble = cell.getNumericCellValue(); + // when need to really check if it is a double or an int + double fraction = valueDouble % 1; + if (fraction == 0) + { + value = Integer.toString((int) valueDouble); + } + else + { + value = Double.toString(valueDouble); + } + } + + if (StringUtils.isEmpty(value)) + { + value = StringUtils.EMPTY; + } + + if ("<NULL>".equalsIgnoreCase(value)) + { + value = null; + } + + values.add(value); + } + + Object[] checkParams = ArrayUtils.subarray(values.toArray(), 0, checkNum); + for (int i = 0; i < checkParams.length; i++) + { + if (StringUtils.isEmpty((String) checkParams[i])) + { + return; + } + } + + int existing; + try + { + existing = jdbcTemplate.queryForInt(checkStatement, checkParams); + } + catch (BadSqlGrammarException bsge) + { + log.error("Error executing check query, current sheet will be skipped. {} Query in error: {}", bsge + .getMessage(), checkStatement); + return; + } + + if (existing == 0) + { + Object[] insertParams = ArrayUtils.subarray(values.toArray(), 0, insertNum); + int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); + if (log.isDebugEnabled()) + { + log.debug("Missing record with key {}; inserting {}", ArrayUtils.toString(checkParams), ArrayUtils + .toString(insertParams)); + } + + if (insertParams.length != insertTypes.length) + { + log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ + tableName, + insertParams.length, + insertTypes.length }); + } + + try + { + jdbcTemplate.update(updateStatement, insertParams, insertTypes); + } + catch (DataIntegrityViolationException bsge) + { + log + .error( + "Error executing update, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", + new Object[]{ + tableName, + rowNum + 1, + insertStatement, + ArrayUtils.toString(insertParams), + bsge.getMessage() }); + continue; + } + } + else if (StringUtils.isNotBlank(updateStatement) && StringUtils.isNotBlank(selectStatement)) + { + try + { + RowMapper rowMapper = new ColumnMapRowMapper(); + Object[] selectParams = ArrayUtils.subarray(values.toArray(), 0, selectNum); + List selectResult = jdbcTemplate.query(selectStatement, selectParams, rowMapper); + Map<String, Object> fetchedColumns = (Map<String, Object>) selectResult.get(0); + int i = 0; + boolean updateNeeded = false; + for (String columnName : columns) + { + Object columnObject = fetchedColumns.get(columnName); + if (columnObject == null) + { + continue; + } + String columnValue = ObjectUtils.toString(fetchedColumns.get(columnName)); + if (!StringUtils.equals(columnValue, values.get(i))) + { + updateNeeded = true; + break; + } + i++; + } + if (updateNeeded) + { + Object[] updateParams = ArrayUtils.subarray(values.toArray(), 0, updateNum); + int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); + if (log.isDebugEnabled()) + { + log.debug( + "Missing record with key {}; updating {}", + ArrayUtils.toString(checkParams), + ArrayUtils.toString(updateParams)); + } + + if (updateParams.length != insertTypes.length) + { + log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ + tableName, + updateParams.length, + insertTypes.length }); + } + + try + { + Object[] compoundUpdateParams = new Object[checkParams.length + updateParams.length]; + System.arraycopy(updateParams, 0, compoundUpdateParams, 0, updateParams.length); + System.arraycopy( + checkParams, + 0, + compoundUpdateParams, + compoundUpdateParams.length - 1, + checkParams.length); + jdbcTemplate.update(updateStatement, compoundUpdateParams); + } + catch (DataIntegrityViolationException bsge) + { + log + .error( + "Error executing insert, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", + new Object[]{ + tableName, + rowNum + 1, + insertStatement, + ArrayUtils.toString(updateParams), + bsge.getMessage() }); + continue; + } + } + } + catch (BadSqlGrammarException bsge) + { + log + .error( + "Error executing query to load row values, current possible update of row will be skipped. {} Query in error: {}", + bsge.getMessage(), + checkStatement); + return; + } + // 1 check if it is the same + // 2 update only if they differ + } + + } + } + + /** + * @author fgiust + * @version $Id$ + */ + public static class QueryConfig + { + + private String checkQuery; + + private String insertQuery; + + private String selectQuery; + + private String updateQuery; + + /** + * Returns the selectQuery. + * @return the selectQuery + */ + public String getSelectQuery() + { + return selectQuery; + } + + /** + * Sets the selectQuery. + * @param selectQuery the selectQuery to set + */ + public void setSelectQuery(String selectQuery) + { + this.selectQuery = selectQuery; + } + + /** + * Returns the checkQuery. + * @return the checkQuery + */ + public String getCheckQuery() + { + return checkQuery; + } + + /** + * Sets the checkQuery. + * @param checkQuery the checkQuery to set + */ + public void setCheckQuery(String checkQuery) + { + this.checkQuery = checkQuery; + } + + /** + * Returns the insertQuery. + * @return the insertQuery + */ + public String getInsertQuery() + { + return insertQuery; + } + + /** + * Sets the insertQuery. + * @param insertQuery the insertQuery to set + */ + public void setInsertQuery(String insertQuery) + { + this.insertQuery = insertQuery; + } + + /** + * Returns the updateQuery. + * @return the updateQuery + */ + public String getUpdateQuery() + { + return updateQuery; + } + + /** + * Sets the updateQuery. + * @param updateQuery the updateQuery to set + */ + public void setUpdateQuery(String updateQuery) + { + this.updateQuery = updateQuery; + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-03-11 17:46:42
|
Revision: 316 http://svn.sourceforge.net/openutils/?rev=316&view=rev Author: fgiust Date: 2007-03-11 10:46:36 -0700 (Sun, 11 Mar 2007) Log Message: ----------- [maven-release-plugin] prepare release openutils-dbmigration-0.4 Modified Paths: -------------- trunk/openutils-dbmigration/pom.xml Modified: trunk/openutils-dbmigration/pom.xml =================================================================== --- trunk/openutils-dbmigration/pom.xml 2007-03-11 17:45:43 UTC (rev 315) +++ trunk/openutils-dbmigration/pom.xml 2007-03-11 17:46:36 UTC (rev 316) @@ -8,7 +8,7 @@ </parent> <artifactId>openutils-dbmigration</artifactId> <name>openutils db migration framework</name> - <version>0.4-SNAPSHOT</version> + <version>0.4</version> <description /> <dependencies> <dependency> @@ -84,4 +84,10 @@ <scope>test</scope> </dependency> </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.4</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-0.4</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-0.4</url> + </scm> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2007-03-11 17:45:42
|
Revision: 315 http://svn.sourceforge.net/openutils/?rev=315&view=rev Author: fgiust Date: 2007-03-11 10:45:43 -0700 (Sun, 11 Mar 2007) Log Message: ----------- allow updates in ExcelConfigurationTask Modified Paths: -------------- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java Modified: trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-03-05 10:59:55 UTC (rev 314) +++ trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-03-11 17:45:43 UTC (rev 315) @@ -17,6 +17,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; @@ -29,8 +30,10 @@ import org.springframework.dao.DataAccessException; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.jdbc.BadSqlGrammarException; +import org.springframework.jdbc.core.ColumnMapRowMapper; import org.springframework.jdbc.core.ConnectionCallback; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; /** @@ -172,6 +175,8 @@ String checkStatement = StringUtils.remove(StringUtils.trim(con.getCheckQuery()), "\n"); String insertStatement = StringUtils.remove(StringUtils.trim(con.getInsertQuery()), "\n"); + String selectStatement = StringUtils.remove(StringUtils.trim(con.getSelectQuery()), "\n"); + String updateStatement = StringUtils.remove(StringUtils.trim(con.getUpdateQuery()), "\n"); processRecords( sheet, @@ -179,6 +184,8 @@ ArrayUtils.toPrimitive(types.toArray(new Integer[types.size()]), Types.NULL), checkStatement, insertStatement, + selectStatement, + updateStatement, dataSource, tableName); } @@ -188,13 +195,17 @@ * @param columns * @param checkStatement * @param insertStatement + * @param updateStatement + * @param selectStatement */ private void processRecords(HSSFSheet sheet, List<String> columns, int[] types, String checkStatement, - String insertStatement, DataSource dataSource, String tableName) + String insertStatement, String selectStatement, String updateStatement, DataSource dataSource, String tableName) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); int checkNum = StringUtils.countMatches(checkStatement, "?"); int insertNum = StringUtils.countMatches(insertStatement, "?"); + int selectNum = StringUtils.countMatches(selectStatement, "?"); + int updateNum = StringUtils.countMatches(updateStatement, "?"); HSSFRow row; for (short rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) @@ -289,13 +300,13 @@ try { - jdbcTemplate.update(insertStatement, insertParams, insertTypes); + jdbcTemplate.update(updateStatement, insertParams, insertTypes); } catch (DataIntegrityViolationException bsge) { log .error( - "Error executing insert, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", + "Error executing update, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", new Object[]{ tableName, rowNum + 1, @@ -305,7 +316,91 @@ continue; } } + else if (StringUtils.isNotBlank(updateStatement) && StringUtils.isNotBlank(selectStatement)) + { + try + { + RowMapper rowMapper = new ColumnMapRowMapper(); + Object[] selectParams = ArrayUtils.subarray(values.toArray(), 0, selectNum); + List selectResult = jdbcTemplate.query(selectStatement, selectParams, rowMapper); + Map<String, Object> fetchedColumns = (Map<String, Object>) selectResult.get(0); + int i = 0; + boolean updateNeeded = false; + for (String columnName : columns) + { + Object columnObject = fetchedColumns.get(columnName); + if (columnObject == null) + { + continue; + } + String columnValue = ObjectUtils.toString(fetchedColumns.get(columnName)); + if (!StringUtils.equals(columnValue, values.get(i))) + { + updateNeeded = true; + break; + } + i++; + } + if (updateNeeded) + { + Object[] updateParams = ArrayUtils.subarray(values.toArray(), 0, updateNum); + int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); + if (log.isDebugEnabled()) + { + log.debug( + "Missing record with key {}; updating {}", + ArrayUtils.toString(checkParams), + ArrayUtils.toString(updateParams)); + } + if (updateParams.length != insertTypes.length) + { + log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ + tableName, + updateParams.length, + insertTypes.length }); + } + + try + { + Object[] compoundUpdateParams = new Object[checkParams.length + updateParams.length]; + System.arraycopy(updateParams, 0, compoundUpdateParams, 0, updateParams.length); + System.arraycopy( + checkParams, + 0, + compoundUpdateParams, + compoundUpdateParams.length - 1, + checkParams.length); + jdbcTemplate.update(updateStatement, compoundUpdateParams); + } + catch (DataIntegrityViolationException bsge) + { + log + .error( + "Error executing insert, record at {}:{} will be skipped. Query in error: '{}', values: {}. Error message: {}", + new Object[]{ + tableName, + rowNum + 1, + insertStatement, + ArrayUtils.toString(updateParams), + bsge.getMessage() }); + continue; + } + } + } + catch (BadSqlGrammarException bsge) + { + log + .error( + "Error executing query to load row values, current possible update of row will be skipped. {} Query in error: {}", + bsge.getMessage(), + checkStatement); + return; + } + // 1 check if it is the same + // 2 update only if they differ + } + } } @@ -320,7 +415,29 @@ private String insertQuery; + private String selectQuery; + + private String updateQuery; + /** + * Returns the selectQuery. + * @return the selectQuery + */ + public String getSelectQuery() + { + return selectQuery; + } + + /** + * Sets the selectQuery. + * @param selectQuery the selectQuery to set + */ + public void setSelectQuery(String selectQuery) + { + this.selectQuery = selectQuery; + } + + /** * Returns the checkQuery. * @return the checkQuery */ @@ -355,5 +472,23 @@ { this.insertQuery = insertQuery; } + + /** + * Returns the updateQuery. + * @return the updateQuery + */ + public String getUpdateQuery() + { + return updateQuery; + } + + /** + * Sets the updateQuery. + * @param updateQuery the updateQuery to set + */ + public void setUpdateQuery(String updateQuery) + { + this.updateQuery = updateQuery; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |