Let's say the [managedObjectID URIRepresentation] uri is:
x-coredata://ABCDEF/Post/p1234567
At first, I thought I could use [[objectID URIRepresentation] lastPathComponent], but this returns
p1234567
instead of just 1234567. I can slice off the p, but this seems like not the proper way of doing things. Is there a better way?
There is no public API to obtain that value. The structure of an NSManagedObjectID is dependent upon the persistent store type for which it is generated (SQLite, XML, etc.).
I am also curious why you need it though, as its not actually possible to query for a managed object using only that number.
Related
As the topic, when I use ortools, I want to serialize cpsolver, CpSolverSolutionCallback and cpmodel to achieve multithread computing. However, I can't just serialize those objects directly and I think I need to only serialize their configuration and reset configuration in each thread, such as all the constraint and variables in the cpmodel and parameters in cpsolver. This is the question, how can I get all those values using ortools? Is there an api or something? I can't find it when searching on Google.
Every language implements a thin wrapper above a protocol buffer file.
This file is described here
This model is accessible from each CpModel class.
Now you can distribute work using this proto directly. You will need to look at the CpSolver class to understand how the c++ Solve method is called.
See the python solve method.
The way to implement your request.
Create your model normally.
Extract the underlying protocol buffer model underneath and use it for parallelism/distribution.
Solve will returns a CpSolverResponse object. To get the value of a variable in the response, call response.Value(var.Index()), or store the index of the relevant variables and use it in the Value() method call.
In glade it is possible to set an unique ID to an object. In the code one can obtain a pointer to this object by searching for it's "glade ID" via gtk_builder_get_object().
However for my current use-case I just want to read out this ID from an GObject. What's the API to do so ?
You can't. The builder ID is stored in the builder internally, not in the GObject.
The reason for this is that IDs must be unique per builder, which would be impossible to enforce if you were able to get and set them via some GObject API.
You could use gtk_widget_get_name() to identify an object.
It is possible using Gtk.Buildable.get_name(object). This method will return the Glade object id.
This snippet will print all object ids in your Glade XML:
builder = Gtk.Builder()
builder.add_from_file("my-window.glade"))
for obj in builder.get_objects():
print(Gtk.Buildable.get_name(obj))
As stated by #ptomato it's seems not possible.
I found that in that line in the documentation:
All the fields in the GObject structure are private to the
implementation and should never be accessed directly.
But you can circumvent it because at one point in your code you were refering to it by the id that you typed in (or the code you wrote type in) so you just need to store it at that point. And link it somehow (with a variable or a data structure) to the name of the variable holding the object.
I have a problem with Lua and I don't know if I going in the right direction. In C++ I have a dictionary that I use to pass parameter to a resource manager. This dictionary is really similar to a map of hash and string.
In Lua I want to access to these resource so I need a representation of hashes. Also hashes must be unique cause are used as index in a table. Our hash function is 64bit and I'm working on 32bit enviroment (PS3).
C++ I have somethings like that:
paramMap.insert(std::make_pair(hash64("vehicleId"), std::string("004")));
resourceManager.createResource(ResourceType("Car"), paramMap);
In Lua want use these resources to create a factory for other userdata.
I do stuff like:
function findBike(carId)
bikeParam = { vehicleId = carId }
return ResourceManager.findResource('car', bikeParam)
end
So, sometime parameter are created by Lua, sometime parameter are created by C++.
Cause my hashkey ('vehicleId') is an index of a table it need to be unique.
I have used lightuserdata to implement uint64_t, but cause I'm in a 32bit enviroment I can't simply store int64 in pointer. :(
I have to create a table to store all int64 used by the program and save a reference in userdata.
void pushUInt64(lua_State *L, GEM::GUInt64 v)
{
Int64Ref::Handle handle = Int64Ref::getInstance().allocateSlot(v);
lua_pushlightuserdata(L, reinterpret_cast<void*>(handle));
luaL_setmetatable(L, s_UInt64LuaName);
}
but userdata are never garbage collected. Then my int64 are never released and my table will grow forever.
Also lightuserdata don't keep reference to metadata so they interfere with other light userdata. Checking the implementation the metadata table is added in L->G_->mt_[2].
doing that
a = createLightUserDataType1()
b = createLightUserDataType2()
a:someFunction()
will use the metatable of b.
I thought that metatable where bounded to type.
I'm pretty confused, with the current implementation lightuserdata have a really limited use case.
With Python you have a hash metafunction that is called anytime the type is used as index for a dictionary. It's possible to do something similar?
Sorry for my english, I'm from Italy. :-/
I am trying to implement a distributed cache with spring-memcached. The docs suggest that
to use an object as the key I need to have a method in my domain class with #CacheKeyMethod
annotation on it.
But the problem is I am using the same domain class in different scenarios and the key to be generated in each case has different logic. For examples for a User class one of the scenarios requires the key to be unique in terms of city and gender and but in the other case it requires to be unique in terms of the user's email, it's essentially what your lookup is based on.
Although a user's email would determine the city and gender, so I can use email as the key in first case as well but that would mean separate cache entries for each user while the cached data would be same as long as the gender and city are same, which is expected to increase the hit ratio by a huge margin(just think how many users you can expect to be males from bangalore).
Is there a way I could define different keys. Also it would be great if the logic of
generating the key could be externalised from the domain class itself.
I read the docs and figured out that something called CacheKeyBuilder and/or CacheKeyBuilderImpl could do the trick but I couldn't understand how to proceed.
Edit..
ok.. I got one clue! What CacheKeyBuliderImpl does is, it calls the generateKey method on defaultKeyProvider instance which looks for #cachekeyannotation on the provided domain class's methods and executes the method found to obtain the key.
So replacing either the CacheKeyBuilderImpl with custom Impl or replacing KeyProvider's default implementation within CacheKeyBuilderImpl with yours might do the trick... but the keyprovider reference is hardwired to DefaultKeyProvider.
Can anybody help me implement CacheKeyBuilder(with respect to what different methods do;the documentation doesn't clarify it) and also how do I inject it to be used instead of ususal CacheKeyBuilderImpl
Simple Spring Memcached (SSM) hasn't be designed to allow such low level customization. As you wrote one of way is to replace CacheKeyBuilderImpl with own implementation. The default implementation is hardwired but it can be easily replaces using custom simplesm-context.xml configuration.
As I understand your question, you want to cache your User objects under different keys depends on use case. It's supported out of the box because by default SSM uses method argument to generate cache key not the result.
Example:
#ReadThroughMultiCache(namespace = "userslist.cityandgenre", expiration = 3600
public List<User> getByCityAndGenre(#ParameterValueKeyProvider(order = 0) String city, #ParameterValueKeyProvider(order = 1) String genre) {
// implementation
}
#ReadThroughSingleCache(namespace = "users", expiration = 3600)
public User getByEmail(#ParameterValueKeyProvider String email) {
// implementation
}
In general the #CacheKeyMethod is only used to generate cache key if object that contains the method is passed as a parameter to the method and the parameter is annotated by #ParameterValueKeyProvider
I have been really deep thinking about a general way of creating "data model", and been jiggling with best practices and MVC pattern. Currently I am using a singleton pattern to get my httprequest and json parser (which comes as NSDictionary). Now rather than accessing this parser directly, I was hoping to make a Data model that can be binded through this.
However, I have been struggling if there is an easy way to do that rather than assigning manually "[myObj setValue:[jsonDict objectForKey:#"name"]];" where myObj tends to be a simple NSString object.
Since NSDictionary is a nice KVC concept, how can I utilize this to enrich a better style of data model in which I can generally access myObj.name or myObj.address entity than "[myObj setValue:[jsonDict objectForKey:#"name"]];" behavior.
I have looked into "Core Data" model, however the current design doesn't require to store anything locally, but just within memory for security reasons.
Any good ideas or best practices solution here will be really helpful.
Just create your classes. Then crate an class that will serialize the data from your dictionaries to your object.
Let say you create an class Person that has properties firstName and lastName. Then you crate a Class like PresonController, that will do manage the person objects, and in it create class methods like
+(Preson *)personFromDictionary:(NSDictionary)peseonDictionary;
And every time you need to create an person from an dictionary you will do
Person *newPerson = [PersonController personFromDictionary:yourPersonDictionary];
And then in the code you just access the properties of the Person object
NSLog(#"Person first name:%#",newPerson.firstName);
Hope I was clear enough for you.