String sizeStmt = getSizeStmt(ecs);
try
{
ExecutionContext ec = ownerSM.getExecutionContext();
ManagedConnection mconn = storeMgr.getConnection(ec);
SQLController sqlControl = storeMgr.getSQLController();
try
{
PreparedStatement ps = sqlControl.getStatementForQuery(mconn, sizeStmt);
try
{
int jdbcPosition = 1;
jdbcPosition = BackingStoreHelper.populateOwnerInStatement(ownerSM, ec, ps, jdbcPosition, ecs);
if (ecs.getElementInfo() != null && ecs.getElementInfo().length == 1)
{
// TODO Allow for multiple element types (e.g interface implementations)
for (int i = 0; i < ecs.getElementInfo().length; i++)
{
if (ecs.getElementInfo()[i].getDiscriminatorMapping() != null)
{
jdbcPosition =
BackingStoreHelper.populateElementDiscriminatorInStatement(ec, ps,
jdbcPosition, true, ecs.getElementInfo()[i], clr);
}
}
}
if (ecs.getRelationDiscriminatorMapping() != null)
{
jdbcPosition =
BackingStoreHelper.populateRelationDiscriminatorInStatement(ec, ps, jdbcPosition, ecs);
}
ResultSet rs = sqlControl.executeStatementQuery(mconn, sizeStmt, ps);
try
{
if (!rs.next())
{
throw new NucleusDataStoreException(localiser.msg("056007", sizeStmt));
}
numRows = rs.getInt(1);
JDBCUtils.logWarnings(rs);
}
finally
{
rs.close();
}
}
finally
{
sqlControl.closeStatement(mconn, ps);
}
}
finally
{
mconn.release();
}
}
catch (SQLException e)
{
throw new NucleusDataStoreException(localiser.msg("056007", sizeStmt), e);