public boolean isDebugEnabled() { return log.isDebugEnabled(); }
protected void printProperties(){ if(log.isDebugEnabled()){ StringWriter msg = new StringWriter(); PrintWriter writer = new PrintWriter(msg); propertyPrinter.printProperties(this.properties.values(), writer); log.debug("Print properties : \n\n{}",msg.toString()); } }
@Override public <T> List<T> readList(OrmContext context, SqlContext sqlContext, ResultSet rs, EntityMapping em, Class<T> elementType, Class<? extends T> resultClass) throws SQLException { List<T> list = new ArrayList<T>(); if(rs.next()){ ResultSetMapping rsm = createResultSetMapping(context, sqlContext, rs, em); do{ list.add(readCurrentRow(context, rs, rsm, resultClass)); }while(rs.next()); } if(log.isDebugEnabled()){ log.debug("Read {} rows of '{}' from result set",list.size(),em.getEntityName()); } return list; }
/** * Remove the binding for the given name from the current JNDI context. * @param name the JNDI name of the object * @throws NamingException thrown by JNDI, mostly name not found */ public void unbind(final String name) throws NamingException { if (logger.isDebugEnabled()) { logger.debug("Unbinding JNDI object with name [" + name + "]"); } execute(new JndiCallback<Object>() { public Object doInContext(Context ctx) throws NamingException { ctx.unbind(name); return null; } }); }
/** * Bind the given object to the current JNDI context, using the given name. * @param name the JNDI name of the object * @param object the object to bind * @throws NamingException thrown by JNDI, mostly name already bound */ public void bind(final String name, final Object object) throws NamingException { if (logger.isDebugEnabled()) { logger.debug("Binding JNDI object with name [" + name + "]"); } execute(new JndiCallback<Object>() { public Object doInContext(Context ctx) throws NamingException { ctx.bind(name, object); return null; } }); }
/** * Rebind the given object to the current JNDI context, using the given name. * Overwrites any existing binding. * @param name the JNDI name of the object * @param object the object to rebind * @throws NamingException thrown by JNDI */ public void rebind(final String name, final Object object) throws NamingException { if (logger.isDebugEnabled()) { logger.debug("Rebinding JNDI object with name [" + name + "]"); } execute(new JndiCallback<Object>() { public Object doInContext(Context ctx) throws NamingException { ctx.rebind(name, object); return null; } }); }
/** * Look up the object with the given name in the current JNDI context. * @param name the JNDI name of the object * @return object found (cannot be {@code null}; if a not so well-behaved * JNDI implementations returns null, a NamingException gets thrown) * @throws NamingException if there is no object with the given * name bound to JNDI */ public Object lookup(final String name) throws NamingException { if (logger.isDebugEnabled()) { logger.debug("Looking up JNDI object with name [" + name + "]"); } return execute(new JndiCallback<Object>() { public Object doInContext(Context ctx) throws NamingException { Object located = ctx.lookup(name); if (located == null) { throw new NameNotFoundException( "JNDI object with [" + name + "] not found: JNDI implementation returned null"); } return located; } }); }
void closeReal() { if(null != conn) { JDBC.closeConnection(conn); conn = null; if(log.isDebugEnabled()) { String state = pool.getStateInfo(); log.debug("Underlying connection closed! {} : [{}]", pool.getName(), state); } } }
@Override public LocalTransaction begin() { increase(); if (log.isDebugEnabled()) { if (isNewTransaction()) { log.debug("Begin a new transaction, referencedCount={}", referenceCount); } else { log.debug("Join a exists transaction, referencedCount={}", referenceCount); } } return this; }
@Override public AppInstrumentClass tryInstrument(ClassLoader loader, Resource r, byte[] bytes, boolean methodBodyOnly) { DefaultAppInstrumentContext context = new DefaultAppInstrumentContext(loader); for(AppInstrumentProcessor p : processors){ try { p.instrument(context, r, bytes, methodBodyOnly); } catch (Throwable e) { throw new AppInitException("Error calling instrument processor '" + p + "', " + e.getMessage(), e); } } AppInstrumentClass ic = null; if(!context.getAllInstrumentedClasses().isEmpty()){ ic = context.getAllInstrumentedClasses().iterator().next(); if(log.isDebugEnabled()) { log.debug("Instrument '{}' by [ {} ]", ic.getClassName(), getInstrumentedBy(ic.getAllInstrumentedBy())); } } return ic; }
@Override public HttpResponse send() { String url = buildRequestUrl(); try { newRequest(url); log.debug("Sending '{}' request to '{}'...", method, url); org.apache.http.HttpResponse rawResponse = rawClient.execute(request); ApacheHttpResponse response = new ApacheHttpResponse(client, this, rawResponse, true); if(log.isDebugEnabled()) { log.debug("Response result : [status={}, content-type='{}', content-length={}]", response.getStatus(), response.getContentType(), response.getContentLength()); } return response; } catch (Exception e) { throw new HttpException("Error send http request : " + e.getMessage(),e); } }
public void buildStatement(SqlContext context, Sql sql, SqlStatementBuilder stm, Params params, String text) throws IOException { if(log.isDebugEnabled()) { log.debug("Tag {} -> {}", toString(), text); } SqlParser parser = new SqlParser(new Lexer(text, Sql.ParseLevel.MORE), el); SqlWhereExpr expr = parser.whereExpr(); expr.buildStatement(context, sql, stm, params); } }
@Override public void destroyDynaApi(DynaApi api) { ApiConfig config = api.getConfig(); if(log.isDebugEnabled()) { log.debug("Routes before destroying api '{}': \n\n{}\n", api.getName(), routesPrinter.print(app.routes())); } config.getApiRoutes().forEach(ar -> { if(ar.isDynamic()) { app.routes().remove(ar.getRoute()); } }); if(log.isDebugEnabled()) { log.debug("Routes after destroying api '{}': \n\n{}\n", api.getName(), routesPrinter.print(app.routes())); } apis.remove(api); }
@Override public THttpResponse send() { String url = buildRequestUrl(); try { initRequest(url); log.debug("Sending '{}' request to '{}'...", method, url); OkTHttpResponse response = new OkTHttpResponse(this, httpClient.newCall(request.build()).execute()); if(log.isDebugEnabled()) { log.debug("Response result : [status={}, content-type='{}', content-length={}]", response.getStatus(), response.getContentType(), response.getContentLength()); MimeType contentType = response.getContentType(); if(null != contentType && ContentTypes.isText(contentType.getMediaType())) { log.debug("Content -> \n{}", Strings.abbreviate(response.getContent(), 200)); } } return response; } catch (Exception e) { throw new HttpException("Error send http request : " + e.getMessage(),e); } }
protected void loadProperties(ConfigContext context, AppResource... resources) { for(AppResource ar : resources){ try{ Resource resource = ar.getResource(); String resourceUrl = resource.getURL().toString(); if(log.isDebugEnabled()){ if(AppResources.isFrameworkAndCoreResource(resourceUrl)) { log.trace("Load properties : {}", LogUtils.getUrl(resource)); }else{ log.debug("Load properties : {}", LogUtils.getUrl(resource)); } } if(context.resources.contains(resourceUrl)){ throw new AppConfigException("Cycle importing detected of '" + resourceUrl + "', please check your config : " + resourceUrl); } context.resources.add(resourceUrl); context.setDefaultOverride(ar.isDefaultOverride()); for(AppPropertyReader reader : propertyReaders) { if(reader.readProperties(context, resource)) { break; } } context.resetDefaultOverride(); }catch(IOException e) { throw new AppConfigException("I/O Exception",e); } } }
@Override public void sendAsync(HttpHandler handler) { String url = buildRequestUrl(); try { newRequest(url); handler.beforeRequest(this); log.debug("Sending '{}' request to '{}'...", method, url); rawClient.execute(request, r -> { ApacheHttpResponse response = new ApacheHttpResponse(client, this, r, false); if (log.isDebugEnabled()) { log.debug("Handling response : [status={}, content-type='{}', content-length={}]", response.getStatus(), response.getContentType(), response.getContentLength()); } handler.afterResponse(this, response); return null; }); } catch (RequestAbortedException e) { handler.afterAborted(this); } catch (Exception e) { if(e instanceof RuntimeException) { throw (RuntimeException)e; } throw new HttpException(e.getMessage(),e); }finally{ release(); } }
public void load(AppResource[] resources) { Args.notNull(resources, "resources"); for (AppResource ar : resources) { Resource resource = ar.getResource(); if (log.isDebugEnabled()) { if (AppResources.isFrameworkAndCoreResource(resource.getURLString())) { log.trace("Load beans : {}", LogUtils.getUrl(resource)); } else { log.debug("Load beans : {}", LogUtils.getUrl(resource)); } } //todo : use AppResource's default override? readDefinitions(container, resource, ar.isDefaultOverride()); } }
@Override protected void buildStatement_(SqlContext context, Sql sql, SqlStatementBuilder stm, Params params) throws IOException { if(null != tagNode){ String s = tagNode.process(context, sql, params); if(Strings.isEmpty(s)) { if(log.isDebugEnabled()) { log.debug("Tag {} -> (empty)", tagNode.toString()); } return; } for(AstNode n : bodyNodes) { if(n == tagNode) { tagNode.buildStatement(context, sql, stm, params, s); }else{ n.buildStatement(context, sql, stm, params); } } }else{ if(!test(params)) { return; } for(AstNode n : bodyNodes) { n.buildStatement(context, sql, stm, params); } } }
@Override public THttpResponse send(){ String url = buildRequestUrl(); try { newRequest(url); log.debug("Sending '{}' request to '{}'...", method, url); ApacheTHttpResponse response = new ApacheTHttpResponse(this, request, httpClient.execute(request) ); if(log.isDebugEnabled()) { log.debug("Response result : [status={}, content-type='{}', content-length={}]", response.getStatus(), response.getContentType(), response.getContentLength()); MimeType contentType = response.getContentType(); if(null != contentType && ContentTypes.isText(contentType.toString())) { log.debug("Content -> \n{}", Strings.abbreviate(response.getContent(), 200)); } } return response; } catch (Exception e) { throw new HttpException("Error send http request : " + e.getMessage(),e); }finally{ if(null != request) { request.releaseConnection(); } } }
@Override public SqlStatement createQueryStatement(QueryContext context, Object p) { Params params = createParameters(context, p); DynamicSql.ExecutionSqls sqls = sql.resolveExecutionSqls(context, params); if(sqls.sql.isSelect()) { Limit limit = context.getLimit(); if (null != limit) { createSqlWithoutOrderBy(sqls); return createLimitQueryStatement(context, sqls, params); } if (!Strings.isEmpty(context.getOrderBy())) { createSqlWithoutOrderBy(sqls); return createOrderByQueryStatement(context, sqls, params); } } if(log.isDebugEnabled()) { log.debug("Creating query statement... \n\noriginal -> \n\n {}\n\nprocessed -> \n\n {}\n", sql, sqls.sql); } return doCreateStatement(context, sqls, params, true); }