include does not work with local data store? - parse-platform

ParseQuery<Custom> query = ParseQuery.getQuery(Custom.class);
query.whereEqualTo("user", ParseUser.getCurrentUser());
query.include("address");
query.fromLocalDatastore();
query.getFirstInBackground(new GetCallback<Custom>() {
#Override
public void done(Custom c, ParseException e) {
c.getAddress().getName(); //this gives me fetchIfneeded exception.
}
});
if I do something like this
ParseQuery<Address> query = ParseQuery.getQuery(Address.class);
query.fromLocalDatastore();
query.findInBackground(new FindCallback<Address>() {
#Override
public void done(List<Address> addresses, ParseException e) {
for(Address address: addresses) {
address.getName(); //it works just fine
}
}
});
looks like the include does not work with local datastore.
is this by design? or miss something?
edit:
I can survive by adding
c.getAddress().fetchFromLocalDatastore();

Related

How to fix 'No way to dispatch this command to Redis Cluster because keys have different slots' in Spring

I need to use Redis Cluster in Spring. But I'm getting the following error when I use mget or del on a list of keys: 'No way to dispatch this command to Redis Cluster because keys have different slots'. Showing a part of my Component code using JedisCluster.
It works when I use single key operations but not with multiple keys.
/* Component Code */
public class RedisServiceManager {
#Value("${redis.hosts}")
String hosts;
#Autowired
JedisPoolConfig jedisPoolConfig;
private JedisCluster jedisCluster;
#PostConstruct
private void init() {
List<String> redisHosts = Arrays.asList(hosts.split(","));
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
redisHosts.forEach(redisHost -> {
jedisClusterNode.add(new HostAndPort(redisHost, 6379));
});
jedisCluster = new JedisCluster(jedisClusterNode, jedisPoolConfig);
}
// This works
public String getValueForKey(String key) {
try {
return jedisCluster.get(key);
} catch (Exception e) {
return null;
}
}
// This works
public void delKey(String cacheKey) {
try {
jedisCluster.del(cacheKey);
} catch (Exception e) {
}
}
// This doesn't work
public List<String> getValuesForAllKeys(String... keys) {
try {
return jedisCluster.mget(keys);
} catch (Exception e) {
return new ArrayList<>();
}
}
// This doesn't work
public void delAllKeys(String... keys) {
try {
jedisCluster.del(keys);
} catch (Exception e) {
}
}
}
Can someone help with this?
This is not a bug or an issue, but is the way how redis cluster works. You can find more details in the cluster documentation. But don't worry: there is a "trick": you can use hash as described here

Http Range request Streaming video from url into exoplayer

I tried a lot to find the solution to my problem. but I can't make it correct. I want to show and download video from URL. Url will be like
https://imgur.com/a/dW7kLCv
As far my research API in python language and it used partial content with range request in the header. I don't know how to use that API and load video into video view/exoplayer.I tried below way and I got this issue.
" com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 500"
Anyone pls give me a way to use that api to show and download video
mPlayerView = findViewById(R.id.videoView);
mPlayerView.requestFocus();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
mPlayerView.setPlayer(player);
player.setPlayWhenReady(shouldAutoPlay);
MediaSource mediaSource = new ExtractorMediaSource.Factory(mediaDataSourceFactory)
.createMediaSource(Uri.parse(videoPath));
boolean haveStartPosition = currentWindow != C.INDEX_UNSET;
if (haveStartPosition) {
player.seekTo(currentWindow, playbackPosition);
}
player.prepare(mediaSource, !haveStartPosition, false);
player.addListener(new ExoPlayer.EventListener() {
#Override
public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
}
#Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
}
#Override
public void onLoadingChanged(boolean isLoading) {
}
#Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == ExoPlayer.STATE_BUFFERING) {
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.INVISIBLE);
}
}
#Override
public void onRepeatModeChanged(int repeatMode) {
}
#Override
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
}
#Override
public void onPlayerError(ExoPlaybackException error) {
}
#Override
public void onPositionDiscontinuity(int reason) {
}
#Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
}
#Override
public void onSeekProcessed() {
}
});

jdbcTemplate.batchUpdate for list of inserts doesn't work

I'm out of nerves cells and I really need your help guys.
For some reason I can't get list of answers inserted to database
I use jdbcTemplate to do that and my code looks like this
public void insertVastaukset(List<Vastaus> vastaukset) {
final String sql = "insert into vastaus (kysymysID, vastausteksti) values(?,?)";
getJdbcTemplate().batchUpdate(sql,
new BatchPreparedStatementSetter() {
#Override
public void setValues(PreparedStatement ps, int i)
throws SQLException {
Vastaus vastaus = vastaukset.get(i);
ps.setInt(1, vastaus.getKysymysID());
ps.setString(2, vastaus.getVastausteksti());
}
#Override
public int getBatchSize() {
return vastaukset.size();
}
});}
And for some reason the program gives no error! When i tried it couple days ago it gave me null pointer, but now its fixed but still no inserts are created into database. Help me please, Thank you very much!
Use the below catch block to examine the exceptions
int[] updateCounts;
try {
updateCounts = getJdbcTemplate().batchUpdate("insert into test123 (id, value) values (?,?)",
new BatchPreparedStatementSetter() {
//// YOUR CODE HERE
});
}
catch (Exception sqle) {
Throwable s2 = sqle;
System.out.println("=============v"+s2.getClass().getName()+"=====================");
while (s2!=null) {
s2.printStackTrace();
s2 = s2.getCause();
if(s2 instanceof java.sql.BatchUpdateException) {
System.out.println("======================^^^^^^======================");
((java.sql.BatchUpdateException) s2).getNextException().printStackTrace();
}
}
throw sqle;
}

how to make and AsyncCallback deliver data before next method is called

I have a method that calls 2 services that make AsyncCallBacks
centroService.buscarCentroPorNombre(nombreCentroSeleccionado, new AsyncCallback<Centro>() {
#Override
public void onSuccess(Centro centro) {
cArticuloCentro.setIdCentro(centro.getIdCentro());
cArticuloCentro.setPrecio(Double.parseDouble(precioTextBox.getText()));
}
#Override
public void onFailure(Throwable caught) {
//do something
}
});
articuloService.buscarArticuloPorNombre(nombreArticuloSeleccionado, new AsyncCallback<Articulo>() { //se llama al sevivio para q busque el la base de datos la Entity por nombre
public void onSuccess(Articulo articulo) {
cArticuloCentro.setIdArticulo(articulo.getCod());
}
#Override
public void onFailure(Throwable caught) {
//do something
}
});
the problem comes when the next method is called
becouse these serviceCalls are asynchronous method activates before the calls are made, does not getting desired data. next method is
save(){
articuloCentroService.saveArticuloCentro(cArticuloCentro, new AsyncCallback<String>() {
#Override
public void onFailure(Throwable caught) {
//do something
}
#Override
public void onSuccess(String result) {
Window.alert("saved");
}
});
}
please can you tell me a way to make save() method execute when the asyncCallbacks have finished
thank you
In pure java you would need to synchronize threads, but in GWT, there's only one thread running at all times, so you can do a simply sync logic using an array:
final int[] sync = new int[1];
centroService.buscarCentroPorNombre(nombreCentroSeleccionado, new AsyncCallback<Centro>() {
#Override
public void onSuccess(Centro centro){
//...
if (++sync[0] == 2){
save();
}
}
#Override
public void onFailure(Throwable caught) {
//do something
}
});
articuloService.buscarArticuloPorNombre(nombreArticuloSeleccionado, new AsyncCallback<Articulo>() {
public void onSuccess(Articulo articulo) {
//...
if (++sync[0] == 2){
save();
}
}
#Override
public void onFailure(Throwable caught) {
//do something
}
});
Explanation: since there's only one thread running, the sync array will only be updated by one thread at a time. You can't control which method will finish first, but when they do, only one callback will be executed at a time. The sync array is just a counter you can use to sync any number of async invocations.

Parse Local Datastore e Message "no results found for query"

I am trying to finish this program and i am stuck. This is my first program and now it wont work. I keep getting this error when i add query.fromLocalDatastore(); The code runs fine until i try to get it from the local storage. This is telling me there is nothing there for it to retrieve and i don't know why. When i added my test data it worked fine but when i try to pull data from another table i get the error above. Apparently when i added the test data the server synced with the local datastore. Now it is not. Can someone tell me what I did wrong?
public class DataHolder extends Application {
int age;
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(getApplicationContext());
Parse.initialize(this,key, key);
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);
}
public class MainActivity extends ActionBarActivity implements Disclaimer.DisclaimerListener {
protected void continueToRun() {
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View v, int x, long lng) {
final ParseQuery<ParseObject> query = ParseQuery.getQuery("Phone_Numbers");
query.fromLocalDatastore();
if (x == 1) {
final Intent intent = new Intent(getBaseContext(), Protocol_Template.class);
query.fromLocalDatastore();
query.whereEqualTo("objectId", "uGANULyrdL");
startActivity(intent);
}
}
public class Protocol_Template extends Activity {
DataHolder global;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_protocol__template);
final TextView protocol = (TextView) findViewById(R.id.txt02);
findViewById(R.id.btn2timesUpperLeft);
final ParseQuery<ParseObject> query = ParseQuery.getQuery("Phone_Numbers");
query.fromLocalDatastore();
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
final String protocols = object.get("PhoneNumber").toString();
protocol.setText(protocols);
} else {
protocol.setText(e.getMessage());
}
}
});
}

Resources