use of jdk.incubator.sql2.Result.Column in project oracle-db-examples by oracle.
the class RowOperationTest method testInvalidAt.
@Test
public void testInvalidAt() throws Exception {
try (DataSource ds = getDataSource();
Session se = ds.getSession()) {
AtomicInteger rowCount = new AtomicInteger();
se.rowOperation("SELECT * FROM " + TEST_TABLE).collect(ArrayList<String>::new, (ls, rc) -> {
int rowIndex = rowCount.getAndIncrement();
assertEquals(rowIndex, rc.rowNumber());
assertEquals(TEST_COLUMNS.length - 1, rc.numberOfValuesRemaining());
try {
rc.at(TEST_COLUMNS.length + 1);
fail("Expected NoSuchElementException");
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
rc.at(0);
fail("Expected NoSuchElementException");
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
rc.at(-(TEST_COLUMNS.length + 1));
fail("Expected NoSuchElementException");
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
rc.at("z");
fail("Expected NoSuchElementException");
} catch (NoSuchElementException expected) {
/* Expected */
}
int coIndex = 0;
for (Column co : rc) {
coIndex++;
assertEquals(TEST_COLUMNS.length - coIndex, co.numberOfValuesRemaining());
for (int sliceSize = (1 - coIndex); sliceSize <= TEST_COLUMNS.length - (coIndex - 1); sliceSize++) {
if (sliceSize == 0)
continue;
Column coSlice = co.slice(sliceSize);
try {
coSlice.at(Math.abs(sliceSize) + 1);
fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(" + (sliceSize + 1) + ")");
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
coSlice.at(0);
fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(0)");
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
coSlice.at(-(Math.abs(sliceSize) + 1));
fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(" + -(sliceSize + 1) + ")");
} catch (NoSuchElementException expected) {
/* Expected */
}
for (int i = 1; i <= TEST_COLUMNS.length; i++) {
if (sliceSize > 0 && i >= coIndex && i < coIndex + sliceSize)
// Skip valid columns
continue;
if (sliceSize < 0 && i < coIndex && i >= coIndex + sliceSize)
// Skip valid columns
continue;
try {
coSlice.at(TEST_COLUMNS[i - 1]);
fail("Expected NoSuchElementException when calling" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(\"" + TEST_COLUMNS[i - 1] + "\")");
} catch (NoSuchElementException expected) {
/* Expected */
}
}
}
}
}).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
}
}
use of jdk.incubator.sql2.Result.Column in project oracle-db-examples by oracle.
the class RowOperationTest method testInvalidSlice.
@Test
public void testInvalidSlice() throws Exception {
try (DataSource ds = getDataSource();
Session se = ds.getSession()) {
AtomicInteger rowCount = new AtomicInteger();
se.rowOperation("SELECT * FROM " + TEST_TABLE).collect(ArrayList<String>::new, (ls, rc) -> {
int rowIndex = rowCount.getAndIncrement();
assertEquals(rowIndex, rc.rowNumber());
assertEquals(TEST_COLUMNS.length - 1, rc.numberOfValuesRemaining());
int coIndex = 0;
for (Column co : rc) {
coIndex++;
assertEquals(TEST_COLUMNS.length - coIndex, co.numberOfValuesRemaining());
// From the current column index, test the invalid ranges.
try {
co.slice(-coIndex);
fail("No exception thrown at call to slice(" + (-coIndex) + ")" + " from column index: " + coIndex);
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
co.slice(1 + TEST_COLUMNS.length - (coIndex - 1));
fail("No exception thrown at call to slice(" + (-coIndex) + ")" + " from column index: " + coIndex);
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
co.slice(0);
fail("No exception thrown at call to slice(0)" + " from column index: " + coIndex);
} catch (NoSuchElementException expected) {
/* Expected */
}
}
}).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
}
}
use of jdk.incubator.sql2.Result.Column in project oracle-db-examples by oracle-samples.
the class RowOperationTest method testInvalidAt.
@Test
public void testInvalidAt() throws Exception {
try (DataSource ds = getDataSource();
Session se = ds.getSession()) {
AtomicInteger rowCount = new AtomicInteger();
se.rowOperation("SELECT * FROM " + TEST_TABLE).collect(ArrayList<String>::new, (ls, rc) -> {
int rowIndex = rowCount.getAndIncrement();
assertEquals(rowIndex, rc.rowNumber());
assertEquals(TEST_COLUMNS.length - 1, rc.numberOfValuesRemaining());
try {
rc.at(TEST_COLUMNS.length + 1);
fail("Expected NoSuchElementException");
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
rc.at(0);
fail("Expected NoSuchElementException");
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
rc.at(-(TEST_COLUMNS.length + 1));
fail("Expected NoSuchElementException");
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
rc.at("z");
fail("Expected NoSuchElementException");
} catch (NoSuchElementException expected) {
/* Expected */
}
int coIndex = 0;
for (Column co : rc) {
coIndex++;
assertEquals(TEST_COLUMNS.length - coIndex, co.numberOfValuesRemaining());
for (int sliceSize = (1 - coIndex); sliceSize <= TEST_COLUMNS.length - (coIndex - 1); sliceSize++) {
if (sliceSize == 0)
continue;
Column coSlice = co.slice(sliceSize);
try {
coSlice.at(Math.abs(sliceSize) + 1);
fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(" + (sliceSize + 1) + ")");
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
coSlice.at(0);
fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(0)");
} catch (NoSuchElementException expected) {
/* Expected */
}
try {
coSlice.at(-(Math.abs(sliceSize) + 1));
fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(" + -(sliceSize + 1) + ")");
} catch (NoSuchElementException expected) {
/* Expected */
}
for (int i = 1; i <= TEST_COLUMNS.length; i++) {
if (sliceSize > 0 && i >= coIndex && i < coIndex + sliceSize)
// Skip valid columns
continue;
if (sliceSize < 0 && i < coIndex && i >= coIndex + sliceSize)
// Skip valid columns
continue;
try {
coSlice.at(TEST_COLUMNS[i - 1]);
fail("Expected NoSuchElementException when calling" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(\"" + TEST_COLUMNS[i - 1] + "\")");
} catch (NoSuchElementException expected) {
/* Expected */
}
}
}
}
}).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
}
}
use of jdk.incubator.sql2.Result.Column in project oracle-db-examples by oracle-samples.
the class RowOperationTest method testOffsetIteration.
@Test
public void testOffsetIteration() throws Exception {
try (DataSource ds = getDataSource();
Session se = ds.getSession()) {
AtomicInteger rowCount = new AtomicInteger();
se.rowOperation("SELECT * FROM " + TEST_TABLE).collect(ArrayList<String>::new, (ls, rc) -> {
int rowIndex = rowCount.getAndIncrement();
assertEquals(rowIndex, rc.rowNumber());
assertEquals(TEST_COLUMNS.length - 1, rc.numberOfValuesRemaining());
for (int offset = 1; offset <= TEST_COLUMNS.length; offset++) {
int count = 0;
Column prev = null;
for (Column col : rc.at(offset)) {
validateColumn(rowIndex, col, offset + count, 0, TEST_COLUMNS.length);
assertFalse(col == rc);
assertFalse(col == prev);
assertEquals(offset, rc.index());
prev = col;
count++;
}
assertEquals(1 + (TEST_COLUMNS.length - offset), count);
}
}).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
}
}
use of jdk.incubator.sql2.Result.Column in project oracle-db-examples by oracle-samples.
the class RowOperationTest method testColumnSlice.
@Test
public void testColumnSlice() throws Exception {
try (DataSource ds = getDataSource();
Session se = ds.getSession()) {
AtomicInteger rowCount = new AtomicInteger();
se.rowOperation("SELECT * FROM " + TEST_TABLE).collect(ArrayList<String>::new, (ls, rc) -> {
int rowIndex = rowCount.getAndIncrement();
assertEquals(rowIndex, rc.rowNumber());
assertEquals(TEST_COLUMNS.length - 1, rc.numberOfValuesRemaining());
// valid slice sizes
for (int sliceSize = 0; sliceSize <= TEST_COLUMNS.length; sliceSize++) {
if (sliceSize == 0)
continue;
Column sliceSequence = rc.slice(sliceSize);
int sliceIndex = 0;
for (Column sliceCo : sliceSequence) {
validateColumn(rowIndex, sliceCo, ++sliceIndex, 0, sliceSize);
}
}
// From each column index, test the full range of valid slice
// sizes.
int coIndex = 0;
for (Column co : rc) {
coIndex++;
assertEquals(TEST_COLUMNS.length - coIndex, co.numberOfValuesRemaining());
for (int sliceSize = (1 - coIndex); sliceSize <= TEST_COLUMNS.length - (coIndex - 1); sliceSize++) {
if (sliceSize == 0)
continue;
Column sliceSequence = co.slice(sliceSize);
assertEquals(Math.abs(sliceSize) - 1, sliceSequence.numberOfValuesRemaining());
// The absolute index of the first column in the sequence.
int absStartIndex = (sliceSize < 0 ? (coIndex + sliceSize) : coIndex);
int sliceIndex = 0;
for (Column sliceCo : sliceSequence) {
sliceIndex++;
validateColumn(rowIndex, sliceCo, sliceIndex, absStartIndex - 1, Math.abs(sliceSize));
}
assertEquals(Math.abs(sliceSize), sliceIndex);
}
}
}).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
}
}
Aggregations