List of usage examples for org.hibernate.criterion DetachedCriteria forClass
public static DetachedCriteria forClass(Class clazz)
From source file:com.headstrong.teevra.services.schema.dao.impl.MessageSchemaDAOImpl.java
License:Open Source License
/** * Saves all the schemas in the tree specified by the root schema name * iteratively//from w ww .j a v a 2s . c om * * @precondition * @postcondition * @param descriptorMap * @param rootSchema * @throws SchemaServiceException */ private void saveSchemas(Map<String, MessageSchemaEO> descriptorMap, MessageSchemaEO rootSchema) throws SchemaServiceException { if (!rootSchema.isSchemaIsPrimitive()) { // check if schema name is provided if (rootSchema.getSchemaName() == null) { logger.error("key attributes are not specified for the schema"); throw new NoKeyAttributeException("Schema name is not specified for the schema"); } else { List<MessageSchemaEO> schemaCheckList = super.getByCriteria( DetachedCriteria.forClass(MessageSchemaEO.class) .add(Restrictions.eq("schemaName", rootSchema.getSchemaName()))); // check if any schema with the name already exists in the // system if (!schemaCheckList.isEmpty()) { logger.error("A schema with the same name already exists in the system"); throw new UniqueSchemaException("A schema with the name " + "'" + rootSchema.getSchemaName() + "'" + "already exists in the system"); } else { // save the schema super.save(rootSchema); // iterate through the attributes // and get the schema type of the attributes List<MessageSchemaAttributeEO> attributes = rootSchema.getAttributes(); for (MessageSchemaAttributeEO attribute : attributes) { String schemaAttrTypeName = attribute.getSchemaAttrTypeName(); // check if the schema type is provided if (schemaAttrTypeName == null) { logger.error("key attributes are not specified for the schema"); throw new NoKeyAttributeException("key attributes are not specified for the schema"); } else { // Repeat the process for the next schema saveSchemas(descriptorMap, descriptorMap.get(schemaAttrTypeName)); } } } } } }
From source file:com.headstrong.teevra.services.schema.dao.impl.MessageSchemaDAOImpl.java
License:Open Source License
/** * Fetches all the attributes present in the schema tree and persist them. * Saves the rootSchema Description and it's corresponding SchemaRaw * //from w ww .j a va 2 s . c o m * @precondition * @postcondition * @param descriptorMap * @param rootSchema * @throws SchemaServiceException */ private void saveSchemaDetails(Map<String, MessageSchemaEO> descriptorMap, MessageSchemaEO rootSchema) throws SchemaServiceException { if (!rootSchema.isSchemaIsPrimitive()) { String schemaName = rootSchema.getSchemaName(); // Get the schemaId from database List<MessageSchemaEO> schemaList = super.getByCriteria(DetachedCriteria.forClass(MessageSchemaEO.class) .add(Restrictions.eq("schemaName", schemaName))); // check if the schema contains any schemaRaw. if yes, set // schemaId and save it if (rootSchema.getSchemaRaw() != null) { MessageSchemaRawEO schemaRaw = new MessageSchemaRawEO(); schemaRaw.setSchemaId(schemaList.get(0).getSchemaId()); if (rootSchema.getSchemaRaw().getSchemaFormattedText() != null) { schemaRaw.setSchemaFormattedText(rootSchema.getSchemaRaw().getSchemaFormattedText()); } schemaRaw.setCreatedBy(rootSchema.getCreatedBy()); schemaRaw.setCreatedDate(rootSchema.getCreatedDate()); schemaRaw.setModifiedBy(rootSchema.getModifiedBy()); schemaRaw.setModifiedDate(rootSchema.getModifiedDate()); messageSchemaRawDAO.saveSchemaRaw(schemaRaw); } List<MessageSchemaAttributeEO> attributes = rootSchema.getAttributes(); for (MessageSchemaAttributeEO attribute : attributes) { String schemaAttrTypeName = attribute.getSchemaAttrTypeName(); // check if schema name and the schema type name of the // attributes are provided if (schemaName == null || schemaAttrTypeName == null) { logger.error("key attributes are not specified for the schema"); throw new NoKeyAttributeException( "Either Schema name or type name is not specified for the attribute"); } else { attribute.setSchemaId(schemaList.get(0).getSchemaId()); // from DB, set the schemaId of the schemaType of the // attribute List<MessageSchemaEO> schemaTypeList = super.getByCriteria( DetachedCriteria.forClass(MessageSchemaEO.class) .add(Restrictions.eq("schemaName", schemaAttrTypeName))); // check if the schemaType is in the system then proceed // with setting Id if (schemaTypeList.size() == 0) { logger.error("Type set in the attribute descriptor is not present"); throw new InvalidAttributeSchemaException( "The type schema" + "'" + schemaAttrTypeName + "'" + " not present in the system"); } else { attribute.setSchemaAttrType(schemaTypeList.get(0).getSchemaId()); // save the attribute messageSchemaAttributeDAO.saveSchemaAttribute(attribute); // Repeat the process for the next schema saveSchemaDetails(descriptorMap, descriptorMap.get(schemaAttrTypeName)); } } } } }
From source file:com.headstrong.teevra.services.schema.dao.impl.MessageSchemaDAOImpl.java
License:Open Source License
public List<MessageSchemaEO> getPublicSchemas() throws SchemaServiceException { return super.getByCriteria( DetachedCriteria.forClass(MessageSchemaEO.class).add(Restrictions.eq("schemaIsPublic", true))); }
From source file:com.headstrong.teevra.services.schema.dao.impl.MessageSchemaDAOImpl.java
License:Open Source License
public List<MessageSchemaEO> getSchemas(MessageSchemaEO criteria) throws SchemaServiceException { return super.getByCriteria(DetachedCriteria.forClass(MessageSchemaEO.class) .add(Restrictions.eq("schemaId", criteria.getSchemaId()))); }
From source file:com.headstrong.teevra.services.serveradmin.dao.impl.ProcessServerDAOImpl.java
License:Open Source License
public ProcessServerEO getPrcsServerMapping(Long prcsId) throws ServerAdminServiceException { List<ProcessServerEO> mappingList = super.getByCriteria( DetachedCriteria.forClass(ProcessServerEO.class).add(Restrictions.eq("prcsId", prcsId))); ProcessServerEO prcsServerMapping = null; if (!mappingList.isEmpty()) { prcsServerMapping = mappingList.get(0); }//from w w w . j a va 2 s .com return prcsServerMapping; }
From source file:com.headstrong.teevra.services.serveradmin.dao.impl.ServerConfigDAOImpl.java
License:Open Source License
public void registerServer(ServerConfigEO serverToRegister) throws ServerAdminServiceException { DetachedCriteria criteria = DetachedCriteria.forClass(ServerConfigEO.class); criteria.add(Restrictions.eq("serverName", serverToRegister.getServerName())); if (serverToRegister.getServerId() != null) { criteria.add(Restrictions.ne("serverId", serverToRegister.getServerId())); }//from ww w. ja v a 2s . c om List<ServerConfigEO> serverList = super.getByCriteria(criteria); if (!serverList.isEmpty()) { logger.error("A server with the same name already exists in the system"); throw new UniqueServerException("A server with the name " + "'" + serverToRegister.getServerName() + "'" + " is already exists in the system"); } else { super.saveOrUpdate(serverToRegister); } }
From source file:com.headstrong.teevra.services.serveradmin.dao.impl.ServerConfigDAOImpl.java
License:Open Source License
public void unregisterServer(String serverName) throws ServerAdminServiceException { List<ServerConfigEO> serverList = super.getByCriteria( DetachedCriteria.forClass(ServerConfigEO.class).add(Restrictions.eq("serverName", serverName))); ServerConfigEO serverToUnregister = serverList.get(0); if (serverToUnregister.getPrcsServerMappings().isEmpty()) { // remvove the server config details from database super.delete(serverToUnregister); } else {/*from www .j av a 2s . c o m*/ List<ProcessServerEO> mappings = serverToUnregister.getPrcsServerMappings(); // remove all the process server mappings for the sever from the // database for (ProcessServerEO mapping : mappings) { processServerDAO.deletePrcsServerMapping(mapping); } // remove the server config details from database super.delete(serverToUnregister); // remove all the processes from the server. If any process is in // LOCKED state change it to PUBLISHED as the RUNNING processes get // STOPPED for (ProcessServerEO mapping : mappings) { try { // get the process using id ProcessEO prcsToRemove = new ProcessEO(); prcsToRemove.setPrcsId(mapping.getPrcsId()); try { prcsToRemove = processDAO.getProcesses(prcsToRemove).get(0); } catch (ProcessServiceException e) { logger.error("Error while retrieving the process ", e); throw new ServerAdminServiceException(e.getMessage()); } // If the Status is LOCKED change it to PUBLISHED and save // it if (prcsToRemove.getPrcsStatus().equals(ProcessEO.STATUS_LOCKED)) { prcsToRemove.setPrcsStatus(ProcessEO.STATUS_PUBLISHED); try { processDAO.saveProcess(prcsToRemove); } catch (ProcessServiceException e) { logger.error("Error while saving the process ", e); throw new ServerAdminServiceException(e.getMessage()); } } // remove the process from the server RemoteProcessAdminDelegate.getInstance().removeProcess(mapping.getPrcsId(), serverToUnregister.getServerUrl()); } catch (ProcessRemoveException e) { logger.error("Error while removing the process from the assigned server", e); throw new ServerAdminServiceException(e.getMessage()); } } } }
From source file:com.headstrong.teevra.services.serveradmin.dao.impl.ServerConfigDAOImpl.java
License:Open Source License
public ServerConfigEO getServerConfig(Long serverId) throws ServerAdminServiceException { return super.getByCriteria( DetachedCriteria.forClass(ServerConfigEO.class).add(Restrictions.eq("serverId", serverId))).get(0); }
From source file:com.headstrong.teevra.services.statemachine.dao.impl.StateMachineDAOImpl.java
License:Open Source License
public void saveStateMachine(StateMachineEO stateMachineToSave) throws StateMachineServiceException { DetachedCriteria criteria = DetachedCriteria.forClass(StateMachineEO.class); criteria.add(Restrictions.eq("stateMachineName", stateMachineToSave.getStateMachineName())); if (stateMachineToSave.getStateMachineId() != null) { criteria.add(Restrictions.ne("stateMachineId", stateMachineToSave.getStateMachineId())); }//from w w w . j a v a 2 s . c o m List<StateMachineEO> stateMachineList = super.getByCriteria(criteria); if (!stateMachineList.isEmpty()) { logger.error("A state machine with the same name already exists in the system"); throw new UniqueStateMachineException("A state machine with the name " + "'" + stateMachineToSave.getStateMachineName() + "'" + " already exists in the system"); } else { super.saveOrUpdate(stateMachineToSave); } }
From source file:com.headstrong.teevra.services.statemachine.dao.impl.StateMachineDAOImpl.java
License:Open Source License
private StateMachineEO getStateMachine(String stateMachineName) { return super.getByCriteria(DetachedCriteria.forClass(StateMachineEO.class) .add(Restrictions.eq("stateMachineName", stateMachineName))).get(0); }