| Method from org.apache.openjpa.jdbc.kernel.AbstractUpdateManager Detail: |
protected Collection addException(Collection exceps,
Exception err) {
if (exceps == null)
exceps = new LinkedList();
exceps.add(err);
return exceps;
}
Add the given exception to the given list, which may start out as null. |
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);
}
Recursive method to delete the given instance, base class last. |
public void endConfiguration() {
}
|
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) {}
}
}
|
abstract protected Collection flush(RowManager rowMgr,
PreparedStatementManager psMgr,
Collection exceps)
Flush all rows of the given row manager. Add exceptions to
exceps (which may start as null) using
#addException . Return exceps. |
protected void insert(OpenJPAStateManager sm,
ClassMapping mapping,
RowManager rowMgr,
JDBCStore store,
Collection customs) throws SQLException {
Boolean custom = mapping.isCustomInsert(sm, store);
if (!Boolean.FALSE.equals(custom))
mapping.customInsert(sm, store);
if (Boolean.TRUE.equals(custom))
return;
ClassMapping sup = mapping.getJoinablePCSuperclassMapping();
if (sup != null)
insert(sm, sup, rowMgr, store, customs);
mapping.insert(sm, store, rowMgr);
FieldMapping[] fields = mapping.getDefinedFieldMappings();
BitSet dirty = sm.getDirty();
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 (sup == null) {
Version vers = mapping.getVersion();
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 insert the given instance, base class first. |
abstract protected PreparedStatementManager newPreparedStatementManager(JDBCStore store,
Connection conn)
|
abstract protected RowManager newRowManager()
|
protected Collection populateRowManager(OpenJPAStateManager sm,
RowManager rowMgr,
JDBCStore store,
Collection exceps,
Collection customs) {
try {
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()));
}
} catch (SQLException se) {
exceps = addException(exceps, SQLExceptions.getStore(se, dict));
} catch (OpenJPAException ke) {
exceps = addException(exceps, ke);
}
return exceps;
}
Populate the row manager with rows to be flushed for the given state. |
public void setConfiguration(Configuration conf) {
this.conf = (JDBCConfiguration) conf;
dict = this.conf.getDBDictionaryInstance();
}
|
public void startConfiguration() {
}
|
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);
}
Recursive method to update the given instance. |
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);
}
}
Update version and discriminator indicators. |