|
|
@ -2,7 +2,6 @@ package com.fr.plugin.db.redis.core; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.Parameter; |
|
|
|
import com.fr.base.Parameter; |
|
|
|
import com.fr.data.AbstractDataModel; |
|
|
|
import com.fr.data.AbstractDataModel; |
|
|
|
import com.fr.general.data.TableDataException; |
|
|
|
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.plugin.PluginLicense; |
|
|
|
import com.fr.plugin.PluginLicense; |
|
|
|
import com.fr.plugin.PluginLicenseManager; |
|
|
|
import com.fr.plugin.PluginLicenseManager; |
|
|
@ -14,12 +13,9 @@ import com.fr.third.redis.clients.jedis.Jedis; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
public class RedisTableDataModel extends AbstractDataModel { |
|
|
|
public class RedisTableDataModel extends AbstractDataModel { |
|
|
|
|
|
|
|
|
|
|
|
private Jedis redisClient; |
|
|
|
|
|
|
|
private String[] columnNames; |
|
|
|
private String[] columnNames; |
|
|
|
private List<List<Object>> data; |
|
|
|
private List<List<Object>> data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RedisTableDataModel(Calculator calculator, Parameter[] ps, RedisDatabaseConnection mc, int dbIndex, String query, String script, int rowCount) { |
|
|
|
public RedisTableDataModel(Calculator calculator, Parameter[] ps, RedisDatabaseConnection mc, int dbIndex, String query, String script, int rowCount) { |
|
|
|
PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(RedisConstants.PLUGIN_ID); |
|
|
|
PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(RedisConstants.PLUGIN_ID); |
|
|
|
if (pluginLicense.isAvailable()) { |
|
|
|
if (pluginLicense.isAvailable()) { |
|
|
@ -33,11 +29,9 @@ public class RedisTableDataModel extends AbstractDataModel { |
|
|
|
if (StringUtils.isEmpty(query)) { |
|
|
|
if (StringUtils.isEmpty(query)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (redisClient == null) { |
|
|
|
Jedis redisClient = mc.createRedisClient(); |
|
|
|
redisClient = mc.createRedisClient(); |
|
|
|
|
|
|
|
redisClient.select(dbIndex); |
|
|
|
redisClient.select(dbIndex); |
|
|
|
FineLoggerFactory.getLogger().info("Connect to redis and select database:" + dbIndex); |
|
|
|
FineLoggerFactory.getLogger().info("Connect to redis and select database:" + dbIndex); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redisClient, query, rowCount); |
|
|
|
DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redisClient, query, rowCount); |
|
|
@ -45,33 +39,34 @@ public class RedisTableDataModel extends AbstractDataModel { |
|
|
|
wrapper.transform(script); |
|
|
|
wrapper.transform(script); |
|
|
|
data = wrapper.getData(); |
|
|
|
data = wrapper.getData(); |
|
|
|
columnNames = wrapper.getColumnNames(); |
|
|
|
columnNames = wrapper.getColumnNames(); |
|
|
|
|
|
|
|
redisClient.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException(e.getCause()); |
|
|
|
throw new RuntimeException(e.getCause()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int getColumnCount() throws TableDataException { |
|
|
|
public int getColumnCount() { |
|
|
|
return columnNames.length; |
|
|
|
return columnNames.length; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String getColumnName(int columnIndex) throws TableDataException { |
|
|
|
public String getColumnName(int columnIndex) { |
|
|
|
return columnNames[columnIndex]; |
|
|
|
return columnNames[columnIndex]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean hasRow(int rowIndex) throws TableDataException { |
|
|
|
public boolean hasRow(int rowIndex) { |
|
|
|
return data != null && data.get(0).size() > rowIndex; |
|
|
|
return data != null && data.get(0).size() > rowIndex; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int getRowCount() throws TableDataException { |
|
|
|
public int getRowCount() { |
|
|
|
return data == null ? 0 : data.get(0).size(); |
|
|
|
return data == null ? 0 : data.get(0).size(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object getValueAt(int rowIndex, int columnIndex) throws TableDataException { |
|
|
|
public Object getValueAt(int rowIndex, int columnIndex) { |
|
|
|
if (data != null && data.size() > columnIndex) { |
|
|
|
if (data != null && data.size() > columnIndex) { |
|
|
|
List<Object> columnData = data.get(columnIndex); |
|
|
|
List<Object> columnData = data.get(columnIndex); |
|
|
|
if (columnData != null && columnData.size() > rowIndex) { |
|
|
|
if (columnData != null && columnData.size() > rowIndex) { |
|
|
@ -83,9 +78,6 @@ public class RedisTableDataModel extends AbstractDataModel { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void release() throws Exception { |
|
|
|
public void release() throws Exception { |
|
|
|
if (redisClient != null) { |
|
|
|
|
|
|
|
redisClient.quit(); |
|
|
|
|
|
|
|
redisClient = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |