// Path: src/main/java/com/javaquery/bean/Item.java
// public class Item {
// 
//     private Long id;
//     private String name;
//     private Double price;
// 
//     public Item() {
//     }
//     
//     public Item(String name, Double price) {
//         this.name = name;
//         this.price = price;
//     }
//     
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
//     
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public Double getPrice() {
//         return price;
//     }
// 
//     public void setPrice(Double price) {
//         this.price = price;
//     }
//     
//     public Comparator<Item> orderByNameASC(){
//         return new Comparator<Item>() {
//             @Override
//             public int compare(Item o1, Item o2) {
//                 if(o1 != null && o1.getName() != null
//                         && o2 != null && o2.getName() != null){
//                     return o1.getName().compareTo(o2.getName());
//                 }
//                 return -1;
//             }
//         };
//     }
//     
//     public Comparator<Item> orderByNameDESC(){
//         return new Comparator<Item>() {
//             @Override
//             public int compare(Item o1, Item o2) {
//                 if(o1 != null && o1.getName() != null
//                         && o2 != null && o2.getName() != null){
//                     return o2.getName().compareTo(o1.getName());
//                 }
//                 return -1;
//             }
//         };
//     }
// 
//     @Override
//     public String toString() {
//         return "Item{" + "name=" + name + ", price=" + price + '}';
//     }
// }


import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.javaquery.bean.Item;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.concurrent.CountDownLatch;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.javaquery.google.firebase;


/**
 * Example of Firebase save.
 *
 * @author javaQuery
 * @date 7th September, 2016
 * @Github: https://github.com/javaquery/Examples
 */
public class FirebaseSaveObject {

    public static void main(String[] args) {
        Item item = new Item();
        item.setId(1L);
        item.setName("MotoG");
        item.setPrice(100.12);

        // save item objec to firebase.
        new FirebaseSaveObject().save(item);
    }

    private FirebaseDatabase firebaseDatabase;

    /**
     * initialize firebase.
     */
    private void initFirebase() {
        try {
            // .setDatabaseUrl("https://fir-66f50.firebaseio.com") - Firebase project url.
            // .setServiceAccount(new FileInputStream(new File("filepath"))) - Firebase private key file path.
            FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
                    .setDatabaseUrl("https://fir-66f50.firebaseio.com")
                    .setServiceAccount(new FileInputStream(new File("C:\\Users\\Vicky\\Documents\\NetBeansProjects\\Examples\\src\\com\\javaquery\\google\\firebase\\Firebase-30f95674f4d5.json")))
                    .build();

            FirebaseApp.initializeApp(firebaseOptions);
            firebaseDatabase = FirebaseDatabase.getInstance();
        } catch (FileNotFoundException ex) {
// Path: src/main/java/com/javaquery/bean/Item.java
// public class Item {
// 
//     private Long id;
//     private String name;
//     private Double price;
// 
//     public Item() {
//     }
//     
//     public Item(String name, Double price) {
//         this.name = name;
//         this.price = price;
//     }
//     
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
//     
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public Double getPrice() {
//         return price;
//     }
// 
//     public void setPrice(Double price) {
//         this.price = price;
//     }
//     
//     public Comparator<Item> orderByNameASC(){
//         return new Comparator<Item>() {
//             @Override
//             public int compare(Item o1, Item o2) {
//                 if(o1 != null && o1.getName() != null
//                         && o2 != null && o2.getName() != null){
//                     return o1.getName().compareTo(o2.getName());
//                 }
//                 return -1;
//             }
//         };
//     }
//     
//     public Comparator<Item> orderByNameDESC(){
//         return new Comparator<Item>() {
//             @Override
//             public int compare(Item o1, Item o2) {
//                 if(o1 != null && o1.getName() != null
//                         && o2 != null && o2.getName() != null){
//                     return o2.getName().compareTo(o1.getName());
//                 }
//                 return -1;
//             }
//         };
//     }
// 
//     @Override
//     public String toString() {
//         return "Item{" + "name=" + name + ", price=" + price + '}';
//     }
// }


// Path: src/main/java/com/javaquery/google/firebase/FirebaseSaveObject.java
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.javaquery.bean.Item;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.concurrent.CountDownLatch;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.javaquery.google.firebase;


/**
 * Example of Firebase save.
 *
 * @author javaQuery
 * @date 7th September, 2016
 * @Github: https://github.com/javaquery/Examples
 */
public class FirebaseSaveObject {

    public static void main(String[] args) {
        Item item = new Item();
        item.setId(1L);
        item.setName("MotoG");
        item.setPrice(100.12);

        // save item objec to firebase.
        new FirebaseSaveObject().save(item);
    }

    private FirebaseDatabase firebaseDatabase;

    /**
     * initialize firebase.
     */
    private void initFirebase() {
        try {
            // .setDatabaseUrl("https://fir-66f50.firebaseio.com") - Firebase project url.
            // .setServiceAccount(new FileInputStream(new File("filepath"))) - Firebase private key file path.
            FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
                    .setDatabaseUrl("https://fir-66f50.firebaseio.com")
                    .setServiceAccount(new FileInputStream(new File("C:\\Users\\Vicky\\Documents\\NetBeansProjects\\Examples\\src\\com\\javaquery\\google\\firebase\\Firebase-30f95674f4d5.json")))
                    .build();

            FirebaseApp.initializeApp(firebaseOptions);
            firebaseDatabase = FirebaseDatabase.getInstance();
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();