Class: OpenWFE::Extras::DbExpressionStorage

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin, OpenWFE::ExpressionStorageBase, OwfeServiceLocator, ServiceMixin
Defined in:
lib/openwfe/extras/expool/dbexpstorage.rb

Overview

Storing OpenWFE flow expressions in a database.

Direct Known Subclasses

ThreadedDbExpressionStorage

Instance Method Summary collapse

Constructor Details

#initialize(service_name, application_context) ⇒ DbExpressionStorage

Constructor.



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 105

def initialize (service_name, application_context)

    require 'openwfe/storage/yamlcustom'
        # making sure this file has been required at this point
        # this yamlcustom thing prevents the whole OpenWFE ecosystem
        # to get serialized :)

    super() # absolutely necessary as we include MonitorMixin
    service_init service_name, application_context

    observe_expool
end

Instance Method Details

#[](fei) ⇒ Object

Retrieves a flow expression.



146
147
148
149
150
151
152
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 146

def [] (fei)

    e = Expression.find_by_fei fei.to_s
    return nil unless e

    as_owfe_expression e
end

#[]=(fei, flow_expression) ⇒ Object

Stores an expression.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 121

def []= (fei, flow_expression)

    ldebug { "[]= storing #{fei.to_s}" }

    synchronize do

        e = Expression.find_by_fei fei.to_s

        unless e
            e = Expression.new
            e.fei = fei.to_s
            e.wfid = fei.wfid
            #e.wfname = fei.wfname
        end

        e.exp_class = flow_expression.class.name
        e.svalue = flow_expression

        e.save!
    end
end

#delete(fei) ⇒ Object

Deletes a flow expression.



165
166
167
168
169
170
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 165

def delete (fei)

    synchronize do
        Expression.delete_all ["fei = ?", fei.to_s]
    end
end

#fetch_root(wfid) ⇒ Object

Fetches the root of a process instance.



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 218

def fetch_root (wfid)

    params = {}

    params[:conditions] = [ 
        "wfid = ? AND exp_class = ?", wfid, DefineExpression.to_s
    ]

    exps = Expression.find(:all, params)

    e = exps.sort { |fe1, fe2| fe1.fei.expid <=> fe2.fei.expid }[0]
        #
        # find the one with the smallest expid

    as_owfe_expression e
end

#find_expressions(options = {}) ⇒ Object

Gather expressions matching certain parameters.



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 193

def find_expressions (options={})

    conditions = determine_conditions options
        # note : this call modifies the options hash...

    #
    # maximize usage of SQL querying

    exps = Expression.find :all, :conditions => conditions

    #
    # do the rest of the filtering

    exps = exps.collect do |exp|
        as_owfe_expression exp
    end

    exps.find_all do |fexp|
        does_match? options, fexp
    end
end

#has_key?(fei) ⇒ Boolean

Returns true if there is a FlowExpression stored with the given id.

Returns:

  • (Boolean)


157
158
159
160
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 157

def has_key? (fei)

    (Expression.find_by_fei(fei.to_s) != nil)
end

#purgeObject

Danger ! Will remove all the expressions in the database.



185
186
187
188
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 185

def purge 

    Expression.delete_all
end

#sizeObject Also known as: length

Returns the count of expressions currently stored.



175
176
177
178
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 175

def size

    Expression.count
end