Esempio n. 1
0
//GohanDbStateUpdate updates resource's state in database
func GohanDbStateUpdate(transaction transaction.Transaction, needCommit bool, schemaID string,
	dataMap map[string]interface{}) (*schema.Resource, error) {

	manager := schema.GetManager()
	resource, err := manager.LoadResource(schemaID, dataMap)
	if err != nil {
		return nil, fmt.Errorf("Error during gohan_db_state_update: %s", err.Error())
	}
	if err = transaction.StateUpdate(resource, nil); err != nil {
		return nil, fmt.Errorf("Error during gohan_db_state_update: %s", err.Error())
	}
	if needCommit {
		err = transaction.Commit()
		if err != nil {
			return nil, fmt.Errorf("Error during gohan_db_state_update: %s", err.Error())
		}
	}
	return resource, nil
}