Пример #1
0
  /* ------------------------------------------------------------------ */
  private boolean ensureDataSource() throws Exception {
    m_orb = (XMultiServiceFactory) param.getMSF();

    XNameAccess databaseContext =
        UnoRuntime.queryInterface(
            XNameAccess.class, m_orb.createInstance("com.sun.star.sdb.DatabaseContext"));
    XNamingService namingService = UnoRuntime.queryInterface(XNamingService.class, databaseContext);

    // revoke the data source, if it previously existed
    if (databaseContext.hasByName(m_dataSourceName)) namingService.revokeObject(m_dataSourceName);

    // // create a new ODB file, and register it with its URL
    m_databaseDocument = new HsqlDatabase(m_orb);
    String documentURL = m_databaseDocument.getDocumentURL();
    namingService.registerObject(m_dataSourceName, databaseContext.getByName(documentURL));

    m_dataSource =
        UnoRuntime.queryInterface(XDataSource.class, databaseContext.getByName(m_dataSourceName));
    m_dataSourceProps = dbfTools.queryPropertySet(m_dataSource);

    XPropertySet dataSourceSettings =
        UnoRuntime.queryInterface(
            XPropertySet.class, m_dataSourceProps.getPropertyValue("Settings"));
    dataSourceSettings.setPropertyValue("FormsCheckRequiredFields", new Boolean(false));

    return m_dataSource != null;
  }
Пример #2
0
  /** executes the given statement on the given connection */
  protected boolean implExecuteStatement(String sStatement) throws java.lang.Exception {
    try {
      m_databaseDocument.executeSQL(sStatement);
    } catch (com.sun.star.sdbc.SQLException e) {
      System.err.println(e);
      return false;
    }

    return true;
  }