use of org.datanucleus.store.rdbms.scostore.ElementContainerStore in project datanucleus-rdbms by datanucleus.
the class AbstractRDBMSQueryResult method registerMemberBulkResultSet.
public void registerMemberBulkResultSet(IteratorStatement iterStmt, ResultSet rs) {
if (bulkLoadedValueByMemberNumber == null) {
bulkLoadedValueByMemberNumber = new HashMap<>();
}
try {
ExecutionContext ec = query.getExecutionContext();
AbstractMemberMetaData mmd = iterStmt.getBackingStore().getOwnerMemberMetaData();
if (mmd.hasCollection() || mmd.hasArray()) {
ElementContainerStore backingStore = (ElementContainerStore) iterStmt.getBackingStore();
if (backingStore.isElementsAreEmbedded() || backingStore.isElementsAreSerialised()) {
int[] param = new int[backingStore.getElementMapping().getNumberOfDatastoreMappings()];
for (int i = 0; i < param.length; ++i) {
param[i] = i + 1;
}
if (backingStore.getElementMapping() instanceof SerialisedPCMapping || backingStore.getElementMapping() instanceof SerialisedReferenceMapping || backingStore.getElementMapping() instanceof EmbeddedElementPCMapping) {
// Element = Serialised
while (rs.next()) {
Object owner = iterStmt.getOwnerMapIndex().getMapping().getObject(ec, rs, iterStmt.getOwnerMapIndex().getColumnPositions());
Object element = backingStore.getElementMapping().getObject(ec, rs, param, ec.findObjectProvider(owner), backingStore.getOwnerMemberMetaData().getAbsoluteFieldNumber());
addOwnerMemberValue(mmd, owner, element);
}
} else {
// Element = Non-PC
while (rs.next()) {
Object owner = iterStmt.getOwnerMapIndex().getMapping().getObject(ec, rs, iterStmt.getOwnerMapIndex().getColumnPositions());
Object element = backingStore.getElementMapping().getObject(ec, rs, param);
addOwnerMemberValue(mmd, owner, element);
}
}
} else if (backingStore.getElementMapping() instanceof ReferenceMapping) {
// Element is Reference (interface/Object) so just use elementMapping
int[] param = new int[backingStore.getElementMapping().getNumberOfDatastoreMappings()];
for (int i = 0; i < param.length; ++i) {
param[i] = i + 1;
}
while (rs.next()) {
Object owner = iterStmt.getOwnerMapIndex().getMapping().getObject(ec, rs, iterStmt.getOwnerMapIndex().getColumnPositions());
Object element = backingStore.getElementMapping().getObject(ec, rs, param);
addOwnerMemberValue(mmd, owner, element);
}
} else {
String elementType = mmd.hasCollection() ? backingStore.getOwnerMemberMetaData().getCollection().getElementType() : backingStore.getOwnerMemberMetaData().getArray().getElementType();
ResultObjectFactory<E> scoROF = new PersistentClassROF(ec, rs, query.getIgnoreCache(), iterStmt.getStatementClassMapping(), backingStore.getElementClassMetaData(), ec.getClassLoaderResolver().classForName(elementType));
while (rs.next()) {
Object owner = iterStmt.getOwnerMapIndex().getMapping().getObject(ec, rs, iterStmt.getOwnerMapIndex().getColumnPositions());
Object element = scoROF.getObject();
addOwnerMemberValue(mmd, owner, element);
}
}
} else if (mmd.hasMap()) {
// TODO Cater for maps
}
} catch (SQLException sqle) {
NucleusLogger.DATASTORE.error("Exception thrown processing bulk loaded field " + iterStmt.getBackingStore().getOwnerMemberMetaData().getFullFieldName(), sqle);
} finally {
// Close the ResultSet (and its Statement)
try {
Statement stmt = null;
try {
stmt = rs.getStatement();
// Close the result set
rs.close();
} catch (SQLException e) {
NucleusLogger.DATASTORE.error(Localiser.msg("052605", e));
} finally {
try {
if (stmt != null) {
// Close the original statement
stmt.close();
}
} catch (SQLException e) {
// Do nothing
}
}
} finally {
rs = null;
}
}
}
Aggregations