Android Open Source - u2020-v2 Db Helper






From Project

Back to project page u2020-v2.

License

The source code is released under:

Apache License

If you think the Android project u2020-v2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gabor.database;
// w w  w  .j  a va 2 s .c  o m
import com.activeandroid.ActiveAndroid;
import com.activeandroid.query.Select;

import java.util.ArrayList;
import java.util.List;

public class DbHelper {

    public static void save(Car cars) {
        // Calls wrapped in transactions can be sped up by a factor of around 100.
        ActiveAndroid.beginTransaction();
        try {
            for (Car_ car : cars.getCars()) {
                CarT carT = new CarT();
                carT.title = car.getTitle();
                carT.date = car.getDate();
                carT.owner = car.getOwner();
                carT.pdf = car.getPdf();
                carT.save();
                for (String image : car.getImages()) {
                    ImagesT imagesT = new ImagesT();
                    imagesT.filename = image;
                    imagesT.car = carT;
                    imagesT.save();
                }
            }
            ActiveAndroid.setTransactionSuccessful();
        } finally {
            ActiveAndroid.endTransaction();
        }
    }

    public static Car toCar (List<CarT> cars) {
        List<Car_> outCars = new ArrayList<>();
        for (CarT car : cars) {
            Car_ out = new Car_();
            out.setTitle(car.title);
            out.setDate(car.date);
            out.setOwner(car.owner);
            out.setPdf(car.pdf);
            List<ImagesT> images = getImages(car);
            List<String> outImages = new ArrayList<>();
            for (ImagesT i : images)
                outImages.add(i.filename);
            out.setImages(outImages);
            outCars.add(out);
        }
        Car res = new Car();
        res.setCars(outCars);
        return res;
    }

    public static List<CarT> getCars() {
        return new Select()
                .from(CarT.class)
                .execute();
    }

    public static List<ImagesT> getImages(CarT car) {
         return new Select()
                .from(ImagesT.class)
                .where("CarT = ?", car.getId())
                .execute();
    }
}




Java Source Code List

com.gabor.common.io.IOUtils.java
com.gabor.database.CarT.java
com.gabor.database.Car.java
com.gabor.database.Car_.java
com.gabor.database.DbHelper.java
com.gabor.database.ImagesT.java
com.gabor.recyclerview.CustomAdapter.java
com.gabor.recyclerview.MainActivityTest.java
com.gabor.recyclerview.MainActivity.java
com.gabor.recyclerview.RecyclerViewFragment.java