diff --git a/.classpath b/.classpath
index af2ac2e3c..476da60bc 100644
--- a/.classpath
+++ b/.classpath
@@ -1,6 +1,10 @@
-
+
+
+
+
+
@@ -83,7 +87,7 @@
-
+
@@ -443,7 +447,7 @@
-
+
@@ -528,11 +532,19 @@
-
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
index 0080155c9..a738d596e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,18 @@
+
## Build folders
+
bin/
build/
-tmp/
target/
+tmp/
+
+<<<<<<< HEAD
+*.class
+*,so
+*,si
+*,dll
+*.o
+*.tmp
## Always ignore these
*~
@@ -25,7 +35,7 @@ nbproject/private/
*.tmp
tmp*
log*
-.classpath
/.externalToolBuilders
/.settings
/test-output
+/target/
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 000000000..99f26c020
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.core.runtime.prefs b/.settings/org.eclipse.core.runtime.prefs
new file mode 100644
index 000000000..5a0ad22d2
--- /dev/null
+++ b/.settings/org.eclipse.core.runtime.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+line.separator=\n
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index b220e2de8..e2a00b7e2 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -2,5 +2,7 @@
+
+
diff --git a/ant.xml b/ant.xml
deleted file mode 100644
index 0d82b5391..000000000
--- a/ant.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/build.xml b/build.xml
new file mode 100644
index 000000000..07919a9d4
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,166 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ivy.xml b/ivy.xml
new file mode 100644
index 000000000..987d9f92c
--- /dev/null
+++ b/ivy.xml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/cobertura/asm-tree.jar b/lib/cobertura/asm-tree.jar
new file mode 100644
index 000000000..374bc2e9b
Binary files /dev/null and b/lib/cobertura/asm-tree.jar differ
diff --git a/lib/cobertura/asm.jar b/lib/cobertura/asm.jar
new file mode 100644
index 000000000..d44dfd860
Binary files /dev/null and b/lib/cobertura/asm.jar differ
diff --git a/lib/cobertura/cobertura.jar b/lib/cobertura/cobertura.jar
new file mode 100644
index 000000000..438fe551a
Binary files /dev/null and b/lib/cobertura/cobertura.jar differ
diff --git a/lib/cobertura/log4j.jar b/lib/cobertura/log4j.jar
new file mode 100644
index 000000000..625130719
Binary files /dev/null and b/lib/cobertura/log4j.jar differ
diff --git a/lib/cobertura/oro.jar b/lib/cobertura/oro.jar
new file mode 100644
index 000000000..23488d260
Binary files /dev/null and b/lib/cobertura/oro.jar differ
diff --git a/lib/commons-email-1.2.jar b/lib/commons-email-1.2.jar
new file mode 100644
index 000000000..f08597594
Binary files /dev/null and b/lib/commons-email-1.2.jar differ
diff --git a/lib/findbugs-2.0.1/lib/annotations.jar b/lib/findbugs-2.0.1/lib/annotations.jar
new file mode 100644
index 000000000..8a0204fc2
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/annotations.jar differ
diff --git a/lib/findbugs-2.0.1/lib/ant.jar b/lib/findbugs-2.0.1/lib/ant.jar
new file mode 100644
index 000000000..f68c9cfc8
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/ant.jar differ
diff --git a/lib/findbugs-2.0.1/lib/asm-3.3.jar b/lib/findbugs-2.0.1/lib/asm-3.3.jar
new file mode 100644
index 000000000..7638ae058
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/asm-3.3.jar differ
diff --git a/lib/findbugs-2.0.1/lib/asm-analysis-3.3.jar b/lib/findbugs-2.0.1/lib/asm-analysis-3.3.jar
new file mode 100644
index 000000000..852d98158
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/asm-analysis-3.3.jar differ
diff --git a/lib/findbugs-2.0.1/lib/asm-commons-3.3.jar b/lib/findbugs-2.0.1/lib/asm-commons-3.3.jar
new file mode 100644
index 000000000..6f9d40fba
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/asm-commons-3.3.jar differ
diff --git a/lib/findbugs-2.0.1/lib/asm-tree-3.3.jar b/lib/findbugs-2.0.1/lib/asm-tree-3.3.jar
new file mode 100644
index 000000000..4a5daa68a
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/asm-tree-3.3.jar differ
diff --git a/lib/findbugs-2.0.1/lib/asm-util-3.3.jar b/lib/findbugs-2.0.1/lib/asm-util-3.3.jar
new file mode 100644
index 000000000..115bcc732
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/asm-util-3.3.jar differ
diff --git a/lib/findbugs-2.0.1/lib/asm-xml-3.3.jar b/lib/findbugs-2.0.1/lib/asm-xml-3.3.jar
new file mode 100644
index 000000000..61d6a8c21
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/asm-xml-3.3.jar differ
diff --git a/lib/findbugs-2.0.1/lib/bcel.jar b/lib/findbugs-2.0.1/lib/bcel.jar
new file mode 100644
index 000000000..fef26b13c
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/bcel.jar differ
diff --git a/lib/findbugs-2.0.1/lib/commons-lang-2.4.jar b/lib/findbugs-2.0.1/lib/commons-lang-2.4.jar
new file mode 100644
index 000000000..532939eca
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/commons-lang-2.4.jar differ
diff --git a/lib/findbugs-2.0.1/lib/dom4j-1.6.1.jar b/lib/findbugs-2.0.1/lib/dom4j-1.6.1.jar
new file mode 100644
index 000000000..c8c4dbb92
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/dom4j-1.6.1.jar differ
diff --git a/lib/findbugs-2.0.1/lib/findbugs-ant.jar b/lib/findbugs-2.0.1/lib/findbugs-ant.jar
new file mode 100644
index 000000000..2128ba85e
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/findbugs-ant.jar differ
diff --git a/lib/findbugs-2.0.1/lib/findbugs.jar b/lib/findbugs-2.0.1/lib/findbugs.jar
new file mode 100644
index 000000000..3201a2650
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/findbugs.jar differ
diff --git a/lib/findbugs-2.0.1/lib/jFormatString.jar b/lib/findbugs-2.0.1/lib/jFormatString.jar
new file mode 100644
index 000000000..62f6c0260
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/jFormatString.jar differ
diff --git a/lib/findbugs-2.0.1/lib/jaxen-1.1.1.jar b/lib/findbugs-2.0.1/lib/jaxen-1.1.1.jar
new file mode 100644
index 000000000..b63363113
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/jaxen-1.1.1.jar differ
diff --git a/lib/findbugs-2.0.1/lib/jcip-annotations.jar b/lib/findbugs-2.0.1/lib/jcip-annotations.jar
new file mode 100644
index 000000000..bb07c0c44
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/jcip-annotations.jar differ
diff --git a/lib/findbugs-2.0.1/lib/jdepend-2.9.jar b/lib/findbugs-2.0.1/lib/jdepend-2.9.jar
new file mode 100644
index 000000000..1838bbb91
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/jdepend-2.9.jar differ
diff --git a/lib/findbugs-2.0.1/lib/jsr305.jar b/lib/findbugs-2.0.1/lib/jsr305.jar
new file mode 100644
index 000000000..43807b02f
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/jsr305.jar differ
diff --git a/lib/findbugs-2.0.1/lib/yjp-controller-api-redist.jar b/lib/findbugs-2.0.1/lib/yjp-controller-api-redist.jar
new file mode 100644
index 000000000..490695f8a
Binary files /dev/null and b/lib/findbugs-2.0.1/lib/yjp-controller-api-redist.jar differ
diff --git a/lib/freemarker.jar b/lib/freemarker.jar
index 968c1d314..b13671dac 100644
Binary files a/lib/freemarker.jar and b/lib/freemarker.jar differ
diff --git a/lib/keggapi.jar b/lib/keggapi.jar
new file mode 100644
index 000000000..a87db3072
Binary files /dev/null and b/lib/keggapi.jar differ
diff --git a/lib/mindterm.jar b/lib/mindterm.jar
new file mode 100644
index 000000000..f315a3f51
Binary files /dev/null and b/lib/mindterm.jar differ
diff --git a/lib/mockito-all-1.9.5.jar b/lib/mockito-all-1.9.5.jar
new file mode 100644
index 000000000..00416eb38
Binary files /dev/null and b/lib/mockito-all-1.9.5.jar differ
diff --git a/lib/ontocat-0.9.9.1.jar b/lib/ontocat-0.9.9.1.jar
new file mode 100644
index 000000000..e1d7bff6c
Binary files /dev/null and b/lib/ontocat-0.9.9.1.jar differ
diff --git a/lib/org.semanticweb.HermiT.jar b/lib/org.semanticweb.HermiT.jar
new file mode 100644
index 000000000..3cd01302d
Binary files /dev/null and b/lib/org.semanticweb.HermiT.jar differ
diff --git a/lib/selenium-server-standalone-2.19.0.jar b/lib/selenium-server-standalone-2.25.0.jar
similarity index 76%
rename from lib/selenium-server-standalone-2.19.0.jar
rename to lib/selenium-server-standalone-2.25.0.jar
index ba7bf2f11..90ee07853 100644
Binary files a/lib/selenium-server-standalone-2.19.0.jar and b/lib/selenium-server-standalone-2.25.0.jar differ
diff --git a/lib/simplecaptcha-1.2.1.jar b/lib/simplecaptcha-1.2.1.jar
new file mode 100644
index 000000000..9bba7cbe7
Binary files /dev/null and b/lib/simplecaptcha-1.2.1.jar differ
diff --git a/pom.xml b/pom.xml
index b23669849..56355ea64 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,212 +1,232 @@
-
- 4.0.0
-
- org.molgenis
- molgenis
- 1.0-SNAPSHOT
- jar
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
- molgenis
+ org.molgenis
+ molgenis
+ 1.0-SNAPSHOT
+ jar
-
- ${project.build.directory}/endorsed
- UTF-8
-
+ molgenis
-
-
- thirdparty-releases
- JBoss Thirdparty Releases
- https://repository.jboss.org/nexus/content/repositories/thirdparty-releases
-
-
+
+ ${project.build.directory}/endorsed
+ UTF-8
+
-
-
- org.hibernate
- hibernate-entitymanager
- 3.6.9.Final
- jar
-
-
- org.hibernate
- hibernate-validator
- 4.2.0.Final
-
-
- commons-dbcp
- commons-dbcp
- 1.4
-
-
-
- commons-pool
- commons-pool
- 20030825.183949
- runtime
-
+
+
+ org.hibernate
+ hibernate-entitymanager
+ 3.6.9.Final
+ jar
+
+
+ org.hibernate
+ hibernate-validator
+ 4.2.0.Final
+
+
+ commons-dbcp
+ commons-dbcp
+ 1.4
+
+
+
+ commons-pool
+ commons-pool
+ 20030825.183949
+ runtime
+
mysql
mysql-connector-java
- 5.1.20
+ 5.1.20
+ provided
-
hsqldb
hsqldb
1.8.0.10
-
-
-
-
-
- javax.servlet
- servlet-api
- 2.5
provided
-
-
-
- taglibs
- standard
- 1.1.2
-
-
- javax.servlet
- jstl
- 1.2
+
+
+
+
+ javax.servlet
+ servlet-api
+ 2.5
+ provided
+
+
+
+
+ taglibs
+ standard
+ 1.1.2
+
+
+ javax.servlet
+ jstl
+ 1.2
runtime
-
-
-
-
- commons-lang
- commons-lang
- 2.6
-
-
-
- commons-fileupload
- commons-fileupload
- 1.2
-
-
-
-
-
-
- org.quartz-scheduler
- quartz
- 1.8.6
-
-
-
+
-
- org.freemarker
- freemarker
- 2.3.18
-
+
+
+ commons-lang
+ commons-lang
+ 2.6
+
+
+ commons-fileupload
+ commons-fileupload
+ 1.2
+
+
+ org.apache.commons
+ commons-email
+ 1.2
+
+
+ commons-io
+ commons-io
+ 2.4
+
+
+
+
+
+ org.quartz-scheduler
+ quartz
+ 1.8.6
+
+
+
+
+
+ org.freemarker
+ freemarker
+ 2.3.18
+
+
+
+
+ ch.ethz.ganymed
+ ganymed-ssh2
+ build210
+
+
+
+
+ org.testng
+ testng
+ 6.4
+ test
+
+
+ junit
+ junit
+ 4.10
+ test
+
+
+ org.mockito
+ mockito-all
+ 1.8.4
+ test
+
-
+
+
+ org.hibernate
+ hibernate-search
+ 3.4.1.Final
+
+
+
- ch.ethz.ganymed
- ganymed-ssh2
- build210
+ org.apache.poi
+ poi
+ 3.8
+
+ net.sourceforge.jexcelapi
+ jxl
+ 2.6.12
+
-
-
- org.testng
- testng
- 6.4
-
-
-
- junit
- junit
- 4.10
-
-
+
+
+ javatar
+ javatar
+ 2.5
+
+
+
+
+ org.apache.cxf
+ cxf-bundle-minimal
+ 2.5.2
+
-
-
- org.hibernate
- hibernate-search
- 3.4.1.Final
-
-
-
-
- net.sourceforge.jexcelapi
- jxl
- 2.6.12
-
-
-
-
- javatar
- javatar
- 2.5
-
-
-
-
- org.apache.cxf
- cxf-bundle-minimal
- 2.5.2
-
-
-
-
- xerces
- xercesImpl
- 2.10.0
-
-
-
-
- net.sf.json-lib
- json-lib
- 2.4
- jdk15
-
+
+
+ xerces
+ xercesImpl
+ 2.10.0
+
+
+
+
+ net.sf.json-lib
+ json-lib
+ 2.4
+ jdk15
+
com.google.code.gson
gson
2.2
compile
-
-
-
- org.apache.ant
- ant
- 1.8.2
-
-
-
- org.apache.ant
- ant-apache-log4j
- 1.8.2
-
-
-
-
- org.json
- json
- 20090211
-
+
+
+ org.apache.ant
+ ant
+ 1.8.2
+
+
+
+ org.apache.ant
+ ant-apache-log4j
+ 1.8.2
+
+
+
+
+ org.json
+ json
+ 20090211
+
@@ -214,14 +234,13 @@
tjws
2.3.4.Final
-
-
-
- src
- src
+
-
-
+
+ src
+ test/java
+
+
src/
@@ -229,29 +248,33 @@
**/*.properties
**/*.index
org/molgenis/framework/ui/res/**
-
+
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 2.3.2
-
- 1.6
- 1.6
-
- ${endorsed.dir}
-
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+
+ ${endorsed.dir}
+
+
+
+
maven-surefire-plugin
2.6
@@ -265,33 +288,32 @@
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 2.1
+
+
+ validate
+
+ copy
+
+
+ ${endorsed.dir}
+ true
+
+
+ javax
+ javaee-endorsed-api
+ 6.0
+ jar
+
+
+
+
+
+
+
+
-
- org.apache.maven.plugins
- maven-dependency-plugin
- 2.1
-
-
- validate
-
- copy
-
-
- ${endorsed.dir}
- true
-
-
- javax
- javaee-endorsed-api
- 6.0
- jar
-
-
-
-
-
-
-
-
-
diff --git a/pom_minimal.xml b/pom_minimal.xml
new file mode 100644
index 000000000..58859b4d0
--- /dev/null
+++ b/pom_minimal.xml
@@ -0,0 +1,302 @@
+
+ 4.0.0
+
+ org.molgenis
+ molgenis
+ 1.0-SNAPSHOT
+ jar
+
+ molgenis
+
+
+ ${project.build.directory}/endorsed
+ UTF-8
+
+
+
+
+
+
+ org.hibernate
+ hibernate-entitymanager
+ 3.6.9.Final
+ jar
+
+
+ org.hibernate
+ hibernate-validator
+ 4.2.0.Final
+
+
+ commons-dbcp
+ commons-dbcp
+ 1.4
+
+
+
+ commons-pool
+ commons-pool
+ 20030825.183949
+ runtime
+
+
+ mysql
+ mysql-connector-java
+ 5.1.20
+ provided
+
+
+ hsqldb
+ hsqldb
+ 1.8.0.10
+ provided
+
+
+
+
+
+ javax.servlet
+ servlet-api
+ 2.5
+ provided
+
+
+
+
+ taglibs
+ standard
+ 1.1.2
+
+
+ javax.servlet
+ jstl
+ 1.2
+ runtime
+
+
+
+
+ commons-lang
+ commons-lang
+ 2.6
+
+
+ commons-fileupload
+ commons-fileupload
+ 1.2
+
+
+ org.apache.commons
+ commons-email
+ 1.2
+
+
+
+
+
+ org.quartz-scheduler
+ quartz
+ 1.8.6
+
+
+
+
+
+ org.freemarker
+ freemarker
+ 2.3.18
+
+
+
+
+ ch.ethz.ganymed
+ ganymed-ssh2
+ build210
+
+
+
+
+ org.testng
+ testng
+ 6.4
+ test
+
+
+ junit
+ junit
+ 4.10
+ test
+
+
+
+
+ org.hibernate
+ hibernate-search
+ 3.4.1.Final
+
+
+
+
+ net.sourceforge.jexcelapi
+ jxl
+ 2.6.12
+
+
+
+
+ javatar
+ javatar
+ 2.5
+
+
+
+
+ org.apache.cxf
+ cxf-bundle-minimal
+ 2.5.2
+
+
+
+
+ xerces
+ xercesImpl
+ 2.10.0
+
+
+
+
+ net.sf.json-lib
+ json-lib
+ 2.4
+ jdk15
+
+
+ com.google.code.gson
+ gson
+ 2.2
+ compile
+
+
+
+ org.apache.ant
+ ant
+ 1.8.2
+
+
+
+ org.apache.ant
+ ant-apache-log4j
+ 1.8.2
+
+
+
+
+ org.json
+ json
+ 20090211
+
+
+
+
+ org.jboss.resteasy
+ tjws
+ 2.3.4.Final
+
+
+
+
+ src
+ src
+
+
+
+
+ src/
+
+ **/*.ftl
+ **/*.properties
+ **/*.index
+ org/molgenis/framework/ui/res/**
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+
+ ${endorsed.dir}
+
+
+ **/*Test.java
+ **/Test*.java
+
+
+ **/*Test.java
+ **/Test*.java
+
+
+
+
+ maven-surefire-plugin
+ 2.6
+
+
+
+ **/*ExcelReaderTest.java
+ **/*PbsTest.java
+ **/*PlinkTest.java
+ **/*VcfReaderTest.java
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 2.1
+
+
+ validate
+
+ copy
+
+
+ ${endorsed.dir}
+ true
+
+
+ javax
+ javaee-endorsed-api
+ 6.0
+ jar
+
+
+
+
+
+
+
+
+
+
diff --git a/src/org/molgenis/Molgenis.java b/src/org/molgenis/Molgenis.java
index 7b1148cd9..49cc207e1 100644
--- a/src/org/molgenis/Molgenis.java
+++ b/src/org/molgenis/Molgenis.java
@@ -81,7 +81,6 @@
import org.molgenis.generators.server.MolgenisGuiServiceGen;
import org.molgenis.generators.server.MolgenisResourceCopyGen;
import org.molgenis.generators.server.MolgenisServletContextGen;
-import org.molgenis.generators.server.MolgenisServletGen;
import org.molgenis.generators.server.RdfApiGen;
import org.molgenis.generators.server.RestApiGen;
import org.molgenis.generators.server.SoapApiGen;
@@ -113,49 +112,53 @@
*
* @author Morris Swertz
*/
-public class Molgenis {
-
- public static void main(String[] args) {
- try {
- if (args.length == 1)
- {
- new Molgenis(args[0]).generate();
- }
- else if(args.length == 2)
- {
- if(args[1].equals("--updatedb"))
- {
- new Molgenis(args[0]).updateDb(false);
- }
- else if(args[1].equals("--updatedbfillmeta"))
- {
- new Molgenis(args[0]).updateDb(true);
- }
- else
- {
- throw new Exception("Bad second argument: use either --updatedb or --updatedbfillmeta");
- }
- }
- else
- {
- throw new Exception("You have to provide the molgenis.properties file as first argument to generate Molgenis.\n" +
- "Alternatively, add the additional argument --updatedb OR --updatedbfillmeta to perform the update database action.\n" +
- "The --updatedbfillmeta will also insert the metadata into the database.\n" +
- "Your arguments:\n"
- + Arrays.toString(args));
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- protected transient static final Logger logger = Logger.getLogger("MOLGENIS");
- MolgenisOptions options = null;
- Model model = null;
- List generators = new ArrayList();
-
- public List getGenerators()
+public class Molgenis
+{
+
+ public static void main(String[] args)
+ {
+ try
+ {
+ if (args.length == 1)
+ {
+ new Molgenis(args[0]).generate();
+ }
+ else if (args.length == 2)
+ {
+ if (args[1].equals("--updatedb"))
+ {
+ new Molgenis(args[0]).updateDb(false);
+ }
+ else if (args[1].equals("--updatedbfillmeta"))
+ {
+ new Molgenis(args[0]).updateDb(true);
+ }
+ else
+ {
+ throw new Exception("Bad second argument: use either --updatedb or --updatedbfillmeta");
+ }
+ }
+ else
+ {
+ throw new Exception(
+ "You have to provide the molgenis.properties file as first argument to generate Molgenis.\n"
+ + "Alternatively, add the additional argument --updatedb OR --updatedbfillmeta to perform the update database action.\n"
+ + "The --updatedbfillmeta will also insert the metadata into the database.\n"
+ + "Your arguments:\n" + Arrays.toString(args));
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ protected transient static final Logger logger = Logger.getLogger("MOLGENIS");
+ MolgenisOptions options = null;
+ Model model = null;
+ List generators = new ArrayList();
+
+ public List getGenerators()
{
return generators;
}
@@ -165,655 +168,789 @@ public void setGenerators(List generators)
this.generators = generators;
}
- public Molgenis(String propertiesFile, Class extends Generator>... generatorsToUse) throws Exception {
- this(new MolgenisOptions(propertiesFile), generatorsToUse);
- }
-
- public Molgenis(String propertiesFile) throws Exception {
- this(new MolgenisOptions(propertiesFile), new Class[] {});
- }
-
- public Molgenis()
- {
- }
-
- public void init(String propertiesFile, Class extends Generator>... generatorsToUse) throws Exception
- {
- new Molgenis(new MolgenisOptions(propertiesFile), generatorsToUse);
- }
-
- /**
- * Construct a MOLGENIS generator
- *
- * @param options
- * with generator settings
- * @param generatorsToUse
- * optional list of generator classes to include
- * @throws Exception
- */
- public Molgenis(MolgenisOptions options,
- Class extends Generator>... generatorsToUse) throws Exception {
- BasicConfigurator.configure();
-
-
-
- this.loadFieldTypes();
-
- this.options = options;
-
- if(generatorsToUse != null && generatorsToUse.length > 0) {
+ public Molgenis(String propertiesFile, Class extends Generator>... generatorsToUse) throws Exception
+ {
+ this(new MolgenisOptions(propertiesFile), generatorsToUse);
+ }
+
+ public Molgenis(String propertiesFile) throws Exception
+ {
+ this(new MolgenisOptions(propertiesFile), new Class[]
+ {});
+ }
+
+ public Molgenis()
+ {
+ }
+
+ public void init(String propertiesFile, Class extends Generator>... generatorsToUse) throws Exception
+ {
+ new Molgenis(new MolgenisOptions(propertiesFile), generatorsToUse);
+ }
+
+ /**
+ * Construct a MOLGENIS generator
+ *
+ * @param options
+ * with generator settings
+ * @param generatorsToUse
+ * optional list of generator classes to include
+ * @throws Exception
+ */
+ public Molgenis(MolgenisOptions options, Class extends Generator>... generatorsToUse)
+ throws Exception
+ {
+ BasicConfigurator.configure();
+
+ this.loadFieldTypes();
+
+ this.options = options;
+
+ if (generatorsToUse != null && generatorsToUse.length > 0)
+ {
this.options.delete_generated_folder = false;
}
- Logger.getLogger("freemarker.cache").setLevel(Level.INFO);
- logger.info("\nMOLGENIS version " + org.molgenis.Version.convertToString());
- logger.info("working dir: " + System.getProperty("user.dir"));
-
- // clean options
- if (!options.output_src.endsWith("/")) {
- options.output_src = options.output_src + "/";
- }
- if (!options.output_python.endsWith("/")) {
- options.output_python = options.output_python + "/";
- }
- if (!options.output_cpp.endsWith("/")) {
- options.output_cpp = options.output_cpp + "/";
- }
- if (!options.output_hand.endsWith("/")) {
- options.output_hand = options.output_hand + "/";
- }
-
- //USED MOLGENIS OPTIONS
- generators.add(new UsedMolgenisOptionsGen());
-
- // COPY resources
- if (options.copy_resources) {
- generators.add(new MolgenisResourceCopyGen());
- }
-
- // DOCUMENTATION
- if (options.generate_doc) {
- //not used: generators.add(new TableDocGen());
- //not used: generators.add(new EntityModelDocGen());
- generators.add(new DotDocGen());
- generators.add(new FileFormatDocGen());
- generators.add(new DotDocMinimalGen());
- generators.add(new ObjectModelDocGen());
- generators.add(new DotDocModuleDependencyGen());
- //not used: generators.add(new TextUmlGen());
- } else {
- logger.info("Skipping documentation ....");
- }
-
- if (options.generate_cpp) {
- generators.add(new CPPCassette());
- }
-
- // TESTS
- if (options.generate_tests) {
- generators.add(new TestDatabaseGen());
- generators.add(new TestCsvGen());
- generators.add(new TestDataSetGen());
- } else {
- logger.info("Skipping Tests ....");
- }
- // DATA
- // generators.add(new DataPListGen());
- // generators.add(new ViewTypeGen());
-
-
- if (options.generate_sql) {
- if (options.mapper_implementation.equals(MapperImplementation.JPA)) {
- System.out.println("--------------JPAGEN--------------");
- generators.add(new JpaDatabaseGen());
- generators.add(new DataTypeGen());
- generators.add(new JpaMapperGen());
- generators.add(new JDBCMetaDatabaseGen());
-
- //generates Entity Listeners
- //JpaEntityListenerGen entityListGen = new JpaEntityListenerGen();
- //entityListGen.setHandwritten(true);
- //generators.add(entityListGen);
-
- if (options.generate_persistence) {
- generators.add(new PersistenceGen());
- }
-
- //generators.add(new FillMetadataTablesGen());
-
-
- } else {
- // DATABASE
- // mysql.org
- if (options.db_driver.equals("com.mysql.jdbc.Driver")) {
- generators.add(new MySqlCreateSubclassPerTableGen());
- generators.add(new MySqlAlterSubclassPerTableGen());
- // use multiquery optimization
- if (options.mapper_implementation.equals(MapperImplementation.MULTIQUERY)) {
- generators.add(new JDBCDatabaseGen());
- generators.add(new DataTypeGen());
- generators.add(new MultiqueryMapperGen());
- } else if (options.mapper_implementation.equals(MapperImplementation.PREPARED_STATEMENT)) {
- generators.add(new JDBCDatabaseGen());
- generators.add(new DataTypeGen());
- generators.add(new PStatementMapperGen());
- }
- } // hsqldb.org
- else if (options.db_driver.equals("oracle.jdbc.driver.OracleDriver")) {
- generators.add(new OracleCreateSubclassPerTableGen());
- generators.add(new JDBCDatabaseGen());
- generators.add(new DataTypeGen());
- generators.add(new PStatementMapperGen());
- }
- else if (options.db_driver.equals("org.hsqldb.jdbcDriver")) {
- logger.info("HsqlDB generators ....");
- generators.add(new JDBCDatabaseGen());
- generators.add(new DataTypeGen());
- generators.add(new HSqlCreateSubclassPerTableGen());
- //generators.add(new MultiqueryMapperGen());
- generators.add(new PStatementMapperGen());
- } // postgresql
- else if (options.db_driver.equals("org.postgresql.Driver")) {
- generators.add(new PSqlCreateSubclassPerTableGen());
- generators.add(new PStatementMapperGen());
- } // h2database.com, branch of hsqldb?
- else if (options.db_driver.equals("org.h2.Driver")) {
- generators.add(new HSqlCreateSubclassPerTableGen());
- generators.add(new PStatementMapperGen());
- } // derby, not functional ignore.
- else if (options.db_driver.equals("org.apache.derby.jdbc.EmbeddedDriver")) {
- generators.add(new DerbyCreateSubclassPerTableGen());
- } else {
- logger.warn("Unknown database driver " + options.db_driver);
- // System.exit(-1);
- }
-
- // test
- generators.add(new JDBCMetaDatabaseGen());
- // SQL
- generators.add(new CountPerEntityGen());
- generators.add(new CountPerTableGen());
- generators.add(new FillMetadataTablesGen());
- }
-
- generators.add(new FillMetadataGen());
-
- // authorization
- if (!options.auth_loginclass.endsWith("SimpleLogin")) {
- generators.add(new MapperSecurityDecoratorGen());
- }
-
- // decorators
- if(options.generate_decorators){
- generators.add(new MapperDecoratorGen());
- }
-
- // DatabaseFactory
- //if (!options.db_driver.equals("org.hsqldb.jdbcDriver")) {
- generators.add(new DatabaseFactoryGen());
- //}
- } else {
- logger.info("SEVERE: Skipping ALL SQL ....");
- }
-
-
- if (options.generate_Python) {
- generators.add(new PythonDataTypeGen());
- } else {
- logger.info("Skipping Python interface ....");
- }
- // generators.add(new HsqlDbGen());
-
- // CSV
- if (options.generate_csv) {
- generators.add(new CsvReaderGen());
- generators.add(new CsvImportByIdGen());
- generators.add(new CsvExportGen());
- generators.add(new CsvImportGen());
- } else {
- logger.info("Skipping CSV importers ....");
- }
- // generators.add(new CopyMemoryToDatabaseGen());
- // generators.add(new CsvReaderFactoryGen());
-
- // XML
- // generators.add(new XmlMapperGen());
-
- // R
- if (options.generate_R) {
- generators.add(new REntityGen());
- generators.add(new RMatrixGen());
- generators.add(new RApiGen());
- } else {
- logger.info("Skipping R interface ....");
- }
- // SCREEN
- if (options.generate_MolgenisServlet) {
- // SERVER SETTINGS
- generators.add(new MolgenisServletContextGen());
- generators.add(new MolgenisContextListenerGen());
- generators.add(new MolgenisServletGen());
- generators.add(new FrontControllerGen()); //will replace MolgenisServlet (service mapping, database & security)
- generators.add(new MolgenisGuiServiceGen()); //will replace MolgenisServlet (gui service)
-
- } else {
- logger.info("Skipping MolgenisServlet ....");
- }
-
- // HTML
- if (options.generate_html) {
- generators.add(new HtmlFormGen());
- generators.add(new FormControllerGen());
- generators.add(new MenuControllerGen());
- } else {
- logger.info("Skipping HTML (HTML,Form,Menu,Tree) ....");
- }
-
- // SCREEN PLUGIN
- if (options.generate_plugins) {
- //generators.add(new PluginControllerGen());
- //generators.add(new PluginScreenFTLTemplateGen());
- //generators.add(new PluginScreenJavaTemplateGen());
-
- //generators.add(new EasyPluginViewGen());
- generators.add(new EasyPluginControllerGen());
- //generators.add(new EasyPluginModelGen());
- } else {
- logger.info("Skipping generation of plugins ....");
- }
-
- //plugin controllers - always need these to map plugins in the GUI
- generators.add(new PluginControllerGen());
-
- // SOAP
- if (options.generate_soap) {
- generators.add(new SoapApiGen());
- } else {
- logger.info("Skipping SOAP API ....");
- }
-
- if (options.generate_rest) {
- generators.add(new RestApiGen());
- } else {
- logger.info("Skipping SOAP API ....");
- }
-
- if (options.generate_rdf) {
- generators.add(new RdfApiGen());
- } else {
- logger.info("Skipping SOAP API ....");
- }
-
- // Excel
- if (options.generate_ExcelImport) {
- generators.add(new ExcelReaderGen());
- generators.add(new ExcelImportGen());
- generators.add(new ExcelExportGen());
- generators.add(new ImportWizardExcelPrognosisGen());
- if (!options.generate_csv) {
- logger.info("Automatically including the CSV importers needed for Excel import");
- generators.add(new CsvReaderGen());
- generators.add(new CsvImportByIdGen());
- generators.add(new CsvExportGen());
- generators.add(new CsvImportGen());
- }
- } else {
- logger.info("Skipping Excel importer ....");
- }
- // RDF
-
-
- // FIXME add more generators
- // FIXME use configuration to add the generators
-
- // clean out generators
- List use = new ArrayList();
- if (!ArrayUtils.isEmpty(generatorsToUse)) {
- for (Class extends Generator> c : generatorsToUse) {
- use.add(c.newInstance());
- }
- generators = use;
- }
-
- logger.debug("\nUsing generators:\n" + toString());
-
- // parsing model
- model = MolgenisModel.parse(options);
- }
-
- private void loadFieldTypes() {
- MolgenisFieldTypes.addType(new BoolField());
- MolgenisFieldTypes.addType(new DateField());
- MolgenisFieldTypes.addType(new DatetimeField());
- MolgenisFieldTypes.addType(new DecimalField());
- MolgenisFieldTypes.addType(new EnumField());
- MolgenisFieldTypes.addType(new FileField());
- MolgenisFieldTypes.addType(new ImageField());
- MolgenisFieldTypes.addType(new HyperlinkField());
- // FieldTypeRegistry.addType(new ListField());
- MolgenisFieldTypes.addType(new LongField());
- MolgenisFieldTypes.addType(new MrefField());
- MolgenisFieldTypes.addType(new NSequenceField());
- MolgenisFieldTypes.addType(new OnoffField());
- MolgenisFieldTypes.addType(new StringField());
- MolgenisFieldTypes.addType(new TextField());
- MolgenisFieldTypes.addType(new XrefField());
- MolgenisFieldTypes.addType(new IntField());
- }
-
- /**
- * Apply all generators on the model
- *
- * @param model
- */
- public void generate() throws Exception {
- logger.info("generating ....");
- logger.info("\nUsing options:\n" + options.toString());
-
- File generatedFolder = new File(options.output_dir);
- if (generatedFolder.exists() && options.delete_generated_folder) {
- logger.info("removing previous generated folder " + generatedFolder);
- deleteContentOfDirectory(generatedFolder);
- }
-
- List threads = new ArrayList();
- for (final Generator g : generators) {
- Runnable runnable = new Runnable() {
-
- public void run() {
- try {
- g.generate(model, options);
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(-1);
- }
- }
- };
- //executor.execute(runnable);
- Thread thread = new Thread(runnable);
- thread.start();
- threads.add(thread);
- }
-
- //wait for all threads to complete
- for (Thread thread : threads) {
- try {
- thread.join();
- } catch (InterruptedException ignore) {
- }
- }
-
- logger.info("Generation completed at " + new Date());
- }
-
- /**
- * Deletes the content of directory (path), excluding hidden files like .svn
- * @param path of directory to delete
- * @return if and only if the content of directory (path) is successfully deleted; false otherwise
- */
- static public boolean deleteContentOfDirectory(File path) {
- boolean result = true;
- if (path.exists()) {
- File[] files = path.listFiles();
- for (File f : files) {
- if (!f.isHidden()) {
- if (f.isDirectory()) {
- result &= deleteContentOfDirectory(f);
- f.delete();
- } else {
- result &= f.delete();
- }
- }
- }
- }
- return result;
-
- }
-
- /**
- * Compile a generated molgenis.
- *
- * Currently not implemented but is needed for batch generation. Not needed
- * if you are generating inside an IDE such as eclipse.
- *
- * @return true if build is succesfull
- * @throws IOException
- */
- @Deprecated
- public boolean compile() throws IOException {
- // reduce loggin
- Logger.getLogger("org.apache.tools.ant.UnknownElement").setLevel(Level.ERROR);
- Logger.getLogger("org.apache.tools.ant.Target").setLevel(Level.ERROR);
-
- // run the ant build script
- logger.info("Compile ...");
-
- File tempdir = new File(options.output_src);
- // File tempdir = (File) ses.getAttribute("workingdir");
-
- // copy the buildfile from sjabloon
- File buildFileSource = new File("sjabloon/build.xml");
- File buildFile = new File(tempdir.getPath() + "/build.xml");
- copyFile(buildFileSource, buildFile);
-
- // create a new ant project
- Project p = new Project();
- p.setUserProperty("ant.file", buildFile.getAbsolutePath());
- p.init();
-
- // execute the ant target
- ProjectHelper helper = ProjectHelper.getProjectHelper();
- p.addReference("ant.projectHelper", helper);
- p.addBuildListener(new Log4jListener());
- helper.parse(p, buildFile);
-
- p.setProperty("jdbc.driver", "mysql-connector-java-5.1.0-bin.jar");
- p.setProperty("main.class", "MolgenisOnMysqlServer");
- p.executeTarget("createjar");
- logger.info("compilation complete.");
-
- return true;
- }
-
- private static void copyFile(File src, File dst) throws IOException {
- InputStream in = new FileInputStream(src);
- OutputStream out = new FileOutputStream(dst);
-
- // Transfer bytes from in to out
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- in.close();
- out.close();
- }
-
- /**
- * Parse the model using settings in options
- *
- * @param options
- * @return MOLGENIS model
- * @throws Exception
- */
-// private void parse() throws Exception {
-// MolgenisModel language = new MolgenisModel();
-// model = language.parse(options);
-// logger.debug("\nUsing metamodel:\n" + model);
-// }
- /**
- * Load the generated SQL into the database.
- *
- * Warning: this will overwrite any existing data in the database!.
- *
- * @throws SQLException
- * @throws FileNotFoundException
- * @throws IOException
- * @throws CmdLineException
- */
- public void updateDb() throws SQLException, FileNotFoundException,
- IOException {
- updateDb(false);
- }
-
- public void updateDb(boolean filldb) throws SQLException, FileNotFoundException,
- IOException {
-
- boolean ask = false;
-
- // ask for confirmation that the database can be updated
- // TODO: Use or throw away! Make a decision.
- while (ask) {
- logger.info("Are you sure that you want overwrite database "
- + options.db_uri
- + "?\n All existing data will be overwritten. \nAnswer 'y' or 'n'.\n");
- String answer = "";
- int c;
- while ((c = System.in.read()) != 13) {
- answer += (char) c;
- }
- if (answer.trim().equals("y")) {
- ask = false;
- } else if (answer.equals("n")) {
- logger.info("MOLGENIS database update canceled.\n");
- return;
- } else {
- logger.info("You must answer 'y' or 'n'.");
- }
- }
-
- // start loading
- BasicDataSource data_src = new BasicDataSource();
- Connection conn = null;
- try {
- data_src = new BasicDataSource();
- data_src.setDriverClassName(options.db_driver);
- data_src.setUsername(options.db_user);
- data_src.setPassword(options.db_password);
- data_src.setUrl(options.db_uri);
-
- conn = data_src.getConnection();
- String create_tables_file = options.output_sql + File.separator
- + "create_tables.sql";
- logger.debug("using file " + create_tables_file);
- // String create_tables_file = "generated" + File.separator + "sql"
- // + File.separator + "create_tables.sql";
-
- // READ THE FILE
- String create_tables_sql = "";
- try {
- BufferedReader in = new BufferedReader(new FileReader(create_tables_file));
- String line;
- while ((line = in.readLine()) != null) {
- create_tables_sql += line + "\n";
- }
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- if (filldb && StringUtils.isNotEmpty(this.options.getAuthLoginclass())) {
- String insert_metadata_file = options.output_sql + File.separator + "insert_metadata.sql";
- logger.debug("using file " + insert_metadata_file);
-
- // READ THE FILE
- try {
- BufferedReader in = new BufferedReader(new FileReader(insert_metadata_file));
- String line;
- while ((line = in.readLine()) != null) {
- create_tables_sql += line + "\n";
- }
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- Statement stmt = conn.createStatement();
- boolean error = false;
- logger.info("Updating database....");
- int i = 0;
-
- for (String command : create_tables_sql.split(";")) {
- if (command.trim().length() > 0) {
- try {
- logger.debug(command.trim() + ";");
- stmt.executeUpdate(command.trim() );
-
- if (i++ % 10 == 0) {
- logger.debug(".");
- }
- } catch (Exception e) {
- error = true;
- logger.error("\nERROR executing command: " + command
- + ";\n" + e.getMessage());
- }
-
- }
- }
-
- if (error) {
- logger.debug("Errors occurred. Make sure you provided sufficient rights! Inside mysql paste the following, assuming your database is called 'molgenis':"
- + "\ncreate database molgenis; "
- + "\ngrant all privileges on molgenis.* to molgenis@localhost "
- + "identified by 'molgenis';"
- + "\nflush privileges;"
- + "\nuse molgenis;");
- }
-
- logger.info("MOLGENIS database updated succesfully");
- } catch (Exception e) {
- logger.error(e);
-
- } finally {
- if (conn != null)
- {
- conn.close();
- }
- }
-
- }
-
- /**
- * Report current settings of the generator.
- */
- @Override
- public final String toString() {
- StringBuffer result = new StringBuffer();
-
- // get name, description and padding
- Map map = new LinkedHashMap();
- int padding = 0;
- for (Generator g : generators) {
- // get the name (without common path)
- String generatorName = null;
- if (g.getClass().getName().indexOf(this.getClass().getPackage().getName()) == 0) {
- generatorName = g.getClass().getName().substring(this.getClass().getPackage().getName().length() + 1);
- } else {
- generatorName = g.getClass().getName();
- }
-
- // calculate the padding
- padding = Math.max(padding, generatorName.length());
-
- // add to map
- map.put(generatorName, g.getDescription());
- }
-
- // print
- for (Map.Entry entry : map.entrySet()) {
- // create padding
- String spaces = "";
- for (int i = entry.getKey().toString().length(); i < padding; i++) {
- spaces += " ";
- }
- result.append(entry.getKey() + spaces + " #" + entry.getValue()
- + "\n");
- }
- return result.toString();
- }
-
- public MolgenisOptions getMolgenisOptions() {
- return this.options;
- }
+ Logger.getLogger("freemarker.cache").setLevel(Level.INFO);
+ logger.info("\nMOLGENIS version " + org.molgenis.Version.convertToString());
+ logger.info("working dir: " + System.getProperty("user.dir"));
+
+ // clean options
+ if (!options.output_src.endsWith("/"))
+ {
+ options.output_src = options.output_src + "/";
+ }
+ if (!options.output_python.endsWith("/"))
+ {
+ options.output_python = options.output_python + "/";
+ }
+ if (!options.output_cpp.endsWith("/"))
+ {
+ options.output_cpp = options.output_cpp + "/";
+ }
+ if (!options.output_hand.endsWith("/"))
+ {
+ options.output_hand = options.output_hand + "/";
+ }
+
+ // USED MOLGENIS OPTIONS
+ generators.add(new UsedMolgenisOptionsGen());
+
+ // COPY resources
+ if (options.copy_resources)
+ {
+ generators.add(new MolgenisResourceCopyGen());
+ }
+
+ // DOCUMENTATION
+ if (options.generate_doc)
+ {
+ // not used: generators.add(new TableDocGen());
+ // not used: generators.add(new EntityModelDocGen());
+ generators.add(new DotDocGen());
+ generators.add(new FileFormatDocGen());
+ generators.add(new DotDocMinimalGen());
+ generators.add(new ObjectModelDocGen());
+ generators.add(new DotDocModuleDependencyGen());
+ // not used: generators.add(new TextUmlGen());
+ }
+ else
+ {
+ logger.info("Skipping documentation ....");
+ }
+
+ if (options.generate_cpp)
+ {
+ generators.add(new CPPCassette());
+ }
+
+ // TESTS
+ if (options.generate_tests)
+ {
+ generators.add(new TestDatabaseGen());
+ generators.add(new TestCsvGen());
+ generators.add(new TestDataSetGen());
+ }
+ else
+ {
+ logger.info("Skipping Tests ....");
+ }
+ // DATA
+ // generators.add(new DataPListGen());
+ // generators.add(new ViewTypeGen());
+
+ if (options.generate_sql)
+ {
+ if (options.mapper_implementation.equals(MapperImplementation.JPA))
+ {
+ System.out.println("--------------JPAGEN--------------");
+ generators.add(new JpaDatabaseGen());
+ generators.add(new DataTypeGen());
+ generators.add(new JpaMapperGen());
+ generators.add(new JDBCMetaDatabaseGen());
+
+ // generates Entity Listeners
+ // JpaEntityListenerGen entityListGen = new
+ // JpaEntityListenerGen();
+ // entityListGen.setHandwritten(true);
+ // generators.add(entityListGen);
+
+ if (options.generate_persistence)
+ {
+ generators.add(new PersistenceGen());
+ }
+
+ // generators.add(new FillMetadataTablesGen());
+
+ }
+ else
+ {
+ // DATABASE
+ // mysql.org
+ if (options.db_driver.equals("com.mysql.jdbc.Driver"))
+ {
+ generators.add(new MySqlCreateSubclassPerTableGen());
+ generators.add(new MySqlAlterSubclassPerTableGen());
+ // use multiquery optimization
+ if (options.mapper_implementation.equals(MapperImplementation.MULTIQUERY))
+ {
+ generators.add(new JDBCDatabaseGen());
+ generators.add(new DataTypeGen());
+ generators.add(new MultiqueryMapperGen());
+ }
+ else if (options.mapper_implementation.equals(MapperImplementation.PREPARED_STATEMENT))
+ {
+ generators.add(new JDBCDatabaseGen());
+ generators.add(new DataTypeGen());
+ generators.add(new PStatementMapperGen());
+ }
+ } // hsqldb.org
+ else if (options.db_driver.equals("oracle.jdbc.driver.OracleDriver"))
+ {
+ generators.add(new OracleCreateSubclassPerTableGen());
+ generators.add(new JDBCDatabaseGen());
+ generators.add(new DataTypeGen());
+ generators.add(new PStatementMapperGen());
+ }
+ else if (options.db_driver.equals("org.hsqldb.jdbcDriver"))
+ {
+ logger.info("HsqlDB generators ....");
+ generators.add(new JDBCDatabaseGen());
+ generators.add(new DataTypeGen());
+ generators.add(new HSqlCreateSubclassPerTableGen());
+ // generators.add(new MultiqueryMapperGen());
+ generators.add(new PStatementMapperGen());
+ } // postgresql
+ else if (options.db_driver.equals("org.postgresql.Driver"))
+ {
+ generators.add(new PSqlCreateSubclassPerTableGen());
+ generators.add(new PStatementMapperGen());
+ } // h2database.com, branch of hsqldb?
+ else if (options.db_driver.equals("org.h2.Driver"))
+ {
+ generators.add(new HSqlCreateSubclassPerTableGen());
+ generators.add(new PStatementMapperGen());
+ } // derby, not functional ignore.
+ else if (options.db_driver.equals("org.apache.derby.jdbc.EmbeddedDriver"))
+ {
+ generators.add(new DerbyCreateSubclassPerTableGen());
+ }
+ else
+ {
+ logger.warn("Unknown database driver " + options.db_driver);
+ // System.exit(-1);
+ }
+
+ // test
+ generators.add(new JDBCMetaDatabaseGen());
+ // SQL
+ generators.add(new CountPerEntityGen());
+ generators.add(new CountPerTableGen());
+ generators.add(new FillMetadataTablesGen());
+ }
+
+ generators.add(new FillMetadataGen());
+
+ // authorization
+ if (!options.auth_loginclass.endsWith("SimpleLogin"))
+ {
+ generators.add(new MapperSecurityDecoratorGen());
+ }
+
+ // decorators
+ if (options.generate_decorators)
+ {
+ generators.add(new MapperDecoratorGen());
+ }
+
+ // DatabaseFactory
+ // if (!options.db_driver.equals("org.hsqldb.jdbcDriver")) {
+ generators.add(new DatabaseFactoryGen());
+ // }
+ }
+ else
+ {
+ logger.info("SEVERE: Skipping ALL SQL ....");
+ }
+
+ if (options.generate_Python)
+ {
+ generators.add(new PythonDataTypeGen());
+ }
+ else
+ {
+ logger.info("Skipping Python interface ....");
+ }
+ // generators.add(new HsqlDbGen());
+
+ // CSV
+ if (options.generate_csv)
+ {
+ generators.add(new CsvReaderGen());
+ generators.add(new CsvImportByIdGen());
+ generators.add(new CsvExportGen());
+ generators.add(new CsvImportGen());
+ }
+ else
+ {
+ logger.info("Skipping CSV importers ....");
+ }
+ // generators.add(new CopyMemoryToDatabaseGen());
+ // generators.add(new CsvReaderFactoryGen());
+
+ // XML
+ // generators.add(new XmlMapperGen());
+
+ // R
+ if (options.generate_R)
+ {
+ generators.add(new REntityGen());
+ generators.add(new RMatrixGen());
+ generators.add(new RApiGen());
+ }
+ else
+ {
+ logger.info("Skipping R interface ....");
+ }
+
+ // always generate frontcontroller
+ generators.add(new FrontControllerGen());
+
+ // also generate context (still used?)
+ generators.add(new MolgenisServletContextGen());
+ generators.add(new MolgenisContextListenerGen());
+
+ // optional: the GUI
+ if (options.generate_gui)
+ {
+ generators.add(new MolgenisGuiServiceGen());
+ }
+
+ // HTML
+ if (options.generate_html)
+ {
+ generators.add(new HtmlFormGen());
+ generators.add(new FormControllerGen());
+ generators.add(new MenuControllerGen());
+ }
+ else
+ {
+ logger.info("Skipping HTML (HTML,Form,Menu,Tree) ....");
+ }
+
+ // SCREEN PLUGIN
+ if (options.generate_plugins)
+ {
+ // generators.add(new PluginControllerGen());
+ // generators.add(new PluginScreenFTLTemplateGen());
+ // generators.add(new PluginScreenJavaTemplateGen());
+
+ // generators.add(new EasyPluginViewGen());
+ generators.add(new EasyPluginControllerGen());
+ // generators.add(new EasyPluginModelGen());
+ }
+ else
+ {
+ logger.info("Skipping generation of plugins ....");
+ }
+
+ // plugin controllers - always need these to map plugins in the GUI
+ generators.add(new PluginControllerGen());
+
+ // SOAP
+ if (options.generate_soap)
+ {
+ generators.add(new SoapApiGen());
+ }
+ else
+ {
+ logger.info("Skipping SOAP API ....");
+ }
+
+ if (options.generate_rest)
+ {
+ generators.add(new RestApiGen());
+ }
+ else
+ {
+ logger.info("Skipping SOAP API ....");
+ }
+
+ if (options.generate_rdf)
+ {
+ generators.add(new RdfApiGen());
+ }
+ else
+ {
+ logger.info("Skipping SOAP API ....");
+ }
+
+ // Excel
+ if (options.generate_ExcelImport)
+ {
+ generators.add(new ExcelReaderGen());
+ generators.add(new ExcelImportGen());
+ generators.add(new ExcelExportGen());
+ generators.add(new ImportWizardExcelPrognosisGen());
+ if (!options.generate_csv)
+ {
+ logger.info("Automatically including the CSV importers needed for Excel import");
+ generators.add(new CsvReaderGen());
+ generators.add(new CsvImportByIdGen());
+ generators.add(new CsvExportGen());
+ generators.add(new CsvImportGen());
+ }
+ }
+ else
+ {
+ logger.info("Skipping Excel importer ....");
+ }
+ // RDF
+
+ // FIXME add more generators
+ // FIXME use configuration to add the generators
+
+ // clean out generators
+ List use = new ArrayList();
+ if (!ArrayUtils.isEmpty(generatorsToUse))
+ {
+ for (Class extends Generator> c : generatorsToUse)
+ {
+ use.add(c.newInstance());
+ }
+ generators = use;
+ }
+
+ logger.debug("\nUsing generators:\n" + toString());
+
+ // parsing model
+ model = MolgenisModel.parse(options);
+ }
+
+ private void loadFieldTypes()
+ {
+ MolgenisFieldTypes.addType(new BoolField());
+ MolgenisFieldTypes.addType(new DateField());
+ MolgenisFieldTypes.addType(new DatetimeField());
+ MolgenisFieldTypes.addType(new DecimalField());
+ MolgenisFieldTypes.addType(new EnumField());
+ MolgenisFieldTypes.addType(new FileField());
+ MolgenisFieldTypes.addType(new ImageField());
+ MolgenisFieldTypes.addType(new HyperlinkField());
+ // FieldTypeRegistry.addType(new ListField());
+ MolgenisFieldTypes.addType(new LongField());
+ MolgenisFieldTypes.addType(new MrefField());
+ MolgenisFieldTypes.addType(new NSequenceField());
+ MolgenisFieldTypes.addType(new OnoffField());
+ MolgenisFieldTypes.addType(new StringField());
+ MolgenisFieldTypes.addType(new TextField());
+ MolgenisFieldTypes.addType(new XrefField());
+ MolgenisFieldTypes.addType(new IntField());
+ }
+
+ /**
+ * Apply all generators on the model
+ *
+ * @param model
+ */
+ public void generate() throws Exception
+ {
+ logger.info("generating ....");
+ logger.info("\nUsing options:\n" + options.toString());
+
+ File generatedFolder = new File(options.output_dir);
+ if (generatedFolder.exists() && options.delete_generated_folder)
+ {
+ logger.info("removing previous generated folder " + generatedFolder);
+ deleteContentOfDirectory(generatedFolder);
+ }
+
+ List threads = new ArrayList();
+ for (final Generator g : generators)
+ {
+ Runnable runnable = new Runnable()
+ {
+
+ public void run()
+ {
+ try
+ {
+ g.generate(model, options);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ }
+ };
+ // executor.execute(runnable);
+ Thread thread = new Thread(runnable);
+ thread.start();
+ threads.add(thread);
+ }
+
+ // wait for all threads to complete
+ for (Thread thread : threads)
+ {
+ try
+ {
+ thread.join();
+ }
+ catch (InterruptedException ignore)
+ {
+ }
+ }
+
+ logger.info("Generation completed at " + new Date());
+ }
+
+ /**
+ * Deletes the content of directory (path), excluding hidden files like .svn
+ *
+ * @param path
+ * of directory to delete
+ * @return if and only if the content of directory (path) is successfully
+ * deleted; false otherwise
+ */
+ static public boolean deleteContentOfDirectory(File path)
+ {
+ boolean result = true;
+ if (path.exists())
+ {
+ File[] files = path.listFiles();
+ for (File f : files)
+ {
+ if (!f.isHidden())
+ {
+ if (f.isDirectory())
+ {
+ result &= deleteContentOfDirectory(f);
+ f.delete();
+ }
+ else
+ {
+ result &= f.delete();
+ }
+ }
+ }
+ }
+ return result;
+
+ }
+
+ /**
+ * Compile a generated molgenis.
+ *
+ * Currently not implemented but is needed for batch generation. Not needed
+ * if you are generating inside an IDE such as eclipse.
+ *
+ * @return true if build is succesfull
+ * @throws IOException
+ */
+ @Deprecated
+ public boolean compile() throws IOException
+ {
+ // reduce loggin
+ Logger.getLogger("org.apache.tools.ant.UnknownElement").setLevel(Level.ERROR);
+ Logger.getLogger("org.apache.tools.ant.Target").setLevel(Level.ERROR);
+
+ // run the ant build script
+ logger.info("Compile ...");
+
+ File tempdir = new File(options.output_src);
+ // File tempdir = (File) ses.getAttribute("workingdir");
+
+ // copy the buildfile from sjabloon
+ File buildFileSource = new File("sjabloon/build.xml");
+ File buildFile = new File(tempdir.getPath() + "/build.xml");
+ copyFile(buildFileSource, buildFile);
+
+ // create a new ant project
+ Project p = new Project();
+ p.setUserProperty("ant.file", buildFile.getAbsolutePath());
+ p.init();
+
+ // execute the ant target
+ ProjectHelper helper = ProjectHelper.getProjectHelper();
+ p.addReference("ant.projectHelper", helper);
+ p.addBuildListener(new Log4jListener());
+ helper.parse(p, buildFile);
+
+ p.setProperty("jdbc.driver", "mysql-connector-java-5.1.0-bin.jar");
+ p.setProperty("main.class", "MolgenisOnMysqlServer");
+ p.executeTarget("createjar");
+ logger.info("compilation complete.");
+
+ return true;
+ }
+
+ private static void copyFile(File src, File dst) throws IOException
+ {
+ InputStream in = new FileInputStream(src);
+ OutputStream out = new FileOutputStream(dst);
+
+ // Transfer bytes from in to out
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0)
+ {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ }
+
+ /**
+ * Parse the model using settings in options
+ *
+ * @param options
+ * @return MOLGENIS model
+ * @throws Exception
+ */
+ // private void parse() throws Exception {
+ // MolgenisModel language = new MolgenisModel();
+ // model = language.parse(options);
+ // logger.debug("\nUsing metamodel:\n" + model);
+ // }
+ /**
+ * Load the generated SQL into the database.
+ *
+ * Warning: this will overwrite any existing data in the database!.
+ *
+ * @throws SQLException
+ * @throws FileNotFoundException
+ * @throws IOException
+ * @throws CmdLineException
+ */
+ public void updateDb() throws SQLException, FileNotFoundException, IOException
+ {
+ updateDb(false);
+ }
+
+ public void updateDb(boolean filldb) throws SQLException, FileNotFoundException, IOException
+ {
+
+ boolean ask = false;
+
+ // ask for confirmation that the database can be updated
+ // TODO: Use or throw away! Make a decision.
+ while (ask)
+ {
+ logger.info("Are you sure that you want overwrite database " + options.db_uri
+ + "?\n All existing data will be overwritten. \nAnswer 'y' or 'n'.\n");
+ StringBuilder answerBuilder = new StringBuilder();
+ int c;
+ while ((c = System.in.read()) != 13)
+ {
+ answerBuilder.append((char) c);
+ }
+ String answer = answerBuilder.toString().trim();
+ if (answer.trim().equals("y"))
+ {
+ ask = false;
+ }
+ else if (answer.equals("n"))
+ {
+ logger.info("MOLGENIS database update canceled.\n");
+ return;
+ }
+ else
+ {
+ logger.info("You must answer 'y' or 'n'.");
+ }
+ }
+
+ // start loading
+ BasicDataSource data_src = new BasicDataSource();
+ Statement stmt = null;
+ Connection conn = null;
+ try
+ {
+ data_src = new BasicDataSource();
+ data_src.setDriverClassName(options.db_driver);
+ data_src.setUsername(options.db_user);
+ data_src.setPassword(options.db_password);
+ data_src.setUrl(options.db_uri);
+
+ conn = data_src.getConnection();
+ String create_tables_file = options.output_sql + File.separator + "create_tables.sql";
+ logger.debug("using file " + create_tables_file);
+ // String create_tables_file = "generated" + File.separator + "sql"
+ // + File.separator + "create_tables.sql";
+
+ // READ THE FILE
+ StringBuilder create_tables_sqlBuilder = new StringBuilder();
+ try
+ {
+ BufferedReader in = new BufferedReader(new FileReader(create_tables_file));
+ String line;
+ while ((line = in.readLine()) != null)
+ {
+ create_tables_sqlBuilder.append(line).append('\n');
+ }
+ in.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+
+ if (filldb && StringUtils.isNotEmpty(this.options.getAuthLoginclass()))
+ {
+ String insert_metadata_file = options.output_sql + File.separator + "insert_metadata.sql";
+ logger.debug("using file " + insert_metadata_file);
+
+ // READ THE FILE
+ try
+ {
+ BufferedReader in = new BufferedReader(new FileReader(insert_metadata_file));
+ String line;
+ while ((line = in.readLine()) != null)
+ {
+ create_tables_sqlBuilder.append(line).append('\n');
+ }
+ in.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ stmt = conn.createStatement();
+ boolean error = false;
+ logger.info("Updating database....");
+ int i = 0;
+
+ String create_tables_sql = create_tables_sqlBuilder.toString();
+ for (String command : create_tables_sql.split(";"))
+ {
+ if (command.trim().length() > 0)
+ {
+ try
+ {
+ logger.debug(command.trim() + ";");
+ stmt.executeUpdate(command.trim());
+
+ if (i++ % 10 == 0)
+ {
+ logger.debug(".");
+ }
+ }
+ catch (Exception e)
+ {
+ error = true;
+ logger.error("\nERROR executing command: " + command + ";\n" + e.getMessage());
+ }
+
+ }
+ }
+
+ if (error)
+ {
+ logger.debug("Errors occurred. Make sure you provided sufficient rights! Inside mysql paste the following, assuming your database is called 'molgenis':"
+ + "\ncreate database molgenis; "
+ + "\ngrant all privileges on molgenis.* to molgenis@localhost "
+ + "identified by 'molgenis';"
+ + "\nflush privileges;" + "\nuse molgenis;");
+ }
+
+ logger.info("MOLGENIS database updated succesfully");
+ }
+ catch (Exception e)
+ {
+ logger.error(e);
+
+ }
+ finally
+ {
+ if (stmt != null)
+ {
+ try
+ {
+ stmt.close();
+ }
+ catch (SQLException e)
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+ }
+
+ }
+
+ /**
+ * Report current settings of the generator.
+ */
+ @Override
+ public final String toString()
+ {
+ StringBuffer result = new StringBuffer();
+
+ // get name, description and padding
+ Map map = new LinkedHashMap();
+ int padding = 0;
+ for (Generator g : generators)
+ {
+ // get the name (without common path)
+ String generatorName = null;
+ if (g.getClass().getName().indexOf(this.getClass().getPackage().getName()) == 0)
+ {
+ generatorName = g.getClass().getName().substring(this.getClass().getPackage().getName().length() + 1);
+ }
+ else
+ {
+ generatorName = g.getClass().getName();
+ }
+
+ // calculate the padding
+ padding = Math.max(padding, generatorName.length());
+
+ // add to map
+ map.put(generatorName, g.getDescription());
+ }
+
+ // print
+ for (Map.Entry entry : map.entrySet())
+ {
+ // create padding
+ String spaces = "";
+ for (int i = entry.getKey().toString().length(); i < padding; i++)
+ {
+ spaces += " ";
+ }
+ result.append(entry.getKey() + spaces + " #" + entry.getValue() + "\n");
+ }
+ return result.toString();
+ }
+
+ public MolgenisOptions getMolgenisOptions()
+ {
+ return this.options;
+ }
}
\ No newline at end of file
diff --git a/src/org/molgenis/MolgenisFieldTypes.java b/src/org/molgenis/MolgenisFieldTypes.java
index f50db4fa1..ddf5686af 100644
--- a/src/org/molgenis/MolgenisFieldTypes.java
+++ b/src/org/molgenis/MolgenisFieldTypes.java
@@ -44,7 +44,7 @@ public class MolgenisFieldTypes
public enum FieldTypeEnum
{
- BOOL, CHAR, DATE, DATE_TIME, DECIMAL, ENUM, EMAIL, FILE, FREEMARKER, HEXA, HYPERLINK, IMAGE, INT, LIST, LONG, MREF, NSEQUENCE, ON_OFF, RICHTEXT, STRING, TEXT, XREF, CATEGORICAL, UNKNOWN,
+ BOOL, CHAR, DATE, DATE_TIME, DECIMAL, ENUM, EMAIL, FILE, FREEMARKER, HEXA, HYPERLINK, IMAGE, INT, LIST, LONG, MREF, NSEQUENCE, ON_OFF, STRING, TEXT, LONGTEXT, XREF, CATEGORICAL, UNKNOWN, RICHTEXT
}
/** Initialize default field types */
@@ -70,6 +70,7 @@ private static void init()
addType(new XrefField());
addType(new IntField());
addType(new RichtextField());
+ // addType(new LongTextField());
addType(new FreemarkerField());
init = true;
diff --git a/src/org/molgenis/MolgenisOptions.java b/src/org/molgenis/MolgenisOptions.java
index 261dc5400..55abb2422 100644
--- a/src/org/molgenis/MolgenisOptions.java
+++ b/src/org/molgenis/MolgenisOptions.java
@@ -4,6 +4,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -11,6 +12,7 @@
import java.util.Map;
import java.util.Properties;
+import org.apache.commons.io.IOUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.molgenis.framework.ui.html.render.LinkoutRenderDecorator;
@@ -41,10 +43,10 @@ public enum MapperImplementation
{
MULTIQUERY, JPA, PREPARED_STATEMENT, UNKNOWN
}
-
+
/**
* Possible log4j log targets
- *
+ *
*/
public enum LogTarget
{
@@ -53,7 +55,7 @@ public enum LogTarget
/** Properties file where this data came from */
private String molgenis_properties = "";
-
+
/** Password file where passwords are */
private String molgenis_passwd = "";
@@ -159,13 +161,13 @@ public enum LogTarget
@Option(name = "generate_persistence", param = Option.Param.STRING, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Expert option: Choosing the JPA persistence unit name from the persistence.xml that is used by molgenis. Default: molgenis")
public String jpa_persistenceUnitName = "molgenis";
-
+
@Option(name = "generate_persistence", param = Option.Param.BOOLEAN, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Expert option: Choosing whether persistence.xml is generated by molgenis (true) or supplied by user (false). Default: true")
public boolean generate_persistence = true;
-
+
@Option(name = "hibernate_dialect", param = Option.Param.STRING, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Expert option: Choosing the JPA dialect for persistence.xml. Default: MySQL5Dialect")
public String hibernate_dialect = "MySQL5Dialect";
-
+
@Option(name = "jpa_use_sequence", param = Option.Param.BOOLEAN, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Expert option: Choosing whether sequence are used to generate primary key (true) or auto (false: default)")
public boolean jpa_use_sequence = false;
@@ -228,8 +230,8 @@ public enum LogTarget
@Option(name = "generate_ExcelImport", param = Option.Param.BOOLEAN, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Should Excel file importing be generated. Default: true.")
public boolean generate_ExcelImport = true;
- @Option(name = "generate_MolgenisServlet", param = Option.Param.BOOLEAN, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Should The molgenisServlet be generated or does the user supply ones own. Default: true.")
- public boolean generate_MolgenisServlet = true;
+ @Option(name = "generate_gui", param = Option.Param.BOOLEAN, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Should the GUI service be generated. Default: true.")
+ public boolean generate_gui = true;
@Option(name = "db_mode", param = Option.Param.STRING, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Which mode should the molgenisServlet use when contacting the dabase. Default: 'servlet'")
public String db_mode = "servlet";
@@ -274,25 +276,29 @@ public enum LogTarget
// default set to false as partial generation leads to compile problems in
// for example molgenis_apps
public boolean delete_generated_folder = true;
-
+
@Option(name = "authorizable", param = Option.Param.COLLECTION, type = Option.Type.OPTIONAL_ARGUMENT, usage = "For use in molgenis_apps! Tells the generator on which entities to append an implements='Authorizable'. Default: new ArrayList()")
public ArrayList authorizable = new ArrayList();
-
+
@Option(name = "services", param = Option.Param.COLLECTION, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Register services to the FrontController. (replaces webserver mappings and MolgenisServlet) Default: new ArrayList()")
public ArrayList services = new ArrayList();
- @Option(name = "disable_decorators", param = Option.Param.BOOLEAN, type = Option.Type.OPTIONAL_ARGUMENT, usage="disables all decorators for generated test")
+ @Option(name = "disable_decorators", param = Option.Param.BOOLEAN, type = Option.Type.OPTIONAL_ARGUMENT, usage = "disables all decorators for generated test")
public boolean disable_decorators = false;
-
- @Option(name = "log4j_properties_uri", param = Option.Param.STRING, type = Type.OPTIONAL_ARGUMENT, usage="specify the location of the log4j.properties file that Molgenis should use, if not specified than log_level and log_target properties are used instead")
+
+ @Option(name = "log4j_properties_uri", param = Option.Param.STRING, type = Type.OPTIONAL_ARGUMENT, usage = "specify the location of the log4j.properties file that Molgenis should use, if not specified than log_level and log_target properties are used instead")
public String log4j_properties_uri = "";
-
- /** The log level of log4j used by your application. Used by FrontController. **/
- @Option(name = "log_level", param = Option.Param.LOG4JLEVEL, type = Option.Type.OPTIONAL_ARGUMENT, usage="Use this log level to initialize log4j. Default: debug")
+
+ /**
+ * The log level of log4j used by your application. Used by FrontController.
+ **/
+ @Option(name = "log_level", param = Option.Param.LOG4JLEVEL, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Use this log level to initialize log4j. Default: debug")
public Level log_level = Level.INFO;
-
- /** The log level of log4j used by your application. Used by FrontController. **/
- @Option(name = "log_target", param = Option.Param.ENUM, type = Option.Type.OPTIONAL_ARGUMENT, usage="Use this log target to initialize log4j. Default: console")
+
+ /**
+ * The log level of log4j used by your application. Used by FrontController.
+ **/
+ @Option(name = "log_target", param = Option.Param.ENUM, type = Option.Type.OPTIONAL_ARGUMENT, usage = "Use this log target to initialize log4j. Default: console")
public LogTarget log_target = LogTarget.CONSOLE;
@Option(name = "hibernate_search_index_base", param = Option.Param.STRING, type = Type.OPTIONAL_ARGUMENT, usage = "Directory where the full text index is created. Default: /tmp/lucene")
@@ -366,68 +372,83 @@ public Map getOptionsAsMap() throws Exception
* @throws FileNotFoundException
* @throws CmdLineException
*/
- public MolgenisOptions(String propertiesFile) throws FileNotFoundException,
- IOException, CmdLineException
+ public MolgenisOptions(String propertiesFile) throws FileNotFoundException, IOException, CmdLineException
{
this.molgenis_properties = propertiesFile;
Properties props = new Properties();
+ InputStream is = null;
try
{
// try to load from local files
- props.load(new FileInputStream(propertiesFile.trim()));
+ is = new FileInputStream(propertiesFile.trim());
+ props.load(is);
}
catch (FileNotFoundException e)
{
+ InputStream is2 = ClassLoader.getSystemResourceAsStream(propertiesFile.trim());
try
{
// try to load from classpath
- props.load(ClassLoader.getSystemResourceAsStream(propertiesFile
- .trim()));
+ props.load(is2);
}
catch (Exception e2)
{
- throw new IOException("couldn't find file "
- + new File(propertiesFile).getAbsolutePath());
+ throw new IOException("couldn't find file " + new File(propertiesFile).getAbsolutePath());
}
-
+ finally
+ {
+ IOUtils.closeQuietly(is2);
+ }
+ }
+ finally
+ {
+ IOUtils.closeQuietly(is);
}
CmdLineParser parser = new CmdLineParser(this);
parser.parse(props);
this.molgenis_properties = propertiesFile;
-
- //parse passwordfile
+
+ // parse passwordfile
String passwordFile = propertiesFile.replace(".properties", ".passwd");
- this.molgenis_passwd= passwordFile;
+ this.molgenis_passwd = passwordFile;
props = new Properties();
+ is = null;
try
{
// try to load from local files
- props.load(new FileInputStream(passwordFile.trim()));
+ is = new FileInputStream(passwordFile.trim());
+ props.load(is);
}
catch (FileNotFoundException e)
{
+ InputStream is2 = ClassLoader.getSystemResourceAsStream(passwordFile.trim());
try
{
// try to load from classpath
- props.load(ClassLoader.getSystemResourceAsStream(passwordFile
- .trim()));
+ props.load(is2);
}
catch (Exception e2)
{
- //no biggie
+ // no biggie
}
-
+ finally
+ {
+ IOUtils.closeQuietly(is2);
+ }
+ }
+ finally
+ {
+ IOUtils.closeQuietly(is);
}
parser = new CmdLineParser(this);
parser.parse(props);
-
- //warn if no password was provided
- if("".equals(this.db_password))
- System.err.println("WARNING: db_password was not provided in neither "+propertiesFile +" nor "+passwordFile);
- Logger.getLogger(this.getClass().getSimpleName()).debug(
- "parsed properties file.");
+ // warn if no password was provided
+ if ("".equals(this.db_password)) System.err.println("WARNING: db_password was not provided in neither "
+ + propertiesFile + " nor " + passwordFile);
+
+ Logger.getLogger(this.getClass().getSimpleName()).debug("parsed properties file.");
}
/**
@@ -445,15 +466,13 @@ public MolgenisOptions(Properties properties)
{
parser = new CmdLineParser(this);
parser.parse(properties);
- Logger.getLogger(this.getClass().getSimpleName()).debug(
- "parsed properties file.");
+ Logger.getLogger(this.getClass().getSimpleName()).debug("parsed properties file.");
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
- throw new RuntimeException("Cannot find property file: "
- + e.getMessage());
+ throw new RuntimeException("Cannot find property file: " + e.getMessage());
}
}
@@ -473,12 +492,14 @@ public String toString()
}
return "";
}
-
- public String getHibernateDialect() {
+
+ public String getHibernateDialect()
+ {
return this.hibernate_dialect;
}
- public String getHibernateSearchIndexBase() {
+ public String getHibernateSearchIndexBase()
+ {
return this.hibernate_search_index_base;
}
@@ -644,8 +665,7 @@ public MapperImplementation getMapperImplementation()
return mapper_implementation;
}
- public void setMapperImplementation(
- MapperImplementation mapper_implementation)
+ public void setMapperImplementation(MapperImplementation mapper_implementation)
{
this.mapper_implementation = mapper_implementation;
}
@@ -743,6 +763,4 @@ public void setLog4j_properties_uri(String log4j_properties_uri)
this.log4j_properties_uri = log4j_properties_uri;
}
-
-
}
diff --git a/src/org/molgenis/Version.java b/src/org/molgenis/Version.java
index 325ee782d..a10cdcbad 100644
--- a/src/org/molgenis/Version.java
+++ b/src/org/molgenis/Version.java
@@ -14,7 +14,7 @@
* api.
*/
public class Version
-{
+{
// static members
/**
* The major part of the version, which is changed for major interface
@@ -30,18 +30,16 @@ public class Version
/** The maintenance part of the version, which is changed for bug-fixes */
public static final int MAINTENANCE = 0;
-
- /** Flag to indicate that this is a testing release*/
- public static final boolean TESTING = true;
+ /** Flag to indicate that this is a testing release */
+ public static final boolean TESTING = true;
// static access methods
/** string representation of the version */
public static String convertToString()
{
- if(!TESTING)
- return "" + MAJOR + "." + MINOR + "." + MAINTENANCE ;
+ if (!TESTING) return "" + MAJOR + "." + MINOR + "." + MAINTENANCE;
else
- return "" + MAJOR +"."+MINOR +"."+MAINTENANCE +"-testing";
+ return "" + MAJOR + "." + MINOR + "." + MAINTENANCE + "-testing";
}
}
diff --git a/src/org/molgenis/fieldtypes/BoolField.java b/src/org/molgenis/fieldtypes/BoolField.java
index d6ed29897..ab284ecea 100644
--- a/src/org/molgenis/fieldtypes/BoolField.java
+++ b/src/org/molgenis/fieldtypes/BoolField.java
@@ -13,14 +13,14 @@ public String getJavaPropertyType()
{
return "Boolean";
}
-
+
@Override
public String getJavaAssignment(String value)
{
- if(value == null || value.equals("")) return "null";
- return ""+Boolean.parseBoolean(value.toString());
+ if (value == null || value.equals("")) return "null";
+ return "" + Boolean.parseBoolean(value.toString());
}
-
+
@Override
public String getJavaPropertyDefault()
{
@@ -32,7 +32,7 @@ public String getMysqlType() throws MolgenisModelException
{
return "BOOL";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
@@ -44,7 +44,7 @@ public String getHsqlType()
{
return "INTEGER";
}
-
+
@Override
public String getXsdType()
{
@@ -79,8 +79,9 @@ public Class> getJavaType()
{
return Boolean.class;
}
-
- public Boolean getTypedValue(String value) {
+
+ public Boolean getTypedValue(String value)
+ {
return Boolean.parseBoolean(value);
}
diff --git a/src/org/molgenis/fieldtypes/CategoricalType.java b/src/org/molgenis/fieldtypes/CategoricalType.java
index fa6333578..2bdffc8d6 100644
--- a/src/org/molgenis/fieldtypes/CategoricalType.java
+++ b/src/org/molgenis/fieldtypes/CategoricalType.java
@@ -112,9 +112,11 @@ public FieldTypeEnum getEnumType()
}
/**
- * @return For a categorical variable type, return the map of value->label pairs.
+ * @return For a categorical variable type, return the map of value->label
+ * pairs.
*/
- public Map getCategoryMapping() {
+ public Map getCategoryMapping()
+ {
return categoryMapping;
}
}
diff --git a/src/org/molgenis/fieldtypes/CharField.java b/src/org/molgenis/fieldtypes/CharField.java
index a36b5da7e..ecd4b3148 100644
--- a/src/org/molgenis/fieldtypes/CharField.java
+++ b/src/org/molgenis/fieldtypes/CharField.java
@@ -15,10 +15,10 @@ public class CharField extends FieldType
@Override
public String getJavaAssignment(String value) throws MolgenisModelException
{
- if(value == null || value.equals("") ) return "null";
- return "\""+value+"\"";
+ if (value == null || value.equals("")) return "null";
+ return "\"" + value + "\"";
}
-
+
@Override
public String getJavaPropertyDefault() throws MolgenisModelException
{
@@ -34,20 +34,21 @@ public String getJavaPropertyType() throws MolgenisModelException
@Override
public String getMysqlType() throws MolgenisModelException
{
- return "CHAR("+f.getVarCharLength()+")";
+ return "CHAR(" + f.getVarCharLength() + ")";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
- return "CHAR("+f.getVarCharLength()+")";
+ return "CHAR(" + f.getVarCharLength() + ")";
}
@Override
public String getHsqlType() throws MolgenisModelException
{
- return "CHAR("+f.getVarCharLength()+")";
+ return "CHAR(" + f.getVarCharLength() + ")";
}
+
@Override
public String getXsdType() throws MolgenisModelException
{
@@ -61,7 +62,7 @@ public String getFormatString()
}
@Override
- public HtmlInput> createInput(String name, String xrefEntityClassName) throws HtmlInputException
+ public HtmlInput> createInput(String name, String xrefEntityClassName) throws HtmlInputException
{
return new StringInput(name);
}
@@ -93,7 +94,7 @@ public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.CHAR;
}
-
+
@Override
public List getAllowedOperators()
{
diff --git a/src/org/molgenis/fieldtypes/DateField.java b/src/org/molgenis/fieldtypes/DateField.java
index c4868518d..bdcc5914c 100644
--- a/src/org/molgenis/fieldtypes/DateField.java
+++ b/src/org/molgenis/fieldtypes/DateField.java
@@ -19,19 +19,20 @@ public String getJavaPropertyType() throws MolgenisModelException
{
return "java.util.Date";
}
-
+
@Override
public String getJavaAssignment(String value)
{
- if(value == null || value.equals("")) return "null";
- return "java.sql.Date.valueOf(\""+value+"\")";
+ if (value == null || value.equals("")) return "null";
+ return "java.sql.Date.valueOf(\"" + value + "\")";
}
-
+
@Override
public String getJavaPropertyDefault()
{
- if(f.isAuto()) return "new java.sql.Date(new java.util.Date().getTime())";
- else return getJavaAssignment(f.getDefaultValue());
+ if (f.isAuto()) return "new java.sql.Date(new java.util.Date().getTime())";
+ else
+ return getJavaAssignment(f.getDefaultValue());
}
@Override
@@ -39,13 +40,13 @@ public String getMysqlType() throws MolgenisModelException
{
return "DATE";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
return "DATE";
}
-
+
@Override
public String getJavaSetterType() throws MolgenisModelException
{
@@ -57,6 +58,7 @@ public String getHsqlType()
{
return "DATE";
}
+
@Override
public String getXsdType()
{
@@ -80,7 +82,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "time_t";
}
-
+
@Override
public String getCppJavaPropertyType()
{
@@ -101,7 +103,7 @@ public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.DATE;
}
-
+
@Override
public List getAllowedOperators()
{
diff --git a/src/org/molgenis/fieldtypes/DatetimeField.java b/src/org/molgenis/fieldtypes/DatetimeField.java
index 4738b16de..fc7452ecf 100644
--- a/src/org/molgenis/fieldtypes/DatetimeField.java
+++ b/src/org/molgenis/fieldtypes/DatetimeField.java
@@ -19,19 +19,20 @@ public String getJavaPropertyType() throws MolgenisModelException
{
return "java.util.Date";
}
-
+
@Override
public String getJavaAssignment(String value)
{
- if(value == null || value.equals("")) return "null";
- return "java.sql.Timestamp.valueOf(\""+value+"\")";
+ if (value == null || value.equals("")) return "null";
+ return "java.sql.Timestamp.valueOf(\"" + value + "\")";
}
-
+
@Override
public String getJavaPropertyDefault()
{
- if(f.isAuto()) return "new java.sql.Date(new java.util.Date().getTime())";
- else return getJavaAssignment(f.getDefaultValue());
+ if (f.isAuto()) return "new java.sql.Date(new java.util.Date().getTime())";
+ else
+ return getJavaAssignment(f.getDefaultValue());
}
@Override
@@ -39,13 +40,13 @@ public String getMysqlType() throws MolgenisModelException
{
return "DATETIME";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
return "DATE";
}
-
+
@Override
public String getXsdType()
{
@@ -81,7 +82,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "time_t";
}
-
+
@Override
public String getCppJavaPropertyType()
{
@@ -97,12 +98,12 @@ public Date getTypedValue(String value) throws ParseException
{
return new SimpleDateFormat("yyyy.MM.dd G HH:mm:ss").parse(value);
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.DATE_TIME;
}
-
+
@Override
public List getAllowedOperators()
{
diff --git a/src/org/molgenis/fieldtypes/DecimalField.java b/src/org/molgenis/fieldtypes/DecimalField.java
index e9d01a852..52eea543a 100644
--- a/src/org/molgenis/fieldtypes/DecimalField.java
+++ b/src/org/molgenis/fieldtypes/DecimalField.java
@@ -22,22 +22,22 @@ public String getJavaPropertyType()
@Override
public String getJavaAssignment(String value)
{
- if(value == null || value.equals("") ) return "null";
- return ""+Double.parseDouble(value);
+ if (value == null || value.equals("")) return "null";
+ return "" + Double.parseDouble(value);
}
-
+
@Override
public String getJavaPropertyDefault()
{
return getJavaAssignment(f.getDefaultValue());
}
-
+
@Override
public String getMysqlType() throws MolgenisModelException
{
return "DECIMAL(65,30)";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
@@ -49,7 +49,7 @@ public String getHsqlType()
{
return "DOUBLE";
}
-
+
@Override
public String getXsdType()
{
@@ -89,12 +89,12 @@ public Double getTypedValue(String value) throws ParseException
{
return Double.parseDouble(value);
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.DECIMAL;
}
-
+
@Override
public List getAllowedOperators()
{
diff --git a/src/org/molgenis/fieldtypes/EmailField.java b/src/org/molgenis/fieldtypes/EmailField.java
index 035f71848..495fd1452 100644
--- a/src/org/molgenis/fieldtypes/EmailField.java
+++ b/src/org/molgenis/fieldtypes/EmailField.java
@@ -13,10 +13,10 @@ public class EmailField extends FieldType
@Override
public String getJavaAssignment(String value) throws MolgenisModelException
{
- if(value == null || value.equals("") ) return "null";
- return "\""+value+"\"";
+ if (value == null || value.equals("")) return "null";
+ return "\"" + value + "\"";
}
-
+
@Override
public String getJavaPropertyDefault() throws MolgenisModelException
{
@@ -34,7 +34,7 @@ public String getMysqlType() throws MolgenisModelException
{
return "VARCHAR(255)";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
@@ -46,6 +46,7 @@ public String getHsqlType() throws MolgenisModelException
{
return "VARCHAR(255)";
}
+
@Override
public String getXsdType() throws MolgenisModelException
{
@@ -69,7 +70,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "string";
}
-
+
@Override
public String getCppJavaPropertyType()
{
@@ -87,7 +88,6 @@ public String getTypedValue(String value) throws ParseException
return value;
}
-
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.EMAIL;
diff --git a/src/org/molgenis/fieldtypes/EnumField.java b/src/org/molgenis/fieldtypes/EnumField.java
index 4a603fb26..4e4e2e13e 100644
--- a/src/org/molgenis/fieldtypes/EnumField.java
+++ b/src/org/molgenis/fieldtypes/EnumField.java
@@ -15,14 +15,14 @@ public String getJavaPropertyType()
{
return "String";
}
-
+
@Override
public String getJavaAssignment(String value)
{
- if(value == null || value.equals("") ) return "null";
- return "\""+value+"\"";
+ if (value == null || value.equals("")) return "null";
+ return "\"" + value + "\"";
}
-
+
@Override
public String getJavaPropertyDefault()
{
@@ -32,21 +32,21 @@ public String getJavaPropertyDefault()
@Override
public String getMysqlType() throws MolgenisModelException
{
- return "ENUM("+this.toCsv(f.getEnumOptions())+")";
+ return "ENUM(" + this.toCsv(f.getEnumOptions()) + ")";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
return "VARCHAR2(255)";
}
-
@Override
public String getHsqlType()
{
return "VARCHAR(1024)";
}
+
@Override
public String getXsdType()
{
@@ -70,7 +70,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "string";
}
-
+
@Override
public String getCppJavaPropertyType()
{
@@ -88,7 +88,7 @@ public Object getTypedValue(String value) throws ParseException
{
throw new UnsupportedOperationException("Unable to cast enum type");
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.ENUM;
diff --git a/src/org/molgenis/fieldtypes/FieldType.java b/src/org/molgenis/fieldtypes/FieldType.java
index 56b3281ed..e3cce2ed8 100644
--- a/src/org/molgenis/fieldtypes/FieldType.java
+++ b/src/org/molgenis/fieldtypes/FieldType.java
@@ -64,7 +64,7 @@ public String getJavaSetterType() throws MolgenisModelException
* @throws MolgenisModelException
*/
abstract public String getJavaPropertyType() throws MolgenisModelException;
-
+
/**
* Product the Java type of this field type. Default: "String".
*
@@ -80,8 +80,7 @@ public String getJavaSetterType() throws MolgenisModelException
* @return default in java code
* @throws MolgenisModelException
*/
- abstract public String getJavaPropertyDefault()
- throws MolgenisModelException;
+ abstract public String getJavaPropertyDefault() throws MolgenisModelException;
/**
* Produce a valid Java snippet to set a value for field.
@@ -89,16 +88,16 @@ abstract public String getJavaPropertyDefault()
* @return default in java code
* @throws MolgenisModelException
*/
- public abstract String getJavaAssignment(String value)
- throws MolgenisModelException;
+ public abstract String getJavaAssignment(String value) throws MolgenisModelException;
/**
* Produce the Java class corresponding to the value
+ *
* @return Java class
* @throws MolgenisModelException
*/
public abstract Class> getJavaType() throws MolgenisModelException;
-
+
/**
* Produce a valid mysql snippet indicating the mysql type. E.g. "BOOL".
*
@@ -120,14 +119,14 @@ public abstract String getJavaAssignment(String value)
*/
public String toCsv(List elements)
{
- String result = "";
+ StringBuilder strBuilder = new StringBuilder();
for (String str : elements)
- {
- result += ((elements.get(0) == str) ? "" : ",") + "'" + str + "'";
- }
+ strBuilder.append('\'').append(str).append('\'').append(',');
- return result;
+ if (!elements.isEmpty()) strBuilder.deleteCharAt(strBuilder.length() - 1);
+
+ return strBuilder.toString();
}
/**
@@ -145,6 +144,7 @@ public void setField(Field f)
/**
* Get the format string, e.g. '%s'
+ *
* @return
*/
public abstract String getFormatString();
@@ -154,27 +154,29 @@ public void setField(Field f)
*/
public String toString()
{
- return this.getClass().getSimpleName().replace("Field", "")
- .toLowerCase();
+ return this.getClass().getSimpleName().replace("Field", "").toLowerCase();
}
-
+
public HtmlInput> createInput(String name) throws HtmlInputException
{
return this.createInput(name, null);
}
-
+
public abstract HtmlInput> createInput(String name, String xrefEntityClassNames) throws HtmlInputException;
- //public abstract HtmlInput> createInput(String name, Class extends Entity> xrefClass ) throws HtmlInputException;
-
+
+ // public abstract HtmlInput> createInput(String name, Class extends
+ // Entity> xrefClass ) throws HtmlInputException;
+
public abstract String getCppJavaPropertyType() throws MolgenisModelException;
public abstract String getOracleType() throws MolgenisModelException;
-
+
public abstract Object getTypedValue(String value) throws ParseException;
-
+
public abstract MolgenisFieldTypes.FieldTypeEnum getEnumType();
- public List getAllowedOperators() {
+ public List getAllowedOperators()
+ {
return Arrays.asList("EQUALS", "NOT EQUALS");
}
}
diff --git a/src/org/molgenis/fieldtypes/FileField.java b/src/org/molgenis/fieldtypes/FileField.java
index 0d671d858..e2b247f9b 100644
--- a/src/org/molgenis/fieldtypes/FileField.java
+++ b/src/org/molgenis/fieldtypes/FileField.java
@@ -16,14 +16,14 @@ public String getJavaPropertyType()
{
return "String";
}
-
+
@Override
public String getJavaAssignment(String value)
{
- if(value == null || value.equals("")) return "null";
- return "\""+value+"\"";
+ if (value == null || value.equals("")) return "null";
+ return "\"" + value + "\"";
}
-
+
@Override
public String getJavaPropertyDefault()
{
@@ -35,7 +35,7 @@ public String getMysqlType() throws MolgenisModelException
{
return "VARCHAR(1024)";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
@@ -47,6 +47,7 @@ public String getHsqlType()
{
return "VARCHAR(1024)";
}
+
@Override
public String getXsdType()
{
@@ -70,7 +71,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "string";
}
-
+
@Override
public String getCppJavaPropertyType()
{
@@ -85,13 +86,16 @@ public Class> getJavaType()
public File getTypedValue(String value) throws ParseException
{
File file = new File(value);
- if (file.exists()) {
+ if (file.exists())
+ {
return file;
- } else {
+ }
+ else
+ {
throw new ParseException("File " + value + " not found.", 0);
}
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.FILE;
diff --git a/src/org/molgenis/fieldtypes/HyperlinkField.java b/src/org/molgenis/fieldtypes/HyperlinkField.java
index 2164bb860..939b7e1b1 100644
--- a/src/org/molgenis/fieldtypes/HyperlinkField.java
+++ b/src/org/molgenis/fieldtypes/HyperlinkField.java
@@ -15,26 +15,26 @@ public String getJavaPropertyType()
{
return "String";
}
-
+
@Override
public String getJavaAssignment(String value)
{
- if(value == null || value.equals("") ) return "null";
- return "\""+value+"\"";
+ if (value == null || value.equals("")) return "null";
+ return "\"" + value + "\"";
}
-
+
@Override
public String getJavaPropertyDefault()
{
return getJavaAssignment(f.getDefaultValue());
}
-
+
@Override
public String getMysqlType() throws MolgenisModelException
{
return "VARCHAR(255)";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
@@ -46,6 +46,7 @@ public String getHsqlType()
{
return "TEXT";
}
+
@Override
public String getXsdType()
{
@@ -86,7 +87,7 @@ public String getTypedValue(String value) throws ParseException
{
return value;
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.HYPERLINK;
diff --git a/src/org/molgenis/fieldtypes/ImageField.java b/src/org/molgenis/fieldtypes/ImageField.java
index 58d46f40c..744a6b745 100644
--- a/src/org/molgenis/fieldtypes/ImageField.java
+++ b/src/org/molgenis/fieldtypes/ImageField.java
@@ -1,6 +1,5 @@
package org.molgenis.fieldtypes;
-
public class ImageField extends FileField
{
}
diff --git a/src/org/molgenis/fieldtypes/IntField.java b/src/org/molgenis/fieldtypes/IntField.java
index f9e2a035c..14fb94d13 100644
--- a/src/org/molgenis/fieldtypes/IntField.java
+++ b/src/org/molgenis/fieldtypes/IntField.java
@@ -17,32 +17,32 @@ public String getJavaPropertyType() throws MolgenisModelException
{
return "Integer";
}
-
+
@Override
public String getJavaAssignment(String value)
{
- if(value == null || value.equals("")) return "null";
- return ""+Integer.parseInt(value);
+ if (value == null || value.equals("")) return "null";
+ return "" + Integer.parseInt(value);
}
-
+
@Override
public String getJavaPropertyDefault()
{
return getJavaAssignment(f.getDefaultValue());
}
-
+
@Override
public String getMysqlType() throws MolgenisModelException
{
return "INTEGER";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
return "NUMBER (10,0)";
}
-
+
public String getJavaSetterType() throws MolgenisModelException
{
return "Int";
@@ -53,6 +53,7 @@ public String getHsqlType()
{
return "INT";
}
+
@Override
public String getXsdType()
{
@@ -76,7 +77,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "int";
}
-
+
@Override
public String getCppJavaPropertyType()
{
@@ -92,12 +93,12 @@ public Object getTypedValue(String value) throws ParseException
{
return Integer.parseInt(value);
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.INT;
}
-
+
@Override
public List getAllowedOperators()
{
diff --git a/src/org/molgenis/fieldtypes/ListField.java b/src/org/molgenis/fieldtypes/ListField.java
index b9ddd6db0..ca63010f1 100644
--- a/src/org/molgenis/fieldtypes/ListField.java
+++ b/src/org/molgenis/fieldtypes/ListField.java
@@ -17,33 +17,33 @@ public String getJavaPropertyDefault() throws MolgenisModelException
{
return "new java.util.ArrayList>()";
}
-
+
@Override
public String getJavaAssignment(String value)
{
return "NOT IMPLEMENTED";
}
-
+
@Override
public String getJavaPropertyType()
{
return "java.util.List>";
}
-
+
@Override
public String getMysqlType() throws MolgenisModelException
{
- //should never happen?
+ // should never happen?
return "LIST CANNOT BE IN SQL";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
- //should never happen?
+ // should never happen?
return "LIST CANNOT BE IN SQL";
}
-
+
@Override
public String getJavaSetterType() throws MolgenisModelException
{
@@ -55,10 +55,10 @@ public String getHsqlType()
{
return "LIST CANNOT BE IN SQL";
}
-
+
public String getXsdType()
{
- return "" ;
+ return "";
}
@Override
@@ -81,7 +81,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "vector";
}
-
+
@Override
public String getCppJavaPropertyType()
{
@@ -97,7 +97,7 @@ public java.util.List> getTypedValue(String value) throws ParseException
{
return Arrays.asList(StringUtils.split(value, ","));
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.LIST;
diff --git a/src/org/molgenis/fieldtypes/LongField.java b/src/org/molgenis/fieldtypes/LongField.java
index 711e33a8c..7414638af 100644
--- a/src/org/molgenis/fieldtypes/LongField.java
+++ b/src/org/molgenis/fieldtypes/LongField.java
@@ -21,23 +21,22 @@ public String getJavaPropertyType()
@Override
public String getJavaAssignment(String value)
{
- if (value == null || value.equals("") ) return "null";
+ if (value == null || value.equals("")) return "null";
return "" + Long.parseLong(value) + "L";
}
-
@Override
public String getJavaPropertyDefault()
{
return getJavaAssignment(f.getDefaultValue());
}
-
+
@Override
public String getMysqlType() throws MolgenisModelException
{
return "BIGINT";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
@@ -49,6 +48,7 @@ public String getHsqlType()
{
return "LONG";
}
+
@Override
public String getXsdType()
{
@@ -72,7 +72,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "long";
}
-
+
@Override
public String getCppJavaPropertyType()
{
@@ -88,12 +88,12 @@ public Long getTypedValue(String value) throws ParseException
{
return Long.parseLong(value);
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.LONG;
}
-
+
@Override
public List getAllowedOperators()
{
diff --git a/src/org/molgenis/fieldtypes/MrefField.java b/src/org/molgenis/fieldtypes/MrefField.java
index 532f14d6a..9e90bb903 100644
--- a/src/org/molgenis/fieldtypes/MrefField.java
+++ b/src/org/molgenis/fieldtypes/MrefField.java
@@ -12,9 +12,12 @@
/**
* Many to many reference.
*
- * Example MOLGENIS DSL,
- *
- *
+ * Example MOLGENIS DSL,
+ *
+ *
+ *
+ *
+ *
* This example would in the UI show a seletion box with 'name' elements.
*/
public class MrefField extends FieldType
@@ -24,44 +27,45 @@ public String getJavaAssignment(String value)
{
return "NOT IMPLEMENTED";
}
-
+
@Override
public String getJavaPropertyType() throws MolgenisModelException
{
- //Entity e_ref = f.getXrefEntity();
+ // Entity e_ref = f.getXrefEntity();
Field f_ref = f.getXrefField();
- return "java.util.List<"+getFieldType(f_ref).getJavaPropertyType()+">";
+ return "java.util.List<" + getFieldType(f_ref).getJavaPropertyType() + ">";
}
-
+
@Override
public String getJavaPropertyDefault() throws MolgenisModelException
{
- //Entity e_ref = f.getXrefEntity();
+ // Entity e_ref = f.getXrefEntity();
Field f_ref = f.getXrefField();
- //if(f.getDefaultValue() == null || f.getDefaultValue() == "") "new java.util.ArrayList<"+getFieldType(f_ref).getJavaPropertyType(f_ref)+">()";
- //FIXME can there be defaults here?
- return "new java.util.ArrayList<"+getFieldType(f_ref).getJavaPropertyType()+">()";
+ // if(f.getDefaultValue() == null || f.getDefaultValue() == "")
+ // "new java.util.ArrayList<"+getFieldType(f_ref).getJavaPropertyType(f_ref)+">()";
+ // FIXME can there be defaults here?
+ return "new java.util.ArrayList<" + getFieldType(f_ref).getJavaPropertyType() + ">()";
}
-
+
@Override
public String getJavaSetterType() throws MolgenisModelException
{
- //Entity e_ref = f.getXrefEntity();
+ // Entity e_ref = f.getXrefEntity();
Field f_ref = f.getXrefField();
- return "new java.util.ArrayList<"+getFieldType(f_ref).getJavaSetterType()+">()";
+ return "new java.util.ArrayList<" + getFieldType(f_ref).getJavaSetterType() + ">()";
}
-
+
@Override
public String getMysqlType() throws MolgenisModelException
{
- //FIXME this function should be never called???
+ // FIXME this function should be never called???
return getFieldType(f.getXrefField()).getMysqlType();
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
- //FIXME this function should be never called???
+ // FIXME this function should be never called???
return getFieldType(f.getXrefField()).getOracleType();
}
@@ -70,7 +74,7 @@ public String getHsqlType() throws MolgenisModelException
{
return getFieldType(f.getXrefField()).getHsqlType();
}
-
+
@Override
public String getXsdType() throws MolgenisModelException
{
@@ -83,35 +87,37 @@ public String getFormatString()
return "";
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings(
+ { "unchecked", "rawtypes" })
@Override
public HtmlInput> createInput(String name, String xrefEntityClassName) throws HtmlInputException
- {
+ {
try
{
Class> klass = Class.forName(xrefEntityClassName);
-
+
return new MrefInput(name, klass);
}
catch (ClassNotFoundException e)
{
throw new HtmlInputException(e);
- }
+ }
}
-
-// @Override
-// public HtmlInput> createInput(String name, Class extends Entity> xrefEntityClassName) throws HtmlInputException
-// {
-// return new MrefInput(name, xrefEntityClassName);
-// }
+
+ // @Override
+ // public HtmlInput> createInput(String name, Class extends Entity>
+ // xrefEntityClassName) throws HtmlInputException
+ // {
+ // return new MrefInput(name, xrefEntityClassName);
+ // }
@Override
public String getCppPropertyType() throws MolgenisModelException
{
Field f_ref = f.getXrefField();
- return "vector<"+getFieldType(f_ref).getCppPropertyType()+">";
+ return "vector<" + getFieldType(f_ref).getCppPropertyType() + ">";
}
-
+
@Override
public String getCppJavaPropertyType() throws MolgenisModelException
{
@@ -128,7 +134,7 @@ public Object getTypedValue(String value) throws ParseException
{
throw new UnsupportedOperationException("Conversion of MRef not supported.");
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.MREF;
diff --git a/src/org/molgenis/fieldtypes/NSequenceField.java b/src/org/molgenis/fieldtypes/NSequenceField.java
index 448b86f40..3bf03f69f 100644
--- a/src/org/molgenis/fieldtypes/NSequenceField.java
+++ b/src/org/molgenis/fieldtypes/NSequenceField.java
@@ -15,40 +15,39 @@ public String getJavaPropertyType()
{
return "String";
}
-
+
@Override
public String getJavaAssignment(String value)
{
- //FIXME check if it is a valid nsequence
- if(value == null || value.equals("") ) return "null";
- return "\""+value+"\"";
+ // FIXME check if it is a valid nsequence
+ if (value == null || value.equals("")) return "null";
+ return "\"" + value + "\"";
}
-
+
@Override
public String getJavaPropertyDefault()
{
return getJavaAssignment(f.getDefaultValue());
}
-
+
@Override
public String getMysqlType() throws MolgenisModelException
{
return "TEXT";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
return "BLOB";
}
-
@Override
public String getHsqlType() throws MolgenisModelException
{
return "TEXT";
}
-
+
@Override
public String getXsdType() throws MolgenisModelException
{
@@ -63,7 +62,7 @@ public String getFormatString()
@Override
public HtmlInput> createInput(String name, String xrefEntityClassName) throws HtmlInputException
-
+
{
return new NsequenceInput(name);
}
@@ -90,7 +89,7 @@ public Object getTypedValue(String value) throws ParseException
{
return value;
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.NSEQUENCE;
diff --git a/src/org/molgenis/fieldtypes/StringField.java b/src/org/molgenis/fieldtypes/StringField.java
index 99dfd3dea..4c1be6a50 100644
--- a/src/org/molgenis/fieldtypes/StringField.java
+++ b/src/org/molgenis/fieldtypes/StringField.java
@@ -13,10 +13,10 @@ public class StringField extends FieldType
@Override
public String getJavaAssignment(String value) throws MolgenisModelException
{
- if(value == null || value.equals("") ) return "null";
- return "\""+value+"\"";
+ if (value == null || value.equals("")) return "null";
+ return "\"" + value + "\"";
}
-
+
@Override
public String getJavaPropertyDefault() throws MolgenisModelException
{
@@ -32,20 +32,21 @@ public String getJavaPropertyType() throws MolgenisModelException
@Override
public String getMysqlType() throws MolgenisModelException
{
- return "VARCHAR("+f.getVarCharLength()+")";
+ return "VARCHAR(" + f.getVarCharLength() + ")";
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
- return "VARCHAR2("+f.getVarCharLength()+")";
+ return "VARCHAR2(" + f.getVarCharLength() + ")";
}
@Override
public String getHsqlType() throws MolgenisModelException
{
- return "VARCHAR("+f.getVarCharLength()+")";
+ return "VARCHAR(" + f.getVarCharLength() + ")";
}
+
@Override
public String getXsdType() throws MolgenisModelException
{
@@ -69,7 +70,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "string";
}
-
+
@Override
public String getCppJavaPropertyType()
{
@@ -87,7 +88,6 @@ public String getTypedValue(String value) throws ParseException
return value;
}
-
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.STRING;
diff --git a/src/org/molgenis/fieldtypes/TextField.java b/src/org/molgenis/fieldtypes/TextField.java
index 304f7d145..b14ebc5ed 100644
--- a/src/org/molgenis/fieldtypes/TextField.java
+++ b/src/org/molgenis/fieldtypes/TextField.java
@@ -13,22 +13,22 @@ public class TextField extends FieldType
@Override
public String getJavaAssignment(String value)
{
- if(value == null ||value.equals("") ) return "null";
- return "\""+value+"\"";
+ if (value == null || value.equals("")) return "null";
+ return "\"" + value + "\"";
}
-
+
@Override
public String getJavaPropertyDefault()
{
return getJavaAssignment(f.getDefaultValue());
}
-
+
@Override
public String getMysqlType() throws MolgenisModelException
{
return "TEXT";
}
-
+
@Override
public String getOracleType()
{
@@ -39,10 +39,10 @@ public String getOracleType()
@Override
public String getHsqlType() throws MolgenisModelException
{
- //these guys don't have TEXT?
+ // these guys don't have TEXT?
return "VARCHAR";
}
-
+
@Override
public String getXsdType() throws MolgenisModelException
{
@@ -73,7 +73,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "string";
}
-
+
@Override
public String getCppJavaPropertyType()
{
diff --git a/src/org/molgenis/fieldtypes/UnknownField.java b/src/org/molgenis/fieldtypes/UnknownField.java
index 4a41f31b7..455c2fa53 100644
--- a/src/org/molgenis/fieldtypes/UnknownField.java
+++ b/src/org/molgenis/fieldtypes/UnknownField.java
@@ -8,8 +8,9 @@
import org.molgenis.model.MolgenisModelException;
/**
- * This type is used when the field type is not known.
- * For example if(MolgenisFieldType.getType(name) instanceof UnknownType( {//handle this bad situation
+ * This type is used when the field type is not known. For example
+ * if(MolgenisFieldType.getType(name) instanceof UnknownType( {//handle this bad
+ * situation
*/
public class UnknownField extends FieldType
{
@@ -49,7 +50,7 @@ public String getMysqlType() throws MolgenisModelException
{
return null;
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
@@ -73,7 +74,7 @@ public String getCppPropertyType() throws MolgenisModelException
{
return "void*";
}
-
+
@Override
public String getCppJavaPropertyType()
{
diff --git a/src/org/molgenis/fieldtypes/XrefField.java b/src/org/molgenis/fieldtypes/XrefField.java
index 8dbd335cb..4c5df21f9 100644
--- a/src/org/molgenis/fieldtypes/XrefField.java
+++ b/src/org/molgenis/fieldtypes/XrefField.java
@@ -10,41 +10,41 @@
import org.molgenis.model.elements.Field;
import org.molgenis.util.Entity;
-public class XrefField extends FieldType
-{
+public class XrefField extends FieldType
+{
@Override
public String getJavaAssignment(String value)
{
return "NOT IMPLEMENTED";
}
-
+
@Override
public String getJavaPropertyType() throws MolgenisModelException
{
Field f_ref = f.getXrefField();
return getFieldType(f_ref).getJavaPropertyType();
}
-
+
@Override
public String getJavaPropertyDefault()
{
- if(f.getDefaultValue() == null || f.getDefaultValue() == "") return "null";
+ if (f.getDefaultValue() == null || f.getDefaultValue().isEmpty()) return "null";
return f.getDefaultValue();
}
-
+
@Override
public String getJavaSetterType() throws MolgenisModelException
{
-
+
return getFieldType(f.getXrefField()).getJavaSetterType();
}
-
+
@Override
public String getMysqlType() throws MolgenisModelException
{
return getFieldType(f.getXrefField()).getMysqlType();
}
-
+
@Override
public String getOracleType() throws MolgenisModelException
{
@@ -56,7 +56,7 @@ public String getHsqlType() throws MolgenisModelException
{
return getFieldType(f.getXrefField()).getHsqlType();
}
-
+
public String getXsdType() throws MolgenisModelException
{
return getFieldType(f.getXrefField()).getXsdType();
@@ -87,7 +87,7 @@ public String getCppPropertyType() throws MolgenisModelException
Field f_ref = f.getXrefField();
return getFieldType(f_ref).getCppPropertyType();
}
-
+
@Override
public String getCppJavaPropertyType() throws MolgenisModelException
{
@@ -106,10 +106,10 @@ public Object getTypedValue(String value) throws ParseException
{
throw new UnsupportedOperationException("Xref conversion not supported.");
}
-
+
public FieldTypeEnum getEnumType()
{
return FieldTypeEnum.XREF;
}
-}
+}
\ No newline at end of file
diff --git a/src/org/molgenis/framework/db/AbstractDatabase.java b/src/org/molgenis/framework/db/AbstractDatabase.java
index 90660bcc0..0f00a3844 100644
--- a/src/org/molgenis/framework/db/AbstractDatabase.java
+++ b/src/org/molgenis/framework/db/AbstractDatabase.java
@@ -199,7 +199,6 @@ public void executeUpdate(String sql) throws DatabaseException
{
stmt = con.createStatement();
stmt.executeUpdate(sql);
- stmt.close();
}
catch (Exception e)
{
@@ -249,7 +248,7 @@ public int update(List entities, DatabaseAction dbAction,
{
// get all the value of all keys (composite key)
// use an index to hash the entities
- String combinedKey = "";
+ StringBuilder combinedKeyBuilder = new StringBuilder();
// extract its key values and put in map
Map keyValues = new LinkedHashMap();
@@ -260,20 +259,11 @@ public int update(List entities, DatabaseAction dbAction,
for (String key : keyNames)
{
// create a hash that concats all key values into one string
- combinedKey += ";" + (entity.get(key) == null ? "" : entity.get(key));
-
- // if (entity.get(key) == null || entity.get(key).equals(""))
- // {
- // if (dbAction.equals(DatabaseAction.UPDATE) ||
- // dbAction.equals(DatabaseAction.REMOVE))
- // {
- // throw new DatabaseException(
- // entityName + " is missing key '" + key + "' in line " +
- // entity.toString());
- // }
- // }
+ combinedKeyBuilder.append(';');
+
if (entity.get(key) != null)
{
+ combinedKeyBuilder.append(entity.get(key));
incompleteKey = false;
keyValues.put(key, entity.get(key));
}
@@ -286,7 +276,7 @@ public int update(List entities, DatabaseAction dbAction,
{
keyIndex.add(keyValues);
// create the entity index using the hash
- entityIndex.put(combinedKey, entity);
+ entityIndex.put(combinedKeyBuilder.toString(), entity);
}
else
{
@@ -343,13 +333,13 @@ public int update(List entities, DatabaseAction dbAction,
for (E p : selectForUpdate)
{
// reconstruct composite key so we can use the entityIndex
- String combinedKey = "";
+ StringBuilder combinedKeyBuilder = new StringBuilder();
for (String key : keyNames)
{
- combinedKey += ";" + p.get(key);
+ combinedKeyBuilder.append(';').append(p.get(key));
}
// copy existing from entityIndex to existingEntities
- entityIndex.remove(combinedKey);
+ entityIndex.remove(combinedKeyBuilder.toString());
existingEntities.add(p);
}
// copy remaining to newEntities
diff --git a/src/org/molgenis/framework/db/AbstractMapper.java b/src/org/molgenis/framework/db/AbstractMapper.java
index 60d7a09b9..aa5c5df8c 100644
--- a/src/org/molgenis/framework/db/AbstractMapper.java
+++ b/src/org/molgenis/framework/db/AbstractMapper.java
@@ -23,8 +23,7 @@ public abstract class AbstractMapper implements Mapper
public static final int BATCH_SIZE = 500;
/** log messages */
- private static transient final Logger logger = Logger
- .getLogger(AbstractJDBCMapper.class.getSimpleName());
+ private static transient final Logger logger = Logger.getLogger(AbstractJDBCMapper.class.getSimpleName());
public AbstractMapper(Database database)
{
@@ -57,8 +56,7 @@ public Database getDatabase()
*
* @throws IOException
*/
- protected abstract void prepareFileAttachements(List entities, File dir)
- throws IOException;
+ protected abstract void prepareFileAttachements(List entities, File dir) throws IOException;
/**
* helper method to do some actions after the transaction. For example:
@@ -68,8 +66,7 @@ protected abstract void prepareFileAttachements(List entities, File dir)
* database)
* @throws IOException
*/
- protected abstract boolean saveFileAttachements(List entities, File dir)
- throws IOException;
+ protected abstract boolean saveFileAttachements(List entities, File dir) throws IOException;
/**
* translate into sql
@@ -77,8 +74,7 @@ protected abstract boolean saveFileAttachements(List entities, File dir)
* @throws DatabaseException
*/
@Override
- public abstract int executeAdd(List extends E> entities)
- throws DatabaseException;
+ public abstract int executeAdd(List extends E> entities) throws DatabaseException;
/**
* translate into sql
@@ -86,15 +82,13 @@ public abstract int executeAdd(List extends E> entities)
* @throws DatabaseException
*/
@Override
- public abstract int executeUpdate(List extends E> entities)
- throws DatabaseException;
+ public abstract int executeUpdate(List extends E> entities) throws DatabaseException;
/**
* translate into sql
*/
@Override
- public abstract int executeRemove(List extends E> entities)
- throws DatabaseException;
+ public abstract int executeRemove(List extends E> entities) throws DatabaseException;
/**
* Foreign key values may be only given via the 'label'. This function
@@ -104,8 +98,7 @@ public abstract int executeRemove(List extends E> entities)
* @throws DatabaseException
* @throws ParseException
*/
- public abstract void resolveForeignKeys(List entities)
- throws DatabaseException, ParseException;
+ public abstract void resolveForeignKeys(List entities) throws DatabaseException, ParseException;
/**
* Helper method for storing multiplicative references. This function should
@@ -118,8 +111,7 @@ public abstract void resolveForeignKeys(List entities)
* @throws IOException
* @throws ParseException
*/
- public abstract void storeMrefs(List entities) throws DatabaseException,
- IOException, ParseException;
+ public abstract void storeMrefs(List entities) throws DatabaseException, IOException, ParseException;
/**
* Helper method for removing multiplicative references ('mrefs')
@@ -130,12 +122,11 @@ public abstract void storeMrefs(List entities) throws DatabaseException,
* @throws DatabaseException
* @throws ParseException
*/
- public abstract void removeMrefs(List entities) throws SQLException,
- IOException, DatabaseException, ParseException;
+ public abstract void removeMrefs(List entities) throws SQLException, IOException, DatabaseException,
+ ParseException;
@Override
- public void find(TupleWriter writer, QueryRule... rules)
- throws DatabaseException
+ public void find(TupleWriter writer, QueryRule... rules) throws DatabaseException
{
this.find(writer, null, rules);
}
@@ -160,8 +151,7 @@ public int add(List entities) throws DatabaseException
if (privateTx) getDatabase().beginTx();
// prepare all file attachments
- this.prepareFileAttachements(entities, getDatabase()
- .getFilesource());
+ this.prepareFileAttachements(entities, getDatabase().getFilesource());
// insert this class in batches
for (int i = 0; i < entities.size(); i += BATCH_SIZE)
@@ -178,8 +168,7 @@ public int add(List entities) throws DatabaseException
this.storeMrefs(entities);
// store file attachments and then update the file paths to them
- if (this.saveFileAttachements(entities, getDatabase()
- .getFilesource()))
+ if (this.saveFileAttachements(entities, getDatabase().getFilesource()))
{
this.update(entities);
}
@@ -187,25 +176,20 @@ public int add(List entities) throws DatabaseException
// commit all batches
if (privateTx) getDatabase().commitTx();
- logger.info(updatedRows + " "
- + this.create().getClass().getSimpleName()
- + " objects added");
+ logger.info(updatedRows + " " + this.create().getClass().getSimpleName() + " objects added");
return updatedRows;
}
catch (Exception sqle)
{
sqle.printStackTrace();
if (privateTx) getDatabase().rollbackTx();
- logger.error("ADD failed on "
- + this.create().getClass().getSimpleName() + ": "
- + sqle.getMessage());
+ logger.error("ADD failed on " + this.create().getClass().getSimpleName() + ": " + sqle.getMessage());
throw new DatabaseException(sqle);
}
}
@Override
- public int add(TupleReader reader, TupleWriter writer)
- throws DatabaseException
+ public int add(TupleReader reader, TupleWriter writer) throws DatabaseException
{
// count affected rows
int rowsAffected = 0;
@@ -247,9 +231,7 @@ public int add(TupleReader reader, TupleWriter writer)
catch (Exception e)
{
if (privateTx) getDatabase().rollbackTx();
- throw new DatabaseException("add("
- + create().getClass().getSimpleName() + ") failed: "
- + e.getMessage(), e);
+ throw new DatabaseException("add(" + create().getClass().getSimpleName() + ") failed: " + e.getMessage(), e);
}
return rowsAffected;
}
@@ -276,8 +258,7 @@ public int update(List entities) throws DatabaseException
if (privateTx) getDatabase().beginTx();
// prepare file attachments
- this.prepareFileAttachements(entities, getDatabase()
- .getFilesource());
+ this.prepareFileAttachements(entities, getDatabase().getFilesource());
// update in batches
for (int i = 0; i < entities.size(); i += BATCH_SIZE)
@@ -286,8 +267,7 @@ public int update(List entities) throws DatabaseException
List sublist = entities.subList(i, endindex);
// put the files in their place
- this.saveFileAttachements(sublist, getDatabase()
- .getFilesource());
+ this.saveFileAttachements(sublist, getDatabase().getFilesource());
// attempt to resolve foreign keys by label (ie. 'name')
this.resolveForeignKeys(sublist);
@@ -299,17 +279,14 @@ public int update(List entities) throws DatabaseException
if (privateTx) getDatabase().commitTx();
- logger.info(updatedRows + " "
- + this.create().getClass().getSimpleName()
- + " objects updated");
+ logger.info(updatedRows + " " + this.create().getClass().getSimpleName() + " objects updated");
return updatedRows;
}
catch (Exception sqle)
{
if (privateTx) getDatabase().rollbackTx();
- throw new DatabaseException("Update("
- + create().getClass().getSimpleName() + ") failed: "
+ throw new DatabaseException("Update(" + create().getClass().getSimpleName() + ") failed: "
+ sqle.getMessage(), sqle);
}
}
@@ -343,9 +320,8 @@ public int update(TupleReader reader) throws DatabaseException
catch (Exception e)
{
if (privateTx) getDatabase().rollbackTx();
- throw new DatabaseException("update("
- + create().getClass().getSimpleName() + ") failed: "
- + e.getMessage(), e);
+ throw new DatabaseException(
+ "update(" + create().getClass().getSimpleName() + ") failed: " + e.getMessage(), e);
}
return rowsAffected;
}
@@ -368,8 +344,7 @@ public int remove(List entities) throws DatabaseException
if (privateTx) getDatabase().beginTx();
// prepare file attachments
- this.prepareFileAttachements(entities, getDatabase()
- .getFilesource());
+ this.prepareFileAttachements(entities, getDatabase().getFilesource());
// remove in batches
for (int i = 0; i < entities.size(); i += BATCH_SIZE)
@@ -388,21 +363,16 @@ public int remove(List entities) throws DatabaseException
getDatabase().flush();
if (privateTx) getDatabase().commitTx();
- logger.info(updatedRows + " "
- + this.create().getClass().getSimpleName()
- + " objects removed");
+ logger.info(updatedRows + " " + this.create().getClass().getSimpleName() + " objects removed");
return updatedRows;
}
catch (Exception sqle)
{
if (privateTx) getDatabase().rollbackTx();
- logger.error("remove failed on "
- + this.create().getClass().getSimpleName() + ": "
- + sqle.getMessage());
+ logger.error("remove failed on " + this.create().getClass().getSimpleName() + ": " + sqle.getMessage());
sqle.printStackTrace();
- throw new DatabaseException("remove("
- + create().getClass().getSimpleName() + ") failed: "
+ throw new DatabaseException("remove(" + create().getClass().getSimpleName() + ") failed: "
+ sqle.getMessage(), sqle);
}
}
@@ -432,28 +402,26 @@ public int remove(TupleReader reader) throws DatabaseException
catch (Exception e)
{
if (privateTx) getDatabase().rollbackTx();
- throw new DatabaseException("remove("
- + create().getClass().getSimpleName() + ") failed: "
- + e.getMessage(), e);
+ throw new DatabaseException(
+ "remove(" + create().getClass().getSimpleName() + ") failed: " + e.getMessage(), e);
}
return rowsAffected;
}
@Override
- //FIXME: limit argument is never used?
- public List toList(TupleReader reader, int limit)
- throws DatabaseException
+ // FIXME: limit argument is never used?
+ public List toList(TupleReader reader, int limit) throws DatabaseException
{
- //hack to while over a reader until the result is empty
- if(reader.isClosed())
+ // hack to while over a reader until the result is empty
+ if (reader.isClosed())
{
return new ArrayList();
}
-
- final List entities = createList(10); //TODO why 10?
+
+ final List entities = createList(10); // TODO why 10?
try
{
- for (Tuple line : reader) //TODO should limit not be used somehow?
+ for (Tuple line : reader) // TODO should limit not be used somehow?
{
E e = create();
e.set(line, false); // parse the tuple
diff --git a/src/org/molgenis/framework/db/ConnectionUtil.java b/src/org/molgenis/framework/db/ConnectionUtil.java
index 472b06daf..02cadba1a 100644
--- a/src/org/molgenis/framework/db/ConnectionUtil.java
+++ b/src/org/molgenis/framework/db/ConnectionUtil.java
@@ -6,34 +6,38 @@
import org.molgenis.MolgenisOptions;
-
-
public class ConnectionUtil
{
- public static Connection createConnection(MolgenisOptions options) {
+ public static Connection createConnection(MolgenisOptions options)
+ {
try
{
Class.forName(options.db_driver.trim()).newInstance();
Connection conn = DriverManager.getConnection(options.db_uri.trim(), options.db_user.trim(),
options.db_password.trim());
return conn;
- }catch (Exception e){
+ }
+ catch (Exception e)
+ {
e.printStackTrace();
}
return null;
}
-
- public static Connection createConnection(Properties p) {
+
+ public static Connection createConnection(Properties p)
+ {
try
{
Class.forName(p.getProperty("db_driver").trim()).newInstance();
Connection conn = DriverManager.getConnection(p.getProperty("db_uri").trim(), p.getProperty("db_user")
.trim(), p.getProperty("db_password").trim());
return conn;
- }catch (Exception e){
+ }
+ catch (Exception e)
+ {
e.printStackTrace();
}
- return null;
+ return null;
}
-
+
}
diff --git a/src/org/molgenis/framework/db/CsvToDatabase.java b/src/org/molgenis/framework/db/CsvToDatabase.java
index 17dcf057e..73b3cd6b6 100644
--- a/src/org/molgenis/framework/db/CsvToDatabase.java
+++ b/src/org/molgenis/framework/db/CsvToDatabase.java
@@ -15,119 +15,161 @@
import freemarker.log.Logger;
-/**will be moved to generic solution*/
+/** will be moved to generic solution */
-public abstract class CsvToDatabase {
+public abstract class CsvToDatabase
+{
protected static int BATCH_SIZE = 10000;
protected transient final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
-
- /**wrapper to use int inside anonymous classes (requires final, so cannot update directly)*/
- //FIXME move to value type elsewhere?
- public static class IntegerWrapper {
+
+ /**
+ * wrapper to use int inside anonymous classes (requires final, so cannot
+ * update directly)
+ */
+ // FIXME move to value type elsewhere?
+ public static class IntegerWrapper
+ {
private int value;
-
- public IntegerWrapper(int value) {
+
+ public IntegerWrapper(int value)
+ {
this.value = value;
}
- public void set(int value) {
+
+ public void set(int value)
+ {
this.value = value;
}
- public int get() {
+
+ public int get()
+ {
return this.value;
}
}
-
+
/**
* Imports ${JavaName(entity)} from tab/comma delimited File.
- * @param db where data should be imported into
- * @param file with the csv values
- * @param defaults default values that override the values in the file columns
+ *
+ * @param db
+ * where data should be imported into
+ * @param file
+ * with the csv values
+ * @param defaults
+ * default values that override the values in the file columns
*/
- public int importCsv(final Database db, File file, final Tuple defaults) throws DatabaseException, IOException, Exception {
- return importCsv(db,file,defaults,DatabaseAction.ADD);
+ public int importCsv(final Database db, File file, final Tuple defaults) throws DatabaseException, IOException,
+ Exception
+ {
+ return importCsv(db, file, defaults, DatabaseAction.ADD);
}
-
- public int importCsv(Database db, File file, Tuple defaults, DatabaseAction dbAction) throws Exception {
- if( file.exists() ) {
- logger.info("trying to import "+file);
+
+ public int importCsv(Database db, File file, Tuple defaults, DatabaseAction dbAction) throws Exception
+ {
+ if (file.exists())
+ {
+ logger.info("trying to import " + file);
CsvReader reader = new CsvFileReader(file);
- return this.importCsv(db,reader,defaults,dbAction, reader.getMissingValues());
+ return this.importCsv(db, reader, defaults, dbAction, reader.getMissingValues());
}
- else {
- logger.warn("CsvImport of "+file+" skipped: file doesn't exists");
+ else
+ {
+ logger.warn("CsvImport of " + file + " skipped: file doesn't exists");
return 0;
}
}
/**
* Imports ${JavaName(entity)} from tab/comma delimited File.
- * @param db where data should be imported into
- * @param file with the csv values
- * @param defaults default values that override the values in the file columns
- * @param dbAction indicating if data needs to be added, updated, etc
- * @param missingValues string that indicates how missing values are specified. E.g. "" or "NA"
+ *
+ * @param db
+ * where data should be imported into
+ * @param file
+ * with the csv values
+ * @param defaults
+ * default values that override the values in the file columns
+ * @param dbAction
+ * indicating if data needs to be added, updated, etc
+ * @param missingValues
+ * string that indicates how missing values are specified. E.g.
+ * "" or "NA"
*/
- public int importCsv(final Database db, File file, final Tuple defaults, DatabaseAction dbAction, String missingValues) throws DatabaseException, IOException, Exception {
- if( file.exists() ) {
- logger.info("trying to import "+file);
+ public int importCsv(final Database db, File file, final Tuple defaults, DatabaseAction dbAction,
+ String missingValues) throws DatabaseException, IOException, Exception
+ {
+ if (file.exists())
+ {
+ logger.info("trying to import " + file);
CsvReader reader = new CsvFileReader(file);
- return this.importCsv(db,reader,defaults,dbAction, missingValues);
+ return this.importCsv(db, reader, defaults, dbAction, missingValues);
}
- else {
- logger.warn("CsvImport of "+file+" skipped: file doesn't exists");
+ else
+ {
+ logger.warn("CsvImport of " + file + " skipped: file doesn't exists");
return 0;
}
- }
-
-
+ }
+
/**
* Imports ${JavaName(entity)} from tab/comma delimited File.
*/
- public int importCsv(final Database db, CsvReader reader, final Tuple defaults) throws DatabaseException, IOException, Exception {
- return importCsv(db,reader,defaults,DatabaseAction.ADD);
+ public int importCsv(final Database db, CsvReader reader, final Tuple defaults) throws DatabaseException,
+ IOException, Exception
+ {
+ return importCsv(db, reader, defaults, DatabaseAction.ADD);
}
-
- public int importCsv(final Database db, CsvReader reader, final Tuple defaults, DatabaseAction action) throws DatabaseException, IOException, Exception {
- return importCsv(db,reader,defaults,DatabaseAction.ADD, reader.getMissingValues());
+
+ public int importCsv(final Database db, CsvReader reader, final Tuple defaults, DatabaseAction action)
+ throws DatabaseException, IOException, Exception
+ {
+ return importCsv(db, reader, defaults, DatabaseAction.ADD, reader.getMissingValues());
}
- public abstract int importCsv(Database db, CsvReader reader, Tuple constants, DatabaseAction action, String missingValues) throws Exception;
-
- public static class ImportResult {
-
+ public abstract int importCsv(Database db, CsvReader reader, Tuple constants, DatabaseAction action,
+ String missingValues) throws Exception;
+
+ public static class ImportResult
+ {
+
List progressLog;
- Map messages;
+ Map messages;
String errorItem;
-
- public ImportResult() {
+
+ public ImportResult()
+ {
progressLog = new ArrayList();
- messages = new HashMap();
+ messages = new HashMap();
errorItem = "no error found";
}
- public List getProgressLog() {
+ public List getProgressLog()
+ {
return progressLog;
}
- public void setProgressLog(List progressLog) {
+ public void setProgressLog(List progressLog)
+ {
this.progressLog = progressLog;
}
- public Map getMessages() {
+ public Map getMessages()
+ {
return messages;
}
- public void setMessages(Map messages) {
+ public void setMessages(Map messages)
+ {
this.messages = messages;
}
- public String getErrorItem() {
+ public String getErrorItem()
+ {
return errorItem;
}
- public void setErrorItem(String errorItem) {
+ public void setErrorItem(String errorItem)
+ {
this.errorItem = errorItem;
}
-
+
}
}
diff --git a/src/org/molgenis/framework/db/Database.java b/src/org/molgenis/framework/db/Database.java
index e2601b62e..037d77e0e 100644
--- a/src/org/molgenis/framework/db/Database.java
+++ b/src/org/molgenis/framework/db/Database.java
@@ -18,7 +18,6 @@
import java.io.File;
import java.sql.Connection;
-import java.sql.ResultSet;
import java.text.ParseException;
import java.util.List;
diff --git a/src/org/molgenis/framework/db/DatabaseException.java b/src/org/molgenis/framework/db/DatabaseException.java
index 2211f3cd9..73cf92010 100644
--- a/src/org/molgenis/framework/db/DatabaseException.java
+++ b/src/org/molgenis/framework/db/DatabaseException.java
@@ -1,34 +1,40 @@
package org.molgenis.framework.db;
-/** A small class defining a database exception.
+/**
+ * A small class defining a database exception.
*
* @author ?
- *
+ *
*/
-public class DatabaseException extends Exception {
+public class DatabaseException extends Exception
+{
String message = "";
/**
*
*/
private static final long serialVersionUID = 1L;
- public DatabaseException(String message) {
+ public DatabaseException(String message)
+ {
super(message);
this.message = message;
}
-
- public DatabaseException(Exception exception) {
+
+ public DatabaseException(Exception exception)
+ {
super(exception);
message = exception.getMessage();
}
-
- public DatabaseException(String message, Exception exception) {
+
+ public DatabaseException(String message, Exception exception)
+ {
super(exception);
this.message = message;
}
-
+
@Override
- public String getMessage() {
+ public String getMessage()
+ {
return message;
}
}
diff --git a/src/org/molgenis/framework/db/DatabaseMapper.java b/src/org/molgenis/framework/db/DatabaseMapper.java
index 816becb1d..c4abb7f6f 100644
--- a/src/org/molgenis/framework/db/DatabaseMapper.java
+++ b/src/org/molgenis/framework/db/DatabaseMapper.java
@@ -8,13 +8,13 @@
public interface DatabaseMapper
{
public E create();
-
+
public int add(List entities) throws DatabaseException;
public int update(List entities) throws DatabaseException;
-
+
public int remove(List entities) throws DatabaseException;
-
+
public String getTableFieldName(String field);
public FieldType getFieldType(String field);
diff --git a/src/org/molgenis/framework/db/ExampleData.java b/src/org/molgenis/framework/db/ExampleData.java
index def8c9d86..6f6764ec1 100644
--- a/src/org/molgenis/framework/db/ExampleData.java
+++ b/src/org/molgenis/framework/db/ExampleData.java
@@ -1,8 +1,8 @@
package org.molgenis.framework.db;
/**
- * Interface to load example data into a data model.
- * Should be used in the context of {@link Database.loadExampleData()}.
+ * Interface to load example data into a data model. Should be used in the
+ * context of {@link Database.loadExampleData()}.
*/
public interface ExampleData
{
diff --git a/src/org/molgenis/framework/db/Mapper.java b/src/org/molgenis/framework/db/Mapper.java
index 92b5a809e..4e0949189 100644
--- a/src/org/molgenis/framework/db/Mapper.java
+++ b/src/org/molgenis/framework/db/Mapper.java
@@ -16,66 +16,64 @@ public interface Mapper
{
/**
* Get the database this mapper is attached to.
+ *
* @return database
*/
public Database getDatabase();
public E create();
-
+
/** Implementation of {@link Database#count(Class, QueryRule...)} */
public int count(QueryRule... rules) throws DatabaseException;
- /** Implementation of {@link Database#find(Class, QueryRule...)}*/
+ /** Implementation of {@link Database#find(Class, QueryRule...)} */
public List find(QueryRule... rules) throws DatabaseException;
- /** Implementation of {@link Database#find(Class, TupleWriter, QueryRule...)}*/
- public void find(TupleWriter writer, QueryRule... rules)
- throws DatabaseException;
+ /** Implementation of {@link Database#find(Class, TupleWriter, QueryRule...)} */
+ public void find(TupleWriter writer, QueryRule... rules) throws DatabaseException;
- /** Implementation of {@link Database#find(Class, TupleWriter, List, QueryRule...)*/
- public void find(TupleWriter writer, List fieldsToExport,
- QueryRule[] rules) throws DatabaseException;
+ /**
+ * Implementation of
+ *
+ */
+ public void find(TupleWriter writer, List fieldsToExport, QueryRule[] rules) throws DatabaseException;
/** Implementation of {@link Database#add(Entity)} */
- //public int add(E entity) throws DatabaseException;
-
+ // public int add(E entity) throws DatabaseException;
+
/** Implementation of {@link Database#add(List)} */
public int add(List entities) throws DatabaseException;
- /** Implementation of {@link Database#add(Class, TupleReader, TupleWriter)}*/
- public int add(TupleReader reader, TupleWriter writer)
- throws DatabaseException;
+ /** Implementation of {@link Database#add(Class, TupleReader, TupleWriter)} */
+ public int add(TupleReader reader, TupleWriter writer) throws DatabaseException;
- /** Implementation of {@link Database#add(Entity)}*/
- //public int update(E entity) throws DatabaseException;
-
- /** Implementation of {@link Database#update(List)}*/
+ /** Implementation of {@link Database#add(Entity)} */
+ // public int update(E entity) throws DatabaseException;
+
+ /** Implementation of {@link Database#update(List)} */
public int update(List entities) throws DatabaseException;
- /** Implementation of {@link Database#update(TupleReader)}*/
+ /** Implementation of {@link Database#update(TupleReader)} */
public int update(TupleReader reader) throws DatabaseException;
- /** Implementation of {@link Database#remove(Entity)}*/
- //public int remove(E entity) throws DatabaseException;
-
- /** Implementation of {@link Database#remove(List)}*/
+ /** Implementation of {@link Database#remove(Entity)} */
+ // public int remove(E entity) throws DatabaseException;
+
+ /** Implementation of {@link Database#remove(List)} */
public int remove(List entities) throws DatabaseException;
- /** Implementation of {@link Database#remove(Class, TupleReader)*/
+ /** Implementation of */
public int remove(TupleReader reader) throws DatabaseException;
- public List toList(TupleReader reader, int limit)
- throws DatabaseException;
+ public List toList(TupleReader reader, int limit) throws DatabaseException;
public String getTableFieldName(String field);
public FieldType getFieldType(String field);
- public void resolveForeignKeys(List enteties) throws ParseException,
- DatabaseException;
+ public void resolveForeignKeys(List enteties) throws ParseException, DatabaseException;
- public String createFindSqlInclRules(QueryRule[] rules)
- throws DatabaseException;
+ public String createFindSqlInclRules(QueryRule[] rules) throws DatabaseException;
public E findById(Object id) throws DatabaseException;
diff --git a/src/org/molgenis/framework/db/MapperDecorator.java b/src/org/molgenis/framework/db/MapperDecorator.java
index d5dc91ff6..9b4287d94 100644
--- a/src/org/molgenis/framework/db/MapperDecorator.java
+++ b/src/org/molgenis/framework/db/MapperDecorator.java
@@ -48,13 +48,13 @@ public int count(QueryRule... rules) throws DatabaseException
}
@Override
- public List find(QueryRule ...rules) throws DatabaseException
+ public List find(QueryRule... rules) throws DatabaseException
{
return mapper.find(rules);
}
@Override
- public void find(TupleWriter writer, QueryRule ...rules) throws DatabaseException
+ public void find(TupleWriter writer, QueryRule... rules) throws DatabaseException
{
mapper.find(writer, rules);
}
@@ -110,8 +110,7 @@ public void find(TupleWriter writer, List fieldsToExport, QueryRule[] ru
}
@Override
- public void resolveForeignKeys(List enteties) throws ParseException,
- DatabaseException
+ public void resolveForeignKeys(List enteties) throws ParseException, DatabaseException
{
mapper.resolveForeignKeys(enteties);
}
@@ -122,24 +121,24 @@ public String createFindSqlInclRules(QueryRule[] rules) throws DatabaseException
return mapper.createFindSqlInclRules(rules);
}
-// @Override
-// public int add(E entity) throws DatabaseException
-// {
-// return this.mapper.add(entity);
-// }
-//
-// @Override
-// public int update(E entity) throws DatabaseException
-// {
-// // TODO Auto-generated method stub
-// return this.mapper.update(entity);
-// }
-//
-// @Override
-// public int remove(E entity) throws DatabaseException
-// {
-// return this.mapper.remove(entity);
-// }
+ // @Override
+ // public int add(E entity) throws DatabaseException
+ // {
+ // return this.mapper.add(entity);
+ // }
+ //
+ // @Override
+ // public int update(E entity) throws DatabaseException
+ // {
+ // // TODO Auto-generated method stub
+ // return this.mapper.update(entity);
+ // }
+ //
+ // @Override
+ // public int remove(E entity) throws DatabaseException
+ // {
+ // return this.mapper.remove(entity);
+ // }
@Override
public E findById(Object id) throws DatabaseException
@@ -179,5 +178,4 @@ public List createList(int i)
return this.mapper.createList(i);
}
-
}
diff --git a/src/org/molgenis/framework/db/Query.java b/src/org/molgenis/framework/db/Query.java
index d648d7a62..cec6e4bd5 100644
--- a/src/org/molgenis/framework/db/Query.java
+++ b/src/org/molgenis/framework/db/Query.java
@@ -3,9 +3,8 @@
import java.text.ParseException;
import java.util.List;
-import org.molgenis.util.TupleWriter;
import org.molgenis.util.Entity;
-
+import org.molgenis.util.TupleWriter;
/**
* Easily build complex QueryRules for Database.
@@ -30,7 +29,7 @@
public interface Query
{
/** Translates a String into a QueryRule and adds it */
- public abstract Query filter( String filter );
+ public Query filter(String filter);
/**
* Shorthand for
@@ -39,21 +38,26 @@ public interface Query
* 'new QueryRule(field, Operator.EQUALS, value)'
*
*/
- public abstract Query equals( String field, Object value );
-
+ public Query equals(String field, Object value);
+
/**
* Shorthand for equals
+ *
* @param field
* @param value
* @return
*/
- public abstract Query eq( String field, Object value );
-
- /** Shorthand for search all fields. Typically translates to 'like' on all textual fields
- * @param searchTerms the terms to search on, space seperated
+ public Query eq(String field, Object value);
+
+ /**
+ * Shorthand for search all fields. Typically translates to 'like' on all
+ * textual fields
+ *
+ * @param searchTerms
+ * the terms to search on, space seperated
*/
- public abstract Query search(String searchTerms) throws DatabaseException;
-
+ public Query search(String searchTerms) throws DatabaseException;
+
/**
* Shorthand for
*
@@ -61,7 +65,7 @@ public interface Query
* 'new QueryRule(field, Operator.IN, objectList)'
*
*/
- public abstract Query in( String field, List> objectList );
+ public Query in(String field, List> objectList);
/**
* Shorthand for
@@ -70,15 +74,16 @@ public interface Query
* 'new QueryRule(field, Operator.GREATER, value)'
*
*/
- public abstract Query greater( String field, Object value );
-
+ public Query greater(String field, Object value);
+
/**
* Shorthand for greater
+ *
* @param field
* @param value
* @return
*/
- public abstract Query gt(String field, Object value);
+ public Query gt(String field, Object value);
/**
* Shorthand for
@@ -87,7 +92,7 @@ public interface Query
* 'new QueryRule(field, Operator.GREATER_EQUAL, value)'
*
*/
- public abstract Query greaterOrEqual( String field, Object value );
+ public Query greaterOrEqual(String field, Object value);
/**
* Shorthand for
@@ -96,12 +101,12 @@ public interface Query
* 'new QueryRule(field, Operator.LESS, value)'
*
*/
- public abstract Query less( String field, Object value );
-
+ public Query less(String field, Object value);
+
/**
* Shorthand for lessThan
*/
- public abstract Query lt( String field, Object value );
+ public Query lt(String field, Object value);
/**
* Shorthand for
@@ -110,9 +115,8 @@ public interface Query
* 'new QueryRule(field, Operator.LESS_EQUAL, value)'
*
*/
- public abstract Query lessOrEqual( String field, Object value );
+ public Query lessOrEqual(String field, Object value);
-
/**
* Shorthand for
*
@@ -120,25 +124,28 @@ public interface Query
* 'new QueryRule(field, Operator.LIKE, value)'
*
*/
- public abstract Query like(String field, Object value);
-
+ public Query like(String field, Object value);
+
/**
* Between, inclusive
+ *
* @param field
- * @param min minimum valid value
- * @param max maximum valid value
+ * @param min
+ * minimum valid value
+ * @param max
+ * maximum valid value
* @return Query
*/
- public abstract Query between(String field, Object min, Object max);
-
+ public Query between(String field, Object min, Object max);
+
/** Add the 'or' option on last queryrule */
- public abstract Query or();
-
- /**
+ public Query or();
+
+ /**
* Add the 'and' option on last query rule (default)
*/
- public abstract Query and();
-
+ public Query and();
+
/**
* Shorthand for
*
@@ -146,7 +153,7 @@ public interface Query
* 'new QueryRule(Operator.LAST)'
*
*/
- public abstract Query last();
+ public Query last();
/**
* Shorthand for
@@ -155,7 +162,7 @@ public interface Query
* 'new QueryRule(Operator.LIMIT, limit)'
*
*/
- public abstract Query limit( int limit );
+ public Query limit(int limit);
/**
* Shorthand for
@@ -164,7 +171,7 @@ public interface Query
* 'new QueryRule(Operator.OFFSET, offset)'
*
*/
- public abstract Query offset( int offset );
+ public Query offset(int offset);
/**
* Shorthand for
@@ -173,7 +180,7 @@ public interface Query
* 'new QueryRule(Operator.ORDER_ASC, orderByField)'
*
*/
- public abstract Query sortASC( String orderByField );
+ public Query sortASC(String orderByField);
/**
* Shorthand for
@@ -182,7 +189,7 @@ public interface Query
* 'new QueryRule(Operator.ORDER_DESC, orderByField)'
*
*/
- public abstract Query sortDESC( String orderByField );
+ public Query sortDESC(String orderByField);
/**
* Execute the query on a database.
@@ -192,34 +199,37 @@ public interface Query
* UnsupportedOperationException().
*
* @throws DatabaseException
- * @throws ParseException
+ * @throws ParseException
*/
- public abstract List find() throws DatabaseException;
-
+ public List find() throws DatabaseException;
+
/** Finder for csv data */
- public abstract void find(TupleWriter writer) throws DatabaseException, ParseException;
+ public void find(TupleWriter writer) throws DatabaseException, ParseException;
+
+ /** Finder for csv data with added option only export particular fields */
+ public void find(TupleWriter writer, List fieldsToExport) throws DatabaseException, ParseException;
- /** Finder for csv data with added option only export particular fields*/
- public abstract void find(TupleWriter writer, List fieldsToExport) throws DatabaseException, ParseException;
+ /**
+ * Finder for csv data with added option to only skip ids
+ *
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ */
+ public void find(TupleWriter writer, boolean skipAutoIds) throws DatabaseException, ParseException,
+ InstantiationException, IllegalAccessException;
- /** Finder for csv data with added option to only skip ids
- * @throws IllegalAccessException
- * @throws InstantiationException */
- public abstract void find(TupleWriter writer, boolean skipAutoIds) throws DatabaseException, ParseException, InstantiationException, IllegalAccessException;
-
-
/**
* Execute the query on a database.
*
* Will return a List of E.
*
* @param db
- * the Database to run this query on.
+ * the Database to run this query on.
* @param klazz
- * the Class to run this query on.
- * @throws ParseException
+ * the Class to run this query on.
+ * @throws ParseException
*/
- public List find( Database db, Class klazz ) throws DatabaseException, ParseException;
+ public List find(Database db, Class klazz) throws DatabaseException, ParseException;
/**
* Execute the query on a database and count the results.
@@ -238,39 +248,45 @@ public interface Query
* Will return a List of E.
*
* @param db
- * the Database to run this query on.
+ * the Database to run this query on.
* @param klazz
- * the Class to run this query on.
+ * the Class to run this query on.
*/
- public int count( Database db, Class klazz ) throws DatabaseException;
+ public int count(Database db, Class klazz) throws DatabaseException;
/** Retrieve array of current QueryRules in this query */
- public abstract QueryRule[] getRules();
+ public QueryRule[] getRules();
/** Pretty print the query rules */
- public abstract String toString();
+ public String toString();
/** Add rules to the query */
- public abstract void addRules( QueryRule... addRules );
+ public void addRules(QueryRule... addRules);
- /** Set the database to use for this query*/
- public abstract void setDatabase(Database db);
+ /** Set the database to use for this query */
+ public void setDatabase(Database db);
- /** Get the database to use for this query*/
- public abstract Database getDatabase();
+ /** Get the database to use for this query */
+ public Database getDatabase();
/** Create a query based on the non-null values of an example */
public Query example(Entity example);
-
- public abstract void removeRule(QueryRule ruleToBeRemoved);
- /** Produce the sql that would be used to query
- * @return
- * @throws DatabaseException */
- public abstract String createFindSql() throws DatabaseException;
+ public void removeRule(QueryRule ruleToBeRemoved);
+
+ /**
+ * Produce the sql that would be used to query
+ *
+ * @return
+ * @throws DatabaseException
+ */
+ public String createFindSql() throws DatabaseException;
- /** Method to create 'where field in (select * from ...)' subquery as condition */
+ /**
+ * Method to create 'where field in (select * from ...)' subquery as
+ * condition
+ */
Query subquery(String field, String sql);
-
+
public Query subQuery(SubQueryRule subQueryRule);
}
\ No newline at end of file
diff --git a/src/org/molgenis/framework/db/QueryImp.java b/src/org/molgenis/framework/db/QueryImp.java
index 18a745f17..95f56f656 100644
--- a/src/org/molgenis/framework/db/QueryImp.java
+++ b/src/org/molgenis/framework/db/QueryImp.java
@@ -5,13 +5,14 @@
import java.util.Vector;
import org.molgenis.framework.db.QueryRule.Operator;
-import org.molgenis.util.TupleWriter;
import org.molgenis.util.Entity;
+import org.molgenis.util.TupleWriter;
/**
* Simple implementation of the Query interface.
*/
-public class QueryImp implements Query {
+public class QueryImp implements Query
+{
public Class getKlazz()
{
return klazz;
@@ -22,7 +23,8 @@ public Class getKlazz()
private Database database;
/** Construct a Query that is not bound to a database and entity-type */
- public QueryImp() {
+ public QueryImp()
+ {
}
/**
@@ -34,29 +36,32 @@ public QueryImp() {
* @param klazz
* the Entity class that this Query will filter.
*/
- public QueryImp(Database db, Class klazz) {
+ public QueryImp(Database db, Class klazz)
+ {
this.database = db;
this.klazz = klazz;
}
- public QueryImp(Class klazz) {
+ public QueryImp(Class klazz)
+ {
this.klazz = klazz;
}
@Override
- public Query filter(String filter) {
+ public Query filter(String filter)
+ {
String[] args = filter.split(" "); // FIXME
- this.rules.add(new QueryRule(args[0], QueryRule.Operator
- .valueOf(args[1]), args[2]));
+ this.rules.add(new QueryRule(args[0], QueryRule.Operator.valueOf(args[1]), args[2]));
return this;
}
@Override
- public Query equals(String field, Object value) {
+ public Query equals(String field, Object value)
+ {
rules.add(new QueryRule(field, Operator.EQUALS, value));
return this;
}
-
+
@Override
public Query search(String searchTerms)
{
@@ -65,135 +70,158 @@ public Query search(String searchTerms)
}
@Override
- public Query in(String field, List> values) {
- if (values.size() > 0) {
+ public Query in(String field, List> values)
+ {
+ if (values.size() > 0)
+ {
rules.add(new QueryRule(field, Operator.IN, values.toArray()));
}
return this;
}
-
+
@Override
public Query subquery(String field, String sql)
{
rules.add(new QueryRule(field, Operator.IN_SUBQUERY, sql));
return this;
- }
-
- public Query subQuery(SubQueryRule subQueryRule)
+ }
+
+ public Query subQuery(SubQueryRule subQueryRule)
{
rules.add(subQueryRule);
return this;
}
-
@Override
- public Query greater(String field, Object value) {
+ public Query greater(String field, Object value)
+ {
rules.add(new QueryRule(field, Operator.GREATER, value));
return this;
}
@Override
- public Query greaterOrEqual(String field, Object value) {
+ public Query greaterOrEqual(String field, Object value)
+ {
rules.add(new QueryRule(field, Operator.GREATER_EQUAL, value));
return this;
}
@Override
- public Query less(String field, Object value) {
+ public Query less(String field, Object value)
+ {
rules.add(new QueryRule(field, Operator.LESS, value));
return this;
}
@Override
- public Query lessOrEqual(String field, Object value) {
+ public Query lessOrEqual(String field, Object value)
+ {
rules.add(new QueryRule(field, Operator.LESS_EQUAL, value));
return this;
}
@Override
- public Query between(String field, Object min, Object max) {
+ public Query between(String field, Object min, Object max)
+ {
return this.lessOrEqual(field, max).greaterOrEqual(field, min);
}
@Override
- public Query like(String field, Object value) {
+ public Query like(String field, Object value)
+ {
rules.add(new QueryRule(field, Operator.LIKE, value));
return this;
}
@Override
- public Query last() {
+ public Query last()
+ {
rules.add(new QueryRule(Operator.LAST));
return this;
}
@Override
- public Query or() {
+ public Query or()
+ {
rules.add(new QueryRule(Operator.OR));
return this;
}
@Override
- public Query and() {
+ public Query and()
+ {
rules.add(new QueryRule(Operator.AND));
return this;
}
@Override
- public Query limit(int limit) {
+ public Query limit(int limit)
+ {
rules.add(new QueryRule(QueryRule.Operator.LIMIT, limit));
return this;
}
@Override
- public Query offset(int offset) {
+ public Query offset(int offset)
+ {
rules.add(new QueryRule(QueryRule.Operator.OFFSET, offset));
return this;
}
@Override
- public Query sortASC(String orderByField) {
+ public Query sortASC(String orderByField)
+ {
rules.add(new QueryRule(Operator.SORTASC, orderByField));
return this;
}
@Override
- public Query sortDESC(String orderByField) {
+ public Query sortDESC(String orderByField)
+ {
rules.add(new QueryRule(Operator.SORTDESC, orderByField));
return this;
}
@Override
- public QueryRule[] getRules() {
+ public QueryRule[] getRules()
+ {
return rules.toArray(new QueryRule[rules.size()]);
}
@Override
- public String toString() {
- String result = "";
- for (QueryRule rule : this.getRules()) {
- result += rule.toString();
+ public String toString()
+ {
+ StringBuilder strBuilder = new StringBuilder();
+ for (QueryRule rule : this.getRules())
+ {
+ strBuilder.append(rule.toString());
}
- return result;
+ return strBuilder.toString();
}
- public void addRules(List addRules) {
- if (addRules != null) {
+ public void addRules(List addRules)
+ {
+ if (addRules != null)
+ {
this.addRules(addRules.toArray(new QueryRule[addRules.size()]));
}
}
@Override
- public void addRules(QueryRule... addRules) {
- for (QueryRule rule : addRules) {
+ public void addRules(QueryRule... addRules)
+ {
+ for (QueryRule rule : addRules)
+ {
// Logger.getLogger("test").debug("added rule " + rule);
rules.add(rule);
}
}
@Override
- public List find() throws DatabaseException {
- if (this.klazz != null && this.database != null) {
+ public List find() throws DatabaseException
+ {
+ if (this.klazz != null && this.database != null)
+ {
return this.find(this.database, this.klazz);
}
throw new UnsupportedOperationException(
@@ -201,13 +229,16 @@ public List find() throws DatabaseException {
}
@Override
- public List find(Database db, Class klazz) throws DatabaseException {
+ public List find(Database db, Class klazz) throws DatabaseException
+ {
return db.find(klazz, this.getRules());
}
@Override
- public int count() throws DatabaseException {
- if (this.klazz != null && this.database != null) {
+ public int count() throws DatabaseException
+ {
+ if (this.klazz != null && this.database != null)
+ {
return this.count(this.database, this.klazz);
}
throw new UnsupportedOperationException(
@@ -215,58 +246,68 @@ public int count() throws DatabaseException {
}
@Override
- public int count(Database db, Class klazz) throws DatabaseException {
+ public int count(Database db, Class klazz) throws DatabaseException
+ {
return db.count(klazz, this.getRules());
}
@Override
- public void find(TupleWriter writer) throws DatabaseException, ParseException {
+ public void find(TupleWriter writer) throws DatabaseException, ParseException
+ {
find(writer, null);
}
@Override
- public void find(TupleWriter writer, List fieldsToExport)
- throws DatabaseException, ParseException {
- if (this.klazz != null && this.database != null) {
+ public void find(TupleWriter writer, List fieldsToExport) throws DatabaseException, ParseException
+ {
+ if (this.klazz != null && this.database != null)
+ {
database.find(this.klazz, writer, fieldsToExport, this.getRules());
- } else {
+ }
+ else
+ {
throw new UnsupportedOperationException(
"Cannot execute this count query because no database and entity is provided. Use count(Database,Class)");
}
}
@Override
- public void find(TupleWriter writer, boolean skipAutoId)
- throws DatabaseException, ParseException, InstantiationException,
- IllegalAccessException {
+ public void find(TupleWriter writer, boolean skipAutoId) throws DatabaseException, ParseException,
+ InstantiationException, IllegalAccessException
+ {
this.find(writer, this.klazz.newInstance().getFields(skipAutoId));
}
@Override
- public Query eq(String field, Object value) {
+ public Query eq(String field, Object value)
+ {
return this.equals(field, value);
}
@Override
- public Query