Class DBCachedObjectStoreFactory

java.lang.Object
ghidra.util.database.DBCachedObjectStoreFactory

public class DBCachedObjectStoreFactory extends Object
A factory for creating object stores for classes extending DBAnnotatedObject

See DBAnnotatedObject for more documentation, including an example object definition. To create a store, e.g., for Person:


 interface MyDomainObject {
 	Person createPerson(String name, String address);
 
 	Person getPerson(long id);
 
 	Collection<? extends Person> getPeopleNamed(String name);
 }
 
 public class DBMyDomainObject extends DBCachedDomainObjectAdapter implements MyDomainObject {
 	private final DBCachedObjectStoreFactory factory;
 	private final DBCachedObjectStore<DBPerson> people;
 	private final DBCachedObjectIndex<String, DBPerson> peopleByName;
 
 	public DBMyDomainObject() { // Constructor parameters elided
 		// super() invocation elided
 		factory = new DBCachedObjectStoreFactory(this);
 		try {
 			people = factory.getOrCreateCachedStore(DBPerson.TABLE_NAME, DBPerson.class,
 				DBPerson::new, false);
 			peopleByName = people.getIndex(String.class, DBPerson.NAME_COLUMN);
 		}
 		catch (VersionException e) {
 			// ...
 		}
 		catch (IOException e) {
 			// ...
 		}
 	}
 
 	@Override
 	public Person createPerson(String name, String address) {
 		// Locking details elided
 		DBPerson person = people.create();
 		person.set(name, address);
 		return person;
 	}
 
 	@Override
 	public Person getPerson(int id) {
 		// Locking details elided
 		return people.getAt(id);
 	}
 
 	@Override
 	public Collection<Person> getPeopleNamed(String name) {
 		// Locking details elided
 		return peopleByName.get(name);
 	}
 }
 

The factory manages tables on behalf of the domain object, so it is typically the first thing constructed. In practice, complex domain objects should be composed of several managers, each of which constructs its own stores, but for simplicity in this example, we construct the people store in the domain object. This will check the schema and could throw a VersionException. Typically, immediately after constructing the store, all desired indexes of the store are retrieved. The domain object then provides API methods for creating and retrieving people. Providing direct API client access to the store from a domain object is highly discouraged.

Implementation Notes:
This class bears the responsibility of processing the DBAnnotatedField, DBAnnotatedColumn, and DBAnnotatedObjectInfo annotations. The relevant entry point is {buildInfo(Class). It creates a DBCachedObjectStoreFactory.TableInfo for the given class, which builds the schema for creating the Table that backs an object store for that class.