mirror of https://github.com/apache/openjpa.git
OPENJPA-1222:
Removing sys.err.printlns, unused variables, and some formatting changes. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@801195 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a3f0d4104c
commit
a84c76fea7
|
@ -149,8 +149,6 @@ public abstract class AbstractCriteriaTestCase extends TestCase {
|
||||||
fail("CriteriaQuery corresponding to " + jpql + " failed to execute\r\n" + w);
|
fail("CriteriaQuery corresponding to " + jpql + " failed to execute\r\n" + w);
|
||||||
}
|
}
|
||||||
|
|
||||||
printSQL("Target SQL for JPQL", jSQL);
|
|
||||||
printSQL("Target SQL for CriteriaQuery", cSQL);
|
|
||||||
if (jSQL.size() != cSQL.size()) {
|
if (jSQL.size() != cSQL.size()) {
|
||||||
printSQL("Target SQL for JPQL", jSQL);
|
printSQL("Target SQL for JPQL", jSQL);
|
||||||
printSQL("Target SQL for CriteriaQuery", cSQL);
|
printSQL("Target SQL for CriteriaQuery", cSQL);
|
||||||
|
@ -183,8 +181,6 @@ public abstract class AbstractCriteriaTestCase extends TestCase {
|
||||||
fail("JPQL " + jpql + " failed to execute\r\n" + w);
|
fail("JPQL " + jpql + " failed to execute\r\n" + w);
|
||||||
}
|
}
|
||||||
|
|
||||||
printSQL("Target SQL for JPQL", jSQL);
|
|
||||||
|
|
||||||
if (!(dict instanceof DerbyDictionary))
|
if (!(dict instanceof DerbyDictionary))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -213,7 +209,6 @@ public abstract class AbstractCriteriaTestCase extends TestCase {
|
||||||
if (!(dict instanceof DerbyDictionary))
|
if (!(dict instanceof DerbyDictionary))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printSQL("Expected SQL", expectedSQL);
|
|
||||||
String jSql = jSQL.get(0).trim();
|
String jSql = jSQL.get(0).trim();
|
||||||
if (jSql.indexOf("optimize for 1 row") != -1)
|
if (jSql.indexOf("optimize for 1 row") != -1)
|
||||||
jSql = jSql.substring(0, jSql.indexOf("optimize for 1 row")).trim();
|
jSql = jSql.substring(0, jSql.indexOf("optimize for 1 row")).trim();
|
||||||
|
@ -225,54 +220,46 @@ public abstract class AbstractCriteriaTestCase extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
void executeExpectFail(CriteriaQuery<?> c, String jpql) {
|
void executeExpectFail(CriteriaQuery<?> c, String jpql) {
|
||||||
List<String> cSQL = null;
|
|
||||||
StringWriter w = new StringWriter();
|
|
||||||
try {
|
try {
|
||||||
Query cQ = getEntityManager().createQuery(c);
|
Query cQ = getEntityManager().createQuery(c);
|
||||||
cSQL = executeQueryAndCollectSQL(cQ);
|
executeQueryAndCollectSQL(cQ);
|
||||||
fail("CriteriaQuery corresponding to " + jpql + " is expected to fail\r\n" + w);
|
fail("CriteriaQuery corresponding to " + jpql + " is expected to fail\r\n");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(new PrintWriter(w));
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void executeExpectFail(CriteriaQuery<?> c, String jpql, String[] paramNames, Object[] params) {
|
void executeExpectFail(CriteriaQuery<?> c, String jpql, String[] paramNames, Object[] params) {
|
||||||
List<String> cSQL = null;
|
|
||||||
StringWriter w = new StringWriter();
|
|
||||||
try {
|
try {
|
||||||
Query cQ = getEntityManager().createQuery(c);
|
Query cQ = getEntityManager().createQuery(c);
|
||||||
for (int i = 0; i < params.length; i++)
|
for (int i = 0; i < params.length; i++)
|
||||||
cQ.setParameter(paramNames[i], params[i]);
|
cQ.setParameter(paramNames[i], params[i]);
|
||||||
cSQL = executeQueryAndCollectSQL(cQ);
|
executeQueryAndCollectSQL(cQ);
|
||||||
fail("CriteriaQuery corresponding to " + jpql + " is expected to fail\r\n" + w);
|
fail("CriteriaQuery corresponding to " + jpql + " is expected to fail\r\n");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(new PrintWriter(w));
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void executeExpectFail(String jpql) {
|
void executeExpectFail(String jpql) {
|
||||||
List<String> jSQL = null;
|
|
||||||
StringWriter w = new StringWriter();
|
|
||||||
try {
|
try {
|
||||||
Query jQ = getEntityManager().createQuery(jpql);
|
Query jQ = getEntityManager().createQuery(jpql);
|
||||||
jSQL = executeQueryAndCollectSQL(jQ);
|
executeQueryAndCollectSQL(jQ);
|
||||||
fail("JPQL " + jpql + " is expected to Failed to execute\r\n" + w);
|
fail("JPQL " + jpql + " is expected to Failed to execute\r\n");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(new PrintWriter(w));
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void executeExpectFail(String jpql, String[] paramNames, Object[] params) {
|
void executeExpectFail(String jpql, String[] paramNames, Object[] params) {
|
||||||
List<String> jSQL = null;
|
|
||||||
StringWriter w = new StringWriter();
|
|
||||||
try {
|
try {
|
||||||
Query jQ = getEntityManager().createQuery(jpql);
|
Query jQ = getEntityManager().createQuery(jpql);
|
||||||
for (int i = 0; i < params.length; i++)
|
for (int i = 0; i < params.length; i++)
|
||||||
jQ.setParameter(paramNames[i], params[i]);
|
jQ.setParameter(paramNames[i], params[i]);
|
||||||
jSQL = executeQueryAndCollectSQL(jQ);
|
executeQueryAndCollectSQL(jQ);
|
||||||
fail("JPQL " + jpql + " is expected to Failed to execute\r\n" + w);
|
fail("JPQL " + jpql + " is expected to Failed to execute\r\n");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(new PrintWriter(w));
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +292,7 @@ public abstract class AbstractCriteriaTestCase extends TestCase {
|
||||||
List<String> executeQueryAndCollectSQL(Query q) {
|
List<String> executeQueryAndCollectSQL(Query q) {
|
||||||
getAuditor().clear();
|
getAuditor().clear();
|
||||||
try {
|
try {
|
||||||
List<?> result = q.getResultList();
|
q.getResultList();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(extractSQL(e), e);
|
throw new RuntimeException(extractSQL(e), e);
|
||||||
}
|
}
|
||||||
|
@ -319,8 +306,9 @@ public abstract class AbstractCriteriaTestCase extends TestCase {
|
||||||
|
|
||||||
String extractSQL(Exception e) {
|
String extractSQL(Exception e) {
|
||||||
Throwable t = e.getCause();
|
Throwable t = e.getCause();
|
||||||
if (t instanceof ReportingSQLException)
|
if (t instanceof ReportingSQLException) {
|
||||||
return ((ReportingSQLException) t).getSQL();
|
return ((ReportingSQLException) t).getSQL();
|
||||||
|
}
|
||||||
return "Can not extract SQL from exception " + e;
|
return "Can not extract SQL from exception " + e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,13 +337,15 @@ public abstract class AbstractCriteriaTestCase extends TestCase {
|
||||||
* Set -DIgnoreAllowFailure=true to ignore this directive altogether.
|
* Set -DIgnoreAllowFailure=true to ignore this directive altogether.
|
||||||
*/
|
*/
|
||||||
protected AllowFailure getAllowFailure() {
|
protected AllowFailure getAllowFailure() {
|
||||||
if (Boolean.getBoolean("IgnoreAllowFailure"))
|
if (Boolean.getBoolean("IgnoreAllowFailure")) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Method runMethod = getClass().getMethod(getName(), (Class[]) null);
|
Method runMethod = getClass().getMethod(getName(), (Class[]) null);
|
||||||
AllowFailure anno = runMethod.getAnnotation(AllowFailure.class);
|
AllowFailure anno = runMethod.getAnnotation(AllowFailure.class);
|
||||||
if (anno != null)
|
if (anno != null) {
|
||||||
return anno;
|
return anno;
|
||||||
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
// ignore
|
// ignore
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
|
@ -370,7 +360,6 @@ public abstract class AbstractCriteriaTestCase extends TestCase {
|
||||||
@Override
|
@Override
|
||||||
public void beforeExecuteStatement(JDBCEvent event) {
|
public void beforeExecuteStatement(JDBCEvent event) {
|
||||||
if (event.getSQL() != null && sqls != null) {
|
if (event.getSQL() != null && sqls != null) {
|
||||||
System.err.println("Adding " + event.getSQL());
|
|
||||||
sqls.add(event.getSQL());
|
sqls.add(event.getSQL());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue