Example usage for org.hibernate.criterion DetachedCriteria forClass

List of usage examples for org.hibernate.criterion DetachedCriteria forClass

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria forClass.

Prototype

public static DetachedCriteria forClass(Class clazz) 

Source Link

Document

Static builder to create a DetachedCriteria for the given entity, by its Class.

Usage

From source file:com.headstrong.teevra.services.refdata.dao.impl.DataSourceConfigDAOImpl.java

License:Open Source License

public void saveDataSourceConfig(DataSourceConfigEO dataSourceConfigToSave) throws RefDataServiceException {

    DetachedCriteria criteria = DetachedCriteria.forClass(DataSourceConfigEO.class);
    criteria.add(Restrictions.eq("dataSourceName", dataSourceConfigToSave.getDataSourceName()));
    if (dataSourceConfigToSave.getDataSourceId() != null) {
        criteria.add(Restrictions.ne("dataSourceId", dataSourceConfigToSave.getDataSourceId()));
    }// w  w  w. j ava2s .com
    List<DataSourceConfigEO> configList = super.getByCriteria(criteria);

    if (!configList.isEmpty()) {
        logger.error("A process with the same name already exists in the system");
        throw new UniqueDataSourceConfigException("A data source with the name " + "'"
                + dataSourceConfigToSave.getDataSourceName() + "'" + " is already exists in the system");
    } else {
        super.saveOrUpdate(dataSourceConfigToSave);

    }

}

From source file:com.headstrong.teevra.services.refdata.dao.impl.DataSourceConfigDAOImpl.java

License:Open Source License

public void deleteDataSourceConfig(String dataSourceName) throws RefDataServiceException {
    // get the list of datasources for the given dataSourceName(list should
    // contain only one element)
    List<DataSourceConfigEO> dataSourceConfigList = super.getByCriteria(DetachedCriteria
            .forClass(DataSourceConfigEO.class).add(Restrictions.eq("dataSourceName", dataSourceName)));

    // delete the config if the list is not empty else throw an exception
    if (!dataSourceConfigList.isEmpty()) {
        super.delete(dataSourceConfigList.get(0));
    } else {/*from   w  w w .  j  a  va2s  . co  m*/

        logger.error("Couldn't delete.. there is no such data source configuration");
        throw new DataSourceConfigDeleteException("Cannot delete the data source configuration with name: "
                + "'" + dataSourceName + "'" + ". there is no such data source configuration");

    }

}

From source file:com.headstrong.teevra.services.refdata.dao.impl.RefDataConfigDAOImpl.java

License:Open Source License

public void saveRefDataConfig(RefDataConfigEO refDataConfigToSave) throws RefDataServiceException {
    DetachedCriteria criteria = DetachedCriteria.forClass(RefDataConfigEO.class);
    criteria.add(Restrictions.eq("refDataName", refDataConfigToSave.getRefDataName()));
    if (refDataConfigToSave.getRefDataId() != null) {
        criteria.add(Restrictions.ne("refDataId", refDataConfigToSave.getRefDataId()));
    }/*ww w .j a v a  2 s .  c  om*/
    List<RefDataConfigEO> configList = super.getByCriteria(criteria);

    if (!configList.isEmpty()) {
        logger.error("A Refdata with the same name already exists in the system");
        throw new UniqueRefDataConfigException("A reference data with the name " + "'"
                + refDataConfigToSave.getRefDataName() + "'" + " is already exists in the system");
    } else {
        super.saveOrUpdate(refDataConfigToSave);

    }

}

From source file:com.headstrong.teevra.services.refdata.dao.impl.RefDataConfigDAOImpl.java

License:Open Source License

public void deleteRefDataConfig(String refDataName) throws RefDataServiceException {
    List<RefDataConfigEO> refDataConfigList = super.getByCriteria(
            DetachedCriteria.forClass(RefDataConfigEO.class).add(Restrictions.eq("refDataName", refDataName)));

    if (!refDataConfigList.isEmpty()) {
        super.delete(refDataConfigList.get(0));
    } else {/*from   w  ww. j  a  v  a  2s  . c om*/

        logger.error("Couldn't delete.. there is no such reference data configuration");
        throw new RefDataConfigDeleteException("Cannot delete the reference data configuration with name: "
                + "'" + refDataName + "'" + ". there is no such reference data configuration");

    }

}

From source file:com.headstrong.teevra.services.schema.dao.impl.MessageSchemaDAOImpl.java

License:Open Source License

public void saveSchema(MessageSchemaEO schema) throws SchemaServiceException {

    if (schema.getSchemaName() == null) {
        logger.error("key attributes are not specified for the schema");
        throw new NoKeyAttributeException("Schema name is not specified for the schema");
    } else {/*from ww w .ja v  a  2  s . c  om*/
        List<MessageSchemaEO> schemaCheckList = super.getByCriteria(DetachedCriteria
                .forClass(MessageSchemaEO.class).add(Restrictions.eq("schemaName", schema.getSchemaName())));
        if (!schemaCheckList.isEmpty()) {
            logger.error("A schema with the same name already exists in the system");
            throw new UniqueSchemaException("A schema with the name " + "'" + schema.getSchemaName() + "'"
                    + " is already exists in the system");
        } else {
            super.save(schema);

            List<MessageSchemaAttributeEO> attributes = schema.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.size(); i++) {
                    MessageSchemaAttributeEO attribute = attributes.get(i);

                    String schemaName = attribute.getSchemaName();
                    String schemaAttrTypeName = attribute.getSchemaAttrTypeName();
                    if (schemaName == null || schemaAttrTypeName == null) {
                        logger.error("key attributes are not specified for the schema");
                        throw new NoKeyAttributeException("key attributes are not specified for the schema");
                    } else {
                        List<MessageSchemaEO> schemaList = super.getByCriteria(
                                DetachedCriteria.forClass(MessageSchemaEO.class)
                                        .add(Restrictions.eq("schemaName", schemaName)));
                        // set id to the attribute
                        attribute.setSchemaId(schemaList.get(0).getSchemaId());
                        List<MessageSchemaEO> schemaTypeList = super.getByCriteria(
                                DetachedCriteria.forClass(MessageSchemaEO.class)
                                        .add(Restrictions.eq("schemaName", schemaAttrTypeName)));
                        if (schemaTypeList.size() == 0) {
                            logger.error("Type set in the attribute descriptor is not present");
                            throw new InvalidAttributeSchemaException("The type schema " + "'"
                                    + schemaAttrTypeName + "'" + " is not present in the system");
                        } else {
                            // set schema type id to the attribute
                            attribute.setSchemaAttrType(schemaTypeList.get(0).getSchemaId());
                        }
                        messageSchemaAttributeDAO.saveSchemaAttribute(attribute);
                    }
                }
            }

        }
    }

}

From source file:com.headstrong.teevra.services.schema.dao.impl.MessageSchemaDAOImpl.java

License:Open Source License

public void deleteSchema(String schemaName) throws SchemaServiceException {
    List<MessageSchemaEO> schemaList = super.getByCriteria(
            DetachedCriteria.forClass(MessageSchemaEO.class).add(Restrictions.eq("schemaName", schemaName)));
    MessageSchemaEO schema = schemaList.get(0);
    List<MessageSchemaAttributeEO> attributes = schema.getAttributes();

    if (!attributes.isEmpty()) {
        super.delete(schemaList.get(0));
    } else {/* ww  w .j a v  a2 s  .com*/

        logger.error("Couldn't delete.. there are dependencies for this schema");
        throw new SchemaDeleteException("Cannot delete the schema " + "'" + schemaName + "'"
                + ". dependencies exist for the schema specified for delete");

    }
}

From source file:com.headstrong.teevra.services.schema.dao.impl.MessageSchemaDAOImpl.java

License:Open Source License

public void deleteSchemaTree(Long rootSchemaId) throws SchemaServiceException {

    List<MessageSchemaEO> schemasToDelete = new ArrayList<MessageSchemaEO>();
    List<MessageSchemaEO> schemaList = super.getByCriteria(
            DetachedCriteria.forClass(MessageSchemaEO.class).add(Restrictions.eq("schemaId", rootSchemaId)));
    MessageSchemaEO rootSchema = schemaList.get(0);

    // Get the non primitive schemas in the tree
    schemasToDelete = getSchemasToDelete(schemasToDelete, rootSchema);

    // delete atributes and schemaRaw for all the schemas
    for (int i = 0; i < schemasToDelete.size(); i++) {
        deleteSchemaDetails(schemasToDelete.get(i));
    }// www .  ja va 2s  .c o  m

    // delete the schemas
    for (int i = 0; i < schemasToDelete.size(); i++) {
        super.delete(schemasToDelete.get(i));
    }

}

From source file:com.headstrong.teevra.services.schema.dao.impl.MessageSchemaDAOImpl.java

License:Open Source License

/**
 * Takes the root schema and gets all the schemas in the object tree and in
 * the process delete the attributes/*from  w ww . j a va2s  .  c o  m*/
 * 
 * @precondition
 * @postcondition
 * @param schemasToDelete
 *            a list of schemas
 * @param rootSchema
 * @return the list of schemas
 */
private List<MessageSchemaEO> getSchemasToDelete(List<MessageSchemaEO> schemasToDelete,
        MessageSchemaEO rootSchema) {

    if (!rootSchema.isSchemaIsPrimitive()) {

        schemasToDelete.add(rootSchema);
        List<MessageSchemaAttributeEO> attributes = rootSchema.getAttributes();
        for (int i = 0; i < attributes.size(); i++) {
            MessageSchemaAttributeEO attribute = attributes.get(i);
            long schemaAttrType = attribute.getSchemaAttrType();

            List<MessageSchemaEO> schemaTypeList = super.getByCriteria(DetachedCriteria
                    .forClass(MessageSchemaEO.class).add(Restrictions.eq("schemaId", schemaAttrType)));

            getSchemasToDelete(schemasToDelete, schemaTypeList.get(0));
        }
    }
    return schemasToDelete;
}

From source file:com.headstrong.teevra.services.schema.dao.impl.MessageSchemaDAOImpl.java

License:Open Source License

public MessageSchemaEO loadSchema(String schemaName) {

    ObjectDescriptorCache objectDescriptorCache = ObjectDescriptorCache.getInstance();
    MessageSchemaEO schema = objectDescriptorCache.getDescriptor(schemaName);
    if (schema != null) {
        logger.info("Schema is already present in the Cache");
        return schema;
    } else {/*from ww  w. ja va 2  s.  c  om*/
        List<MessageSchemaEO> schemaList = super.getByCriteria(DetachedCriteria.forClass(MessageSchemaEO.class)
                .add(Restrictions.eq("schemaName", schemaName)));
        MessageSchemaEO rootSchema = schemaList.get(0);
        // load all the schemas to the cache
        loadSchemasToCache(objectDescriptorCache, rootSchema);
        return rootSchema;
    }

}

From source file:com.headstrong.teevra.services.schema.dao.impl.MessageSchemaDAOImpl.java

License:Open Source License

/**
 * Loads all the schemas in the tree specified by the root schema name to
 * the cache iteratively//  w  ww.ja v  a  2s .  c  o  m
 * 
 * @precondition
 * @postcondition
 * @param objectDescriptorCache
 * @param rootSchema
 */
private void loadSchemasToCache(ObjectDescriptorCache objectDescriptorCache, MessageSchemaEO rootSchema) {
    objectDescriptorCache.addDescriptor(rootSchema.getSchemaName(), rootSchema);
    if (!rootSchema.isSchemaIsPrimitive()) {
        List<MessageSchemaAttributeEO> attributes = rootSchema.getAttributes();
        for (int i = 0; i < attributes.size(); i++) {
            MessageSchemaAttributeEO attribute = attributes.get(i);
            long schemaAttrType = attribute.getSchemaAttrType();

            List<MessageSchemaEO> schemaTypeList = super.getByCriteria(DetachedCriteria
                    .forClass(MessageSchemaEO.class).add(Restrictions.eq("schemaId", schemaAttrType)));

            loadSchemasToCache(objectDescriptorCache, schemaTypeList.get(0));

        }
    }
}