Package net.sf.isolation.logging

Examples of net.sf.isolation.logging.IsoLog


    return methods;
  }

  protected Constructor<?> getConstructor(Class<?> klass,
      Class<?>[] parameterTypes) {
    IsoLog log = context.getLog();
    Map<IsoMethodNode, Constructor<?>> constructors;
    synchronized (this.constructor) {
      constructors = this.constructor.get(klass);
    }
    if (constructors == null) {
      synchronized (this.constructor) {
        constructors = this.constructor.get(klass);
        if (constructors == null) {
          constructors = new WeakHashMap<IsoMethodNode, Constructor<?>>();
          log.trace("Creating cache for: {0}", klass);
          this.constructor.put(klass, constructors);
        }
      }
    }
    IsoMethodNode methodNode = new IsoMethodNode(null, parameterTypes);
    Constructor<?> constructor;
    synchronized (constructors) {
      constructor = constructors.get(methodNode);
    }
    if (constructor == null) {
      synchronized (constructors) {
        constructor = constructors.get(methodNode);
        if (constructor == null) {
          constructor = super.getConstructor(klass, parameterTypes);
          log.trace("Cache of constructor for: {1}", klass);
          constructors.put(methodNode, constructor);
        }
      }
    }
    return constructor;
View Full Code Here


    constructor = new WeakHashMap<Class<?>, Map<IsoMethodNode, Constructor<?>>>();
  }

  protected Method getMethod(Class<?> klass, String methodName,
      Class<?>[] parameterTypes) {
    IsoLog log = context.getLog();
    Map<IsoMethodNode, Method> methods = this.method.get(klass);
    if (methods == null) {
      methods = new WeakHashMap<IsoMethodNode, Method>();
      log.trace("Creating cache for: {0}", klass);
      this.method.put(klass, methods);
    }
    IsoMethodNode methodNode = new IsoMethodNode(methodName, parameterTypes);
    Method method = methods.get(methodNode);
    if (method == null) {
      method = super.getMethod(klass, methodName, parameterTypes);
      log.trace("Cache of {0} for: {1}", method, klass);
      methods.put(methodNode, method);
    }
    return method;
  }
View Full Code Here

    return methods;
  }

  protected Constructor<?> getConstructor(Class<?> klass,
      Class<?>[] parameterTypes) {
    IsoLog log = context.getLog();
    Map<IsoMethodNode, Constructor<?>> constructors = this.constructor
        .get(klass);
    if (constructors == null) {
      constructors = new WeakHashMap<IsoMethodNode, Constructor<?>>();
      log.trace("Creating cache for: {0}", klass);
      this.constructor.put(klass, constructors);
    }
    IsoMethodNode methodNode = new IsoMethodNode(null, parameterTypes);
    Constructor<?> constructor = constructors.get(methodNode);
    if (constructor == null) {
      constructor = super.getConstructor(klass, parameterTypes);
      log.trace("Cache of constructor for: {1}", klass);
      constructors.put(methodNode, constructor);
    }
    return constructor;
  }
View Full Code Here

  public IsoBeanCopierSpi(IsoContext context) {
    this.context = context;
  }

  public void copy(final Object sourceBean, final Object targetBean) {
    final IsoLog log = context.getLog();
    final IsoBeanPropertyManager propertyManager = context
        .getBeanPropertyManager();
    propertyManager.invoke(targetBean, new IsoSetterCallback() {
      private Object value;

      public boolean execute(String propertyName, Class<?> type) {
        try {
          Object value = propertyManager.getProperty(sourceBean,
              propertyName);
          try {
            this.value = context.getConversionManager().convert(
                type, value);
            return true;
          } catch (IsoConversionException exception) {
            log.debug(exception, propertyName);
          }
        } catch (IllegalStateException exception) {
          log.debug(exception, propertyName);
          if (exception.getCause().getClass() != NoSuchMethodException.class) {
            throw exception;
          }
        }
        return false;
View Full Code Here

    return execute(name, m);
  }

  public Map<String, Object> execute(String name,
      Map<String, Object> parameters) {
    IsoLog log = context.getLog();
    assert name != null : "name is null";
    assert name.length() > 0 : "name is \"\"";
    log.debug("Execute: {0}", name);
    IsoSPExpression sp = sps.get(name);
    if (sp == null) {
      throw new NoSuchElementException(name);
    }
    Connection connection = getConnection();
    try {
      String sql = sp.getSql();
      if (sql == null) {
        throw new IllegalStateException("sql is null");
      }
      log.debug("Sql: {0}", sql);
      CallableStatement statement = connection.prepareCall(sql);
      IsoSPExpressionParameterInformation[] parametersInformation = sp
          .getParametersInformation();
      if (parametersInformation != null
          && parametersInformation.length > 0 && parameters != null) {
        for (IsoSPExpressionParameterInformation parameterInformation : parametersInformation) {
          log.trace(parameterInformation);
          statement.setObject(parameterInformation.getIndex(),
              parameters.get(parameterInformation.getName()));
        }
      }
      try {
View Full Code Here

      }
    }
  }

  public Map<String, Object> execute(String name, Object bean) {
    IsoLog log = context.getLog();
    assert name != null : "name is null";
    assert name.length() > 0 : "name is \"\"";
    log.debug("Execute: {0}", name);
    IsoSPExpression sp = sps.get(name);
    if (sp == null) {
      throw new NoSuchElementException(name);
    }
    Connection connection = getConnection();
    try {
      String sql = sp.getSql();
      if (sql == null) {
        throw new IllegalStateException("sql is null");
      }
      log.debug("Sql: {0}", sql);
      CallableStatement statement = connection.prepareCall(sql);
      IsoSPExpressionParameterInformation[] parametersInformation = sp
          .getParametersInformation();
      if (parametersInformation != null
          && parametersInformation.length > 0 && bean != null) {
        IsoBeanPropertyManager propertyManager = context
            .getBeanPropertyManager();
        for (IsoSPExpressionParameterInformation parameterInformation : parametersInformation) {
          log.trace(parameterInformation);
          statement.setObject(parameterInformation.getIndex(),
              propertyManager.getProperty(bean,
                  parameterInformation.getName()));
        }
      }
View Full Code Here

    }
  }

  public Object convert(Class<?> sourceType, Class<?> targetType, Object value)
      throws IsoConversionException {
    IsoLog log = context.getLog();
    Map<Class<?>, IsoConverter> convertersBySourceTypes = convertersByTargetTypes
        .get(targetType);
    if (convertersBySourceTypes == null) {
      log.warn("(Step 1) Not Configured {0} -> ${1}", sourceType
          .getName(), targetType.getName());
      throw new IsoConversionNotSupportedException(sourceType.getName()
          + "->" + targetType.getName());
    }
    IsoConverter converter = convertersBySourceTypes.get(sourceType);
    if (converter == null) {
      log.warn("(Step 2) Not Configured {0} -> ${1}", sourceType
          .getName(), targetType.getName());
      throw new IsoConversionNotSupportedException(sourceType.getName()
          + "->" + targetType.getName());
    } else {
      return converter.convert(targetType, value);
View Full Code Here

  }

  public <T> T handle(ResultSet resultSet, Class<T> resultType)
      throws SQLException {
    if (resultType == List.class) {
      IsoLog log = context.getInstance(IsoLog.class);
      IsoReflectionManager reflectionManager = context
          .getInstance(IsoReflectionManager.class);
      IsoBeanPropertyManager propertyManager = context
          .getInstance(IsoBeanPropertyManager.class);
      IsoColumnTypeConverter columnTypeConverter = context
          .getInstance(IsoColumnTypeConverter.class);
      log.debug("Processing: {0}", klass);
      List<Object> list = new ArrayList<Object>();
      ResultSetMetaData metaData = resultSet.getMetaData();
      int columnCount = metaData.getColumnCount();
      String[] columnNames = new String[columnCount];
      for (int i = 0; i < columnCount; i++) {
        String columnName = metaData.getColumnName(i + 1);
        columnNames[i] = columnName;
        log.trace("Catch of column: {0}", columnName);
      }
      while (resultSet.next()) {
        Object bean = reflectionManager.newInstance(klass);
        for (int i = 0; i < columnCount; i++) {
          String columnName = columnNames[i];
          IsoSQLResultSetProcessorColumnInfo columnInfo = columnsInfo
              .get(columnName);
          Object value;
          Class<?> type;
          switch (columnTypeConverter.getColumnType(columnInfo
              .getType())) {
          case FLOAT:
            value = Float.valueOf(resultSet.getFloat(i + 1));
            type = Float.class;
            break;
          case DOUBLE:
            value = Double.valueOf(resultSet.getDouble(i + 1));
            type = Double.class;
            break;
          case STRING:
            value = resultSet.getString(i + 1);
            type = String.class;
            break;
          case INTEGER:
            value = Integer.valueOf(resultSet.getInt(i + 1));
            type = Integer.class;
            break;
          case LONG:
            value = Long.valueOf(resultSet.getLong(i + 1));
            type = Long.class;
            break;
          case DATE:
            value = resultSet.getDate(i + 1);
            type = Date.class;
            break;
          default:
            continue;
          }
          propertyManager.setProperty(bean, type,
              columnInfo.getName(), value);
        }
        list.add(bean);
      }
      log.debug("List size: {0}", Integer.valueOf(list.size()));
      @SuppressWarnings("unchecked")
      T resultList = (T) list;
      return resultList;
    } else {
      throw new IllegalArgumentException(resultType.getName());
View Full Code Here

  }

  public <T> T handle(Connection connection, Class<T> resultType,
      String query, List<IsoSQLParameter> parameters, Object data)
      throws SQLException {
    IsoLog log = context.getInstance(IsoLog.class);
    log.debug(query);
    PreparedStatement statement = connection.prepareStatement(query);
    try {
      context.getInstance(IsoPreparedStatementParameterSetter.class)
          .setParameters(statement, parameters, data);
      ResultSet resultSet = statement.executeQuery();
      try {
        return context.getInstance(IsoResultSetHandler.class).handle(
            resultSet, resultType);
      } finally {
        try {
          resultSet.close();
        } catch (SQLException exception) {
          log.error(exception);
        }
      }
    } finally {
      try {
        statement.close();
      } catch (SQLException exception) {
        log.error(exception);
      }
    }
  }
View Full Code Here

    this.context = context;
  }

  public <T> T execute(Class<T> resultType, String query,
      List<IsoSQLParameter> parameters, Object data) {
    IsoLog log = context.getInstance(IsoLog.class);
    Connection connection = context.getInstance(IsoDataSource.class)
        .getConnection();
    try {
      return context.getInstance(IsoConnectionHandler.class).handle(
          connection, resultType, query, parameters, data);
    } catch (SQLException e) {
      throw new IsoSQLException(e);
    } finally {
      try {
        connection.close();
      } catch (SQLException e) {
        log.warn(e);
      }
    }
  }
View Full Code Here

TOP

Related Classes of net.sf.isolation.logging.IsoLog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.