如何构建gremlin查询以作为第一个事务添加和删除顶点

时间:2019-07-09 21:31:06

标签: python gremlin tinkerpop tinkerpop3

我想动态构建一个gremlin_python查询,该查询在单个事务中添加顶点并删除顶点。

例如:假设我的图形的顶点具有属性desc ='toBeDeleted'。我想建立一个查询来添加desc = My adapter.java public class MyAdapter extends ArrayAdapter<String> { ArrayList<String> name=new ArrayList<>(); ArrayList<String> status=new ArrayList<>(); ArrayList<String> imgs=new ArrayList<>(); ArrayList<String> key=new ArrayList<>(); private Context context; private int resource; private LayoutInflater layoutInflater; public MyAdapter(@NonNull Context context, int resource, ArrayList<String> name, ArrayList<String> status, ArrayList<String> imgs,ArrayList<String> key) { super(context, resource); this.imgs=imgs; this.name=name; this.status=status; this.key=key; this.resource=resource; this.context=context; layoutInflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { return name.size(); } @NonNull @Override public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) { // return super.getView(position, convertView, parent); View v=layoutInflater.inflate(resource,parent,false); CircleImageView view=v.findViewById(R.id.single_user_image); if(imgs!=null) { Picasso.get().load(imgs.get(position)).placeholder(R.drawable.user).into(view); }else{ Picasso.get().load(R.drawable.user).into(view); Toasty.error(context,"check internet connection", Toast.LENGTH_SHORT).show(); } TextView tv1=v.findViewById(R.id.single_user_name); TextView tv2=v.findViewById(R.id.single_user_status); tv1.setText(name.get(position)); tv2.setText("Connected Since:"+status.get(position)); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(getContext(),SingleUserProfileActivity.class); intent.putExtra("key",key.get(position)); getContext().startActivity(intent); } }); return v; } } Myactivity.java public class ConnectedUsersFragment extends Fragment { ListView connectedUsersList; DatabaseReference connectedUsersReference; DatabaseReference userInfoRefernce; DatabaseReference presenceReference; ArrayList<String> name=new ArrayList<>(); ArrayList<String> status=new ArrayList<>(); ArrayList<String> imgs=new ArrayList<>(); ArrayList<String> key=new ArrayList<>(); MyAdapter adapter; FirebaseUser user; public ConnectedUsersFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v= inflater.inflate(R.layout.fragment_connected_users, container, false); connectedUsersList=v.findViewById(R.id.connected_users_list); user=FirebaseAuth.getInstance().getCurrentUser(); presenceReference=FirebaseDatabase.getInstance().getReference().child("users").child(user.getUid()); connectedUsersReference= FirebaseDatabase.getInstance().getReference().child("connected_users").child(user.getUid()); userInfoRefernce=FirebaseDatabase.getInstance().getReference().child("users"); adapter=new MyAdapter(getContext(),R.layout.single_user_layout,name,status,imgs,key); connectedUsersList.setAdapter(adapter); connectedUsersReference.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) { String userKey=dataSnapshot.getKey(); final String userConnectedDate=dataSnapshot.child("date").getValue(String.class); userInfoRefernce.child(userKey).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { String userKey=dataSnapshot.getKey(); String username=dataSnapshot.child("name").getValue(String.class); String userstatus=dataSnapshot.child("profile_status").getValue(String.class); String userimg=dataSnapshot.child("thumb_image").getValue(String.class); name.add(username); status.add(userConnectedDate); imgs.add(userimg); key.add(userKey); adapter.notifyDataSetChanged(); } @Override public void onCancelled(@NonNull DatabaseError databaseError) { Toasty.error(getContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show(); } }); } @Override public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) { } @Override public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) { } @Override public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) { } @Override public void onCancelled(@NonNull DatabaseError databaseError) { Toasty.warning(getContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show(); } }); return v; } @Override public void onStart() { super.onStart(); if(user!=null) { presenceReference.child("online").setValue("true"); } } @Override public void onResume() { super.onResume(); if(user!=null) { presenceReference.child("online").setValue("true"); } } @Override public void onStop() { super.onStop(); if(user!=null) { presenceReference.child("online").setValue(ServerValue.TIMESTAMP); } } @Override public void onPause() { super.onPause(); if(user!=null) { presenceReference.child("online").setValue(ServerValue.TIMESTAMP); } } } desc_1desc_2的顶点,并删除desc = desc_3的顶点吗?

toBeDeleted

注意:我已经尝试过了,但是它两次创建了desc_1,desc_2,desc_3。

我也在寻找一种删除边以及部分交易的方法

0 个答案:

没有答案