Where Used Report

This is not the most efficient way to find where a database field is used, but it is a useful example of using ProRefactor.

See this WebSVN link for the full source.

It prompts for a fully qualified db.table.field name, checks that it exists in ProRefactor's configured schema, and splits it into two string variables: fieldName, and dbTableName.

It then finds all parse units in the directory of your choice, and loads or builds the PUB file for each of those, and then checks to see if your field is used in that compile unit. So, for each parse unit pu:

PUB pub = pu.getPUB();
boolean wasCurrent = pub.loadTo(PUB.SCHEMA);
if (wasCurrent==false) pub.build();
if (usesField(pub) == false) return;
reportOut.write(pu.getFile().toString());

Next is the relevant code for usesField(). The PUB object has a record of all tables and fields used in that compile unit. We get a copy of the list of fields of the table that were used in the PUB, then check if it contains the name of the field we are interested in.

pub.copySchemaFieldLowercaseNamesInto(fieldNames, dbTableName);
return fieldNames.contains(fieldName);