当前位置: 首页>>代码示例>>Java>>正文


Java Query类代码示例

本文整理汇总了Java中com.google.firebase.database.Query的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Query类属于com.google.firebase.database包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDifferentIndependentQueries

import com.google.firebase.database.Query; //导入依赖的package包/类
@Test
public void testDifferentIndependentQueries() throws Exception {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
  Query query1 = ref.limitToFirst(1);
  Query query2 = ref.limitToFirst(2);

  query1.keepSynced(true);
  assertIsKeptSynced(query1);
  assertNotKeptSynced(query2);

  query2.keepSynced(true);
  assertIsKeptSynced(query1);
  assertIsKeptSynced(query2);

  query1.keepSynced(false);
  assertIsKeptSynced(query2);
  assertNotKeptSynced(query1);

  query2.keepSynced(false);
  assertNotKeptSynced(query1);
  assertNotKeptSynced(query2);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:23,代码来源:KeepSyncedTestIT.java

示例2: FirebaseItemAdapter

import com.google.firebase.database.Query; //导入依赖的package包/类
public FirebaseItemAdapter(Class<Item> modelClass, Query ref) {
    mModelClass = modelClass;
    mSnapshots = new FirebaseArray(ref);

    mSnapshots.setOnChangedListener(new FirebaseArray.OnChangedListener() {
        @Override
        public void onChanged(EventType type, int index, int oldIndex) {
            switch (type) {
                case Added:
                    notifyItemInserted(index);
                    break;
                case Changed:
                    notifyItemChanged(index);
                    break;
                case Removed:
                    notifyItemRemoved(index);
                    break;
                case Moved:
                    notifyItemMoved(oldIndex, index);
                    break;
                default:
                    throw new IllegalStateException("Incomplete case statement");
            }
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:FirebaseItemAdapter.java

示例3: searchWithoutFilter

import com.google.firebase.database.Query; //导入依赖的package包/类
protected void searchWithoutFilter() {
    final String keyword = etSearch.getText().toString().trim();
    Query query = mDatabase.orderByChild("category").equalTo(keyword);

    mDatabase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(DataSnapshot snap : dataSnapshot.getChildren()) {
                String itemName = snap.child("itemName").getValue(String.class);
                if(itemName.toLowerCase().contains(keyword.toLowerCase())) {
                    items.add(itemName);
                    itemKeys.add(snap.getKey());
                }
            }
            loadListView();
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
开发者ID:ppdesai434,项目名称:MavsSnapUp,代码行数:23,代码来源:SearchActivity.java

示例4: loaditems

import com.google.firebase.database.Query; //导入依赖的package包/类
private void loaditems() {
    Query query = mDatabase.orderByChild("createdBy").equalTo(mAuth.getCurrentUser().getUid());
    query.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            items.clear();
            itemKey.clear();
            for(DataSnapshot snap : dataSnapshot.getChildren()) {
                if(snap.child("isItemSold").getValue(String.class)==null){
                    items.add(snap.child("itemName").getValue(String.class));
                    itemKey.add(snap.getKey());
                }
            }
            loadListView();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
开发者ID:ppdesai434,项目名称:MavsSnapUp,代码行数:23,代码来源:MyItemsActivity.java

示例5: getFollowingList

import com.google.firebase.database.Query; //导入依赖的package包/类
public void getFollowingList(String userId, final OnCompleteGetUserFollowingListener listener)
{
    RemoteDatabaseManager rdm = new RemoteDatabaseManager();

    Query recentPostsQuery = rdm.getUsersReference().child(userId).child("following")
            .limitToFirst(3000);
    recentPostsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            ArrayList<String> arrayList = new ArrayList<String>();

            for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) {
                String name = (String) messageSnapshot.getKey();
                Log.e("UserManager", "Name : "+ name);
                arrayList.add(name);
            }

            listener.onComplete(arrayList);
            followingListCache = arrayList;
        }

        @Override
        public void onCancelled(DatabaseError databaseError) { }
    });
}
 
开发者ID:icaynia,项目名称:pracler,代码行数:26,代码来源:UserManager.java

示例6: findBookSearch

import com.google.firebase.database.Query; //导入依赖的package包/类
public Query findBookSearch(String userId, String folderId) {
    if (folderId == null) {

        return mDatabaseReference.child(userId)
                .child(REF_FOLDERS)
                .child(REF_MY_BOOKS_FOLDER)
                .child(REF_BOOKS)
                .orderByChild("volumeInfo/searchField");

    } else {

        return mDatabaseReference.child(userId)
                .child(REF_FOLDERS)
                .child(folderId)
                .child(REF_BOOKS)
                .orderByChild("volumeInfo/searchField");

    }
}
 
开发者ID:victoraldir,项目名称:BuddyBook,代码行数:20,代码来源:FirebaseDatabaseHelper.java

示例7: singleValue

import com.google.firebase.database.Query; //导入依赖的package包/类
@NonNull public static Observable<DataSnapshot> singleValue(final Query query) {
    return Observable.create(new Observable.OnSubscribe<DataSnapshot>() {
        @Override public void call(final Subscriber<? super DataSnapshot> subscriber) {
            final ValueEventListener valueEvent = query.addValueEventListener(new ValueEventListener() {
                @Override public void onDataChange(DataSnapshot dataSnapshot) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(dataSnapshot);
                    }
                }
                @Override public void onCancelled(DatabaseError databaseError) {
                    subscriber.onError(databaseError.toException());
                }
            });
            subscriber.add(Subscriptions.create(new Action0() {
                @Override public void call() {
                    query.removeEventListener(valueEvent);
                }
            }));
        }
    });
}
 
开发者ID:isfaaghyth,项目名称:RxFBase,代码行数:22,代码来源:RxFirebase.java

示例8: onResume

import com.google.firebase.database.Query; //导入依赖的package包/类
@Override
protected void onResume() {
    super.onResume();

    Query listenNewNotif = FirebaseDatabase
            .getInstance()
            .getReference(getString(R.string.firebase_key_last_notif))
            .child(getString(R.string.firebase_key_notif_id));
    listenNewNotif.keepSynced(true);
    final DatabaseHelper dbHelper = new DatabaseHelper(this);
    listenNewNotif.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            if(dbHelper.getUnreadCount()>0 && notifMenu!=null){
                notifMenu.setIcon(getResources().getDrawable(R.drawable.ic_notification_new));
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.d(TAG,databaseError.getMessage());
        }
    });
}
 
开发者ID:CSI-KJSCE,项目名称:CSI-KJSCEOfficial,代码行数:26,代码来源:MainActivity.java

示例9: getObjects

import com.google.firebase.database.Query; //导入依赖的package包/类
public <T> Observable<T> getObjects(final Query query, final Class<T> objectClass, final boolean useRootElement) {
    return Observable.create(new Observable.OnSubscribe<T>() {
        @Override
        public void call(final Subscriber<? super T> subscriber) {
            query.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if(useRootElement) {
                        converter.convert(dataSnapshot, objectClass, subscriber);
                    } else {
                        for (DataSnapshot entry : dataSnapshot.getChildren()) {
                            converter.convert(entry, objectClass, subscriber);
                        }
                    }
                    subscriber.onCompleted();
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
        }
    });
}
 
开发者ID:florent37,项目名称:EasyFirebase,代码行数:26,代码来源:RxFirebaseHelper.java

示例10: observeSingleValueEvent

import com.google.firebase.database.Query; //导入依赖的package包/类
/**
 * Listener for a single change in te data at the given query location.
 *
 * @param query reference represents a particular location in your Database and can be used for reading or writing data to that Database location.
 * @return a {@link Maybe} which emits the actual state of the database for the given query.
 */
@NonNull
public static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) {
   return Maybe.create(new MaybeOnSubscribe<DataSnapshot>() {
      @Override
      public void subscribe(final MaybeEmitter<DataSnapshot> emitter) throws Exception {
         query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
               emitter.onSuccess(dataSnapshot);
               emitter.onComplete();
            }

            @Override
            public void onCancelled(DatabaseError error) {
               emitter.onError(new RxFirebaseDataException(error));
            }
         });
      }
   });
}
 
开发者ID:DVT,项目名称:showcase-android,代码行数:27,代码来源:RxFirebaseDatabase.java

示例11: populateProfile

import com.google.firebase.database.Query; //导入依赖的package包/类
public void populateProfile() {
    nameEt.setText(currentUser.getDisplayName());
    emailEt.setText(currentUser.getEmail());

    Query userQuery = databaseReference.child("users").child(currentUser.getUid());
    userQuery.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            try {
                User user = dataSnapshot.getValue(User.class);
                nameEt.setText(user.getName());
                emailEt.setText(user.getEmail());
                collegeEt.setText(user.getCollege());
                departmentEt.setText(user.getDepartment());
                yearEt.setText(String.valueOf(user.getYear()));
                mobileEt.setText(user.getMobile());
            } catch (Exception e) {
                Log.e("populateProfile", e.toString());
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
 
开发者ID:adithya321,项目名称:Instincts-2k17,代码行数:27,代码来源:RegisterActivity.java

示例12: open

import com.google.firebase.database.Query; //导入依赖的package包/类
/**
 * Creates a query for habit events from each user followed
 */
@Override
public void open() {
    recentEvents.clear();
    recentHabitEventMap.clear();

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -7);
    long millis = cal.getTimeInMillis();

    for (String id : idList) {
        Query eventsQuery = FirebaseDatabase.getInstance().getReference("events/" + id)
                .orderByChild("eventDate").startAt(millis).endAt(DateTime.now().getMillis());
        eventsQuery.addChildEventListener(this);
        activeQueries.add(eventsQuery);
    }
}
 
开发者ID:CMPUT301F17T13,项目名称:cat-is-a-dog,代码行数:20,代码来源:RecentHabitEventHistoryDataSource.java

示例13: open

import com.google.firebase.database.Query; //导入依赖的package包/类
/**
 * Creates one query per week up to 4 weeks in the past
 */
@Override
public void open() {
    completionResultArray.clear();
    completionRates = new double[4];
    completionLatch = new CountDownLatch(4);

    if(habit.getSchedule().size() > 0) {
        for(Week week : DateUtil.GetNPastWeeks(DateTime.now(), 4)) {
            String startKey = HabitEventDataModel.habitStampKey(habit.getKey(), week.getStartOfWeek());
            String endKey = HabitEventDataModel.habitStampKey(habit.getKey(), week.getEndOfWeek());

            Query eventCountQuery = FirebaseDatabase.getInstance().getReference("events/" + habit.getUserId())
                    .orderByChild("habitStamp").startAt(startKey).endAt(endKey);

            eventCountQuery.addValueEventListener(this);
            queryRegister.add(eventCountQuery);
        }
    }
}
 
开发者ID:CMPUT301F17T13,项目名称:cat-is-a-dog,代码行数:23,代码来源:CompletionMetricDataSource.java

示例14: getPostListByUser

import com.google.firebase.database.Query; //导入依赖的package包/类
public void getPostListByUser(final OnDataChangedListener<Post> onDataChangedListener, String userId) {
    DatabaseReference databaseReference = database.getReference("posts");
    Query postsQuery;
    postsQuery = databaseReference.orderByChild("authorId").equalTo(userId);

    postsQuery.keepSynced(true);
    postsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            PostListResult result = parsePostList((Map<String, Object>) dataSnapshot.getValue());
            onDataChangedListener.onListChanged(result.getPosts());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            LogUtil.logError(TAG, "getPostListByUser(), onCancelled", new Exception(databaseError.getMessage()));
        }
    });
}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:20,代码来源:DatabaseHelper.java

示例15: observe

import com.google.firebase.database.Query; //导入依赖的package包/类
private Observable<DataSnapshot> observe(final Query ref) {
    return Observable.create(emitter -> {
        final ValueEventListener listener =
                ref.addValueEventListener(new ValueEventListener() {
                    @Override public void onDataChange(DataSnapshot dataSnapshot) {
                        emitter.onNext(dataSnapshot);
                    }

                    @Override public void onCancelled(DatabaseError databaseError) {
                        emitter.onError(new FirebaseException(databaseError.getMessage()));
                    }
                });

        emitter.setCancellable(() -> ref.removeEventListener(listener));
    });
}
 
开发者ID:riteshakya037,项目名称:Wallpapers-Android-Clean-Architecture,代码行数:17,代码来源:Comments.java


注:本文中的com.google.firebase.database.Query类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。