forked from p81075629/datagear
添加datagear-util模块,集中项目常用工具类
This commit is contained in:
parent
1bdbf3d2aa
commit
3944577dc1
|
@ -13,5 +13,10 @@
|
|||
<name>datagear-connection</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.datagear</groupId>
|
||||
<artifactId>datagear-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -8,6 +8,8 @@ import java.sql.Connection;
|
|||
import java.sql.Driver;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.datagear.util.JdbcUtil;
|
||||
|
||||
/**
|
||||
* 抽象{@linkplain DriverChecker}。
|
||||
*
|
||||
|
|
|
@ -23,6 +23,8 @@ import java.util.zip.ZipEntry;
|
|||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.datagear.util.FileUtil;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -243,7 +245,7 @@ public abstract class AbstractFileDriverEntityManager implements DriverEntityMan
|
|||
for (String ln : libraryName)
|
||||
{
|
||||
File file = new File(directory, ln);
|
||||
IOUtil.deleteFile(file);
|
||||
FileUtil.deleteFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,7 +254,7 @@ public abstract class AbstractFileDriverEntityManager implements DriverEntityMan
|
|||
{
|
||||
File directory = getDriverLibraryDirectory(driverEntity.getId(), false);
|
||||
|
||||
IOUtil.clearDirectory(directory);
|
||||
FileUtil.clearDirectory(directory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -444,7 +446,7 @@ public abstract class AbstractFileDriverEntityManager implements DriverEntityMan
|
|||
if (zipEntry.isDirectory())
|
||||
{
|
||||
if (file.exists())
|
||||
IOUtil.clearDirectory(file);
|
||||
FileUtil.clearDirectory(file);
|
||||
else
|
||||
file.mkdirs();
|
||||
}
|
||||
|
@ -943,7 +945,7 @@ public abstract class AbstractFileDriverEntityManager implements DriverEntityMan
|
|||
protected void deleteDriverLibraryDirectory(String driverEntityId)
|
||||
{
|
||||
File file = getDriverLibraryDirectory(driverEntityId, false);
|
||||
IOUtil.deleteFile(file);
|
||||
FileUtil.deleteFile(file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Vector;
|
|||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.List;
|
|||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.io.InputStreamReader;
|
|||
import java.io.Reader;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.util.IOUtil;
|
||||
|
||||
/**
|
||||
* 抽象字符输入流{@linkplain ResourceFactory}。
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.io.OutputStreamWriter;
|
|||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.util.IOUtil;
|
||||
|
||||
/**
|
||||
* 抽象字符输入流{@linkplain ResourceFactory}。
|
||||
|
|
|
@ -22,12 +22,12 @@ import java.util.List;
|
|||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.dataexchange.DataFormat;
|
||||
import org.datagear.dataexchange.DataFormat.BinaryFormat;
|
||||
import org.datagear.dataexchange.TextDataExport;
|
||||
import org.datagear.dbinfo.ColumnInfo;
|
||||
import org.datagear.dbinfo.DatabaseInfoResolver;
|
||||
import org.datagear.util.IOUtil;
|
||||
|
||||
/**
|
||||
* 抽象文本导出服务。
|
||||
|
|
|
@ -13,13 +13,13 @@ import java.util.List;
|
|||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.dataexchange.ConnectionFactory;
|
||||
import org.datagear.dataexchange.DataExchangeException;
|
||||
import org.datagear.dataexchange.ExceptionResolve;
|
||||
import org.datagear.dataexchange.TextDataImportListener;
|
||||
import org.datagear.dbinfo.ColumnInfo;
|
||||
import org.datagear.dbinfo.DatabaseInfoResolver;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
|
||||
/**
|
||||
* CSV导入服务。
|
||||
|
|
|
@ -14,11 +14,11 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.dataexchange.support.CsvDataExport;
|
||||
import org.datagear.dataexchange.support.CsvDataExportService;
|
||||
import org.datagear.dataexchange.support.CsvDataImport;
|
||||
import org.datagear.dataexchange.support.CsvDataImportService;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -18,11 +18,11 @@ import java.util.logging.Logger;
|
|||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.dbinfo.DatabaseInfoResolver;
|
||||
import org.datagear.dbinfo.DevotedDatabaseInfoResolver;
|
||||
import org.datagear.dbinfo.GenericDatabaseInfoResolver;
|
||||
import org.datagear.dbinfo.WildcardDevotedDatabaseInfoResolver;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
|
||||
/**
|
||||
* 数据交换测试支持类。
|
||||
|
|
|
@ -17,8 +17,6 @@ import java.util.List;
|
|||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.dataexchange.ClasspathReaderResourceFactory;
|
||||
import org.datagear.dataexchange.DataFormat;
|
||||
import org.datagear.dataexchange.DataexchangeTestSupport;
|
||||
|
@ -29,6 +27,8 @@ import org.datagear.dataexchange.SimpleConnectionFactory;
|
|||
import org.datagear.dataexchange.TableQuery;
|
||||
import org.datagear.dataexchange.TextDataExportOption;
|
||||
import org.datagear.dataexchange.TextDataImportOption;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.io.Reader;
|
|||
import java.sql.Connection;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.dataexchange.DataExchangeException;
|
||||
import org.datagear.dataexchange.DataFormat;
|
||||
import org.datagear.dataexchange.DataexchangeTestSupport;
|
||||
|
@ -18,6 +16,8 @@ import org.datagear.dataexchange.ResourceFactory;
|
|||
import org.datagear.dataexchange.SimpleConnectionFactory;
|
||||
import org.datagear.dataexchange.TextDataImportListener;
|
||||
import org.datagear.dataexchange.TextDataImportOption;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.sql.SQLNonTransientException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.sql.SQLException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.sql.Connection;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
|
|
@ -33,5 +33,10 @@
|
|||
<artifactId>datagear-persistence</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.datagear</groupId>
|
||||
<artifactId>datagear-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -13,14 +13,14 @@ import java.sql.Statement;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.model.Model;
|
||||
import org.datagear.model.Property;
|
||||
import org.datagear.model.support.MU;
|
||||
import org.datagear.persistence.columnconverter.LOBConversionContext;
|
||||
import org.datagear.persistence.columnconverter.LOBConversionContext.LOBConversionSetting;
|
||||
import org.datagear.persistence.support.AbstractModelDataAccessObject;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
|
||||
/**
|
||||
* 基于查询SQL的模型数据查询服务类。
|
||||
|
@ -134,7 +134,7 @@ public class ModelSqlSelectService extends AbstractModelDataAccessObject
|
|||
st = sr.getStatement();
|
||||
rs = sr.getResultSet();
|
||||
|
||||
Model model = databaseModelResolver.resolve(cn, rs, UUID.gen());
|
||||
Model model = databaseModelResolver.resolve(cn, rs, IDUtil.uuid());
|
||||
|
||||
return select(cn, sql, rs, model, startRow, fetchSize);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.datagear.connection.ConnectionSensor;
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.dbinfo.DatabaseInfoResolver;
|
||||
import org.datagear.dbinfo.DevotedDatabaseInfoResolver;
|
||||
import org.datagear.dbinfo.GenericDatabaseInfoResolver;
|
||||
|
@ -27,6 +26,7 @@ import org.datagear.persistence.features.TableName;
|
|||
import org.datagear.persistence.support.DefaultDialectSource;
|
||||
import org.datagear.persistence.support.DefaultPersistenceManager;
|
||||
import org.datagear.persistence.support.dialect.MysqlDialectBuilder;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
|
|
@ -12,11 +12,11 @@ import java.util.List;
|
|||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.management.util.AbstractVersionContentReader;
|
||||
import org.datagear.management.util.Version;
|
||||
import org.datagear.management.util.VersionContent;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.datagear.util.version.AbstractVersionContentReader;
|
||||
import org.datagear.util.version.Version;
|
||||
import org.datagear.util.version.VersionContent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ package org.datagear.management.dbversion;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.management.util.Version;
|
||||
import org.datagear.management.util.VersionContent;
|
||||
import org.datagear.util.version.Version;
|
||||
import org.datagear.util.version.VersionContent;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -28,6 +28,11 @@
|
|||
<artifactId>datagear-dbinfo</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.datagear</groupId>
|
||||
<artifactId>datagear-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-expression</artifactId>
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.persistence;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* JDBC工具类。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class JdbcUtil
|
||||
{
|
||||
private JdbcUtil()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定对象的JDBC类型。
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public static int getJdbcType(Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return Types.NULL;
|
||||
else
|
||||
return getJdbcType(obj.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类的JDBC类型。
|
||||
*
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static int getJdbcType(Class<?> clazz)
|
||||
{
|
||||
if (String.class.equals(clazz))
|
||||
{
|
||||
return Types.VARCHAR;
|
||||
}
|
||||
else if (boolean.class.equals(clazz) || Boolean.class.equals(clazz))
|
||||
{
|
||||
return Types.BOOLEAN;
|
||||
}
|
||||
else if (int.class.equals(clazz) || Integer.class.equals(clazz))
|
||||
{
|
||||
return Types.INTEGER;
|
||||
}
|
||||
else if (long.class.equals(clazz) || Long.class.equals(clazz))
|
||||
{
|
||||
return Types.BIGINT;
|
||||
}
|
||||
else if (float.class.equals(clazz) || Float.class.equals(clazz))
|
||||
{
|
||||
return Types.FLOAT;
|
||||
}
|
||||
else if (double.class.equals(clazz) || Double.class.equals(clazz))
|
||||
{
|
||||
return Types.DOUBLE;
|
||||
}
|
||||
else if (java.math.BigDecimal.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.NUMERIC;
|
||||
}
|
||||
else if (java.math.BigInteger.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.NUMERIC;
|
||||
}
|
||||
else if (java.sql.Date.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.DATE;
|
||||
}
|
||||
else if (java.sql.Time.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.TIME;
|
||||
}
|
||||
else if (java.sql.Timestamp.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.TIMESTAMP;
|
||||
}
|
||||
else if (java.util.Date.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.DATE;
|
||||
}
|
||||
else if (byte.class.equals(clazz) || Byte.class.equals(clazz))
|
||||
{
|
||||
return Types.TINYINT;
|
||||
}
|
||||
else if (short.class.equals(clazz) || Short.class.equals(clazz))
|
||||
{
|
||||
return Types.SMALLINT;
|
||||
}
|
||||
else if (char.class.equals(clazz) || Character.class.equals(clazz))
|
||||
{
|
||||
return Types.CHAR;
|
||||
}
|
||||
else if (byte[].class.equals(clazz) || Byte[].class.equals(clazz))
|
||||
{
|
||||
return Types.BINARY;
|
||||
}
|
||||
else if (java.sql.Clob.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.CLOB;
|
||||
}
|
||||
else if (java.sql.Blob.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.BLOB;
|
||||
}
|
||||
else if (java.sql.Array.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.ARRAY;
|
||||
}
|
||||
else if (java.sql.Struct.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.STRUCT;
|
||||
}
|
||||
else if (java.sql.Ref.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.REF;
|
||||
}
|
||||
else if (java.net.URL.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.REF;
|
||||
}
|
||||
else if (Class.class.equals(clazz))
|
||||
{
|
||||
return Types.JAVA_OBJECT;
|
||||
}
|
||||
else
|
||||
throw new UnsupportedOperationException("Unsupported Java type [" + clazz + "] for getting JDBC type");
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.util.JdbcUtil;
|
||||
|
||||
/**
|
||||
* SQL构建器。
|
||||
*
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
package org.datagear.persistence.columnconverter;
|
||||
|
||||
import org.datagear.persistence.features.ColumnConverter;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.util.IDUtil;
|
||||
|
||||
/**
|
||||
* 抽象{@linkplain ColumnConverter}。
|
||||
|
@ -27,6 +27,6 @@ public abstract class AbstractColumnConverter implements ColumnConverter
|
|||
*/
|
||||
protected String uuid()
|
||||
{
|
||||
return UUID.gen();
|
||||
return IDUtil.uuid();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ import java.sql.Statement;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.persistence.PersistenceException;
|
||||
import org.datagear.persistence.SqlBuilder;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.model.Model;
|
||||
import org.datagear.model.Property;
|
||||
import org.datagear.model.support.MU;
|
||||
import org.datagear.persistence.UnsupportedModelCharacterException;
|
||||
import org.datagear.persistence.support.ExpressionResolver.Expression;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.datagear.util.expression.ExpressionResolver;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
|
@ -32,9 +32,9 @@ public abstract class AbstractExpressionModelPersistenceOperation extends Abstra
|
|||
{
|
||||
private ConversionService conversionService;
|
||||
|
||||
private ExpressionResolver variableExpressionResolver;
|
||||
private NameExpressionResolver variableExpressionResolver;
|
||||
|
||||
private ExpressionResolver sqlExpressionResolver;
|
||||
private NameExpressionResolver sqlExpressionResolver;
|
||||
|
||||
private SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
|
||||
|
||||
|
@ -44,7 +44,7 @@ public abstract class AbstractExpressionModelPersistenceOperation extends Abstra
|
|||
}
|
||||
|
||||
public AbstractExpressionModelPersistenceOperation(ConversionService conversionService,
|
||||
ExpressionResolver variableExpressionResolver, ExpressionResolver sqlExpressionResolver)
|
||||
NameExpressionResolver variableExpressionResolver, NameExpressionResolver sqlExpressionResolver)
|
||||
{
|
||||
super();
|
||||
this.conversionService = conversionService;
|
||||
|
@ -67,24 +67,19 @@ public abstract class AbstractExpressionModelPersistenceOperation extends Abstra
|
|||
return variableExpressionResolver;
|
||||
}
|
||||
|
||||
public void setVariableExpressionResolver(ExpressionResolver variableExpressionResolver)
|
||||
{
|
||||
this.variableExpressionResolver = variableExpressionResolver;
|
||||
}
|
||||
|
||||
public ExpressionResolver getSqlExpressionResolver()
|
||||
public NameExpressionResolver getSqlExpressionResolver()
|
||||
{
|
||||
return sqlExpressionResolver;
|
||||
}
|
||||
|
||||
public void setSqlExpressionResolver(ExpressionResolver sqlExpressionResolver)
|
||||
public void setSqlExpressionResolver(NameExpressionResolver sqlExpressionResolver)
|
||||
{
|
||||
this.sqlExpressionResolver = sqlExpressionResolver;
|
||||
}
|
||||
|
||||
public SpelExpressionParser getSpelExpressionParser()
|
||||
public void setVariableExpressionResolver(NameExpressionResolver variableExpressionResolver)
|
||||
{
|
||||
return spelExpressionParser;
|
||||
this.variableExpressionResolver = variableExpressionResolver;
|
||||
}
|
||||
|
||||
public void setSpelExpressionParser(SpelExpressionParser spelExpressionParser)
|
||||
|
@ -108,7 +103,7 @@ public abstract class AbstractExpressionModelPersistenceOperation extends Abstra
|
|||
protected Object evaluatePropertyValueIfExpression(Connection cn, Model model, Property property, Object propValue,
|
||||
ExpressionEvaluationContext expressionEvaluationContext)
|
||||
{
|
||||
List<Expression> variableExpressions = this.variableExpressionResolver.resolve(propValue);
|
||||
List<NameExpression> variableExpressions = this.variableExpressionResolver.resolveNameExpressions(propValue);
|
||||
|
||||
Object evaluatedPropValue = propValue;
|
||||
|
||||
|
@ -122,7 +117,7 @@ public abstract class AbstractExpressionModelPersistenceOperation extends Abstra
|
|||
expressionEvaluationContext);
|
||||
}
|
||||
|
||||
List<Expression> sqlExpressions = this.sqlExpressionResolver.resolve(evaluatedPropValue);
|
||||
List<NameExpression> sqlExpressions = this.sqlExpressionResolver.resolveNameExpressions(evaluatedPropValue);
|
||||
|
||||
if (sqlExpressions != null && !sqlExpressions.isEmpty())
|
||||
{
|
||||
|
@ -158,14 +153,14 @@ public abstract class AbstractExpressionModelPersistenceOperation extends Abstra
|
|||
* @return
|
||||
* @throws VariableExpressionErrorException
|
||||
*/
|
||||
protected Object evaluateVariableExpressions(String source, List<Expression> expressions,
|
||||
protected Object evaluateVariableExpressions(String source, List<NameExpression> expressions,
|
||||
ExpressionEvaluationContext expressionEvaluationContext) throws VariableExpressionErrorException
|
||||
{
|
||||
List<Object> expressionValues = new ArrayList<Object>();
|
||||
|
||||
for (int i = 0, len = expressions.size(); i < len; i++)
|
||||
{
|
||||
Expression expression = expressions.get(i);
|
||||
NameExpression expression = expressions.get(i);
|
||||
|
||||
if (expressionEvaluationContext.containsCachedValue(expression))
|
||||
{
|
||||
|
@ -198,7 +193,7 @@ public abstract class AbstractExpressionModelPersistenceOperation extends Abstra
|
|||
* @throws SqlExpressionErrorException
|
||||
* @throws VariableExpressionErrorException
|
||||
*/
|
||||
protected Object evaluateSqlExpressions(Connection cn, String source, List<Expression> expressions,
|
||||
protected Object evaluateSqlExpressions(Connection cn, String source, List<NameExpression> expressions,
|
||||
ExpressionEvaluationContext expressionEvaluationContext)
|
||||
throws SqlExpressionErrorException, VariableExpressionErrorException
|
||||
{
|
||||
|
@ -206,7 +201,7 @@ public abstract class AbstractExpressionModelPersistenceOperation extends Abstra
|
|||
|
||||
for (int i = 0, len = expressions.size(); i < len; i++)
|
||||
{
|
||||
Expression expression = expressions.get(i);
|
||||
NameExpression expression = expressions.get(i);
|
||||
|
||||
if (expressionEvaluationContext.containsCachedValue(expression))
|
||||
{
|
||||
|
@ -237,7 +232,7 @@ public abstract class AbstractExpressionModelPersistenceOperation extends Abstra
|
|||
* @param cn
|
||||
* @throws SqlExpressionErrorException
|
||||
*/
|
||||
protected void evaluateAsSelectSqlExpression(Expression expression,
|
||||
protected void evaluateAsSelectSqlExpression(NameExpression expression,
|
||||
ExpressionEvaluationContext expressionEvaluationContext, List<Object> expressionValues, Connection cn)
|
||||
throws SqlExpressionErrorException
|
||||
{
|
||||
|
@ -278,7 +273,7 @@ public abstract class AbstractExpressionModelPersistenceOperation extends Abstra
|
|||
* @param expressionValues
|
||||
* @throws VariableExpressionErrorException
|
||||
*/
|
||||
protected void evaluateAsVariableExpression(Expression expression,
|
||||
protected void evaluateAsVariableExpression(NameExpression expression,
|
||||
ExpressionEvaluationContext expressionEvaluationContext, List<Object> expressionValues)
|
||||
throws VariableExpressionErrorException
|
||||
{
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.datagear.connection.ConnectionOption;
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.dbinfo.ColumnInfo;
|
||||
import org.datagear.dbinfo.DatabaseInfoResolver;
|
||||
import org.datagear.dbinfo.TableInfo;
|
||||
|
@ -25,6 +24,7 @@ import org.datagear.persistence.DialectSource;
|
|||
import org.datagear.persistence.Order;
|
||||
import org.datagear.persistence.SqlBuilder;
|
||||
import org.datagear.persistence.UnsupportedDialectException;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
|
||||
/**
|
||||
* 默认{@linkplain DialectSource}。
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.datagear.persistence.PersistenceManager;
|
|||
import org.datagear.persistence.QueryResultMetaInfo;
|
||||
import org.datagear.persistence.SqlBuilder;
|
||||
import org.datagear.persistence.mapper.Mapper;
|
||||
import org.datagear.util.expression.ExpressionResolver;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
|
||||
/**
|
||||
|
@ -37,9 +38,9 @@ public class DefaultPersistenceManager extends AbstractModelDataAccessObject imp
|
|||
|
||||
private ConversionService conversionService;
|
||||
|
||||
private ExpressionResolver variableExpressionResolver;
|
||||
private NameExpressionResolver variableExpressionResolver;
|
||||
|
||||
private ExpressionResolver sqlExpressionResolver;
|
||||
private NameExpressionResolver sqlExpressionResolver;
|
||||
|
||||
private InsertPersistenceOperation insertPersistenceOperation;
|
||||
|
||||
|
@ -105,7 +106,7 @@ public class DefaultPersistenceManager extends AbstractModelDataAccessObject imp
|
|||
return variableExpressionResolver;
|
||||
}
|
||||
|
||||
public void setVariableExpressionResolver(ExpressionResolver variableExpressionResolver)
|
||||
public void setVariableExpressionResolver(NameExpressionResolver variableExpressionResolver)
|
||||
{
|
||||
this.variableExpressionResolver = variableExpressionResolver;
|
||||
this.insertPersistenceOperation.setVariableExpressionResolver(variableExpressionResolver);
|
||||
|
@ -117,7 +118,7 @@ public class DefaultPersistenceManager extends AbstractModelDataAccessObject imp
|
|||
return sqlExpressionResolver;
|
||||
}
|
||||
|
||||
public void setSqlExpressionResolver(ExpressionResolver sqlExpressionResolver)
|
||||
public void setSqlExpressionResolver(NameExpressionResolver sqlExpressionResolver)
|
||||
{
|
||||
this.sqlExpressionResolver = sqlExpressionResolver;
|
||||
this.insertPersistenceOperation.setSqlExpressionResolver(sqlExpressionResolver);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
package org.datagear.persistence.support;
|
||||
|
||||
import org.datagear.persistence.PersistenceException;
|
||||
import org.datagear.persistence.support.ExpressionResolver.Expression;
|
||||
import org.datagear.util.expression.Expression;
|
||||
|
||||
/**
|
||||
* {@linkplain Expression}执行出错异常。
|
||||
|
|
|
@ -7,10 +7,10 @@ package org.datagear.persistence.support;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.datagear.persistence.support.ExpressionResolver.Expression;
|
||||
import org.datagear.util.expression.ExpressionResolver;
|
||||
|
||||
/**
|
||||
* {@linkplain Expression}计算上下文。
|
||||
* {@linkplain NameExpression}计算上下文。
|
||||
* <p>
|
||||
* 为了方便支持批量添加操作,此类的实例默认会添加{@linkplain #VARIABLE_INDEX}变量并且初值为{@code 0}。
|
||||
* </p>
|
||||
|
@ -56,12 +56,12 @@ public class ExpressionEvaluationContext
|
|||
}
|
||||
|
||||
/**
|
||||
* 是否包含指定{@linkplain Expression}的缓存值。
|
||||
* 是否包含指定{@linkplain NameExpression}的缓存值。
|
||||
*
|
||||
* @param expression
|
||||
* @return
|
||||
*/
|
||||
public boolean containsCachedValue(Expression expression)
|
||||
public boolean containsCachedValue(NameExpression expression)
|
||||
{
|
||||
String cacheKey = getCachedValueKey(expression);
|
||||
|
||||
|
@ -69,12 +69,12 @@ public class ExpressionEvaluationContext
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取指定{@linkplain Expression}的缓存值。
|
||||
* 获取指定{@linkplain NameExpression}的缓存值。
|
||||
*
|
||||
* @param expression
|
||||
* @return
|
||||
*/
|
||||
public Object getCachedValue(Expression expression)
|
||||
public Object getCachedValue(NameExpression expression)
|
||||
{
|
||||
String cacheKey = getCachedValueKey(expression);
|
||||
|
||||
|
@ -82,12 +82,12 @@ public class ExpressionEvaluationContext
|
|||
}
|
||||
|
||||
/**
|
||||
* 将指定{@linkplain Expression}的值加入缓存。
|
||||
* 将指定{@linkplain NameExpression}的值加入缓存。
|
||||
*
|
||||
* @param expression
|
||||
* @param value
|
||||
*/
|
||||
public void putCachedValue(Expression expression, Object value)
|
||||
public void putCachedValue(NameExpression expression, Object value)
|
||||
{
|
||||
String cacheKey = getCachedValueKey(expression);
|
||||
|
||||
|
@ -147,7 +147,7 @@ public class ExpressionEvaluationContext
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
protected String getCachedValueKey(Expression expression)
|
||||
protected String getCachedValueKey(NameExpression expression)
|
||||
{
|
||||
return expression.getStartIdentifier() + (expression.hasName() ? expression.getName() : expression.getContent())
|
||||
+ expression.getEndIdentifier();
|
||||
|
|
|
@ -1,557 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.persistence.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表达式解析器。
|
||||
* <p>
|
||||
* 它解析字符串中类似"${content}"、"${name:content}"格式的表达式。
|
||||
* </p>
|
||||
* <p>
|
||||
* 默认地,它使用{@code '\'}作为转义字符,字符串中的"\${"、"\:"、"\}"将作为普通字符。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class ExpressionResolver
|
||||
{
|
||||
/** "${"起始标识符 */
|
||||
public static final String DEFAULT_START_IDENTIFIER_DOLLAR = "${";
|
||||
|
||||
/** "#{"起始标识符 */
|
||||
public static final String DEFAULT_START_IDENTIFIER_SHARP = "#{";
|
||||
|
||||
public static final String DEFAULT_END_IDENTIFIER = "}";
|
||||
|
||||
public static final String DEFAULT_SEPARATOR = ":";
|
||||
|
||||
public static final char DEFAULT_ESCAPER = '\\';
|
||||
|
||||
private String startIdentifier = DEFAULT_START_IDENTIFIER_DOLLAR;
|
||||
|
||||
private String endIdentifier = DEFAULT_END_IDENTIFIER;
|
||||
|
||||
private String separator = DEFAULT_SEPARATOR;
|
||||
|
||||
private char escaper = DEFAULT_ESCAPER;
|
||||
|
||||
private transient char[] _startIdentifierChars = DEFAULT_START_IDENTIFIER_DOLLAR.toCharArray();
|
||||
|
||||
private transient char[] _endIdentifierChars = DEFAULT_END_IDENTIFIER.toCharArray();
|
||||
|
||||
private transient char[] _separatorChars = DEFAULT_SEPARATOR.toCharArray();
|
||||
|
||||
public ExpressionResolver()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public String getStartIdentifier()
|
||||
{
|
||||
return startIdentifier;
|
||||
}
|
||||
|
||||
public void setStartIdentifier(String startIdentifier)
|
||||
{
|
||||
this.startIdentifier = startIdentifier;
|
||||
this._startIdentifierChars = startIdentifier.toCharArray();
|
||||
}
|
||||
|
||||
public String getEndIdentifier()
|
||||
{
|
||||
return endIdentifier;
|
||||
}
|
||||
|
||||
public void setEndIdentifier(String endIdentifier)
|
||||
{
|
||||
this.endIdentifier = endIdentifier;
|
||||
this._endIdentifierChars = endIdentifier.toCharArray();
|
||||
}
|
||||
|
||||
public String getSeparator()
|
||||
{
|
||||
return separator;
|
||||
}
|
||||
|
||||
public void setSeparator(String separator)
|
||||
{
|
||||
this.separator = separator;
|
||||
this._separatorChars = separator.toCharArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串是否是表达式字符串。
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public boolean isExpression(String source)
|
||||
{
|
||||
if (source == null || source.isEmpty())
|
||||
return false;
|
||||
|
||||
char[] cs = source.toCharArray();
|
||||
|
||||
return (resolveNextExpression(cs, 0) != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对象是否是表达式字符串。
|
||||
* <p>
|
||||
* 如果对象不是字符串,将返回{@code false}。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public boolean isExpression(Object source)
|
||||
{
|
||||
if (source == null || !(source instanceof String))
|
||||
return false;
|
||||
|
||||
return isExpression((String) source);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析对象中的{@linkplain Expression}列表。
|
||||
* <p>
|
||||
* 如果对象不是字符串,将返回空列表。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public List<Expression> resolve(Object source)
|
||||
{
|
||||
if (source == null || !(source instanceof String))
|
||||
return Collections.emptyList();
|
||||
else
|
||||
return resolve((String) source);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析字符串中的{@linkplain Expression}列表。
|
||||
* <p>
|
||||
* 如果不包含表达式,将返回空列表。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public List<Expression> resolve(String source)
|
||||
{
|
||||
if (source == null || source.isEmpty())
|
||||
return Collections.emptyList();
|
||||
|
||||
List<Expression> expressions = null;
|
||||
|
||||
char[] cs = source.toCharArray();
|
||||
|
||||
Expression next = null;
|
||||
int startIndex = 0;
|
||||
|
||||
while ((next = resolveNextExpression(cs, startIndex)) != null)
|
||||
{
|
||||
if (expressions == null)
|
||||
expressions = new ArrayList<Expression>();
|
||||
|
||||
expressions.add(next);
|
||||
startIndex = next.getEnd();
|
||||
}
|
||||
|
||||
if (expressions == null)
|
||||
expressions = Collections.emptyList();
|
||||
|
||||
return expressions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算字符串表达式的值。
|
||||
*
|
||||
* @param source
|
||||
* @param expressions
|
||||
* @param values
|
||||
* @param nullValue
|
||||
* @return
|
||||
*/
|
||||
public String evaluate(String source, List<Expression> expressions, List<?> values, String nullValue)
|
||||
{
|
||||
if (expressions == null || expressions.isEmpty())
|
||||
return source;
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
int gapStart = 0;
|
||||
|
||||
char[] cs = source.toCharArray();
|
||||
for (int i = 0; i < expressions.size(); i++)
|
||||
{
|
||||
Expression expression = expressions.get(i);
|
||||
Object value = values.get(i);
|
||||
|
||||
copyForUnescape(cs, gapStart, expression.getStart(), result);
|
||||
|
||||
if (value == null)
|
||||
result.append(nullValue);
|
||||
else if (value instanceof String)
|
||||
result.append((String) value);
|
||||
else
|
||||
result.append(value.toString());
|
||||
|
||||
gapStart = expression.getEnd();
|
||||
}
|
||||
|
||||
copyForUnescape(cs, gapStart, cs.length, result);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串进行表达式语法反转义。
|
||||
* <p>
|
||||
* 注意:它仅会反转义匹配表达式起始标识符、分隔标识符、结束标识符的的子串。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public String unescape(String source)
|
||||
{
|
||||
if (source == null || source.isEmpty())
|
||||
return source;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
char[] cs = source.toCharArray();
|
||||
|
||||
copyForUnescape(cs, 0, cs.length, sb);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象进行表达式语法反转义。
|
||||
* <p>
|
||||
* 如果{@code obj}不是字符串,将直接返回它。
|
||||
* </p>
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public Object unescape(Object obj)
|
||||
{
|
||||
if (obj instanceof String)
|
||||
return unescape((String) obj);
|
||||
else
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将源字符数组中的某些字符拷贝到目标字符串缓冲,并进行表达式语法反转义。
|
||||
* <p>
|
||||
* 注意:为了减少输入时的转义麻烦,它仅会反转义匹配表达式起始标识符、分隔标识符、结束标识符的的字符串。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @param start
|
||||
* @param end
|
||||
* @param sb
|
||||
*/
|
||||
protected void copyForUnescape(char[] source, int start, int end, StringBuilder sb)
|
||||
{
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
char c = source[i];
|
||||
|
||||
if (c == this.escaper)
|
||||
{
|
||||
if (match(source, i + 1, this._startIdentifierChars, 0))
|
||||
;
|
||||
else if (match(source, i + 1, this._separatorChars, 0))
|
||||
;
|
||||
else if (match(source, i + 1, this._endIdentifierChars, 0))
|
||||
;
|
||||
else
|
||||
sb.append(c);
|
||||
}
|
||||
else
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从给定起始位置解析下一个{@linkplain Expression}。
|
||||
* <p>
|
||||
* 如果没有,将返回{@code null}。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @param startIndex
|
||||
* @return
|
||||
*/
|
||||
protected Expression resolveNextExpression(char[] source, int startIndex)
|
||||
{
|
||||
for (int i = startIndex; i < source.length; i++)
|
||||
{
|
||||
char pci = (i < 1 ? 0 : source[i - 1]);
|
||||
|
||||
// 是起始标识符并且前一个字符不是转义字符
|
||||
if (match(source, i, this._startIdentifierChars, 0) && pci != this.escaper)
|
||||
{
|
||||
StringBuilder first = new StringBuilder();
|
||||
StringBuilder second = null;
|
||||
|
||||
int j = i + this._startIdentifierChars.length;
|
||||
for (; j < source.length; j++)
|
||||
{
|
||||
char cj = source[j];
|
||||
|
||||
if (cj == this.escaper)
|
||||
{
|
||||
if (match(source, j + 1, this._separatorChars, 0))
|
||||
{
|
||||
if (second != null)
|
||||
second.append(this._separatorChars);
|
||||
else
|
||||
first.append(this._separatorChars);
|
||||
|
||||
j += this._separatorChars.length;
|
||||
}
|
||||
else if (match(source, j + 1, this._endIdentifierChars, 0))
|
||||
{
|
||||
if (second != null)
|
||||
second.append(this._endIdentifierChars);
|
||||
else
|
||||
first.append(this._endIdentifierChars);
|
||||
|
||||
j += this._endIdentifierChars.length;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (second != null)
|
||||
second.append(this._separatorChars);
|
||||
else
|
||||
first.append(this._separatorChars);
|
||||
}
|
||||
}
|
||||
else if (match(source, j, this._separatorChars, 0) && second == null)
|
||||
{
|
||||
j += this._separatorChars.length - 1;
|
||||
second = new StringBuilder();
|
||||
}
|
||||
else if (match(source, j, this._endIdentifierChars, 0))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (second != null)
|
||||
second.append(cj);
|
||||
else
|
||||
first.append(cj);
|
||||
}
|
||||
}
|
||||
|
||||
if (j == source.length || first.length() == 0 || (second != null && second.length() == 0))
|
||||
continue;
|
||||
else
|
||||
{
|
||||
String name = null, content = null;
|
||||
|
||||
if (second == null)
|
||||
content = first.toString().trim();
|
||||
else
|
||||
{
|
||||
name = first.toString().trim();
|
||||
content = second.toString().trim();
|
||||
}
|
||||
|
||||
return new Expression(this.getStartIdentifier(), this.endIdentifier,
|
||||
new String(source, i, j + 1 - i), i, j + 1, name, content);
|
||||
}
|
||||
}
|
||||
else
|
||||
;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否匹配前缀。
|
||||
*
|
||||
* @param source
|
||||
* @param sourceStartIndex
|
||||
* @param prefix
|
||||
* @param prefixStartIndex
|
||||
* @return
|
||||
*/
|
||||
protected boolean match(char[] source, int sourceStartIndex, char[] prefix, int prefixStartIndex)
|
||||
{
|
||||
for (int i = sourceStartIndex, j = prefixStartIndex; i < source.length && j < prefix.length; i++, j++)
|
||||
{
|
||||
if (source[i] != prefix[j])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 表达式。
|
||||
* <p>
|
||||
* 格式为:${name:content}、${content}、#{name:content}、#{content}。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public static class Expression implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 起始标识符 */
|
||||
private String startIdentifier;
|
||||
|
||||
/** 结束标识符 */
|
||||
private String endIdentifier;
|
||||
|
||||
/** 表达式字符串 */
|
||||
private String expression;
|
||||
|
||||
/** 表达式起始位置 */
|
||||
private int start;
|
||||
|
||||
/** 表达式结束位置 */
|
||||
private int end;
|
||||
|
||||
/** 表达式的名称 */
|
||||
private String name;
|
||||
|
||||
/** 表达式内容 */
|
||||
private String content;
|
||||
|
||||
public Expression(String startIdentifier, String endIdentifier, String expression, int start, int end,
|
||||
String content)
|
||||
{
|
||||
super();
|
||||
this.startIdentifier = startIdentifier;
|
||||
this.endIdentifier = endIdentifier;
|
||||
this.expression = expression;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Expression(String startIdentifier, String endIdentifier, String expression, int start, int end,
|
||||
String name, String content)
|
||||
{
|
||||
super();
|
||||
this.startIdentifier = startIdentifier;
|
||||
this.endIdentifier = endIdentifier;
|
||||
this.expression = expression;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.name = name;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getStartIdentifier()
|
||||
{
|
||||
return startIdentifier;
|
||||
}
|
||||
|
||||
protected void setStartIdentifier(String startIdentifier)
|
||||
{
|
||||
this.startIdentifier = startIdentifier;
|
||||
}
|
||||
|
||||
public String getEndIdentifier()
|
||||
{
|
||||
return endIdentifier;
|
||||
}
|
||||
|
||||
protected void setEndIdentifier(String endIdentifier)
|
||||
{
|
||||
this.endIdentifier = endIdentifier;
|
||||
}
|
||||
|
||||
public String getExpression()
|
||||
{
|
||||
return expression;
|
||||
}
|
||||
|
||||
protected void setExpression(String expression)
|
||||
{
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
public int getStart()
|
||||
{
|
||||
return start;
|
||||
}
|
||||
|
||||
protected void setStart(int start)
|
||||
{
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public int getEnd()
|
||||
{
|
||||
return end;
|
||||
}
|
||||
|
||||
protected void setEnd(int end)
|
||||
{
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有名称。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean hasName()
|
||||
{
|
||||
return (this.name != null && !this.name.isEmpty());
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
protected void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getContent()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
protected void setContent(String content)
|
||||
{
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getSimpleName() + " [expression=" + expression + ", start=" + start + ", end=" + end
|
||||
+ ", name=" + name + ", content=" + content + "]";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,7 +39,7 @@ public class InsertPersistenceOperation extends AbstractExpressionModelPersisten
|
|||
}
|
||||
|
||||
public InsertPersistenceOperation(ConversionService conversionService,
|
||||
ExpressionResolver variableExpressionResolver, ExpressionResolver sqlExpressionResolver)
|
||||
NameExpressionResolver variableExpressionResolver, NameExpressionResolver sqlExpressionResolver)
|
||||
{
|
||||
super(conversionService, variableExpressionResolver, sqlExpressionResolver);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.org. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.persistence.support;
|
||||
|
||||
import org.datagear.util.expression.Expression;
|
||||
|
||||
/**
|
||||
* 名字表达式。
|
||||
* <p>
|
||||
* 格式为:<code>"${name:content}"</code>、<code>"#{name:content}"</code>
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class NameExpression extends Expression
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String name;
|
||||
|
||||
public NameExpression()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public NameExpression(String startIdentifier, String endIdentifier, String expression, int startIndex, int endIndex,
|
||||
String content)
|
||||
{
|
||||
super(startIdentifier, endIdentifier, expression, startIndex, endIndex, content);
|
||||
}
|
||||
|
||||
public boolean hasName()
|
||||
{
|
||||
return (this.name != null && !this.name.isEmpty());
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.org. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.persistence.support;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.util.expression.ExpressionResolver;
|
||||
|
||||
/**
|
||||
* {@linkplain NameExpression}解析器。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class NameExpressionResolver extends ExpressionResolver
|
||||
{
|
||||
public static final String DEFAULT_SEPARATOR = ":";
|
||||
|
||||
private String separator = DEFAULT_SEPARATOR;
|
||||
|
||||
public NameExpressionResolver()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public String getSeparator()
|
||||
{
|
||||
return separator;
|
||||
}
|
||||
|
||||
public void setSeparator(String separator)
|
||||
{
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析{@linkplain NameExpression}。
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public List<NameExpression> resolveNameExpressions(String source)
|
||||
{
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
List<NameExpression> expressions = (List) super.resolve(source);
|
||||
|
||||
return expressions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析{@linkplain NameExpression}。
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public List<NameExpression> resolveNameExpressions(Object source)
|
||||
{
|
||||
if (source == null || !(source instanceof String))
|
||||
return Collections.emptyList();
|
||||
else
|
||||
return resolveNameExpressions((String) source);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对象是否是表达式字符串。
|
||||
* <p>
|
||||
* 如果对象不是字符串,将返回{@code false}。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public boolean isExpression(Object source)
|
||||
{
|
||||
if (source == null || !(source instanceof String))
|
||||
return false;
|
||||
|
||||
return isExpression((String) source);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NameExpression newExpressionInstance(String startIdentifier, String endIdentifier, String expression,
|
||||
int startIndex, int endIndex, String content)
|
||||
{
|
||||
NameExpression nameExpression = new NameExpression(startIdentifier, endIdentifier, expression, startIndex,
|
||||
endIndex, content);
|
||||
|
||||
String[] nameAndContent = resolveNameAndContent(content);
|
||||
|
||||
if (nameAndContent.length == 1)
|
||||
nameExpression.setContent(nameAndContent[0]);
|
||||
else
|
||||
{
|
||||
nameExpression.setName(nameAndContent[0]);
|
||||
nameExpression.setContent(nameAndContent[1]);
|
||||
}
|
||||
|
||||
return nameExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析名字内容数组。
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
protected String[] resolveNameAndContent(String source)
|
||||
{
|
||||
StringBuilder first = new StringBuilder();
|
||||
StringBuilder second = null;
|
||||
|
||||
for (int i = 0; i < source.length();)
|
||||
{
|
||||
char c = source.charAt(i);
|
||||
if (c == getEscaper() && matchAtIndex(source, i + 1, this.separator))
|
||||
{
|
||||
if (second != null)
|
||||
second.append(this.separator);
|
||||
else
|
||||
first.append(this.separator);
|
||||
|
||||
i += this.separator.length() + 1;
|
||||
}
|
||||
else if (matchAtIndex(source, i, this.separator))
|
||||
{
|
||||
i += this.separator.length();
|
||||
second = new StringBuilder();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (second != null)
|
||||
second.append(c);
|
||||
else
|
||||
first.append(c);
|
||||
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
String firstStr = first.toString().trim();
|
||||
String secondStr = (second == null ? null : second.toString().trim());
|
||||
|
||||
if (secondStr == null || secondStr.isEmpty())
|
||||
return new String[] { firstStr };
|
||||
else
|
||||
return new String[] { firstStr, secondStr };
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package org.datagear.persistence.support;
|
||||
|
||||
import org.datagear.persistence.support.ExpressionResolver.Expression;
|
||||
import org.datagear.util.expression.Expression;
|
||||
|
||||
/**
|
||||
* SQL表达式出错异常。
|
||||
|
|
|
@ -13,7 +13,7 @@ package org.datagear.persistence.support;
|
|||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class SqlExpressionResolver extends ExpressionResolver
|
||||
public class SqlExpressionResolver extends NameExpressionResolver
|
||||
{
|
||||
public SqlExpressionResolver()
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package org.datagear.persistence.support;
|
||||
|
||||
import org.datagear.persistence.support.ExpressionResolver.Expression;
|
||||
import org.datagear.util.expression.Expression;
|
||||
|
||||
/**
|
||||
* SQL表达式语法出错异常。
|
||||
|
|
|
@ -43,7 +43,7 @@ public class UpdatePersistenceOperation extends AbstractExpressionModelPersisten
|
|||
|
||||
public UpdatePersistenceOperation(InsertPersistenceOperation insertPersistenceOperation,
|
||||
DeletePersistenceOperation deletePersistenceOperation, ConversionService conversionService,
|
||||
ExpressionResolver variableExpressionResolver, ExpressionResolver sqlExpressionResolver)
|
||||
NameExpressionResolver variableExpressionResolver, NameExpressionResolver sqlExpressionResolver)
|
||||
{
|
||||
super(conversionService, variableExpressionResolver, sqlExpressionResolver);
|
||||
this.insertPersistenceOperation = insertPersistenceOperation;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package org.datagear.persistence.support;
|
||||
|
||||
import org.datagear.persistence.support.ExpressionResolver.Expression;
|
||||
import org.datagear.util.expression.Expression;
|
||||
|
||||
/**
|
||||
* 变量表达式出错异常。
|
||||
|
|
|
@ -13,7 +13,7 @@ package org.datagear.persistence.support;
|
|||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class VariableExpressionResolver extends ExpressionResolver
|
||||
public class VariableExpressionResolver extends NameExpressionResolver
|
||||
{
|
||||
public VariableExpressionResolver()
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package org.datagear.persistence.support;
|
||||
|
||||
import org.datagear.persistence.support.ExpressionResolver.Expression;
|
||||
import org.datagear.util.expression.Expression;
|
||||
|
||||
/**
|
||||
* 变量表达式语法错误异常。
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.persistence.support;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.util.expression.ExpressionResolver;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* {@linkplain ExpressionResolver}单元测试类。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class NameExpressionResolverTest
|
||||
{
|
||||
@Test
|
||||
public void resolveTest()
|
||||
{
|
||||
NameExpressionResolver expressionResolver = new NameExpressionResolver();
|
||||
|
||||
{
|
||||
List<NameExpression> expressions = expressionResolver.resolveNameExpressions("${name:content}");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
NameExpression e = expressions.get(0);
|
||||
Assert.assertEquals("${name:content}", e.getExpression());
|
||||
Assert.assertEquals(0, e.getStartIndex());
|
||||
Assert.assertEquals("${name:content}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("name", e.getName());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<NameExpression> expressions = expressionResolver.resolveNameExpressions("prefix${name:content}");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
NameExpression e = expressions.get(0);
|
||||
Assert.assertEquals("${name:content}", e.getExpression());
|
||||
Assert.assertEquals(6, e.getStartIndex());
|
||||
Assert.assertEquals(6 + "${name:content}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("name", e.getName());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<NameExpression> expressions = expressionResolver.resolveNameExpressions("${name:content}suffix");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
NameExpression e = expressions.get(0);
|
||||
Assert.assertEquals("${name:content}", e.getExpression());
|
||||
Assert.assertEquals(0, e.getStartIndex());
|
||||
Assert.assertEquals("${name:content}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("name", e.getName());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<NameExpression> expressions = expressionResolver.resolveNameExpressions("prefix${name:content}suffix");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
NameExpression e = expressions.get(0);
|
||||
Assert.assertEquals("${name:content}", e.getExpression());
|
||||
Assert.assertEquals(6, e.getStartIndex());
|
||||
Assert.assertEquals(6 + "${name:content}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("name", e.getName());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<NameExpression> expressions = expressionResolver.resolveNameExpressions("${ name : content }");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
NameExpression e = expressions.get(0);
|
||||
Assert.assertEquals("${ name : content }", e.getExpression());
|
||||
Assert.assertEquals(0, e.getStartIndex());
|
||||
Assert.assertEquals("${ name : content }".length(), e.getEndIndex());
|
||||
Assert.assertEquals("name", e.getName());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<NameExpression> expressions = expressionResolver
|
||||
.resolveNameExpressions("prefix${content0}gap${name1 : content1}gap${ name2: content2 }sufix");
|
||||
|
||||
Assert.assertEquals(3, expressions.size());
|
||||
|
||||
{
|
||||
NameExpression e = expressions.get(0);
|
||||
Assert.assertEquals("${content0}", e.getExpression());
|
||||
Assert.assertEquals(6, e.getStartIndex());
|
||||
Assert.assertEquals(6 + "${content0}".length(), e.getEndIndex());
|
||||
Assert.assertFalse(e.hasName());
|
||||
Assert.assertEquals("content0", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
NameExpression e = expressions.get(1);
|
||||
Assert.assertEquals("${name1 : content1}", e.getExpression());
|
||||
Assert.assertEquals("prefix${content0}gap".length(), e.getStartIndex());
|
||||
Assert.assertEquals("prefix${content0}gap${name1 : content1}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("name1", e.getName());
|
||||
Assert.assertEquals("content1", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
NameExpression e = expressions.get(2);
|
||||
Assert.assertEquals("${ name2: content2 }", e.getExpression());
|
||||
Assert.assertEquals("prefix${content0}gap${name1 : content1}gap".length(), e.getStartIndex());
|
||||
Assert.assertEquals("prefix${content0}gap${name1 : content1}gap${ name2: content2 }".length(),
|
||||
e.getEndIndex());
|
||||
Assert.assertEquals("name2", e.getName());
|
||||
Assert.assertEquals("content2", e.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
List<NameExpression> expressions = expressionResolver.resolveNameExpressions("prefix${cont\\:ent\\}0}");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
NameExpression e = expressions.get(0);
|
||||
Assert.assertEquals("cont:ent}0", e.getContent());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.datagear</groupId>
|
||||
<artifactId>datagear</artifactId>
|
||||
<version>1.3.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>datagear-util</artifactId>
|
||||
<name>datagear-util</name>
|
||||
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.web.vo;
|
||||
package org.datagear.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.DecimalFormat;
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.org. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 文件工具类。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class FileUtil
|
||||
{
|
||||
private FileUtil()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件对象。
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static File getFile(String file)
|
||||
{
|
||||
return new File(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定目录下的文件对象。
|
||||
*
|
||||
* @param parent
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static File getFile(File parent, String file)
|
||||
{
|
||||
return new File(parent, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件。
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
public static void deleteFile(File file)
|
||||
{
|
||||
if (!file.exists())
|
||||
return;
|
||||
|
||||
if (file.isDirectory())
|
||||
{
|
||||
File[] children = file.listFiles();
|
||||
|
||||
for (File child : children)
|
||||
deleteFile(child);
|
||||
}
|
||||
|
||||
file.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空目录,保留目录本身。
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
public static void clearDirectory(File directory)
|
||||
{
|
||||
if (!directory.exists())
|
||||
return;
|
||||
|
||||
if (directory.isDirectory())
|
||||
{
|
||||
File[] children = directory.listFiles();
|
||||
|
||||
for (File child : children)
|
||||
deleteFile(child);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在指定目录下生成一个文件。
|
||||
*
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
public static File generateUniqueFile(File parent)
|
||||
{
|
||||
return new File(parent, IDUtil.uuid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 在指定目录下生成一个子文件夹。
|
||||
*
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
public static File generateUniqueDirectory(File parent)
|
||||
{
|
||||
File file = new File(parent, IDUtil.uuid());
|
||||
|
||||
if (!file.exists())
|
||||
file.mkdirs();
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出指定目录下的文件名称。
|
||||
*
|
||||
* @param directory
|
||||
* @return
|
||||
*/
|
||||
public static String[] listFileNames(File directory)
|
||||
{
|
||||
if (!directory.exists())
|
||||
return new String[0];
|
||||
|
||||
return directory.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定文件的{@linkplain FileInfo}。
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static FileInfo getFileInfo(File file)
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(file.getName());
|
||||
|
||||
if (file.exists())
|
||||
fileInfo.setBytes(file.length());
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定目录下文件的{@linkplain FileInfo}。
|
||||
*
|
||||
* @param directory
|
||||
* @return
|
||||
*/
|
||||
public static FileInfo[] getFileInfos(File directory)
|
||||
{
|
||||
if (!directory.exists())
|
||||
return new FileInfo[0];
|
||||
|
||||
File[] files = directory.listFiles();
|
||||
|
||||
FileInfo[] fileInfos = new FileInfo[files.length];
|
||||
|
||||
for (int i = 0; i < files.length; i++)
|
||||
fileInfos[i] = getFileInfo(files[i]);
|
||||
|
||||
return fileInfos;
|
||||
}
|
||||
}
|
|
@ -2,30 +2,27 @@
|
|||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.persistence.support;
|
||||
package org.datagear.util;
|
||||
|
||||
/**
|
||||
* UUID工具类。
|
||||
* ID工具类。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class UUID
|
||||
public class IDUtil
|
||||
{
|
||||
private UUID()
|
||||
private IDUtil()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成一个UUID字符串。
|
||||
* <p>
|
||||
* 此方法会移除{@linkplain UUID}中的所有'-'字符。
|
||||
* </p>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String gen()
|
||||
public static String uuid()
|
||||
{
|
||||
char[] uuid = java.util.UUID.randomUUID().toString().toCharArray();
|
||||
char[] chars = new char[uuid.length];
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.connection;
|
||||
package org.datagear.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
|
@ -35,72 +35,9 @@ import java.util.zip.ZipOutputStream;
|
|||
*/
|
||||
public class IOUtil
|
||||
{
|
||||
public IOUtil()
|
||||
private IOUtil()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件对象。
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static File getFile(String file)
|
||||
{
|
||||
return new File(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件对象。
|
||||
*
|
||||
* @param directory
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static File getFile(File directory, String file)
|
||||
{
|
||||
return new File(directory, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件。
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
public static void deleteFile(File file)
|
||||
{
|
||||
if (!file.exists())
|
||||
return;
|
||||
|
||||
if (file.isDirectory())
|
||||
{
|
||||
File[] children = file.listFiles();
|
||||
|
||||
for (File child : children)
|
||||
deleteFile(child);
|
||||
}
|
||||
|
||||
file.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空目录,保留目录本身。
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
public static void clearDirectory(File directory)
|
||||
{
|
||||
if (!directory.exists())
|
||||
return;
|
||||
|
||||
if (directory.isDirectory())
|
||||
{
|
||||
File[] children = directory.listFiles();
|
||||
|
||||
for (File child : children)
|
||||
deleteFile(child);
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.connection;
|
||||
package org.datagear.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
@ -10,6 +10,7 @@ import java.sql.Connection;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* JDBC工具支持类。
|
||||
|
@ -19,8 +20,9 @@ import java.sql.Statement;
|
|||
*/
|
||||
public class JdbcUtil
|
||||
{
|
||||
public JdbcUtil()
|
||||
private JdbcUtil()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,6 +177,124 @@ public class JdbcUtil
|
|||
+ targetType.getName() + "] is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定对象的JDBC类型。
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public static int getJdbcType(Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return Types.NULL;
|
||||
else
|
||||
return getJdbcType(obj.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类的JDBC类型。
|
||||
*
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static int getJdbcType(Class<?> clazz)
|
||||
{
|
||||
if (String.class.equals(clazz))
|
||||
{
|
||||
return Types.VARCHAR;
|
||||
}
|
||||
else if (boolean.class.equals(clazz) || Boolean.class.equals(clazz))
|
||||
{
|
||||
return Types.BOOLEAN;
|
||||
}
|
||||
else if (int.class.equals(clazz) || Integer.class.equals(clazz))
|
||||
{
|
||||
return Types.INTEGER;
|
||||
}
|
||||
else if (long.class.equals(clazz) || Long.class.equals(clazz))
|
||||
{
|
||||
return Types.BIGINT;
|
||||
}
|
||||
else if (float.class.equals(clazz) || Float.class.equals(clazz))
|
||||
{
|
||||
return Types.FLOAT;
|
||||
}
|
||||
else if (double.class.equals(clazz) || Double.class.equals(clazz))
|
||||
{
|
||||
return Types.DOUBLE;
|
||||
}
|
||||
else if (java.math.BigDecimal.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.NUMERIC;
|
||||
}
|
||||
else if (java.math.BigInteger.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.NUMERIC;
|
||||
}
|
||||
else if (java.sql.Date.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.DATE;
|
||||
}
|
||||
else if (java.sql.Time.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.TIME;
|
||||
}
|
||||
else if (java.sql.Timestamp.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.TIMESTAMP;
|
||||
}
|
||||
else if (java.util.Date.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.DATE;
|
||||
}
|
||||
else if (byte.class.equals(clazz) || Byte.class.equals(clazz))
|
||||
{
|
||||
return Types.TINYINT;
|
||||
}
|
||||
else if (short.class.equals(clazz) || Short.class.equals(clazz))
|
||||
{
|
||||
return Types.SMALLINT;
|
||||
}
|
||||
else if (char.class.equals(clazz) || Character.class.equals(clazz))
|
||||
{
|
||||
return Types.CHAR;
|
||||
}
|
||||
else if (byte[].class.equals(clazz) || Byte[].class.equals(clazz))
|
||||
{
|
||||
return Types.BINARY;
|
||||
}
|
||||
else if (java.sql.Clob.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.CLOB;
|
||||
}
|
||||
else if (java.sql.Blob.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.BLOB;
|
||||
}
|
||||
else if (java.sql.Array.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.ARRAY;
|
||||
}
|
||||
else if (java.sql.Struct.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.STRUCT;
|
||||
}
|
||||
else if (java.sql.Ref.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.REF;
|
||||
}
|
||||
else if (java.net.URL.class.isAssignableFrom(clazz))
|
||||
{
|
||||
return Types.REF;
|
||||
}
|
||||
else if (Class.class.equals(clazz))
|
||||
{
|
||||
return Types.JAVA_OBJECT;
|
||||
}
|
||||
else
|
||||
throw new UnsupportedOperationException("Unsupported Java type [" + clazz + "] for getting JDBC type");
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭{@linkplain Connection}。
|
||||
* <p>
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2018 datagear.org. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.web.util;
|
||||
package org.datagear.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.org. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.util.expression;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 表达式。
|
||||
* <p>
|
||||
* 此类描述嵌入在字符串中的某个表达式子串。
|
||||
* </p>
|
||||
* <p>
|
||||
* 通常格式为:${...}、#{...}。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class Expression implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 表达式字符串 */
|
||||
private String expression;
|
||||
|
||||
/** 起始标识符 */
|
||||
private String startIdentifier;
|
||||
|
||||
/** 结束标识符 */
|
||||
private String endIdentifier;
|
||||
|
||||
/** 表达式起始位置 */
|
||||
private int startIndex;
|
||||
|
||||
/** 表达式结束位置 */
|
||||
private int endIndex;
|
||||
|
||||
/** 表达式内容 */
|
||||
private String content;
|
||||
|
||||
public Expression()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public Expression(String startIdentifier, String endIdentifier, String expression, int startIndex, int endIndex,
|
||||
String content)
|
||||
{
|
||||
super();
|
||||
this.startIdentifier = startIdentifier;
|
||||
this.endIdentifier = endIdentifier;
|
||||
this.expression = expression;
|
||||
this.startIndex = startIndex;
|
||||
this.endIndex = endIndex;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getStartIdentifier()
|
||||
{
|
||||
return startIdentifier;
|
||||
}
|
||||
|
||||
public void setStartIdentifier(String startIdentifier)
|
||||
{
|
||||
this.startIdentifier = startIdentifier;
|
||||
}
|
||||
|
||||
public String getEndIdentifier()
|
||||
{
|
||||
return endIdentifier;
|
||||
}
|
||||
|
||||
public void setEndIdentifier(String endIdentifier)
|
||||
{
|
||||
this.endIdentifier = endIdentifier;
|
||||
}
|
||||
|
||||
public String getExpression()
|
||||
{
|
||||
return expression;
|
||||
}
|
||||
|
||||
public void setExpression(String expression)
|
||||
{
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
public int getStartIndex()
|
||||
{
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
public void setStartIndex(int startIndex)
|
||||
{
|
||||
this.startIndex = startIndex;
|
||||
}
|
||||
|
||||
public int getEndIndex()
|
||||
{
|
||||
return endIndex;
|
||||
}
|
||||
|
||||
public void setEndIndex(int endIndex)
|
||||
{
|
||||
this.endIndex = endIndex;
|
||||
}
|
||||
|
||||
public String getContent()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content)
|
||||
{
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.expression;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,327 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.util.expression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字符串表达式解析器。
|
||||
* <p>
|
||||
* 它解析字符串中类似<code>"${...}"</code>、<code>"#{...}"</code>格式的表达式子串。
|
||||
* </p>
|
||||
* <p>
|
||||
* 默认地,它使用<code>'\'</code>作为转义字符。
|
||||
* </p>
|
||||
* <p>
|
||||
* 例如:<code>"\${"</code>表示不做表达式解析、表达式里面的<code>"\}"</code>表示<code>"}"</code>普通字符而非表达式结束标识符。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class ExpressionResolver
|
||||
{
|
||||
/** "${"起始标识符 */
|
||||
public static final String DEFAULT_START_IDENTIFIER_DOLLAR = "${";
|
||||
|
||||
/** "#{"起始标识符 */
|
||||
public static final String DEFAULT_START_IDENTIFIER_SHARP = "#{";
|
||||
|
||||
public static final String DEFAULT_END_IDENTIFIER = "}";
|
||||
|
||||
public static final char DEFAULT_ESCAPER = '\\';
|
||||
|
||||
private String startIdentifier = DEFAULT_START_IDENTIFIER_DOLLAR;
|
||||
|
||||
private String endIdentifier = DEFAULT_END_IDENTIFIER;
|
||||
|
||||
private char escaper = DEFAULT_ESCAPER;
|
||||
|
||||
public ExpressionResolver()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public String getStartIdentifier()
|
||||
{
|
||||
return startIdentifier;
|
||||
}
|
||||
|
||||
public void setStartIdentifier(String startIdentifier)
|
||||
{
|
||||
this.startIdentifier = startIdentifier;
|
||||
}
|
||||
|
||||
public String getEndIdentifier()
|
||||
{
|
||||
return endIdentifier;
|
||||
}
|
||||
|
||||
public void setEndIdentifier(String endIdentifier)
|
||||
{
|
||||
this.endIdentifier = endIdentifier;
|
||||
}
|
||||
|
||||
public char getEscaper()
|
||||
{
|
||||
return escaper;
|
||||
}
|
||||
|
||||
public void setEscaper(char escaper)
|
||||
{
|
||||
this.escaper = escaper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串是否是表达式字符串。
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public boolean isExpression(String source)
|
||||
{
|
||||
if (source == null || source.isEmpty())
|
||||
return false;
|
||||
|
||||
return (resolveNextExpression(source, 0) != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析字符串中的{@linkplain Expression}列表。
|
||||
* <p>
|
||||
* 如果不包含表达式,将返回空列表。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public List<Expression> resolve(String source)
|
||||
{
|
||||
if (source == null || source.isEmpty())
|
||||
return Collections.emptyList();
|
||||
|
||||
List<Expression> expressions = null;
|
||||
|
||||
Expression next = null;
|
||||
int startIndex = 0;
|
||||
|
||||
while ((next = resolveNextExpression(source, startIndex)) != null)
|
||||
{
|
||||
if (expressions == null)
|
||||
expressions = new ArrayList<Expression>();
|
||||
|
||||
expressions.add(next);
|
||||
startIndex = next.getEndIndex();
|
||||
}
|
||||
|
||||
if (expressions == null)
|
||||
expressions = Collections.emptyList();
|
||||
|
||||
return expressions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算字符串表达式的值。
|
||||
* <p>
|
||||
* 将字符串中的表达式子串替换为目标值,并返回替换后的新字符串。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @param expressions
|
||||
* @param values
|
||||
* @param nullValue
|
||||
* @return
|
||||
*/
|
||||
public String evaluate(String source, List<? extends Expression> expressions, List<?> values, String nullValue)
|
||||
{
|
||||
if (expressions == null || expressions.isEmpty())
|
||||
return source;
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
int gapStart = 0;
|
||||
|
||||
for (int i = 0; i < expressions.size(); i++)
|
||||
{
|
||||
Expression expression = expressions.get(i);
|
||||
Object value = values.get(i);
|
||||
|
||||
copyForUnescape(source, gapStart, expression.getStartIndex(), result);
|
||||
|
||||
if (value == null)
|
||||
result.append(nullValue);
|
||||
else if (value instanceof String)
|
||||
result.append((String) value);
|
||||
else
|
||||
result.append(value.toString());
|
||||
|
||||
gapStart = expression.getEndIndex();
|
||||
}
|
||||
|
||||
copyForUnescape(source, gapStart, source.length(), result);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将不包含表达式的字符串进行表达式语法反转义。
|
||||
* <p>
|
||||
* 注意:它仅将表达式起始标识符进行反转义。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public String unescape(String source)
|
||||
{
|
||||
if (source == null || source.isEmpty())
|
||||
return source;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
copyForUnescape(source, 0, source.length(), sb);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象进行表达式语法反转义。
|
||||
* <p>
|
||||
* 如果{@code obj}不是字符串,将直接返回它。
|
||||
* </p>
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public Object unescape(Object obj)
|
||||
{
|
||||
if (obj instanceof String)
|
||||
return unescape((String) obj);
|
||||
else
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将源字符串中指定索引区间的字符拷贝到目标字符串缓冲,并进行表达式语法反转义。
|
||||
*
|
||||
* @param source
|
||||
* @param startIndex
|
||||
* @param endIndex
|
||||
* @param sb
|
||||
*/
|
||||
protected void copyForUnescape(String source, int startIndex, int endIndex, StringBuilder sb)
|
||||
{
|
||||
for (int i = startIndex; i < endIndex; i++)
|
||||
{
|
||||
char c = source.charAt(i);
|
||||
|
||||
if (c == this.escaper && matchAtIndex(source, i + 1, this.startIdentifier))
|
||||
;
|
||||
else
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从给定起始位置解析下一个{@linkplain Expression}。
|
||||
* <p>
|
||||
* 如果没有,将返回{@code null}。
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* @param startIndex
|
||||
* @return
|
||||
*/
|
||||
protected Expression resolveNextExpression(String source, int startIndex)
|
||||
{
|
||||
int length = source.length();
|
||||
|
||||
for (int i = startIndex; i < length;)
|
||||
{
|
||||
// 起始标识符转义
|
||||
if (source.charAt(i) == this.escaper && matchAtIndex(source, i + 1, this.startIdentifier))
|
||||
{
|
||||
i += this.startIdentifier.length() + 1;
|
||||
}
|
||||
else if (matchAtIndex(source, i, this.startIdentifier))
|
||||
{
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
int j = i + this.startIdentifier.length();
|
||||
|
||||
while (j < length)
|
||||
{
|
||||
char cj = source.charAt(j);
|
||||
|
||||
// 结束标识符转义
|
||||
if (cj == this.escaper && matchAtIndex(source, j + 1, this.endIdentifier))
|
||||
{
|
||||
content.append(this.endIdentifier);
|
||||
j += this.endIdentifier.length() + 1;
|
||||
}
|
||||
else if (matchAtIndex(source, j, this.endIdentifier))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
content.append(cj);
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (j >= length || content.length() == 0)
|
||||
{
|
||||
i = j + 1;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return newExpressionInstance(this.startIdentifier, this.endIdentifier, source.substring(i, j + 1),
|
||||
i, j + 1, content.toString().trim());
|
||||
}
|
||||
}
|
||||
else
|
||||
i += 1;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串指定位置是否是目标子串。
|
||||
*
|
||||
* @param source
|
||||
* @param startIndex
|
||||
* @param sub
|
||||
* @return
|
||||
*/
|
||||
protected boolean matchAtIndex(String source, int startIndex, String sub)
|
||||
{
|
||||
if (startIndex >= source.length())
|
||||
return false;
|
||||
|
||||
return source.startsWith(sub, startIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建{@linkplain Expression}实例。
|
||||
*
|
||||
* @param startIdentifier
|
||||
* @param endIdentifier
|
||||
* @param expression
|
||||
* @param startIndex
|
||||
* @param endIndex
|
||||
* @param content
|
||||
* @return
|
||||
*/
|
||||
protected Expression newExpressionInstance(String startIdentifier, String endIdentifier, String expression,
|
||||
int startIndex, int endIndex, String content)
|
||||
{
|
||||
return new Expression(startIdentifier, endIdentifier, expression, startIndex, endIndex, content);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2018 datagear.org. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.management.util;
|
||||
package org.datagear.util.version;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.management.util;
|
||||
package org.datagear.util.version;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2018 datagear.org. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.management.util;
|
||||
package org.datagear.util.version;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2018 datagear.org. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.web.util;
|
||||
package org.datagear.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
@ -13,7 +13,7 @@ import java.io.Reader;
|
|||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.web.util.SqlScriptParser.SqlStatement;
|
||||
import org.datagear.util.SqlScriptParser.SqlStatement;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -313,7 +313,7 @@ public class SqlScriptParserTest
|
|||
public void parseTestScriptFile() throws IOException
|
||||
{
|
||||
InputStream inputStream = SqlScriptParserTest.class.getClassLoader()
|
||||
.getResourceAsStream("org/datagear/web/util/SqlScriptParserTest.sql");
|
||||
.getResourceAsStream("org/datagear/util/SqlScriptParserTest.sql");
|
||||
|
||||
Reader reader = new InputStreamReader(inputStream, "UTF-8");
|
||||
|
|
@ -2,12 +2,11 @@
|
|||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.persistence.support;
|
||||
package org.datagear.util.expression;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.persistence.support.ExpressionResolver.Expression;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -29,27 +28,13 @@ public class ExpressionResolverTest
|
|||
Assert.assertTrue(expressionResolver.isExpression("${content}ghi"));
|
||||
Assert.assertTrue(expressionResolver.isExpression("abcdef${content}ghi"));
|
||||
|
||||
Assert.assertTrue(expressionResolver.isExpression("${name:content}"));
|
||||
Assert.assertTrue(expressionResolver.isExpression("abcdef${name:content}"));
|
||||
Assert.assertTrue(expressionResolver.isExpression("${name:content}ghi"));
|
||||
Assert.assertTrue(expressionResolver.isExpression("abcdef${name:content}ghi"));
|
||||
|
||||
Assert.assertFalse(expressionResolver.isExpression("${name:}"));
|
||||
Assert.assertFalse(expressionResolver.isExpression("abcdef${name:}ghi"));
|
||||
|
||||
Assert.assertFalse(expressionResolver.isExpression("${:content}"));
|
||||
Assert.assertFalse(expressionResolver.isExpression("abcdef${:content}ghi"));
|
||||
|
||||
Assert.assertFalse(expressionResolver.isExpression("${name:content"));
|
||||
Assert.assertFalse(expressionResolver.isExpression("abcdef${name:content"));
|
||||
|
||||
Assert.assertFalse(expressionResolver.isExpression("${}"));
|
||||
Assert.assertFalse(expressionResolver.isExpression("abcdef${}"));
|
||||
Assert.assertFalse(expressionResolver.isExpression("${}ghi"));
|
||||
|
||||
Assert.assertFalse(expressionResolver.isExpression("${:}"));
|
||||
Assert.assertFalse(expressionResolver.isExpression("abcdef${:}"));
|
||||
Assert.assertFalse(expressionResolver.isExpression("${:}ghi"));
|
||||
Assert.assertFalse(expressionResolver.isExpression("${}"));
|
||||
Assert.assertFalse(expressionResolver.isExpression("abcdef${}"));
|
||||
Assert.assertFalse(expressionResolver.isExpression("${}ghi"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -64,108 +49,86 @@ public class ExpressionResolverTest
|
|||
|
||||
Expression e = expressions.get(0);
|
||||
Assert.assertEquals("${content}", e.getExpression());
|
||||
Assert.assertEquals(0, e.getStart());
|
||||
Assert.assertEquals("${content}".length(), e.getEnd());
|
||||
Assert.assertFalse(e.hasName());
|
||||
Assert.assertEquals(0, e.getStartIndex());
|
||||
Assert.assertEquals("${content}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<Expression> expressions = expressionResolver.resolve("${name:content}");
|
||||
List<Expression> expressions = expressionResolver.resolve("prefix${content}");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
Expression e = expressions.get(0);
|
||||
Assert.assertEquals("${name:content}", e.getExpression());
|
||||
Assert.assertEquals(0, e.getStart());
|
||||
Assert.assertEquals("${name:content}".length(), e.getEnd());
|
||||
Assert.assertEquals("name", e.getName());
|
||||
Assert.assertEquals("${content}", e.getExpression());
|
||||
Assert.assertEquals(6, e.getStartIndex());
|
||||
Assert.assertEquals(6 + "${content}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<Expression> expressions = expressionResolver.resolve("prefix${name:content}");
|
||||
List<Expression> expressions = expressionResolver.resolve("${content}suffix");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
Expression e = expressions.get(0);
|
||||
Assert.assertEquals("${name:content}", e.getExpression());
|
||||
Assert.assertEquals(6, e.getStart());
|
||||
Assert.assertEquals(6 + "${name:content}".length(), e.getEnd());
|
||||
Assert.assertEquals("name", e.getName());
|
||||
Assert.assertEquals("${content}", e.getExpression());
|
||||
Assert.assertEquals(0, e.getStartIndex());
|
||||
Assert.assertEquals("${content}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<Expression> expressions = expressionResolver.resolve("${name:content}suffix");
|
||||
List<Expression> expressions = expressionResolver.resolve("prefix${content}suffix");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
Expression e = expressions.get(0);
|
||||
Assert.assertEquals("${name:content}", e.getExpression());
|
||||
Assert.assertEquals(0, e.getStart());
|
||||
Assert.assertEquals("${name:content}".length(), e.getEnd());
|
||||
Assert.assertEquals("name", e.getName());
|
||||
Assert.assertEquals("${content}", e.getExpression());
|
||||
Assert.assertEquals(6, e.getStartIndex());
|
||||
Assert.assertEquals(6 + "${content}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<Expression> expressions = expressionResolver.resolve("prefix${name:content}suffix");
|
||||
List<Expression> expressions = expressionResolver.resolve("${ content }");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
Expression e = expressions.get(0);
|
||||
Assert.assertEquals("${name:content}", e.getExpression());
|
||||
Assert.assertEquals(6, e.getStart());
|
||||
Assert.assertEquals(6 + "${name:content}".length(), e.getEnd());
|
||||
Assert.assertEquals("name", e.getName());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<Expression> expressions = expressionResolver.resolve("${ name : content }");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
Expression e = expressions.get(0);
|
||||
Assert.assertEquals("${ name : content }", e.getExpression());
|
||||
Assert.assertEquals(0, e.getStart());
|
||||
Assert.assertEquals("${ name : content }".length(), e.getEnd());
|
||||
Assert.assertEquals("name", e.getName());
|
||||
Assert.assertEquals("${ content }", e.getExpression());
|
||||
Assert.assertEquals(0, e.getStartIndex());
|
||||
Assert.assertEquals("${ content }".length(), e.getEndIndex());
|
||||
Assert.assertEquals("content", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
List<Expression> expressions = expressionResolver
|
||||
.resolve("prefix${content0}gap${name1 : content1}gap${ name2: content2 }sufix");
|
||||
.resolve("prefix${content0}gap${content1}gap${ content2 }sufix");
|
||||
|
||||
Assert.assertEquals(3, expressions.size());
|
||||
|
||||
{
|
||||
Expression e = expressions.get(0);
|
||||
Assert.assertEquals("${content0}", e.getExpression());
|
||||
Assert.assertEquals(6, e.getStart());
|
||||
Assert.assertEquals(6 + "${content0}".length(), e.getEnd());
|
||||
Assert.assertFalse(e.hasName());
|
||||
Assert.assertEquals(6, e.getStartIndex());
|
||||
Assert.assertEquals(6 + "${content0}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("content0", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
Expression e = expressions.get(1);
|
||||
Assert.assertEquals("${name1 : content1}", e.getExpression());
|
||||
Assert.assertEquals("prefix${content0}gap".length(), e.getStart());
|
||||
Assert.assertEquals("prefix${content0}gap${name1 : content1}".length(), e.getEnd());
|
||||
Assert.assertEquals("name1", e.getName());
|
||||
Assert.assertEquals("${content1}", e.getExpression());
|
||||
Assert.assertEquals("prefix${content0}gap".length(), e.getStartIndex());
|
||||
Assert.assertEquals("prefix${content0}gap${content1}".length(), e.getEndIndex());
|
||||
Assert.assertEquals("content1", e.getContent());
|
||||
}
|
||||
|
||||
{
|
||||
Expression e = expressions.get(2);
|
||||
Assert.assertEquals("${ name2: content2 }", e.getExpression());
|
||||
Assert.assertEquals("prefix${content0}gap${name1 : content1}gap".length(), e.getStart());
|
||||
Assert.assertEquals("prefix${content0}gap${name1 : content1}gap${ name2: content2 }".length(),
|
||||
e.getEnd());
|
||||
Assert.assertEquals("name2", e.getName());
|
||||
Assert.assertEquals("${ content2 }", e.getExpression());
|
||||
Assert.assertEquals("prefix${content0}gap${content1}gap".length(), e.getStartIndex());
|
||||
Assert.assertEquals("prefix${content0}gap${content1}gap${ content2 }".length(), e.getEndIndex());
|
||||
Assert.assertEquals("content2", e.getContent());
|
||||
}
|
||||
}
|
||||
|
@ -177,12 +140,12 @@ public class ExpressionResolverTest
|
|||
}
|
||||
|
||||
{
|
||||
List<Expression> expressions = expressionResolver.resolve("prefix${cont\\:ent\\}0}");
|
||||
List<Expression> expressions = expressionResolver.resolve("prefix${content\\}0}");
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
Expression e = expressions.get(0);
|
||||
Assert.assertEquals("cont:ent}0", e.getContent());
|
||||
Assert.assertEquals("content}0", e.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,17 +164,7 @@ public class ExpressionResolverTest
|
|||
}
|
||||
|
||||
{
|
||||
String source = "${name:content}";
|
||||
List<Expression> expressions = expressionResolver.resolve(source);
|
||||
|
||||
List<?> values = Arrays.asList("a");
|
||||
|
||||
Assert.assertEquals("a", expressionResolver.evaluate(source, expressions, values, ""));
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
String source = "prefix${name:content}";
|
||||
String source = "prefix${content}";
|
||||
List<Expression> expressions = expressionResolver.resolve(source);
|
||||
|
||||
List<?> values = Arrays.asList("a");
|
||||
|
@ -220,7 +173,7 @@ public class ExpressionResolverTest
|
|||
}
|
||||
|
||||
{
|
||||
String source = "${name:content}suffix";
|
||||
String source = "${content}suffix";
|
||||
List<Expression> expressions = expressionResolver.resolve(source);
|
||||
|
||||
List<?> values = Arrays.asList("a");
|
||||
|
@ -229,7 +182,7 @@ public class ExpressionResolverTest
|
|||
}
|
||||
|
||||
{
|
||||
String source = "prefix${name:content}suffix";
|
||||
String source = "prefix${content}suffix";
|
||||
List<Expression> expressions = expressionResolver.resolve(source);
|
||||
|
||||
List<?> values = Arrays.asList("a");
|
||||
|
@ -238,7 +191,7 @@ public class ExpressionResolverTest
|
|||
}
|
||||
|
||||
{
|
||||
String source = "${ name : content }";
|
||||
String source = "${ content }";
|
||||
List<Expression> expressions = expressionResolver.resolve(source);
|
||||
|
||||
List<?> values = Arrays.asList("a");
|
||||
|
@ -247,7 +200,7 @@ public class ExpressionResolverTest
|
|||
}
|
||||
|
||||
{
|
||||
String source = "prefix${content0}gap${name1 : content1}gap${ name2: content2 }sufix";
|
||||
String source = "prefix${content0}gap${content1}gap${ content2 }sufix";
|
||||
List<Expression> expressions = expressionResolver.resolve(source);
|
||||
|
||||
List<?> values = Arrays.asList("a", "b", "c");
|
||||
|
@ -256,7 +209,7 @@ public class ExpressionResolverTest
|
|||
}
|
||||
|
||||
{
|
||||
String source = "pr\\e\\${fix${name:content}suffix";
|
||||
String source = "pr\\e\\${fix${content}suffix";
|
||||
List<Expression> expressions = expressionResolver.resolve(source);
|
||||
|
||||
List<?> values = Arrays.asList("a");
|
||||
|
@ -277,9 +230,9 @@ public class ExpressionResolverTest
|
|||
}
|
||||
|
||||
{
|
||||
String e = expressionResolver.unescape("prefix${cont\\:ent\\}0}");
|
||||
String e = expressionResolver.unescape("prefix${cont\\ent\\}0}");
|
||||
|
||||
Assert.assertEquals("prefix${cont:ent}0}", e);
|
||||
Assert.assertEquals("prefix${cont\\ent\\}0}", e);
|
||||
}
|
||||
|
||||
{
|
|
@ -44,6 +44,11 @@
|
|||
<artifactId>datagear-dataexchange</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.datagear</groupId>
|
||||
<artifactId>datagear-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
|
|
|
@ -12,10 +12,10 @@ import java.io.Writer;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.cometd.bayeux.server.ServerChannel;
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.dataexchange.DataExchangeException;
|
||||
import org.datagear.dataexchange.DataExchangeListener;
|
||||
import org.datagear.dataexchange.ExceptionResolve;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.web.cometd.dataexchange.CometdBatchDataExchangeListener.SubSubmitSuccess;
|
||||
import org.springframework.context.MessageSource;
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ import org.datagear.connection.ConnectionOption;
|
|||
import org.datagear.connection.ConnectionSource;
|
||||
import org.datagear.connection.ConnectionSourceException;
|
||||
import org.datagear.connection.DriverEntity;
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.management.domain.Schema;
|
||||
import org.datagear.management.service.SchemaService;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.datagear.web.convert.ClassDataConverter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
|
|
|
@ -22,7 +22,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.datagear.connection.ConnectionSource;
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.dbmodel.CachedDbModelFactory;
|
||||
import org.datagear.dbmodel.ModelSqlSelectService;
|
||||
import org.datagear.management.domain.Schema;
|
||||
|
@ -45,6 +44,9 @@ import org.datagear.persistence.support.PMU;
|
|||
import org.datagear.persistence.support.SelectOptions;
|
||||
import org.datagear.persistence.support.SqlExpressionSyntaxErrorException;
|
||||
import org.datagear.persistence.support.VariableExpressionSyntaxErrorException;
|
||||
import org.datagear.util.FileInfo;
|
||||
import org.datagear.util.FileUtil;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.datagear.web.convert.ClassDataConverter;
|
||||
import org.datagear.web.convert.ConverterException;
|
||||
|
@ -54,10 +56,8 @@ import org.datagear.web.format.SqlDateFormatter;
|
|||
import org.datagear.web.format.SqlTimeFormatter;
|
||||
import org.datagear.web.format.SqlTimestampFormatter;
|
||||
import org.datagear.web.freemarker.WriteJsonTemplateDirectiveModel;
|
||||
import org.datagear.web.util.FileUtils;
|
||||
import org.datagear.web.util.ModelUtils;
|
||||
import org.datagear.web.util.WebUtils;
|
||||
import org.datagear.web.vo.FileInfo;
|
||||
import org.datagear.web.vo.PropertyPathDisplayName;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
@ -1750,7 +1750,7 @@ public class DataController extends AbstractSchemaModelConnController
|
|||
public FileInfo fileUpload(HttpServletRequest request, @RequestParam("file") MultipartFile multipartFile)
|
||||
throws Throwable
|
||||
{
|
||||
File file = FileUtils.generateUniqueFile(this.blobFileManagerDirectory);
|
||||
File file = FileUtil.generateUniqueFile(this.blobFileManagerDirectory);
|
||||
|
||||
multipartFile.transferTo(file);
|
||||
|
||||
|
@ -1772,7 +1772,7 @@ public class DataController extends AbstractSchemaModelConnController
|
|||
{
|
||||
out = response.getOutputStream();
|
||||
|
||||
File file = IOUtil.getFile(this.blobFileManagerDirectory, fileName);
|
||||
File file = FileUtil.getFile(this.blobFileManagerDirectory, fileName);
|
||||
IOUtil.write(file, out);
|
||||
}
|
||||
finally
|
||||
|
@ -1786,11 +1786,11 @@ public class DataController extends AbstractSchemaModelConnController
|
|||
public FileInfo fileDelete(HttpServletRequest request, HttpServletResponse response,
|
||||
@RequestParam("file") String fileName) throws Throwable
|
||||
{
|
||||
File file = IOUtil.getFile(this.blobFileManagerDirectory, fileName);
|
||||
File file = FileUtil.getFile(this.blobFileManagerDirectory, fileName);
|
||||
|
||||
FileInfo fileInfo = FileUtils.getFileInfo(file);
|
||||
FileInfo fileInfo = FileUtil.getFileInfo(file);
|
||||
|
||||
IOUtil.deleteFile(file);
|
||||
FileUtil.deleteFile(file);
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import javax.servlet.http.HttpSession;
|
|||
|
||||
import org.cometd.bayeux.server.ServerChannel;
|
||||
import org.datagear.connection.ConnectionSource;
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.dataexchange.BatchDataExchange;
|
||||
import org.datagear.dataexchange.BatchDataExchangeContext;
|
||||
import org.datagear.dataexchange.ConnectionFactory;
|
||||
|
@ -61,14 +60,16 @@ import org.datagear.dbinfo.TableInfo;
|
|||
import org.datagear.dbinfo.TableType;
|
||||
import org.datagear.management.domain.Schema;
|
||||
import org.datagear.management.service.SchemaService;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.util.FileInfo;
|
||||
import org.datagear.util.FileUtil;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.datagear.web.cometd.dataexchange.CometdBatchDataExchangeListener;
|
||||
import org.datagear.web.cometd.dataexchange.CometdSubTextDataExportListener;
|
||||
import org.datagear.web.cometd.dataexchange.CometdSubTextDataImportListener;
|
||||
import org.datagear.web.cometd.dataexchange.DataExchangeCometdService;
|
||||
import org.datagear.web.convert.ClassDataConverter;
|
||||
import org.datagear.web.vo.FileInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.MessageSource;
|
||||
|
@ -197,7 +198,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
|
||||
DataFormat defaultDataFormat = new DataFormat();
|
||||
|
||||
String dataExchangeId = UUID.gen();
|
||||
String dataExchangeId = IDUtil.uuid();
|
||||
|
||||
springModel.addAttribute("defaultDataFormat", defaultDataFormat);
|
||||
springModel.addAttribute("dataExchangeId", dataExchangeId);
|
||||
|
@ -221,7 +222,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
}
|
||||
}.execute();
|
||||
|
||||
springModel.addAttribute("dataExchangeId", UUID.gen());
|
||||
springModel.addAttribute("dataExchangeId", IDUtil.uuid());
|
||||
|
||||
return "/dataexchange/import_db";
|
||||
}
|
||||
|
@ -238,12 +239,12 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
|
||||
String rawFileName = multipartFile.getOriginalFilename();
|
||||
boolean isZipFile = isZipFile(rawFileName);
|
||||
String serverFileName = UUID.gen();
|
||||
String serverFileName = IDUtil.uuid();
|
||||
|
||||
if (isZipFile)
|
||||
{
|
||||
File unzipDirectory = new File(directory, serverFileName);
|
||||
IOUtil.deleteFile(unzipDirectory);
|
||||
File unzipDirectory = FileUtil.getFile(directory, serverFileName);
|
||||
FileUtil.deleteFile(unzipDirectory);
|
||||
unzipDirectory.mkdirs();
|
||||
|
||||
ZipInputStream in = null;
|
||||
|
@ -263,7 +264,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
}
|
||||
else
|
||||
{
|
||||
File importFile = IOUtil.getFile(directory, serverFileName);
|
||||
File importFile = FileUtil.getFile(directory, serverFileName);
|
||||
|
||||
InputStream in = null;
|
||||
OutputStream importFileOut = null;
|
||||
|
@ -279,7 +280,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
IOUtil.close(importFileOut);
|
||||
}
|
||||
|
||||
DataImportFileInfo fileInfo = new DataImportFileInfo(UUID.gen(), serverFileName, importFile.length(),
|
||||
DataImportFileInfo fileInfo = new DataImportFileInfo(IDUtil.uuid(), serverFileName, importFile.length(),
|
||||
rawFileName, DataImportFileInfo.fileNameToTableName(rawFileName));
|
||||
|
||||
fileInfos.add(fileInfo);
|
||||
|
@ -322,7 +323,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
|
||||
for (int i = 0; i < subDataExchangeIds.length; i++)
|
||||
{
|
||||
File file = new File(directory, fileNames[i]);
|
||||
File file = FileUtil.getFile(directory, fileNames[i]);
|
||||
ResourceFactory<Reader> readerFactory = FileReaderResourceFactory.valueOf(file,
|
||||
dataImportForm.getFileEncoding());
|
||||
|
||||
|
@ -457,7 +458,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
|
||||
DataFormat defaultDataFormat = new DataFormat();
|
||||
|
||||
String dataExchangeId = UUID.gen();
|
||||
String dataExchangeId = IDUtil.uuid();
|
||||
|
||||
springModel.addAttribute("defaultDataFormat", defaultDataFormat);
|
||||
springModel.addAttribute("dataExchangeId", dataExchangeId);
|
||||
|
@ -502,7 +503,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
{
|
||||
Query query = toQuery(queries[i]);
|
||||
|
||||
File file = new File(directory, fileNames[i]);
|
||||
File file = FileUtil.getFile(directory, fileNames[i]);
|
||||
ResourceFactory<Writer> writerFactory = FileWriterResourceFactory.valueOf(file,
|
||||
exportForm.getFileEncoding());
|
||||
|
||||
|
@ -552,7 +553,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
|
||||
DataFormat defaultDataFormat = new DataFormat();
|
||||
|
||||
String dataExchangeId = UUID.gen();
|
||||
String dataExchangeId = IDUtil.uuid();
|
||||
|
||||
springModel.addAttribute("defaultDataFormat", defaultDataFormat);
|
||||
springModel.addAttribute("dataExchangeId", dataExchangeId);
|
||||
|
@ -600,7 +601,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
{
|
||||
Query query = toQuery(queries[i]);
|
||||
|
||||
File file = new File(directory, fileNames[i]);
|
||||
File file = FileUtil.getFile(directory, fileNames[i]);
|
||||
ResourceFactory<Writer> writerFactory = FileWriterResourceFactory.valueOf(file,
|
||||
exportForm.getFileEncoding());
|
||||
|
||||
|
@ -646,7 +647,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
"attachment; filename=" + new String(fileName.getBytes(RESPONSE_ENCODING), "iso-8859-1") + "");
|
||||
|
||||
File directory = getTempDataExchangeDirectory(dataExchangeId, true);
|
||||
File file = new File(directory, fileName);
|
||||
File file = FileUtil.getFile(directory, fileName);
|
||||
|
||||
OutputStream out = null;
|
||||
|
||||
|
@ -886,8 +887,8 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
listDataImportFileInfos(file, fileFilter, myPath, myDisplayPath, dataImportFileInfos);
|
||||
else
|
||||
{
|
||||
DataImportFileInfo fileInfo = new DataImportFileInfo(UUID.gen(), myPath, file.length(), myDisplayPath,
|
||||
DataImportFileInfo.fileNameToTableName(file.getName()));
|
||||
DataImportFileInfo fileInfo = new DataImportFileInfo(IDUtil.uuid(), myPath, file.length(),
|
||||
myDisplayPath, DataImportFileInfo.fileNameToTableName(file.getName()));
|
||||
|
||||
dataImportFileInfos.add(fileInfo);
|
||||
}
|
||||
|
@ -904,7 +905,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
|
||||
protected File getTempDataExchangeDirectory(String dataExchangeId, boolean notNull)
|
||||
{
|
||||
File directory = new File(this.tempDataExchangeRootDirectory, dataExchangeId);
|
||||
File directory = FileUtil.getFile(this.tempDataExchangeRootDirectory, dataExchangeId);
|
||||
|
||||
if (notNull && !directory.exists())
|
||||
directory.mkdirs();
|
||||
|
@ -914,7 +915,7 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
|
||||
protected File getTempDataExchangeLogDirectory(String dataExchangeId, boolean notNull)
|
||||
{
|
||||
File directory = new File(this.tempDataExchangeRootDirectory, dataExchangeId + "_logs");
|
||||
File directory = FileUtil.getFile(this.tempDataExchangeRootDirectory, dataExchangeId + "_logs");
|
||||
|
||||
if (notNull && !directory.exists())
|
||||
directory.mkdirs();
|
||||
|
@ -924,13 +925,13 @@ public class DataExchangeController extends AbstractSchemaConnController
|
|||
|
||||
protected File getTempSubDataExchangeLogFile(File logDirectory, String subDataExchangeId)
|
||||
{
|
||||
File logFile = new File(logDirectory, "log_" + subDataExchangeId + ".txt");
|
||||
File logFile = FileUtil.getFile(logDirectory, "log_" + subDataExchangeId + ".txt");
|
||||
return logFile;
|
||||
}
|
||||
|
||||
protected File getExportFileZip(String dataExchangeId)
|
||||
{
|
||||
File file = new File(this.tempDataExchangeRootDirectory, dataExchangeId + ".zip");
|
||||
File file = FileUtil.getFile(this.tempDataExchangeRootDirectory, dataExchangeId + ".zip");
|
||||
return file;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,16 +18,16 @@ import org.datagear.connection.DriverEntity;
|
|||
import org.datagear.connection.DriverEntityManager;
|
||||
import org.datagear.connection.DriverEntityManagerException;
|
||||
import org.datagear.connection.DriverLibraryInfo;
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.connection.XmlDriverEntityManager;
|
||||
import org.datagear.dbinfo.TableInfo;
|
||||
import org.datagear.persistence.PagingQuery;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.util.FileInfo;
|
||||
import org.datagear.util.FileUtil;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.datagear.web.convert.ClassDataConverter;
|
||||
import org.datagear.web.util.FileUtils;
|
||||
import org.datagear.web.util.KeywordMatcher;
|
||||
import org.datagear.web.vo.FileInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.MessageSource;
|
||||
|
@ -109,7 +109,7 @@ public class DriverEntityController extends AbstractController
|
|||
public String add(HttpServletRequest request, HttpServletResponse response, org.springframework.ui.Model model)
|
||||
{
|
||||
DriverEntity driverEntity = new DriverEntity();
|
||||
driverEntity.setId(UUID.gen());
|
||||
driverEntity.setId(IDUtil.uuid());
|
||||
|
||||
model.addAttribute("driverEntity", driverEntity);
|
||||
model.addAttribute(KEY_TITLE_MESSAGE_KEY, "driverEntity.addDriverEntity");
|
||||
|
@ -161,7 +161,7 @@ public class DriverEntityController extends AbstractController
|
|||
public String importDriverEntity(HttpServletRequest request, HttpServletResponse response,
|
||||
org.springframework.ui.Model model)
|
||||
{
|
||||
model.addAttribute("importId", UUID.gen());
|
||||
model.addAttribute("importId", IDUtil.uuid());
|
||||
|
||||
return "/driverEntity/driverEntity_import";
|
||||
}
|
||||
|
@ -174,9 +174,9 @@ public class DriverEntityController extends AbstractController
|
|||
{
|
||||
File directory = getTempImportDirectory(importId, true);
|
||||
|
||||
IOUtil.clearDirectory(directory);
|
||||
FileUtil.clearDirectory(directory);
|
||||
|
||||
File importFile = IOUtil.getFile(directory, TEMP_IMPORT_FILE_NAME);
|
||||
File importFile = FileUtil.getFile(directory, TEMP_IMPORT_FILE_NAME);
|
||||
|
||||
InputStream in = null;
|
||||
OutputStream importFileOut = null;
|
||||
|
@ -220,7 +220,7 @@ public class DriverEntityController extends AbstractController
|
|||
throws Exception
|
||||
{
|
||||
File directory = getTempImportDirectory(importId, false);
|
||||
File importFile = IOUtil.getFile(directory, TEMP_IMPORT_FILE_NAME);
|
||||
File importFile = FileUtil.getFile(directory, TEMP_IMPORT_FILE_NAME);
|
||||
|
||||
if (!importFile.exists())
|
||||
throw new IllegalInputException("import file for [" + importId + "] not exists");
|
||||
|
@ -362,7 +362,7 @@ public class DriverEntityController extends AbstractController
|
|||
|
||||
multipartFile.transferTo(tempFile);
|
||||
|
||||
fileInfos = FileUtils.getFileInfos(directory);
|
||||
fileInfos = FileUtil.getFileInfos(directory);
|
||||
}
|
||||
|
||||
return fileInfos;
|
||||
|
@ -414,9 +414,9 @@ public class DriverEntityController extends AbstractController
|
|||
File directory = getTempDriverLibraryDirectoryNotNull(id);
|
||||
File tempFile = getTempDriverLibraryFile(directory, fileName);
|
||||
|
||||
IOUtil.deleteFile(tempFile);
|
||||
FileUtil.deleteFile(tempFile);
|
||||
|
||||
fileInfos = FileUtils.getFileInfos(directory);
|
||||
fileInfos = FileUtil.getFileInfos(directory);
|
||||
}
|
||||
|
||||
ResponseEntity<OperationMessage> responseEntity = buildOperationMessageDeleteSuccessResponseEntity(request);
|
||||
|
@ -442,7 +442,7 @@ public class DriverEntityController extends AbstractController
|
|||
else
|
||||
{
|
||||
File directory = getTempDriverLibraryDirectoryNotNull(id);
|
||||
fileInfos = FileUtils.getFileInfos(directory);
|
||||
fileInfos = FileUtil.getFileInfos(directory);
|
||||
}
|
||||
|
||||
return fileInfos;
|
||||
|
|
|
@ -11,8 +11,8 @@ import java.util.List;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.datagear.management.util.Version;
|
||||
import org.datagear.management.util.VersionContent;
|
||||
import org.datagear.util.version.Version;
|
||||
import org.datagear.util.version.VersionContent;
|
||||
import org.datagear.web.util.ChangelogResolver;
|
||||
import org.datagear.web.util.WebUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
|
@ -11,7 +11,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import org.datagear.management.domain.User;
|
||||
import org.datagear.management.service.UserService;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.datagear.web.convert.ClassDataConverter;
|
||||
import org.datagear.web.util.WebUtils;
|
||||
|
@ -105,7 +105,7 @@ public class RegisterController extends AbstractController
|
|||
|| !confirmPassword.equals(user.getPassword()))
|
||||
throw new IllegalInputException();
|
||||
|
||||
user.setId(UUID.gen());
|
||||
user.setId(IDUtil.uuid());
|
||||
user.setAdmin(false);
|
||||
user.setAnonymous(false);
|
||||
user.setCreateTime(new Date());
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.datagear.management.domain.User;
|
|||
import org.datagear.management.service.GlobalSettingService;
|
||||
import org.datagear.management.service.ResetPasswordRequestService;
|
||||
import org.datagear.management.service.UserService;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.datagear.web.ResetPasswordRequestConfig;
|
||||
import org.datagear.web.format.SqlTimestampFormatter;
|
||||
|
@ -336,7 +336,7 @@ public class ResetPasswordController extends AbstractController
|
|||
Date currentTime = new Date();
|
||||
SqlTimestampFormatter dateFormatter = new SqlTimestampFormatter();
|
||||
|
||||
ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest(UUID.gen(), user, password,
|
||||
ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest(IDUtil.uuid(), user, password,
|
||||
currentTime, request.getRemoteHost());
|
||||
|
||||
resetPasswordRequest = this.resetPasswordRequestService.addIfNone(resetPasswordRequest);
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.datagear.persistence.Order;
|
|||
import org.datagear.persistence.PagingData;
|
||||
import org.datagear.persistence.PagingQuery;
|
||||
import org.datagear.persistence.Query;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.datagear.web.convert.ClassDataConverter;
|
||||
import org.datagear.web.util.KeywordMatcher;
|
||||
|
@ -114,7 +114,7 @@ public class SchemaController extends AbstractSchemaModelConnController
|
|||
if (isBlank(schema.getTitle()) || isBlank(schema.getUrl()))
|
||||
throw new IllegalInputException();
|
||||
|
||||
schema.setId(UUID.gen());
|
||||
schema.setId(IDUtil.uuid());
|
||||
schema.setCreateTime(new Date());
|
||||
schema.setCreateUser(WebUtils.getUser(request, response));
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ import javax.servlet.ServletContext;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.util.FileUtil;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -85,7 +86,7 @@ public class SchemaUrlBuilderController extends AbstractController implements Se
|
|||
@Value("${schemaUrlBuilderScriptFile}")
|
||||
public void setSchemaUrlBuilderScriptFileString(String schemaUrlBuilderScriptFile)
|
||||
{
|
||||
this.schemaUrlBuilderScriptFile = IOUtil.getFile(schemaUrlBuilderScriptFile);
|
||||
this.schemaUrlBuilderScriptFile = FileUtil.getFile(schemaUrlBuilderScriptFile);
|
||||
}
|
||||
|
||||
@RequestMapping("/editScriptCode")
|
||||
|
|
|
@ -18,7 +18,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.datagear.connection.ConnectionSource;
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.dbinfo.ColumnInfo;
|
||||
import org.datagear.dbinfo.DatabaseInfoResolver;
|
||||
import org.datagear.dbinfo.TableInfo;
|
||||
|
@ -27,7 +26,10 @@ import org.datagear.dbmodel.ModelSqlSelectService;
|
|||
import org.datagear.dbmodel.ModelSqlSelectService.ModelSqlResult;
|
||||
import org.datagear.management.domain.Schema;
|
||||
import org.datagear.management.service.SchemaService;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.util.SqlScriptParser;
|
||||
import org.datagear.util.SqlScriptParser.SqlStatement;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.datagear.web.convert.ClassDataConverter;
|
||||
import org.datagear.web.sqlpad.SqlpadExecutionService;
|
||||
|
@ -35,8 +37,6 @@ import org.datagear.web.sqlpad.SqlpadExecutionService.CommitMode;
|
|||
import org.datagear.web.sqlpad.SqlpadExecutionService.ExceptionHandleMode;
|
||||
import org.datagear.web.sqlpad.SqlpadExecutionService.SqlCommand;
|
||||
import org.datagear.web.util.KeywordMatcher;
|
||||
import org.datagear.web.util.SqlScriptParser;
|
||||
import org.datagear.web.util.SqlScriptParser.SqlStatement;
|
||||
import org.datagear.web.util.WebUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
|
@ -376,6 +376,6 @@ public class SqlpadController extends AbstractSchemaConnController
|
|||
|
||||
protected String generateSqlpadId(HttpServletRequest request, HttpServletResponse response)
|
||||
{
|
||||
return UUID.gen();
|
||||
return IDUtil.uuid();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.datagear.management.domain.User;
|
|||
import org.datagear.management.service.SchemaService;
|
||||
import org.datagear.management.service.UserService;
|
||||
import org.datagear.persistence.PagingQuery;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.datagear.web.convert.ClassDataConverter;
|
||||
import org.datagear.web.util.WebUtils;
|
||||
|
@ -104,7 +104,7 @@ public class UserController extends AbstractController
|
|||
return buildOperationMessageFailResponseEntity(request, HttpStatus.BAD_REQUEST,
|
||||
buildMessageCode("userNameExists"), user.getName());
|
||||
|
||||
user.setId(UUID.gen());
|
||||
user.setId(IDUtil.uuid());
|
||||
|
||||
// 禁用新建管理员账号功能
|
||||
user.setAdmin(User.isAdminUser(user));
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.util.concurrent.LinkedBlockingDeque;
|
|||
import org.datagear.model.support.DefaultDynamicBean;
|
||||
import org.datagear.model.support.DynamicBean;
|
||||
import org.datagear.model.support.PropertyPath;
|
||||
import org.datagear.persistence.support.ExpressionResolver;
|
||||
import org.datagear.persistence.support.NameExpressionResolver;
|
||||
import org.datagear.persistence.support.SqlExpressionResolver;
|
||||
import org.datagear.persistence.support.VariableExpressionResolver;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
|
@ -69,9 +69,9 @@ public abstract class AbstractDataConverter
|
|||
|
||||
private ConversionService conversionService;
|
||||
|
||||
private ExpressionResolver variableExpressionResolver = new VariableExpressionResolver();
|
||||
private NameExpressionResolver variableExpressionResolver = new VariableExpressionResolver();
|
||||
|
||||
private ExpressionResolver sqlExpressionResolver = new SqlExpressionResolver();
|
||||
private NameExpressionResolver sqlExpressionResolver = new SqlExpressionResolver();
|
||||
|
||||
private Map<Class<?>, Class<?>> instanceTypeMap = new HashMap<Class<?>, Class<?>>();
|
||||
|
||||
|
@ -98,22 +98,22 @@ public abstract class AbstractDataConverter
|
|||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
public ExpressionResolver getVariableExpressionResolver()
|
||||
public NameExpressionResolver getVariableExpressionResolver()
|
||||
{
|
||||
return variableExpressionResolver;
|
||||
}
|
||||
|
||||
public void setVariableExpressionResolver(ExpressionResolver variableExpressionResolver)
|
||||
public void setVariableExpressionResolver(NameExpressionResolver variableExpressionResolver)
|
||||
{
|
||||
this.variableExpressionResolver = variableExpressionResolver;
|
||||
}
|
||||
|
||||
public ExpressionResolver getSqlExpressionResolver()
|
||||
public NameExpressionResolver getSqlExpressionResolver()
|
||||
{
|
||||
return sqlExpressionResolver;
|
||||
}
|
||||
|
||||
public void setSqlExpressionResolver(ExpressionResolver sqlExpressionResolver)
|
||||
public void setSqlExpressionResolver(NameExpressionResolver sqlExpressionResolver)
|
||||
{
|
||||
this.sqlExpressionResolver = sqlExpressionResolver;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ package org.datagear.web.scheduling;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.util.FileUtil;
|
||||
|
||||
/**
|
||||
* 删除过期文件任务。
|
||||
|
@ -137,7 +137,7 @@ public class DeleteExpiredFileJob
|
|||
}
|
||||
|
||||
if (delete)
|
||||
IOUtil.deleteFile(file);
|
||||
FileUtil.deleteFile(file);
|
||||
|
||||
return delete;
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ import org.cometd.bayeux.server.BayeuxServer;
|
|||
import org.cometd.bayeux.server.ServerChannel;
|
||||
import org.cometd.server.AbstractService;
|
||||
import org.datagear.dbmodel.ModelSqlSelectService.ModelSqlResult;
|
||||
import org.datagear.util.SqlScriptParser.SqlStatement;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.datagear.web.sqlpad.SqlpadExecutionService.SQLExecutionStat;
|
||||
import org.datagear.web.sqlpad.SqlpadExecutionService.SqlCommand;
|
||||
import org.datagear.web.sqlpad.SqlpadExecutionService.SqlResultType;
|
||||
import org.datagear.web.util.SqlScriptParser.SqlStatement;
|
||||
|
||||
/**
|
||||
* SQL工作台cometd服务。
|
||||
|
|
|
@ -21,14 +21,14 @@ import org.datagear.connection.ConnectionOption;
|
|||
import org.datagear.connection.ConnectionSource;
|
||||
import org.datagear.connection.ConnectionSourceException;
|
||||
import org.datagear.connection.DriverEntity;
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.dbmodel.DatabaseModelResolver;
|
||||
import org.datagear.dbmodel.ModelSqlSelectService;
|
||||
import org.datagear.dbmodel.ModelSqlSelectService.ModelSqlResult;
|
||||
import org.datagear.management.domain.Schema;
|
||||
import org.datagear.model.Model;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.web.util.SqlScriptParser.SqlStatement;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.datagear.util.SqlScriptParser.SqlStatement;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.NoSuchMessageException;
|
||||
|
||||
|
@ -676,7 +676,7 @@ public class SqlpadExecutionService
|
|||
{
|
||||
ResultSet rs = st.getResultSet();
|
||||
|
||||
Model model = SqlpadExecutionService.this.databaseModelResolver.resolve(cn, rs, UUID.gen());
|
||||
Model model = SqlpadExecutionService.this.databaseModelResolver.resolve(cn, rs, IDUtil.uuid());
|
||||
|
||||
ModelSqlResult modelSqlResult = SqlpadExecutionService.this.modelSqlSelectService.select(cn,
|
||||
sqlStatement.getSql(), rs, model, 1, this.resultsetFetchSize);
|
||||
|
|
|
@ -12,10 +12,10 @@ import java.util.List;
|
|||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.management.util.AbstractVersionContentReader;
|
||||
import org.datagear.management.util.Version;
|
||||
import org.datagear.management.util.VersionContent;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.util.version.AbstractVersionContentReader;
|
||||
import org.datagear.util.version.Version;
|
||||
import org.datagear.util.version.VersionContent;
|
||||
import org.springframework.web.context.ServletContextAware;
|
||||
import org.springframework.web.context.support.ServletContextResource;
|
||||
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.web.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.web.vo.FileInfo;
|
||||
|
||||
/**
|
||||
* 文件工具类。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class FileUtils
|
||||
{
|
||||
/**
|
||||
* 生成目录下唯一文件。
|
||||
*
|
||||
* @param directory
|
||||
* @return
|
||||
*/
|
||||
public static File generateUniqueFile(File directory)
|
||||
{
|
||||
return new File(directory, UUID.gen());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成目录下唯一子目录。
|
||||
*
|
||||
* @param directory
|
||||
* @return
|
||||
*/
|
||||
public static File generateUniqueDirectory(File directory)
|
||||
{
|
||||
File file = new File(directory, UUID.gen());
|
||||
|
||||
if (!file.exists())
|
||||
file.mkdirs();
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出指定目录下的文件名称。
|
||||
*
|
||||
* @param directory
|
||||
* @return
|
||||
*/
|
||||
public static String[] listFileNames(File directory)
|
||||
{
|
||||
if (!directory.exists())
|
||||
return new String[0];
|
||||
|
||||
return directory.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定文件的{@linkplain FileInfo}。
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static FileInfo getFileInfo(File file)
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(file.getName());
|
||||
|
||||
if (file.exists())
|
||||
fileInfo.setBytes(file.length());
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定目录下文件的{@linkplain FileInfo}。
|
||||
*
|
||||
* @param directory
|
||||
* @return
|
||||
*/
|
||||
public static FileInfo[] getFileInfos(File directory)
|
||||
{
|
||||
if (!directory.exists())
|
||||
return new FileInfo[0];
|
||||
|
||||
File[] files = directory.listFiles();
|
||||
|
||||
FileInfo[] fileInfos = new FileInfo[files.length];
|
||||
|
||||
for (int i = 0; i < files.length; i++)
|
||||
fileInfos[i] = getFileInfo(files[i]);
|
||||
|
||||
return fileInfos;
|
||||
}
|
||||
}
|
|
@ -11,9 +11,9 @@ import java.sql.Statement;
|
|||
import org.datagear.connection.AbstractDriverChecker;
|
||||
import org.datagear.connection.ConnectionOption;
|
||||
import org.datagear.connection.DriverChecker;
|
||||
import org.datagear.connection.JdbcUtil;
|
||||
import org.datagear.dbinfo.DatabaseInfoResolver;
|
||||
import org.datagear.dbinfo.TableInfo;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
|
||||
/**
|
||||
* 会执行测试SQL的{@linkplain DriverChecker}。
|
||||
|
|
|
@ -13,7 +13,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.datagear.management.domain.User;
|
||||
import org.datagear.persistence.support.UUID;
|
||||
import org.datagear.util.IDUtil;
|
||||
import org.datagear.web.OperationMessage;
|
||||
import org.datagear.web.security.AuthUser;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
@ -75,7 +75,7 @@ public class WebUtils
|
|||
|
||||
if (anonymousUserId == null || anonymousUserId.isEmpty())
|
||||
{
|
||||
anonymousUserId = UUID.gen();
|
||||
anonymousUserId = IDUtil.uuid();
|
||||
|
||||
Cookie cookie = new Cookie(COOKIE_USER_ID_ANONYMOUS, anonymousUserId);
|
||||
cookie.setPath(request.getContextPath() + "/");
|
||||
|
|
|
@ -10,8 +10,8 @@ import java.util.zip.ZipInputStream;
|
|||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.datagear.connection.IOUtil;
|
||||
import org.datagear.connection.XmlDriverEntityManager;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.context.ServletContextAware;
|
||||
|
|
11
pom.xml
11
pom.xml
|
@ -31,6 +31,7 @@
|
|||
<module>datagear-management</module>
|
||||
<module>datagear-web</module>
|
||||
<module>datagear-webembd</module>
|
||||
<module>datagear-util</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
|
@ -108,10 +109,10 @@ ${line.separator}
|
|||
${line.separator}
|
||||
</echo>
|
||||
<!-- 替换web模块datagear-version.properties中的版本号 -->
|
||||
<replaceregexp file="datagear-web/src/main/resources/datagear-version.properties" encoding="UTF-8" match="version=\d+(\.\d+){1,2}(\-\w+){0,1}" replace="version=${project.version}" />
|
||||
<replaceregexp file="datagear-web/src/main/resources/datagear-version.properties" encoding="UTF-8" match="version=\d+(\.\d+){1,2}(\-\w+){0,1}" replace="version=${project.version}"/>
|
||||
|
||||
<!-- 替换web模块readme.txt中的版本号 -->
|
||||
<replaceregexp file="datagear-web/src/main/webapp/readme.txt" encoding="UTF-8" match="数据齿轮\-v\d+(\.\d+){1,2}(\-\w+){0,1}" replace="数据齿轮-v${project.version}" />
|
||||
<replaceregexp file="datagear-web/src/main/webapp/readme.txt" encoding="UTF-8" match="数据齿轮\-v\d+(\.\d+){1,2}(\-\w+){0,1}" replace="数据齿轮-v${project.version}"/>
|
||||
|
||||
<!-- 为web模块的changelog.txt添加版本号行 -->
|
||||
<echo file="datagear-web/src/main/webapp/WEB-INF/changelog.txt" encoding="UTF-8" append="true">
|
||||
|
@ -123,13 +124,13 @@ ${line.separator}
|
|||
</echo>
|
||||
|
||||
<!-- 替换webembd模块readme.txt中的版本号 -->
|
||||
<replaceregexp file="datagear-webembd/src/main/dist/readme.txt" encoding="UTF-8" match="数据齿轮\-v\d+(\.\d+){1,2}(\-\w+){0,1}" replace="数据齿轮-v${project.version}" />
|
||||
<replaceregexp file="datagear-webembd/src/main/dist/readme.txt" encoding="UTF-8" match="数据齿轮\-v\d+(\.\d+){1,2}(\-\w+){0,1}" replace="数据齿轮-v${project.version}"/>
|
||||
|
||||
<!-- 替换webembd模块startup.bat中的版本号 -->
|
||||
<replaceregexp file="datagear-webembd/src/main/dist/startup.bat" encoding="UTF-8" match="datagear\-webembd\-\d+(\.\d+){1,2}(\-\w+){0,1}" replace="datagear-webembd-${project.version}" />
|
||||
<replaceregexp file="datagear-webembd/src/main/dist/startup.bat" encoding="UTF-8" match="datagear\-webembd\-\d+(\.\d+){1,2}(\-\w+){0,1}" replace="datagear-webembd-${project.version}"/>
|
||||
|
||||
<!-- 替换webembd模块startup.sh中的版本号 -->
|
||||
<replaceregexp file="datagear-webembd/src/main/dist/startup.sh" encoding="UTF-8" match="datagear\-webembd\-\d+(\.\d+){1,2}(\-\w+){0,1}" replace="datagear-webembd-${project.version}" />
|
||||
<replaceregexp file="datagear-webembd/src/main/dist/startup.sh" encoding="UTF-8" match="datagear\-webembd\-\d+(\.\d+){1,2}(\-\w+){0,1}" replace="datagear-webembd-${project.version}"/>
|
||||
|
||||
</tasks>
|
||||
</configuration>
|
||||
|
|
Loading…
Reference in New Issue