Example #1
0
 /**
  * Adds or modifies the home.
  *
  * @param home
  */
 public void changeHome(Warp home) {
   if (dataSource.getHome(home.Name) == null) {
     dataSource.addHome(home);
   } else {
     dataSource.changeHome(home);
   }
 }
Example #2
0
 /**
  * Adds or modifies the warp
  *
  * @param warp
  */
 public void setWarp(Warp warp) {
   if (dataSource.getWarp(warp.Name) == null) {
     dataSource.addWarp(warp);
   } else {
     dataSource.changeWarp(warp);
   }
 }
Example #3
0
  public static void main(String[] argv) {
    try {

      String dmds_name = null;
      String cpds_name = null;
      String pbds_name = null;

      if (argv.length == 3) {
        dmds_name = argv[0];
        cpds_name = argv[1];
        pbds_name = argv[2];
      } else usage();

      InitialContext ctx = new InitialContext();
      DataSource dmds = (DataSource) ctx.lookup(dmds_name);
      dmds.getConnection().close();
      System.out.println(
          "DriverManagerDataSource " + dmds_name + " sucessfully looked up and checked.");
      ConnectionPoolDataSource cpds = (ConnectionPoolDataSource) ctx.lookup(cpds_name);
      cpds.getPooledConnection().close();
      System.out.println(
          "ConnectionPoolDataSource " + cpds_name + " sucessfully looked up and checked.");
      DataSource pbds = (DataSource) ctx.lookup(pbds_name);
      pbds.getConnection().close();
      System.out.println(
          "PoolBackedDataSource " + pbds_name + " sucessfully looked up and checked.");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public static void runTest3() throws Exception {
   boolean exceptionOccured = false;
   try {
     Context ctx = cache.getJNDIContext();
     DataSource ds1 = null;
     DataSource ds2 = null;
     ds1 = (DataSource) ctx.lookup("java:/XAPooledDataSource");
     ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
     ds2.getConnection();
     UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
     utx.begin();
     utx.setTransactionTimeout(2);
     ds1.getConnection();
     Thread.sleep(4000);
     try {
       utx.commit();
     } catch (Exception e) {
       exceptionOccured = true;
     }
     if (!exceptionOccured)
       fail("Exception (Transaction-Time-Out)did not occur although was supposed" + "to occur");
   } catch (Exception e) {
     fail("failed in runTest3 due to " + e);
   }
 }
Example #5
0
 SnapshotDao(DataSource dataSource, RollingFile rollingFile) throws SQLException {
   this.dataSource = dataSource;
   this.rollingFile = rollingFile;
   upgradeSnapshotTable(dataSource);
   dataSource.syncTable("snapshot", columns);
   dataSource.syncIndexes("snapshot", indexes);
 }
 public void parse(DataSource dataSource, ByteBuffer header, long contentSize, BoxParser boxParser)
     throws IOException {
   this.offset = dataSource.position() - header.remaining();
   this.dataSource = dataSource;
   this.size = contentSize + header.remaining();
   dataSource.position(dataSource.position() + contentSize);
 }
  private void printGroupDataSourceList(PrintWriter out, Group group) {
    DataSource ds = null;
    String dsname = null;
    String dstype = null;
    String label = null;
    out.println("<table >");
    out.println(" <caption>" + group.getGroupName() + " combination</caption>");
    out.println("<tr><th> virtual sensor name </th>");
    out.println("<th> access right</th></tr>");

    for (int j = 0; j < group.getDataSourceList().size(); j++) {
      ds = (DataSource) group.getDataSourceList().get(j);
      dsname = ds.getDataSourceName();
      dstype = ds.getDataSourceType();

      if (dstype.charAt(0) == '1') {
        label = "read";
      } else if (dstype.charAt(0) == '2') {
        label = "write";
      } else if (dstype.charAt(0) == '3') {
        label = "read/write";
      }
      out.println("<tr><td>" + dsname + "</td>");
      out.println("<td>" + label + "</td></tr>");
    }
    out.println("</table>");
  }
Example #8
0
  private void removeReceiveStream(ReceiveStreamDesc receiveStream, boolean emptyJB) {
    if (receiveStream.format instanceof VideoFormat) {
      rtpConnector.packetBuffer.disable(receiveStream.ssrc);
      emptyPacketBuffer(receiveStream.ssrc);
    }

    if (receiveStream.dataSink != null) {
      try {
        receiveStream.dataSink.stop();
      } catch (IOException e) {
        logger.error("Failed to stop DataSink " + e);
      }

      receiveStream.dataSink.close();
    }

    if (receiveStream.processor != null) {
      receiveStream.processor.stop();
      receiveStream.processor.close();
    }

    DataSource dataSource = receiveStream.receiveStream.getDataSource();
    if (dataSource != null) {
      try {
        dataSource.stop();
      } catch (IOException ioe) {
        logger.warn("Failed to stop DataSource");
      }
      dataSource.disconnect();
    }

    synchronized (receiveStreams) {
      receiveStreams.remove(receiveStream);
    }
  }
 public static void runTest1() throws Exception {
   boolean exceptionOccured = false;
   try {
     Context ctx = cache.getJNDIContext();
     DataSource ds1 = null;
     DataSource ds2 = null;
     ds1 = (DataSource) ctx.lookup("java:/XAPooledDataSource");
     ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
     ds2.getConnection();
     ds1 = (DataSource) ctx.lookup("java:/XAPooledDataSource");
     UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
     utx.begin();
     ds1.getConnection();
     Thread.sleep(8000);
     try {
       utx.commit();
     } catch (Exception e) {
       exceptionOccured = true;
     }
     if (!exceptionOccured)
       fail("Exception did not occur on commit although was supposed" + "occur");
   } catch (Exception e) {
     getLogWriter().fine("Exception caught in runTest1 due to : " + e);
     fail("failed in runTest1 due to " + e);
   }
 }
 @Override
 public DataSource removeDataSource(String dataSourceName) {
   DataSource dataSource = dataSources_.remove(dataSourceName);
   if (dataSource != null) {
     dataSource.setCatalogVersion(incrementAndGetCatalogVersion());
   }
   return dataSource;
 }
Example #11
0
 @Test
 public void testSQLSources() throws Exception {
   sm.register("testH", super.getAnyNonSpatialResource());
   sm.register("sql", "select * from testH;");
   DataSource ds = dsf.getDataSource("sql");
   assertEquals((ds.getSource().getType() & SourceManager.SQL), SourceManager.SQL);
   assertFalse(ds.isEditable());
 }
Example #12
0
 @Test
 public void testChangeNameOnExistingDataSources() throws Exception {
   sm.register("file", super.getAnyNonSpatialResource());
   DataSource ds = dsf.getDataSourceFromSQL("select * from file;");
   sm.rename(ds.getName(), "sql");
   DataSource ds2 = dsf.getDataSource("sql");
   assertEquals(ds.getName(), ds2.getName());
 }
 private static String createId(DataSource datasource) {
   if (datasource instanceof DataSourcePro) return ((DataSourceSupport) datasource).id();
   return datasource.getClazz().getName()
       + ":"
       + datasource.getDsnTranslated()
       + ":"
       + datasource.getClazz().getName();
 }
  //
  // Find all the objects inside the DataSource and vet them.
  //
  private void vetDataSource(HashSet<String> unsupportedList, HashSet<String> notUnderstoodList)
      throws Exception {
    DataSource ds = JDBCDataSource.getDataSource();
    Connection conn = ds.getConnection();

    vetObject(ds, unsupportedList, notUnderstoodList);

    connectionWorkhorse(conn, unsupportedList, notUnderstoodList);
  }
Example #15
0
  /**
   * Retrieves this DataProvider's DataSource with identifier dataSourceId if this DataProvider
   * contains the DataSource with dataSourceId or null otherwise
   *
   * @param dataSourceId
   * @return DataSource with id dataSourceId or null otherwise
   */
  public DataSource getDataSource(String dataSourceId) {
    for (DataSource dataSource : dataSources) {
      if (dataSource.getId().equals(dataSourceId)) {
        return dataSource;
      }
    }

    return null;
  }
 public void parseContainer(DataSource dataSource, long containerSize, BoxParser boxParser)
     throws IOException {
   this.dataSource = dataSource;
   this.parsePosition = dataSource.position();
   this.startPosition =
       parsePosition - (((largeBox || (containerSize + 8) >= (1L << 32)) ? 16 : 8));
   dataSource.position(dataSource.position() + containerSize);
   this.endPosition = dataSource.position();
   this.boxParser = boxParser;
 }
Example #17
0
  @Test
  public void testNameAndID() {
    Map<String, Object> raw = new HashMap<String, Object>();
    raw.put("id", "abcdef");
    raw.put("name", "MyDS");

    DataSource dataSource = new DataSource(raw, mock(ApiClient.class));

    assertEquals(dataSource.getId(), raw.get("id"));
    assertEquals(dataSource.getName(), raw.get("name"));
  }
  /**
   * Return the DataFlavors for this <code>DataContentHandler</code>.
   *
   * @return the DataFlavors
   */
  public DataFlavor[] getTransferDataFlavors() {

    if (transferFlavors == null) {
      if (dch != null) { // is there a dch?
        transferFlavors = dch.getTransferDataFlavors();
      } else {
        transferFlavors = new DataFlavor[1];
        transferFlavors[0] = new ActivationDataFlavor(ds.getContentType(), ds.getContentType());
      }
    }
    return transferFlavors;
  }
  public Connection getConnection() throws Exception {
    InitialContext ctx = null;
    ctx = new InitialContext();

    if (getDataSourceJndiName() == null)
      throw (new Exception("Data Source JNDI name is null. Check whether the JNDI name is null."));

    DataSource ds = (javax.sql.DataSource) ctx.lookup(getDataSourceJndiName());
    Connection conn = ds.getConnection();

    return conn;
  }
Example #20
0
 private static void upgradeSnapshotTable(DataSource dataSource) throws SQLException {
   if (!dataSource.tableExists("snapshot")) {
     return;
   }
   // 'headline' column renamed to 'grouping'
   for (Column column : dataSource.getColumns("snapshot")) {
     if (column.getName().equals("headline")) {
       dataSource.execute("alter table snapshot alter column headline rename to" + " grouping");
       break;
     }
   }
 }
 private Connection getConnection() throws SQLException {
   DataSource dataSource = null;
   try {
     dataSource = DataSource.getInstance();
   } catch (IOException e) {
     LOG.error("IOException : " + e);
   } catch (SQLException e) {
     LOG.error("SQLException : " + e);
   } catch (PropertyVetoException e) {
     LOG.error("PropertyVetoException : " + e);
   }
   return dataSource.getConnection();
 }
Example #22
0
  public void saveStreams() throws IOException {
    Config config = Config.getConfiguration("manager.streams");

    config.setArray("streams", streams.toArray());

    Iterator it = streams.iterator();
    while (it.hasNext()) {
      DataSource ds = (DataSource) it.next();
      ds.save();
    }

    config.save();
  }
Example #23
0
  @Test
  public void testRemoveDataSources() throws Exception {
    sm.register("temp", super.getAnyNonSpatialResource());

    DataSource d = dsf.getDataSource("temp");
    sm.remove(d.getName());

    try {
      dsf.getDataSource("temp");
      fail();
    } catch (NoSuchTableException e) {
    }
  }
Example #24
0
 @Test
 public void toJson() throws Exception {
   List<Student> ls = new ArrayList<>(data.StudentRepo().values());
   InputMeta testObj = new InputMeta(ls, data.ProjectRepo());
   String expected = testObj.getHottestProject();
   String allRaw = testObj.toJson();
   assertTrue(allRaw.contains("hottestProject"));
   String head = "\"hottestProject\": \"";
   int strBegin = allRaw.indexOf(head) + head.length();
   int strEnd = strBegin + expected.length();
   String got = allRaw.substring(strBegin, strEnd);
   assertTrue(expected.equals(got));
 }
 private void printRemainingDataSourcesList(PrintWriter out, User user, ConnectToDB ctdb)
     throws SQLException {
   DataSource dataSource = null;
   String dataSourceName = null;
   Vector remainingDataSourcesList =
       ctdb.getDataSourceListsDifference(
           this.dataSourceVectorForDataSourceNames(
               ctdb.getValuesVectorForOneColumnUnderOneCondition(
                   new Column("DATASOURCENAME"), new Column("ISCANDIDATE", "no"), "ACDATASOURCE")),
           user.getDataSourceList());
   if (remainingDataSourcesList.size() == 0) {
     out.println("<table class=transparenttable>");
     out.println("<tr><td><FONT COLOR=#000000>No virtaul sensor is available.</td></tr>");
     out.println("</table>");
   } else {
     out.println("<table>");
     out.println("<tr><th> virtual sensor name </th>");
     out.println("<th> access right</th></tr>");
     for (int i = 0; i < remainingDataSourcesList.size(); i++) {
       dataSource = (DataSource) (remainingDataSourcesList.get(i));
       dataSourceName = dataSource.getDataSourceName();
       if (ctdb.valueExistsForThisColumnUnderTwoConditions(
           new Column("ISUSERWAITING", "yes"),
           new Column("USERNAME", user.getUserName()),
           new Column("DATASOURCENAME", dataSource.getDataSourceName()),
           "ACUSER_ACDATASOURCE")) {
         out.println("<tr><td>" + dataSourceName + " </td>");
       } else {
         out.println("<FORM ACTION=/gsn/MyUpdateUserWaitingForDataSourceServlet METHOD=POST>");
         out.println("<tr><td>" + dataSourceName + " </td>");
         out.println("<td><INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 1> read ");
         out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE= 2> write ");
         out.println("<INPUT TYPE=RADIO NAME=" + dataSourceName + " VALUE=3> read/write ");
       }
       if (ctdb.valueExistsForThisColumnUnderTwoConditions(
           new Column("ISUSERWAITING", "yes"),
           new Column("USERNAME", user.getUserName()),
           new Column("DATASOURCENAME", dataSource.getDataSourceName()),
           "ACUSER_ACDATASOURCE")) {
         out.println("<td>" + "<FONT COLOR=#0000FF>in updates waiting list!</td></tr>");
       } else {
         out.println(
             "&nbsp&nbsp&nbsp<INPUT TYPE=SUBMIT TYPE=SUBMIT class= buttonstyle VALUE=\"add\"></td></tr>");
         out.println("</FORM>");
       }
     }
     out.println("</table>");
   }
 }
 public void parse(DataSource dataSource, ByteBuffer header, long contentSize, BoxParser boxParser)
     throws IOException {
   this.offset = dataSource.position() - header.remaining();
   this.largeBox =
       header.remaining() == 16; // sometime people use large boxes without requiring them
   parseContainer(dataSource, contentSize, boxParser);
 }
Example #27
0
  @Override
  public void deleteDataSource(final DataSource dataSource, final AsyncCallback<Boolean> callback) {

    AddressBinding address = dsMetaData.getAddress();
    ModelNode addressModel = address.asResource(baseadress.getAdress(), dataSource.getName());

    ModelNode operation = dataSourceAdapter.fromEntity(dataSource);
    operation.get(OP).set(REMOVE);
    operation.get(ADDRESS).set(addressModel.get(ADDRESS));

    dispatcher.execute(
        new DMRAction(operation),
        new SimpleCallback<DMRResponse>() {

          @Override
          public void onFailure(Throwable caught) {
            callback.onFailure(caught);
          }

          @Override
          public void onSuccess(DMRResponse result) {
            boolean wasSuccessful = responseIndicatesSuccess(result);
            callback.onSuccess(wasSuccessful);
          }
        });
  }
Example #28
0
  @Override
  public void createDataSource(
      final DataSource datasource, final AsyncCallback<ResponseWrapper<Boolean>> callback) {

    AddressBinding address = dsMetaData.getAddress();
    ModelNode addressModel = address.asResource(baseadress.getAdress(), datasource.getName());

    ModelNode operation = dataSourceAdapter.fromEntity(datasource);
    operation.get(OP).set(ADD);
    operation.get(ADDRESS).set(addressModel.get(ADDRESS));

    dispatcher.execute(
        new DMRAction(operation),
        new SimpleCallback<DMRResponse>() {

          @Override
          public void onFailure(Throwable caught) {
            callback.onFailure(caught);
          }

          @Override
          public void onSuccess(DMRResponse result) {
            ModelNode modelNode = result.get();
            boolean wasSuccessful = modelNode.get(OUTCOME).asString().equals(SUCCESS);

            callback.onSuccess(new ResponseWrapper<Boolean>(wasSuccessful, modelNode));
          }
        });
  }
Example #29
0
  public static UserLoginResponse userLogIn(final UserLoginRequest userInfo)
      throws SQLException, IOException, PropertyVetoException, ClassNotFoundException {
    final String query = Query.SELECT_USER_DETAILS.toString();
    final Connection conn = DataSource.getInstance().getConnection();
    final PreparedStatement stmt = conn.prepareStatement(query);
    stmt.setString(1, userInfo.getUserId());

    ResultSet rs = stmt.executeQuery();
    if (!rs.next()) {
      conn.close();
      throw new SQLException("User ID " + userInfo.getUserId() + " does not exist.");
    } else {
      if (!rs.getString("password").equals(userInfo.getPassword())) {
        conn.close();
        throw new SQLException("Authentication problem.");
      }
      UserLoginResponse resp =
          new UserLoginResponse(
              "200",
              "Login Success.",
              userInfo.getUserId(),
              rs.getString("name"),
              rs.getString("password"),
              rs.getString("clickDelayInSeconds"),
              rs.getString("uploadIntervalInSeconds"));
      conn.close();
      return resp;
    }
  }
 /** Return the content. */
 public Object getContent(DataSource ds) throws IOException {
   // create a new DeliveryStatus
   try {
     /*
        Session session;
        if (ds instanceof MessageAware) {
     javax.mail.MessageContext mc =
     	((MessageAware)ds).getMessageContext();
     session = mc.getSession();
        } else {
     // Hopefully a rare case.  Also hopefully the application
     // has created a default Session that can just be returned
     // here.  If not, the one we create here is better than
     // nothing, but overall not a really good answer.
     session = Session.getDefaultInstance(new Properties(), null);
        }
        return new DeliveryStatus(session, ds.getInputStream());
        */
     return new DeliveryStatus(ds.getInputStream());
   } catch (MessagingException me) {
     throw new IOException(
         "Exception creating DeliveryStatus in "
             + "message/delivery-status DataContentHandler: "
             + me.toString());
   }
 }