@Override public void accept(String action) { if (formatter != null) { action = formatter.format(action); } if ( delimiter != null ) { action += delimiter; } System.out.println( action ); }
/** * Log a SQL statement string using the specified formatter * * @param statement The SQL statement. * @param formatter The formatter to use. */ @AllowSysOut public void logStatement(String statement, Formatter formatter) { if ( format ) { if ( logToStdout || LOG.isDebugEnabled() ) { statement = formatter.format( statement ); } } LOG.debug( statement ); if ( logToStdout ) { System.out.println( "Hibernate: " + statement ); } } }
private static void applySqlString( String sqlString, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { if ( StringHelper.isEmpty( sqlString ) ) { return; } try { String sqlStringFormatted = formatter.format( sqlString ); for ( GenerationTarget target : targets ) { target.accept( sqlStringFormatted ); } } catch (CommandAcceptanceException e) { options.getExceptionHandler().handleException( e ); } }
private static void applySqlString( String sqlString, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { if ( StringHelper.isEmpty( sqlString ) ) { return; } String sqlStringFormatted = formatter.format( sqlString ); for ( GenerationTarget target : targets ) { try { target.accept( sqlStringFormatted ); } catch (CommandAcceptanceException e) { options.getExceptionHandler().handleException( e ); } } }
private static void applySqlString( boolean quiet, String sqlString, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { if ( !StringHelper.isEmpty( sqlString ) ) { String sqlStringFormatted = formatter.format( sqlString ); for ( GenerationTarget target : targets ) { try { target.accept( sqlStringFormatted ); } catch (CommandAcceptanceException e) { if ( !quiet ) { options.getExceptionHandler().handleException( e ); } // otherwise ignore the exception } } } }
private void assertNoLoss(String query) { String formattedQuery = FormatStyle.BASIC.getFormatter().format( query ); StringTokenizer formatted = new StringTokenizer( formattedQuery, " \t\n\r\f()" ); StringTokenizer plain = new StringTokenizer( query, " \t\n\r\f()" ); log.debugf( "Original: {}", query ); log.debugf( "Formatted: {}", formattedQuery ); while ( formatted.hasMoreTokens() && plain.hasMoreTokens() ) { String plainToken = plain.nextToken(); String formattedToken = formatted.nextToken(); assertEquals( "formatter did not return the same token", plainToken, formattedToken ); } assertFalse( formatted.hasMoreTokens() ); assertFalse( plain.hasMoreTokens() ); } }
private void write(PrintWriter writer, String[] lines, Formatter formatter) { for (String string : lines) writer.println(formatter.format(string) + ";"); }
@Override public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql) { if (sql.isEmpty()) { return ""; } String batch = "batch".equals(category) ? " add to batch " : ""; return String.format("Hibernate: %s %s {elapsed: %dms}", batch, HIBERNATE_SQL_FORMATTER.format(sql), elapsed); } }
@Override public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql) { if (sql.isEmpty()) { return ""; } String batch = "batch".equals(category) ? " add to batch " : ""; return String.format("Hibernate: %s %s {elapsed: %dms}", batch, HIBERNATE_SQL_FORMATTER.format(sql), elapsed); } }
private static void export(File outFile, String delimiter, Formatter formatter, String[] createSQL) { PrintWriter writer = null; try { writer = new PrintWriter(outFile); for (String string : createSQL) { writer.print(formatter.format(string) + "\n" + delimiter + "\n"); } } catch (FileNotFoundException e) { System.err.println(e); } finally { if (writer != null) writer.close(); } }
/** * Method reponsible to formmat the script, should skip line, and put the DDL and DML scripts. * * @param scriptsEntities the script of the entities generated by hibernate. * @param scriptsAdicionais some extra scripts, normally DML scripts. * @return A StringBuilder containg all DML and DDL scripts. */ private static StringBuilder formatterScript(String[] scriptsEntities, StringBuilder scriptsAdicionais) { Formatter formatter = FormatStyle.DDL.getFormatter(); StringBuilder stringSql = new StringBuilder(); for (String string : scriptsEntities) { String lineFormated = formatter.format(string) + "; \n"; stringSql.append(lineFormated); } if (scriptsAdicionais != null) { stringSql.append(scriptsAdicionais); } return stringSql; }
public void logStatement(String statement, Formatter formatter) { if ( format ) { if ( logToStdout || LOG.isDebugEnabled() ) { statement = formatter.format( statement ); } } LOG.debug( statement ); if ( logToStdout ) { System.out.println( "Hibernate: " + statement ); } } }
public void logStatement(String statement, Formatter formatter) { if ( format ) { if ( logToStdout || LOG.isDebugEnabled() ) { statement = formatter.format( statement ); } } LOG.debug( statement ); if ( logToStdout ) { System.out.println( "Hibernate: " + statement ); } } }
/** * Log a SQL statement string using the specified formatter * * @param statement The SQL statement. * @param formatter The formatter to use. */ @AllowSysOut public void logStatement(String statement, Formatter formatter) { if ( format ) { if ( logToStdout || LOG.isDebugEnabled() ) { statement = formatter.format( statement ); } } LOG.debug( statement ); if ( logToStdout ) { System.out.println( "Hibernate: " + statement ); } } }
String formatted = formatter.format(transformed); try { log.debug(formatted);
sb.append(formatter.format(schemaString)); sb.append(System.getProperty("line.separator")); sb.append(System.getProperty("line.separator"));
try { for (final String sqlCommand : sqlCommands) { final String formatted = formatter.format(sqlCommand); sqlWriter.println(formatted);
private void execute(boolean script, boolean export, Writer fileOutput, Statement statement, final String sql) throws IOException, SQLException { final SqlExceptionHelper sqlExceptionHelper = new SqlExceptionHelper(); String formatted = formatter.format( sql ); if (delimiter != null) formatted += delimiter; if (script) System.out.println(formatted); LOG.debug(formatted); if ( outputFile != null ) { fileOutput.write( formatted + "\n" ); } if ( export ) { statement.executeUpdate( sql ); try { SQLWarning warnings = statement.getWarnings(); if ( warnings != null) { sqlExceptionHelper.logAndClearWarnings( connectionHelper.getConnection() ); } } catch( SQLException sqle ) { LOG.unableToLogSqlWarnings(sqle); } } }
private void perform(String[] sqlCommands, List<Exporter> exporters) { for ( String sqlCommand : sqlCommands ) { String formatted = formatter.format( sqlCommand ); if ( delimiter != null ) { formatted += delimiter; } sqlStatementLogger.logStatement( sqlCommand, formatter ); for ( Exporter exporter : exporters ) { try { exporter.export( formatted ); } catch (Exception e) { if ( haltOnError ) { throw new HibernateException( "Error during DDL export", e ); } exceptions.add( e ); LOG.unsuccessfulCreate( sqlCommand ); LOG.error( e.getMessage() ); } } } }