org.jdbi.v3.sqlobject.transaction.Transaction Java Examples
The following examples show how to use
org.jdbi.v3.sqlobject.transaction.Transaction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestcaseRunDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default void insert(TestcaseRun testcaseRun) throws JsonProcessingException { long id = _insert(testcaseRun.getTestcaseId(), testcaseRun.getTestcaseName(), testcaseRun.getTestcaseFolderPath(), testcaseRun.getStartTime(), testcaseRun.getDuration(), testcaseRun.getResult().toString()); testcaseRun.setId(id); if (testcaseRun instanceof RegularTestcaseRun) { RegularTestcaseRun regularTestcaseRun = (RegularTestcaseRun) testcaseRun; for (TeststepRun teststepRun: regularTestcaseRun.getStepRuns()) { teststepRunDAO().insert(id, null, teststepRun); } } else if (testcaseRun instanceof DataDrivenTestcaseRun) { DataDrivenTestcaseRun dataDrivenTestcaseRun = (DataDrivenTestcaseRun) testcaseRun; for (TestcaseIndividualRun testcaseIndividualRun: dataDrivenTestcaseRun.getIndividualRuns()) { testcaseIndividualRunDAO().insert(id, testcaseIndividualRun); } } }
Example #2
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default void duplicateByTestcase(long sourceTestcaseId, long newTestcaseId) { List<Long> oldTeststepIds = findIdsByTestcaseId(sourceTestcaseId); for (long oldTeststepId : oldTeststepIds) { long newTeststepId = duplicateById(oldTeststepId, newTestcaseId); // duplicate endpoint if needed Long newEndpointId = endpointDAO().duplicateUnmanagedEndpoint(oldTeststepId); if (newEndpointId != null) { updateEndpointIdByIdForDuplication(newTeststepId, newEndpointId); } // duplicate assertions assertionDAO().duplicateByTeststep(oldTeststepId, newTeststepId); // duplicate property extractors propertyExtractorDAO().duplicateByTeststep(oldTeststepId, newTeststepId); } }
Example #3
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default Teststep saveApiRequestFile(long teststepId, String fileName, InputStream inputStream) throws IOException { Teststep teststep = findById_Complete(teststepId); if (Teststep.TYPE_FTP.equals(teststep.getType())) { FtpPutRequestFileFromFile putRequest = (FtpPutRequestFileFromFile) teststep.getApiRequest(); putRequest.setFileName(fileName); byte[] fileBytes; try { fileBytes = IOUtils.toByteArray(inputStream); } finally { inputStream.close(); } putRequest.setFileContent(fileBytes); saveApiRequest(teststepId, new ObjectMapper().writeValueAsString(putRequest)); } return findById_Complete(teststepId); }
Example #4
Source File: DataTableColumnDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default void moveInTestcase(long testcaseId, short fromSequence, short toSequence) { if (fromSequence != toSequence) { long draggedColumnId = findBySequence(testcaseId, fromSequence).getId(); // shelve the dragged column first updateSequenceById(draggedColumnId, (short) -1); if (fromSequence < toSequence) { batchMove(testcaseId, (short) (fromSequence + 1), toSequence, "left"); } else { batchMove(testcaseId, toSequence, (short) (fromSequence - 1), "right"); } // move the dragged column last updateSequenceById(draggedColumnId, toSequence); } }
Example #5
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default void moveInTestcase(long testcaseId, short fromSequence, short toSequence) { if (fromSequence != toSequence) { long draggedStepId = findIdBySequence(testcaseId, fromSequence); // shelve the dragged step first updateSequenceById(draggedStepId, (short) -1); if (fromSequence < toSequence) { batchMove(testcaseId, (short) (fromSequence + 1), toSequence, STEP_MOVE_DIRECTION_UP); } else { batchMove(testcaseId, toSequence, (short) (fromSequence - 1), STEP_MOVE_DIRECTION_DOWN); } // move the dragged step last updateSequenceById(draggedStepId, toSequence); } }
Example #6
Source File: TestcaseDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default Testcase findById_Complete(long id) { Testcase result = _findById(id); result.setFolderPath(getFolderPath(id)); List<UserDefinedProperty> udps = udpDAO().findByTestcaseId(id); result.setUdps(udps); List<Teststep> teststeps = teststepDAO().findByTestcaseId_Complete(id); result.setTeststeps(teststeps); DataTable dataTable = dataTableDAO().getTestcaseDataTable(id, false); result.setDataTable(dataTable); List<HTTPStubMapping> httpStubMappings = httpStubMappingDAO().findByTestcaseId(id); result.setHttpStubMappings(httpStubMappings); return result; }
Example #7
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default void updateAssertions(Teststep teststep) { AssertionDAO assertionDAO = assertionDAO(); List<Long> newAssertionIds = new ArrayList<>(); for (Assertion assertion: teststep.getAssertions()) { if (assertion.getId() == null) { // insert the assertion assertion.setTeststepId(teststep.getId()); newAssertionIds.add(assertionDAO.insert(assertion)); } else { // update the assertion newAssertionIds.add(assertion.getId()); assertionDAO.update(assertion); } } // delete assertions whose id is not in the newAssertionIds list; // if newAssertionIds list is empty, delete all assertions newAssertionIds.add(-1L); assertionDAO.deleteByTeststepIdIfIdNotIn(teststep.getId(), newAssertionIds); }
Example #8
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default void insertByImport(Teststep teststep) throws JsonProcessingException { Long endpointId = null; if (teststep.getEndpoint() != null) { endpointId = endpointDAO().insertUnmanagedEndpoint(teststep.getEndpoint()); } String requestString = (String) teststep.getRequest(); byte[] request = null; if (requestString != null) { request = teststep.getRequestType() == TeststepRequestType.FILE ? Base64.getDecoder().decode(requestString) : requestString.getBytes(); } String apiRequestJSONString = new ObjectMapper().writeValueAsString(teststep.getApiRequest()); long teststepId = _insertWithName(teststep, request, teststep.getRequestType().toString(), apiRequestJSONString, endpointId); for (Assertion assertion : teststep.getAssertions()) { assertion.setTeststepId(teststepId); assertionDAO().insert(assertion); } for (PropertyExtractor propertyExtractor: teststep.getPropertyExtractors()) { propertyExtractorDAO().insert(teststepId, propertyExtractor); } }
Example #9
Source File: UserDefinedPropertyDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default void moveInTestcase(long testcaseId, short fromSequence, short toSequence) { if (fromSequence != toSequence) { long draggedUDPId = findBySequence(testcaseId, fromSequence).getId(); // shelve the dragged UDP first updateSequenceById(draggedUDPId, (short) -1); if (fromSequence < toSequence) { batchMove(testcaseId, (short) (fromSequence + 1), toSequence, "up"); } else { batchMove(testcaseId, toSequence, (short) (fromSequence - 1), "down"); } // move the dragged UDP last updateSequenceById(draggedUDPId, toSequence); } }
Example #10
Source File: FolderTreeNodeDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default FolderTreeNode insert(FolderTreeNode node) { if (node.getType() == FolderTreeNodeType.TESTCASE) { Testcase testcase = new Testcase(); testcase.setParentFolderId(node.getParentFolderId()); testcase = testcaseDAO().insert(testcase); dataTableDAO().createCaptionColumn(testcase.getId()); node.setIdPerType(testcase.getId()); node.setText(testcase.getName()); } else if (node.getType() == FolderTreeNodeType.FOLDER) { Folder folder = folderDAO().insert(node.getParentFolderId()); node.setIdPerType(folder.getId()); node.setText(folder.getName()); } return node; }
Example #11
Source File: HTTPStubMappingDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default void moveInTestcase(long testcaseId, short fromNumber, short toNumber) { if (fromNumber != toNumber) { long draggedStubId = findByNumber(testcaseId, fromNumber).getId(); // shelve the dragged stub first updateNumberById(draggedStubId, (short) -1); if (fromNumber < toNumber) { batchMove(testcaseId, (short) (fromNumber + 1), toNumber, "up"); } else { batchMove(testcaseId, toNumber, (short) (fromNumber - 1), "down"); } // move the dragged stub last updateNumberById(draggedStubId, toNumber); } }
Example #12
Source File: DataTableDAO.java From irontest with Apache License 2.0 | 6 votes |
@Transaction default void duplicateByTestcase(long sourceTestcaseId, long targetTestcaseId) { dataTableColumnDAO().duplicateByTestcase(sourceTestcaseId, targetTestcaseId); List<DataTableColumn> sourceColumns = dataTableColumnDAO().findByTestcaseId(sourceTestcaseId); List<DataTableColumn> targetColumns = dataTableColumnDAO().findByTestcaseId(targetTestcaseId); for (DataTableColumn targetColumn: targetColumns) { long sourceColumnId = -1; for (DataTableColumn sourceColumn: sourceColumns) { if (sourceColumn.getName().equals(targetColumn.getName())) { sourceColumnId = sourceColumn.getId(); break; } } dataTableCellDAO().duplicateByColumn(sourceColumnId, targetColumn.getId()); } }
Example #13
Source File: UserDefinedPropertyDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default UserDefinedProperty insert(long testcaseId) { long id = _insertWithoutName(testcaseId); String name = "P" + id; updateNameForInsert(id, name); return findById(id); }
Example #14
Source File: DataTableCellDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default void insert(long columnId, DataTableCell cell) { Long endpointId = null; if (cell.getEndpoint() != null) { endpointId = endpointDAO().insertUnmanagedEndpoint(cell.getEndpoint()); } _insert(columnId, cell, endpointId); }
Example #15
Source File: TestcaseDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default long createByImport(Testcase testcase, long targetFolderId) throws JsonProcessingException { if (_nameExistsInFolder(testcase.getName(), targetFolderId)) { throw new RuntimeException("Duplicate test case name: " + testcase.getName()); } // insert the test case record testcase.setParentFolderId(targetFolderId); long testcaseId = _insertWithName(testcase); // insert UDPs for (UserDefinedProperty udp: testcase.getUdps()) { udpDAO()._insertWithName(testcaseId, udp.getName(), udp.getValue()); } // insert test steps for (Teststep teststep : testcase.getTeststeps()) { teststep.setTestcaseId(testcaseId); teststepDAO().insertByImport(teststep); } // insert data table dataTableDAO().insertByImport(testcaseId, testcase.getDataTable()); // insert HTTP stubs for (HTTPStubMapping stub: testcase.getHttpStubMappings()) { httpStubMappingDAO().insertByImport(testcaseId, stub); } return testcaseId; }
Example #16
Source File: TestcaseDAO.java From irontest with Apache License 2.0 | 5 votes |
/** * Clone/copy test case in the same system database. * @param sourceTestcaseId id of the test case to be cloned * @param targetFolderId id of the folder in which the new test case will be created * @return ID of the new test case */ @Transaction default long duplicate(long sourceTestcaseId, long targetFolderId) { Testcase oldTestcaseRecord = _findById(sourceTestcaseId); // resolve new test case name String newTestcaseName = oldTestcaseRecord.getName(); if (oldTestcaseRecord.getParentFolderId() == targetFolderId) { int copyIndex = 1; newTestcaseName = oldTestcaseRecord.getName() + " - Copy"; while (_nameExistsInFolder(newTestcaseName, targetFolderId)) { copyIndex++; newTestcaseName = oldTestcaseRecord.getName() + " - Copy (" + copyIndex + ")"; } } // duplicate the test case record long newTestcaseId = duplicateById(newTestcaseName, targetFolderId, sourceTestcaseId); // duplicate user defined properties udpDAO().duplicateByTestcase(sourceTestcaseId, newTestcaseId); // duplicate test steps teststepDAO().duplicateByTestcase(sourceTestcaseId, newTestcaseId); // duplicate data table dataTableDAO().duplicateByTestcase(sourceTestcaseId, newTestcaseId); // duplicate HTTP stubs httpStubMappingDAO().duplicateByTestcase(sourceTestcaseId, newTestcaseId); return newTestcaseId; }
Example #17
Source File: DataTableDAO.java From irontest with Apache License 2.0 | 5 votes |
/** * @param testcaseId * @param fetchFirstRowOnly if true, only the first data table row (if exists) will be fetched; if false, all rows will be fetched. * @return */ @Transaction default DataTable getTestcaseDataTable(long testcaseId, boolean fetchFirstRowOnly) { DataTable dataTable = new DataTable(); List<DataTableColumn> columns = dataTableColumnDAO().findByTestcaseId(testcaseId); // populate the data table rows Java model column by column List<LinkedHashMap<String, DataTableCell>> rows = new ArrayList<>(); Map<Short, LinkedHashMap<String, DataTableCell>> rowSequenceMap = new HashMap<>(); // map rowSequence to row object (because rowSequence is not consecutive) for (DataTableColumn column: columns) { List<DataTableCell> cellsInColumn = dataTableCellDAO().findByColumnId(column.getId()); for (DataTableCell cellInColumn: cellsInColumn) { short rowSequence = cellInColumn.getRowSequence(); if (column.getType() != DataTableColumnType.STRING && cellInColumn.getEndpoint() != null) { cellInColumn.setEndpoint(endpointDAO().findById(cellInColumn.getEndpoint().getId())); } if (!rowSequenceMap.containsKey(rowSequence)) { LinkedHashMap<String, DataTableCell> row = new LinkedHashMap<>(); rowSequenceMap.put(rowSequence, row); rows.add(row); } rowSequenceMap.get(rowSequence).put(column.getName(), cellInColumn); if (fetchFirstRowOnly && rows.size() == 1) { break; } } } if (columns.size() > 0) { dataTable = new DataTable(); dataTable.setColumns(columns); dataTable.setRows(rows); } return dataTable; }
Example #18
Source File: TestcaseDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default Testcase findById_TestcaseEditView(long id) { Testcase result = _findById(id); if (result != null) { List<Teststep> teststeps = teststepDAO().findByTestcaseId_TestcaseEditView(id); result.setTeststeps(teststeps); } return result; }
Example #19
Source File: DataTableDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default void insertByImport(long testcaseId, DataTable dataTable) throws JsonProcessingException { for (DataTableColumn column: dataTable.getColumns()) { long columnId = dataTableColumnDAO().insert(testcaseId, column.getName(), column.getType().toString()); for (LinkedHashMap<String, DataTableCell> row: dataTable.getRows()) { for (Map.Entry<String, DataTableCell> cellEntry: row.entrySet()) { if (cellEntry.getKey().equals(column.getName())) { dataTableCellDAO().insert(columnId, cellEntry.getValue()); break; } } } } }
Example #20
Source File: DataTableColumnDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default void insert(long testcaseId, String columnType) { long id = _insert(testcaseId, columnType); String name = "COL" + id; updateNameForInsert(id, name); dataTableCellDAO().insertCellsForNewColumn(testcaseId, id); }
Example #21
Source File: TempPasswordDao.java From triplea with GNU General Public License v3.0 | 5 votes |
@Transaction default boolean insertTempPassword( final String username, final String email, final String password) { return lookupUserIdByUsernameAndEmail(username, email) .map( userId -> { invalidateTempPasswords(username); insertPassword(userId, password); return true; }) .orElse(false); }
Example #22
Source File: TeamSqlObject.java From jdit with MIT License | 5 votes |
@Transaction default void addTeam(Team team, List<Player> players) { long teamId = createTeam(team.name, team.division); for (Player player : players) { long playerId = playerDao().createPlayer(player); addPlayerToTeam(teamId, playerId); } }
Example #23
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default Teststep setRequestFile(long teststepId, String fileName, InputStream inputStream) throws IOException { byte[] fileBytes; try { fileBytes = IOUtils.toByteArray(inputStream); } finally { inputStream.close(); } _setRequestFile(teststepId, fileBytes, TeststepRequestType.FILE.toString(), fileName); return findById_NoRequest(teststepId); }
Example #24
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default Teststep findById_Complete(long id) { Teststep teststep = _findById_Complete(id); if (teststep != null) { populateTeststepWithOtherDetails(teststep); } return teststep; }
Example #25
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default Teststep findById_NoRequest(long id) { Teststep teststep = _findById_NoRequest(id); if (teststep != null) { populateTeststepWithOtherDetails(teststep); } return teststep; }
Example #26
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default void populateTeststepWithOtherDetails(Teststep teststep) { Endpoint endpoint = endpointDAO().findById(teststep.getEndpoint().getId()); teststep.setEndpoint(endpoint); teststep.setAssertions(assertionDAO().findByTeststepId(teststep.getId())); teststep.setPropertyExtractors(propertyExtractorDAO().findByTeststepId(teststep.getId())); }
Example #27
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default void deleteById(long id) { Teststep teststep = findById_NoRequest(id); _deleteById(id); // decrement sequence number of all next test steps batchMove(teststep.getTestcaseId(), (short) (teststep.getSequence() + 1), Short.MAX_VALUE, STEP_MOVE_DIRECTION_UP); Endpoint endpoint = teststep.getEndpoint(); if (endpoint != null && !endpoint.isManaged()) { // delete the teststep's endpoint if it exists and is unmanaged endpointDAO().deleteById(endpoint.getId()); } }
Example #28
Source File: TeststepDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default void update(Teststep teststep) throws Exception { Teststep oldTeststep = findById_NoRequest(teststep.getId()); // old request is not read into memory, to save memory switch (teststep.getType()) { case Teststep.TYPE_HTTP: processHTTPTeststepBackupRestore(oldTeststep, teststep); break; case Teststep.TYPE_FTP: processFTPTeststep(oldTeststep, teststep); break; case Teststep.TYPE_DB: processDBTeststep(teststep); break; case Teststep.TYPE_MQ: processMQTeststep(oldTeststep, teststep); break; default: break; } Endpoint oldEndpoint = oldTeststep.getEndpoint(); Endpoint newEndpoint = teststep.getEndpoint(); Long newEndpointId = newEndpoint == null ? null : newEndpoint.getId(); if (teststep.getRequestType() == TeststepRequestType.FILE) { // update teststep without file request (this can save memory, as file could be big) _updateWithoutRequest(teststep, teststep.getRequestType().toString(), newEndpointId); } else { // update teststep with string request Object request = teststep.getRequest() == null ? null : ((String) teststep.getRequest()).getBytes(); String apiRequest = new ObjectMapper().writeValueAsString(teststep.getApiRequest()); _updateWithStringRequest(teststep, request, teststep.getRequestType().toString(), apiRequest, newEndpointId); } updateEndpointIfExists(oldEndpoint, newEndpoint); updateAssertions(teststep); }
Example #29
Source File: TestcaseIndividualRunDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default List<TestcaseIndividualRun> findByTestcaseRunId(long testcaseRunId) { List<TestcaseIndividualRun> individualRuns = _findByTestcaseRunId(testcaseRunId); for (TestcaseIndividualRun individualRun: individualRuns) { individualRun.setStepRuns(teststepRunDAO().findByTestcaseIndividualRunId(individualRun.getId())); } return individualRuns; }
Example #30
Source File: TestcaseIndividualRunDAO.java From irontest with Apache License 2.0 | 5 votes |
@Transaction default void insert(long testcaseRunId, TestcaseIndividualRun testcaseIndividualRun) throws JsonProcessingException { long id = _insert(testcaseRunId, testcaseIndividualRun.getCaption(), testcaseIndividualRun.getStartTime(), testcaseIndividualRun.getDuration(), testcaseIndividualRun.getResult().toString()); for (TeststepRun teststepRun: testcaseIndividualRun.getStepRuns()) { teststepRunDAO().insert(testcaseRunId, id, teststepRun); } }