Deprecation begone!
This commit is contained in:
@@ -27,6 +27,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.samskivert.io.PersistenceException;
|
import com.samskivert.io.PersistenceException;
|
||||||
import com.samskivert.util.ArrayUtil;
|
import com.samskivert.util.ArrayUtil;
|
||||||
@@ -50,7 +51,7 @@ import com.samskivert.jdbc.depot.expression.ValueExp;
|
|||||||
* Provides a base for classes that provide access to persistent objects. Also defines the
|
* Provides a base for classes that provide access to persistent objects. Also defines the
|
||||||
* mechanism by which all persistent queries and updates are routed through the distributed cache.
|
* mechanism by which all persistent queries and updates are routed through the distributed cache.
|
||||||
*/
|
*/
|
||||||
public class DepotRepository
|
public abstract class DepotRepository
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a repository with the supplied connection provider and its own private persistence
|
* Creates a repository with the supplied connection provider and its own private persistence
|
||||||
@@ -59,6 +60,7 @@ public class DepotRepository
|
|||||||
protected DepotRepository (ConnectionProvider conprov)
|
protected DepotRepository (ConnectionProvider conprov)
|
||||||
{
|
{
|
||||||
_ctx = new PersistenceContext(getClass().getName(), conprov);
|
_ctx = new PersistenceContext(getClass().getName(), conprov);
|
||||||
|
_ctx.repositoryCreated(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,8 +69,14 @@ public class DepotRepository
|
|||||||
protected DepotRepository (PersistenceContext context)
|
protected DepotRepository (PersistenceContext context)
|
||||||
{
|
{
|
||||||
_ctx = context;
|
_ctx = context;
|
||||||
|
_ctx.repositoryCreated(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the persistent classes used by this repository to the supplied set.
|
||||||
|
*/
|
||||||
|
protected abstract void getManagedRecords (Set<Class<? extends PersistentRecord>> classes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the persistent object that matches the specified primary key.
|
* Loads the persistent object that matches the specified primary key.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -20,8 +20,11 @@
|
|||||||
|
|
||||||
package com.samskivert.jdbc.depot;
|
package com.samskivert.jdbc.depot;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -393,6 +396,29 @@ public class PersistenceContext
|
|||||||
listenerSet.add(listener);
|
listenerSet.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates over all {@link PersistentRecord} classes managed by this context and initializes
|
||||||
|
* their {@link DepotMarshaller}. This forces migrations to run and the database schema to be
|
||||||
|
* created.
|
||||||
|
*/
|
||||||
|
public void initializeManagedRecords ()
|
||||||
|
throws PersistenceException
|
||||||
|
{
|
||||||
|
for (Class<? extends PersistentRecord> rclass : _managedRecords) {
|
||||||
|
getMarshaller(rclass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a depot repository is created. We register all persistent record classes used by
|
||||||
|
* the repository so that systems that desire it can force the resolution of all database
|
||||||
|
* tables rather than allowing resolution to happen on demand.
|
||||||
|
*/
|
||||||
|
protected void repositoryCreated (DepotRepository repo)
|
||||||
|
{
|
||||||
|
repo.getManagedRecords(_managedRecords);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up and creates, but does not initialize, the marshaller for the specified Entity
|
* Looks up and creates, but does not initialize, the marshaller for the specified Entity
|
||||||
* type.
|
* type.
|
||||||
@@ -474,4 +500,16 @@ public class PersistenceContext
|
|||||||
|
|
||||||
protected Map<Class<?>, DepotMarshaller<?>> _marshallers =
|
protected Map<Class<?>, DepotMarshaller<?>> _marshallers =
|
||||||
new HashMap<Class<?>, DepotMarshaller<?>>();
|
new HashMap<Class<?>, DepotMarshaller<?>>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The set of persistent records for which this context is responsible. This data is used by
|
||||||
|
* {@link #initializeManagedRecords} to force migration/schema initialization.
|
||||||
|
*/
|
||||||
|
protected Set<Class<? extends PersistentRecord>> _managedRecords =
|
||||||
|
new HashSet<Class<? extends PersistentRecord>>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collection of all {@link PersistenceContext} objects in existence.
|
||||||
|
*/
|
||||||
|
protected static List<PersistenceContext> _contexts = new ArrayList<PersistenceContext>();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user