BlackBerry OS 5: PersistentStore.getPersistentObject returns null? - blackberry

PersistentStore.getPersistentObject returns null?
I am using a random key to retrieve an object form PersistentStore
persist = PersistentStore.getPersistentObject( KEY );
Works fine on the Simulator (OS 5), when i take the signed code to the device (BB OS 5.0 Bold 8900)
For some reason this returns null, without an exception. Subsequently any API I inoke on PersistentStore/persist returns null without an exception even when persist is null.
I am not sure if this is an eclipse debugger thing, but even though the debugger shows that objects are null. Null check applied in the code seems to fail, that means code sees these objects as not null. Pheww!!! how is this possible?
In this code persist shows up as null, so does safetyTable and orderedkeys. However, the null checks in the code fail.
At a later point in the code, when i try to access orderedkeys these are null again!!! Have been grappling with this issue for two days now, any pointers would be very heplful.
persist = PersistentStore.getPersistentObject( KEY );
persistOrderedKeys = PersistentStore.getPersistentObject(KEY_ORDERED_KEYS);
safetyTable = (Hashtable)persist.getContents();
orderedKeys = (Vector)persistOrderedKeys.getContents();
if (safetyTable == null)
{
safetyTable = new Hashtable();
persist.setContents(safetyTable);
persist.commit();
}
if (orderedKeys==null)
{
orderedKeys=new Vector();
if (safetyTable.size() > 0)
{
Enumeration addressKeys = safetyTable.keys();
while(addressKeys.hasMoreElements())
{
orderedKeys.addElement((String)addressKeys.nextElement());
}
}
persistOrderedKeys.setContents(orderedKeys);
persistOrderedKeys.commit();
}

Related

How to print GeckoWebBrowser to default printer?

I'm trying to print the document in a GeckoWebBrowser, but documentation is limited and to me, it's not at all clear.
I found some code on the internet that at least communicates with the printer (it starts beeping) but I think the printer is asking for a Letter size paper, but it requires the settings to be from print.GetGlobalPrintSettingsAttribute(), if I try my own settings, it gives me a NotImplementedException.
I suspect this is exception is raised on my Gecko.PrinterSettings, because when I swap ps in the print.Print(ps, null);
with the global settings, this exception isn't raised.
The code below:
var domWindow = browser.Window.DomWindow;
var print = Gecko.Xpcom.QueryInterface<Gecko.nsIWebBrowserPrint>(domWindow);
Gecko.PrintSettings ps = new Gecko.PrintSettings();
ps.SetPrintSilentAttribute(false);
ps.SetPrintToFileAttribute(false);
ps.SetShowPrintProgressAttribute(false);
ps.SetOutputFormatAttribute(1); //2 == PDF, so I assume 1 is actual printer
ps.SetPrintBGImagesAttribute(true);
ps.SetStartPageRangeAttribute(1);
ps.SetEndPageRangeAttribute(100);
ps.SetPrintOptions(2, true); // evenPages
ps.SetPrintOptions(1, true); // oddpages
ps.SetEffectivePageSize(768 * 20f, 1024 * 20f);
ps.SetShrinkToFitAttribute(true);
ps.SetScalingAttribute(1.0);
ps.SetPrintBGImagesAttribute(true);
print.Print(ps, null);
Managed to come up with a solution.
What was throwing an exception was
public void SetPersistMarginBoxSettingsAttribute(bool aPersistMarginBoxSettings)
{
throw new NotImplementedException();
}
The above is in PrinterSettings.cs, so it is hard-coded coded to throw a NotImplementedException on a number off attributes (the attribute above isn't the only one hard-coded to throw the exception) as it is not finished(?), so I cannot use it.
However, I can use the GetGlobalSettingsAttribute() as it uses the same interface as PrinterSettings (nsiPrintSettings), so therefore it will have the same attributes all populated for me.
So what can I do is:
I simply copy the GetGlobalPrintSettingsAttribute() into my own printer settings, and adjust them as necessary.
var mySettings = print.GetGlobalPrintSettingsAttribute();
mySettings.SetPrintSilentAttribute(true);
mySettings.SetPrintToFileAttribute(true);
mySettings.SetShowPrintProgressAttribute(false);
mySettings.SetOutputFormatAttribute(2); //2 == PDF
mySettings.SetToFileNameAttribute(#"c:\temp\temp.pdf");
mySettings.SetPrintBGImagesAttribute(true);
mySettings.SetStartPageRangeAttribute(1);
mySettings.SetEndPageRangeAttribute(100);
mySettings.SetPrintOptions(2, true); // evenPages
mySettings.SetPrintOptions(1, true); // oddpages
mySettings.SetShrinkToFitAttribute(true);
mySettings.SetScalingAttribute(1.0);
mySettings.SetPrintBGImagesAttribute(true);
print.Print(mySettings, new Gecko.WebProgressListener());
Please notice I reverted back to PDF for now, in the SetOutputFormatAttribute(2); //2 == PDF
Also changed the print.Print(ps, null); to print.Print(mySettings, new Gecko.WebProgressListener()); but I think having null or Gecko.WebProgressListener() won't make a difference.
Et voilĂ ! - Now, onto the next step, which is to print to a printer, and not as a PDF file.

No such property: getFlatConfig when trying to access configuration

So have set up a couple of values in the groovy.config file which I want for my application.
Set them as follows:
environments {
development {
grails.logging.jul.usebridge = true
reslist = ['1400x1200','1200x1024','1024x800','800x600']
resdef = '1024x800'
mapregs = ['World', 'Europe', 'Asia', 'South America','Central America', 'Pacific','Africa']
mapdef = 'World'
Then I try to access them in a controller
if ( params.mapreq == null) {
mapreq = grailsApplication.config.grails.mapdef
} else {
mapreq = params.mapreq
}
It seems to work (kind a) I get something back, but looks like an object pointer in the format
groovy.util.ConfigObject#3764a904
Tried changing it to getFlatConfig
if ( params.mapreq == null) {
mapreq = grailsApplication.getFlatConfig.grails.mapdef
} else {
mapreq = params.mapreq
}
At which point I get a "No such property: getFlatConfig when trying to access configuration" instead
So any suggestions?
Also, would the same solution work for getting the lists (like the mapregs one)?
grailsApplication.config.grails.mapdef should be grailsApplication.config.mapdef since mapdef is at the top level of the config (within that environment block). Since there's nothing stored under grails.mapdef, the value will be a new ConfigObject. That's why config.a.b.c.d=1 works - each time you access a new level that doesn't exist, Groovy automatically creates a new ConfigObject to hold the value being set, but if you're getting and not setting, you end up with just the empty instance.
The 2nd one doesn't work because getFlatConfig should be getFlatConfig() or flatConfig. But you can't use the ConfigObject-style dots with the flat config because it's flattened. If mapdef was actually under grails you'd access it as grailsApplication.flatConfig.'grails.mapdef' or grailsApplication.flatConfig['grails.mapdef']. But like the other one it's not, so you'd use grailsApplication.flatConfig.mapdef.

Dart HttpRequest polling

I have a web app that have a Timer that fires a poll to get data every 3 seconds. It works fine for about 2.5 minutes then Chromium crashes.
My request Dart looks like this
HttpRequest.getString('data/get_load_history_recent.json')
.then((e) => _recentHistoryResponse(e))
.catchError((e) => _recentHistoryError(e));
Can you think of any reasons why this would happen? I assume it's a memory leak...
Edit:
Here is my _recentHistoryResponse()
void _recentHistoryResponse(String data)
{
Map obj = JSON.decode(data);
if(obj['status'] == 'success')
{
List processes = obj['data']['processes'];
List newItems = new List();
List oldIdsArray = new List();
int length = appDataDic.load_history_list.length;
for(HistoryDataVO oldVO in appDataDic.load_history_list)
{
oldIdsArray.add(oldVO.loadID);
}
for(Map process in processes)
{
HistoryDataVO dataVO = new HistoryDataVO();
dataVO.loadID = process['loadID'];
dataVO.time = process['time'];
dataVO.loadType = process['loadType'];
dataVO.fileName = process['fileName'];
dataVO.label = process['label'];
dataVO.description = process['description'];
dataVO.count = process['count'];
dataVO.progress = process['progress'];
dataVO.loadTask = process['loadTask'];
// Check if the item is currently in the list
if(length >= 1)
{
if(!LoadHistoryHelper.exists(oldIdsArray, dataVO.loadID))
{
dataVO.isNew = true;
}
}
newItems.add(dataVO);
}
appDataDic.load_history_list.clear();
appDataDic.load_history_list.addAll(newItems);
}
}
I have commented out the exists check !LoadHistoryHelper.exists(oldIdsArray, dataVO.loadID)) (because this seemed like the obvious place) but it the VM still crashes.
Also, I have taken this same code and put it into an isolated app with the only real difference in the poll check is appDataDic.load_history_list is just an #observable List, not an ObservableList.
Edit 2 :
Ok, so I have discovered that Map obj = JSON.decode(data); causes the crash. I was reading in a Javascript forum that timeouts cause the memory to not be released (I had never thought of this but it makes sense), is this true? Can any one think of a better way to do this? Can I directly call the garbage collection? I'm running out of ideas.
There's another question here, suggesting a memory leak in HttpRequest; however I'm not able to find anything in the Dart issue tracker. If you think this might be a real memory leak, it might be worth raising a bug.

MonoTouch SecKeyChain.Add returning SecStatusCode.Param

I'm trying to save a record like so:
var testRecord = new SecRecord(SecKind.GenericPassword)
{
CreationDate = DateTime.UtcNow,
MatchCaseInsensitive = false,
Service = "MyService",
Label = "MyService",
Account = "User",
Generic = NSData.FromString("test", NSStringEncoding.UTF8),
};
SecKeyChain.Add(testRecord);
...but I'm getting SecStatusCode.Param back when I run it in the simulator. According to the documentation, that code means "Invalid or incomplete parameters passed" but I don't see anything missing or unusual that others aren't doing with apparent success.
Even adding CreationDate, Invisible, Description, Comment, Accessible, and ValueData properties to the SecRecord (some as in this example) didn't help -- still getting SecStatusCode.Param.
Are there any non-obvious things that might cause a Param status code to be returned?
I had a lot of trouble trying to use the keychain. I finally got mine working to store user credentials in the app. Here is what I have:
SecRecord existingRec = new SecRecord (SecKind.GenericPassword) {
Service = Keychain.USER_SERVICE,
Label = Keychain.USER_LABEL
};
var record = new SecRecord (SecKind.GenericPassword) {
Service = Keychain.USER_SERVICE,
Label = Keychain.USER_LABEL,
Account = username,
ValueData = NSData.FromString (password),
Accessible = SecAccessible.Always
};
SecStatusCode code = SecKeyChain.Add (record);
if (code == SecStatusCode.DuplicateItem) {
code = SecKeyChain.Remove (existingRec);
if (code == SecStatusCode.Success)
code = SecKeyChain.Add (record);
}
Keychain is a static class with constants so I don't have to retype the strings.
The only thing different between yours and mine is the CreationDate/MatchCaseInsensitive properties and the encoding for NSData. Maybe try it without those and see if it works? If so, add them back separately and see what gives the problem.
This might be because you are running on the simulator - in that case you need to add an Entitlements plist in the project options for your current build config in order to make keychain access work.

OCI_SUCCESS_WITH_INFO Error For Ruby

I am facing an issue with rake. When I give rake, rake fails with the following error:
/Ruby/lib/ruby/site_ruby/1.8/oci8.rb:228 - ORA-28002: the password will expire within 5 days
The problem here is that OCILogon will give a status as OCI_SUCCESS_WITH_INFO which i believe is not handled in evn.c
So when I dug up into the code, I found that evn.c did indeed have check only for OCI_SUCCESS
But then, I changed the code to something like this in the function oci8_logon present in env.c of ruby:
rv = OCILogon(envh->hp, envh->errhp, &svchp,
u.ptr, u.len, p.ptr, p.len, d.ptr, d.len);
if (rv != OCI_SUCCESS && rv != OCI_SUCCESS_WITH_INFO) {
oci8_raise(envh->errhp, rv, NULL);
}
Still I am facing the same issue.
I verified the return value (rv) it is coming as 1 which from oci.h, I verified to be OCI_SUCCESS_WITH_INFO
Any idea what I need to do next?
PS: I don't want to go and change the password expiry behavior on the oracle side by changing the Profile to which the account is associated. I need a workaround at ruby level.
Change your comparison to
if (rv != OCI_SUCCESS && rv != OCI_SUCCESS_WITH_INFO)
^^ logical AND instead of logical OR
Share and enjoy.
EDIT:
After further consideration, I think this would be clearer if it was rewritten to make positive comparisons instead of negative comparisons:
rv = OCILogon(envh->hp, envh->errhp, &svchp,
u.ptr, u.len, p.ptr, p.len, d.ptr, d.len);
if (rv == OCI_SUCCESS || rv == OCI_SUCCESS_WITH_INFO)
{
/* Code to perform when OCILogon succeeds */
}
else
{
/* Code to perform when OCILogon fails */
oci8_raise(envh->errhp, rv, NULL);
}
And so it goes...

Resources