未验证 提交 1658176e 编写于 作者: G gabry.wu 提交者: GitHub

Adapting partial code(file name start with P #1) to the sonar cloud rule (#2171) (#2187)

上级 e0fc3171
......@@ -31,12 +31,12 @@ public class PlaceholderUtils {
/**
* Prefix of the position to be replaced
*/
public static final String placeholderPrefix = "${";
public static final String PLACEHOLDER_PREFIX = "${";
/**
* The suffix of the position to be replaced
*/
public static final String placeholderSuffix = "}";
public static final String PLACEHOLDER_SUFFIX = "}";
/**
......@@ -68,7 +68,7 @@ public class PlaceholderUtils {
*/
public static PropertyPlaceholderHelper getPropertyPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) {
return new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix, null, ignoreUnresolvablePlaceholders);
return new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, null, ignoreUnresolvablePlaceholders);
}
/**
......
......@@ -426,6 +426,7 @@ public class ProcessBuilderForWin32 {
static final ProcessBuilderForWin32.NullInputStream INSTANCE = new ProcessBuilderForWin32.NullInputStream();
private NullInputStream() {}
public int read() { return -1; }
@Override
public int available() { return 0; }
}
......@@ -462,7 +463,7 @@ public class ProcessBuilderForWin32 {
*
* @since 1.7
*/
public static abstract class Redirect {
public abstract static class Redirect {
/**
* The type of a {@link ProcessBuilderForWin32.Redirect}.
*/
......@@ -494,7 +495,7 @@ public class ProcessBuilderForWin32 {
* {@link ProcessBuilderForWin32.Redirect#appendTo Redirect.appendTo(File)}.
*/
APPEND
};
}
/**
* Returns the type of this {@code Redirect}.
......@@ -568,6 +569,7 @@ public class ProcessBuilderForWin32 {
throw new NullPointerException();
return new ProcessBuilderForWin32.Redirect() {
public Type type() { return Type.READ; }
@Override
public File file() { return file; }
public String toString() {
return "redirect to read from file \"" + file + "\"";
......@@ -595,10 +597,12 @@ public class ProcessBuilderForWin32 {
throw new NullPointerException();
return new ProcessBuilderForWin32.Redirect() {
public Type type() { return Type.WRITE; }
@Override
public File file() { return file; }
public String toString() {
return "redirect to write to file \"" + file + "\"";
}
@Override
boolean append() { return false; }
};
}
......@@ -626,10 +630,12 @@ public class ProcessBuilderForWin32 {
throw new NullPointerException();
return new ProcessBuilderForWin32.Redirect() {
public Type type() { return Type.APPEND; }
@Override
public File file() { return file; }
public String toString() {
return "redirect to append to file \"" + file + "\"";
}
@Override
boolean append() { return true; }
};
}
......
......@@ -40,7 +40,7 @@ public class PostgreDataSource extends BaseDataSource {
@Override
public String getJdbcUrl() {
String jdbcUrl = getAddress();
if (jdbcUrl.lastIndexOf("/") != (jdbcUrl.length() - 1)) {
if (jdbcUrl.lastIndexOf('/') != (jdbcUrl.length() - 1)) {
jdbcUrl += "/";
}
......
......@@ -30,16 +30,8 @@ import java.sql.SQLException;
*/
public class PostgresqlUpgradeDao extends UpgradeDao {
public static final Logger logger = LoggerFactory.getLogger(UpgradeDao.class);
private static final String schema = getSchema();
/**
* init
*/
@Override
protected void init() {
}
public static final Logger logger = LoggerFactory.getLogger(PostgresqlUpgradeDao.class);
private static final String SCHEMA = getSchema();
/**
* postgresql upgrade dao holder
......@@ -58,16 +50,6 @@ public class PostgresqlUpgradeDao extends UpgradeDao {
return PostgresqlUpgradeDaoHolder.INSTANCE;
}
/**
* init schema
* @param initSqlPath initSqlPath
*/
@Override
public void initSchema(String initSqlPath) {
super.initSchema(initSqlPath);
}
/**
* getSchema
* @return schema
......@@ -107,13 +89,9 @@ public class PostgresqlUpgradeDao extends UpgradeDao {
try {
conn = dataSource.getConnection();
rs = conn.getMetaData().getTables(null, schema, tableName, null);
if (rs.next()) {
return true;
} else {
return false;
}
rs = conn.getMetaData().getTables(null, SCHEMA, tableName, null);
return rs.next();
} catch (SQLException e) {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e);
......@@ -135,13 +113,8 @@ public class PostgresqlUpgradeDao extends UpgradeDao {
ResultSet rs = null;
try {
conn = dataSource.getConnection();
rs = conn.getMetaData().getColumns(null,schema,tableName,columnName);
if (rs.next()) {
return true;
} else {
return false;
}
rs = conn.getMetaData().getColumns(null, SCHEMA,tableName,columnName);
return rs.next();
} catch (SQLException e) {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e);
......
......@@ -24,7 +24,6 @@ import java.util.Date;
import org.apache.dolphinscheduler.common.enums.DbType;
import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.dao.MonitorDBDao;
import org.apache.dolphinscheduler.dao.entity.MonitorRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -34,7 +33,7 @@ import org.slf4j.LoggerFactory;
*/
public class PostgrePerformance extends BaseDBPerformance {
private static Logger logger = LoggerFactory.getLogger(MonitorDBDao.class);
private static Logger logger = LoggerFactory.getLogger(PostgrePerformance.class);
/**
* get monitor record
......
......@@ -77,7 +77,7 @@ public class ProcessDefinitionMapperTest {
//update
processDefinition.setUpdateTime(new Date());
int update = processDefinitionMapper.updateById(processDefinition);
Assert.assertEquals(update, 1);
Assert.assertEquals(1, update);
processDefinitionMapper.deleteById(processDefinition.getId());
}
......@@ -88,7 +88,7 @@ public class ProcessDefinitionMapperTest {
public void testDelete(){
ProcessDefinition processDefinition = insertOne();
int delete = processDefinitionMapper.deleteById(processDefinition.getId());
Assert.assertEquals(delete, 1);
Assert.assertEquals(1, delete);
}
/**
......@@ -189,7 +189,7 @@ public class ProcessDefinitionMapperTest {
List<ProcessDefinition> processDefinitions = processDefinitionMapper.queryDefinitionListByIdList(array);
processDefinitionMapper.deleteById(processDefinition.getId());
processDefinitionMapper.deleteById(processDefinition1.getId());
Assert.assertEquals(processDefinitions.size(), 2);
Assert.assertEquals(2, processDefinitions.size());
}
......
......@@ -30,12 +30,12 @@ public class Ping implements Serializable {
/**
* ping body
*/
protected static ByteBuf EMPTY_BODY = Unpooled.EMPTY_BUFFER;
protected static final ByteBuf EMPTY_BODY = Unpooled.EMPTY_BUFFER;
/**
* request command body
*/
private static byte[] EMPTY_BODY_ARRAY = new byte[0];
private static final byte[] EMPTY_BODY_ARRAY = new byte[0];
private static final ByteBuf PING_BUF;
......
......@@ -30,12 +30,12 @@ public class Pong implements Serializable {
/**
* pong body
*/
protected static ByteBuf EMPTY_BODY = Unpooled.EMPTY_BUFFER;
protected static final ByteBuf EMPTY_BODY = Unpooled.EMPTY_BUFFER;
/**
* pong command body
*/
private static byte[] EMPTY_BODY_ARRAY = new byte[0];
private static final byte[] EMPTY_BODY_ARRAY = new byte[0];
/**
* ping byte buffer
......
......@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.server.utils;
import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.process.Property;
import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils;
import java.util.Date;
......@@ -70,17 +71,16 @@ public class ParamUtils {
Map.Entry<String, Property> en = iter.next();
Property property = en.getValue();
if (property.getValue() != null && property.getValue().length() > 0){
if (property.getValue().startsWith("$")){
/**
* local parameter refers to global parameter with the same name
* note: the global parameters of the process instance here are solidified parameters,
* and there are no variables in them.
*/
String val = property.getValue();
val = ParameterUtils.convertParameterPlaceholders(val, timeParams);
property.setValue(val);
}
if (StringUtils.isNotEmpty(property.getValue())
&& property.getValue().startsWith("$")){
/**
* local parameter refers to global parameter with the same name
* note: the global parameters of the process instance here are solidified parameters,
* and there are no variables in them.
*/
String val = property.getValue();
val = ParameterUtils.convertParameterPlaceholders(val, timeParams);
property.setValue(val);
}
}
......
......@@ -60,11 +60,6 @@ public class ProcedureTask extends AbstractTask {
*/
private ProcessService processService;
/**
* base datasource
*/
private BaseDataSource baseDataSource;
/**
* constructor
* @param taskProps task props
......@@ -117,7 +112,7 @@ public class ProcedureTask extends AbstractTask {
// load class
DataSourceFactory.loadClass(dataSource.getType());
// get datasource
baseDataSource = DataSourceFactory.getDatasource(dataSource.getType(),
BaseDataSource baseDataSource = DataSourceFactory.getDatasource(dataSource.getType(),
dataSource.getConnectionParams());
// get jdbc connection
......@@ -163,7 +158,7 @@ public class ProcedureTask extends AbstractTask {
stmt.setQueryTimeout(taskProps.getTaskTimeout());
}
Map<Integer,Property> outParameterMap = new HashMap<>();
if (userDefParamsList != null && userDefParamsList.size() > 0){
if (CollectionUtils.isNotEmpty(userDefParamsList)){
int index = 1;
for (Property property : userDefParamsList){
logger.info("localParams : prop : {} , dirct : {} , type : {} , value : {}"
......@@ -237,31 +232,31 @@ public class ProcedureTask extends AbstractTask {
private void getOutputParameter(CallableStatement stmt, int index, String prop, DataType dataType) throws SQLException {
switch (dataType){
case VARCHAR:
logger.info("out prameter key : {} , value : {}",prop,stmt.getString(index));
logger.info("out prameter varchar key : {} , value : {}",prop,stmt.getString(index));
break;
case INTEGER:
logger.info("out prameter key : {} , value : {}", prop, stmt.getInt(index));
logger.info("out prameter integer key : {} , value : {}", prop, stmt.getInt(index));
break;
case LONG:
logger.info("out prameter key : {} , value : {}",prop,stmt.getLong(index));
logger.info("out prameter long key : {} , value : {}",prop,stmt.getLong(index));
break;
case FLOAT:
logger.info("out prameter key : {} , value : {}",prop,stmt.getFloat(index));
logger.info("out prameter float key : {} , value : {}",prop,stmt.getFloat(index));
break;
case DOUBLE:
logger.info("out prameter key : {} , value : {}",prop,stmt.getDouble(index));
logger.info("out prameter double key : {} , value : {}",prop,stmt.getDouble(index));
break;
case DATE:
logger.info("out prameter key : {} , value : {}",prop,stmt.getDate(index));
logger.info("out prameter date key : {} , value : {}",prop,stmt.getDate(index));
break;
case TIME:
logger.info("out prameter key : {} , value : {}",prop,stmt.getTime(index));
logger.info("out prameter time key : {} , value : {}",prop,stmt.getTime(index));
break;
case TIMESTAMP:
logger.info("out prameter key : {} , value : {}",prop,stmt.getTimestamp(index));
logger.info("out prameter timestamp key : {} , value : {}",prop,stmt.getTimestamp(index));
break;
case BOOLEAN:
logger.info("out prameter key : {} , value : {}",prop, stmt.getBoolean(index));
logger.info("out prameter boolean key : {} , value : {}",prop, stmt.getBoolean(index));
break;
default:
break;
......
......@@ -147,7 +147,7 @@ public class PermissionCheck<T> {
List<T> unauthorizedList = processService.listUnauthorized(userId,needChecks,authorizationType);
// if exist unauthorized resource
if(CollectionUtils.isNotEmpty(unauthorizedList)){
logger.error("user {} didn't has permission of {}: {}", user.getUserName(), authorizationType.getDescp(),unauthorizedList.toString());
logger.error("user {} didn't has permission of {}: {}", user.getUserName(), authorizationType.getDescp(),unauthorizedList);
throw new RuntimeException(String.format("user %s didn't has permission of %s %s", user.getUserName(), authorizationType.getDescp(), unauthorizedList.get(0)));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册