Examples of MetaDataException


Examples of org.apache.openjpa.util.MetaDataException

        if (!join)
            return;

        Message msg = _loc.get("unexpected-join", context);
        if (die)
            throw new MetaDataException(msg);
        context.getRepository().getLog().warn(msg);
    }
View Full Code Here

Examples of org.apache.openjpa.util.MetaDataException

    public Table createTable(MetaDataContext context, TableDefaults def,
        String schemaName, String given, boolean adapt) {
        MappingRepository repos = (MappingRepository) context.getRepository();
        if (given == null && (def == null || (!adapt
            && !repos.getMappingDefaults().defaultMissingInfo())))
            throw new MetaDataException(_loc.get("no-table", context));

        if (schemaName == null)
            schemaName = Schemas.getNewTableSchema((JDBCConfiguration)
                repos.getConfiguration());

        // if no given and adapting or defaulting missing info, use template
        SchemaGroup group = repos.getSchemaGroup();
        Schema schema = null;
        if (given == null) {
            schema = group.getSchema(schemaName);
            if (schema == null)
                schema = group.addSchema(schemaName);
            given = def.get(schema);
        }

        String fullName;
        int dotIdx = given.lastIndexOf('.');
        if (dotIdx == -1)
            fullName = (schemaName == null) ? given : schemaName + "." + given;
        else {
            fullName = given;
            schema = null;
            schemaName = given.substring(0, dotIdx);
            given = given.substring(dotIdx + 1);
        }

        // look for named table using full name and findTable, which allows
        // the dynamic schema factory to create the table if needed
        Table table = group.findTable(fullName);
        if (table != null)
            return table;
        if (!adapt)
            throw new MetaDataException(_loc.get("bad-table", given, context));

        // named table doesn't exist; create it
        if (schema == null) {
            schema = group.getSchema(schemaName);
            if (schema == null)
View Full Code Here

Examples of org.apache.openjpa.util.MetaDataException

        List given = getColumns();
        boolean fill = ((MappingRepository) context.getRepository()).
            getMappingDefaults().defaultMissingInfo();
        if ((!given.isEmpty() || (!adapt && !fill))
            && given.size() != tmplates.length)
            throw new MetaDataException(_loc.get(prefix + "-num-cols",
                context, String.valueOf(tmplates.length),
                String.valueOf(given.size())));

        Column[] cols = new Column[tmplates.length];
        _io = null;
View Full Code Here

Examples of org.apache.openjpa.util.MetaDataException

    /**
     * Assert that the given table is non-null.
     */
    private static void assertTable(MetaDataContext context, Table table) {
        if (table == null)
            throw new MetaDataException(_loc.get("unmapped", context));
    }
View Full Code Here

Examples of org.apache.openjpa.util.MetaDataException

        assertTable(context, table);

        // if not adapting must provide column name at a minimum
        String colName = (given == null) ? null : given.getName();
        if (colName == null && !adapt && !fill)
            throw new MetaDataException(_loc.get(prefix + "-no-col-name",
                context));

        // determine the column name based on given info, or template if none;
        // also make sure that if the user gave a column name, he didn't try
        // to put the column in an unexpected table
        if (colName == null)
            colName = tmplate.getName();
        int dotIdx = colName.lastIndexOf('.');
        if (dotIdx == 0)
            colName = colName.substring(1);
        else if (dotIdx != -1) {
            findTable(context, colName.substring(0, dotIdx), table,
                null, null);
            colName = colName.substring(dotIdx + 1);
        }

        // find existing column
        Column col = table.getColumn(colName);
        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();

            // leave this info as the template defaults unless the user
            // explicitly turns it on in the given column
            if (given.isNotNullExplicit())
                notNull = (given.isNotNull()) ? Boolean.TRUE : Boolean.FALSE;
            if (given.getDefaultString() != null)
                defStr = given.getDefaultString();
            if (given.isAutoAssigned())
                autoAssign = true;
            if (given.isRelationId())
                relationId = true;
        }

        // default char column size if original type is char (test original
        // type rather than final type because orig might be clob, translated
        // to an unsized varchar, which is supported by some dbs)
        if (size == 0 && (otype == Types.VARCHAR || otype == Types.CHAR))
            size = dict.characterColumnSize;

        // create column, or make sure existing column matches expected type
        if (col == null) {
            col = table.addColumn(colName);
            col.setType(type);
        } else if ((compat || !ttype) && !col.isCompatible(type, typeName,
            size, decimals)) {
            // if existing column isn't compatible with desired type, die if
            // can't adapt, else warn and change the existing column type
            Message msg = _loc.get(prefix + "-bad-col", context,
                Schemas.getJDBCName(type), col.getDescription());
            if (!adapt)
                throw new MetaDataException(msg);
            Log log = repos.getLog();
            if (log.isWarnEnabled())
                log.warn(msg);

            col.setType(type);
View Full Code Here

Examples of org.apache.openjpa.util.MetaDataException

                return rel.getTable();
            rel = rel.getJoinablePCSuperclassMapping();
        }

        // none of the possible tables
        throw new MetaDataException(_loc.get("col-wrong-table", context,
            expected, name));
    }
View Full Code Here

Examples of org.apache.openjpa.util.MetaDataException

            prefix = "generic";

        // can't create an index if there are no cols
        if (cols == null || cols.length == 0) {
            if (_idx != null)
                throw new MetaDataException(_loc.get(prefix
                    + "-no-index-cols", context));
            return null;
        }

        // look for an existing index on these columns
        Table table = cols[0].getTable();
        Index[] idxs = table.getIndexes();
        Index exist = null;
        for (int i = 0; i < idxs.length; i++) {
            if (idxs[i].columnsMatch(cols)) {
                exist = idxs[i];
                break;
            }
        }

        // remove existing index?
        if (!_canIdx) {
            if (exist == null)
                return null;
            if (!adapt)
                throw new MetaDataException(_loc.get(prefix + "-index-exists",
                    context));
            table.removeIndex(exist);
            return null;
        }

        // if we have an existing index, merge given info into it
        if (exist != null) {
            if (_idx != null && _idx.isUnique() && !exist.isUnique()) {
                if (!adapt)
                    throw new MetaDataException(_loc.get(prefix
                        + "-index-not-unique", context));
                exist.setUnique(true);
            }
            return exist;
        }
View Full Code Here

Examples of org.apache.openjpa.util.MetaDataException

            prefix = "generic";

        // can't create a constraint if there are no cols
        if (cols == null || cols.length == 0) {
            if (_unq != null || tmplate != null)
                throw new MetaDataException(_loc.get(prefix
                    + "-no-unique-cols", context));
            return null;
        }

        // look for an existing constraint on these columns
        Table table = cols[0].getTable();
        Unique[] unqs = table.getUniques();
        Unique exist = null;
        for (int i = 0; i < unqs.length; i++) {
            if (unqs[i].columnsMatch(cols)) {
                exist = unqs[i];
                break;
            }
        }

        // remove existing unique?
        if (!_canUnq) {
            if (exist == null)
                return null;
            if (!adapt)
                throw new MetaDataException(_loc.get(prefix
                    + "-unique-exists", context));
            table.removeUnique(exist);
            return null;
        }
View Full Code Here

Examples of org.apache.openjpa.util.MetaDataException

                tmp = ((Column) joins[i][0]).getTable();
                if (!localSet) {
                    local = tmp;
                    localSet = true;
                } else if (tmp != local)
                    throw new MetaDataException(_loc.get(prefix
                        + "-mult-fk-tables", context, local, tmp));
                foreign = ((Column) joins[i][1]).getTable();

                if (joins[i][2] == Boolean.TRUE)
                    _join = JOIN_INVERSE;
            } else
                constant = true;
        }

        // if this is not a constant join, look for existing foreign key
        // on local columns
        ForeignKey exist = null;
        if (!constant && local.getForeignKeys().length > 0) {
            Column[] cols = new Column[joins.length];
            Column[] pks = new Column[joins.length];
            for (int i = 0; i < joins.length; i++) {
                cols[i] = (Column) joins[i][0];
                pks[i] = (Column) joins[i][1];
            }

            ForeignKey[] fks = local.getForeignKeys();
            for (int i = 0; i < fks.length; i++) {
                if (fks[i].getConstantColumns().length == 0
                    && fks[i].getConstantPrimaryKeyColumns().length == 0
                    && fks[i].columnsMatch(cols, pks)) {
                    exist = fks[i];
                    break;
                }
            }
        }

        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()) {
View Full Code Here

Examples of org.apache.openjpa.util.MetaDataException

        Object[][] joins;

        // if no columns given, just create mirrors of target columns
        if (given.isEmpty()) {
            if (!adapt && !fill)
                throw new MetaDataException(_loc.get(prefix + "-no-fk-cols",
                    context));

            Column[] targets = rel.getPrimaryKeyColumns();
            joins = new Object[targets.length][3];
            Column tmplate;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.