TableModels
? I have a few models implementing the same custom interface and before I can persist those custom interface objects I must cast them to TableModel
because I can't define an interface like public interface ICommonTableModel extends TableModel
because there is no base interface
ICommonTableModel
, e.g. methods that accept them as arguments, but that context doesn't know that they're also TableModels? would an intersection type help you here? e.g. public void <T extends ICommonTableModel & TableModel> persistMyCommonTableModel(T item)
. this would be safer than a cast because it would only accept objects that are of both types. maybe I could answer your question a little better if you gave a more specific example. we could consider making interfaces like IModel
and ITableModel
in a future major version, but I am totally swamped with other projects right now and I don't have a good timeline for when a stable 4.0 might launch, so I want to be able to give you good suggestions that will help now
<T extends TableModel & ICommonTableModel>
. I was just curious because I would prefer to define that my custom interface extends TableModel
and then I can forget about it instead of defining the T
type in all functions I write...
@TableModelSpec
we could have Class<? extends TableModel> superclass() default TableModel.class
. this would require some dependency wrangling but might be useful...
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