How to do an IF/ELSE in NANT 0.91? - nant

We're using Nant 0.91 so <choose> is not available. How would you do an IF/ELSE in Nant 0.91? I would like to do something like (using NAnt 0.92 syntax) in NAnt 0.91. [I am not allowed to modify the current installation of NAnt 0.91]:
<choose>
<when test="${deploy.env=='PROD'}">
<property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${app.dest.dir}\" />
</when>
<otherwise>
<property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${deploy.env}\${app.dest.dir}\" />
</otherwise>
</choose>

The simplest solution, which we use here, is to just use two if tasks, one with a negative test to the other:
<if test="${deploy.env == 'PROD'}">
<property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${app.dest.dir}\" />
</if>
<if test="${deploy.env != 'PROD'}">
<property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${deploy.env}\${app.dest.dir}\" />
</if>
However in your case, you can also make use of the fact that the property task has inbuilt if/unless functionality:
<property name="deploy.root.dir" if="${deploy.env == 'PROD'}" value="\\${deploy.server}\${deploy.mode}\${app.dest.dir}\" />
<property name="deploy.root.dir" unless="${deploy.env == 'PROD'}" value="\\${deploy.server}\${deploy.mode}\${deploy.env}\${app.dest.dir}\" />

You can set a default property value and then an override if the condition is true:
<property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${deploy.env}\${app.dest.dir}\" />
<if test="${deploy.env == 'PROD'}">
<property name="deploy.root.dir" value="\\${deploy.server}\${deploy.mode}\${app.dest.dir}\" />
</if>

Related

Hibernate exception javassist

I need some help as I'm stumped on an Hibernate 4/Struts 2 project. This is my first Hibernate 4 (4.3.11) project, as I worked for years with Hibernate 3. The database is MySQL 5.
All mapping classes were produced with Hibernate Tools provided by JBoss Tools 4.3.5, on Eclipse Mars 2. No problem was encountered, it worked fine.
But when testing, I faced this exception :
2017-02-16 17:23:45 ERROR Dispatcher:38 - Exception occurred during processing request: metier.Ville_$$_javassist_2 cannot be cast to javassist.util.proxy.Proxy
java.lang.ClassCastException: metier.Ville_$$_javassist_2 cannot be cast to javassist.util.proxy.Proxy
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:147)
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:75)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:771)
I read that post but I don't understand what's happening.
Two classes are involved : Salle and Ville. Here's the Hibernate XML files : Salle.hbm.xml & Ville.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 2 f?vr. 2017 11:28:16 by Hibernate Tools 4.3.5.Final -->
<hibernate-mapping>
<class name="metier.Salle" table="salle" catalog="aevbadherents" optimistic-lock="version">
<id name="idSalle" type="int">
<column name="idSALLE" />
<generator class="assigned" />
</id>
<many-to-one name="ville" class="metier.Ville" fetch="select">
<column name="idVilleSalle" />
</many-to-one>
<property name="adresse1" type="string">
<column name="Adresse1" length="80" />
</property>
<property name="adresse2" type="string">
<column name="Adresse2" length="80" />
</property>
<property name="description" type="string">
<column name="Description" length="500" />
</property>
<set name="courses" table="cours" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdSalle" not-null="true" />
</key>
<one-to-many class="metier.Cours" />
</set>
<set name="passagegrades" table="passagegrade" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdSalle" />
</key>
<one-to-many class="metier.Passagegrade" />
</set>
</class>
</hibernate-mapping>
The second file :
<hibernate-mapping>
<class name="metier.Ville" table="ville" catalog="aevbadherents" optimistic-lock="version">
<id name="idVille" type="int">
<column name="idVILLE" />
<generator class="assigned" />
</id>
<many-to-one name="departement" class="metier.Departement" fetch="select">
<column name="idDepartement" not-null="true" />
</many-to-one>
<property name="nom" type="string">
<column name="Nom" length="60" not-null="true" />
</property>
<property name="codepostal" type="string">
<column name="codepostal" length="6" not-null="true" />
</property>
<property name="gpslat" type="string">
<column name="GPSLat" length="12" not-null="true" />
</property>
<property name="gpslon" type="string">
<column name="GPSLon" length="12" not-null="true" />
</property>
<set name="adherentsForIdVilleResid" table="adherent" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdVilleResid" />
</key>
<one-to-many class="metier.Adherent" />
</set>
<set name="clubs" table="club" inverse="true" lazy="true" fetch="select">
<key>
<column name="idville" not-null="true" />
</key>
<one-to-many class="metier.Club" />
</set>
<set name="salles" table="salle" inverse="true" lazy="true" fetch="select">
<key>
<column name="idVilleSalle" />
</key>
<one-to-many class="metier.Salle" />
</set>
<set name="adherentsForIdVilleNais" table="adherent" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdVilleNais" />
</key>
<one-to-many class="metier.Adherent" />
</set>
</class>
</hibernate-mapping>
I read that this exception may be caused by a JAR conflict, but I did not find anything.I don't use Maven (maybe I should ?), so let me show you the JARs included :
antlr-2.7.7.jar
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.2-javadoc.jar
commons-logging-1.2.jar
dom4j-1.6.1.jar
freemarker-2.3.19.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.11.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
log4j-1.2.15.jar
mysql-connector-java-5.1.40-bin.jar
ognl-3.0.6.jar
struts2-core-2.3.15.3.jar
truc.txt
xwork-core-2.3.15.3.jar
Please help me, as I'm stumped...
One of the possible cause for this problem is that you have in your classpath several versions of the same class.
I have been looking in java2s.com and, none of the jar you listed, seems to contain the class javassist.util.proxy.Proxy, so I will try to find if any other jar contains that class using jarscan with the following command:
jarscan -d PATH_TO_YOUR_CLASSPATH_DIR -j javassist.util.proxy.Proxy
You can download jarscan from here https://java.net/projects/jarscan/downloads
If you found that several packages contains the same class, you are done.
Malaguna,
Thanks for your help. Here's the result of jarscan :
D:\temp\java\jarscan>jarscan -j javassist.util.proxy.Proxy
......................
+javassist-3.18.1-GA.jar
javassist-3.18.1-GA.jar\javassist/util/proxy/Proxy.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$1.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$2.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$3.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$ClassLoaderProvide
r.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$Find2MethodsArgs.c
lass
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$ProxyDetails.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$UniqueName.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyObject.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyObjectInputStream.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyObjectOutputStream.class
----------------------------------------------
Scanned archives: 22
Errors: 0
Archives with hits: 12
So, it means that no other jar contains that class.

SAPUI5 - mockup server

I'm following this Mockup Server tutorial for SAPUI5. But I'm not able to retrieve the data and set it to my model. Here's what I do:
I have slightly changed the data so, so two things have to be changed:
json data - Person.json:
{ "id":1,
"first_name":"Chris",
"last_name":"Johnston", "email":"cjohnston0#dailymotion.com", "gender":"Male", "ip_address":"119.220.205.173" }
emphasized text
``
<edmx:Edmx Version="1.0"
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"/>
<edmx:DataServices m:DataServiceVersion="1.0"
m:MaxDataServiceVersion="3.0">
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="PersonsData" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityType Name="Person">
<Key>
<PropertyRef Name="id"/>
</Key>
<Property name="id" Type="Edm.Int16" Nullable="false" />
<Property Name="first_name" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
<Property Name="last_name" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
<Property Name="email" Type="Edm.String" Nullable="false"/>
<Property Name="gender" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false"/>
<Property Name="ip_address" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
</EntityType>
</Schema>
<Schema Namespace="databinding.PersonsData.Model" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="PersonEntities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true"
xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntitySet Name="Persons" EntityType="PersonsData.Invoice"/>
</EntityContainer>
</Schema>
</edmx:DataServices>
The SAPUI5 Web IDE says that edmx namespace does not exist.
So I went to check edmx namespace and it does not exists.
Chrome developer tools reports the same error:
Could this be the problem?
I checked and mockserver.init() is triggered.
Did Microsoft moved this namespace somewhere? Cause I was not able to find it.
Thanks
what I see is that you messed up your XML structure. As the error says your XML is invalid.
You've closed the surrounding edmx:Edmx tag at the beginning of the document
You've closed the edmx:DataServices tag too early
Furthermore the attribute name of the property id is in lowercase. Try to make an uppercased Name.
Try to use this xml:
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="PersonsData" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityType Name="Person">
<Key>
<PropertyRef Name="id"/>
</Key>
<Property Name="id" Type="Edm.Int16" Nullable="false"/>
<Property Name="first_name" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
<Property Name="last_name" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
<Property Name="email" Type="Edm.String" Nullable="false"/>
<Property Name="gender" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false"/>
<Property Name="ip_address" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true"/>
</EntityType>
</Schema>
<Schema Namespace="databinding.PersonsData.Model" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="PersonEntities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true"
xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntitySet Name="Persons" EntityType="PersonsData.Invoice"/>
</EntityContainer>
</Schema>
</edmx:DataServices>

DB2 in AS400 date format configuration using spring

I'm trying to get a date after 12-31-2039 in DB2 but it always returns null. My project uses spring JDBC configured with jt400.jar JDBC driver. How can I resolve this problem? Follows my config at spring:
<bean id="dataSource" class="br.com.mycompany.persistence.driver.SecuredAS400JDBC">
<property name="serverName" value="${br.com.mycompany.dao.jdbc.server}" />
<property name="databaseName" value="${br.com.mycompany.dao.jdbc.database}" />
<property name="libraries" value="${br.com.mycompany.dao.jdbc.database}" />
<property name="user" value="${br.com.mycompany.dao.jdbc.username}" />
<property name="password" value="${br.com.mycompany.dao.jdbc.password}" />
<property name="dataTruncation" value="false" />
<property name="naming" value="sql" />
<property name="errors" value="full" />
<property name="trace" value="false" />
<property name="prompt" value="false" />
</bean>
And here is my resultset operation:
private static final class rowMapperDTO implements RowMapper<AcionamentoFaixa> {
public AcionamentoFaixa mapRow(ResultSet rs, int rowNum) throws SQLException {
AcionamentoFaixa obj = new AcionamentoFaixa();
obj.setDe(rs.getDate(4));
obj.setAte(rs.getDate(5));
return obj;
}
}
I found the answer at IBM Toolbox Java official documentation: http://www-03.ibm.com/systems/power/software/i/toolbox/faq/jdbc.html#faqB5
"The Toolbox JDBC driver uses the date format that is set up as the
default on the IBM i system. This default is usually set to "mdy"
which only supports dates between 1940 and 2039. You can override the date format by specifying the "date format" property when opening the JDBC connection. The best choice is "iso", which supports a full four-digit date."
So, I tried to config the bean with the property dateFormat to iso and it works perfectly!
<bean id="dataSource" class="br.com.mycompany.persistence.driver.SecuredAS400JDBC">
<property name="serverName" value="${br.com.mycompany.dao.jdbc.server}" />
<property name="databaseName" value="${br.com.mycompany.dao.jdbc.database}" />
<property name="libraries" value="${br.com.mycompany.dao.jdbc.database}" />
<property name="user" value="${br.com.mycompany.dao.jdbc.username}" />
<property name="password" value="${br.com.mycompany.dao.jdbc.password}" />
<property name="dataTruncation" value="false" />
<property name="naming" value="sql" />
<property name="errors" value="full" />
<property name="trace" value="false" />
<property name="prompt" value="false" />
<property name="dateFormat" value="iso" />
</bean>

Sakai Hibernate lazy initialize

I'm having some issues building my database. I have this two hbm mappings:
<class name="br.unicamp.iel.model.Module" table="readinweb_modules">
<id name="id" type="java.lang.Long">
<generator class="increment" />
</id>
<many-to-one name="course" class="br.unicamp.iel.model.Course"
column="course_id" fetch="select" />
<property name="position" type="integer" />
<property name="module_grammar" type="text" />
</class>
<class name="br.unicamp.iel.model.Course" table="readinweb_courses">
<id name="id" type="java.lang.Long">
<generator class="increment" />
</id>
<property name="title" length="255" not-null="true" type="string" />
<property name="idiom" length="255" not-null="true" type="string" />
<property name="description" type="text" />
<set name="courseModules" table="readinweb_modules"
inverse="true" lazy="true" fetch="select">
<key column="id" not-null="true" />
<one-to-many class="br.unicamp.iel.model.Module" />
</set>
</class>
and when I try to access data on my logic bean as:
List modules = new ArrayList(dao.findById(Course.class,
course).getCourseModules());
it gives me a
org.hibernate.LazyInitializationException: failed to lazily initialize
a collection of role: br.unicamp.iel.model.Course.courseModules, no
session or session was closed
We need to see the complete code of the
List modules = new ArrayList(dao.findById(Course.class, course).getCourseModules())
Do you open and close a Session (or a EntityManager) inside the dao.findById method? The session must still be open to resolve lazy relationships

if condition in nant

I am trying to figure out how to write a simple if condition in nant
that will evaluate to true when both x & y properties are true.
<project default="all">
<property name="x" value="True" />
<property name="y" value="True" />
<target name="all">
<echo message="x is True" if="${x}" />
<echo message="y is True" if="${x}" />
<echo message="x AND y are True" if="${x} AND ${y}" />
<echo message="x AND y are True" if="${x} && ${y}" />
</target>
</project>
I cannot figure out the syntax for the x AND y echo message - I tried both AND and '&&' and that doesn't seem to work.(i keep getting error messages like : String was not recognized as a valid Boolean.)
You want to use if="${x and y}", where both x and y are in the same pair of brackets:
<project default="all">
<property name="x" value="true" />
<property name="y" value="true" />
<target name="all">
<echo message="x is True" if="${x}" />
<echo message="y is True" if="${y}" />
<echo message="x AND y are True" if="${x and y}" />
</target>
</project>
Hope that helps!