You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by mp...@apache.org on 2003/12/05 19:35:53 UTC
cvs commit: db-torque/src/generator/src/test/org/apache/torque/engine/database/model PostgresqlDomainTest.java OracleDomainTest.java
mpoeschl 2003/12/05 10:35:53
Modified: src/generator/src/java/org/apache/torque/engine/platform
PlatformPostgresqlImpl.java
PlatformDefaultImpl.java Platform.java
PlatformOracleImpl.java
Added: src/generator/src/test/org/apache/torque/engine/database/model
PostgresqlDomainTest.java OracleDomainTest.java
Log:
add hasSize() and hasScale() to Platform (not implemented yet)
more tests
Revision Changes Path
1.4 +14 -14 db-torque/src/generator/src/java/org/apache/torque/engine/platform/PlatformPostgresqlImpl.java
Index: PlatformPostgresqlImpl.java
===================================================================
RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/platform/PlatformPostgresqlImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PlatformPostgresqlImpl.java 4 Dec 2003 09:39:38 -0000 1.3
+++ PlatformPostgresqlImpl.java 5 Dec 2003 18:35:52 -0000 1.4
@@ -79,21 +79,21 @@
*/
private void initialize()
{
- setSchemaDomainMapping(new Domain(SchemaType.BIT, "boolean"));
- setSchemaDomainMapping(new Domain(SchemaType.TINYINT, "int2"));
- setSchemaDomainMapping(new Domain(SchemaType.SMALLINT, "int2"));
- setSchemaDomainMapping(new Domain(SchemaType.BIGINT, "int8"));
- setSchemaDomainMapping(new Domain(SchemaType.REAL, "float"));
+ setSchemaDomainMapping(new Domain(SchemaType.BIT, "BOOLEAN"));
+ setSchemaDomainMapping(new Domain(SchemaType.TINYINT, "INT2"));
+ setSchemaDomainMapping(new Domain(SchemaType.SMALLINT, "INT2"));
+ setSchemaDomainMapping(new Domain(SchemaType.BIGINT, "INT8"));
+ setSchemaDomainMapping(new Domain(SchemaType.REAL, "FLOAT"));
// TODO check this .. just copied from db.props
- setSchemaDomainMapping(new Domain(SchemaType.BOOLEANCHAR, "char"));
+ setSchemaDomainMapping(new Domain(SchemaType.BOOLEANCHAR, "CHAR"));
// TODO check this .. just copied from db.props
- setSchemaDomainMapping(new Domain(SchemaType.BOOLEANINT, "int2"));
- setSchemaDomainMapping(new Domain(SchemaType.DOUBLE, "double precision"));
- setSchemaDomainMapping(new Domain(SchemaType.LONGVARCHAR, "text"));
- setSchemaDomainMapping(new Domain(SchemaType.BINARY, "bytea"));
- setSchemaDomainMapping(new Domain(SchemaType.VARBINARY, "bytea"));
- setSchemaDomainMapping(new Domain(SchemaType.LONGVARBINARY, "bytea"));
- setSchemaDomainMapping(new Domain(SchemaType.CLOB, "text"));
+ setSchemaDomainMapping(new Domain(SchemaType.BOOLEANINT, "INT2"));
+ setSchemaDomainMapping(new Domain(SchemaType.DOUBLE, "DOUBLE PRECISION"));
+ setSchemaDomainMapping(new Domain(SchemaType.LONGVARCHAR, "TEXT"));
+ setSchemaDomainMapping(new Domain(SchemaType.BINARY, "BYTEA"));
+ setSchemaDomainMapping(new Domain(SchemaType.VARBINARY, "BYTEA"));
+ setSchemaDomainMapping(new Domain(SchemaType.LONGVARBINARY, "BYTEA"));
+ setSchemaDomainMapping(new Domain(SchemaType.CLOB, "TEXT"));
}
/**
1.7 +19 -2 db-torque/src/generator/src/java/org/apache/torque/engine/platform/PlatformDefaultImpl.java
Index: PlatformDefaultImpl.java
===================================================================
RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/platform/PlatformDefaultImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PlatformDefaultImpl.java 5 Dec 2003 14:28:27 -0000 1.6
+++ PlatformDefaultImpl.java 5 Dec 2003 18:35:52 -0000 1.7
@@ -62,7 +62,6 @@
import org.apache.torque.engine.database.model.SchemaType;
-
/**
* Default implementation for the Platform interface.
*
@@ -143,6 +142,24 @@
public String getAutoIncrement()
{
return "IDENTITY";
+ }
+
+ /**
+ * @see Platform#hasScale(String)
+ * TODO collect info for all platforms
+ */
+ public boolean hasScale(SchemaType type)
+ {
+ return true;
+ }
+
+ /**
+ * @see Platform#hasSize(String)
+ * TODO collect info for all platforms
+ */
+ public boolean hasSize(SchemaType type)
+ {
+ return true;
}
}
1.6 +16 -1 db-torque/src/generator/src/java/org/apache/torque/engine/platform/Platform.java
Index: Platform.java
===================================================================
RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/platform/Platform.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Platform.java 4 Dec 2003 09:39:38 -0000 1.5
+++ Platform.java 5 Dec 2003 18:35:52 -0000 1.6
@@ -103,4 +103,19 @@
*/
String getAutoIncrement();
+ /**
+ * Returns if the RDBMS-specific SQL type has a size attribute.
+ *
+ * @param type the SchemaType
+ * @return true if the type has a size attribute
+ */
+ boolean hasSize(SchemaType type);
+
+ /**
+ * Returns if the RDBMS-specific SQL type has a scale attribute.
+ *
+ * @param type the SchemaType
+ * @return true if the type has a scale attribute
+ */
+ boolean hasScale(SchemaType type);
}
1.5 +9 -1 db-torque/src/generator/src/java/org/apache/torque/engine/platform/PlatformOracleImpl.java
Index: PlatformOracleImpl.java
===================================================================
RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/platform/PlatformOracleImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PlatformOracleImpl.java 5 Dec 2003 14:28:27 -0000 1.4
+++ PlatformOracleImpl.java 5 Dec 2003 18:35:52 -0000 1.5
@@ -88,6 +88,7 @@
setSchemaDomainMapping(new Domain(SchemaType.REAL, "NUMBER"));
setSchemaDomainMapping(new Domain(SchemaType.DOUBLE, "FLOAT"));
setSchemaDomainMapping(new Domain(SchemaType.DECIMAL, "NUMBER"));
+ setSchemaDomainMapping(new Domain(SchemaType.NUMERIC, "NUMBER"));
setSchemaDomainMapping(new Domain(SchemaType.VARCHAR, "VARCHAR2"));
setSchemaDomainMapping(new Domain(SchemaType.LONGVARCHAR, "VARCHAR2", "2000"));
setSchemaDomainMapping(new Domain(SchemaType.TIME, "DATE"));
@@ -113,4 +114,11 @@
return Platform.SEQUENCE;
}
+ /**
+ * @see Platform#getAutoIncrement()
+ */
+ public String getAutoIncrement()
+ {
+ return "";
+ }
}
1.1 db-torque/src/generator/src/test/org/apache/torque/engine/database/model/PostgresqlDomainTest.java
Index: PostgresqlDomainTest.java
===================================================================
package org.apache.torque.engine.database.model;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Torque" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Torque", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
import org.apache.torque.engine.database.transform.XmlToAppData;
/**
* Tests for domain handling (for Postgresql).
*
* @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
* @version $Id: PostgresqlDomainTest.java,v 1.1 2003/12/05 18:35:53 mpoeschl Exp $
*/
public class PostgresqlDomainTest extends TestCase
{
private XmlToAppData xmlToAppData = null;
private Database db = null;
public PostgresqlDomainTest(String name)
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
xmlToAppData = new XmlToAppData("postgresql", "defaultpackage");
db = xmlToAppData.parseFile(
"src/test/org/apache/torque/engine/database/model/domaintest-schema.xml");
}
protected void tearDown() throws Exception
{
xmlToAppData = null;
super.tearDown();
}
/**
* test if the tables get the package name from the properties file
*/
public void testDomainColumn() throws Exception
{
Table table = db.getTable("product");
Column name = table.getColumn("name");
assertEquals("VARCHAR", name.getType());
assertEquals("VARCHAR", name.getDomain().getSqlType());
assertEquals("40", name.getSize());
Column price = table.getColumn("price");
assertEquals("NUMERIC", price.getTorqueType());
assertEquals("NUMERIC", price.getType());
assertEquals("NUMERIC", price.getDomain().getSqlType());
assertEquals("10", price.getSize());
assertEquals("2", price.getScale());
assertEquals("0", price.getDefaultValue());
assertEquals("(10,2)", price.printSize());
}
/**
* test if the tables get the package name from the properties file
*/
public void testExtendedDomainColumn() throws Exception
{
Table table = db.getTable("article");
Column price = table.getColumn("price");
assertEquals("NUMERIC", price.getTorqueType());
assertEquals("NUMERIC", price.getType());
assertEquals("NUMERIC", price.getDomain().getSqlType());
assertEquals("12", price.getSize());
assertEquals("2", price.getScale());
assertEquals("1000", price.getDefaultValue());
assertEquals("(12,2)", price.printSize());
}
public void testDecimalColumn() throws Exception
{
Table table = db.getTable("article");
Column col = table.getColumn("decimal_col");
assertEquals("DECIMAL", col.getTorqueType());
assertEquals("DECIMAL", col.getType());
assertEquals("DECIMAL", col.getDomain().getSqlType());
assertEquals("10", col.getSize());
assertEquals("3", col.getScale());
assertEquals("(10,3)", col.printSize());
}
public void testDateColumn() throws Exception
{
Table table = db.getTable("article");
Column col = table.getColumn("date_col");
assertEquals("DATE", col.getTorqueType());
assertEquals("DATE", col.getType());
assertEquals("DATE", col.getDomain().getSqlType());
assertEquals("", col.printSize());
}
public void testNativeAutoincrement() throws Exception
{
Table table = db.getTable("native");
Column col = table.getColumn("native_id");
assertEquals("SERIAL", col.getAutoIncrementString());
col = table.getColumn("name");
assertEquals("", col.getAutoIncrementString());
}
public void testIdBrokerAutoincrement() throws Exception
{
Table table = db.getTable("article");
Column col = table.getColumn("article_id");
assertEquals("", col.getAutoIncrementString());
col = table.getColumn("name");
assertEquals("", col.getAutoIncrementString());
}
public void testBooleanint() throws Exception
{
Table table = db.getTable("types");
Column col = table.getColumn("cbooleanint");
assertEquals("", col.getAutoIncrementString());
assertEquals("BOOLEANINT", col.getTorqueType());
assertEquals("INTEGER", col.getType());
assertEquals("INT2", col.getDomain().getSqlType());
}
}
1.1 db-torque/src/generator/src/test/org/apache/torque/engine/database/model/OracleDomainTest.java
Index: OracleDomainTest.java
===================================================================
package org.apache.torque.engine.database.model;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Torque" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Torque", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
import org.apache.torque.engine.database.transform.XmlToAppData;
/**
* Tests for domain handling (for Oracle).
*
* @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
* @version $Id: OracleDomainTest.java,v 1.1 2003/12/05 18:35:53 mpoeschl Exp $
*/
public class OracleDomainTest extends TestCase
{
private XmlToAppData xmlToAppData = null;
private Database db = null;
public OracleDomainTest(String name)
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
xmlToAppData = new XmlToAppData("oracle", "defaultpackage");
db = xmlToAppData.parseFile(
"src/test/org/apache/torque/engine/database/model/domaintest-schema.xml");
}
protected void tearDown() throws Exception
{
xmlToAppData = null;
super.tearDown();
}
/**
* test if the tables get the package name from the properties file
*/
public void testDomainColumn() throws Exception
{
Table table = db.getTable("product");
Column name = table.getColumn("name");
assertEquals("VARCHAR", name.getType());
assertEquals("VARCHAR2", name.getDomain().getSqlType());
assertEquals("40", name.getSize());
Column price = table.getColumn("price");
assertEquals("NUMERIC", price.getTorqueType());
assertEquals("NUMERIC", price.getType());
assertEquals("NUMBER", price.getDomain().getSqlType());
assertEquals("10", price.getSize());
assertEquals("2", price.getScale());
assertEquals("0", price.getDefaultValue());
assertEquals("(10,2)", price.printSize());
}
/**
* test if the tables get the package name from the properties file
*/
public void testExtendedDomainColumn() throws Exception
{
Table table = db.getTable("article");
Column price = table.getColumn("price");
assertEquals("NUMERIC", price.getTorqueType());
assertEquals("NUMERIC", price.getType());
assertEquals("NUMBER", price.getDomain().getSqlType());
assertEquals("12", price.getSize());
assertEquals("2", price.getScale());
assertEquals("1000", price.getDefaultValue());
assertEquals("(12,2)", price.printSize());
}
public void testDecimalColumn() throws Exception
{
Table table = db.getTable("article");
Column col = table.getColumn("decimal_col");
assertEquals("DECIMAL", col.getTorqueType());
assertEquals("DECIMAL", col.getType());
assertEquals("NUMBER", col.getDomain().getSqlType());
assertEquals("10", col.getSize());
assertEquals("3", col.getScale());
assertEquals("(10,3)", col.printSize());
}
public void testDateColumn() throws Exception
{
Table table = db.getTable("article");
Column col = table.getColumn("date_col");
assertEquals("DATE", col.getTorqueType());
assertEquals("DATE", col.getType());
assertEquals("DATE", col.getDomain().getSqlType());
assertEquals("", col.printSize());
}
public void testNativeAutoincrement() throws Exception
{
Table table = db.getTable("native");
Column col = table.getColumn("native_id");
assertEquals("", col.getAutoIncrementString());
col = table.getColumn("name");
assertEquals("", col.getAutoIncrementString());
}
public void testIdBrokerAutoincrement() throws Exception
{
Table table = db.getTable("article");
Column col = table.getColumn("article_id");
assertEquals("", col.getAutoIncrementString());
col = table.getColumn("name");
assertEquals("", col.getAutoIncrementString());
}
public void testBooleanint() throws Exception
{
Table table = db.getTable("types");
Column col = table.getColumn("cbooleanint");
assertEquals("", col.getAutoIncrementString());
assertEquals("BOOLEANINT", col.getTorqueType());
assertEquals("INTEGER", col.getType());
assertEquals("NUMBER", col.getDomain().getSqlType());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org