Morphia subclasses [MONGO] - java

So basically I'm trying to create a settings manager for users. Once I save the class in MongoDB and then redirect to another sector it throws an error similar to this - http://hastebin.com/isenakibaj.java (Error). I'm using the class loader from the Plugin class. This works fine on the server with the class 'HubSettings', that extends 'SettingsEntry', but when I change server to one without the HubSettings class as it has no intention to use it (different build) it doesn't like it.

Morphia stores the class type as part of the document. When you try to load that document, morphia tries to load that class when loading documents from the database. you'll either need to tweak the data in your database or make that class avaiable at runtime.

Related

Is there any way auto generate graphql schema from protobuf?

I am developing springboot with GraphQL. Since the data structure is already declared within Protobuf, I tried to use it. This is example of my code.
#Service
public class Query implements GraphQLQueryResolver {
public MyProto getMyProto() {
/**/
}
}
I want make code like upper structure. To to this, I divided job into 2 sections.
Since ".proto file" can be converted to java class, I will use this class as return type.
And The second section is a main matter.
Also Schema is required. At first, I tried to code schema with my hand. But, the real size of proto is about 1000 lines. So, I want to know Is there any way to convert ".proto file" to ".graphqls file".
There is a way. I am using the a protoc plugin for that purpose: go-proto-gql
It is fairly simple to be used, for example:
protoc --gql_out=paths=source_relative:. -I=. ./*.proto
Hope this is working for you as well.

Backend Endpoint Class in Google Cloud Module not Updating (Android)

I have a class which is used to generate endpoints to the save in Google Cloud Datastore. I populate objects of this class on the application side and then call the generated API to store them (I'm using Objectify)
I've recently added a new field of type List<String> including a method to add strings to the list. However on the application said I can only see the old version of the class (which is imported from backend.MyApi.model.MyClass)
The culprit according to Android Studio is in backend/build/libs/backend-android-endpoints.jar which has a MyClass.class object
I've tried deleting the build files in the backend module, cleaning and rebuilding but it still uses the old version
How do I force the class to be rebuilt using the new source to include the new fields/methods?
So I think I've found the solution.
Any class defined as an entity by Objectify shows up in API.model but only with getters and setters for its defined fields. Therefore my add method isn't part of it
Therefore to include the functionality of add() instead on the application side I write
List<String> classList = classInstance.getClassList();
String stringToAdd = "Blah";
if (!classList.contains(stringToAdd))
{
classList.add(stringToAdd);
classInstance.setClassList(classList)
}

REQ: Retrieving properties in my java app. collected by "PropertyPlaceholderConfigurer" -- properties are stored in a database as key/value

PUsing Spring 3.2.0.release and JDK 1.6. I've a standalone Java program (NOT running inside tomcat etal) and I'm loading properties from a database.
I've used this excellent article as a base and it works perfectly. Using the PropertiesPrinter bean (defined there) as a base and adding getters I can do stuff like getFileLocation(), getPetDogsName() but then I need to have/create setter/getters for every property.
What I would like to have is a Spring Bean or normal Java class called DatabaseProperties with a method like getProperty("filelocation"); which I can use in my application (main)and so I can retrieve/get the value of the property filelocation which is somewhere inside the information collected by PropertyPlaceholderConfigurer.
I've done a lot of digging but can't seem to find the information I need or at least I'm not able to combine the gathered info into a working program as I'm not fluent with Spring....
Any hint/pointers/urls/code is higly appreciated. It's probably relative easy but it is still out of reach for me atm.
One solution for reading values set by the PropertyPlaceholderConfigurer, is to use the #Value annotation rather than a method for setting class member variables:
class MyClass {
#Value("${file.location}")
private String fileLocation;
...
}

How do you tell the reference path when loading a class?

I'm trying to use JavaLoader to load a java (HttpAsyncClient) class into ColdFusion.
client = loader.create("org.apache.commons.HttpAsyncClient")
How do we know the reference that is org.apache.commons.HttpAsyncClient? I thought if you open the jar file and follow the directory structure, it will give you the reference path. But I don't think this is true.
I'm trying to use the HttpAsyncClient but I'm unable to load it:
client = loader.create("org.apache.commons.HttpAsyncClient") returns a class not found error.
Loader is a reference to JavaLoader, which loads Java classes into your CF server.
Rather than reinvent the wheel, why not try an existing tool like Mark Mandel's AsyncHTTP library?
Update: From the comments, that tool is ACF only. So you might try using the concrete class DefaultHttpAsyncClient as shown in the Asynchronous HTTP Exchange example.
I don't know ColdFusion. You probably have to specify the full path to the class, not just the package containing the class.
According to an example I found the full package and class name is this: org.apache.http.nio.client.HttpAsyncClient
You can also use the javadoc to find out the package and class names: http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/index.html
Getting something async going with an interface like this will probably be brutal. I would suggest trying the sync version first.
EDIT
I would try adapting this sync example to CF: http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientWithResponseHandler.java
When you instantiate HttpGet you have to pass extra parameters to init() as they do in this example: http://www.coldfusionjedi.com/index.cfm/2009/5/29/Generating-Speech-with-ColdFusion-and-Java

How can I add a namespace to valueObjects using FlashBuilder

When I use FlashBuilder to connect to a remote Java object using BlazeDS, FlashBuilder automatically creates a local valueObject matching the object in the remote server.
However, the package name of the remote object gets lost in translation.
Hence if I have two remote Java objects com.foo.A and com.bar.A, I won't be able to distinguish between them in Flex. So I end up having to name my remote classes com.foo.AFoo, com.bar.ABar.
Is there a better way?
I don't see why you you can't used com.foo.A on the flex end as well as the java end. Personally, I think Flex project structure is very different from Java (for instance, Java likes to use DTO naming, while Flex uses Model) and this is why I use RemoteClass metadata to bind the Java DTO to a Flex model.
The Flex class name is not important, and is ignored when sending / receiving classes to / from BlazeDS.
What is important is the name that's specified in the [RemoteClass] metadata on your Flex class.
Eg:
// Actionscript class Apple.as
package com.mangofactory.sample
{
[RemoteClass(alias="org.orchard.Orange")]
public class Apple {
... etc ....
Here, the Actionscript class com.mangofactory.sample.Apple is mapped to the Java class org.orchard.Orange
While the naming of the fields & properties within the class is important, the actual class mapping is specified explicitly using Metadata.

Categories

Resources