doanduyhai / Achilles

An advanced Java Object Mapper/Query DSL generator for Cassandra
http://achilles.archinnov.info
Apache License 2.0
241 stars 92 forks source link

Shorten generated class names #293

Closed toadzky closed 7 years ago

toadzky commented 7 years ago

Since generated DSL class names are created by concatenating primary key fields, when a class has multiple primary key fields that are descriptively named, the generated code fails to compile because the class name is too long.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project core-data-session-router-entities: Compilation failure
[ERROR] /development/core-data/session-router-entities/target/generated-sources/annotations/info/archinnov/achilles/generated/dsl/ConditionByGotoDestinationEntity_Select.java:[8913,17] error: error while writing ConditionByGotoDestinationEntity_Select.ConditionByGotoDestinationEntity_SelectWhereTypedMap_GotoDestinationType.gotoDestinationType_And_gotoDestinationAddress_And_destinationGroupAddress_And_destinationType_And_destinationAddress_And_identifier_Relation: /development/core-data/session-router-entities/target/classes/info/archinnov/achilles/generated/dsl/ConditionByGotoDestinationEntity_Select$ConditionByGotoDestinationEntity_SelectWhereTypedMap_GotoDestinationType$gotoDestinationType_And_gotoDestinationAddress_And_destinationGroupAddress_And_destinationType_And_destinationAddress_And_identifier_Relation.class (File name too long)
doanduyhai commented 7 years ago

Are you using Windows ?

toadzky commented 7 years ago

Nope, I'm on a Mac. I'm pretty sure it's a JVM limitation. I would guess it might be related to Windows limitations but it's a cross platform issue.

On Thu, Mar 9, 2017, 13:46 DuyHai DOAN notifications@github.com wrote:

Are you using Windows ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/doanduyhai/Achilles/issues/293#issuecomment-285477842, or mute the thread https://github.com/notifications/unsubscribe-auth/ACLkWluiWkq7TxxAB5odbHmhkMlzQhj4ks5rkGUdgaJpZM4MV1k_ .

doanduyhai commented 7 years ago

So your generated class name is:

ConditionByGotoDestinationEntity_Select$ConditionByGotoDestinationEntity_SelectWhereTypedMap_GotoDestinationType$gotoDestinationType_And_gotoDestinationAddress_And_destinationGroupAddress_And_destinationType_And_destinationAddress_And_identifier_Relation

It has 255 characters. The Java specs says that your class name can have up to 65535 characters: http://stackoverflow.com/questions/1039029/does-java-have-a-limit-on-the-class-name-length

Indeed you're on Mac and the max allowed filename length is 255 characters with HFS+ filesystem, see here: http://apple.stackexchange.com/questions/86611/does-os-x-enforce-a-maximum-filename-length-or-character-restriction

toadzky commented 7 years ago

it's definitely still a bug because it means you can run it on a mac. that's a supported platform right?

doanduyhai commented 7 years ago

Humm, fair enough but my problem is how to shorten the classname without loosing its semantics ...

doanduyhai commented 7 years ago

Ohhhh, idea !

How about adding a new @AchillesCompileTimeConfig attribute to force Achilles to use randomly generated short name instead of using the natural name ?

So that if you're on MAC it should do the job !

@toadzky

toadzky commented 7 years ago

You should probably make it the default configuration with an option to override. Based on a wikipedia comparison of file systems, exFAT, NTFS, ext2/3/4, ZFS, and several others all have the same 255 character filename limit.

Source: https://en.wikipedia.org/wiki/Comparison_of_file_systems

doanduyhai commented 7 years ago

thanks for the link