- Cryptography utilities
- JDBC utilities (Named parameters, Array parameters, LIKE_ANY operator, etc.)
- Record framework
- JSON Web Signature/Json Web Token (HS/RS/ES/PS)
- Geography utilities
- CSV Utilities
- ToStringBuilder
- appslandia-common
- Java 21
<dependency>
<groupId>com.appslandia</groupId>
<artifactId>appslandia-common</artifactId>
<version>{LATEST_VERSION}</version>
</dependency>
dependencies {
compile 'com.appslandia:appslandia-common:{LATEST_VERSION}'
}
new ToStringBuilder().toString(anyObject);
new ToStringBuilder().setTsDepthLevel(3).toString(anyObject);
new ToStringBuilder().setToOneLine(true).toString(anyObject);
// JdbcSql can be reused
JdbcSql sql = new JdbcSql("SELECT * FROM User WHERE status=:status");
ConnectionImpl conn = new ConnectionImpl(javax.sql.DataSource);
try (StatementImpl stat = conn.prepareStatement(sql)) {
stat.setInt("status", 1); // Named parameter
//
stat.executeQuery();
}
JdbcSql sql = new JdbcSql("SELECT * FROM User WHERE userType IN :types");
ConnectionImpl conn = new ConnectionImpl(javax.sql.DataSource);
try (StatementImpl stat = conn.prepareStatement(sql)) {
stat.setIntArray("types", new int[] {1,2,3});
//
stat.executeQuery();
}
JdbcSql sql = new JdbcSql("SELECT * FROM User WHERE name LIKE_ANY :names");
ConnectionImpl conn = new ConnectionImpl(javax.sql.DataSource);
try (StatementImpl stat = conn.prepareStatement(sql)) {
stat.setLikeAny("names", new String[] {"a, "b"}); // name LIKE '%a%' OR name LIKE '%b%'
//
stat.executeQuery();
}
try (ConnectionImpl connScoped = new ConnectionImpl(javax.sql.DataSource)) {
try (RecordContext db = new RecordContext()) {
// Insert an user into the User table.
db.insert("UserTable", new DataRecord().set("FirstName", fName)
.set("LastName", lName)
.set("Email", email));
}
}
String password = SYS.resolve("{db.password, env.DB_PASSWORD}")
// resolving order: System.getProperty("db.password"), System.getenv("DB_PASSWORD")
GeoLocation loc = new GeoLocation(longitudeX, latitudeY);
GeoLocation loc_east = loc.move(Direction.EAST, 10, DistanceUnit.MILE);
//
double distanceInMiles = loc.distanceTo(loc_east, DistanceUnit.MILE); // ~10 miles
// JoseJsonb or JoseGson.newJsonProcessor() or your implementation
JsonProcessor jsonProcessor = JoseGson.newJsonProcessor();
// JwtSigner - HS256/HS384/HS512
JwtSigner jwtSigner = HsJwtSigner.HS256().setJsonProcessor(jsonProcessor)
.setSecret("secret".getBytes()).setIssuer("Issuer1").build();
// OR JwtSigner - ES256/ES384/ES512 - RS256/RS384/RS512 - PS256/PS384/PS512
JwtSigner jwtSigner = DsaJwtSigner.ES256().setJsonProcessor(jsonProcessor)
.setPrivateKey(privateKey).setPublicKey(publicKey).setIssuer("Issuer1").build();
JoseHeader header = processor.newHeader();
JwtPayload payload = processor.newPayload().setExpiresIn(1, TimeUnit.DAYS);
// Sign
String jwt = jwtSigner.sign(new JwtToken(header, payload));
// Parse
JwtToken token = jwtSigner.parse(jwt);
// Verify
jwtSigner.verify(token);
token.getHeader();
token.getPayload();
// Can be reused
CsvProcessor csvReader = new CsvProcessor();
// BufferedReader
BufferedReader br = IOUtils.readerBOM(new FileInputStream("a_csv_file"), "UTF-8");
List<CsvRecord> records = csvReader.parseRecords(br);
records.get(0).getString(0);
// getInt(), getBool(), ...
This code is distributed under the terms and conditions of the MIT license.