Package org.apache.openjpa.jdbc.sql

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


        testOptimizeForClause(false,true,true);
    }
    public void testOptimizeForClause(boolean hint,
        boolean find, boolean queryHint) {
        OpenJPAEntityManagerSPI em = emf.createEntityManager();
        DBDictionary dict = ((JDBCConfiguration) em.getConfiguration())
            .getDBDictionaryInstance();

        // hsql doesn't support optimizing; circumvent the test
        if (dict instanceof HSQLDictionary)
            return;
View Full Code Here


    }

    public void testSelectForUpdateOverride() {
        OpenJPAEntityManagerSPI em = (OpenJPAEntityManagerSPI)
            OpenJPAPersistence.cast(emf.createEntityManager());
        DBDictionary dict = ((JDBCConfiguration) em.getConfiguration())
            .getDBDictionaryInstance();

        // hsql doesn't support locking; circumvent the test
        if (dict instanceof HSQLDictionary)
            return;
View Full Code Here

        if (col == null && !adapt)
            throw new MetaDataException(_loc.get(prefix + "-bad-col-name",
                context, colName, table));

        MappingRepository repos = (MappingRepository) context.getRepository();
        DBDictionary dict = repos.getDBDictionary();

        // use information from template column by default, allowing any
        // user-given specifics to override it
        int type = tmplate.getType();
        int size = tmplate.getSize();
        if (type == Types.OTHER)
            type = dict.getJDBCType(tmplate.getJavaType(), size == -1);
        boolean ttype = true;
        int otype = type;
        String typeName = tmplate.getTypeName();
        Boolean notNull = null;
        if (tmplate.isNotNullExplicit())
            notNull = (tmplate.isNotNull()) ? Boolean.TRUE : Boolean.FALSE;
        int decimals = tmplate.getDecimalDigits();
        String defStr = tmplate.getDefaultString();
        boolean autoAssign = tmplate.isAutoAssigned();
        boolean relationId = tmplate.isRelationId();
        String targetField = tmplate.getTargetField();
        if (given != null) {
            // use given type if provided, but warn if it isn't compatible with
            // the expected column type
            if (given.getType() != Types.OTHER) {
                ttype = false;
                if (compat && !given.isCompatible(type, typeName, size,
                    decimals)) {
                    Log log = repos.getLog();
                    if (log.isWarnEnabled())
                        log.warn(_loc.get(prefix + "-incompat-col",
                            context, colName, Schemas.getJDBCName(type)));
                }
                otype = given.getType();
                type = dict.getPreferredType(otype);
            }
            typeName = given.getTypeName();
            size = given.getSize();
            decimals = given.getDecimalDigits();
View Full Code Here

            }
            return exist;
        }

        // dict can't handle unique constraints?
        DBDictionary dict = repos.getDBDictionary();
        if (_unq != null && !dict.supportsUniqueConstraints) {
            Log log = repos.getLog();
            if (log.isWarnEnabled())
                log.warn(_loc.get(prefix + "-unique-support", context));
            return null;
View Full Code Here

                }
            }
        }

        MappingRepository repos = (MappingRepository) context.getRepository();
        DBDictionary dict = repos.getDBDictionary();
        if (exist != null) {
            // make existing key logical?
            if (!_canFK) {
                if (exist.getDeleteAction() != exist.ACTION_NONE && !adapt)
                    throw new MetaDataException(_loc.get(prefix
                        + "-fk-exists", context));
                exist.setDeleteAction(exist.ACTION_NONE);
            }

            if (_fk != null && _fk.isDeferred() && !exist.isDeferred()) {
                Log log = repos.getLog();
                if (log.isWarnEnabled())
                    log.warn(_loc.get(prefix + "-defer-fk", context));
            }

            // allow user-given info to override existing key if we're adapting;
            // template info cannot override existing key
            if (adapt && _fk != null) {
                if (_fk.getUpdateAction() != ForeignKey.ACTION_NONE)
                    exist.setUpdateAction(_fk.getUpdateAction());
                if (_fk.getDeleteAction() != ForeignKey.ACTION_NONE)
                    exist.setDeleteAction(_fk.getDeleteAction());
            }
            setIOFromJoins(exist, joins);
            return exist;
        }

        String name = null;
        int delAction = ForeignKey.ACTION_NONE;
        int upAction = ForeignKey.ACTION_NONE;
        boolean deferred = false;
        boolean fill = repos.getMappingDefaults().defaultMissingInfo();
        ForeignKey tmplate = (def == null) ? null
            : def.get(local, foreign, _join == JOIN_INVERSE);
        if (_fk != null && (tmplate == null || (!adapt && !fill))) {
            // if not adapting or no template info use given data
            name = _fk.getName();
            delAction = _fk.getDeleteAction();
            upAction = _fk.getUpdateAction();
            deferred = _fk.isDeferred();
        } else if (_canFK && (adapt || fill)) {
            if (_fk == null && tmplate != null) {
                // no user given info; use template data
                name = tmplate.getName();
                delAction = tmplate.getDeleteAction();
                upAction = tmplate.getUpdateAction();
                deferred = tmplate.isDeferred();
            } else if (_fk != null && tmplate != null) {
                // merge user and template data, always letting user info win
                name = _fk.getName();
                if (name == null && tmplate.getName() != null)
                    name = tmplate.getName();
                delAction = _fk.getDeleteAction();
                if (delAction == ForeignKey.ACTION_NONE)
                    delAction = tmplate.getDeleteAction();
                upAction = _fk.getUpdateAction();
                if (upAction == ForeignKey.ACTION_NONE)
                    upAction = tmplate.getUpdateAction();
                deferred = _fk.isDeferred();
            }
        }

        if (!dict.supportsDeleteAction(delAction)
            || !dict.supportsUpdateAction(upAction)) {
            Log log = repos.getLog();
            if (log.isWarnEnabled())
                log.warn(_loc.get(prefix + "-unsupported-fk-action", context));
            delAction = ForeignKey.ACTION_NONE;
            upAction = ForeignKey.ACTION_NONE;
View Full Code Here

    protected static Column syncColumn(MetaDataContext context, Column col,
        int num, boolean forceJDBCType, Table colTable, Table targetTable,
        Object target, boolean inverse) {
        // use full name for cols that aren't in the expected table, or that
        // are inverse joins
        DBDictionary dict = ((MappingRepository) context.getRepository()).
            getDBDictionary();
        Column copy = new Column();
        if (col.getTable() != colTable || inverse)
            copy.setName(dict.getFullName(col.getTable(), true)
                + "." + col.getName());
        else
            copy.setName(col.getName());

        // set target if not default
        if (target != null) {
            if (target == NULL)
                copy.setTarget("null");
            else if (target instanceof Column) {
                Column tcol = (Column) target;
                if ((!inverse && tcol.getTable() != targetTable)
                    || (inverse && tcol.getTable() != colTable))
                    copy.setTarget(dict.getFullName(tcol.getTable(), true)
                        + "." + tcol.getName());
                else if (!defaultTarget(col, tcol, num))
                    copy.setTarget(tcol.getName());
            } else if (target instanceof Number)
                copy.setTarget(target.toString());
            else
                copy.setTarget("'" + target + "'");
        } else if (num > 1)
            copy.setTargetField(col.getTargetField());

        if (col.getSize() != 0 && col.getSize() != dict.characterColumnSize
            && (col.getSize() != -1 || !col.isLob()))
            copy.setSize(col.getSize());
        if (col.getDecimalDigits() != 0)
            copy.setDecimalDigits(col.getDecimalDigits());
        if (col.getDefaultString() != null)
            copy.setDefaultString(col.getDefaultString());
        if (col.isNotNull() && !col.isPrimaryKey()
            && (!isPrimitive(col.getJavaType()) || isForeignKey(col)))
            copy.setNotNull(true);

        // set type name if not default
        String typeName = col.getTypeName();
        if (typeName != null || copy.getSize() != 0
            || copy.getDecimalDigits() != 0) {
            // is this the dict default type? have to ensure jdbc-type set
            // prior to finding dict default
            copy.setType(col.getType());
            String defName = dict.getTypeName(copy);
            copy.setType(Types.OTHER);

            // copy should not have size info set if it isn't used in type name
            boolean defSized = defName.indexOf('(') != -1;
            if (!defSized) {
                if (copy.getSize() > 0)
                    copy.setSize(0);
                copy.setDecimalDigits(0);
            }

            if (typeName != null) {
                // make sure to strip size for comparison
                if (typeName.indexOf('(') == -1 && defSized)
                    defName = defName.substring(0, defName.indexOf('('));
                if (!typeName.equalsIgnoreCase(defName))
                    copy.setTypeName(typeName);
            }
        }

        // set jdbc-type if not default or if forced
        if (forceJDBCType
            || (target != null && !(target instanceof Column)
            && col.getType() != Types.VARCHAR)
            || dict.getJDBCType(col.getJavaType(), false) != col.getType())
            copy.setType(col.getType());

        return copy;
    }
View Full Code Here

            return new ValueMapDiscriminatorStrategy();
        if (cls.getMappedPCSuperclassMapping() != null)
            return NoneDiscriminatorStrategy.getInstance();
        if (adapting || _defaults.defaultMissingInfo())
            return new ClassNameDiscriminatorStrategy();
        DBDictionary dict = ((JDBCConfiguration) getConfiguration()).
            getDBDictionaryInstance();
        if (dict.joinSyntax == JoinSyntaxes.SYNTAX_TRADITIONAL)
            return NoneDiscriminatorStrategy.getInstance();
        return new SubclassJoinDiscriminatorStrategy();
    }
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;
            if (params.length > 0) {
                paramList = new ArrayList(Arrays.asList(params));
                try {
                    sql = substituteParams(sql, paramList);
                } catch (IOException ioe) {
                    throw new UserException(ioe);
                }
            } else
                paramList = Collections.EMPTY_LIST;

            SQLBuffer buf = new SQLBuffer(dict).append(sql);
            Connection conn = store.getConnection();
            JDBCFetchConfiguration fetch = (JDBCFetchConfiguration)
                q.getContext().getFetchConfiguration();

            PreparedStatement stmnt = null;
            try {
                stmnt = buf.prepareCall(conn);

                int index = 0;
                for (Iterator i = paramList.iterator(); i.hasNext();)
                    dict.setUnknown(stmnt, ++index, i.next(), null);
               
                int count = 0;
                if (_call && stmnt.execute() == false) {
                    count = stmnt.getUpdateCount();
                }
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;
            if (params.length > 0) {
                paramList = new ArrayList(Arrays.asList(params));
                try {
                    sql = substituteParams(sql, paramList);
                } catch (IOException ioe) {
                    throw new UserException(ioe);
                }
            } else
                paramList = Collections.EMPTY_LIST;

            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 = buf.prepareStatement(conn);
                else if (_select)
                    stmnt = buf.prepareStatement(conn, fetch, -1, -1);
                else if (!range.lrs)
                    stmnt = buf.prepareCall(conn);
                else
                    stmnt = buf.prepareCall(conn, fetch, -1, -1);

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

                ResultSetResult res = new ResultSetResult(conn, stmnt,
                    stmnt.executeQuery(), store);
                if (_resultMapping != null)
                    rop = new MappedQueryResultObjectProvider(_resultMapping,
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

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.