2020-04-16_datacollector-factories.html
001|
002|
003|
004|
005| def ListFactory (iterable, list_type):
006| '''Creates a list of a given type.'''
007|
008| if list_type.lower() == 'mutable':
009| return list(iterable)
010|
011| if list_type.lower() == 'immutable':
012| return tuple(iterable)
013|
014| raise RuntimeError('Unknown type: "%s"' % list_type)
015|
016| list_items = [1,2,3,4,5,6,7,8,9,10]
017|
018| list1 = ListFactory(list_items, 'mutable')
019| list2 = ListFactory(list_items, 'immutable')
020|
021|
022| def ListFactoryFactory (list_type='mutable'):
023| '''Returns a typed list factory.'''
024|
025| if list_type.lower() == 'mutable':
026| return lambda xs:list(xs)
027|
028| if list_type.lower() == 'immutable':
029| return lambda xs:tuple(xs)
030|
031| raise RuntimeError('Unknown type: "%s"' % list_type)
032|
033| factory1 = ListFactoryFactory()
034| factory2 = ListFactoryFactory('immutable')
035|
036| list_items = [1,2,3,4,5,6,7,8,9,10]
037| list1 = factory1(list_items)
038| list2 = factory2(list_items)
039|
040|
041| TypeFactoryFactory FF = new TypeFactoryFactory();
042|
043| ITypeFactory TF = FF.getTypeFactory(record_type);
044| IQuery qry = TF.getQuery();
045| IRecord rcd = TF.getRecord();
046|
047|
048| TypeFactoryFactory FF = new TypeFactoryFactory();
049| ITypeFactory TF = FF.getTypeFactory(record_type);
050|
051| // Create the query...
052| IRecord recd = TF.getRecord();
053|
054| for (f in select_fields) {
055| recd.setField(f.name, "");
056| }
057|
058| for (f in where_fields) {
059| recd.setField(f.name, f.value);
060| }
061|
062| // Make the query...
063| IQuery qry = TF.getQuery();
064| qry.login(UserName, Password);
065|
066| IRecord[] data = qry.get(recd);
067| qry.logout();
068|
069| // Process the query result...
070| SortRecords(data, orderby_fields);
071|
072| for (d in data) {
073| print("Record:");
074| for (f in select_fields) {
075| print(d.getField(f.name));
076| }
077| }
078|
079|
080|