Index: entity-persistence/src/java/oracle/toplink/essentials/exceptions/DatabaseException.java =================================================================== RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/exceptions/DatabaseException.java,v retrieving revision 1.4 diff -c -w -r1.4 DatabaseException.java *** entity-persistence/src/java/oracle/toplink/essentials/exceptions/DatabaseException.java 4 Jan 2007 14:30:35 -0000 1.4 --- entity-persistence/src/java/oracle/toplink/essentials/exceptions/DatabaseException.java 19 Mar 2007 13:42:39 -0000 *************** *** 177,182 **** --- 177,183 ---- } else { StringWriter writer = new StringWriter(); writer.write(super.getMessage()); + writer.write(cr()); writer.write(getIndentationString()); writer.write(ExceptionMessageGenerator.getHeader("ErrorCodeHeader")); if (getInternalException() instanceof SQLException) { *************** *** 187,193 **** if (getCall() != null) { writer.write(cr()); writer.write(getIndentationString()); ! writer.write("Call:"); if (getAccessor() != null) { writer.write(getCall().getLogString(getAccessor())); } else { --- 188,194 ---- if (getCall() != null) { writer.write(cr()); writer.write(getIndentationString()); ! writer.write(ExceptionMessageGenerator.getHeader("CallHeader")); if (getAccessor() != null) { writer.write(getCall().getLogString(getAccessor())); } else { *************** *** 197,203 **** if (getQuery() != null) { writer.write(cr()); writer.write(getIndentationString()); ! writer.write("Query:"); try { writer.write(getQuery().toString()); } catch (RuntimeException badTooString) { --- 198,204 ---- if (getQuery() != null) { writer.write(cr()); writer.write(getIndentationString()); ! writer.write(ExceptionMessageGenerator.getHeader("QueryHeader")); try { writer.write(getQuery().toString()); } catch (RuntimeException badTooString) { Index: entity-persistence/src/java/oracle/toplink/essentials/exceptions/i18n/ExceptionResource.java =================================================================== RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/exceptions/i18n/ExceptionResource.java,v retrieving revision 1.3 diff -c -w -r1.3 ExceptionResource.java *** entity-persistence/src/java/oracle/toplink/essentials/exceptions/i18n/ExceptionResource.java 4 Jan 2007 14:30:38 -0000 1.3 --- entity-persistence/src/java/oracle/toplink/essentials/exceptions/i18n/ExceptionResource.java 19 Mar 2007 13:42:39 -0000 *************** *** 43,48 **** --- 43,49 ---- { "MappingHeader", "Mapping: " }, { "DescriptorHeader", "Descriptor: " }, { "QueryHeader", "Query: " }, + { "CallHeader", "Call: " }, { "DescriptorExceptionsHeader", "Descriptor Exceptions: " }, { "RuntimeExceptionsHeader", "Runtime Exceptions: " }, { "ErrorFormattingMessage", "Error in message format: {0} Arguments: {1}" } Index: entity-persistence/src/java/oracle/toplink/essentials/platform/database/MySQL4Platform.java =================================================================== RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/platform/database/MySQL4Platform.java,v retrieving revision 1.10 diff -c -w -r1.10 MySQL4Platform.java *** entity-persistence/src/java/oracle/toplink/essentials/platform/database/MySQL4Platform.java 15 Jan 2007 16:38:15 -0000 1.10 --- entity-persistence/src/java/oracle/toplink/essentials/platform/database/MySQL4Platform.java 19 Mar 2007 13:42:41 -0000 *************** *** 23,28 **** --- 23,29 ---- import java.io.*; import java.util.*; + import oracle.toplink.essentials.exceptions.ValidationException; import oracle.toplink.essentials.expressions.ExpressionOperator; import oracle.toplink.essentials.internal.databaseaccess.FieldTypeDefinition; *************** *** 204,209 **** --- 205,212 ---- addOperator(dateToStringOperator()); addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.Nvl, "IFNULL")); addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.Trunc, "TRUNCATE")); + addOperator(leftTrim2()); + addOperator(rightTrim2()); } /** *************** *** 287,292 **** --- 290,337 ---- v.addElement(", CHAR)"); exOperator.printsAs(v); exOperator.bePrefix(); + exOperator.setNodeClass(ClassConstants.FunctionExpression_Class); + return exOperator; + } + + /** + * INTERNAL: + * Build MySQL equivalent to LTRIM(string_exp, character). + * MySQL: TRIM(LEADING character FROM string_exp) + */ + protected ExpressionOperator leftTrim2() { + ExpressionOperator exOperator = new ExpressionOperator(); + exOperator.setType(ExpressionOperator.FunctionOperator); + exOperator.setSelector(ExpressionOperator.LeftTrim2); + Vector v = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(5); + v.addElement("TRIM(LEADING "); + v.addElement(" FROM "); + v.addElement(")"); + exOperator.printsAs(v); + exOperator.bePrefix(); + int[] indices = {1, 0}; + exOperator.setArgumentIndices(indices); + exOperator.setNodeClass(ClassConstants.FunctionExpression_Class); + return exOperator; + } + + /** + * INTERNAL: + * Build MySQL equivalent to RTRIM(string_exp, character). + * MySQL: TRIM(TRAILING character FROM string_exp) + */ + protected ExpressionOperator rightTrim2() { + ExpressionOperator exOperator = new ExpressionOperator(); + exOperator.setType(ExpressionOperator.FunctionOperator); + exOperator.setSelector(ExpressionOperator.RightTrim2); + Vector v = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(5); + v.addElement("TRIM(TRAILING "); + v.addElement(" FROM "); + v.addElement(")"); + exOperator.printsAs(v); + exOperator.bePrefix(); + int[] indices = {1, 0}; + exOperator.setArgumentIndices(indices); exOperator.setNodeClass(ClassConstants.FunctionExpression_Class); return exOperator; } Index: entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/fieldaccess/relationships/ExpressionJUnitTestSuite.java =================================================================== RCS file: /cvs/glassfish/entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/fieldaccess/relationships/ExpressionJUnitTestSuite.java,v retrieving revision 1.2 diff -c -w -r1.2 ExpressionJUnitTestSuite.java *** entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/fieldaccess/relationships/ExpressionJUnitTestSuite.java 4 Jan 2007 14:30:36 -0000 1.2 --- entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/fieldaccess/relationships/ExpressionJUnitTestSuite.java 19 Mar 2007 13:42:44 -0000 *************** *** 57,63 **** */ public void testLeftTrimWithTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (dbPlatform.isDerby() || dbPlatform.isDB2()) { getServerSession().logMessage("Test testLeftTrimWithTrimChar skipped for this platform"); return; } --- 57,63 ---- */ public void testLeftTrimWithTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (!(dbPlatform.isOracle() || dbPlatform.isMySQL() || dbPlatform.isPostgreSQL())) { getServerSession().logMessage("Test testLeftTrimWithTrimChar skipped for this platform"); return; } *************** *** 108,119 **** } /* * trim(string) feature test * tests that trim(trim_char) works. */ public void testTrimWithTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (dbPlatform.isDerby() || dbPlatform.isDB2()) { getServerSession().logMessage("Test testTrimWithTrimChar skipped for this platform"); return; } --- 108,278 ---- } /* + * lefTrim() feature test + * tests that leftTrim() works. + */ + public void testLeftTrimWithoutTrimChar() throws Exception { + // All platforms seem to support this + + Customer c = RelationshipsExamples.customerExample4(); + c.setCity(" anotick"); + EntityManager em = createEntityManager(); + try{ + em.getTransaction().begin(); + em.persist(c); + em.getTransaction().commit(); + }catch (Exception e){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + throw e; + } + em.close(); + try{ + ExpressionBuilder builder = new ExpressionBuilder(); + Expression expression = builder.get("city").leftTrim().equal("anotick"); + + ReadAllQuery r = new ReadAllQuery(); + r.setReferenceClass(Customer.class); + r.setSelectionCriteria(expression); + Vector v = (Vector)getServerSession().executeQuery(r); + assertTrue("Test error: No Customers found", v.size()!=0 ); + Customer returned = (Customer)v.firstElement(); + assertTrue("Test error: No Customers found", " anotick".equals(returned.getCity()) ); + + }catch(Exception e){ + em = createEntityManager(); + em.getTransaction().begin(); + c = (Customer)em.find(Customer.class, c.getCustomerId()); + em.remove(c); + try{ + em.getTransaction().commit(); + }catch (Throwable t){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + }finally{ + em.close(); + throw e; + } + } + } + + + /* + * rightTrim(string) feature test + * tests that rightTrim(trim_char) works. + */ + public void testRightTrimWithTrimChar() throws Exception { + Platform dbPlatform = getDbPlatform(); + if (!(dbPlatform.isOracle() || dbPlatform.isMySQL() || dbPlatform.isPostgreSQL())) { + getServerSession().logMessage("Test testRightTrimWithTrimChar skipped for this platform"); + return; + } + + Customer c = RelationshipsExamples.customerExample4(); + c.setCity("ManotickM"); + EntityManager em = createEntityManager(); + try{ + em.getTransaction().begin(); + em.persist(c); + em.getTransaction().commit(); + }catch (Exception e){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + throw e; + } + em.close(); + try{ + ExpressionBuilder builder = new ExpressionBuilder(); + Expression expression = builder.get("city").rightTrim("M").equal("Manotick"); + + ReadAllQuery r = new ReadAllQuery(); + r.setReferenceClass(Customer.class); + r.setSelectionCriteria(expression); + Vector v = (Vector)getServerSession().executeQuery(r); + assertTrue("Test error: No Customers found", v.size()!=0 ); + Customer returned = (Customer)v.firstElement(); + assertTrue("Test error: No Customers found", "ManotickM".equals(returned.getCity()) ); + + }catch(Exception e){ + em = createEntityManager(); + em.getTransaction().begin(); + c = (Customer)em.find(Customer.class, c.getCustomerId()); + em.remove(c); + try{ + em.getTransaction().commit(); + }catch (Throwable t){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + }finally{ + em.close(); + throw e; + } + } + } + + /* + * rightTrim() feature test + * tests that rightTrim() works. + */ + public void testRightTrimWithoutTrimChar() throws Exception { + // All platforms seem to support this + + Customer c = RelationshipsExamples.customerExample4(); + c.setCity("Manotic "); + EntityManager em = createEntityManager(); + try{ + + em.getTransaction().begin(); + em.persist(c); + em.getTransaction().commit(); + }catch (Exception e){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + throw e; + } + em.close(); + try{ + ExpressionBuilder builder = new ExpressionBuilder(); + Expression expression = builder.get("city").rightTrim().equal("Manotic"); + + ReadAllQuery r = new ReadAllQuery(); + r.setReferenceClass(Customer.class); + r.setSelectionCriteria(expression); + Vector v = (Vector)getServerSession().executeQuery(r); + assertTrue("Test error: No Customers found", v.size()!=0 ); + Customer returned = (Customer)v.firstElement(); + assertTrue("Test error: No Customers found", "Manotic ".equals(returned.getCity()) ); + + }catch(Exception e){ + em = createEntityManager(); + em.getTransaction().begin(); + c = (Customer)em.find(Customer.class, c.getCustomerId()); + em.remove(c); + try{ + em.getTransaction().commit(); + }catch (Throwable t){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + }finally{ + em.close(); + throw e; + } + } + } + + /* * trim(string) feature test * tests that trim(trim_char) works. */ public void testTrimWithTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (!(dbPlatform.isOracle() || dbPlatform.isMySQL() || dbPlatform.isPostgreSQL())) { getServerSession().logMessage("Test testTrimWithTrimChar skipped for this platform"); return; } *************** *** 168,175 **** */ public void testTrimWithoutTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (dbPlatform.isDerby() || dbPlatform.isDB2()) { ! getServerSession().logMessage("Test testTrimWithTrimChar skipped for this platform"); return; } Item i = new Item(); --- 327,335 ---- */ public void testTrimWithoutTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (!(dbPlatform.isOracle() || dbPlatform.isMySQL() || dbPlatform.isPostgreSQL() ! || dbPlatform.isInformix() || dbPlatform.isSQLAnywhere() || dbPlatform.isHSQL())) { ! getServerSession().logMessage("Test testTrimWithoutTrimChar skipped for this platform"); return; } Item i = new Item(); Index: entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/relationships/ExpressionJUnitTestSuite.java =================================================================== RCS file: /cvs/glassfish/entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/relationships/ExpressionJUnitTestSuite.java,v retrieving revision 1.9 diff -c -w -r1.9 ExpressionJUnitTestSuite.java *** entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/relationships/ExpressionJUnitTestSuite.java 4 Jan 2007 14:30:38 -0000 1.9 --- entity-persistence-tests/src/java/oracle/toplink/essentials/testing/tests/cmp3/relationships/ExpressionJUnitTestSuite.java 19 Mar 2007 13:42:44 -0000 *************** *** 57,63 **** */ public void testLeftTrimWithTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (dbPlatform.isDerby() || dbPlatform.isDB2()) { getServerSession().logMessage("Test testLeftTrimWithTrimChar skipped for this platform"); return; } --- 57,63 ---- */ public void testLeftTrimWithTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (!(dbPlatform.isOracle() || dbPlatform.isMySQL() || dbPlatform.isPostgreSQL())) { getServerSession().logMessage("Test testLeftTrimWithTrimChar skipped for this platform"); return; } *************** *** 108,119 **** } /* * trim(string) feature test * tests that trim(trim_char) works. */ public void testTrimWithTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (dbPlatform.isDerby() || dbPlatform.isDB2()) { getServerSession().logMessage("Test testTrimWithTrimChar skipped for this platform"); return; } --- 108,278 ---- } /* + * lefTrim() feature test + * tests that leftTrim() works. + */ + public void testLeftTrimWithoutTrimChar() throws Exception { + // All platforms seem to support this + + Customer c = RelationshipsExamples.customerExample4(); + c.setCity(" anotick"); + EntityManager em = createEntityManager(); + try{ + em.getTransaction().begin(); + em.persist(c); + em.getTransaction().commit(); + }catch (Exception e){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + throw e; + } + em.close(); + try{ + ExpressionBuilder builder = new ExpressionBuilder(); + Expression expression = builder.get("city").leftTrim().equal("anotick"); + + ReadAllQuery r = new ReadAllQuery(); + r.setReferenceClass(Customer.class); + r.setSelectionCriteria(expression); + Vector v = (Vector)getServerSession().executeQuery(r); + assertTrue("Test error: No Customers found", v.size()!=0 ); + Customer returned = (Customer)v.firstElement(); + assertTrue("Test error: No Customers found", " anotick".equals(returned.getCity()) ); + + }catch(Exception e){ + em = createEntityManager(); + em.getTransaction().begin(); + c = (Customer)em.find(Customer.class, c.getCustomerId()); + em.remove(c); + try{ + em.getTransaction().commit(); + }catch (Throwable t){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + }finally{ + em.close(); + throw e; + } + } + } + + + /* + * rightTrim(string) feature test + * tests that rightTrim(trim_char) works. + */ + public void testRightTrimWithTrimChar() throws Exception { + Platform dbPlatform = getDbPlatform(); + if (!(dbPlatform.isOracle() || dbPlatform.isMySQL() || dbPlatform.isPostgreSQL())) { + getServerSession().logMessage("Test testRightTrimWithTrimChar skipped for this platform"); + return; + } + + Customer c = RelationshipsExamples.customerExample4(); + c.setCity("ManotickM"); + EntityManager em = createEntityManager(); + try{ + em.getTransaction().begin(); + em.persist(c); + em.getTransaction().commit(); + }catch (Exception e){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + throw e; + } + em.close(); + try{ + ExpressionBuilder builder = new ExpressionBuilder(); + Expression expression = builder.get("city").rightTrim("M").equal("Manotick"); + + ReadAllQuery r = new ReadAllQuery(); + r.setReferenceClass(Customer.class); + r.setSelectionCriteria(expression); + Vector v = (Vector)getServerSession().executeQuery(r); + assertTrue("Test error: No Customers found", v.size()!=0 ); + Customer returned = (Customer)v.firstElement(); + assertTrue("Test error: No Customers found", "ManotickM".equals(returned.getCity()) ); + + }catch(Exception e){ + em = createEntityManager(); + em.getTransaction().begin(); + c = (Customer)em.find(Customer.class, c.getCustomerId()); + em.remove(c); + try{ + em.getTransaction().commit(); + }catch (Throwable t){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + }finally{ + em.close(); + throw e; + } + } + } + + /* + * rightTrim() feature test + * tests that rightTrim() works. + */ + public void testRightTrimWithoutTrimChar() throws Exception { + // All platforms seem to support this + + Customer c = RelationshipsExamples.customerExample4(); + c.setCity("Manotic "); + EntityManager em = createEntityManager(); + try{ + + em.getTransaction().begin(); + em.persist(c); + em.getTransaction().commit(); + }catch (Exception e){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + throw e; + } + em.close(); + try{ + ExpressionBuilder builder = new ExpressionBuilder(); + Expression expression = builder.get("city").rightTrim().equal("Manotic"); + + ReadAllQuery r = new ReadAllQuery(); + r.setReferenceClass(Customer.class); + r.setSelectionCriteria(expression); + Vector v = (Vector)getServerSession().executeQuery(r); + assertTrue("Test error: No Customers found", v.size()!=0 ); + Customer returned = (Customer)v.firstElement(); + assertTrue("Test error: No Customers found", "Manotic ".equals(returned.getCity()) ); + + }catch(Exception e){ + em = createEntityManager(); + em.getTransaction().begin(); + c = (Customer)em.find(Customer.class, c.getCustomerId()); + em.remove(c); + try{ + em.getTransaction().commit(); + }catch (Throwable t){ + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + }finally{ + em.close(); + throw e; + } + } + } + + /* * trim(string) feature test * tests that trim(trim_char) works. */ public void testTrimWithTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (!(dbPlatform.isOracle() || dbPlatform.isMySQL() || dbPlatform.isPostgreSQL())) { getServerSession().logMessage("Test testTrimWithTrimChar skipped for this platform"); return; } *************** *** 168,175 **** */ public void testTrimWithoutTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (dbPlatform.isDerby() || dbPlatform.isDB2()) { ! getServerSession().logMessage("Test testTrimWithTrimChar skipped for this platform"); return; } Item i = new Item(); --- 327,335 ---- */ public void testTrimWithoutTrimChar() throws Exception { Platform dbPlatform = getDbPlatform(); ! if (!(dbPlatform.isOracle() || dbPlatform.isMySQL() || dbPlatform.isPostgreSQL() ! || dbPlatform.isInformix() || dbPlatform.isSQLAnywhere() || dbPlatform.isHSQL())) { ! getServerSession().logMessage("Test testTrimWithoutTrimChar skipped for this platform"); return; } Item i = new Item();