Package org.apache.openjpa.jdbc.sql

Examples of org.apache.openjpa.jdbc.sql.DBDictionary


    public void testJDBCEscape() {
        populate();
        EntityManager em = emf.createEntityManager();

        String[] jpql;
        DBDictionary dict = ((JDBCConfiguration)emf.getConfiguration()).getDBDictionaryInstance();
        if ((dict instanceof SQLServerDictionary) || (dict instanceof HSQLDictionary)) {
            jpql = new String[] {
                // some changes to the jpql strings had to be made for MSSQL and HSQLDB
                "select a from Employee a where a.hireDate >= {d '2009-08-25'}",
                "select a from Employee a where a.hireDate >= {d '2009-08-05'}",    // requires yyyy-mm-dd
View Full Code Here


        em.close();
    }

    public void testNoRoundingNoMillisecondLoss() {
        JDBCConfiguration conf = (JDBCConfiguration) emf.getConfiguration();
        DBDictionary dict = conf.getDBDictionaryInstance();
        dict.setDateMillisecondBehavior(DBDictionary.DateMillisecondBehaviors.RETAIN.toString());
       
        em = emf.createEntityManager();
        final List<TemporalEntity> temporalEntityList = findAll(em);
        assertNotNull(temporalEntityList);
        assertNotEquals(temporalEntityList.size(), 0);
View Full Code Here

        em.close();
    }
   
    public void testRounding() {
        JDBCConfiguration conf = (JDBCConfiguration) emf.getConfiguration();
        DBDictionary dict = conf.getDBDictionaryInstance();
        // set value back to default
        dict.setDateMillisecondBehavior(DBDictionary.DateMillisecondBehaviors.ROUND.toString());
       
        em = emf.createEntityManager();
        final List<TemporalEntity> temporalEntityList = findAll(em);
        assertNotNull(temporalEntityList);
        assertNotEquals(temporalEntityList.size(), 0);
View Full Code Here

   
   
    @Override
    protected boolean startDelimitedIdentifiers() {
        JDBCConfiguration conf = (JDBCConfiguration) getConfiguration();
        DBDictionary dict = conf.getDBDictionaryInstance();
        dict.setDelimitIdentifiers(true);
        return true;
    }
View Full Code Here

    }

    public void endConfiguration() {
        buildSequence();

        DBDictionary dict = _conf.getDBDictionaryInstance();
        String format = dict.nextSequenceQuery;
        if (format == null) {
            throw new MetaDataException(_loc.get("no-seq-sql", _seqName));
        }

        String name = dict.getFullName(_seq);
        // Increment step is needed for Firebird which uses non-standard sequence fetch syntax.
        // Use String.valueOf to get rid of possible locale-specific number formatting.
        _select = MessageFormat.format(format, new Object[]{name, String.valueOf(_allocate * _increment)});
       
        type = dict.nativeSequenceType;
View Full Code Here

    protected synchronized void allocateInternal(int additional, JDBCStore store, ClassMapping mapping)
        throws SQLException {
        Connection conn = getConnection(store);
        try {
            if (!alterIncrementBy) {
                DBDictionary dict = _conf.getDBDictionaryInstance();
                if (!dict.disableAlterSeqenceIncrementBy) {
                    // If this fails, we will warn the user at most one time and set _allocated and _increment to 1 so
                    // as to not potentially insert records ahead of what the database thinks is the next sequence
                    // value.
                    if (updateSql(conn, dict.getAlterSequenceSQL(_seq)) == -1) {
                        if (!alreadyLoggedAlterSeqFailure) {
                            Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
                            if (log.isWarnEnabled()) {
                                log.warn(_loc.get("fallback-no-seq-cache", _seqName));
                            }
View Full Code Here

    /**
     * Return the next sequence value.
     */
    private long getSequence(Connection conn)
        throws SQLException {
        DBDictionary dict = _conf.getDBDictionaryInstance();
        PreparedStatement stmnt = null;
        ResultSet rs = null;
        try {
            stmnt = conn.prepareStatement(_select);
            dict.setTimeouts(stmnt, _conf, false);
            rs = stmnt.executeQuery();
            if (rs.next())
                return rs.getLong(1);

            // no row !?
View Full Code Here

                try { stmnt.close(); } catch (SQLException se) {}
        }
    }

    private int updateSql(Connection conn, String sql) throws SQLException {
        DBDictionary dict = _conf.getDBDictionaryInstance();
        PreparedStatement stmnt = null;
        int rc = -1;
        try {
            stmnt = conn.prepareStatement(sql);
            dict.setTimeouts(stmnt, _conf, false);
            rc = stmnt.executeUpdate();
        } catch (Exception e) {
            // tolerate exception when attempting to alter increment,
            // however, caller should check rc and not cache sequence values if rc != -1.
        } finally {
View Full Code Here

    /**
     * Tests that application identity classes are returned correctly.
     */
    public void testSchemaGeneration() {
        JDBCConfiguration conf = new JDBCConfigurationImpl();
        DBDictionary dict = conf.getDBDictionaryInstance();
        MappingRepository repos = conf.getMappingRepositoryInstance();
        repos.setStrategyInstaller(new RefreshStrategyInstaller(repos));
        ClassMapping mapping = repos.getMapping(Column.class, null, true);

        Class cls;
        if (dict.getPreferredType(JavaSQLTypes.CLOB) ==  JavaSQLTypes.CLOB) {
            if (dict.maxEmbeddedClobSize > 0) {
                cls = mapping.getFieldMapping("toClob").getStrategy().
                    getClass();
                assertTrue(cls.getName(),
                    MaxEmbeddedClobFieldStrategy.class.isAssignableFrom(cls));
            } else {
                cls = mapping.getFieldMapping("toClob").getHandler().
                    getClass();
                assertTrue(cls.getName(),
                    ClobValueHandler.class.isAssignableFrom(cls));
            }
        } else
            assertTrue(mapping.getFieldMapping("toClob").getStrategy()
                instanceof StringFieldStrategy);

        cls = mapping.getFieldMapping("toBlob").getHandler().getClass();
        assertTrue(cls.getName(),
            BlobValueHandler.class.isAssignableFrom(cls));

        SchemaGroup schema = repos.getSchemaGroup();
        Table table = schema.getSchemas()[0].getTables()[0];
        Column[] cols = table.getColumns();
        for (int i = 0; i < cols.length; i++) {
            if (cols[i].getName().equalsIgnoreCase("id")
                || cols[i].getName().equalsIgnoreCase("versn")
                || cols[i].getName().equalsIgnoreCase("typ"))
                continue;
            if ("longToInt".equalsIgnoreCase(cols[i].getName()))
                assertEquals(dict.getPreferredType(JavaSQLTypes.INT),
                    cols[i].getType());
            else if ("longToSQL".equalsIgnoreCase(cols[i].getName()))
                assertEquals("varchar", cols[i].getTypeName());
            else if ("toClob".equalsIgnoreCase(cols[i].getName()))
                assertEquals(dict.getPreferredType(JavaSQLTypes.CLOB),
                    cols[i].getType());
            else if ("toBlob".equalsIgnoreCase(cols[i].getName()))
                assertEquals(dict.getPreferredType(JavaSQLTypes.BLOB),
                    cols[i].getType());
            else
                fail("Unknown column:" + cols[i].getName());
        }
    }   
View Full Code Here

    public DBDictionary getDBDictionaryInstance() {
        // lock on connection factory name, since getting the connection
        // factory and getting the dictionary have to use the same locks to
        // prevent deadlock since they call each other
        DBDictionary dbdictionary = (DBDictionary) dbdictionaryPlugin.get();
        if (dbdictionary == null) {
            String clsName = dbdictionaryPlugin.getClassName();
            String props = dbdictionaryPlugin.getProperties();
            if (!StringUtils.isEmpty(clsName)) {
                dbdictionary = DBDictionaryFactory.newDBDictionary
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.sql.DBDictionary

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.