Search in sources :

Example 1 with ISO8859_2

use of org.jpox.samples.i18n.ISO8859_2 in project tests by datanucleus.

the class BasicTest method testMetaDataManagerI18N.

/**
 * Test for the MetaDataManager.
 */
public void testMetaDataManagerI18N() {
    JDOMetaDataHelper mdProc = new JDOMetaDataHelper();
    String filename = "/org/jpox/samples/i18n/UTF8.jdo";
    MetaDataManager mmgr1 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    MetaDataParser parser1 = new MetaDataParser(mmgr1, mmgr1.getNucleusContext().getPluginManager(), true, true);
    mmgr1.setValidate(false);
    FileMetaData fmd = (FileMetaData) parser1.parseMetaDataStream(MetaDataParser.class.getResourceAsStream(filename), filename, "jdo");
    fmd.getPackage("org.jpox.samples.i18n").getClass("UTF8");
    org.datanucleus.metadata.AbstractClassMetaData cmd1 = fmd.getPackage("org.jpox.samples.i18n").getClass("UTF8");
    cmd1.populate(new ClassLoaderResolverImpl(), null, mmgr1);
    cmd1.initialise(new ClassLoaderResolverImpl());
    MetaDataManager mmgr2 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mmgr2.setValidate(false);
    org.datanucleus.metadata.AbstractClassMetaData cmd = mmgr2.getMetaDataForClass(UTF8.class, new ClassLoaderResolverImpl());
    if (!mdProc.getXMLForMetaData(cmd, "", "").equals(mdProc.getXMLForMetaData(cmd1, "", ""))) {
        fail("i18n UTF-8 issues in parser");
    }
    filename = "/org/jpox/samples/i18n/ISO8859_2.jdo";
    MetaDataManager mmgr3 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    MetaDataParser parser3 = new MetaDataParser(mmgr3, mmgr3.getNucleusContext().getPluginManager(), true, true);
    mmgr3.setValidate(false);
    fmd = (FileMetaData) parser3.parseMetaDataStream(MetaDataParser.class.getResourceAsStream(filename), filename, "jdo");
    fmd.getPackage("org.jpox.samples.i18n").getClass("ISO8859_2");
    MetaDataManager mmgr4 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mmgr4.setValidate(false);
    cmd1 = fmd.getPackage("org.jpox.samples.i18n").getClass("ISO8859_2");
    cmd1.populate(new ClassLoaderResolverImpl(), null, mmgr4);
    cmd1.initialise(null);
    cmd = mmgr4.getMetaDataForClass(ISO8859_2.class, new ClassLoaderResolverImpl());
    if (!mdProc.getXMLForMetaData(cmd, "", "").equals(mdProc.getXMLForMetaData(cmd1, "", ""))) {
        fail("i18n ISO8859_2 issues in parser");
    }
}
Also used : JDOMetaDataHelper(org.datanucleus.api.jdo.metadata.JDOMetaDataHelper) ISO8859_2(org.jpox.samples.i18n.ISO8859_2) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataParser(org.datanucleus.metadata.xml.MetaDataParser) FileMetaData(org.datanucleus.metadata.FileMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 2 with ISO8859_2

use of org.jpox.samples.i18n.ISO8859_2 in project tests by datanucleus.

the class I18NTest method testISO8859_2.

/**
 * Simple test to load up the ISO8859-2 class.
 */
public void testISO8859_2() throws Exception {
    if (vendorID != null && vendorID.equals("postgresql")) {
        // Dont run on Postgresql
        return;
    }
    String datastoreProtocol = TestHelper.getDatastorePluginProtocol(1);
    if (datastoreProtocol != null && datastoreProtocol.equals("cassandra")) {
        // Don't run on Cassandra
        return;
    }
    try {
        try {
            addClassesToSchema(new Class[] { ISO8859_2.class });
        } catch (Exception e) {
            fail("Failed to load class with ISO8859-2 field names : " + e.getMessage());
        } finally {
        }
        // Test persistence of an object
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            ISO8859_2 obj = new ISO8859_2("����", "����");
            pm.makePersistent(obj);
            tx.commit();
        } catch (Exception e) {
            fail("Failed to persist an object of class with ISO8859-2 field names : " + e.getMessage());
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
        }
        // Test retrieval of object
        tx = pm.currentTransaction();
        try {
            tx.begin();
            Extent<ISO8859_2> e = pm.getExtent(org.jpox.samples.i18n.ISO8859_2.class, false);
            Query<ISO8859_2> q = pm.newQuery(e);
            Collection<ISO8859_2> c = q.executeList();
            assertTrue("Number of ISO8859_2 objects is incorrect (" + c.size() + ") : should have been 1", c.size() == 1);
            Iterator<ISO8859_2> iter = c.iterator();
            while (iter.hasNext()) {
                ISO8859_2 obj = iter.next();
                LOG.info(obj);
            }
            tx.commit();
        } catch (Exception e) {
            fail("Failed to retrieve an object of class with ISO8859-2 field names : " + e.getMessage());
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
        }
        pm.close();
    } finally {
        clean(ISO8859_2.class);
    }
}
Also used : ISO8859_2(org.jpox.samples.i18n.ISO8859_2) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager)

Aggregations

ISO8859_2 (org.jpox.samples.i18n.ISO8859_2)2 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)1 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)1 JDOMetaDataHelper (org.datanucleus.api.jdo.metadata.JDOMetaDataHelper)1 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)1 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)1 FileMetaData (org.datanucleus.metadata.FileMetaData)1 MetaDataManager (org.datanucleus.metadata.MetaDataManager)1 MetaDataParser (org.datanucleus.metadata.xml.MetaDataParser)1