Java Reference
In-Depth Information
is a class that parses
XML
metadata files, instantiates metadata objects, and stores
them in a
MetaDataManager
class that acts as a repository of the metadata.
ORMU
nit can then use the information contained in the metadata objects to
make assertions about the object/relational mapping. Similarly, the
assertData-
baseSchema()
method calls
SchemaTool.validateSchema()
, which is a
JPOX
class that reads the
XML
mapping data and throws an exception if tables or col-
umns are missing from the database schema.
Listing 5.1
JPOXMappingStrategy
public class JPOXMappingStrategy implements
JDOMappingTestsStrategy {
private MetaDataManager mdm;
private ClassMetaData cmd;
private final String jdoProperties;
private final String[] metadataFiles;
public JPOXMappingStrategy(String jdoProperties,
String[] metadataFiles) throws Exception {
this.jdoProperties = jdoProperties;
this.metadataFiles = metadataFiles;
mdm = createMetaDataManager();
}
B
Gets
the JDO metadata
private MetaDataManager createMetaDataManager()
throws Exception {
mdm = new MetaDataManager();
for (int i = 0; i < metadataFiles.length; i++) {
String fileName = metadataFiles[i];
FileInputStream fis = new FileInputStream(fileName);
FileMetaData fmdUtil =
MetaDataParser.parseMetaDataStream(fis,
true, mdm, fileName);
fis.close();
}
return mdm;
}
private void assertClassMapped(Class type, String table) {
cmd = mdm.getMetaDataForClass(type);
assertEquals(table, cmd.getTable());
}
C
Verifies the
class mapping
protected void assertDatabaseSchema()
throws FileNotFoundException, IOException, Exception {
FileInputStream fis =
Search WWH ::
Custom Search