Package net.sf.isolation.logging

Examples of net.sf.isolation.logging.IsoLog


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

  public void copy(final Object sourceBean, final Object targetBean) {
    final IsoLog log = context.getInstance(IsoLog.class);
    final IsoBeanPropertyManager propertyManager = context
        .getInstance(IsoBeanPropertyManager.class);
    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.getInstance(
                IsoConversionManager.class)
                .convert(value, type);
            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


    }
  }

  public <T> T convert(Class<?> sourceType, Object value, Class<T> targetType)
      throws IsoConversionException {
    IsoLog log = context.getInstance(IsoLog.class);
    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

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

  protected Method getMethod(Class<?> klass, String methodName,
      Class<?>[] parameterTypes) {
    IsoLog log = context.getInstance(IsoLog.class);
    Map<IsoMethodNode, Method> methods;
    synchronized (this.method) {
      methods = this.method.get(klass);
    }
    if (methods == null) {
      synchronized (this.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;
    synchronized (methods) {
      method = methods.get(methodNode);
    }
    if (method == null) {
      synchronized (methods) {
        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.getInstance(IsoLog.class);
    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.getInstance(IsoLog.class);
    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.getInstance(IsoLog.class);
    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

    this.columnsInfo = columnsInfo;
    this.columnTypeConverter = columnTypeConverter;
  }

  public Object process(ResultSet resultSet) throws SQLException {
    IsoLog log = context.getLog();
    IsoReflectionManager reflectionManager = context.getReflectionManager();
    IsoBeanPropertyManager propertyManager = context
        .getBeanPropertyManager();
    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()));
    return list;
  }
View Full Code Here

    Map<String, Object> m = Collections.emptyMap();
    return execute(name, m);
  }

  public 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);
    IsoSQLExpression query = queries.get(name);
    if (query == null) {
      throw new NoSuchElementException(name);
    }
    Connection connection = getConnection();
    try {
      String sql = query.getSql();
      if (sql == null) {
        throw new IllegalStateException("sql is null");
      }
      log.debug("Sql: {0}", sql);
      PreparedStatement statement = connection.prepareStatement(sql);
      IsoSQLExpressionParameterInformation[] parametersInformation = query
          .getParametersInformation();
      if (parametersInformation != null
          && parametersInformation.length > 0 && parameters != null) {
        for (IsoSQLExpressionParameterInformation parameterInformation : parametersInformation) {
          log.trace(parameterInformation);
          statement.setObject(parameterInformation.getIndex(),
              parameters.get(parameterInformation.getName()));
        }
      }
      try {
View Full Code Here

      }
    }
  }

  public 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);
    IsoSQLExpression query = queries.get(name);
    if (query == null) {
      throw new NoSuchElementException(name);
    }
    Connection connection = getConnection();
    try {
      String sql = query.getSql();
      if (sql == null) {
        throw new IllegalStateException("sql is null");
      }
      log.debug("Sql: {0}", sql);
      PreparedStatement statement = connection.prepareStatement(sql);
      IsoSQLExpressionParameterInformation[] parametersInformation = query
          .getParametersInformation();
      if (parametersInformation != null
          && parametersInformation.length > 0 && bean != null) {
        IsoBeanPropertyManager propertyManager = context
            .getBeanPropertyManager();
        for (IsoSQLExpressionParameterInformation parameterInformation : parametersInformation) {
          log.trace(parameterInformation);
          statement.setObject(parameterInformation.getIndex(),
              propertyManager.getProperty(bean,
                  parameterInformation.getName()));
        }
      }
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;
    synchronized (this.method) {
      methods = this.method.get(klass);
    }
    if (methods == null) {
      synchronized (this.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;
    synchronized (methods) {
      method = methods.get(methodNode);
    }
    if (method == null) {
      synchronized (methods) {
        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

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.