/** * Return a new row. */ protected RowImpl newInstance(Column[] cols, int action) { return new RowImpl(cols, action); }
/** * Return the SQL for a prepared statement delete on this row. */ private String getDeleteSQL(DBDictionary dict) { StringBuilder buf = new StringBuilder(); buf.append("DELETE FROM "). append(dict.getFullName(getTable(), false)); appendWhere(buf, dict); return buf.toString(); }
/** * Performs a proper deep clone. */ public Object clone() { RowImpl clone = newInstance(getColumns(), getAction()); copyInto(clone, false); return clone; }
public void copyInto(RowImpl row, boolean whereOnly) { super.copyInto(row, whereOnly); if (_fks == null || whereOnly || row.getAction() == ACTION_DELETE || !(row instanceof SecondaryRow)) return; SecondaryRow srow = (SecondaryRow) row; if (srow._fks == null) srow._fks = new OpenJPAStateManager[_fks.length]; System.arraycopy(_fks, 0, srow._fks, 0, _fks.length); if (_fkIO != null) { if (srow._fkIO == null) srow._fkIO = new ColumnIO[_fkIO.length]; System.arraycopy(_fkIO, 0, srow._fkIO, 0, _fkIO.length); } } }
if (to == null) { for (int i = 0; i < fromCols.length; i++) { if (set && canSet(io, i, true)) setNull(fromCols[i]); else if (!set) whereNull(fromCols[i]); if (set && !canSetAny(io, fromCols.length, false)) return; if (_action == ACTION_INSERT && fromCols[i].isAutoAssigned()) continue; if (!canSet(io, i, false)) continue; getContext().getStoreManager().getInnermostDelegate()); if (set && val == null) { if (canSet(io, i, true)) setNull(fromCols[i]); } else if (set && val instanceof Raw) setRaw(fromCols[i], val.toString()); else if (set) setObject(fromCols[i], val, toCols[i].getJavaType(), false); else if (val == null) whereNull(fromCols[i]); else if (val instanceof Raw) whereRaw(fromCols[i], val.toString()); else whereObject(fromCols[i], val, toCols[i].getJavaType());
private void flushSingleRow(RowImpl row, PreparedStatement ps) throws SQLException { row.flush(ps, _dict, _store); int count = ps.executeUpdate(); if (count != 1) { Object failed = row.getFailedObject(); if (failed != null) _exceptions.add(new OptimisticException(failed)); else if (row.getAction() == Row.ACTION_INSERT) throw new SQLException(_loc.get("update-failed-no-failed-obj", String.valueOf(count), row.getSQL(_dict)).getMessage()); } }
/** * Flush the foreign key values. */ private void flushForeignKey(ForeignKey fk, ColumnIO io, OpenJPAStateManager sm, boolean set) throws SQLException { flushJoinValues(sm, null, fk.getPrimaryKeyColumns(), fk.getColumns(), io, set); if (sm != null) { Column[] cols = fk.getConstantColumns(); int len = fk.getColumns().length; Object obj; int type; for (int i = 0; i < cols.length; i++) { obj = fk.getConstant(cols[i]); type = cols[i].getJavaType(); if (set && canSet(io, i + len, obj == null)) setObject(cols[i], obj, type, false); else if (!set) whereObject(cols[i], obj, type); } } }
int i = (getAction() == ACTION_DELETE) ? _cols.length: 0; Column col; Object val; if (_vals[i] == NULL && getAction() != ACTION_INSERT && i >= half) continue; setFlushed(true);
/** * Flush the primary key values. */ private void flushPrimaryKey(OpenJPAStateManager sm, ColumnIO io, boolean set) throws SQLException { ClassMapping mapping = (ClassMapping) sm.getMetaData(); while (mapping.getTable() != getTable()) mapping = mapping.getPCSuperclassMapping(); Column[] cols = mapping.getPrimaryKeyColumns(); flushJoinValues(sm, cols, cols, io, set); }
/** * All set column methods delegate to this one. Set the given object * unless this is an insert and the given column is auto-assigned. */ protected void setObject(Column col, Object val, int metaType, boolean overrideDefault) throws SQLException { // never set auto increment columns and honor column defaults if (_action == ACTION_INSERT) { if (col.isAutoAssigned()) { // OPENJPA-349: validate because this can be the only column setValid(true); return; } if (!overrideDefault && val == null && col.getDefaultString() != null) return; } flush(col, val, metaType, true); }
if (count < _batchLimit || _batchLimit == -1) { if (ps != null) onerow.flush(ps, _dict, _store); addBatch(ps, onerow, count); count++; onerow.flush(ps, _dict, _store); addBatch(ps, onerow, count); throw SQLExceptions.getStore(se, (_batchedRows.get(index)).getFailedObject(), _dict);
public void whereForeignKey(ForeignKey fk, OpenJPAStateManager sm) throws SQLException { flushForeignKey(fk, null, sm, false); }
/** * All where column methods delegate to this one. */ protected void whereObject(Column col, Object val, int metaType) throws SQLException { flush(col, val, metaType, false); }
public void clearRelationId(Column col) throws SQLException { super.clearRelationId(col); if (_relSet != null) { int idx = getRelationIdIndex(col); _relSet[idx] = null; _callbacks[idx] = null; } }
public void clearForeignKey(ForeignKey fk) throws SQLException { super.clearForeignKey(fk); if (_fkSet != null) _fkSet[fk.getIndex()] = null; if (_fkIO != null) _fkIO[fk.getIndex()] = null; }
public void copyInto(RowImpl row, boolean whereOnly) { super.copyInto(row, whereOnly); if (!(row instanceof PrimaryRow)) return;
if (to == null) { for (int i = 0; i < fromCols.length; i++) { if (set && canSet(io, i, true)) setNull(fromCols[i]); else if (!set) whereNull(fromCols[i]); if (set && !canSetAny(io, fromCols.length, false)) return; if (_action == ACTION_INSERT && fromCols[i].isAutoAssigned()) continue; if (!canSet(io, i, false)) continue; if (canSet(io, i, true)) setNull(fromCols[i]); } else if (set && val instanceof Raw) setRaw(fromCols[i], val.toString()); else if (set) setObject(fromCols[i], val, toCols[i].getJavaType(), false); else if (val == null) whereNull(fromCols[i]); else if (val instanceof Raw) whereRaw(fromCols[i], val.toString()); else whereObject(fromCols[i], val, toCols[i].getJavaType());
private void flushSingleRow(RowImpl row, PreparedStatement ps) throws SQLException { if (ps != null) row.flush(ps, _dict, _store); int count = executeUpdate(ps, row.getSQL(_dict), row); if (count != 1) { logSQLWarnings(ps); Object failed = row.getFailedObject(); if (failed != null) _exceptions.add(new OptimisticException(failed)); else if (row.getAction() == Row.ACTION_INSERT) throw new SQLException(_loc.get("update-failed-no-failed-obj", String.valueOf(count), row.getSQL(_dict)).getMessage()); } }
/** * Flush the foreign key values. */ private void flushForeignKey(ForeignKey fk, ColumnIO io, OpenJPAStateManager sm, boolean set) throws SQLException { flushJoinValues(sm, null, fk.getPrimaryKeyColumns(), fk.getColumns(), io, set); if (sm != null) { Column[] cols = fk.getConstantColumns(); int len = fk.getColumns().length; Object obj; int type; for (int i = 0; i < cols.length; i++) { obj = fk.getConstant(cols[i]); type = cols[i].getJavaType(); if (set && canSet(io, i + len, obj == null)) setObject(cols[i], obj, type, false); else if (!set) whereObject(cols[i], obj, type); } } }