Package org.apache.openjpa.jdbc.meta

Examples of org.apache.openjpa.jdbc.meta.Discriminator


    }

    public void testCharDiscriminators() {
        EntityManager em = emf.createEntityManager(); // load types

        Discriminator discrim = getMapping("CharAbstractEntity")
                .getDiscriminator();
        assertEquals(new Character('C'), discrim.getValue()); // Generated
        assertEquals(JavaTypes.CHAR, discrim.getJavaType());

        discrim = getMapping("chrLeaf").getDiscriminator();
        assertEquals(new Character('c'), discrim.getValue());
        assertEquals(JavaTypes.CHAR, discrim.getJavaType());

        discrim = getMapping("CharRootEntity").getDiscriminator();
        assertEquals(new Character('R'), discrim.getValue());
        assertEquals(JavaTypes.CHAR, discrim.getJavaType());

        em.close();
    }
View Full Code Here


    }

    public void testIntDiscriminators() {
        EntityManager em = emf.createEntityManager(); // load the types

        Discriminator discrim = getMapping("IntegerAbstractEntity")
                .getDiscriminator();
        assertEquals(new Integer("IntegerAbstractEntity".hashCode()), discrim
                .getValue()); // Generated value
        assertEquals(JavaTypes.INT, discrim.getJavaType());

        discrim = getMapping("intLeaf").getDiscriminator();
        assertEquals(new Integer("intLeaf".hashCode()), discrim.getValue());
        assertEquals(JavaTypes.INT, discrim.getJavaType());

        discrim = getMapping("IntegerRootEntity").getDiscriminator();
        assertEquals(new Integer(10101), discrim.getValue());
        assertEquals(JavaTypes.INT, discrim.getJavaType());

        em.close();
    }
View Full Code Here

        em.close();
    }

    public void testStringDiscriminators() {
        EntityManager em = emf.createEntityManager(); // load the types
        Discriminator discrim = getMapping("StringAbstractEntity")
                .getDiscriminator();
        assertEquals("StringAbstractEntity", discrim.getValue()); // Generated
        assertEquals(JavaTypes.STRING, discrim.getJavaType());

        discrim = getMapping("strLeaf").getDiscriminator();
        assertEquals("strLeaf", discrim.getValue());
        assertEquals(JavaTypes.STRING, discrim.getJavaType());

        discrim = getMapping("StringRootEntity").getDiscriminator();
        assertEquals("StringRoot", discrim.getValue());
        assertEquals(JavaTypes.STRING, discrim.getJavaType());
        em.close();
    }
View Full Code Here

    /**
     * Makes sure all subclasses of the given type are loaded in the JVM.
     * This is usually done automatically.
     */
    public void loadSubclasses(ClassMapping mapping) {
        Discriminator dsc = mapping.getDiscriminator();
        if (dsc.getSubclassesLoaded())
            return;

        // if the subclass list is set, no need to load subs
        if (mapping.getRepository().getPersistentTypeNames(false,
            _ctx.getClassLoader()) != null) {
            dsc.setSubclassesLoaded(true);
            return;
        }

        try {
            dsc.loadSubclasses(this);
        } catch (ClassNotFoundException cnfe) {
            throw new StoreException(cnfe);
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, _dict);
        }
View Full Code Here

        Column col = new Column();
        if (!StringUtils.isEmpty(dcol.name()))
            col.setName(dcol.name());
        if (!StringUtils.isEmpty(dcol.columnDefinition()))
            col.setTypeName(dcol.columnDefinition());
        Discriminator discrim = cm.getDiscriminator();
        switch (dcol.discriminatorType()) {
            case CHAR:
                col.setJavaType(JavaTypes.CHAR);
                discrim.setJavaType(JavaTypes.CHAR);
                break;
            case INTEGER:
                col.setJavaType(JavaTypes.INT);
                if (dcol.length() != 31)
                    col.setSize(dcol.length());
                discrim.setJavaType(JavaTypes.INT);
                break;
            default:
                col.setJavaType(JavaTypes.STRING);
                col.setSize(dcol.length());
                discrim.setJavaType(JavaTypes.STRING);
        }
        cm.getDiscriminator().getMappingInfo().setColumns
            (Arrays.asList(new Column[]{ col }));
    }
View Full Code Here

            pstate.field.appendIndex(sql, sel, pstate.joins);
    }

    public void appendType(Select sel, ExpContext ctx, ExpState state,
        SQLBuffer sql) {
        Discriminator disc = null;
        ClassMapping sup = _class;
        while (sup.getMappedPCSuperclassMapping() != null)
            sup = sup.getMappedPCSuperclassMapping();

        disc = sup.getDiscriminator();

        Column[] cols = null;
        if (disc != null)
            cols = disc.getColumns();
        else
            cols = getColumns(state);

        if (cols == null || cols.length == 0) {
            sql.append("1");
View Full Code Here

    /**
     * Makes sure all subclasses of the given type are loaded in the JVM.
     * This is usually done automatically.
     */
    public void loadSubclasses(ClassMapping mapping) {
        Discriminator dsc = mapping.getDiscriminator();
        if (dsc.getSubclassesLoaded())
            return;

        // if the subclass list is set, no need to load subs
        if (mapping.getRepository().getPersistentTypeNames(false,
            _ctx.getClassLoader()) != null) {
            dsc.setSubclassesLoaded(true);
            return;
        }

        try {
            dsc.loadSubclasses(this);
        } catch (ClassNotFoundException cnfe) {
            throw new StoreException(cnfe);
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, _dict);
        }
View Full Code Here

        assertNotNull(vers);
        assertEquals("MAPPINGTEST1", vers.getColumns()[0].getTable().
            getName().toUpperCase());
        assertEquals(Types.INTEGER, vers.getColumns()[0].getType());

        Discriminator cls = _mapping.getDiscriminator();
        assertNotNull(cls);
        assertEquals("MAPPINGTEST1", cls.getColumns()[0].getTable().
            getName().toUpperCase());
        assertEquals(Types.VARCHAR, cls.getColumns()[0].getType());
    }
View Full Code Here

    /**
     * Makes sure all subclasses of the given type are loaded in the JVM.
     * This is usually done automatically.
     */
    public void loadSubclasses(ClassMapping mapping) {
        Discriminator dsc = mapping.getDiscriminator();
        if (dsc.getSubclassesLoaded())
            return;

        // if the subclass list is set, no need to load subs
        if (mapping.getRepository().getPersistentTypeNames(false,
            _ctx.getClassLoader()) != null) {
            dsc.setSubclassesLoaded(true);
            return;
        }

        try {
            dsc.loadSubclasses(this);
        } catch (ClassNotFoundException cnfe) {
            throw new StoreException(cnfe);
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, _dict);
        }
View Full Code Here

        assertEquals(1, _mapping.getPrimaryKeyColumns().length);
        assertEquals("OID", _mapping.getPrimaryKeyColumns()[0].getName());
    }

    public void testDiscriminator() {
        Discriminator disc = _mapping.getDiscriminator();
        assertTrue(disc.getStrategy() instanceof
            ClassNameDiscriminatorStrategy);
        assertEquals(1, disc.getColumns().length);
        assertEquals("DISCRIM", disc.getColumns()[0].getName());
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.meta.Discriminator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.