seade 2004/08/23 04:49:47
Modified: src/generator/src/java/org/apache/torque/engine/database/model
TypeMap.java Column.java
src/generator/src/templates/om Peer.vm
xdocs changes.xml
Log:
Corrected handling of BIT with PostgreSQL. Note that the solution implemented has been
tested under MySLQ and PostgreSQL only.
Revision Changes Path
1.8 +13 -1 db-torque/src/generator/src/java/org/apache/torque/engine/database/model/TypeMap.java
Index: TypeMap.java
===================================================================
RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/TypeMap.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TypeMap.java 22 Feb 2004 06:27:19 -0000 1.7
+++ TypeMap.java 23 Aug 2004 11:49:47 -0000 1.8
@@ -589,6 +589,18 @@
}
/**
+ * Returns true if the type is boolean in the
+ * java object and a Bit "1" or "0" in the db.
+ *
+ * @param type The type to check.
+ * @return true if the type is BIT
+ */
+ public static boolean isBit(String type)
+ {
+ return BIT.equals(type);
+ }
+
+ /**
* Returns true if values for the type need to be quoted.
*
* @param type The type to check.
1.24 +10 -1 db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Column.java
Index: Column.java
===================================================================
RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Column.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Column.java 22 Feb 2004 06:27:19 -0000 1.23
+++ Column.java 23 Aug 2004 11:49:47 -0000 1.24
@@ -891,6 +891,15 @@
}
/**
+ * Returns true if the column type is boolean in the
+ * java object and a Bit ("1" or "0") in the db.
+ */
+ public boolean isBit()
+ {
+ return TypeMap.isBit(torqueType);
+ }
+
+ /**
* returns true, if the columns java native type is an
* boolean, byte, short, int, long, float, double, char
*/
1.8 +102 -0 db-torque/src/generator/src/templates/om/Peer.vm
Index: Peer.vm
===================================================================
RCS file: /home/cvs/db-torque/src/generator/src/templates/om/Peer.vm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Peer.vm 6 Apr 2004 12:50:05 -0000 1.7
+++ Peer.vm 23 Aug 2004 11:49:47 -0000 1.8
@@ -282,6 +282,23 @@
}
}
}
+ #elseif ($col.isBit())
+ // check for conversion from boolean to bit (1/0)
+ if (criteria.containsKey($cup))
+ {
+ Object possibleBoolean = criteria.get($cup);
+ if (possibleBoolean instanceof Boolean)
+ {
+ if (((Boolean) possibleBoolean).booleanValue())
+ {
+ criteria.add($cup, "1");
+ }
+ else
+ {
+ criteria.add($cup, "0");
+ }
+ }
+ }
#end
#end
@@ -478,6 +495,23 @@
}
}
}
+ #elseif ($col.isBit())
+ // check for conversion from boolean to bit (1/0)
+ if (criteria.containsKey($cup))
+ {
+ Object possibleBoolean = criteria.get($cup);
+ if (possibleBoolean instanceof Boolean)
+ {
+ if (((Boolean) possibleBoolean).booleanValue())
+ {
+ criteria.add($cup, "1");
+ }
+ else
+ {
+ criteria.add($cup, "0");
+ }
+ }
+ }
#end
#end
@@ -666,6 +700,23 @@
}
}
}
+ #elseif ($col.isBit())
+ // check for conversion from boolean to bit (1/0)
+ if (criteria.containsKey($cup))
+ {
+ Object possibleBoolean = criteria.get($cup);
+ if (possibleBoolean instanceof Boolean)
+ {
+ if (((Boolean) possibleBoolean).booleanValue())
+ {
+ criteria.add($cup, "1");
+ }
+ else
+ {
+ criteria.add($cup, "0");
+ }
+ }
+ }
#end
#if($col.isPrimaryKey())
selectCriteria.put($cup, criteria.remove($cup));
@@ -751,6 +802,23 @@
}
}
}
+ #elseif ($col.isBit())
+ // check for conversion from boolean to bit (1/0)
+ if (criteria.containsKey($cup))
+ {
+ Object possibleBoolean = criteria.get($cup);
+ if (possibleBoolean instanceof Boolean)
+ {
+ if (((Boolean) possibleBoolean).booleanValue())
+ {
+ criteria.add($cup, "1");
+ }
+ else
+ {
+ criteria.add($cup, "0");
+ }
+ }
+ }
#end
#end
@@ -1290,6 +1358,23 @@
}
}
}
+ #elseif ($col.isBit())
+ // check for conversion from boolean to bit (1/0)
+ if (c.containsKey($cup))
+ {
+ Object possibleBoolean = c.get($cup);
+ if (possibleBoolean instanceof Boolean)
+ {
+ if (((Boolean) possibleBoolean).booleanValue())
+ {
+ c.add($cup, "1");
+ }
+ else
+ {
+ c.add($cup, "0");
+ }
+ }
+ }
#end
#end
@@ -1457,6 +1542,23 @@
else
{
c.add($cup, "N");
+ }
+ }
+ }
+ #elseif ($col.isBit())
+ // check for conversion from boolean to bit (1/0)
+ if (c.containsKey($cup))
+ {
+ Object possibleBoolean = c.get($cup);
+ if (possibleBoolean instanceof Boolean)
+ {
+ if (((Boolean) possibleBoolean).booleanValue())
+ {
+ c.add($cup, "1");
+ }
+ else
+ {
+ c.add($cup, "0");
}
}
}
1.131 +4 -0 db-torque/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/db-torque/xdocs/changes.xml,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -r1.130 -r1.131
--- changes.xml 23 Aug 2004 02:54:31 -0000 1.130
+++ changes.xml 23 Aug 2004 11:49:47 -0000 1.131
@@ -9,6 +9,10 @@
<body>
<release version="3.2-alpha" date="in CVS">
+ <action dev='seade' type='fix'>
+ Corrected handling of BIT with PostgreSQL. Note that the solution
+ implemented has been tested under MySLQ and PostgreSQL only.
+ </action>
<action dev='seade' type='add'>
The <code>adapter</code> property is now used in preference to
<code>driver</code> when building the database map. This allows Torque
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org
|