Skip to content

Commit

Permalink
Diagnostic Patch apache#1
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Grassel committed Aug 30, 2021
1 parent 172c084 commit 3c3342d
Show file tree
Hide file tree
Showing 7 changed files with 1,266 additions and 185 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.util.MetaDataException;

import jag.JAGDebug;

/**
* Mapping for serialized fields on a dictionary that has a maximum embedded
* BLOB size.
Expand All @@ -53,37 +55,96 @@ protected int getExpectedJavaType() {

protected void update(OpenJPAStateManager sm, Row row)
throws SQLException {
byte[] b = (byte[]) sm.getImplData(field.getIndex());
if (b == null || (b.length > _maxSize && !field.getColumns()[0].isNotNull()))
row.setNull(field.getColumns()[0], true);
else {
sm.setImplData(field.getIndex(), null);
DBDictionary.SerializedData dat =
new DBDictionary.SerializedData(b);
row.setObject(field.getColumns()[0], dat);
JAGDebug.beginReportTracking();
JAGDebug.ReportChain rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedBlobFieldStrategy.update() entry:").nl();
rc.logVariable("sm", sm, false).nl();
rc.logVariable("row", row, false).nl();
rc.logVariable("this", this, false).nl();
rc.logVariable("field", field, false).nl();
rc.logVariable("_maxSize", _maxSize, false).nl();
} catch (Throwable t) {} finally {
rc.done();
}

try {
byte[] b = (byte[]) sm.getImplData(field.getIndex());
JAGDebug.startReportChain().logVariable("b.length", b == null ? "null" : b.length).done();

if (b == null || (b.length > _maxSize && !field.getColumns()[0].isNotNull()))
row.setNull(field.getColumns()[0], true);
else {
sm.setImplData(field.getIndex(), null);
DBDictionary.SerializedData dat =
new DBDictionary.SerializedData(b);
row.setObject(field.getColumns()[0], dat);
}
} finally {
rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedBlobFieldStrategy.update() exit:").nl();
} catch (Throwable t) {} finally {
rc.done();
}

JAGDebug.endReportTracking();
}

}

protected Boolean isCustom(OpenJPAStateManager sm, JDBCStore store) {
// have we already stored our serialized data?
byte[] b = (byte[]) sm.getImplData(field.getIndex());
if (b == null) {
Object o = sm.fetch(field.getIndex());
if (o == null)
return Boolean.FALSE;
JAGDebug.beginReportTracking();
JAGDebug.ReportChain rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedBlobFieldStrategy.isCustom() entry:").nl();
rc.logVariable("sm", sm, false).nl();
rc.logVariable("store", store, false).nl();
rc.logVariable("this", this, false).nl();
rc.logVariable("field", field, false).nl();
rc.logVariable("_maxSize", _maxSize, false).nl();
} catch (Throwable t) {} finally {
rc.done();
}

Boolean retVal = null;
try {
// have we already stored our serialized data?
byte[] b = (byte[]) sm.getImplData(field.getIndex());
JAGDebug.startReportChain().logVariable("b.length", b == null ? "null" : b.length).done();

if (b == null) {
Object o = sm.fetch(field.getIndex());
if (o == null) {
retVal = Boolean.FALSE;
return retVal; // Boolean.FALSE;
}
// serialize field value
DBDictionary dict = field.getMappingRepository().getDBDictionary();
try {
b = dict.serialize(o, store);
JAGDebug.startReportChain().logVariable("#2 b.length", b == null ? "null" : b.length).done();
} catch (SQLException se) {
throw SQLExceptions.getStore(se, dict);
}

// serialize field value
DBDictionary dict = field.getMappingRepository().getDBDictionary();
// set in impl data so that we don't have to re-serialize on store
sm.setImplData(field.getIndex(), b);
}
retVal = (b.length > _maxSize) ? null : Boolean.FALSE;
return retVal; // (b.length > _maxSize) ? null : Boolean.FALSE;
} finally {
rc = JAGDebug.startReportChain();
try {
b = dict.serialize(o, store);
} catch (SQLException se) {
throw SQLExceptions.getStore(se, dict);
rc.append("MaxEmbeddedBlobFieldStrategy.isCustom() exit:").nl();
rc.logVariable("retVal", retVal, false).nl();
} catch (Throwable t) {} finally {
rc.done();
}

// set in impl data so that we don't have to re-serialize on store
sm.setImplData(field.getIndex(), b);
JAGDebug.endReportTracking();
}
return (b.length > _maxSize) ? null : Boolean.FALSE;

}

protected void putData(OpenJPAStateManager sm, ResultSet rs,
Expand All @@ -101,9 +162,32 @@ public void map(boolean adapt) {
}

public void initialize() {
DBDictionary dict = field.getMappingRepository().getDBDictionary();
_maxSize = dict.maxEmbeddedBlobSize;
field.setUsesImplData(Boolean.TRUE);
JAGDebug.beginReportTracking(true);
JAGDebug.ReportChain rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedBlobFieldStrategy.initialize() entry:").nl();
rc.logVariable("this", this, false).nl();
rc.logVariable("field", field, false).nl();
} catch (Throwable t) {} finally {
rc.done();
}

try {
DBDictionary dict = field.getMappingRepository().getDBDictionary();
_maxSize = dict.maxEmbeddedBlobSize;
JAGDebug.startReportChain().logVariable("_maxSize", _maxSize).done();
field.setUsesImplData(Boolean.TRUE);
} finally {
rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedBlobFieldStrategy.initialize() exit:").nl();
} catch (Throwable t) {} finally {
rc.done();
}

JAGDebug.endReportTracking();
}

}

protected Object getValue(OpenJPAStateManager sm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.util.MetaDataException;

import jag.JAGDebug;

/**
* Mapping for byte array fields on a dictionary that has a maximum embedded
* BLOB size.
Expand All @@ -56,17 +58,76 @@ protected int getExpectedJavaType() {

protected void update(OpenJPAStateManager sm, Row row)
throws SQLException {
byte[] b = (byte[]) getValue(sm);
if (b == null)
row.setBytes(field.getColumns()[0], null);
else
row.setBytes(field.getColumns()[0], b);
JAGDebug.beginReportTracking(true);
JAGDebug.ReportChain rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedByteArrayFieldStrategy.update() entry:").nl();
rc.logVariable("sm", sm, false).nl();
rc.logVariable("row", row, false).nl();
rc.logVariable("this", this, false).nl();
rc.logVariable("field", field, false).nl();
rc.logVariable("_maxSize", _maxSize, false).nl();
} catch (Throwable t) {} finally {
rc.done();
}

try {
byte[] b = (byte[]) getValue(sm);
JAGDebug.startReportChain().logVariable("b.length", b == null ? "null" : b.length).done();
if (b == null)
row.setBytes(field.getColumns()[0], null);
else
row.setBytes(field.getColumns()[0], b);
} finally {
rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedByteArrayFieldStrategy.update() exit:").nl();
} catch (Throwable t) {} finally {
rc.done();
}

JAGDebug.endReportTracking();
}


}

protected Boolean isCustom(OpenJPAStateManager sm, JDBCStore store) {
Object val = sm.fetchObject(field.getIndex());
return (val != null && Array.getLength(val) > _maxSize) ? null
: Boolean.FALSE;
JAGDebug.beginReportTracking(true);
JAGDebug.ReportChain rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedByteArrayFieldStrategy.isCustom() entry:").nl();
rc.logVariable("sm", sm, false).nl();
rc.logVariable("store", store, false).nl();
rc.logVariable("this", this, false).nl();
rc.logVariable("field", field, false).nl();
rc.logVariable("_maxSize", _maxSize, false).nl();
} catch (Throwable t) {} finally {
rc.done();
}

Boolean retVal = null;
try {
Object val = sm.fetchObject(field.getIndex());
JAGDebug.startReportChain().logObjectAddress(val).done();
if (val != null) {
JAGDebug.startReportChain().logVariable("Array.getLength(val)", Array.getLength(val)).done();
}
retVal = (val != null && Array.getLength(val) > _maxSize) ? null : Boolean.FALSE;
return retVal; // (val != null && Array.getLength(val) > _maxSize) ? null
// : Boolean.FALSE;
} finally {
rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedByteArrayFieldStrategy.isCustom() exit:").nl();
rc.logVariable("retVal", retVal, false).nl();
} catch (Throwable t) {} finally {
rc.done();
}

JAGDebug.endReportTracking();
}

}

protected void putData(OpenJPAStateManager sm, ResultSet rs,
Expand All @@ -90,8 +151,31 @@ public void map(boolean adapt) {
}

public void initialize() {
DBDictionary dict = field.getMappingRepository().getDBDictionary();
_maxSize = dict.maxEmbeddedBlobSize;
JAGDebug.beginReportTracking(true);
JAGDebug.ReportChain rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedByteArrayFieldStrategy.initialize() entry:").nl();
rc.logVariable("this", this, false).nl();
rc.logVariable("field", field, false).nl();
} catch (Throwable t) {} finally {
rc.done();
}

try {
DBDictionary dict = field.getMappingRepository().getDBDictionary();
_maxSize = dict.maxEmbeddedBlobSize;
JAGDebug.startReportChain().logVariable("_maxSize", _maxSize).done();
} finally {
rc = JAGDebug.startReportChain();
try {
rc.append("MaxEmbeddedByteArrayFieldStrategy.initialize() exit:").nl();
} catch (Throwable t) {} finally {
rc.done();
}

JAGDebug.endReportTracking();
}

}

protected Object getValue(OpenJPAStateManager sm) {
Expand Down
Loading

0 comments on commit 3c3342d

Please sign in to comment.