Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.
/ kerberos Public archive

A thin but effective orm to persist entities in a mysql database.

License

Notifications You must be signed in to change notification settings

d3adspace/kerberos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kerberos

Caution: Just a PoC and not longer maintained. You may have a look at https://github.com/FelixKlauke/psycho

A very simple and lightweight framework to store entities in mySQL databases. This is absolutely experimental and not really ready to use.

Installation / Usage

  • Install Maven
  • Clone this repo
  • Install: mvn clean install

Maven dependencies

<dependency>
    <groupId>de.d3adspace</groupId>
    <artifactId>kerberos</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

#Example

Model:

/*
 * Copyright (c) 2017 D3adspace
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import de.d3adspace.kerberos.annotation.Entity;
import de.d3adspace.kerberos.annotation.Id;

/**
 * @author Felix 'SasukeKawaii' Klauke
 */
@Entity(table = "kerberos_users")
public class KerberosUser {
	
	@Id private String id;
	private String name;
	private int age;
	
	public KerberosUser(String id, String name, int age) {
		this.id = id;
		this.name = name;
		this.age = age;
	}
	
	public KerberosUser() {
	}
	
	public int getAge() {
		return age;
	}
	
	public String getName() {
		return name;
	}
	
	public String getId() {
		return id;
	}
	
	@Override
	public String toString() {
		return "KerberosUser{" +
			"id='" + id + '\'' +
			", name='" + name + '\'' +
			", age=" + age +
			'}';
	}
}

CRUD:

KerberosConfig config = KerberosConfig.newBuilder()
	.setDatabaseHost("localhost")
	.setDatabasePort("3306")
	.setDatabaseName("kerberos")
	.setDatabaseUser("root")
	.setDatabasePassword("")
	.createKerberosConfig();
		
Kerberos kerberos = KerberosFactory.createKerberos(config);
		
Datastore<KerberosUser> datastore = kerberos.openDatastore(KerberosUser.class);
		
KerberosUser user = new KerberosUser("1", "KerberosDerHund", 812);
		
// Save
datastore.save(user);
		
// Get
user = datastore.get("1");
		
// Delete
datastore.delete("1");

Lifecycle Processing; Add

@Watcher(watcher = KerberosUserWatcher.class)

to your entity class and watch the lifecycle of an entity:

/*
 * Copyright (c) 2017 D3adspace
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import de.d3adspace.kerberos.database.DatabaseObject;
import de.d3adspace.kerberos.watcher.EntityWatcher;

/**
 * @author Felix 'SasukeKawaii' Klauke
 */
public class KerberosUserWatcher<EntityType> implements EntityWatcher<EntityType> {
	
	@Override
	public void prePersist(EntityType entity, DatabaseObject databaseObject) {
		System.out.println("Persisting: " + entity);
	}
	
	@Override
	public void postLoad(EntityType entity, DatabaseObject databaseObject) {
		System.out.println("Loaded: " + entity);
	}
}

Releases

No releases published

Packages

No packages published

Languages