InsertStatementHandler implements SQLStatementHandler { public static Optional<WithSegment> getWithSegment(final InsertStatement insertStatement) { if (insertStatement instanceof PostgreSQLStatement) { return ((PostgreSQLInsertStatement) insertStatement).getWithSegment(); } if (insertStatement instanceof SQLServerStatement) { return ((SQLServerInsertStatement) insertStatement).getWithSegment(); } return Optional.empty(); }  static Optional<OnDuplicateKeyColumnsSegment> getOnDuplicateKeyColumnsSegment(final InsertStatement insertStatement); static Optional<SetAssignmentSegment> getSetAssignmentSegment(final InsertStatement insertStatement); static Optional<WithSegment> getWithSegment(final InsertStatement insertStatement); static Optional<OutputSegment> getOutputSegment(final InsertStatement insertStatement);  }
@Test public void assertGetWithSegmentWithWithSegmentForPostgreSQL() { PostgreSQLInsertStatement insertStatement = new PostgreSQLInsertStatement(); insertStatement.setWithSegment(new WithSegment(0, 0, Collections.emptyList())); Optional<WithSegment> withSegment = InsertStatementHandler.getWithSegment(insertStatement); assertTrue(withSegment.isPresent()); }
@Test public void assertGetWithSegmentWithoutWithSegmentForPostgreSQL() { PostgreSQLInsertStatement insertStatement = new PostgreSQLInsertStatement(); Optional<WithSegment> withSegment = InsertStatementHandler.getWithSegment(insertStatement); assertFalse(withSegment.isPresent()); }
@Test public void assertGetWithSegmentWithWithSegmentForSQLServer() { SQLServerInsertStatement insertStatement = new SQLServerInsertStatement(); insertStatement.setWithSegment(new WithSegment(0, 0, Collections.emptyList())); Optional<WithSegment> withSegment = InsertStatementHandler.getWithSegment(insertStatement); assertTrue(withSegment.isPresent()); }
@Test public void assertGetWithSegmentWithoutWithSegmentForSQLServer() { SQLServerInsertStatement insertStatement = new SQLServerInsertStatement(); Optional<WithSegment> withSegment = InsertStatementHandler.getWithSegment(insertStatement); assertFalse(withSegment.isPresent()); }