Another question: can I make a model implement an interface with multiple paramters?
Following
@TableModelSpec(className = "DesktopItem", tableName = "desktopItem")
@Implements(interfaceDefinitions = {@Implements.InterfaceSpec(interfaceClass=Item.class, interfaceTypeArgs={DesktopItem.class, Long.class})})
public class DesktopItemEntrySpec
Generates this:
public class DesktopItem extends AndroidTableModel implements Item<Long>
So the generated class is missing the DesktopItem
paramaeter in the interface...
disableGettersAndSetters
flag (documented here), and defining a new code generation plugin that scans the list of each model's properties and generates getters and setters using the interface that you would prefer. you can look at the BasicPropertyGenerator
class to see how that class creates getter/setter definitions, and take inspiration from that.
@Implements.InterfaceSpec
type args, the reason it's not working is because you can't refer to a class object of a generated class while you're generating that class -- it doesn't exist at compile time, so the annotation processing APIs can't pick up the package name. using the fully qualified class name is the correct solution, and that's why that option exists
Is it possible to overwrite a generated model method? Like following:
@ColumnSpec(name = "name", defaultValue = "")
String name;
@ModelMethod
public static String getName(CustomItem item) {
// custom code...
return ...;
}
The ModelMethod will throw an exception because the generated model has this function already...
I know I can solve it by renaming the field name and then I can define my custom getName
function, I'm just interested if there is a way to overwrite the generated method instead
TableModelSpecFieldPlugin
as well as custom subclasses of the BasicPropertyGenerator
classes for different field types, i.e. BasicStringPropertyGenerator
, BasicLongPropertyGenerator
, etc. your custom property generator subclasses could look for specific annotations on their fields and override methods such as getterMethodName
or writeGetterBody
in order to customize the implementation details of your accessors. (at this time you can't skip generating getters/setters entirely, but you could you just design your annotations such that they caused the getter to delegate to a private model method, or you could make the getter name different and the method private). you'd need to register your custom property generator classes with your subclass of TableModelSpecFieldPlugin
by overriding the methods such as getStringPropertyGenerator
and getLongPropertyGenerator
. hope that makes sense!
@TableModelSpec
) are currently written in Java. When I try to use one of these classes from Kotlin I get a symbol not found error from the compiler. Issues #278 and #166 seem related. What I'm wondering is if this is a supported use-case in SquiDB? Or would we need to do something like port our existing spec classes to Kotlin and use kapt
?
kapt
-- while I haven't done much with kotlin myself, my understanding is that you just need to use that to configure both java and kotlin annotation processing when using the kotlin plugin. I think this is the same issue as #278 -- I just realized that a user submitted a pull request to clarify the readme for this issue that I missed, I should get that in :) hope that helps! definitely post back here if things still seem amiss
in
Criterion does not return true for instanceof java.util.Collection<?>
. can you provide a brief code sample for how you're constructing the in
Criterion? might help us to track down if there's some kind of bug with how j2objc translates things (I'm assuming this issue doesn't happen in java)
@property
changes you needed to make? I don't think I encountered those when I was experimenting with j2objc 2
public List<Habit> getById(List<String> ids) {
SquidCursor<Habit> cur = db.query(Habit.class, Query.select(Habit.PROPERTIES).where(Habit.UID.in(ids)));
return habitCursorToList(cur);
}
@property
stuff. I'm not well versed in obj-c at all, what does that change do?
List
s should also be Collection
s though, since List extends Collection. I'll probably need to examine the translated code and do some debug stepping to track down the problem
InCollectionCriterion
to make sure it's adding your argument as a collection, and also add some logging to the private findCollectionArgs
method in CompiledArgumentResolver
to see if that is in turn finding your collection args.
findCollectionArgs
looks through the argument list for anything that's a collection, and adds it to the collectionArgs
field in CompiledArgumentResolver
. line 94 in that class extracts them: Collection<?> values = collectionArgs.get(index);
, but the exception indicates the list is empty. it'll be illuminating to understand why it's empty