Package org.apache.openjpa.jdbc.sql

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


     */
    public void writeSchemaColumn(String schema)
        throws SQLException {
        // always use special clob handling when dict has max embedded size;
        // for some reason optimizing for string length causes errors
        DBDictionary dict = _conf.getDBDictionaryInstance();
        boolean embedded = dict.maxEmbeddedClobSize == -1;
        String update;
        if (embedded)
            update = "UPDATE " + dict.getFullName(_pkColumn.getTable(), false)
                + " SET " + dict.getColumnDBName(_schemaColumn) + " = ?  WHERE " +
                dict.getColumnIdentifier(_pkColumn) + " = ?";
        else
            update = "SELECT " + dict.getColumnDBName(_schemaColumn) + " FROM "
                + dict.getFullName(_pkColumn.getTable(), false)
                + " WHERE " + dict.getColumnDBName(_pkColumn) + " = ?";

        Connection conn = getConnection();
        PreparedStatement stmnt = null;
        ResultSet rs = null;
        boolean wasAuto = true;
        try {
            // if embedded we want autocommit true, else false
            wasAuto = conn.getAutoCommit();
            if (wasAuto != embedded)
                conn.setAutoCommit(embedded);

            if (embedded) {
                stmnt = conn.prepareStatement(update);
                if (schema == null)
                    dict.setNull(stmnt, 1, _schemaColumn.getType(),
                        _schemaColumn);
                else if (_schemaColumn.getType() == Types.CLOB)
                    dict.setClobString(stmnt, 1, schema, _schemaColumn);
                else
                    dict.setString(stmnt, 1, schema, _schemaColumn);
                dict.setInt(stmnt, 2, 1, _pkColumn);
                dict.setTimeouts(stmnt, _conf, true);
                stmnt.executeUpdate();
            } else {
                stmnt = conn.prepareStatement(update,
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_UPDATABLE);
                dict.setInt(stmnt, 1, 1, _pkColumn);
                dict.setTimeouts(stmnt, _conf, true);
                rs = stmnt.executeQuery();
                rs.next();
                dict.putString(rs.getClob(1), schema);
                conn.commit();
            }
        }
        finally {
            if (rs != null)
View Full Code Here


        Schema schema = group.addSchema(schemaName);

        Table table = schema.addTable(tableName);
        PrimaryKey pk = table.addPrimaryKey();

        DBDictionary dict = _conf.getDBDictionaryInstance();
        _pkColumn = table.addColumn(dict.getValidColumnName
            (_pkColumnName, table));
        _pkColumn.setType(dict.getPreferredType(Types.TINYINT));
        _pkColumn.setJavaType(JavaTypes.INT);
        pk.addColumn(_pkColumn);

        _schemaColumn = table.addColumn(dict.getValidColumnName
            (_schemaColumnName, table));
        _schemaColumn.setType(dict.getPreferredType(Types.CLOB));
        _schemaColumn.setJavaType(JavaTypes.STRING);
    }
View Full Code Here

        OpenJPAEntityManagerFactorySPI tempEMF = emf;
        if (tempEMF == null) {
            tempEMF = createEMF();
        }
        assertNotNull(tempEMF);
        DBDictionary dict = ((JDBCConfiguration)tempEMF.getConfiguration()).getDBDictionaryInstance();
        assertNotNull(dict);
        if (!dict.supportsSelectForUpdate || !dict.supportsQueryTimeout || dict instanceof SolidDBDictionary)
            setTestsDisabled(true);
        if (emf == null) {
            closeEMF(tempEMF);
View Full Code Here

                        ? OP_SELECT : OP_UPDATE;
        }

        public Number executeUpdate(StoreQuery q, Object[] params) {
            JDBCStore store = ((SQLStoreQuery) q).getStore();
            DBDictionary dict = store.getDBDictionary();
            String sql = q.getContext().getQueryString();

            List paramList = new ArrayList(Arrays.asList(params));
            SQLBuffer buf = new SQLBuffer(dict).append(sql);
           
            // we need to make sure we have an active store connection
            store.getContext().beginStore();
            Connection conn = store.getConnection();
            JDBCFetchConfiguration fetch = (JDBCFetchConfiguration)
                q.getContext().getFetchConfiguration();

            PreparedStatement stmnt = null;
            try {
                if (_call)
                    stmnt = prepareCall(conn, buf);
                else
                    stmnt = prepareStatement(conn, buf);
               
                buf.setParameters(paramList);
                if (stmnt != null)
                    buf.setParameters(stmnt);

                dict.setTimeouts(stmnt, fetch, true);
               
                int count = executeUpdate(store, conn, stmnt, buf)
             
                return count;
            } catch (SQLException se) {
View Full Code Here

        }

        public ResultObjectProvider executeQuery(StoreQuery q,
            Object[] params, Range range) {
            JDBCStore store = ((SQLStoreQuery) q).getStore();
            DBDictionary dict = store.getDBDictionary();
            String sql = q.getContext().getQueryString();

            List paramList = new ArrayList(Arrays.asList(params));
            SQLBuffer buf = new SQLBuffer(dict).append(sql);
            Connection conn = store.getConnection();
            JDBCFetchConfiguration fetch = (JDBCFetchConfiguration)
                q.getContext().getFetchConfiguration();

            ResultObjectProvider rop;
            PreparedStatement stmnt = null;
            try {
                // use the right method depending on sel vs. proc, lrs setting
                if (_select && !range.lrs)
                    stmnt = prepareStatement(conn, buf);
                else if (_select)
                    stmnt = prepareStatement(conn, buf, fetch, -1, -1);
                else if (!range.lrs)
                    stmnt = prepareCall(conn, buf);
                else
                    stmnt = prepareCall(conn, buf, fetch, -1, -1);

                int index = 0;
                for (Iterator i = paramList.iterator(); i.hasNext() &&
                    stmnt != null;)
                    dict.setUnknown(stmnt, ++index, i.next(), null);

                dict.setTimeouts(stmnt, fetch, false);
                ResultSet rs = executeQuery(store, conn, stmnt, buf, paramList);
                ResultSetResult res = stmnt != null ?
                    new ResultSetResult(conn, stmnt, rs, store) :
                    new ResultSetResult(conn, rs, dict);
                if (_resultMapping != null)
View Full Code Here

     * Append SQL for a sub-select testing whether an inverse object exists
     * for this relation.
     */
    private void testInverseNull(SQLBuffer sql, Select sel, Joins joins,
        boolean empty) {
        DBDictionary dict = field.getMappingRepository().getDBDictionary();
        dict.assertSupport(dict.supportsSubselect, "SupportsSubselect");

        if (field.getIndependentTypeMappings().length != 1)
            throw RelationStrategies.uninversable(field);

        if (empty)
View Full Code Here

    protected void setUnsupportedDatabases(Class<?> ... dbs) {
        OpenJPAEntityManagerFactorySPI tempEMF = emf;
        if (tempEMF == null) {
            tempEMF = createEMF();
        }
        DBDictionary dict = ((JDBCConfiguration)tempEMF.getConfiguration()).getDBDictionaryInstance();
        for (Class<?> db : dbs) {
            if (dict.getClass().getCanonicalName().equalsIgnoreCase(db.getCanonicalName())) {
                setTestsDisabled(true);
                break;
            }
        }
        if (emf == null) {
View Full Code Here

    protected void setSupportedDatabases(Class<?> ... dbs) {
        OpenJPAEntityManagerFactorySPI tempEMF = emf;
        if (tempEMF == null) {
            tempEMF = createEMF();
        }
        DBDictionary dict = ((JDBCConfiguration)tempEMF.getConfiguration()).getDBDictionaryInstance();
        boolean supportedDB = false;
        for (Class<?> db : dbs) {
            if (dict.getClass().getCanonicalName().equalsIgnoreCase(db.getCanonicalName())) {
                supportedDB = true;
                break;
            }
        }
        setTestsDisabled(!supportedDB);
View Full Code Here

    protected Log getLog() {
        return emf.getConfiguration().getLog("Tests");
    }
   
    protected String getForUpdateClause() {
        DBDictionary dict = getDBDictionary();
        if (dict.forUpdateClause != null) {
            return dict.forUpdateClause;
        }
        if (dict.tableForUpdateClause != null) {
            return dict.tableForUpdateClause;
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.