Package org.apache.openjpa.jdbc.schema

Examples of org.apache.openjpa.jdbc.schema.Column


                augmentUpdates = false;

            Val val = (Val) next.getValue();
            if (val == null)
                val = new Null();
            Column col = fmd.getColumns()[0];
            if (allowAlias) {
              sql.append(sel.getColumnAlias(col));
            } else {
              sql.append(toDBName(col.getIdentifier()));
            }           
            sql.append(" = ");

            ExpState state = val.initialize(sel, ctx, 0);
            // JDBC Paths are always PCPaths; PCPath implements Val
            ExpState pathState = ((Val) path).initialize(sel, ctx, 0);
            calculateValue(val, sel, ctx, state, path, pathState);

            // append the value with a null for the Select; i
            // indicates that the
            int length = val.length(sel, ctx, state);
            for (int j = 0; j < length; j++)
                val.appendTo((allowAlias) ? sel : null, ctx, state, sql, j);

            if (i.hasNext())
                sql.append(", ");
        }

        if (augmentUpdates) {
            Path path = (Path) updateParams.keySet().iterator().next();
            FieldMapping fm = (FieldMapping) path.last();
           
            ClassMapping meta = fm.getDefiningMapping();
            Map<Column,?> updates = meta.getVersion().getBulkUpdateValues();
            for (Map.Entry e : updates.entrySet()) {
                Column col = (Column) e.getKey();
                Object val = e.getValue();
                sql.append(", ").append(toDBName(col.getIdentifier())).append(" = ");
                // Version update value for Numeric version is encoded in a String
                // to make SQL such as version = version+1 while Time stamp version is parameterized
                if (val instanceof String) {
                    sql.append((String)val);
                } else {
View Full Code Here


    /**
     * Create a new column from the information in the schema metadata.
     */
    protected Column newColumn(ResultSet colMeta)
        throws SQLException {
        Column c = new Column();
        c.setSchemaIdentifier(fromDBName(colMeta.getString("TABLE_SCHEM"), DBIdentifierType.SCHEMA));
        c.setTableIdentifier(fromDBName(colMeta.getString("TABLE_NAME"), DBIdentifierType.TABLE));
        c.setIdentifier(fromDBName(colMeta.getString("COLUMN_NAME"), DBIdentifierType.COLUMN));
        c.setType(colMeta.getInt("DATA_TYPE"));
        c.setTypeIdentifier(fromDBName(colMeta.getString("TYPE_NAME"), DBIdentifierType.COLUMN_DEFINITION));
        c.setSize(colMeta.getInt("COLUMN_SIZE"));
        c.setDecimalDigits(colMeta.getInt("DECIMAL_DIGITS"));
        c.setNotNull(colMeta.getInt("NULLABLE")
            == DatabaseMetaData.columnNoNulls);

        String def = colMeta.getString("COLUMN_DEF");
        if (!StringUtils.isEmpty(def) && !"null".equalsIgnoreCase(def))
            c.setDefaultString(def);
        return c;
    }
View Full Code Here

            // we key directly on objs and join-less cols, or on the alias
            // for cols with joins
            PathJoins pj = getJoins(joins);
            Boolean pk = null;
            if (pj != null && pj.path() != null) {
                Column col = (Column) obj;
                pk = (col.isPrimaryKey()) ? Boolean.TRUE : Boolean.FALSE;
                if (joins == null && cachedColumnAlias_ != null) {
                    obj = cachedColumnAlias_.get(col);
                    if (obj == null)
                        obj = getColumnAlias(col, pj);
                } else {
                    obj = getColumnAlias(col, pj);
                }
                if (obj == null)
                    throw new SQLException(col.getTable() + ": "
                        + pj.path() + " (" + _sel._aliases + ")");
            }

            // we load in the same order we select, more or less...
            if (_sel._selects.get(_pos).equals(obj))
View Full Code Here

    public void setParameters(PreparedStatement ps)
        throws SQLException {
        if (_params == null)
            return;

        Column col;
        for (int i = 0; i < _params.size(); i++) {
            col = (_cols == null) ? null : (Column) _cols.get(i);
            _dict.setUnknown(ps, i + 1, _params.get(i), col);
        }
    }
View Full Code Here

    public Object getPrimaryKeyValue(Result res, Column[] cols, ForeignKey fk,
        JDBCStore store, Joins joins)
        throws SQLException {
        ClassMapping relmapping = field.getTypeMapping();
        if (relmapping.getIdentityType() == ClassMapping.ID_DATASTORE) {
            Column col = cols[0];
            if (fk != null)
                col = fk.getColumn(col);  
            long id = res.getLong(col, joins);
            if (field.getObjectIdFieldTypeCode() == JavaTypes.LONG)
                return Numbers.valueOf(id);
View Full Code Here

        Column[] gcols, ForeignKey gfk) {
        ForeignKey fk = field.getForeignKey();
        Column[] cols = fk.getColumns();

        ForeignKey tfk = null;
        Column tcol;
        for (int i = 0; i < gcols.length; i++) {
            tcol = gcols[i];
            if (gfk != null)
                tcol = gfk.getColumn(tcol);
            if (tfk == null)
                tfk = new ForeignKey(null, tcol.getTable());
            tfk.join(tcol, fk.getPrimaryKeyColumn(cols[i]));
        }
        return tfk;
    }
View Full Code Here

            // we key directly on objs and join-less cols, or on the alias
            // for cols with joins
            PathJoins pj = getJoins(joins);
            Boolean pk = null;
            if (pj != null && pj.path() != null) {
                Column col = (Column) obj;
                pk = (col.isPrimaryKey()) ? Boolean.TRUE : Boolean.FALSE;
                obj = getColumnAlias(col, pj);
                if (obj == null)
                    throw new SQLException(col.getTable() + ": "
                        + pj.path() + " (" + _sel._aliases + ")");
            }

            // we load in the same order we select, more or less...
            if (_sel._selects.get(_pos).equals(obj))
View Full Code Here

        if (getIdentityType() == ID_UNKNOWN)
            throw new InternalException();

        Column[] pks = getPrimaryKeyColumns();
        if (getIdentityType() == ID_DATASTORE) {
            Column col = (fk == null) ? pks[0] : fk.getColumn(pks[0]);
            long id = res.getLong(col, joins);
            return (id == 0 && res.wasNull()) ? null
                : store.newDataStoreId(id, cls, subs);
        }
View Full Code Here

            cacheParams : _params);   
       
        if (params == null)
            return;

        Column col;
        for (int i = 0; i < params.size(); i++) {
            col = (_cols == null) ? null : (Column) _cols.get(i);
            _dict.setUnknown(ps, i + 1, params.get(i), col);
        }
    }
View Full Code Here

    private boolean isClob(ValueMapping val, boolean warn) {
        List cols = val.getValueInfo().getColumns();
        if (cols.size() != 1)
            return false;

        Column col = (Column) cols.get(0);
        if (col.getSize() != -1 && col.getType() != Types.CLOB)
            return false;

        if (_dict.getPreferredType(Types.CLOB) != Types.CLOB)
            return false;
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.schema.Column

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.