private Collection flush(Collection states, JDBCStore store, PreparedStatementManager psMgr) { // run through all the states and update them as necessary RowManager rowMgr = newRowManager(); Collection customs = new LinkedList(); Collection exceps = null; for (Iterator itr = states.iterator(); itr.hasNext();) exceps = populateRowManager((OpenJPAStateManager) itr.next(), rowMgr, store, exceps, customs); // flush rows exceps = flush(rowMgr, psMgr, exceps); // now do any custom mappings for (Iterator itr = customs.iterator(); itr.hasNext();) { try { ((CustomMapping) itr.next()).execute(store); } catch (SQLException se) { exceps = addException(exceps, SQLExceptions.getStore(se, dict)); } catch (OpenJPAException ke) { exceps = addException(exceps, ke); } } // return all exceptions Collection psExceps = psMgr.getExceptions(); if (exceps == null) return psExceps; if (psExceps == null) return exceps; exceps.addAll(psExceps); return exceps; }
public Collection flush(Collection states, JDBCStore store) { Connection conn = store.getConnection(); try { PreparedStatementManager psMgr = newPreparedStatementManager(store, conn); return flush(states, store, psMgr); } finally { try { conn.close(); } catch (SQLException se) {} } }
BitSet dirty; if (sm.getPCState() == PCState.PNEW && !sm.isFlushed()) { insert(sm, (ClassMapping) sm.getMetaData(), rowMgr, store, customs); } else if (sm.getPCState() == PCState.PNEWFLUSHEDDELETED || sm.getPCState() == PCState.PDELETED) { delete(sm, (ClassMapping) sm.getMetaData(), rowMgr, store, customs); } else if ((dirty = ImplHelper.getUpdateFields(sm)) != null) { update(sm, dirty, (ClassMapping) sm.getMetaData(), rowMgr, store, customs); } else if (sm.isVersionUpdateRequired()) { updateIndicators(sm, (ClassMapping) sm.getMetaData(), rowMgr, store, customs, true); } else if (sm.isVersionCheckRequired()) { if (!((ClassMapping) sm.getMetaData()).getVersion(). checkVersion(sm, store, false)) exceps = addException(exceps, new OptimisticException(sm. getManagedInstance())); exceps = addException(exceps, SQLExceptions.getStore(se, dict)); } catch (OpenJPAException ke) { exceps = addException(exceps, ke);
/** * Recursive method to update the given instance. */ protected void update(OpenJPAStateManager sm, BitSet dirty, ClassMapping mapping, RowManager rowMgr, JDBCStore store, Collection customs) throws SQLException { Boolean custom = mapping.isCustomUpdate(sm, store); if (!Boolean.FALSE.equals(custom)) mapping.customUpdate(sm, store); if (Boolean.TRUE.equals(custom)) return; // update all fields before all mappings so that the mappings can // detect whether any fields in their rows have been modified FieldMapping[] fields = mapping.getDefinedFieldMappings(); for (int i = 0; i < fields.length; i++) { if (dirty.get(fields[i].getIndex()) && !bufferCustomUpdate(fields[i], sm, store, customs)) fields[i].update(sm, store, rowMgr); } ClassMapping sup = mapping.getJoinablePCSuperclassMapping(); if (sup == null) updateIndicators(sm, mapping, rowMgr, store, customs, false); else update(sm, dirty, sup, rowMgr, store, customs); mapping.update(sm, store, rowMgr); }
insert(sm, sup, rowMgr, store, customs); fields = reorderFields(fields); for (int i = 0; i < fields.length; i++) { if (dirty.get(fields[i].getIndex()) && !bufferCustomInsert(fields[i], sm, store, customs)) { fields[i].insert(sm, store, rowMgr); if (!bufferCustomInsert(vers, sm, store, customs)) vers.insert(sm, store, rowMgr); Discriminator dsc = mapping.getDiscriminator(); if (!bufferCustomInsert(dsc, sm, store, customs)) dsc.insert(sm, store, rowMgr);
/** * Recursive method to delete the given instance, base class last. */ protected void delete(OpenJPAStateManager sm, ClassMapping mapping, RowManager rowMgr, JDBCStore store, Collection customs) throws SQLException { Boolean custom = mapping.isCustomDelete(sm, store); if (!Boolean.FALSE.equals(custom)) mapping.customDelete(sm, store); if (Boolean.TRUE.equals(custom)) return; FieldMapping[] fields = mapping.getDefinedFieldMappings(); for (int i = 0; i < fields.length; i++) if (!bufferCustomDelete(fields[i], sm, store, customs)) fields[i].delete(sm, store, rowMgr); ClassMapping sup = mapping.getJoinablePCSuperclassMapping(); if (sup == null) { Version vers = mapping.getVersion(); if (!bufferCustomDelete(vers, sm, store, customs)) vers.delete(sm, store, rowMgr); Discriminator dsc = mapping.getDiscriminator(); if (!bufferCustomDelete(dsc, sm, store, customs)) dsc.delete(sm, store, rowMgr); } mapping.delete(sm, store, rowMgr); if (sup != null) delete(sm, sup, rowMgr, store, customs); }
insert(sm, sup, rowMgr, store, customs); for (int i = 0; i < fields.length; i++) { if (dirty.get(fields[i].getIndex()) && !bufferCustomInsert(fields[i], sm, store, customs)) fields[i].insert(sm, store, rowMgr); if (!bufferCustomInsert(vers, sm, store, customs)) vers.insert(sm, store, rowMgr); Discriminator dsc = mapping.getDiscriminator(); if (!bufferCustomInsert(dsc, sm, store, customs)) dsc.insert(sm, store, rowMgr);
/** * Update version and discriminator indicators. */ protected void updateIndicators(OpenJPAStateManager sm, ClassMapping mapping, RowManager rowMgr, JDBCStore store, Collection customs, boolean versionUpdateOnly) throws SQLException { while (mapping.getJoinablePCSuperclassMapping() != null) mapping = mapping.getJoinablePCSuperclassMapping(); Version vers = mapping.getVersion(); if (!bufferCustomUpdate(vers, sm, store, customs)) vers.update(sm, store, rowMgr); if (versionUpdateOnly) { // if we are only updating the version column, we need to add // in the primary key select mapping.update(sm, store, rowMgr); } else { // otherwise we need to make sure we update the discriminator too Discriminator dsc = mapping.getDiscriminator(); if (!bufferCustomUpdate(dsc, sm, store, customs)) dsc.update(sm, store, rowMgr); } }
if (sm.getPCState() == PCState.PNEW && !sm.isFlushed()) { action = Row.ACTION_INSERT; insert(sm, (ClassMapping) sm.getMetaData(), rowMgr, store, customs); } else if (sm.getPCState() == PCState.PNEWFLUSHEDDELETED || sm.getPCState() == PCState.PDELETED) { action = Row.ACTION_DELETE; delete(sm, (ClassMapping) sm.getMetaData(), rowMgr, store, customs); } else if ((dirty = ImplHelper.getUpdateFields(sm)) != null) { update(sm, dirty, (ClassMapping) sm.getMetaData(), rowMgr, store, customs, false); } else if (sm.isVersionUpdateRequired()) { updateIndicators(sm, (ClassMapping) sm.getMetaData(), rowMgr, store, customs, true); } else if (sm.isVersionCheckRequired()) { if (!((ClassMapping) sm.getMetaData()).getVersion(). checkVersion(sm, store, false)) exceps = addException(exceps, new OptimisticException(sm. getManagedInstance())); exceps = addException(exceps, SQLExceptions.getStore(se, dict)); } catch (OpenJPAException ke) { RowImpl row = (RowImpl) rowMgr.getRow(((ClassMapping) sm.getMetaData()).getTable(), action, sm, false); row.setFlushed(true); exceps = addException(exceps, ke);
FieldMapping field = fields[i]; if (dirty.get(field.getIndex()) && !bufferCustomUpdate(field, sm, store, customs)) { field.update(sm, store, rowMgr); if (!updateIndicators) { if (sup == null) { if (updateIndicators) { updateIndicators(sm, mapping, rowMgr, store, customs, false); update(sm, dirty, sup, rowMgr, store, customs, updateIndicators);
insert(sm, sup, rowMgr, store, customs); fields = reorderFields(fields); for (int i = 0; i < fields.length; i++) { if (dirty.get(fields[i].getIndex()) && !bufferCustomInsert(fields[i], sm, store, customs)) { fields[i].insert(sm, store, rowMgr); if (!bufferCustomInsert(vers, sm, store, customs)) vers.insert(sm, store, rowMgr); Discriminator dsc = mapping.getDiscriminator(); if (!bufferCustomInsert(dsc, sm, store, customs)) dsc.insert(sm, store, rowMgr);
/** * Recursive method to delete the given instance, base class last. */ protected void delete(OpenJPAStateManager sm, ClassMapping mapping, RowManager rowMgr, JDBCStore store, Collection customs) throws SQLException { Boolean custom = mapping.isCustomDelete(sm, store); if (!Boolean.FALSE.equals(custom)) mapping.customDelete(sm, store); if (Boolean.TRUE.equals(custom)) return; FieldMapping[] fields = mapping.getDefinedFieldMappings(); for (int i = 0; i < fields.length; i++) if (!bufferCustomDelete(fields[i], sm, store, customs)) fields[i].delete(sm, store, rowMgr); ClassMapping sup = mapping.getJoinablePCSuperclassMapping(); if (sup == null) { Version vers = mapping.getVersion(); if (!bufferCustomDelete(vers, sm, store, customs)) vers.delete(sm, store, rowMgr); Discriminator dsc = mapping.getDiscriminator(); if (!bufferCustomDelete(dsc, sm, store, customs)) dsc.delete(sm, store, rowMgr); } mapping.delete(sm, store, rowMgr); if (sup != null) delete(sm, sup, rowMgr, store, customs); }
/** * Update version and discriminator indicators. */ protected void updateIndicators(OpenJPAStateManager sm, ClassMapping mapping, RowManager rowMgr, JDBCStore store, Collection customs, boolean versionUpdateOnly) throws SQLException { while (mapping.getJoinablePCSuperclassMapping() != null) mapping = mapping.getJoinablePCSuperclassMapping(); Version vers = mapping.getVersion(); if (!bufferCustomUpdate(vers, sm, store, customs)) vers.update(sm, store, rowMgr); if (versionUpdateOnly) { // if we are only updating the version column, we need to add // in the primary key select mapping.update(sm, store, rowMgr); } else { // otherwise we need to make sure we update the discriminator too Discriminator dsc = mapping.getDiscriminator(); if (!bufferCustomUpdate(dsc, sm, store, customs)) dsc.update(sm, store, rowMgr); } }
if (sm.getPCState() == PCState.PNEW && !sm.isFlushed()) { action = Row.ACTION_INSERT; insert(sm, (ClassMapping) sm.getMetaData(), rowMgr, store, customs); } else if (sm.getPCState() == PCState.PNEWFLUSHEDDELETED || sm.getPCState() == PCState.PDELETED) { action = Row.ACTION_DELETE; delete(sm, (ClassMapping) sm.getMetaData(), rowMgr, store, customs); } else if ((dirty = ImplHelper.getUpdateFields(sm)) != null) { update(sm, dirty, (ClassMapping) sm.getMetaData(), rowMgr, store, customs, false); } else if (sm.isVersionUpdateRequired()) { updateIndicators(sm, (ClassMapping) sm.getMetaData(), rowMgr, store, customs, true); } else if (sm.isVersionCheckRequired()) { if (!((ClassMapping) sm.getMetaData()).getVersion(). checkVersion(sm, store, false)) exceps = addException(exceps, new OptimisticException(sm. getManagedInstance())); exceps = addException(exceps, SQLExceptions.getStore(se, dict)); } catch (OpenJPAException ke) { RowImpl row = (RowImpl) rowMgr.getRow(((ClassMapping) sm.getMetaData()).getTable(), action, sm, false); row.setFlushed(true); exceps = addException(exceps, ke);
protected Collection flush(Collection states, JDBCStore store, PreparedStatementManager psMgr) { RowManager rowMgr = newRowManager(); Collection customs = new LinkedList(); Collection exceps = psMgr.getExceptions(); if (sm.getMappedByIdFields() != null) mappedByIdStates.add(sm); else exceps = populateRowManager(sm, rowMgr, store, exceps, customs); } else exceps = populateRowManager(obj, rowMgr, store, exceps, customs); exceps = flush(rowMgr, psMgr, exceps); exceps = populateRowManager(sm, rowMgr, store, exceps, customs); exceps = flush(rowMgr, psMgr, exceps); ((CustomMapping) itr.next()).execute(store); } catch (SQLException se) { exceps = addException(exceps, SQLExceptions.getStore(se, dict)); } catch (OpenJPAException ke) { exceps = addException(exceps, ke);
FieldMapping field = fields[i]; if (dirty.get(field.getIndex()) && !bufferCustomUpdate(field, sm, store, customs)) { field.update(sm, store, rowMgr); if (!updateIndicators) { if (sup == null) { if (updateIndicators) { updateIndicators(sm, mapping, rowMgr, store, customs, false); update(sm, dirty, sup, rowMgr, store, customs, updateIndicators);
insert(sm, sup, rowMgr, store, customs); fields = reorderFields(fields); for (int i = 0; i < fields.length; i++) { if (dirty.get(fields[i].getIndex()) && !bufferCustomInsert(fields[i], sm, store, customs)) { fields[i].insert(sm, store, rowMgr); if (!bufferCustomInsert(vers, sm, store, customs)) vers.insert(sm, store, rowMgr); Discriminator dsc = mapping.getDiscriminator(); if (!bufferCustomInsert(dsc, sm, store, customs)) dsc.insert(sm, store, rowMgr);
public Collection flush(Collection states, JDBCStore store) { Connection conn = store.getConnection(); try { PreparedStatementManager psMgr = newPreparedStatementManager(store, conn); return flush(states, store, psMgr); } finally { try { conn.close(); } catch (SQLException se) {} } }
/** * Recursive method to delete the given instance, base class last. */ protected void delete(OpenJPAStateManager sm, ClassMapping mapping, RowManager rowMgr, JDBCStore store, Collection customs) throws SQLException { Boolean custom = mapping.isCustomDelete(sm, store); if (!Boolean.FALSE.equals(custom)) mapping.customDelete(sm, store); if (Boolean.TRUE.equals(custom)) return; FieldMapping[] fields = mapping.getDefinedFieldMappings(); for (int i = 0; i < fields.length; i++) if (!bufferCustomDelete(fields[i], sm, store, customs)) fields[i].delete(sm, store, rowMgr); ClassMapping sup = mapping.getJoinablePCSuperclassMapping(); if (sup == null) { Version vers = mapping.getVersion(); if (!bufferCustomDelete(vers, sm, store, customs)) vers.delete(sm, store, rowMgr); Discriminator dsc = mapping.getDiscriminator(); if (!bufferCustomDelete(dsc, sm, store, customs)) dsc.delete(sm, store, rowMgr); } mapping.delete(sm, store, rowMgr); if (sup != null) delete(sm, sup, rowMgr, store, customs); }
/** * Update version and discriminator indicators. */ protected void updateIndicators(OpenJPAStateManager sm, ClassMapping mapping, RowManager rowMgr, JDBCStore store, Collection customs, boolean versionUpdateOnly) throws SQLException { while (mapping.getJoinablePCSuperclassMapping() != null) mapping = mapping.getJoinablePCSuperclassMapping(); Version vers = mapping.getVersion(); if (!bufferCustomUpdate(vers, sm, store, customs)) vers.update(sm, store, rowMgr); if (versionUpdateOnly) { // if we are only updating the version column, we need to add // in the primary key select mapping.update(sm, store, rowMgr); } else { // otherwise we need to make sure we update the discriminator too Discriminator dsc = mapping.getDiscriminator(); if (!bufferCustomUpdate(dsc, sm, store, customs)) dsc.update(sm, store, rowMgr); } }