Problem using DdlUtils with Oracle 11.1.0 - java

This question is similar to question https://stackoverflow.com/questions/3362965/problem-with-ddlutils-in-oracle-10g. Since my problem is (or at least i think it is) slightly different to the question mentioned, i post a new one.
I am using DdlUtils-1.0, Java-6 (OpenJdk), ojdbc6.jar and Oracle 11.1.0. The migration is started by ant tasks. The task looks like this:
<target name="dump-db" description="Dumps DB" depends="">
<taskdef name="databaseToDdl" classname="org.apache.ddlutils.task.DatabaseToDdlTask">
<classpath>
<path refid="runtime-classpath"/>
<path refid="project-classpath"/>
</classpath>
</taskdef>
<databaseToDdl modelname="${modelname}" verbosity="DEBUG" databasetype="${source.platform}"
usedelimitedsqlidentifiers="true" tabletypes="TABLE" schemapattern="${schemapattern}">
<database url="${source.url}"
driverClassName="${source.driver}"
username="${source.username}"
password="${source.passwd}"
initialsize="5"
testonborrow="true"
testonreturn="true"/>
<writeschemasqltofile failonerror="false" outputfile="${out.dir}/${schema.file.sql}"/>
<writedtdtofile outputfile="${out.dir}/${schema.file.dtd}"/>
<writeSchemaToFile failonerror="false" outputFile="${out.dir}/${schema.file.xml}"/>
<writedatatofile failonerror="false" outputfile="${out.dir}/${data.file.xml}" determineschema="true"/>
</databaseToDdl>
</target>
${source.platform} is set to 'oracle10', since oracle11 is not supported by ddlutils. Creation of schema definitions works quite well, but when dumping the data i face the following exception:
[databaseToDdl] org.apache.ddlutils.model.ModelException: Unknown JDBC type code 2007
[databaseToDdl] at org.apache.ddlutils.model.Column.setTypeCode(Column.java:215)
[databaseToDdl] at org.apache.ddlutils.platform.JdbcModelReader.readColumn(JdbcModelReader.java:781)
[databaseToDdl] at org.apache.ddlutils.platform.oracle.Oracle8ModelReader.readColumn(Oracle8ModelReader.java:117)
[databaseToDdl] at org.apache.ddlutils.platform.JdbcModelReader.readColumns(JdbcModelReader.java:755)
[databaseToDdl] at org.apache.ddlutils.platform.JdbcModelReader.readTable(JdbcModelReader.java:565)
[databaseToDdl] at org.apache.ddlutils.platform.oracle.Oracle8ModelReader.readTable(Oracle8ModelReader.java:102)
[databaseToDdl] at org.apache.ddlutils.platform.oracle.Oracle10ModelReader.readTable(Oracle10ModelReader.java:80)
[databaseToDdl] at
...
In http://download.oracle.com/javase/6/docs/api/constant-values.html#java.sql.Types.BIT the jdbc type codes are listed. Apparently ddlutils gets this type code from the jdbc driver but could not find a corresponding type in java.sql.Types.
Does anybody have an idea how to solve this?

It's very late, after 5 years,
However thought, can be helpful for few in in future.
Visit: org.apache.ddlutils.model.TypeMap
Method: getJdbcTypeName(int typeCode)
write small logic, to set 2007 to 12
ie;
if(typeCode == 2007){
typeCode = java.sql.Types.VARCHAR;
}
Issue: TypeMapping in DdlUtils, is done with exisitinf java.sql.Types enum. Whereas, for the Oracle11g, the are few extra types. Hence issue raised.
Hope it helps.

Related

How to make Ant junit task show detail only if a test fails?

My Ant junit task is currently set to output minimal information. On the console, for each test class, it prints the class name, how many tests were run, failed, and errored, along with the elapsed time for each test. If the test failed, there's an additional line saying the test failed.
I'd like to get additional detail on the console, but ONLY if a test fails. If I follow advice like this, by adding an additional plain formatter with usefile=false, then I get additional redundant detail for ALL tests, even if all tests pass. This includes printing each test method executed, and a redundant line for each test class.
Is it possible to get this?
I believe I've implemented a reasonable solution.
The key points of the solution are:
* Executing a task after the unit tests are complete, which only runs if "test.failed"
* Use the "xmltask" task library to parse the test results files and emit concise results
I wrote the following target to do this:
<target name="show-unit-test-failures" if="test.failed">
<taskdef if:set="xmltask.present" name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
<echo if:set="xmltask.present" message="Unit test failure report details:"/>
<xmltask if:set="xmltask.present">
<fileset dir="gen/reports/artifacts/junit">
<include name="TEST-*Test.xml"/>
</fileset>
<call path="//testcase[./error]">
<parThatam name="className" path="#classname"/>
<param name="methodName" path="#name"/>
<param name="errorText" path="./error/text()"/>
<actions>
<echo>---------------------------------</echo>
<echo>#{className}.#{methodName}:</echo>
<echo>#{errorText}</echo>
</actions>
</call>
<call path="//testcase[./failure]">
<param name="className" path="#classname"/>
<param name="methodName" path="#name"/>
<param name="errorText" path="./failure/text()"/>
<actions>
<echo>---------------------------------</echo>
<echo>#{className}.#{methodName}:</echo>
<echo>#{errorText}</echo>
</actions>
</call>
</xmltask>
</target>
Note that I also let it "fail gracefully" if the "xmltask.jar" file isn't available. The ability to reference namespaces in tasks is a new feature in Ant 1.9.1 and newer.
I call this target at the end of my "run-unit-test" target.

Ant conditional property expansion not working as expected

So, I have this setup in ant:
<target name="context">
<echo>docbase: ${docbase.dir}</echo>
<antcall target="_context.docbase"/>
<antcall target="_context.nodocbase"/>
</target>
<target name="_context.docbase" if="${docbase.dir}">
<echo>Context with docbase</echo>
<context.md docbase="..."/>
</target>
<target name="_context.nodocbase" unless="${docbase.dir}">
<echo>Context without docbase</echo>
<context.md/>
</target>
And when docbase.dir is set to true or false things work as you'd expect. But when docbase.dir is set to an actual value (e.g., /tmp/docbase) for some reason it hits the _context.nodocbase target instead of the expected _context.docbase target.
Reading the docs it implies that if the expanded property isn't one of the "truthy" for "falsey" constants then it will just interpret it as before, but this isn't what I'm seeing.
What am I doing wrong? Should I use a different approach?
Note: I'm using Ant 1.8.2 (and conditional parameter expansion started in 1.8.0).
As mentioned here: http://ant.apache.org/manual/properties.html
As of Ant 1.8.0, you may instead use property expansion; a value of true (or on or yes) will enable the item, while false (or off or no) will disable it. Other values are still assumed to be property names and so the item is enabled only if the named property is defined.
This is some really subtle information here. So what's going on in your code is ${docbase.dir} is expanded to "/tmp/docbase". That's not true/on/yes/false/off/no so Ant then looks for a property named "/tmp/docbase". It can't find it, so it runs the unless.
Here's an example that I hope will clarify things. This will run only the if target:
<project name="MyProject" default="context" basedir=".">
<target name="context">
<echo>docbase: ${docbase.dir}</echo>
<property name="/tmp/docbase" value="i exist!"/>
<antcall target="_context.docbase"/>
<antcall target="_context.nodocbase"/>
</target>
<target name="_context.docbase" if="${docbase.dir}">
<echo>Context with docbase</echo>
</target>
<target name="_context.nodocbase" unless="${docbase.dir}">
<echo>Context without docbase</echo>
</target>
</project>
The important thing here is this line:
<property name="/tmp/docbase" value="i exist!"/>
Because that property is defined, it will run the if and not the unless.

Ant publish stuff to different locations

I have a java project and an ANT script to build and then distribute the project to other projects with a simple copy command.
I would like to only name the place where to copy to files to once in the header of the ant script, and not have an explicit copy-task for every project that is dependent on this project.
I can't find anything like arrays in ANT, so what would be the cleanest way of distributing something to multiple directories?
According to what I commented under Martin's answer, I'd like to post my version of solution as another choice. And I am using property names from Martin's answer to make it clear.
<target name="deploy" >
<property name="dest.dirs" value="/dir/one,/dir/two,/dir/thr/ee" />
<for list="${dest.dirs}" param="dest.dir" parallel="true" delimiter="," >
<sequential>
<copy todir="#{dest.dir}" >
<fileset dir="${srd.dir}" />
</copy>
</sequential>
</for>
</target>
Please note that "for" is an Ant-Contrib task, and it's using Macrodef in the back so you should use #{} to refer to "dest.dir"; the "dest.dirs" will be splited into a list (maybe String[]) by delimiter. Here we use comma to split it (and the default value to delimiter is comma). I also added "parallel" to make it copy files to all the "dest.dirs" at same time, however, if the project to copy is large, you should delete "parallel".
Please check http://ant-contrib.sourceforge.net/tasks/tasks/for.html
and http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html for more information.
I don't believe you have many viable options: the copy task accepts only a single directory.
Create your own copy task that takes a list of directories.
Exec a script/program that does the copying.
Have the subprojects do a pull.
I'm really hesitant about having a project push to other projects, because that makes the assumption that those projects will work with the newly-pushed code. IMO the "sub-"projects should be making the decision if they want the new version or not.
To me this sounds more like a dependency management issue, better handled with Ivy/Maven/Gradle (or other Maven-alike).
All that said, it sounds like you'd want to do option 1, create a custom Ant task that accepts a list of destination directories; it might be pretty easy to just extend the existing copy task to get all its functionality--just add a "todirs" property.
You might consider using a scriptmapper in your copy task with enablemultiplemappings true.
First, list the target directories in a property and create a filelist from it. (You could use a dirset, but the API for filelist is simpler.) Then run the copy, with the scriptmapper setting up the multiple destinations.
<property name="dest.dirs" value="/dir/one,/dir/two,/dir/thr/ee" />
<filelist id="dests" dir="/" files="${dest.dirs}" />
<copy todir="/" enablemultiplemappings="yes">
<fileset dir="${srd.dir}" />
<scriptmapper language="javascript">
<![CDATA[
// Obtain a reference to the filelist
var filelist = project.getReference( "dests" );
var dests = filelist.getFiles( project );
for ( var i = 0; i < dests.length; i++ )
{
self.addMappedName( dests[i] + "/" + source );
}
]]>
</scriptmapper>
</copy>

Removing Date Comment from Apache's Ant PropertyFile Task

I'm using the propertyfile task shown below in my build script:
<target name="build-brand" depends="-init" description="Adds version information to branding files.">
<propertyfile file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties">
<entry key="currentVersion" value="${app.windowtitle} ${app.version}" />
</propertyfile>
</target>
The task works as expected, except that each time I build the project, the date comment line of the Bundle.properties file is updated with the current time stamp. This occurs even if the app.version variable does not change and results in an un-necessary commit to version control consisting solely of the following diff:
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
## -1,4 +1,4 ##
-#Thu, 22 Jul 2010 15:05:24 -0400
+#Tue, 10 Aug 2010 13:38:27 -0400
How can I prevent addition of or remove this date comment from the .properties file? I considered a delete operation in propertyfile nested entry element, but a key value is required.
This isn't a great solution, but how about removing the comment all together?
<target name="build-brand" depends="-init" description="Adds version information to branding files.">
<propertyfile file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties">
<entry key="currentVersion" value="${app.windowtitle} ${app.version}" />
</propertyfile>
<replaceregexp file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties" match="^#.*\n" replace=""/>
</target>
If you need to put a single property in a file just use echo:
<echo output="somefiles.properties">lastmodified=${lastmodified}</echo>
Try: <propertyfile file="..." comment="">
Edit: Which probably won't work :(. It looks like the culprit is actually Properties.store(OutputStream, String):
Next, a comment line is always
written, consisting of an ASCII #
character, the current date and time
(as if produced by the toString method
of Date for the current time), and a
line separator as generated by the
Writer.

(Unknown Source) in Exception stack trace

Background
This question is related to Why does String.valueOf(null) throw a NullPointerException?
Consider the following snippet:
public class StringValueOfNull {
public static void main(String[] args) {
String.valueOf(null);
// programmer intention is to invoke valueOf(Object), but instead
// code invokes valueOf(char[]) and throws NullPointerException
}
}
As explained in the answer to the linked question, Java's method overloading resolves the above invokation to String.valueOf(char[]), which rightfully results in a NullPointerException at run-time.
Compiled in Eclipse and javac 1.6.0_17, this is the stack trace:
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at StringValueOfNull.main(StringValueOfNull.java:3)
Note that the stack trace above is missing the KEY information: it does NOT have the full signature of the valueOf method! It just says String.valueOf(Unknown Source)!
In most situations I've encountered, exception stack traces always have the complete signature of the methods that are actually in the stack trace, which of course is very helpful in identifying the problem immediately and a major reason why the stack trace (which needless to say is rather expensive to construct) is provided in the first place.
And yet, in this case, the stack trace does not help at all. It has failed miserably in helping the programmer identify the problem.
As is, I can see 3 ways that a programmer can identify the problem with the above snippet:
Programmer realizes on his/her own that the method is overloaded, and by resolution rule, the "wrong" overload gets invoked in this case
Programmer uses a good IDE that allows him/her to quickly see which method is selected
In Eclipse, for example, mouse-hovering on the above expression quickly tells programmer that the String valueOf(char[] data) is indeed the one selected
Programmer examines the bytecode (ugh!)
The last option is probably the least accessible, but of course is the Ultimate Answer (a programmer may misunderstood the overloading rule, IDE may be buggy, but bytecodes always(?) tell the truth on what's being done).
The questions
Why is the stack trace so uninformative in this case with regards to the signatures of the methods that are actually in the stack trace?
Is this due to the compiler? The runtime? Something else?
In what other (rare?) scenarios can the stack trace fail to capture essential information like these?
Note that if you are using Ant build and if the debug attribute set to false in javac command this could happen.
ex : if you need proper location in trace set debug = true in Ant build,
<javac verbose="false" srcdir="${src}" destdir="${classdir}" debug="true" includes="**/*.java">
<classpath refid="compile.classpath" />
</javac>
This is normally related to missing debug information. You are probably using JRE (not JDK), which does not include debug information for rt.jar classes. Try using full JDK, you'll get proper locations in the stack trace:
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(String.java:177)
at java.lang.String.valueOf(String.java:2840)
at StringValueOfNull.main(StringValueOfNull.java:3)
I had the same problem, I'm using spring and apache ant for continuous integration.
The error I had was in the build.xml file.
The gender change log with more precise content was:
build.xml with the error:
<javac srcdir="${src.home}" destdir="${work.home}/WEB-INF/classes">
<classpath refid="compile.classpath" />
</javac>
build.xml without error:
<javac srcdir="${src.home}" destdir="${work.home}/WEB-INF/classes" debug="true">
<classpath refid="compile.classpath" />
</javac>
Within the structure I lacked the courage debug = "true"
I ran the code in Eclipse and I got the following output,
public class Aloof {
public static void main(String[] args) {
String.valueOf(null);
}
}
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(String.java:177)
at java.lang.String.valueOf(String.java:2840)
at mysql.Aloof.main(Aloof.java:19)
If you include the full source (from JDK), you can actually debug to the line 177 in String.java
This happens when there is no debug (line) information in the source or the VM is told to throw that information away at class loading time. Since you have some line numbers, it's not the VM setting but the class String is missing debug information.
In Eclipse: Preferences > Java > Installed JREs. The checked entry should have a path inside the JDK, e.g. C:\Program Files (x86)\Java\jdk1.7.0_55\jre.

Categories

Resources