/*
* JBoss, Home of Professional Open Source.
* Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.cache.loader;
import net.jcip.annotations.ThreadSafe;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.marshall.NodeData;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* JDBC implementation of AdjListJDBCCacheLoader.
* Represents a faster alternative than JDBCCacheLoaderOld and relies on the same database structrure.
* It is backward compatible with data created by existing JDBCCacheLoaderOld implemetation.
* All configuration elements described there {@link org.jboss.cache.loader.JDBCCacheLoaderOld} also apply for this
* implementation.
*
*
* Additional configuration info:
*
*
* cache.jdbc.batch.enable: whether or not to use batching on repetitive operations (e.g. inserts during state transfer).
* Enabling batching should give an important performance boost. It might be required to disable this if the JDBC driver
* does not support batching. Default set to 'true'
*
*
* cache.jdbc.batch.size: number of operations afer which the batching buffer will be flushed. If 'cache.jdbc.batch.enable'
* is false, this will be ignored. Default value is 1000.
*
*
*
* @author Mircea.Markus@iquestint.com
* @author Galder Zamarreno
* @version 1.0
*/
@ThreadSafe
public class JDBCCacheLoader extends AdjListJDBCCacheLoader
{
private static final Log log = LogFactory.getLog(JDBCCacheLoader.class);
private JDBCCacheLoaderConfig config;
/**
* Builds a AdjListJDBCCacheLoaderConfig based on the supplied base config.
*/
@Override
protected AdjListJDBCCacheLoaderConfig processConfig(CacheLoaderConfig.IndividualCacheLoaderConfig base)
{
if (base instanceof JDBCCacheLoaderConfig)
{
config = (JDBCCacheLoaderConfig) base;
}
else
{
config = new JDBCCacheLoaderConfig(base);
}
return config;
}
/**
* As per interface's contract.
* Performance Note: Optimised O(nodeDepth) db calls.
*/
public Object put(Fqn name, Object key, Object value) throws Exception
{
lock.acquireLock(name, true);
try
{
Map