Skip to content

Use annotation and reflection to handle the ORM (Object-Relational Mapping) between Java class and the Java related external configuration files (.properties).

License

Notifications You must be signed in to change notification settings

wuyichen24/jpropertiesorm

Repository files navigation

jpropertiesorm

Build Status Coverage Status Codacy Badge License

Use annotation and reflection to handle the ORM (Object-Relational Mapping) between Java class and the Java related external configuration files (.properties).

Overview

.properties is a file extension for files mainly used in Java related technologies to store the configurable parameters of an application. The structure of properties file content is very similar to a list of key-value pairs. Traditionally, we need to create a Java config class and populate each field by reading the properties file manually. But jpropertiesorm is a framework which can map Java config class to a properties file directly, and you don't have to populate each field manually.

In jpropertiesorm, there are multiple ways to do ORM between Java config class and properties file, and the pros & cons among different ways is still in discussion. Generally, jpropertiesorm uses @ValueX annotation with parameter to specify each field map to which parameter in the properties file. And use @PathX annotation to specify which field is to store the path of the properties file, like

public class AppConfig2 {
    @PathX
    private String path;
	
    public AppConfig2(String path) {
	this.path = path;
    }
	
    public AppConfig2 initialize() throws IllegalArgumentException, IllegalAccessException, IOException {
	return ConfigurationX.bindExternalConfigurationWithInstanceFieldsUsingPathX(this);
    }
	
    @ValueX("app.host")
    private String host;
	
    @ValueX("app.api_key")
    private String apiKey;
	
    @ValueX("app.username")
    private String username;
	
    @ValueX("app.password")
    private String password;

    public String getHost()                    { return host;              }
    public void   setHost(String host)         { this.host = host;         }
    public String getApiKey()                  { return apiKey;            }
    public void   setApiKey(String apiKey)     { this.apiKey = apiKey;     }
    public String getUsername()                { return username;          }
    public void   setUsername(String username) { this.username = username; }
    public String getPassword()                { return password;          }
    public void   setPassword(String password) { this.password = password; }
}

And the properties file looks like

app.host=aaa
app.api_key=bbb
app.username=ccc
app.password=ddd

Currently, jproperties just supports reading properties file, the functionality of writing properties file needs to be implemented in the next release.

Getting Started

Please see our Wiki page.

Documentation

Please see our Wiki page.

Download

Contributing

License

Apache-2.0

Authors

About

Use annotation and reflection to handle the ORM (Object-Relational Mapping) between Java class and the Java related external configuration files (.properties).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages