この割り当ての仕様は次のとおりです。
- すべての埋め込みSQLステートメントを見つけて、まだ定数を使用していない埋め込みSQLの定数を実装します。
- Sqlステートメント作成内の文字列連結をString.format()に置き換えます。
- String.formatコマンドの場合、既存の%記号をエスケープする必要があります。これらのシンボルは、LIKE操作でよく使用されます。
このSQLクエリを「publicstaticStringMY_QUERY」に移動して、前方参照を行わず、「match」変数と「useFor」変数を解決するにはどうすればよいですか。MY_QUERYで行うことは、JUnitテストからアクセスし、ソースデータベースとターゲットデータベースに対してクエリを実行して、データ移行に必要なクエリが両方のデータベースで実行されることを確認することです。
package artemispm.autocalc;
import java.sql.*;
import java.util.*;
import a7.unittests.dao.UnitTestHelper;
import artemispm.serverutil.*;
import artemispm.trdo.*;
import artemispm.parser.*;
public abstract class TRBaseScoreCalculator implements ExpressionParserLookup {
/*****THIS IS THE NEW QUERY THAT WILL BE ACCESSED FROM JUNIT TEST****/
public static String MY_QUERY =
public Connection m_con;
protected String m_characName = "";
public boolean isThisCharacInUse(Connection con, String characName,String useFor)
throws SQLException, TRException {
boolean result;
String match = "[" + TRBaseSql.rewrapQuotes(characName) + "]";
if(TRBaseSql.getDatabaseType(con) == TRBaseSql.DBTYPESQLSERVER) {
match = "[[]" + TRBaseSql.rewrapQuotes(characName) + "]";
}
TRSystemSQL sql = new TRSystemSQL();
TRSystem sys=sql.getSystem(con);
result = ( sys.getScoreCalculation() != null
&& sys.getScoreCalculation().indexOf(match) >= 0 );
if (result) return(result);
else {
int count;
/*****THIS IS THE PLACE I NEED HELP AT 12/5/2012 ******/
/*I NEED TO SOMEHOW MOVE THE BELOW STATEMENT USING THE SPECS INTO MY_QUERY**/
/**"select count(userfieldid) from tr_userfield where calcexpression like '%" + match + "%'and usefor like '%" + useFor +"%'"***/
count = sql.executeGetInt(con, "select count(userfieldid) from tr_userfield where calcexpression like '%" + match + "%'and usefor like '%" + useFor +"%'" , null);
if (count > 0) return true;
count = sql.executeGetInt(con,
"select count(characid) from tr_charac where calcexpression like '%" + match + "%'and usefor like '%" + useFor +"%'" , null);
return (count > 0);
}
}
}