Example usage for org.apache.ibatis.session SqlSession rollback

List of usage examples for org.apache.ibatis.session SqlSession rollback

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession rollback.

Prototype

void rollback();

Source Link

Document

Discards pending batch statements and rolls database connection back.

Usage

From source file:net.cbtltd.server.PartyService.java

/**
 * Executes the ActorRead action to read an actor Party instance.
 *
 * @param sqlSession the current SQL session.
 * @param action the action to be executed.
 * @return the response.//from  w w w  .j av  a  2 s.c  o  m
 */
public final Party execute(SqlSession sqlSession, ActorRead action) {
    Party party = null;
    try {
        party = sqlSession.getMapper(PartyMapper.class).read(action.getId());
        party.setRoles(RelationService.read(sqlSession, Relation.PARTY_ROLE, party.getId(), null));
    } catch (Throwable x) {
        sqlSession.rollback();
        LOG.error(x.getMessage());
    }
    return party;
}

From source file:net.cbtltd.server.PartyService.java

/**
 * Executes the ActorUpdate action to update an actor Party instance.
 *
 * @param sqlSession the current SQL session.
 * @param action the action to be executed.
 * @return the response.//from  w  w  w.  j  a  v a  2  s.c om
 */
public final Party execute(SqlSession sqlSession, ActorUpdate action) {
    try {
        if (action.hasPassword()) {
            String password = Party.decrypt(action.getPassword());
            action.setPassword(BCrypt.hashpw(password, BCrypt.gensalt()));
        } else {
            action.setPassword(null);
        }
        sqlSession.getMapper(PartyMapper.class).update(action);
        RelationService.create(sqlSession, Relation.ORG_PARTY_ + Party.Type.Actor.name(),
                action.getOrganizationid(), action.getId());
        RelationService.replace(sqlSession, Relation.PARTY_ROLE, action.getId(), action.getRoles());
        MonitorService.update(sqlSession, Data.Origin.CONSOLE, NameId.Type.Party, action);
    } catch (Throwable x) {
        sqlSession.rollback();
        LOG.error(x.getMessage());
    }
    return action;
}

From source file:net.cbtltd.server.PartyService.java

/**
 * Executes the ActorDelete action to delete an actor Party instance.
 * This deletes the actor roles.//ww w . j a v  a  2s. c om
 *
 * @param sqlSession the current SQL session.
 * @param action the action to be executed.
 * @return the response.
 */
public final Party execute(SqlSession sqlSession, ActorDelete action) {
    try {
        if (action.getOrganizationid().equalsIgnoreCase(action.getEmployerid())) {
            action.setEmployerid(Model.ZERO);
            sqlSession.getMapper(PartyMapper.class).update(action);
        }
        RelationService.delete(sqlSession, Relation.ORG_PARTY_ + Party.Type.Actor.name(),
                action.getOrganizationid(), action.getId());
        RelationService.delete(sqlSession, Relation.PARTY_ROLE, action.getId(), null);
    } catch (Throwable x) {
        sqlSession.rollback();
        LOG.error(x.getMessage());
    }
    return null;
}

From source file:net.cbtltd.server.PartyService.java

/**
 * Executes the PartyLicense action to check the party license and reinstate if OK.
 *
 * @param sqlSession the current SQL session.
 * @param action the action to be executed.
 * @return the response./*from w  ww .ja v a 2s.c om*/
 */
public final Party execute(SqlSession sqlSession, PartyLicense action) {
    try {
        LicenseService.check(sqlSession, action.getId());
    } catch (Throwable x) {
        sqlSession.rollback();
        LOG.error(x.getMessage());
    }
    return action;
}

From source file:net.cbtltd.server.PartyService.java

/**
 * Executes the PartyCreate action to create a Party instance.
 *
 * @param sqlSession the current SQL session.
 * @param action the action to be executed.
 * @return the response.//  w w w  .ja v a  2  s . co  m
 */
public final Party execute(SqlSession sqlSession, PartyCreate action) {
    LOG.debug("PartyCreate " + action);
    Party exists = null;
    try {
        exists = sqlSession.getMapper(PartyMapper.class).readbyemailaddress(action.getEmailaddress());
        if (exists == null) {
            sqlSession.getMapper(PartyMapper.class).create(action);
            action.setContractText(Party.getContractText(action.getId(), Language.EN));
            action.setPrivateText(action.getOrganizationid(),
                    Party.getPrivateText(action.getOrganizationid(), action.getId(), Language.EN));
            action.setPublicText(Party.getPublicText(action.getId(), Language.EN));
            exists = action;
        } else {
            exists.setState(action.getState());
        }
        RelationService.create(sqlSession, Relation.ORG_PARTY_ + action.getType(), action.getOrganizationid(),
                action.getId());
    } catch (Throwable x) {
        sqlSession.rollback();
        LOG.error(x.getMessage());
    }
    return exists;
}

From source file:net.cbtltd.server.PartyService.java

/**
 * Executes the PartyCreator action to create an affiliate Party instance.
 *
 * @param sqlSession the current SQL session.
 * @param action the action to be executed.
 * @return the response./*w ww .  j  a va2s  .c o m*/
 */
public final Party execute(SqlSession sqlSession, PartyCreator action) {
    try {
        RelationService.create(sqlSession, Relation.PARTY_CREATOR, action.getCreatorid(),
                action.getEmailaddress());
        EmailService.partyCreator(sqlSession, action);
    } catch (Throwable x) {
        sqlSession.rollback();
        LOG.error(x.getMessage());
    }
    return action;
}

From source file:net.cbtltd.server.PartyService.java

private final Party partyRead(SqlSession sqlSession, String organizationid, String partyid) {
    LOG.debug("\npartyRead " + organizationid + ", " + partyid);
    Party party = null;/*w  w  w.j  a v  a 2s  . c o  m*/
    try {
        party = sqlSession.getMapper(PartyMapper.class).read(partyid);
        if (party != null) {
            party.setImageurls(sqlSession.getMapper(TextMapper.class)
                    .imageidsbynameid(new NameId(NameId.Type.Party.name(), partyid)));
            party.setRoles(RelationService.read(sqlSession, Relation.PARTY_ROLE, partyid, null));
            party.setValues(RelationService.read(sqlSession, Relation.PARTY_VALUE, partyid, null));
            party.setTypes(getTypes(sqlSession, organizationid, partyid));
            party.setOrganization(RelationService.read(sqlSession,
                    Relation.ORG_PARTY_ + Party.Type.Organization.name(), organizationid, partyid) != null);
            party.setAgent(RelationService.read(sqlSession, Relation.ORG_PARTY_ + Party.Type.Agent.name(),
                    organizationid, partyid) != null);
        }
    } catch (Throwable x) {
        sqlSession.rollback();
        LOG.error(x.getMessage());
    }
    LOG.debug("partyRead " + party);
    return party;
}

From source file:net.cbtltd.server.PartyService.java

/**
 * Executes the PartyUpdate action to update a Party instance.
 *
 * @param sqlSession the current SQL session.
 * @param action the action to be executed.
 * @return the response.//  ww  w .j a va  2s  . c  o m
 */
public final Party execute(SqlSession sqlSession, PartyUpdate action) {
    LOG.debug("PartyUpdate in " + action);
    try {
        if (action.hasPassword()) {
            String password = Party.decrypt(action.getPassword());
            action.setPassword(BCrypt.hashpw(password, BCrypt.gensalt()));
        } else {
            action.setPassword(null);
        }
        if (action.hasState(Party.FINAL)) {
            action.setState(Party.CREATED);
        }
        if (action.hasType(Party.Type.Affiliate.name())) {
            EmailService.affiliate(action);
        }
        sqlSession.getMapper(PartyMapper.class).update(action);
        if (action.hasValues()) {
            RelationService.replace(sqlSession, Relation.PARTY_VALUE, action.getId(), action.getValues());
        }

        Party.Type[] values = Party.Type.values();
        for (Party.Type value : values) {
            RelationService.delete(sqlSession, Relation.ORG_PARTY_ + value.name(), action.getOrganizationid(),
                    action.getId());
        }
        for (String type : action.getTypes()) {
            RelationService.create(sqlSession, Relation.ORG_PARTY_ + type, action.getOrganizationid(),
                    action.getId());
        }

        TextService.update(sqlSession, action.getTexts());
        MonitorService.update(sqlSession, Data.Origin.CONSOLE, NameId.Type.Party, action);
    } catch (Throwable x) {
        sqlSession.rollback();
        LOG.error(x.getMessage());
    }
    LOG.debug("PartyUpdate out " + action);
    return action;
}

From source file:net.cbtltd.server.PartyService.java

/**
 * Executes the PartyDelete action to delete a Party instance.
 * This deletes the relation between the party and the current organization, not the party instance.
 *
 * @param sqlSession the current SQL session.
 * @param action the action to be executed.
 * @return the response./*www .j  a v  a  2  s .co m*/
 */
public final Party execute(SqlSession sqlSession, PartyDelete action) {
    try {
        if (action.getOrganizationid().equalsIgnoreCase(action.getEmployerid())) {
            action.setEmployerid(Model.ZERO);
            sqlSession.getMapper(PartyMapper.class).update(action);
        }
        for (String type : action.getTypes()) {
            RelationService.delete(sqlSession, Relation.ORG_PARTY_ + type, action.getOrganizationid(),
                    action.getId());
        }

        //         RelationService.delete(sqlSession, Relation.ORGANIZATION_PARTY, action.getOrganizationid(), action.getId());
    } catch (Throwable x) {
        sqlSession.rollback();
        LOG.error(x.getMessage());
    }
    return null;
}

From source file:net.cbtltd.server.PartyService.java

/**
 * Executes the NameIdAction action to read a list of party NameId instances.
 *
 * @param sqlSession the current SQL session.
 * @param action the action to be executed.
 * @return the response.//w w w . java2s .  c o  m
 */
public final Table<NameId> execute(SqlSession sqlSession, NameIdAction action) {
    LOG.debug("NameIdAction " + action);
    Table<NameId> table = new Table<NameId>();
    try {
        if (action.isSuggested()) {
            table.setValue(sqlSession.getMapper(PartyMapper.class).nameidbyid(action));
        } else {
            table.setValue(sqlSession.getMapper(PartyMapper.class).nameidbyname(action));
        }
    } catch (Throwable x) {
        sqlSession.rollback();
        LOG.error(x.getMessage());
    }
    LOG.debug("NameIdAction " + table);
    return table;
}