Example usage for org.hibernate Criteria createCriteria

List of usage examples for org.hibernate Criteria createCriteria

Introduction

In this page you can find the example usage for org.hibernate Criteria createCriteria.

Prototype

public Criteria createCriteria(String associationPath) throws HibernateException;

Source Link

Document

Create a new Criteria, "rooted" at the associated entity.

Usage

From source file:com.mx.teknei.pcabordo.lib.dao.impl.RecpNavDAO.java

@Override
public SfmoReceNave findByIdVehi(int idVehi) {
    SfmoReceNave recpnav = null;//w w w  .  ja  v  a 2  s. co m
    Transaction trans = null;
    Session session = null;
    try {
        session = LoadConnection.getSessionFactory().openSession();
    } catch (ExceptionInInitializerError eiie) {
        System.out.println("Error al iniciar la coneccion a BD postgres:" + eiie.getMessage());
    } catch (Exception e) {
        System.err.println("Error en LoadConnection." + e.getMessage());
    }
    try {
        trans = session.beginTransaction();
        Criteria crit = session.createCriteria(SfmoReceNave.class);
        Criteria vehi = crit.createCriteria("sfvhVehi");
        vehi.add(Restrictions.eq("idVehi", idVehi));
        recpnav = (SfmoReceNave) crit.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        trans.commit();
        session.flush();
        session.close();
    }

    return recpnav;
}

From source file:com.netspective.medigy.service.party.TestAddContactMechanismService.java

License:Open Source License

public void testAddPostalAddress() throws Exception {
    // the dataset inserted this person
    final Person p = (Person) HibernateUtil.getSession().load(Person.class, new Long(2));
    assertEquals(p.getPartyContactMechanisms().size(), 0);

    final NewPostalAddress address = service.addPostalAddress(new AddPostalAddressParameters() {
        public Serializable getPartyId() {
            return p.getPartyId();
        }/* ww  w. j a  v a2s.c o  m*/

        public String getStreet1() {
            return "123 Acme Road";
        }

        public String getStreet2() {
            return "Suite 100";
        }

        public String getCity() {
            return "Fairfax";
        }

        public String getState() {
            return "VA";
        }

        public String getProvince() {
            return null;
        }

        public String getPostalCode() {
            return "22033";
        }

        public String getCounty() {
            return "Fairfax County";
        }

        public String getCountry() {
            return "USA";
        }

        public String getPurpose() {
            return ContactMechanismPurposeType.Cache.HOME_ADDRESS.getCode();
        }
    });

    // first check the relationship table between the actual contact mechanism and the party
    Criteria criteria = HibernateUtil.getSession().createCriteria(PartyContactMechanism.class);
    criteria.createCriteria("party").add(Restrictions.eq("partyId", p.getPartyId()));
    List partyContactMechList = criteria.list();
    Object[] objects = partyContactMechList.toArray();
    for (int i = 0; i < objects.length; i++) {
        log.info(((PartyContactMechanism) objects[i]).getContactMechanism().getContactMechanismId());
    }
    assertEquals(partyContactMechList.size(), 1);
    PartyContactMechanism partyContactMechanism = ((PartyContactMechanism) partyContactMechList.toArray()[0]);
    final Party party = partyContactMechanism.getParty();
    assertEquals(party.getPartyId(), p.getPartyId());
    assertEquals(partyContactMechanism.getContactMechanism().getType(),
            ContactMechanismType.Cache.POSTAL_ADDRESS.getEntity());
    assertEquals(partyContactMechanism.getPurposes().size(), 1);
    final PartyContactMechanismPurpose purpose = (PartyContactMechanismPurpose) partyContactMechanism
            .getPurposes().toArray()[0];
    assertEquals(purpose.getType(), ContactMechanismPurposeType.Cache.HOME_ADDRESS.getEntity());

    // verify the contact mchanism data
    final PostalAddress ps = (PostalAddress) HibernateUtil.getSession().load(PostalAddress.class,
            address.getPostalAddressId());
    assertEquals(ps.getAddress1(), "123 Acme Road");
    assertEquals(ps.getAddress2(), "Suite 100");
    assertEquals(5, ps.getAddressBoundaries().size());
    assertEquals(ps.getCity().getName(), "Fairfax");
    assertEquals(ps.getState().getName(), "VA");
    assertEquals(ps.getPostalCode().getName(), "22033");
    assertEquals(ps.getCounty().getName(), "Fairfax County");
    assertEquals(ps.getCountry().getName(), "USA");
}

From source file:com.netspective.medigy.service.person.PatientRegistrationServiceImpl.java

License:Open Source License

protected void registerInsuranceInformation(final Person person, final RegisterPatientParameters params)
        throws UnknownReferenceTypeException {
    final ReferenceEntityLookupService referenceEntityService = (ReferenceEntityLookupService) ServiceLocator
            .getInstance().getService(ReferenceEntityLookupService.class);

    final String[] policyNumbers = params.getInsurancePolicyNumbers();
    final String[] policyTypes = params.getInsurancePolicyTypes();
    final String[] contractHolderIds = params.getInsurancePolicyHolderId();
    final String[] contractHolderLastNames = params.getInsurancePolicyHolderLastNames();
    final String[] contractHolderFirstNames = params.getInsurancePolicyHolderFirstNames();
    final String[] policyProviders = params.getInsurancePolicyProviders();
    final String[] policyProviderIds = params.getInsurancePolicyProviderIds();

    for (int i = 0; i < policyNumbers.length; i++) {
        final String policyType = params.getInsurancePolicyTypes()[i];
        final InsurancePolicyType type = referenceEntityService.getInsurancePolicyType(policyType);
        final String contractHolderId = contractHolderIds[i];
        final String contractHolderFirstName = contractHolderFirstNames[i];
        final String contractHolderLastName = contractHolderLastNames[i];
        final String policyProvider = policyProviders[i];
        final String policyProviderId = policyProviderIds[i];

        Person policyHolder = null;//from   w w  w  .java2s . c  o  m
        if (contractHolderId == null && contractHolderLastName != null) {
            // create a new contract holder but check if this is the same person as the responsible party
            if (params.getResponsiblePartyLastName().equals(contractHolderLastName)
                    && params.getResponsiblePartyFirstName().equals(contractHolderFirstName)) {
                // TODO:
            } else {
                policyHolder = new Person();
                policyHolder.setLastName(contractHolderLastName);
                policyHolder.setFirstName(contractHolderFirstName);
                HibernateUtil.getSession().save(policyHolder);
            }
        } else {
            // NOTE: this will throw HibernateException if the ID doesnt exist
            policyHolder = (Person) HibernateUtil.getSession().load(Person.class,
                    getPrimaryKey(contractHolderId));
        }

        Organization providerOrg = null;
        if (policyProviderId != null) {
            providerOrg = (Organization) HibernateUtil.getSession().load(Organization.class,
                    getPrimaryKey(policyProviderId));
        } else {
            providerOrg = new Organization();
            providerOrg.setOrganizationName(policyProvider);
            providerOrg.addPartyRole(OrganizationRoleType.Cache.INSURANCE_PROVIDER.getEntity());
            HibernateUtil.getSession().save(providerOrg);
        }

        boolean newPolicy = false;

        Criteria criteria = HibernateUtil.getSession().createCriteria(InsurancePolicy.class);
        criteria.add(Restrictions.eq("policyNumber", policyNumbers[i]));
        Criteria providerCriteria = criteria.createCriteria("insuranceProvider");
        providerCriteria.add(Restrictions.eq("partyId", providerOrg.getPartyId()));
        Criteria policyHolderCriteria = criteria.createCriteria("pol");

        InsurancePolicy policy = new InsurancePolicy();
        policy.setType(type);
        policy.setPolicyNumber(policyNumbers[i]);
        policy.setInsuranceProvider(providerOrg);
        policy.setPolicyHolder(policyHolder);
        policy.addInsuredDependent(person);

        if (newPolicy)
            HibernateUtil.getSession().save(newPolicy);
        else
            HibernateUtil.getSession().flush();
    }

}

From source file:com.netspective.medigy.service.util.InsurancePolicyFacadeImpl.java

License:Open Source License

public InsurancePolicy getIndividualInsurancePolicy(final String policyNumber) {
    Criteria criteria = HibernateUtil.getSession().createCriteria(InsurancePolicy.class);
    criteria.add(Restrictions.eq("policyNumber", policyNumber));
    criteria.createCriteria("type")
            .add(Expression.eq("code", InsurancePolicyType.Cache.INDIVIDUAL_INSURANCE_POLICY.getCode()));

    log.info(criteria.list().size());//  w w w . j  a va2 s  .  co m
    return (InsurancePolicy) criteria.uniqueResult();
}

From source file:com.netspective.medigy.service.util.InsurancePolicyFacadeImpl.java

License:Open Source License

public List listInsurancePolicies(final Serializable personId) {
    Criteria criteria = HibernateUtil.getSession().createCriteria(InsurancePolicy.class);
    criteria.createCriteria("agreementRoles").createCriteria("party").add(Expression.eq("partyId", personId));

    return criteria.list();
}

From source file:com.netspective.medigy.service.util.PartyRelationshipFacadeImpl.java

License:Open Source License

public List getValidPartyRolesByRelationshipType(PartyRelationshipType type) {
    Criteria criteria = HibernateUtil.getSession().createCriteria(ValidPartyRelationshipRole.class);
    Criteria relationshipCriteria = criteria.createCriteria("partyRelationshipType");
    relationshipCriteria.add(Expression.eq("code", type.getCode()));

    return criteria.list();
}

From source file:com.netspective.medigy.service.util.PartyRelationshipFacadeImpl.java

License:Open Source License

public List listPartyRelationshipsByTypeAndFromRole(PartyRelationshipType type, PartyRole fromRole) {
    Criteria criteria = HibernateUtil.getSession().createCriteria(PartyRelationship.class)
            .createCriteria("partyRelationshipType");
    criteria.add(Expression.eq("code", type.getCode()));
    criteria.createCriteria("fromPartyRole").add(Expression.eq("partyRoleId", fromRole.getPartyRoleId()));
    return criteria.list();
}

From source file:com.netspective.medigy.service.util.PartyRelationshipFacadeImpl.java

License:Open Source License

/**
 * Lists all relationships where the party is the responsible party for a patient
 *
 * @param patient/*from  w w w  .  j a  v a  2s.  c  om*/
 * @return List of Party Relationships
 */
public List listPatientResponsiblePartyRelationship(Party patient) {
    Criteria criteria = HibernateUtil.getSession().createCriteria(PartyRelationship.class);
    Criteria partyRelTypeCriteria = criteria.createCriteria("type");
    partyRelTypeCriteria
            .add(Expression.eq("code", PartyRelationshipType.Cache.PATIENT_RESPONSIBLE_PARTY.getCode()));
    criteria.createCriteria("partyFrom").add(Expression.eq("partyId", patient.getPartyId()));
    return criteria.list();
}

From source file:com.npower.dm.hibernate.management.ClientProvTemplateBeanImpl.java

License:Open Source License

public ClientProvTemplate findTemplate(Model model, ProfileCategory category) throws DMException {
    if (model == null) {
        return null;
    }/*  w  w  w  .j  a  v  a2 s  . com*/
    Session session = this.getHibernateSession();
    try {
        Criteria criteria = session.createCriteria(ClientProvTemplate.class);
        criteria.add(Expression.eq("profileCategory", category));
        Criteria mappingCriteria = criteria.createCriteria("modelClientProvMaps");
        mappingCriteria.add(Expression.eq("model", model));
        List<ClientProvTemplate> list = criteria.list();
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    } catch (HibernateException e) {
        throw new DMException(e);
    } finally {
    }
}

From source file:com.npower.dm.hibernate.management.ClientProvTemplateBeanImpl.java

License:Open Source License

public List<ClientProvTemplate> findTemplates(Model model) throws DMException {
    if (model == null) {
        return new ArrayList<ClientProvTemplate>(0);
    }//from   www .java2s. c om
    Session session = this.getHibernateSession();
    try {
        Criteria criteria = session.createCriteria(ClientProvTemplate.class);
        Criteria mappingCriteria = criteria.createCriteria("modelClientProvMaps");
        mappingCriteria.add(Expression.eq("model", model));
        List<ClientProvTemplate> list = criteria.list();
        return list;
    } catch (HibernateException e) {
        throw new DMException(e);
    } finally {
    }
}