Source code

Database, model, supporting classes

Click to view SimpleDatabase.class
 1package net.akaish.kittyormdemo.sqlite.introductiondb;
 2
 3import android.content.Context;
 4
 5import net.akaish.kitty.orm.KittyDatabase;
 6import net.akaish.kitty.orm.annotations.KITTY_DATABASE;
 7
 8/**
 9 * Created by akaish on 09.08.18.
10 */
11@KITTY_DATABASE(
12        isLoggingOn = true,
13        isProductionOn = false,
14        domainPackageNames = {"net.akaish.kittyormdemo.sqlite.introductiondb"}
15)
16public class SimpleDatabase extends KittyDatabase {
17    /**
18     * KittyORM main database class that represents bootstrap and holder for all related with database
19     * components.
20     * <br> See {@link KittyDatabase#KittyDatabase(Context, String)} for more info.
21     *
22     * @param ctx
23     */
24    public SimpleDatabase(Context ctx) {
25        super(ctx);
26    }
27}

Click to view SimpleExampleModel.class
 1package net.akaish.kittyormdemo.sqlite.introductiondb;
 2
 3import net.akaish.kitty.orm.KittyModel;
 4import net.akaish.kitty.orm.annotations.column.KITTY_COLUMN;
 5import net.akaish.kitty.orm.annotations.table.KITTY_TABLE;
 6
 7@KITTY_TABLE
 8public class SimpleExampleModel extends KittyModel {
 9    public SimpleExampleModel() {
10        super();
11    }
12
13    @KITTY_COLUMN(
14            isIPK = true,
15            columnOrder = 0
16    )
17    public Long id;
18
19    @KITTY_COLUMN(columnOrder = 1)
20    public int randomInteger;
21
22    @KITTY_COLUMN(columnOrder = 2)
23    public String firstName;
24
25    @Override
26    public String toString() {
27        StringBuilder sb = new StringBuilder(64);
28        return sb.append("[ rowid = ")
29                    .append(getRowID())
30                    .append(" ; id = ")
31                    .append(id)
32                    .append(" ; randomInteger = ")
33                    .append(randomInteger)
34                    .append(" ; firstName = ")
35                    .append(firstName)
36                    .append(" ]")
37                    .toString();
38    }
39}

Click to view RandomSimpleExampleModelUtil.class
 1package net.akaish.kittyormdemo.sqlite.introductiondb.util;
 2
 3import net.akaish.kittyormdemo.sqlite.introductiondb.SimpleExampleModel;
 4
 5import java.util.Random;
 6
 7/**
 8 * Created by akaish on 21.08.18.
 9 */
10
11public class RandomSimpleExampleModelUtil {
12
13    private static String NAMES[] = new String[] {"Adam", "Ada", "Joseph", "Michel", "Mickie", "Boris", "Denis", "Denise", "Alexander", "Irina"};
14
15    public static SimpleExampleModel randomSEModel() {
16        SimpleExampleModel m = new SimpleExampleModel();
17        Random rnd = new Random();
18        m.randomInteger = rnd.nextInt(1000);
19        m.firstName = NAMES[rnd.nextInt(10)];
20        return m;
21    }
22}

“RUN CRUD OPERATIONS” code

Click to view GettingStartedTutorialCode.allInOne()
  1// Creating new instance of SimpleDatabase
  2SimpleDatabase simpleDatabase = new SimpleDatabase(context);
  3
  4KittyMapper mapper = simpleDatabase.getMapper(SimpleExampleModel.class);
  5
  6// Counting records in db table and deleting them if table not empty
  7if(mapper.countAll() > 0)
  8      mapper.deleteAll();
  9// Insert new model example
 10// Creating and setting three new models
 11SimpleExampleModel alex = new SimpleExampleModel();
 12
 13alex.randomInteger = 545141;
 14alex.firstName = "Alex";
 15
 16SimpleExampleModel marina = new SimpleExampleModel();
 17
 18marina.randomInteger = 228;
 19marina.firstName = "Marina";
 20
 21SimpleExampleModel marina2 = new SimpleExampleModel();
 22
 23marina2.randomInteger = 445555;
 24marina2.firstName = "Marina";
 25
 26// Saving those models
 27// Saving model with mapper.save(M model)
 28mapper.save(alex);
 29mapper.save(marina2);
 30
 31// Saving model with mapper.insert(M model)
 32// Better to use insert(M model) for new DB records cause it is little bit faster
 33long marinaRowid = mapper.insert(marina);
 34
 35
 36// Finding existing records in DB and mapping them to entities
 37
 38int findOperationId = 0;
 39List<SimpleExampleModel> marinas;
 40
 41// find with condition
 42SQLiteConditionBuilder builder = new SQLiteConditionBuilder();
 43builder.addColumn("first_name")
 44       .addSQLOperator(SQLiteOperator.EQUAL)
 45       .addValue("Marina");
 46marinas = mapper.findWhere(builder.build());
 47
 48// find with condition (you may use shorter syntax)
 49builder = new SQLiteConditionBuilder();
 50builder.addColumn("first_name")
 51       .addSQLOperator("=") // You may use string operators instead SQLiteOperator enum element
 52       .addValue("Marina");
 53marinas = mapper.findWhere(builder.build());
 54
 55// find with condition (without query builder)
 56marinas = mapper.findWhere("first_name = ?", "Marina");
 57
 58// find with condition (pass POJO field name as parameter, in ?#fieldName; form)
 59marinas = mapper.findWhere("?#firstName; = ?", "Marina");
 60
 61
 62findOperationId++;
 63// find with RowID
 64SimpleExampleModel marinaFromTableRowid = mapper.findByRowID(marinaRowid);
 65
 66findOperationId++;
 67// find with IPK
 68SimpleExampleModel marinaFromTableIPK = mapper.findByIPK(marinaFromTableRowid.id);
 69
 70findOperationId++;
 71// find with KittyPrimaryKey
 72KittyPrimaryKey pk = new KittyPrimaryKeyBuilder()
 73        .addKeyColumnValue("id", marinaFromTableRowid.id.toString())
 74        .build();
 75SimpleExampleModel marinaFromTableKPK = mapper.findByPK(pk);
 76
 77
 78// Generating and inserting list of 10 random models
 79List<SimpleExampleModel> randomModels = new LinkedList<>();
 80for(int i = 0; i < 10; i++)
 81    randomModels.add(RandomSimpleExampleModelUtil.randomSEModel());
 82mapper.save(randomModels);
 83
 84// Deleting some models
 85// Deleting by entity, make sure that entity has RowID\IPK\PK set
 86SQLiteCondition alexCondition = new SQLiteConditionBuilder()
 87                .addColumn("first_name")
 88                .addSQLOperator(SQLiteOperator.EQUAL)
 89                .addValue("Alex")
 90                .build();
 91SimpleExampleModel alexToDelete = mapper.findFirst(alexCondition);
 92mapper.delete(alexToDelete);
 93
 94
 95// Deleting with condition
 96mapper.deleteWhere("random_integer = ?", marina2.randomInteger);
 97
 98// Updating models
 99// updating current model
100// if model has RowId or IPK or PrimaryKey values set (3-rd is slowest) just
101SimpleExampleModel newMarina = marinaFromTableIPK.clone(SimpleExampleModel.class);
102newMarina.randomInteger = 1337;
103if(mapper.update(newMarina) > 0) {
104    findOperationId++;
105    SimpleExampleModel marinaFromTableIPK2 = mapper.findByIPK(marinaFromTableRowid.id);
106}
107
108// another option is updating with generating query
109SimpleExampleModel updateMarina = new SimpleExampleModel();
110updateMarina.randomInteger = 121212;
111builder = new SQLiteConditionBuilder();
112builder.addColumn("first_name")
113       .addSQLOperator(SQLiteOperator.EQUAL)
114       .addValue("Marina");
115if(mapper.update(updateMarina, builder.build(), new String[]{"randomInteger"}, CVUtils.INCLUDE_ONLY_SELECTED_FIELDS) > 0) {
116    findOperationId++;
117    // find with IPK
118    SimpleExampleModel marinaFromTableIPK2 = mapper.findByIPK(marinaFromTableRowid.id);
119}
120
121// bulk operations in TX mode
122LinkedList<SimpleExampleModel> randModels = new LinkedList<>();
123for(int i = 0; i < 10; i++)
124    randModels.add(RandomSimpleExampleModelUtil.randomSEModel());
125mapper.saveInTransaction(randModels);
126
127// closing mapper
128mapper.close();

Lesson’s activity fragment

Click to view Lesson1Tab2GettingStarted.class
  1package net.akaish.kittyormdemo.lessons.one;
  2
  3import android.os.Bundle;
  4import android.util.Log;
  5import android.view.LayoutInflater;
  6import android.view.MotionEvent;
  7import android.view.View;
  8import android.view.ViewGroup;
  9import android.widget.Button;
 10import android.widget.ListView;
 11import android.widget.TextView;
 12
 13import net.akaish.kitty.orm.CVUtils;
 14import net.akaish.kitty.orm.KittyMapper;
 15import net.akaish.kitty.orm.pkey.KittyPrimaryKey;
 16import net.akaish.kitty.orm.pkey.KittyPrimaryKeyBuilder;
 17import net.akaish.kitty.orm.query.conditions.SQLiteCondition;
 18import net.akaish.kitty.orm.query.conditions.SQLiteConditionBuilder;
 19import net.akaish.kitty.orm.query.conditions.SQLiteOperator;
 20import net.akaish.kitty.orm.util.KittyLog;
 21import net.akaish.kittyormdemo.KittyTutorialActivity;
 22import net.akaish.kittyormdemo.R;
 23import net.akaish.kittyormdemo.lessons.LessonTabFragmentOnVisibleAction;
 24import net.akaish.kittyormdemo.lessons.adapters.BasicArrayAdapter;
 25import net.akaish.kittyormdemo.lessons.LessonBaseFragment;
 26import net.akaish.kittyormdemo.sqlite.introductiondb.SimpleDatabase;
 27import net.akaish.kittyormdemo.sqlite.introductiondb.SimpleExampleModel;
 28import net.akaish.kittyormdemo.sqlite.introductiondb.util.RandomSimpleExampleModelUtil;
 29
 30import java.util.Iterator;
 31import java.util.LinkedList;
 32import java.util.List;
 33
 34import static java.text.MessageFormat.format;
 35import static net.akaish.kittyormdemo.lessons.LessonsUriConstants.L1_T2_SCHEMA;
 36import static net.akaish.kittyormdemo.lessons.LessonsUriConstants.L1_T2_SOURCE;
 37import static net.akaish.kittyormdemo.lessons.LessonsUriConstants.L1_T2_TUTORIAL;
 38
 39/**
 40 * Created by akaish on 21.08.18.
 41 * @author akaish (Denis Bogomolov)
 42 */
 43
 44public class Lesson1Tab2GettingStarted extends LessonBaseFragment implements LessonTabFragmentOnVisibleAction {
 45
 46    private ListView actionsLW;
 47    private Button goButton;
 48
 49    private ListView expandedLW;
 50    private TextView expandedText;
 51    private String expandedTextPattern;
 52
 53    public Lesson1Tab2GettingStarted() {}
 54
 55    @Override
 56    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 57        View rootView = inflater.inflate(R.layout.lesson1_tab2_getting_started, container, false);
 58        actionsLW = rootView.findViewById(R.id.l1_t2_actions);
 59        goButton = rootView.findViewById(R.id.l1_t2_go_button);
 60        goButton.setOnClickListener(new View.OnClickListener() {
 61            @Override
 62            public void onClick(View v) {
 63                go();
 64            }
 65        });
 66        expandedLW = rootView.findViewById(R.id._l1_t2_expanded_panel_list);
 67        expandedText = rootView.findViewById(R.id._l1_t2_expanded_panel_text);
 68        expandedTextPattern = getString(R.string._l1_t2_expanded_text_pattern);
 69        rootView.findViewById(R.id.l1_t2_clear_button).setOnClickListener(new View.OnClickListener() {
 70            @Override
 71            public void onClick(View v) {
 72                clear();
 73            }
 74        });
 75        return rootView;
 76    }
 77
 78    @Override
 79    public void onResume() {
 80        super.onResume();
 81        updateExpandPanelList();
 82    }
 83
 84    void clear() {
 85        SimpleDatabase simpleDatabase = new SimpleDatabase(getContext());
 86        KittyMapper mapper = simpleDatabase.getMapper(SimpleExampleModel.class);
 87        if(actionsLW != null) {
 88            actionsLW.setAdapter(new BasicArrayAdapter(getContext(), new LinkedList<String>()));
 89            actionsLW.setOnTouchListener(new View.OnTouchListener() {
 90
 91                // Setting on Touch Listener for handling the touch inside ScrollView
 92                @Override
 93                public boolean onTouch(View v, MotionEvent event) {
 94                    // Disallow the touch request for parent scroll on touch of child view
 95                    v.getParent().requestDisallowInterceptTouchEvent(true);
 96                    return false;
 97                }
 98            });
 99            addActionListItem(format(getString(R.string._l1_t2_count), mapper.countAll()));
100            addActionListItem(format(getString(R.string._l1_t2_clear), mapper.deleteAll()));
101            updateExpandPanelList();
102        }
103        mapper.close();
104    }
105
106    private static final String NST_LOGTAG = "NST_LOGTAG";
107
108    private void newSyntaxTest() {
109        SimpleDatabase simpleDatabase = new SimpleDatabase(getContext());
110        KittyMapper mapper = simpleDatabase.getMapper(SimpleExampleModel.class);
111        Log.e(NST_LOGTAG, "1: adding ten rgen models");
112        LinkedList<SimpleExampleModel> randModels = new LinkedList<>();
113        for(int i = 0; i < 10; i++)
114            randModels.add(RandomSimpleExampleModelUtil.randomSEModel());
115        mapper.saveInTransaction(randModels);
116        Log.e(NST_LOGTAG, "2: adding at least two Pavels");
117        SimpleExampleModel p1 = new SimpleExampleModel(); p1.randomInteger = 1; p1.firstName = "pavel";
118        SimpleExampleModel p2 = new SimpleExampleModel(); p2.randomInteger = 2; p2.firstName = "pavel";
119        Log.e(NST_LOGTAG, "#" + mapper.insert(p1));
120        Log.e(NST_LOGTAG, "#" + mapper.insert(p2));
121        mapper.save(p2);
122        List<SimpleExampleModel> pavels = mapper.findWhere("#?firstName = ?", "pavel");
123        Iterator<SimpleExampleModel> pavelsI = pavels.iterator();
124        while (pavelsI.hasNext())
125            Log.e(NST_LOGTAG, "3: " + pavelsI.next().toString());
126        Log.e(NST_LOGTAG, "4: adding at least one Morty");
127        SimpleExampleModel d1 = new SimpleExampleModel(); d1.randomInteger = 228; d1.firstName = "Morty";
128        mapper.save(d1);
129        SQLiteConditionBuilder sqb = new SQLiteConditionBuilder();
130        sqb.addColumn("first_name").addSQLOperator("=").addValue("Morty");
131        List<SimpleExampleModel> mortys = mapper.findWhere(sqb.build());
132        Iterator<SimpleExampleModel> mI = mortys.iterator();
133        while (mI.hasNext())
134            Log.e(NST_LOGTAG, "5: " + mI.next().toString());
135        Log.e(NST_LOGTAG, "6: " + mapper.countWhere("first_name = ?", "pavel"));
136        Log.e(NST_LOGTAG, "7: " + mapper.countAll());
137        Log.e(NST_LOGTAG, "8: " + mapper.deleteWhere("first_name = ?", "pavel"));
138        Log.e(NST_LOGTAG, "9: " + mapper.countAll());
139        Log.e(NST_LOGTAG, "0: " + mapper.deleteAll());
140        mapper.close();
141    }
142
143    void go() {
144        if(actionsLW != null) {
145            actionsLW.setAdapter(new BasicArrayAdapter(getContext(), new LinkedList<String>()));
146            actionsLW.setOnTouchListener(new View.OnTouchListener() {
147
148                // Setting on Touch Listener for handling the touch inside ScrollView
149                @Override
150                public boolean onTouch(View v, MotionEvent event) {
151                    // Disallow the touch request for parent scroll on touch of child view
152                    v.getParent().requestDisallowInterceptTouchEvent(true);
153                    return false;
154                }
155            });
156
157            // Creating new instance of SimpleDatabase
158            SimpleDatabase simpleDatabase = new SimpleDatabase(getContext());
159
160            // Printing generated by KittyORM schema create and drop scripts
161            simpleDatabase.printPregeneratedCreateSchemaToLog("KITTY_ORM_DEMO_L1T2");
162            simpleDatabase.printPregeneratedDropSchemaToLog("KITTY_ORM_DEMO_L1T2");
163
164            // Printing registry to log (e.g. collection of KittyModels->KittyMappers that would be used)
165            simpleDatabase.printRegistryToLog(KittyLog.LOG_LEVEL.E);
166            KittyMapper mapper = simpleDatabase.getMapper(SimpleExampleModel.class);
167
168            // Counting records in db table and deleting them if table not empty
169            if(mapper.countAll() > 0) {
170                addActionListItem(format(getString(R.string._l1_t2_count), mapper.countAll()));
171                addActionListItem(format(getString(R.string._l1_t2_clear), mapper.deleteAll()));
172            }
173
174            // Insert new model example
175            // Creating and setting three new models
176            SimpleExampleModel alex = new SimpleExampleModel();
177
178            alex.randomInteger = 545141;
179            alex.firstName = "Alex";
180
181            SimpleExampleModel marina = new SimpleExampleModel();
182
183            marina.randomInteger = 228;
184            marina.firstName = "Marina";
185
186            SimpleExampleModel marina2 = new SimpleExampleModel();
187
188            marina2.randomInteger = 445555;
189            marina2.firstName = "Marina";
190
191            addActionListItem(format(getString(R.string._l1_t2_inserting), alex));
192            addActionListItem(format(getString(R.string._l1_t2_inserting), marina));
193            addActionListItem(format(getString(R.string._l1_t2_inserting), marina2));
194
195            // Saving those models
196            // Saving model with mapper.save(M model)
197            mapper.save(alex);
198            mapper.save(marina2);
199
200            // Saving model with mapper.insert(M model)
201            // Better to use insert(M model) for new DB records cause it is little bit faster
202            long marinaRowid = mapper.insert(marina);
203
204
205            addActionListItem(format(getString(R.string._l1_t2_inserted), alex));
206            addActionListItem(format(getString(R.string._l1_t2_inserted), marina));
207            addActionListItem(format(getString(R.string._l1_t2_inserted), marina2));
208
209            addActionListItem(format(getString(R.string._l1_t2_count), mapper.countAll()));
210
211
212            // Finding existing records in DB and mapping them to entities
213
214            int findOperationId = 0;
215            // find with condition
216            addActionListItem(format(getContext().getString(R.string._l1_t2_retrieving), "mapper.findWhere", "WHERE first_name = Marina", findOperationId));
217            SQLiteConditionBuilder builder = new SQLiteConditionBuilder();
218            builder.addColumn("first_name")
219                    .addSQLOperator(SQLiteOperator.EQUAL)
220                    .addValue("Marina");
221            List<SimpleExampleModel> marinas = mapper.findWhere(builder.build());
222            // Also you may define conditions in alternative way
223            marinas = mapper.findWhere(SQLiteConditionBuilder.fromSQL("first_name = ?", null, "Marina"));
224            // Or specify field name instead column name using following syntax
225            marinas = mapper.findWhere(SQLiteConditionBuilder.fromSQL("#?firstName = ?", SimpleExampleModel.class, "Marina"));
226            if(marinas != null) {
227                addActionListItem(format(getString(R.string._l1_t2_retrieved),  marinas.size(), findOperationId));
228            }
229            int marinasCounter = 0;
230            for(SimpleExampleModel m : marinas) {
231                addActionListItem(format(getString(R.string._l1_t2_retrieved_model_show),  findOperationId, marinasCounter, m));
232                marinasCounter++;
233            }
234
235            findOperationId++;
236            // find with RowID
237            addActionListItem(format(getString(R.string._l1_t2_retrieving), "mapper.findByRowID", "RowID = "+marinaRowid, findOperationId));
238            SimpleExampleModel marinaFromTableRowid = mapper.findByRowID(marinaRowid);
239            if(marinaFromTableRowid != null) {
240                addActionListItem(format(getString(R.string._l1_t2_retrieved),  1, findOperationId));
241                addActionListItem(format(getString(R.string._l1_t2_retrieved_model_show),  findOperationId, 0, marinaFromTableRowid));
242            }
243
244            findOperationId++;
245            // find with IPK
246            addActionListItem(format(getContext().getString(R.string._l1_t2_retrieving), "mapper.findByIPK", "IPK = "+marinaFromTableRowid.id, findOperationId));
247            SimpleExampleModel marinaFromTableIPK = mapper.findByIPK(marinaFromTableRowid.id);
248            if(marinaFromTableIPK != null) {
249                addActionListItem(format(getString(R.string._l1_t2_retrieved),  1, findOperationId));
250                addActionListItem(format(getString(R.string._l1_t2_retrieved_model_show),  findOperationId, 0, marinaFromTableIPK));
251            }
252
253            findOperationId++;
254            // find with KittyPrimaryKey
255            addActionListItem(format(format(getString(R.string._l1_t2_retrieving), "mapper.findByPK", "KittyPrimaryKey [ id = "+marinaFromTableRowid.id, findOperationId)));
256            KittyPrimaryKey pk = new KittyPrimaryKeyBuilder()
257                                            .addKeyColumnValue("id", marinaFromTableRowid.id.toString())
258                                            .build();
259            SimpleExampleModel marinaFromTableKPK = mapper.findByPK(pk);
260            if(marinaFromTableKPK != null) {
261                addActionListItem(format(getString(R.string._l1_t2_retrieved),  1, findOperationId));
262                addActionListItem(format(getString(R.string._l1_t2_retrieved_model_show),  findOperationId, 0, marinaFromTableKPK));
263            }
264
265            // Generating and inserting list of 10 random models
266            List<SimpleExampleModel> randomModels = new LinkedList<>();
267            for(int i = 0; i < 10; i++)
268                randomModels.add(RandomSimpleExampleModelUtil.randomSEModel());
269            mapper.save(randomModels);
270            addActionListItem(getString(R.string._l1_t2_random_save));
271
272            addActionListItem(format(getString(R.string._l1_t2_count), mapper.countAll()));
273
274            // Deleting some models
275            // Deleting by entity, make sure that entity has RowID\IPK\PK set
276            SQLiteCondition alexCondition = new SQLiteConditionBuilder()
277                                                        .addColumn("first_name")
278                                                        .addSQLOperator(SQLiteOperator.EQUAL)
279                                                        .addValue("Alex")
280                                                        .build();
281            SimpleExampleModel alexToDelete = mapper.findFirst(alexCondition);
282            if(alexToDelete!=null) {
283                addActionListItem(getString(R.string._l1_t2_one_alex_to_delete_found));
284                if(mapper.delete(alexToDelete) > 0) {
285                    addActionListItem(getString(R.string._l1_t2_one_alex_deleted));
286                    addActionListItem(format(getString(R.string._l1_t2_count), mapper.countAll()));
287                }
288            }
289
290            // Deleting with condition
291            SQLiteCondition marina445555Condition = new SQLiteConditionBuilder()
292                                                            .addColumn("random_integer")
293                                                            .addSQLOperator(SQLiteOperator.EQUAL)
294                                                            .addValue(marina2.randomInteger)
295                                                            .build();
296            addActionListItem(getString(R.string._l1_2_one_marina_deleting));
297            if(mapper.deleteWhere(marina445555Condition) > 0) {
298                addActionListItem(getString(R.string._l1_2_one_marina_deleted));
299                addActionListItem(format(getString(R.string._l1_t2_count), mapper.countAll()));
300            }
301
302            // Updating models
303            // updating current model
304            // if model has RowId or IPK or PrimaryKey values set (3-rd is slowest) just
305            SimpleExampleModel oldMarina = marinaFromTableIPK.clone(SimpleExampleModel.class);
306            SimpleExampleModel newMarina = marinaFromTableIPK.clone(SimpleExampleModel.class);
307            newMarina.randomInteger = 1337;
308            addActionListItem(format(getString(R.string._l1_t2_updating_entity), oldMarina, newMarina));
309            if(mapper.update(newMarina) > 0) {
310                addActionListItem(format(getString(R.string._l1_t2_updated), oldMarina, newMarina));
311                findOperationId++;
312                // find with IPK
313                addActionListItem(format(getContext().getString(R.string._l1_t2_retrieving), "mapper.findByIPK", "IPK = "+marinaFromTableRowid.id, findOperationId));
314                SimpleExampleModel marinaFromTableIPK2 = mapper.findByIPK(marinaFromTableRowid.id);
315                if(marinaFromTableIPK != null) {
316                    addActionListItem(format(getString(R.string._l1_t2_retrieved),  1, findOperationId));
317                    addActionListItem(format(getString(R.string._l1_t2_retrieved_model_show),  findOperationId, 0, marinaFromTableIPK2));
318                    addActionListItem(format(getString(R.string._l1_t2_count), mapper.countAll()));
319                }
320            }
321
322            // another option is updating with generating query
323            SimpleExampleModel updateMarina = new SimpleExampleModel();
324            updateMarina.randomInteger = 121212;
325            addActionListItem(format(getString(R.string._l1_t2_updating_query_like), updateMarina));
326            builder = new SQLiteConditionBuilder();
327            builder.addColumn("first_name")
328                    .addSQLOperator(SQLiteOperator.EQUAL)
329                    .addValue("Marina");
330            if(mapper.update(updateMarina, builder.build(), new String[]{"randomInteger"}, CVUtils.INCLUDE_ONLY_SELECTED_FIELDS) > 0) {
331                addActionListItem(format(getString(R.string._l1_t2_updating_query_like_updated), updateMarina));
332                findOperationId++;
333                // find with IPK
334                addActionListItem(format(getContext().getString(R.string._l1_t2_retrieving), "mapper.findByIPK", "IPK = "+marinaFromTableRowid.id, findOperationId));
335                SimpleExampleModel marinaFromTableIPK2 = mapper.findByIPK(marinaFromTableRowid.id);
336                if(marinaFromTableIPK != null) {
337                    addActionListItem(format(getString(R.string._l1_t2_retrieved),  1, findOperationId));
338                    addActionListItem(format(getString(R.string._l1_t2_retrieved_model_show),  findOperationId, 0, marinaFromTableIPK2));
339                    addActionListItem(format(getString(R.string._l1_t2_count), mapper.countAll()));
340                }
341            }
342
343            // bulk operations in TX mode
344            LinkedList<SimpleExampleModel> randModels = new LinkedList<>();
345            for(int i = 0; i < 10; i++)
346                randModels.add(RandomSimpleExampleModelUtil.randomSEModel());
347            mapper.saveInTransaction(randModels);
348            addActionListItem(getString(R.string._l1_t2_random_save));
349
350            addActionListItem(format(getString(R.string._l1_t2_count), mapper.countAll()));
351
352            // closing mapper
353            mapper.close();
354
355            updateExpandPanelList();
356        }
357    }
358
359    void updateExpandPanelList() {
360        if (expandedText != null && expandedLW != null && expandedTextPattern != null) {
361            SimpleDatabase sdb = new SimpleDatabase(getContext());
362            KittyMapper mapper = sdb.getMapper(SimpleExampleModel.class);
363            expandedText.setText(format(expandedTextPattern, mapper.countAll()));
364            List<SimpleExampleModel> models = mapper.findAll();
365            if (models == null) {
366                models = new LinkedList<>();
367            }
368            LinkedList<String> modelsToString = new LinkedList<>();
369            Iterator<SimpleExampleModel> modelIterator = models.iterator();
370            while (modelIterator.hasNext()) {
371                modelsToString.addLast(modelIterator.next().toString());
372            }
373            expandedLW.setAdapter(new BasicArrayAdapter(getContext(), modelsToString));
374            expandedLW.setOnTouchListener(new View.OnTouchListener() {
375
376                // Setting on Touch Listener for handling the touch inside ScrollView
377                @Override
378                public boolean onTouch(View v, MotionEvent event) {
379                    // Disallow the touch request for parent scroll on touch of child view
380                    v.getParent().requestDisallowInterceptTouchEvent(true);
381                    return false;
382                }
383            });
384
385            mapper.close();
386        }
387    }
388
389    void addActionListItem(String item) {
390        if(actionsLW != null) {
391            ((BasicArrayAdapter)actionsLW.getAdapter()).addItemLast(item);
392            ((BasicArrayAdapter) actionsLW.getAdapter()).notifyDataSetChanged();
393        }
394    }
395
396    // Fab menu section
397
398    @Override
399    public View.OnClickListener helpFabMenuAction() {
400        return new View.OnClickListener() {
401
402            /**
403             * Called when a view has been clicked.
404             *
405             * @param v The view that was clicked.
406             */
407            @Override
408            public void onClick(View v) {
409                ((KittyTutorialActivity) getParentFragment().getActivity()).showWebViewDialog(L1_T2_TUTORIAL);
410            }
411        };
412    }
413
414    @Override
415    public View.OnClickListener sourceFabMenuAction() {
416        return new View.OnClickListener() {
417
418            /**
419             * Called when a view has been clicked.
420             *
421             * @param v The view that was clicked.
422             */
423            @Override
424            public void onClick(View v) {
425                ((KittyTutorialActivity) getParentFragment().getActivity()).showWebViewDialog(L1_T2_SOURCE);
426            }
427        };
428    }
429
430    @Override
431    public View.OnClickListener schemaFabMenuAction() {
432        return new View.OnClickListener() {
433
434            /**
435             * Called when a view has been clicked.
436             *
437             * @param v The view that was clicked.
438             */
439            @Override
440            public void onClick(View v) {
441                ((KittyTutorialActivity) getParentFragment().getActivity()).showWebViewDialog(L1_T2_SCHEMA);
442            }
443        };
444    }
445
446    @Override
447    protected int snackbarMessageResource() {
448        return R.string._l1_t2_snackbar_message;
449    }
450
451    @Override
452    public void onVisible() {
453
454    }
455}