List of usage examples for org.apache.commons.logging Log error
void error(Object message, Throwable t);
From source file:org.acmsl.queryj.api.MetaLanguageUtils.java
/** * Retrieves which values of the column correspond to which ISA descendant * table (whose parent is declared in table comments as <code>@isatype</code>). * @param columnComment the column comment. * @return such associations.//from w w w. jav a 2s . co m */ @SuppressWarnings("unused") @NotNull public List<List<String>> retrieveColumnDiscriminatedTables(@NotNull final String columnComment) { @Nullable List<List<String>> result = null; if (!isEmpty(columnComment)) { try { @NotNull final PerCommentParser t_Parser = setUpParser(columnComment); @NotNull final ParseTree tree = t_Parser.columnComment(); @NotNull final PerCommentVisitor<List<List<String>>> visitor = new PerCommentColIsarefsVisitor(); @Nullable final List<List<String>> resultValue = visitor.visit(tree); if (resultValue != null) { result = resultValue; } } catch (@NotNull final RecognitionException recognitionException) { @Nullable final Log t_Log = UniqueLogFactory.getLog(MetaLanguageUtils.class); if (t_Log != null) { t_Log.error(Literals.INVALID_COLUMN_COMMENT + columnComment, recognitionException); } } } if (result == null) { result = new ArrayList<>(0); } return result; }
From source file:org.acmsl.queryj.api.MetaLanguageUtils.java
/** * Retrieves whether the table is meant to be decorated. * @param tableComment the table comment. * @return such condition.//from w w w. j a v a2 s .co m */ public boolean retrieveTableDecorator(@NotNull final String tableComment) { boolean result = false; if (!isEmpty(tableComment)) { try { @NotNull final PerCommentParser t_Parser = setUpParser(tableComment); @Nullable final ParseTree t_Tree = t_Parser.tableComment(); if (t_Tree != null) { @NotNull final PerCommentVisitor<Boolean> t_Visitor = new PerCommentTabDecoratorVisitor(); try { @Nullable final Boolean resultValue = t_Visitor.visit(t_Tree); if (resultValue != null) { result = resultValue; } } catch (@NotNull final Throwable npe) { @Nullable final Log t_Log = UniqueLogFactory.getLog(MetaLanguageUtils.class); if (t_Log != null) { t_Log.fatal(npe); } npe.printStackTrace(System.err); } } } catch (@NotNull final RecognitionException recognitionException) { @Nullable final Log t_Log = UniqueLogFactory.getLog(MetaLanguageUtils.class); if (t_Log != null) { t_Log.error(Literals.INVALID_TABLE_COMMENT + tableComment, recognitionException); } } } return result; }
From source file:org.acmsl.queryj.api.MetaLanguageUtils.java
/** * Retrieves whether the table is modelling a relationship. * @param tableComment the table comment. * @return such condition./*from w w w . j ava2 s. c om*/ */ @SuppressWarnings("unused") @NotNull public List<List<String>> retrieveTableRelationship(@NotNull final String tableComment) { @Nullable List<List<String>> result = null; if (!isEmpty(tableComment)) { try { @NotNull final PerCommentParser t_Parser = setUpParser(tableComment); @NotNull final ParseTree tree = t_Parser.tableComment(); @NotNull final PerCommentVisitor<List<List<String>>> visitor = new PerCommentTabRelationshipVisitor(); @Nullable final List<List<String>> resultValue = visitor.visit(tree); if (resultValue != null) { result = resultValue; } } catch (final RecognitionException recognitionException) { @Nullable final Log t_Log = UniqueLogFactory.getLog(MetaLanguageUtils.class); if (t_Log != null) { t_Log.error(Literals.INVALID_TABLE_COMMENT + tableComment, recognitionException); } result = new ArrayList<>(); } } if (result == null) { result = new ArrayList<>(0); } return result; }
From source file:org.acmsl.queryj.api.MetaLanguageUtils.java
/** * Retrieves whether the column is bound to a sequence. * @param columnComment the column comment. * @return the sequence name, or {@code null} otherwise. *///from www. j a v a 2s . com @SuppressWarnings("unused") @Nullable public String retrieveColumnOraseq(@NotNull final String columnComment) { @Nullable String result = null; if (!isEmpty(columnComment)) { try { @NotNull final PerCommentParser t_Parser = setUpParser(columnComment); @NotNull final ParseTree tree = t_Parser.columnComment(); @NotNull final PerCommentVisitor<String> visitor = new PerCommentColOraseqVisitor(); @Nullable final String resultValue = visitor.visit(tree); if (resultValue != null) { result = resultValue; } } catch (@NotNull final RecognitionException recognitionException) { @Nullable final Log t_Log = UniqueLogFactory.getLog(MetaLanguageUtils.class); if (t_Log != null) { t_Log.error(Literals.INVALID_COLUMN_COMMENT + columnComment, recognitionException); } } } return result; }
From source file:org.acmsl.queryj.customsql.xml.SqlXmlParserImpl.java
/** * Loads the information from the XML resource. * @param digester the Digester instance. * @param input the input stream.// www. j a v a2 s. c om * @throws QueryJBuildException if the parsing operation fails. */ protected synchronized void load(@Nullable final Digester digester, @Nullable final InputStream input) throws QueryJBuildException { if (digester != null) { @NotNull final List<? extends IdentifiableElement<String>> collection = new ArrayList<>(); digester.push(collection); try { if (input != null) { digester.parse(input); processCollection(collection); } } catch (@NotNull final RuntimeException exception) { throw exception; } catch (@NotNull final Exception exception) { try { @Nullable final Log t_Log = UniqueLogFactory.getLog(SqlXmlParser.class); if (t_Log != null) { t_Log.error("Cannot read sql.xml information.", exception); } } catch (@NotNull final Throwable throwable) { // class-loading problem. } @Nullable final File t_File; if (exception instanceof SAXParseException) { t_File = SaxUtils.getInstance().retrieveFailingFile((SAXParseException) exception); } else if (input instanceof FileInputStream) { t_File = FileUtils.getInstance().retrieveFile((FileInputStream) input); } else { t_File = null; } throw new CannotReadCustomSqlXmlFileException(t_File, exception); } } }
From source file:org.acmsl.queryj.debugging.QueryJDebuggingChain.java
/** * Sends given command to a concrete chain. * @param chain the concrete chain./*from ww w . j a v a2 s .c o m*/ * @param command the command that represents which actions should be done. * @param service the {@link org.acmsl.queryj.debugging.TemplateDebuggingService service}. * @return <code>true</code> if the command is processed by the chain. * @throws QueryJBuildException if the process fails. */ protected boolean process(@NotNull final Chain<QueryJCommand, QueryJBuildException, CH> chain, @NotNull final QueryJCommand command, @NotNull final TemplateDebuggingService<C> service) throws QueryJBuildException { final boolean result = false; @Nullable final Log t_Log = command.getLog(); final boolean t_bLoggingEnabled = (t_Log != null); @NotNull TemplateDebuggingCommand t_DebugCommand = TemplateDebuggingCommand.NEXT; try { @Nullable CH t_CurrentCommandHandler = null; do { if (t_DebugCommand.equals(TemplateDebuggingCommand.NEXT)) { t_CurrentCommandHandler = getNextChainLink(chain, t_CurrentCommandHandler); } else if (t_DebugCommand.equals(TemplateDebuggingCommand.PREVIOUS)) { t_CurrentCommandHandler = getPreviousChainLink(chain, t_CurrentCommandHandler); } if (t_bLoggingEnabled) { t_Log.debug("Next handler: " + t_CurrentCommandHandler); } if (t_CurrentCommandHandler != null) { t_DebugCommand = service.debug(t_CurrentCommandHandler, command); } if (t_bLoggingEnabled) { t_Log.debug(t_CurrentCommandHandler + "#handle(QueryJCommand) returned " + result); } } while (t_CurrentCommandHandler != null); } catch (@NotNull final QueryJBuildException buildException) { cleanUpOnError(buildException, command); if (t_bLoggingEnabled) { t_Log.error("QueryJ could not generate sources correctly.", buildException); } throw buildException; } return result; }
From source file:org.acmsl.queryj.metadata.AbstractTableDecorator.java
/** * Retrieves the static content.//w w w . ja va 2 s . c o m * @param table the table. * @param metadataManager the {@link MetadataManager} instance. * @return such information. */ @NotNull protected List<Row<DecoratedString>> getStaticContent( @NotNull final Table<String, Attribute<String>, List<Attribute<String>>> table, @NotNull final MetadataManager metadataManager) { List<Row<DecoratedString>> result = null; try { result = retrieveStaticContent(table.getName(), metadataManager, metadataManager.getTableDAO(), getDecoratorFactory()); } catch (@NotNull final SQLException invalidQuery) { @Nullable final Log t_Log = UniqueLogFactory.getLog(AbstractTableDecorator.class); if (t_Log != null) { t_Log.error("Cannot retrieve contents in table " + getTable().getName(), invalidQuery); } } if (result == null) { result = new ArrayList<>(0); } else { try { Collections.sort(result); } catch (@NotNull final Throwable throwable) { @Nullable final Log t_Log = UniqueLogFactory.getLog(AbstractTableDecorator.class); if (t_Log != null) { t_Log.error(throwable); } } } return result; }
From source file:org.acmsl.queryj.metadata.engines.MetadataManagerTableDAO.java
/** * Queries the contents of given table./*from w w w .j av a 2 s. co m*/ * @param tableName the table name. * @param staticAttributeName the static attribute name. * @param attributes the attributes. * @param connection the connection. * @return the retrieved rows. * @throws SQLException if the contents cannot be retrieved. */ @NotNull protected List<Row<String>> queryContents(@NotNull final String tableName, @Nullable final String staticAttributeName, @NotNull final List<Attribute<String>> attributes, @NotNull final Connection connection) throws SQLException { // TODO: Move this to TableDAO @NotNull final List<Row<String>> result = new ArrayList<>(); @Nullable final Log t_Log = UniqueLogFactory.getLog(DAOTemplateUtils.class); final int t_iColumnCount = attributes.size(); @Nullable ResultSet t_rsResults = null; @Nullable PreparedStatement t_PreparedStatement = null; try { t_PreparedStatement = connection.prepareStatement("select * from " + tableName); t_rsResults = t_PreparedStatement.executeQuery(); @NotNull final String[] t_astrColumnNames = new String[t_iColumnCount]; @NotNull final String[] t_astrColumnValues = new String[t_iColumnCount]; @Nullable String t_strRowName; if (t_rsResults != null) { while (t_rsResults.next()) { t_strRowName = null; @NotNull final ResultSetMetaData t_rsMetaData = t_rsResults.getMetaData(); int t_iArrayIndex; for (int t_iIndex = 1; t_iIndex <= t_iColumnCount; t_iIndex++) { t_iArrayIndex = t_iIndex - 1; t_astrColumnNames[t_iArrayIndex] = t_rsMetaData.getColumnName(t_iIndex); t_astrColumnValues[t_iArrayIndex] = t_rsResults.getString(t_iIndex); if (staticAttributeName.equalsIgnoreCase(t_astrColumnNames[t_iArrayIndex])) { t_strRowName = t_astrColumnValues[t_iArrayIndex]; } } reorderAttributes(attributes, t_astrColumnNames, t_astrColumnValues); @NotNull final List<Attribute<String>> t_lAttributes = new ArrayList<>(t_astrColumnValues.length); Attribute<String> t_NewAttribute; for (int t_iIndex = 0; t_iIndex < t_astrColumnValues.length; t_iIndex++) { @Nullable final Attribute<String> t_Attribute = attributes.get(t_iIndex); if (t_Attribute != null) { t_NewAttribute = new AttributeValueObject(t_Attribute.getName(), t_Attribute.getTypeId(), t_Attribute.getType(), t_Attribute.getTableName(), t_Attribute.getComment(), t_Attribute.getOrdinalPosition(), t_Attribute.getLength(), t_Attribute.getPrecision(), t_Attribute.getKeyword(), t_Attribute.getRetrievalQuery(), t_Attribute.getSequence(), t_Attribute.isNullable(), t_astrColumnValues[t_iIndex], t_Attribute.isReadOnly(), t_Attribute.isBoolean(), t_Attribute.getBooleanTrue(), t_Attribute.getBooleanFalse(), t_Attribute.getBooleanNull()); t_lAttributes.add(t_NewAttribute); } } result.add(buildRow(t_strRowName, tableName, t_lAttributes)); } } } finally { try { if (t_rsResults != null) { t_rsResults.close(); } } catch (@NotNull final SQLException sqlException) { if (t_Log != null) { t_Log.error("Cannot close the ResultSet.", sqlException); } } try { if (t_PreparedStatement != null) { t_PreparedStatement.close(); } } catch (@NotNull final SQLException sqlException) { if (t_Log != null) { t_Log.error("Cannot close the PreparedStatement.", sqlException); } } } return result; }
From source file:org.acmsl.queryj.metadata.engines.oracle.OracleMetadataManager.java
/** * Processes the schema./*from w ww. j a v a 2 s. com*/ * @param tableNames the table names. * @param connection the database connection. * @param caseSensitiveness whether the checks are case sensitive or not. * @param metadataExtractionListener the metadata extraction listener. * @param metaLanguageUtils the {@link MetaLanguageUtils} instance. * @param metadataTypeManager the {@link MetadataTypeManager} instance. * @return the list of all table names. * @throws SQLException if the extraction fails. * @throws QueryJException if any other error occurs. */ @NotNull @SuppressWarnings("unused") protected List<Table<String, Attribute<String>, List<Attribute<String>>>> extractTableMetadata( @Nullable final List<String> tableNames, @NotNull final Connection connection, final boolean caseSensitiveness, @NotNull final MetadataExtractionListener metadataExtractionListener, @NotNull final MetaLanguageUtils metaLanguageUtils, @NotNull final MetadataTypeManager metadataTypeManager) throws SQLException, QueryJException { @NotNull final List<Table<String, Attribute<String>, List<Attribute<String>>>> result; @Nullable final Log t_Log = UniqueLogFactory.getLog(OracleMetadataManager.class); @Nullable SQLException sqlExceptionToThrow = null; @Nullable ResultSet t_rsResults = null; @Nullable PreparedStatement t_PreparedStatement = null; @Nullable TableIncompleteValueObject t_Table; @NotNull final Map<String, TableIncompleteValueObject> t_mTableMap = new HashMap<>(); @NotNull final Map<String, List<AttributeIncompleteValueObject>> t_mColumnMap = new HashMap<>(); @NotNull final Map<String, List<AttributeIncompleteValueObject>> t_mPrimaryKeyMap = new HashMap<>(); @NotNull final Map<String, List<ForeignKeyIncompleteValueObject>> t_mForeignKeyMap = new HashMap<>(); @NotNull final Map<String, List<AttributeIncompleteValueObject>> t_mForeignKeyAttributeMap = new HashMap<>(); try { @NotNull final String t_strQuery = "select c.table_name, " + "tc.comments table_comment, " + "c.column_name, " + "uc.comments column_comment, " + "c.data_type, " + "c.data_length, " + "c.data_precision, " + "c.data_scale, " + "c.nullable, " + "c.column_id, " + "cons.position pk_position, " + "fks.constraint_name fk_name, " + "fks.target_table, " + "fks.position fk_position " + "from user_tab_comments tc, user_col_comments uc, " + "user_tab_columns c " + LEFT_OUTER_JOIN + "select ucc.* " + "from user_cons_columns ucc, user_constraints uc " + "where uc.constraint_type = 'P' and uc.status = 'ENABLED' " + "and uc.constraint_name = ucc.constraint_name) cons " + "on c.table_name = cons.table_name and c.column_name = cons.column_name " + LEFT_OUTER_JOIN + "select rcon.constraint_name, " + "col.position, " + "rcol.table_name source_table, " + "con.table_name target_table, " + "rcol.column_name " + "from user_constraints con, " + "user_cons_columns col, " + "user_constraints rcon, " + "user_cons_columns rcol " + "where rcon.constraint_type = 'R' " + "and rcon.r_constraint_name = con.constraint_name " + "and col.table_name = con.table_name " + "and col.constraint_name = con.constraint_name " + "and rcol.table_name = rcon.table_name " + "and rcol.constraint_name = rcon.constraint_name " + "and rcol.position = col.position) fks " + "on c.table_name = fks.source_table and c.column_name = fks.column_name " + "where instr(tc.table_name, '$') = 0 " + "and tc.table_name = c.table_name " + "and tc.table_name = uc.table_name " + "and c.column_name = uc.column_name "; if ((t_Log != null) && (t_Log.isDebugEnabled())) { t_Log.debug("query:" + t_strQuery); } t_PreparedStatement = connection.prepareStatement(t_strQuery); } catch (@NotNull final SQLException invalidQuery) { sqlExceptionToThrow = invalidQuery; } if (t_PreparedStatement != null) { try { t_rsResults = t_PreparedStatement.executeQuery(); } catch (@NotNull final SQLException queryFailed) { sqlExceptionToThrow = queryFailed; } } if (t_rsResults != null) { try { while (t_rsResults.next()) { processRow(t_rsResults, t_mTableMap, t_mColumnMap, t_mPrimaryKeyMap, t_mForeignKeyMap, t_mForeignKeyAttributeMap, caseSensitiveness, metaLanguageUtils, metadataTypeManager); } } catch (@NotNull final SQLException errorIteratingResults) { sqlExceptionToThrow = errorIteratingResults; } } if (t_rsResults != null) { try { t_rsResults.close(); } catch (@NotNull final SQLException sqlException) { if (t_Log != null) { t_Log.error("Cannot close the result set.", sqlException); } } } if (t_PreparedStatement != null) { try { t_PreparedStatement.close(); } catch (@NotNull final SQLException sqlException) { if (t_Log != null) { t_Log.error("Cannot close the statement.", sqlException); } } } if (sqlExceptionToThrow != null) { throw sqlExceptionToThrow; } buildUpTables(t_mTableMap, t_mColumnMap, t_mPrimaryKeyMap, t_mForeignKeyMap, t_mForeignKeyAttributeMap, caseSensitiveness, metaLanguageUtils); result = cloneTables(t_mTableMap.values()); return result; }
From source file:org.acmsl.queryj.tools.cli.QueryJCLIHelper.java
/** * Reads the configuration properties specified as a command-line * option.//from ww w. j a v a 2 s . co m * @param stream the input stream of the properties file. * @param log whether to log errors or not. * @return the <code>Properties</code> instance with the configuration * settings. */ @Nullable public Properties readConfigurationSettings(@NotNull final InputStream stream, final boolean log) { @Nullable Properties result = new Properties(); try { result.load(stream); } catch (@NotNull final IOException ioException) { result = null; if (log) { @Nullable final Log t_Log = UniqueLogFactory.getLog(QueryJCLIHelper.class); if (t_Log != null) { t_Log.error(Literals.CANNOT_READ_THE_CONFIGURATION_PROPERTIES_FILE, ioException); } } } return result; }