log = Logger.getLogger(getClass().getName() + "." + tableName);
this.schema = schema;
this.tableId = tableId;
final EntityMetaData entityMetaData = ((EntityMetaData)entity.getContainer().getBeanMetaData());
final ConfigurationMetaData containerConf = entityMetaData.getContainerConfiguration();
dontFlushCreated = containerConf.isInsertAfterEjbPostCreate();
// create cache
final Element cacheConf = containerConf.getContainerCacheConf();
final Element cachePolicy = cacheConf == null ? null : MetaData.getOptionalChild(cacheConf, "cache-policy-conf");
int minCapacity;
int maxCapacity;
if(cachePolicy != null)
{
String str = MetaData.getOptionalChildContent(cachePolicy, "min-capacity");
minCapacity = (str == null ? 1000 : Integer.parseInt(str));
str = MetaData.getOptionalChildContent(cachePolicy, "max-capacity");
maxCapacity = (str == null ? 10000 : Integer.parseInt(str));
}
else
{
minCapacity = 1000;
maxCapacity = 10000;
}
final Element otherConf = cacheConf == null ? null : MetaData.getOptionalChild(cacheConf, "cache-policy-conf-other");
int partitionsTotal;
final boolean invalidable;
final Element batchCommitStrategy;
if(otherConf != null)
{
String str = MetaData.getOptionalChildContent(otherConf, "partitions");
partitionsTotal = (str == null ? 10 : Integer.parseInt(str));
batchCommitStrategy = MetaData.getOptionalChild(otherConf, "batch-commit-strategy");
invalidable = MetaData.getOptionalChild(otherConf, "invalidable") == null ? false : true;
}
else
{
partitionsTotal = 10;
batchCommitStrategy = null;
invalidable = false;
}
if(cachePolicy != null)
{
cache = new PartitionedTableCache(minCapacity, maxCapacity, partitionsTotal);
String periodStr = MetaData.getOptionalChildContent(cachePolicy, "overager-period");
String maxAgeStr = MetaData.getOptionalChildContent(cachePolicy, "max-bean-age");
if(periodStr != null && maxAgeStr == null || maxAgeStr != null && periodStr == null)
{
throw new DeploymentException(
"Failed to initialize age-out thread for entity " + entity.getEntityName() +
": overager-period or max-bean-age is missing!");
}
else if(periodStr != null && maxAgeStr != null)
{
long period = Long.parseLong(periodStr);
long maxAge = Long.parseLong(maxAgeStr);
((PartitionedTableCache)cache).initOverager(period, maxAge, entity.getEntityName() + " overager");
if(log.isTraceEnabled())
{
log.trace("initialized age-out thread for " + entity.getEntityName() +
": overager-period=" + period + ", max-bean-age=" + maxAge);
}
}
final MBeanServer server = MBeanServerLocator.locateJBoss();
serviceController = (ServiceControllerMBean)
MBeanProxyExt.create(ServiceControllerMBean.class,
ServiceControllerMBean.OBJECT_NAME,
server);
try
{
cacheName =
new ObjectName("jboss.cmp:service=tablecache,ejbname=" + metadata.getName() + ",table=" + tableName);
server.registerMBean(cache, cacheName);
serviceController.create(cacheName);
}
catch(Exception e)
{
throw new DeploymentException("Failed to register table cache for " + tableName, e);
}
}
else
{
cache = Cache.NONE;
}
if(invalidable)
{
String groupName = entityMetaData.getDistributedCacheInvalidationConfig().getInvalidationGroupName();
String imName = entityMetaData.getDistributedCacheInvalidationConfig().getInvalidationManagerName();
InvalidationManagerMBean im = (InvalidationManagerMBean) Registry.lookup(imName);
InvalidationGroup invalidationGroup = im.getInvalidationGroup(groupName);
cacheInvalidator = new CacheInvalidator(cache, entity.getContainer().getTransactionManager(), invalidationGroup);