How can I access this value, the max value and message from the controller
I try to access the information schema table, do it via sql and access this variable without writing it directly in the code,
I was trying to access the schema Information table, to get the maximum value from the column but it generates an error that is not mapped
thank you very much and sorry, I'm new to this
There are 2 options to do this.
Since the value is constant, you can declare a static final variable and use it as the class variable.
eg:
static final int MAX_RANGE = 100;
In this case, just use "class_name".MAX_RANGE
You could also specify the value in a property file and use the property file as and when needed.
You can use reflection (which is not the best case)
Class<?> cls = Class.forName(name);
cls.getDeclaredAnnotations(); // get all annotation
(cls.getDeclaredMethods()[0]).getAnnotations(); //get annotation of a method
Annotation ety = cls.getAnnotation(Annotation.class); // get annotation of particular annotation class
Related
I have a property set to "true", that I want to bind to my checkStatus field.
#Value("${prop.checkstatus}")
private boolean checkStatus;
I am able to access the value from inside an #Service class. However, if I use #Value inside a class that I instantiate or retrieve using AppliationContext.getBean("classA"), the value is always "false" since it cannot get the correct value from the property file. Please advise as I need to access this value from an instance and from a bean.
In some parts of the code, I create the object using new and try to access #Value. I understand that this is not possible since the new object is not managed by spring. But there are parts of the code where the object is retrieved using applicationcontext. Still I cannot access the #Value. Is there a better approach in retrieving #Value both for objects created using new and applicationcontext.getbean?
I am looking to pass a field value to a resolved field using another object type.
Another way to put it if I have `Customer > User > Profile' - how can I pass the CustomerID field value that would be in customer to Profile as an argument or variable in order to resolve correctly?
There's exactly 5 possibilities (as of graphql-java v12) to provide info to a resolver (DataFetcher) at any level:
1) Directly pass them in the query (possibly on multiple levels):
{customer(id: 3) {
user {
profile(id: 3) {
name
}
}
}
}
2) Get values from the source object
The source is the result of the enclosing query.
In your case, the source for the customer query is the root (whatever you provided at the query execution time, e.g.
graphQL.execute(ExecutionInput.newExecutionInput()
.query(query)
.root(root)
.build())
The source for the user query is whatever customer query returned, presumably some Customer instance.
The source for the profile query is whatever the user query returned, presumably a User instance.
You can get a hold of the source via DataFetchingEnvironment#getSource(). So, if User contains the CustomerID you're after, just get it via ((User) env.getSource()).getCustomerId(). If not, consider wrapping the result into an object that would contain all you need in the sub-queries.
3) Pass the values around using the shared context
graphql-java passes around an instance of GraphQLContext available to all resolvers. So, inside the DataFetcher for customer, you can store the CustomerID into it:
Customer customer = getCustomer();
GraphQLContext context = env.getContext();
context.put("CustomerID", customer.getId());
Later on, inside the DataFetcher for profile, you can get it from the context:
String customerId = env.getContext().get("CustomerID");
To initialize a context, pass it when executing the query:
ExecutionInput input = ExecutionInput.newExecutionInput()
.query(operation)
.graphQLContext(new HashMap<>())
.build()
graphQL.execute(query, input);
This way is stateful, thus the hardest to manage, so use it only if all else fails.
4) Directly get the arguments passed to a parent field
ExecutionStepInfo stepInfo = dataFetchingEnvironment.getExecutionStepInfo();
stepInfo.getParent().getArguments(); // get the parent arguments
5) Pass the values around using the local context
Instead of returning the result directly, wrap it into a DataFetcherResult. That way you can also attach any object as a localContext that will be available to all child DataFetchers via DataFetchingEnvironment#getLocalContext()
I want to have a depper look into java reflection and hibernate.
To pass values to a known setter works, but I want to do the same with an unknown setter of a hibernate pojo.
I get the mapped class with
PersistentClass mappedClass = session.configuration.getClassMapping(classFromPath.getName());
Table myTable = mappedClass.getTable();
iter = myTable.getColumnIterator();
while(iter.hasNext()) {
Column myColumn = (Column) iter.next();
Property myProperty = mappedClass.getProperty(myColumn.getName());
System.out.println(myProperty.getName());
}
This is my way, to get a specific property. Now, I want to get the propertys getter and setter methods.
One way is to get the name, to concate the words get/set with the property names. I don't like that way and want a better solution.
I know, there is a function like myProperty.getSetter, but I'm not sure, how to deal with it.
I'm totally wrong? Are there any ways to get the getter/setter methods?
You can use Introspector and PropertyDescriptor for this.
For details, please refer here
I have created a POJO class in morphia to save data object to MongoDB ,
I have a property called 'unitPrice', i want to keep this as read only property, mean not allow to modify DB value once it save to mongo,
Is there a morphia annotation to do this or else,
Is it possible to bind #NotSaved annotation to the property at run time ?
This is my POJO
#Entity("items")
public class Items {
private int id;
private int sequence;
private int unitPrice;
}
Thanks
BR
Ero
I don't know of a way to bind #NotSaved at runtime, but I could think of a (hacky) workaround:
Set the attribute in the constructor (Morphia will still require the no-args constructor)
Don't provide a setter, just a getter for the attribute
It ain't pretty, but it should get the job done.
In Servoy, a development and deployment platform, you have the possibility to use what is called a JSFoundSet which is an object containing record objects defined by its SQL. Such a JSFoundSet is created as follows using the appropriate annotation:
/** #type{JSFoundSet<db:/database/table_name}*/
var fs = null;
from this point on you can use in your code the variable fs to get or set values to the properties of table_name. So if I would create a foundset of table Customer and this table contains the columns id, firstName and lastName, then the Servoy platform provides intellisense that allows me to do this:
fs.id = 1;
fs.firstName = 'John';
fs.lastName = 'Doe';
Since I use a lot of Java too, I wanted to see if I can create something similar of this in Java. So I want to create a class FoundSet of a certain generic type, say of type Customer in our example, after which in my code I can create an object of this class and then access the public fields (set/get) of FoundSet. While typing I wish to see these fields show up through intellisense.
Is there a library or some sort that allows me to define some annotations as the Servoy example to accomplish this?