Package fr.norsys.mapper.console.model

Examples of fr.norsys.mapper.console.model.Connection


    assertTrue(l.size() > 0);
  }
 
  public void test01AddModifyGetAndDelete() throws Exception {
    List connections = new ArrayList();
    Connection connection = new Connection();
    connection.setName("test5");
    connectionService.save(connection,connections);
    assertTrue("size must be superior to 0",connections.size() > 0);
    File f = new File(PROPERTIES_PATH+"test5.properties");
    assertTrue(f.exists());
   
    String id = "";
    for(Iterator it=connections.iterator();it.hasNext();) {
      Connection c = (Connection) it.next();
      if("test5".equals(c.getName()))
        id=c.getId();
    }
   
    Connection connection2 = new Connection("test6");
    connection2.setId(id);
    connectionService.save(connection2,connections);
    for(Iterator it=connections.iterator();it.hasNext();) {
      Connection c = (Connection) it.next();
      if(id.equals(c.getId())) {
        assertEquals("name must be equals to test6","test6",c.getName());
        break;
      }
    }
    f = new File(PROPERTIES_PATH+"test6.properties");
    assertTrue(f.exists());
   
    assertNotNull(connectionService.get(id,connections));
   
    Connection connection3 = new Connection("test6");
    connection3.setId(id);
    connectionService.delete(id,connections);

    for(Iterator it=connections.iterator();it.hasNext();) {
      Connection c = (Connection) it.next();
      if(id.equals(c.getId())) {
        fail();
      }
    }
    f = new File(PROPERTIES_PATH+"test6.properties");
    assertFalse(f.exists());
View Full Code Here


    try {
      map = propertyService.getProperty(connectionService.getConnectionsDirPath()+connectionName+".properties");
    } catch (PropertyException e) {
      log.error(e);
    }
    Connection connection = new Connection(connectionName);
    fr.norsys.mapper.console.utils.BeanUtils.toObject(map, connection);
    application.setConnection(connection);
  }
View Full Code Here

      {add(connection,connections);}
    else
      {modify(connection,connections);}
  }
  private void add(Connection connection, Collection connections) throws ConnectionException {
    Connection c = null;
    try {
      c = (Connection) BeanUtils.cloneBean(connection);
    } catch (Exception e) {
      throw new ConnectionException("Unable to clone bean "+c);
    }
    c.setId(UIDGenerator.generateId());
    connections.add(c);
    try {
      fileService.createNewFile(c.getName()+propFileExt,connectionsDirPath);
    } catch (FileException e) {
      throw new ConnectionException(e.toString());
    }
  }
View Full Code Here

    } catch (FileException e) {
      throw new ConnectionException(e.toString());
    }
  }
  private void modify(Connection conn, Collection connectionsthrows ConnectionException{
    Connection connection = conn;
    for (Iterator it = connections.iterator(); it.hasNext();) {
      Connection c = (Connection) it.next();
      if (connection.getId().equals(c.getId())) {
        if (!connection.getName().equals(c.getName())) {
          try {
            fileService.changeFileName(c.getName()+propFileExt, connection.getName()+propFileExt, connectionsDirPath);
          } catch (FileException e) {
            throw new ConnectionException(e.toString());
          }
        }
        fr.norsys.mapper.console.utils.BeanUtils.copyFilledProperties(
View Full Code Here

    }
  }

  public void delete(String id, Collection connectionsthrows ConnectionException{
    for (Iterator it = connections.iterator(); it.hasNext();) {
      Connection c = (Connection) it.next();
      if (c.getId().equals(id)) {
        connections.remove(c);
        try {
          fileService.deleteFile(c.getName()+".properties",connectionsDirPath);
        } catch (FileException e) {
          throw new ConnectionException(e.toString());
        }
        break;
      }
View Full Code Here

      }
    }
  }

  public Connection get(String id, Collection connections) throws ConnectionException {
    Connection result = null;
    for (Iterator it = connections.iterator(); it.hasNext();) {
      Connection c = (Connection) it.next();
      if (c.getId().equals(id)) {
        result = c;
        break;
      }
    }
    return result;
View Full Code Here

      connectionsNames = fileService.getFilesName(connectionsDirPath,propFileExt);
    } catch (FileException e) {
      throw new ConnectionException(e.toString());
    }
    Collection connections = new TreeSet(new ConnectionNameComparator());
    Connection c = null;
    for(Iterator i=connectionsNames.iterator();i.hasNext();){
      c = new Connection((String)i.next());
      connections.add(c);
    }
    return connections;
  }
View Full Code Here

TOP

Related Classes of fr.norsys.mapper.console.model.Connection

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.