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.



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 111

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.



152
153
154
155
156
157
158
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 152

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.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 127

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.



171
172
173
174
175
176
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 171

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.



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 224

def fetch_root (wfid)

    params = {}

    params[:conditions] = [ 
        "wfid = ? AND exp_class = ?", 
        wfid, 
        OpenWFE::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.



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 199

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)


163
164
165
166
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 163

def has_key? (fei)

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

#purgeObject

Danger ! Will remove all the expressions in the database.



191
192
193
194
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 191

def purge 

    Expression.delete_all
end

#sizeObject Also known as: length

Returns the count of expressions currently stored.



181
182
183
184
# File 'lib/openwfe/extras/expool/dbexpstorage.rb', line 181

def size

    Expression.count
end