I have a problem with thinking. I decided to create a SQL Query Generator using reflection. I created my own annotations to determine which classes can be used, which attributes can be stored, etc. The code works the way I want, but the problem is using this project as a dependency in others.
I have another project using OJDBC and I'm trying to use my library to create queries based on a class. However, when I pass a class from my ojdbc project, all the class information is lost, the class appears as java.lang.Class, and even annotation information is lost. Does anyone know why this is happening?
private static <T> void appendTableName(Class<T> cls) throws NotStorableException { Storable storable = cls.getAnnotation(Storable.class); String tableName = null; if (storable != null) { if ((tableName = storable.tableName()).isEmpty()) tableName = cls.getSimpleName(); } else { throw new NotStorableException( "The class you are trying to persist must declare the Storable annotaion"); } createStatement.append(tableName.toUpperCase()); }
cls.getAnnotation(Storable.class) loses information when the next class is passed to it
package com.fdm.ojdbc; import com.fdm.QueryBuilder.annotations.PrimaryKey; import com.fdm.QueryBuilder.annotations.Storable; @Storable(tableName="ANIMALS") public class Animal { @PrimaryKey private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
The animal class is in the ojdbc project, and the appendTableName method belongs to my query builder. I tried to create a querybuilder project in the bank and use maven install to add it to my repository and still have no luck.
Thanks for the quick response, however this is not a problem since the generated annotation was saved in Runtime below.
package com.fdm.QueryBuilder.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target(value = { ElementType.TYPE }) @Retention(value = RetentionPolicy.RUNTIME) public @interface Storable { public String tableName() default ""; }
My annotation is indicated at runtime, but class information is still lost.