I have a problem with Neo4j database. When I add new Data to database and update the value of it (default : 0.0), it will recorded in database and then when I refresh the page, the data will not changed.
But, when I relaunch the program (Stop - Star or Restart) the program, the value of new Data will back to its original value (0.0). I already try to tracing all event that related to change the value, but none of the breakpoint is executed to change the value.
Is there any bug that can revert the value to its default value? Because the value of my new Data, same like the default value after I added it to database (Before update).
This is my simple code to create new data
LineItem newLineItem = new LineItem(engine, previousLineItem.getNo() + 1, previousLineItem.getSection(), "ACTIVITY ENGINE", previousLineItem.getActivityCode(), "ENGINE", 0.0,
"",checked, "");
lineItems.add(newLineItem);
lineItemService.save(lineItems);
And this is how I updated my data
LineItem lineItem = lineItemService.findById(id);
if(lineItem != null){
if(name != null)lineItem.setName(name);
if(duration != null)lineItem.setDuration(roundUpToNearestQuarter(duration));
lineItemService.save(lineItem);
return lineItemList;
}
return new ArrayList<LineItem>();
The problem is, When I just refresh the page, and never Relaunch it, the duration data is same like the newest data, but after I relaunch the program, the duration data will revert back to default value (0.0)
There is no code that revert back my data to its original, because I already search global and give breakpoint on each code that have possibility to changed the value.
This bug related to my other bug, Argument mistype. Link : Spring Data Neo4j - Argument Type Mismatch
It will revert all my values to default because when I relaunch the program, it will get the default data that I set before.
Just need to check the attribute data and data saved on database, is it correct data or wrong type data.
Related
So imagine the following scenario, using the Parse platform on iOS:
I get a PFObject from the server, let's call it GlassChalice.
Someone else, let's say Bill Blofeld, changes GlassChalice from a different location.
Later, I make some changes to my local GlassChalice, but don't save them to the server.
Still later, I want to update GlassChalice, but I want to update it to the current server values, in other word Bill Blofeld's values. I do not want to replace the server values with my local values, and also do not want to reset my local values to the values GlassChalice was loaded with.
So if I use revert(), will I get what I want?
According to the Parse docs:
- revert Clears any changes to this object made since the last call to save and sets it back to the server state.
...but, as in my example, clearing "changes made since the last call to save" and setting it "back to the server state" aren't always the same thing.
So far this seems like the only way to guarantee the results I want, but it has one obvious problem:
public func updateObjectFromServer(_ objectToUpdate: PFObject, then doThis: (()->Void)? = nil) {
let query = PFObject.query()
query?.whereKey("objectId", equalTo: objectToUpdate.objectId!)
query?.getFirstObjectInBackground (block: {
(serverObject, error) in
if error.isNil() {
objectToUpdate["numberOfLimbs"] = serverObject?["numberOfLimbs"]
objectToUpdate["eyePlacement"] = serverObject?["eyePlacement"]
objectToUpdate["crossStitchingTalentRating"] = serverObject?["crossStitchingTalentRating"]
objectToUpdate["clamsEaten"] = serverObject?["clamsEaten"]
} else {
//handle error...
}
doThis?()
})
}
But the huge problem here is that I have to know all the key names, and type them in explicitly, for this to work.
Is there a better, more generic, way?
I had this app that fetches some data from a remote API. So the data that I am going to receive and display in a JSON Future:
{"status":200,"out":{"summary":[{"bc":"1876","wc":"488679","pc":"731904"}],"last":[{"id":"1877","place":"7","publisher":"-1","bookid":"01877","title":"Neither Civil Nor Servant","author":"Peh","region":"\u65b0\u52a0\u5761","copyrighter":"","translated":"0","purchdate":"2017-04-18","price":"200.00","pubdate":"2016-01-01","printdate":"2016-01-01","ver":"1.1","deco":"\u666e\u901a","kword":"0","page":"220","isbn":"978-981-4642-63-7","category":"","location":"","intro":"TT\u8d60\u4e66\u3002","instock":"1","p_name":"\uff08\u672a\u6307\u5b9a\uff09"}]}}
I will extract the out field from this JSON and assing summary and last to two variables:
initState() async {
var getter = createHttpClient();
String uri='http://api.rsywx.com/book/summary';
var res=await getter.get(uri);
Map data=JSON.decode(res.body);
var out=data['out'];
setState(() {
_today=formatDate(new DateTime.now());
_lb=out['last'][0];
_bs=out['summary'][0];
_lb['purchdate']=formatDate(DateTime.parse(_lb['purchdate']));
});
}
So _bs and _lb are all compound objects.
In my widget build function, I will display the contents of these two objects:
new TextSpan(
text: numFormatter.format(int.parse(_bs['bc'])),
style: aboutTextStyle,
),
The program compiles OK but when launched, a quick splash RED screen will appear:
And soon enough, the correct screen will appear:
I know that during the initial build, the object _bs, _lb is not there yet and the async call to a remote API is still trying to populate the returned response, so in this case, _bs['bc'] will definitely be not callable. Thus the non-blocking error pops out.
Workaround
I can eliminate this error by declaring a bunch of variables and assign them in the initState function; instead of rendering _bs['bc'], I will render a new variable _bookCoount. This way, the rendering will be done without this RED screen and the value of that variable will initially be null and soon be the correct value fetched from remote API.
But this is too cumbersome, if you get what I mean: A lot of used-only-once variables.
Or, shall I make the data fetched on the parent level, so that it will be passed to this widget as props? Not tried yet.
Would appreciate your best practice input.
Update
The issue really comes from int.parse. If I took out that call, the program runs peacefully.
So the question now becomes
I would suppress int.parse prompting an error before the value it is going to parse becomes valid.
Not sure what you mean with your workaround. In your example setState() won't be called before await getter.get(uri); returns a value.
I guess this should do
new TextSpan(
text: _bs != null && _bs['bc'] != null ? [numFormatter.format(int.parse(_bs['bc'])) : 0,
style: aboutTextStyle,
),
I use Reflux.connect methods to change component state, but I can't get the different part in shouldComponentUpdate between nextState and this.state. Actually, this.state already has the new values I was expecting to be in nextState when shouldComponentUpdate is called.
What should I need to do when I want to use shouldComponentUpdate with Reflux?
var component = React.createClass({
mixins: [Reflux.connect(store1, 'store1data'),
Reflux.connect(store2, 'store2data')],
shouldComponentUpdate: function(nextProps, nextState) {
//Here this.state.store1data is equal to nextState.store1data
}
Make sure you're not mutating the state and instead returning a new copy of it. If your store only changes the field inside the state, then the this.state pointer already points to the mutated state.
so in your store1, instead of:
store1Data.someKey = newValue;
this.trigger(store1Data)
try doing:
store1Data = _.assign({}, store1Data, {someKey: newValue}); // this uses lodash, for example
this.trigger(store1Data)
That way you will get a fresh copy of store1Data every time it changes.
Immutability is an important concept when working with states, especially in React/Flux, since it allows you to determine quickly whether a state was changed. Try making a habit of always returning a new copy when changing the state, and to never change to anything inside the state unless you clone it first.
Immutablity in ReactImmutableJs
Recently, a program that creates an Access db (a requirement of our downstream partner), adds a table with all memo columns, and then inserts a bunch of records stopped working. Oddly, there were no changes in the environment that I could see and nothing in any diffs that could have affected it. Furthermore, this repros on any machine I've tried, whether it has Office or not and if it has Office, whether it's 32- or 64-bit.
The problem is that when you open the db after the program runs, the destination table is empty and instead there's a MSysCompactError table with a bunch of rows.
Here's the distilled code:
var connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=corrupt.mdb;Jet OLEDB:Engine Type=5";
// create the db and make a table
var cat = new ADOX.Catalog();
try
{
cat.Create(connectionString);
var tbl = new ADOX.Table();
try
{
tbl.Name = "tbl";
tbl.Columns.Append("a", ADOX.DataTypeEnum.adLongVarWChar);
cat.Tables.Append(tbl);
}
finally
{
Marshal.ReleaseComObject(tbl);
}
}
finally
{
cat.ActiveConnection.Close();
Marshal.ReleaseComObject(cat);
}
using (var connection = new OleDbConnection(connectionString))
{
connection.Open();
// insert a value
using (var cmd = new OleDbCommand("INSERT INTO [tbl] VALUES ( 'x' )", connection))
cmd.ExecuteNonQuery();
}
Here are a couple of workarounds I've stumbled into:
If you insert a breakpoint between creating the table and inserting the value (line 28 above), and you open the mdb with Access and close it again, then when the app continues it will not corrupt the database.
Changing the engine type from 5 to 4 (line 1) will create an uncorrupted mdb. You end up with an obsolete mdb version but the table has values and there's no MSysCompactError. Note that I've tried creating a database this way and then upgrading it to 5 programmatically at the end with no luck. I end up with a corrupt db in the newest version.
If you change from memo to text fields by changing the adLongVarWChar on line 13 to adVarWChar, then the database isn't corrupt. You end up with text fields in the db instead of memo, though.
A final note: in my travels, I've seen that MSysCompactError is related to compacting the database, but I'm not doing anything explicit to make the db compact.
Any ideas?
As I replied to HasUp:
According MS support, creation of Jet databases programmatically is deprecated. I ended up checking in an empty model database and then copying it whenever I needed a new one. See http://support.microsoft.com/kb/318559 for more info.
I want to use the following method to flag people in the Person table so that they can be processed. These people must be flagged as "In Process" so that other threads do not operate on the same rows.
In SQL Management Studio the query works as expected. When I call the method in my application I receive the row for the person but with the old status.
Status is one of many navigation properties off of Person and when this query returns it is the only property returned as a proxy object.
// This is how I'm calling it (obvious, I know)
var result = PersonLogic.GetPeopleWaitingInLine(100);
// And Here is my method.
public IList<Person> GetPeopleWaitingInLine(int count)
{
const string query =
#"UPDATE top(#count) PERSON
SET PERSON_STATUS_ID = #inProcessStatusId
OUTPUT INSERTED.PERSON_ID,
INSERTED.STATUS_ID
FROM PERSON
WHERE PERSON_STATUS_ID = #queuedStatusId";
var queuedStatusId = StatusLogic.GetStatus("Queued").Id;
var inProcessStatusId = StatusLogic.GetStatus("In Process").Id;
return Context.People.SqlQuery(query,
new SqlParameter("count", count),
new SqlParameter("queuedStateId", queuedStateId),
new SqlParameter("inProcessStateId", inProcessStateId)
}
// update | if I refresh the result set then I get the correct results
// but I'm not sure about this solution since it will require 2 DB calls
Context.ObjectContext().Refresh(RefreshMode.StoreWins, results);
I know it is an old question but this could help somebody.
It seems you are using a global Context for your query, EF is designed to retain cache info, if you allways need fresh data must use a fresh context to retrieve it. as this:
using (var tmpContext = new Contex())
{
// your query here
}
This create the context and recycle it. This means no cache was stored and next time it gets fresh data from database not from cache.