Пример #1
0
 /**
  * Load an interprocedural property database.
  *
  * @param <DatabaseType> actual type of the database
  * @param <KeyType> type of key (e.g., method or field)
  * @param <Property> type of properties stored in the database
  * @param database the empty database object
  * @param resourceName name of resource to load the database from
  * @param description description of the database (for diagnostics)
  * @return the database object, or null if the database couldn't be loaded
  */
 public <
         DatabaseType extends PropertyDatabase<KeyType, Property>,
         KeyType extends FieldOrMethodDescriptor,
         Property>
     DatabaseType loadPropertyDatabaseFromResource(
         DatabaseType database, String resourceName, String description) {
   try {
     if (DEBUG) {
       System.out.println(
           "Loading default "
               + description
               + " from "
               + resourceName
               + " @ "
               + database.getClass().getResource(resourceName)
               + " ... ");
     }
     try (InputStream in = database.getClass().getResourceAsStream(resourceName)) {
       if (in == null) {
         AnalysisContext.logError(
             "Unable to load " + description + " from resource " + resourceName);
       } else {
         database.read(in);
       }
     }
     return database;
   } catch (IOException e) {
     getLookupFailureCallback().logError("Error loading " + description, e);
   } catch (PropertyDatabaseFormatException e) {
     getLookupFailureCallback().logError("Invalid " + description, e);
   }
   return null;
 }
Пример #2
0
 public PLSQLargument(String name, int index, int direction, DatabaseType databaseType) {
   this.name = name;
   this.index = index;
   this.direction = direction;
   if (!databaseType.isComplexDatabaseType() && databaseType.isJDBCType()) {
     databaseTypeWrapper = new JDBCTypeWrapper(databaseType);
   } else if (!databaseType.isComplexDatabaseType() && !databaseType.isJDBCType()) {
     databaseTypeWrapper = new SimplePLSQLTypeWrapper(databaseType);
   } else if (databaseType.isComplexDatabaseType()) {
     databaseTypeWrapper = new ComplexPLSQLTypeWrapper(databaseType);
   }
 }
  /**
   * 初始化JDBCProxy回放脚本的Stub数据库连接
   *
   * @param dataSource
   */
  protected void initStubProxyDataSource(BasicDataSource dataSource) {
    log.info(
        "Creating data source. Driver: "
            + type.getDriveClass()
            + ", url: "
            + type.getConnUrl()
            + ", user: "******", password: <not shown>");

    dataSource.setDriverClassName("org.jtester.jdbcproxy.driver.FileStubTracerDriver");
    dataSource.setUsername(type.getUserName());
    dataSource.setPassword(type.getUserPass());
    String url = "jdbc:stub:output/mergerfile.xml"; // TODO
    dataSource.setUrl(url);
  }
Пример #4
0
  private List<String> loadSqlDataFile(
      ServletContext servletContext, Dbms dbms, String appPath, String filePath, String filePrefix)
      throws FileNotFoundException, IOException {
    // --- find out which dbms data file to load
    String file = checkFilePath(filePath, filePrefix, DatabaseType.lookup(dbms).toString());

    // --- load the sql data
    return Lib.text.load(servletContext, appPath, file, Jeeves.ENCODING);
  }
Пример #5
0
 private DatabaseType getDialect() {
   if (databaseType == null) {
     // need to guess from the database type!
     Connection connection = null;
     try {
       connection = connectionFactory.getConnection();
       String dbProduct = connection.getMetaData().getDatabaseProductName();
       databaseType = guessDialect(dbProduct);
     } catch (Exception e) {
       log.debug("Unable to guess dialect from JDBC metadata.", e);
     } finally {
       connectionFactory.releaseConnection(connection);
     }
     if (databaseType == null) {
       log.debug(
           "Unable to detect database dialect using connection metadata.  Attempting to guess on driver name.");
       try {
         connection = connectionFactory.getConnection();
         String dbProduct = connectionFactory.getConnection().getMetaData().getDriverName();
         databaseType = guessDialect(dbProduct);
       } catch (Exception e) {
         log.debug("Unable to guess database dialect from JDBC driver name.", e);
       } finally {
         connectionFactory.releaseConnection(connection);
       }
     }
     if (databaseType == null) {
       throw new CacheConfigurationException(
           "Unable to detect database dialect from JDBC driver name or connection metadata.  Please provide this manually using the 'dialect' property in your configuration.  Supported database dialect strings are "
               + Arrays.toString(DatabaseType.values()));
     } else {
       log.debugf(
           "Guessing database dialect as '%s'.  If this is incorrect, please specify the correct dialect using the 'dialect' attribute in your configuration.  Supported database dialect strings are %s",
           databaseType, Arrays.toString(DatabaseType.values()));
     }
   }
   return databaseType;
 }
 @Test(expected = IllegalStateException.class)
 public void testBadGeneratedId() throws Exception {
   Field field = GeneratedId.class.getField("id");
   DatabaseType mockDb = createMock(DatabaseType.class);
   expect(mockDb.isIdSequenceNeeded()).andReturn(false);
   DataPersister dataPersister = createMock(DataPersister.class);
   expect(mockDb.getDataPersister(isA(DataPersister.class), isA(FieldType.class)))
       .andReturn(dataPersister);
   expect(mockDb.getFieldConverter(isA(DataPersister.class), isA(FieldType.class)))
       .andReturn(dataPersister);
   expect(mockDb.isEntityNamesMustBeUpCase()).andReturn(true);
   replay(mockDb);
   connectionSource.setDatabaseType(mockDb);
   try {
     FieldType fieldType =
         FieldType.createFieldType(connectionSource, "foo", field, GeneratedId.class);
     verify(mockDb);
     StringBuilder sb = new StringBuilder();
     List<String> statementsBefore = new ArrayList<String>();
     databaseType.appendColumnArg(null, sb, fieldType, null, statementsBefore, null, null);
   } finally {
     connectionSource.setDatabaseType(databaseType);
   }
 }
Пример #7
0
  /**
   * Write an interprocedural property database.
   *
   * @param <DatabaseType> actual type of the database
   * @param <KeyType> type of key (e.g., method or field)
   * @param <Property> type of properties stored in the database
   * @param database the database
   * @param fileName name of database file
   * @param description description of the database
   */
  public <
          DatabaseType extends PropertyDatabase<KeyType, Property>,
          KeyType extends FieldOrMethodDescriptor,
          Property>
      void storePropertyDatabase(DatabaseType database, String fileName, String description) {

    try {
      File dbFile = new File(getDatabaseOutputDir(), fileName);
      if (DEBUG) {
        System.out.println("Writing " + description + " to " + dbFile.getPath() + "...");
      }
      database.writeToFile(dbFile.getPath());
    } catch (IOException e) {
      getLookupFailureCallback().logError("Error writing " + description, e);
    }
  }
 /**
  * 初始化实际的数据库连接
  *
  * @param dataSource
  */
 protected void initFactualDataSource(BasicDataSource dataSource) {
   log.info(
       "Creating data source. Driver: "
           + type.getDriveClass()
           + ", url: "
           + type.getConnUrl()
           + ", user: "******", password: <not shown>");
   dataSource.setDriverClassName(type.getDriveClass());
   dataSource.setUsername(type.getUserName());
   dataSource.setPassword(type.getUserPass());
   dataSource.setUrl(type.getConnUrl());
 }
Пример #9
0
 private static void elementToDatabaseConfig(Element element, RetsConfig config) {
   DatabaseConfig database = new DatabaseConfig();
   database.setDatabaseType(DatabaseType.getType(getString(element, TYPE)));
   database.setHostName(getString(element, HOST));
   database.setDatabaseName(getString(element, NAME));
   database.setUsername(getString(element, USERNAME));
   database.setPassword(getString(element, PASSWORD));
   database.setMaxActive(getInt(element, MAX_ACTIVE));
   database.setMaxIdle(getInt(element, MAX_IDLE));
   database.setMaxWait(getInt(element, MAX_WAIT));
   database.setMaxPsActive(getInt(element, MAX_PS_ACTIVE));
   database.setMaxPsIdle(getInt(element, MAX_PS_IDLE));
   database.setMaxPsWait(getInt(element, MAX_PS_WAIT));
   database.setShowSql(getBoolean(element, SHOW_SQL));
   config.setDatabase(database);
 }
  /**
   * 初始化JDBCProxy的录制脚本的数据库连接
   *
   * @param dataSource
   */
  protected void initRecordProxyDataSource(BasicDataSource dataSource) {
    log.info(
        "Creating data source. Driver: "
            + type.getDriveClass()
            + ", url: "
            + type.getConnUrl()
            + ", user: "******", password: <not shown>");

    dataSource.setDriverClassName("nl.griffelservices.proxy.jdbc.oracle.StubTracerDriver");
    dataSource.setUsername(type.getUserName());
    dataSource.setPassword(type.getUserPass());
    String url =
        String.format(
            "jdbc:stubtracer:%s:%s:%s", "output", type.getDriveClass(), type.getConnUrl());
    dataSource.setUrl(url);
  }
Пример #11
0
  /**
   * Load an interprocedural property database.
   *
   * @param <DatabaseType> actual type of the database
   * @param <KeyType> type of key (e.g., method or field)
   * @param <Property> type of properties stored in the database
   * @param database the empty database object
   * @param fileName file to load database from
   * @param description description of the database (for diagnostics)
   * @return the database object, or null if the database couldn't be loaded
   */
  public <
          DatabaseType extends PropertyDatabase<KeyType, Property>,
          KeyType extends FieldOrMethodDescriptor,
          Property>
      DatabaseType loadPropertyDatabase(
          DatabaseType database, String fileName, String description) {
    try {
      File dbFile = new File(getDatabaseInputDir(), fileName);
      if (DEBUG) {
        System.out.println("Loading " + description + " from " + dbFile.getPath() + "...");
      }

      database.readFromFile(dbFile.getPath());
      return database;
    } catch (IOException e) {
      getLookupFailureCallback().logError("Error loading " + description, e);
    } catch (PropertyDatabaseFormatException e) {
      getLookupFailureCallback().logError("Invalid " + description, e);
    }
    return null;
  }
Пример #12
0
  /**
   * @param dbms
   * @return
   * @throws FileNotFoundException
   * @throws IOException
   */
  private List<String> loadSchemaFile(
      ServletContext servletContext,
      Dbms dbms,
      String appPath,
      String filePath,
      String filePrefix) // FIXME :
      // use
      // resource
      // dir
      // instead
      // of
      // appPath
      throws FileNotFoundException, IOException {
    // --- find out which dbms schema to load
    String file = checkFilePath(filePath, filePrefix, DatabaseType.lookup(dbms).toString());

    if (Log.isDebugEnabled(Geonet.DB)) Log.debug(Geonet.DB, "  Loading script:" + file);

    // --- load the dbms schema
    return Lib.text.load(servletContext, appPath, file);
  }
 public void init(Properties configuration) {
   this.type = DatabaseType.type();
 }
Пример #14
0
  private void getOptionsFromFile(final String optionsFilename) {
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;
    try {
      db = dbf.newDocumentBuilder();
    } catch (final ParserConfigurationException e) {
      ThreadContext.assertFault(false, "XML parser error [%s]", e.getMessage());
    }

    Document doc = null;
    try {
      final File file = new File(optionsFilename);
      doc = db.parse(file);
    } catch (final SAXException e) {
      ThreadContext.assertFault(false, "XML error [%s]", e.getMessage());
    } catch (final IOException e) {
      ThreadContext.assertFault(false, "Cannot read file [%s]%n", optionsFilename);
    }
    doc.getDocumentElement().normalize();

    final NodeList topLevelNodes = doc.getDocumentElement().getChildNodes();

    m_options = new Options();
    m_options.m_optionsFilename = optionsFilename;

    for (int i = 0; i < topLevelNodes.getLength(); ++i) {
      final Node node = topLevelNodes.item(i);

      if (node.getNodeType() == Node.ELEMENT_NODE) {
        final String nodeName = node.getNodeName();
        final String value = getItem(node);

        if (nodeName.equals("connection-driver")) {
          m_options.m_connectionDriver = value;
        } else if (nodeName.equals("jdbc-url")) {
          m_options.m_jdbcUrl = value;
        } else if (nodeName.equals("schema")) {
          m_options.m_schemaName = value;
        } else if (nodeName.equals("username")) {
          m_options.m_username = value;
        } else if (nodeName.equals("password")) {
          m_options.m_password = value;
        } else if (nodeName.equals("connection-properties")) {
          getConnectionProperties(node);
        } else if (nodeName.equals("filter-type")) {
          final String filter = value;
          if (filter.equals("AllPass")) {
            m_options.m_schemaObjectFilterStrategy =
                new AllPassSchemaObjectFilterStrategy(); // set filter strategy
          } else {
            ThreadContext.assertError(false, "Unknown [%s] [%s]", nodeName, filter);
          }
        } else if (nodeName.equals("database-type")) {
          try {
            m_options.m_databaseType = DatabaseType.valueOf(value);
          } catch (final IllegalArgumentException e) {
            ThreadContext.assertError(false, "Unsupported database type value [%s]", value);
          }
        } else if (nodeName.equals("database-version")) {
          m_options.m_databaseVersion = value;
        } else if (nodeName.equals("logical-name-style")) {
          if (value.equals("MixedCase")) {
            m_options.m_logicalNameStrategy = new MixedCaseLogicalNameStrategy();
          } else if (value.equals("SybaseStyle")) {
            m_options.m_logicalNameStrategy = new SybaseStyleLogicalNameStrategy();
          } else if (value.equals("PhysicalAsLogical")) {
            m_options.m_logicalNameStrategy = new PhysicalAsLogicalNameStrategy();
          } else {
            ThreadContext.assertError(false, "Unknown [%s] [%s]", nodeName, value);
          }
        } else if (nodeName.equals("output-file")) {
          m_options.m_outputFilename = value;
        } else {
          ThreadContext.assertError(
              false, "[%s] unknown option element [%s]", getClass().getSimpleName(), nodeName);
        }
      }
    }

    // Set database-specific behaviour.
    switch (m_options.m_databaseType) {
      case Oracle:
        {
          if (m_options.m_logicalNameStrategy == null) {
            // No specific naming strategy defined. Default to Oracle-style.
            m_options.m_logicalNameStrategy = new MixedCaseLogicalNameStrategy();
          }
          break;
        }

      case Sybase:
        {
          if (m_options.m_logicalNameStrategy == null) {
            // No specific naming strategy defined. Default to Sybase-style.
            m_options.m_logicalNameStrategy = new SybaseStyleLogicalNameStrategy();
          }
          m_options.m_ignoreReturnParameterOnProcedure = true;
          break;
        }
    }
  }