String defaultDir = DbHelper.getDatabaseDirectory(DbHelper.DB_DEFAULT); PDL.loadPDLFiles(new File(pdlDir + "/" + defaultDir));   String databaseDir = DbHelper.getDatabaseDirectory(database); PDL.loadPDLFiles(new File(pdlDir + "/" + databaseDir));
PDL.loadPDLFiles(new File(pdlDir));
    public void startup() {        s_log.warn("Persistence initializer is starting");        int database = DbHelper.getDatabase();        // Set the utilities        if (database == DbHelper.DB_ORACLE) {            SessionManager.setSQLUtilities(new OracleSQLUtilities());        } else if (database == DbHelper.DB_POSTGRES) {            SessionManager.setSQLUtilities(new PostgresSQLUtilities());        } else {            DbHelper.unsupportedDatabaseError("SQL Utilities");        }        ObjectType.setOptimizeDefault(                                      m_conf.getParameter(OPTIMIZE_BY_DEFAULT).equals(Boolean.TRUE)                                      );        if (database == DbHelper.DB_ORACLE) {            MDSQLGeneratorFactory.setMDSQLGenerator(                                                    MDSQLGeneratorFactory.ORACLE_GENERATOR                                                    );        } else if (database == DbHelper.DB_POSTGRES) {            MDSQLGeneratorFactory.setMDSQLGenerator(                                                    MDSQLGeneratorFactory.POSTGRES_GENERATOR                                                    );        } else {            DbHelper.unsupportedDatabaseError("MDSQL generator");        }        String pdlDir = (String)m_conf.getParameter(PDL_DIRECTORY);        if ((m_conf.getParameter(METADATA_XML_FILE_NAMES) != null) &&            (pdlDir == null)) {            throw new InitializationException(                                              "Invalid persistence configuration.  Please replace " +                                              "metadataXmlFileNames with pdlDirectory.");        }        SessionManager.setSchemaConnectionInfo( "",  "", "", "");        final SessionFactory factory = getSessionFactory();        SessionManager.setSessionFactory(factory);        Boolean aggressiveClose =            (Boolean)m_conf.getParameter(AGGRESSIVE_CONNECTION_CLOSE);        if (aggressiveClose != null && aggressiveClose.booleanValue()) {            s_log.info("Using aggressive connection closing");            factory.setAggressiveConnectionClose(true);        } else {            s_log.info("Not using aggressive connection closing " +                       "[aggressiveConnectionClose parameter]");        }        //SessionManager.setSessionFactory();        // Load the default pdl files        String defaultDir = DbHelper.getDatabaseDirectory(DbHelper.DB_DEFAULT);        PDL.loadPDLFiles(new File(pdlDir + "/" + defaultDir));        // NOw the database specific ones        String databaseDir = DbHelper.getDatabaseDirectory(database);        PDL.loadPDLFiles(new File(pdlDir + "/" + databaseDir));        // Finally the files out of the database        try {            Session session = SessionManager.getSession();            TransactionContext txn = session.getTransactionContext();            txn.beginTxn();            MetadataRoot root = MetadataRoot.getMetadataRoot();            PDL pdl = new PDL();            DataCollection collection = SessionManager.getSession()                .retrieve("com.arsdigita.persistence.DynamicObjectType");            while (collection.next()) {                String currentFile = (String)collection.get("dynamicType");                if (s_log.isInfoEnabled()) {                    s_log.info("loading... " + currentFile.toString());                }                if (root.getObjectType(currentFile) != null) {                    // this means that there is a type in the database                    // that has already been defined so we write an error                    s_log.warn                        ("The Object Type [" + currentFile + "] has already " +                         "been defined in the static files.  Ignoring " +                         "object type definition from the database");                    continue;                }                String pdlFile = (String)collection.get("pdlFile");                pdl.load(new StringReader(pdlFile),                         "DATABASE: " + currentFile);            }            collection = SessionManager.getSession()                .retrieve("com.arsdigita.persistence.DynamicAssociation");            while (collection.next()) {                String currentFile = "Association from " +                    collection.get("objectType1") + " to " +                    collection.get("objectType2");                // XXX: I'm going to ignore the possibility of this error for                // now.                //s_log.warn("An association from " + currentFile + " has " +                //"already been defined.  Ignoring version in " +                //"the database");                if (s_log.isInfoEnabled()) {                    s_log.info("loading " + currentFile);                }                String pdlFile = (String)collection.get("pdlFile");                pdl.load(new StringReader(pdlFile),                         "DATABASE: " + currentFile);            }            pdl.generateMetadata(root);            //try {            // Future use -- Patrick            //PDLOutputter.writePDL(root, new java.io.File("/tmp/pdl"));            //} catch (java.io.IOException e) {            //System.out.println(e.getMessage());            //}            txn.commitTxn();        } catch (PDLException e) {            throw new InitializationException                ("Persistence Initialization error while trying to " +                 "compile the PDL files: " + e.getMessage());        }    }