use of org.apache.ibatis.session.SqlSession in project HackTutorial by linrongbin16.
the class App method insertUser.
private void insertUser(String firstNname, String lastName, String email, Integer age) {
SqlSession sqlSession = null;
User u = new User(-1, firstNname, lastName, email, age);
try {
sqlSession = sqlSessionFactory.openSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
int result = mapper.insert(u);
sqlSession.commit();
logger.info("insert success, result:{}, User:{}", result, u);
} catch (Exception ex) {
logger.info("insert exception, exception:{}, User:{}", ex, u);
if (sqlSession != null) {
sqlSession.rollback();
}
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
}
use of org.apache.ibatis.session.SqlSession in project HackTutorial by linrongbin16.
the class App method findUserById.
private void findUserById(int id) {
SqlSession sqlSession = null;
User user = null;
try {
sqlSession = sqlSessionFactory.openSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
user = mapper.findUserById(id);
} catch (Exception ex) {
logger.info("findUserById exception, id:{}, exception:{}", id, ex);
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
if (user == null) {
logger.info("findUserById fail, id {} not exist", id);
} else {
logger.info("findUserById success, User: {}", user);
}
}
use of org.apache.ibatis.session.SqlSession in project HackTutorial by linrongbin16.
the class App method deleteUserById.
private void deleteUserById(int id) {
SqlSession sqlSession = null;
int result = 0;
try {
sqlSession = sqlSessionFactory.openSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
result = mapper.delete(id);
sqlSession.commit();
} catch (Exception ex) {
logger.info("deleteUserById exception, id:{}, exception:{}", id, ex);
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
if (result <= 0) {
logger.info("deleteUserById fail, id {} not exist, result:{}", id, result);
} else {
logger.info("deleteUserById success, result:{}", result);
}
}
use of org.apache.ibatis.session.SqlSession in project taskana by Taskana.
the class CreateTaskAccTest method testCreateExternalTaskWithAttachment.
@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testCreateExternalTaskWithAttachment() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException, ConcurrencyException {
TaskService taskService = taskanaEngine.getTaskService();
Task newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
newTask.setClassificationKey("L12010");
Map<String, String> customAttributesForCreate = createSimpleCustomProperties(27);
newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", customAttributesForCreate));
newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
Task createdTask = taskService.createTask(newTask);
assertNotNull(createdTask.getId());
assertThat(createdTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
// verify that the database content is as expected
TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest((TaskanaEngineImpl) taskanaEngine);
try {
SqlSession session = engineProxy.getSqlSession();
AttachmentMapper mapper = session.getMapper(AttachmentMapper.class);
engineProxy.openConnection();
String customProperties = mapper.getCustomAttributesAsString(createdTask.getAttachments().get(0).getId());
assertTrue(customProperties.contains("\"Property_26\":\"Property Value of Property_26\""));
assertTrue(customProperties.contains("\"Property_25\":\"Property Value of Property_25\""));
assertTrue(customProperties.contains("\"Property_21\":\"Property Value of Property_21\""));
assertTrue(customProperties.contains("\"Property_19\":\"Property Value of Property_19\""));
assertTrue(customProperties.contains("\"Property_16\":\"Property Value of Property_16\""));
assertTrue(customProperties.contains("\"Property_12\":\"Property Value of Property_12\""));
assertTrue(customProperties.contains("\"Property_11\":\"Property Value of Property_11\""));
assertTrue(customProperties.contains("\"Property_7\":\"Property Value of Property_7\""));
assertTrue(customProperties.contains("\"Property_6\":\"Property Value of Property_6\""));
} finally {
engineProxy.returnConnection();
}
Task readTask = taskService.getTask(createdTask.getId());
assertNotNull(readTask);
assertThat(readTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
assertNotNull(readTask.getAttachments());
assertEquals(1, readTask.getAttachments().size());
assertNotNull(readTask.getAttachments().get(0).getCreated());
assertNotNull(readTask.getAttachments().get(0).getModified());
assertEquals(readTask.getAttachments().get(0).getCreated(), readTask.getAttachments().get(0).getModified());
assertNotNull(readTask.getAttachments().get(0).getClassificationSummary());
assertNotNull(readTask.getAttachments().get(0).getObjectReference());
// verify that the map is correctly retrieved from the database
Map<String, String> customAttributesFromDb = readTask.getAttachments().get(0).getCustomAttributes();
assertNotNull(customAttributesFromDb);
assertTrue(customAttributesFromDb.equals(customAttributesForCreate));
}
use of org.apache.ibatis.session.SqlSession in project camunda-bpm-platform by camunda.
the class JobMigrationScenario method triggerEntryCriterion.
@DescribesScenario("createJob")
public static ScenarioSetup triggerEntryCriterion() {
return new ScenarioSetup() {
public void execute(ProcessEngine engine, final String scenarioName) {
final ProcessEngineConfigurationImpl engineConfiguration = (ProcessEngineConfigurationImpl) engine.getProcessEngineConfiguration();
CommandExecutor commandExecutor = engineConfiguration.getCommandExecutorTxRequired();
// create a job with the scenario name as id and a null suspension state
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try {
SqlSession sqlSession = commandContext.getDbSqlSession().getSqlSession();
connection = sqlSession.getConnection();
statement = connection.createStatement();
statement.executeUpdate("INSERT INTO ACT_RU_JOB(ID_, REV_, RETRIES_, TYPE_, EXCLUSIVE_, HANDLER_TYPE_) " + "VALUES (" + "'" + scenarioName + "'," + "1," + "3," + "'timer'," + DbSqlSessionFactory.databaseSpecificTrueConstant.get(engineConfiguration.getDatabaseType()) + "," + "'" + TimerStartEventJobHandler.TYPE + "'" + ")");
connection.commit();
statement.close();
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
if (statement != null) {
statement.close();
}
if (rs != null) {
rs.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return null;
}
});
}
};
}
Aggregations