concept foreign key name in category java
appears as: foreign key names, foreign key name
 |
Although we’re testing only foreign key names, we could test other aspects of the generated schema, so we create a generic SchemaTest class. |
 |
The test case method by itself is quite simple: it calls the superclass analyzeSchema() method (described shortly), passing as a parameter an inner class that will do the job. |
 |
This regular expression is used to identify whether a line defines a foreign key. |
 |
This regular expression is used to extract the foreign key name. |
 |
The SQL representing the schema generation is parsed in two levels: first, split() is used to break the lines, and then a regular expression checks for lines that define a foreign key. We could use only one regular expression to handle both, but the result would be more complex. |
,  |
Once we find an invalid foreign key, we buffer it and fail later, with the failure message containing all violations. Although it would be simpler to fail right away, this approach is more helpful, because it requires just one run to spot all invalid names. |
 |
The meaning of a valid foreign key is up to the project. In our case, we define that it has to start with FK_ and have two names (which should represent the tables involved in the relationship) separated by an underscore (_). |