获得SQL脚本中SQL语句列表

@param scriptName SQL脚本名称

@return SQL语句列表
358102
public List<String> getScript(String scriptName) {
		String scriptFilename = this.scriptMap.get(scriptName);
		InputStream scriptFileStream = FileUtils.getFileInputStream(scriptFilename);
		
		List<String> sqlList = new SqlScriptReader().getSQLList(scriptFileStream);

		return sqlList;
	}
462481
public static String getObjectScript(String objectName, boolean multiDb, String dialect, WorkspaceEntry wsEntry)
      throws RepositoryConfigurationException, IOException
   {
      String scripts = prepareScripts(wsEntry, dialect);

      String sql = null;
      for (String query : JDBCUtils.splitWithSQLDelimiter(scripts))
      {
         String q = JDBCUtils.cleanWhitespaces(query);
         if (q.contains(objectName))
         {
            if (sql != null)
            {
               throw new RepositoryConfigurationException("Can't find unique script for object creation. Object name: "
                  + objectName);
            }

            sql = q;
         }
      }

      if (sql != null)
      {
         return sql;
      }

      throw new RepositoryConfigurationException("Script for object creation is not found. Object name: " + objectName);
   }
481000
public String getSmartCountSql(String sql, String name) {
        //解析SQL
        Statement stmt = null;
        //特殊sql不需要去掉order by时，使用注释前缀
        if(sql.indexOf(KEEP_ORDERBY) >= 0){
            return getSimpleCountSql(sql);
        }
        try {
            stmt = CCJSqlParserUtil.parse(sql);
        } catch (Throwable e) {
            //无法解析的用一般方法返回count语句
            return getSimpleCountSql(sql);
        }
        Select select = (Select) stmt;
        SelectBody selectBody = select.getSelectBody();
        try {
            //处理body-去order by
            processSelectBody(selectBody);
        } catch (Exception e) {
            //当 sql 包含 group by 时，不去除 order by
            return getSimpleCountSql(sql);
        }
        //处理with-去order by
        processWithItemsList(select.getWithItemsList());
        //处理为count查询
        sqlToCount(select, name);
        String result = select.toString();
        return result;
    }
706409
public static String getCsvFileAsSqlInsertScript(final String tableName, final CsvBean csvBean)
	{
		return getCsvFileAsSqlInsertScript(tableName, csvBean, true, true);
	}
1017384
private void executeGalaxyScript(final String scriptName) {
    final String bashScript = String.format("cd %s; if [ -d .venv ]; then . .venv/bin/activate; fi; %s", getPath(), scriptName);
    IoUtils.executeAndWait("bash", "-c", bashScript);
  }
940605
public ExecuteSQLQueryBuilder validateScript(Resource scriptResource, String type) {
        return validateScript(scriptResource, type, FileUtils.getDefaultCharset());
    }
1042747
public static String readScript(final String resourceName) throws IOException {
        final StringBuilder buf = new StringBuilder();
        try (final InputStream inputStream = ScriptUtils.class.getResourceAsStream(resourceName)) {
            if (inputStream == null) {
                throw new IOException("Could not find script resource: " + resourceName);
            }
            try (final BufferedReader reader = new BufferedReader(
                    new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
                String prefix = "";
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.length() > 0) {
                        buf.append(prefix).append(line.trim());
                        prefix = "\n";
                    }
                }
            }
        }
        return buf.toString();
    }
1270629
public String getQueryNamesPrepareSQL(T bean) {
        if (this.tableStrategy == null) return queryNamesPrepareSQL;
        return queryNamesPrepareSQL.replace("${newtable}", getTable(bean));
    }
992021
public static ScriptEnvironment getTemporaryEnvironment(String environmentName) {
      Preconditions.checkArgument(StringUtils.isNotNullOrBlank(environmentName),
                                  "Environment name cannot be null or empty"
                                 );
      ScriptEngine engine = ScriptEnvironmentManager.getInstance().engineManager.getEngineByName(environmentName);
      Preconditions.checkArgument(engine != null, environmentName + " is an unknown.");
      return new ScriptEnvironment(engine);
   }
612478
public TableMetadata getTableMetadata(String tableName){
		if(tableName == null) return null;
		
		try {
			tableMetadataStatement.setInt(1, tableName.hashCode());
			ResultSet set = tableMetadataStatement.executeQuery();
			
			return transformToTableMetadata(set);
		} catch (SQLException e) {
			throw new BackendException("Could not get TableMetadata for table '" + tableName + "'", e);
		}
	}
755214
public Script updateName(int id, String name) throws Exception {
        PreparedStatement statement = null;

        try (Connection sqlConnection = SQLService.getInstance().getConnection()) {
            statement = sqlConnection.prepareStatement(
                "UPDATE " + Constants.DB_TABLE_SCRIPT +
                    " SET " + Constants.SCRIPT_NAME + " = ? " +
                    " WHERE " + Constants.GENERIC_ID + " = ?"
            );
            statement.setString(1, name);
            statement.setInt(2, id);
            statement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }

        return this.getScript(id);
    }
1036357
public Session getSysSessionForScript(Database db) {

        Session session = new Session(db, db.getUserManager().getSysUser(),
                                      false, false, false, 0, 0);

        session.isProcessingScript = true;

        return session;
    }
1182464
public String buildAllDataSql()
    {
        String sql="select * from ${tablename} ";
        String tablename= ModelHelper.getTableName(this.getClass());
        sql= StringUtil.replace(sql,"${tablename}",tablename);
        return sql;
    }
289991
private String loadfromFromFile(String queryName) throws IllegalStateException {
		try (final InputStream is = getClass().getResourceAsStream(scriptsFolder + queryName + ".sql");) {
		    String sql = StringUtils.join(IOUtils.readLines(is, StandardCharsets.UTF_8), IOUtils.LINE_SEPARATOR);
		    
		    // Look for tokens
		    final String[] tokens = StringUtils.substringsBetween(sql, "${", "}");
		    if (tokens != null && tokens.length > 0) {
    		    final Map<String, String> values = Arrays.stream(tokens).collect(Collectors.toMap(
    	            Function.identity(),
    	            this::load,
    	            (o, n) -> o
    	        ));
		    
		        sql = StrSubstitutor.replace(sql, values);
		    }
		    
			return sql;
		} catch (Exception e) {
			throw new IllegalStateException("Could not load query " + scriptsFolder + queryName, e);
		}
	}
1288021
public SqlBuilder from(String... tableNames) {
		if (ArrayUtil.isEmpty(tableNames) || StrUtil.hasBlank(tableNames)) {
			throw new DbRuntimeException("Table name is blank in table names !");
		}

		if (null != wrapper) {
			// 包装表名
			tableNames = wrapper.wrap(tableNames);
		}

		sql.append(" FROM ").append(ArrayUtil.join(tableNames, StrUtil.COMMA));

		return this;
	}
1087276
public Clob toClob(String stringName, Connection sqlConnection) {
        Clob clobName = null;
        try {
            clobName = sqlConnection.createClob();
            clobName.setString(1, stringName);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            logger.info("Unable to create clob object");
            e.printStackTrace();
        }
        return clobName;
    }
714038
private static SQLTransform getTransform(TypeName typeName) {
		if (typeName.isPrimitive()) {
			return getPrimitiveTransform(typeName);
		}

		if (typeName instanceof ArrayTypeName) {
			ArrayTypeName typeNameArray = (ArrayTypeName) typeName;
			TypeName componentTypeName = typeNameArray.componentType;

			if (TypeUtility.isEquals(componentTypeName, Byte.TYPE.toString())) {
				return new ByteArraySQLTransform();
			} else {
				return new ArraySQLTransform();
			}
		} else if (typeName instanceof ParameterizedTypeName) {
			ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName;
			if (TypeUtility.isList(parameterizedTypeName)) {
				return new ListSQLTransformation();
			} else if (TypeUtility.isSet(parameterizedTypeName)) {
				return new SetSQLTransformation();
			} else if (TypeUtility.isMap(parameterizedTypeName)) {
				return new MapSQLTransformation();
			}
		}

		String name = typeName.toString();

		if (name.startsWith("java.lang")) {
			return getLanguageTransform(typeName);
		}

		if (name.startsWith("java.util")) {
			return getUtilTransform(typeName);
		}

		if (name.startsWith("java.math")) {
			return getMathTransform(typeName);
		}

		if (name.startsWith("java.net")) {
			return getNetTransform(typeName);
		}

		if (name.startsWith("java.sql")) {
			return getSqlTransform(typeName);
		}

		if (TypeUtility.isEnum(typeName)) {
			return new EnumSQLTransform(typeName);
		}

		return new ObjectSQLTransform();
	}