Package com.j256.ormlite.db

Examples of com.j256.ormlite.db.DatabaseType


    assertEquals(tableName + "_" + fields[0].getName() + "_idx", fieldConfig.getIndexName());
  }

  @Test
  public void testComboIndex() throws Exception {
    DatabaseType databaseType = new StubDatabaseType();
    Field[] fields = ComboIndex.class.getDeclaredFields();
    assertTrue(fields.length >= 2);
    DatabaseFieldConfig fieldConfig = DatabaseFieldConfig.fromField(databaseType, "foo", fields[0]);
    assertEquals(ComboIndex.INDEX_NAME, fieldConfig.getIndexName());
    fieldConfig = DatabaseFieldConfig.fromField(databaseType, "foo", fields[1]);
View Full Code Here


    assertEquals(ComboIndex.INDEX_NAME, fieldConfig.getIndexName());
  }

  @Test
  public void testDefaultValue() throws Exception {
    DatabaseType databaseType = new StubDatabaseType();
    DatabaseFieldConfig fieldConfig =
        DatabaseFieldConfig.fromField(databaseType, "defaultstring",
            DefaultString.class.getDeclaredField("stuff"));
    assertNotNull(fieldConfig.getDefaultValue());
    assertEquals(DefaultString.STUFF_DEFAULT, fieldConfig.getDefaultValue());
View Full Code Here

  }

  @Test
  public void testCreateTableQueriesAfter() throws Exception {
    final String queryAfter = "SELECT * from foo";
    DatabaseType databaseType = new H2DatabaseType() {
      @Override
      public void appendColumnArg(StringBuilder sb, FieldType fieldType, List<String> additionalArgs,
          List<String> statementsBefore, List<String> statementsAfter, List<String> queriesAfter)
          throws SQLException {
        super.appendColumnArg(sb, fieldType, additionalArgs, statementsBefore, statementsAfter, queriesAfter);
View Full Code Here

  @Test
  public void testFieldTypeConverter() throws Exception {
    Field[] fields = LocalFoo.class.getDeclaredFields();
    assertTrue(fields.length >= 4);
    Field nameField = fields[0];
    DatabaseType databaseType = createMock(DatabaseType.class);
    final SqlType sqlType = SqlType.DATE;
    final String nameArg = "zippy buzz";
    final String nameResult = "blabber bling";
    final AtomicBoolean resultToSqlArgCalled = new AtomicBoolean(false);
    DataPersister stringPersister = DataType.STRING.getDataPersister();
    expect(databaseType.getDataPersister(isA(DataPersister.class), isA(FieldType.class))).andReturn(stringPersister);
    expect(databaseType.getFieldConverter(isA(DataPersister.class), isA(FieldType.class))).andReturn(
        new BaseFieldConverter() {
          public SqlType getSqlType() {
            return sqlType;
          }
          public Object parseDefaultString(FieldType fieldType, String defaultStr) {
            return defaultStr;
          }
          public Object resultToSqlArg(FieldType fieldType, DatabaseResults resultSet, int columnPos) {
            resultToSqlArgCalled.set(true);
            return nameResult;
          }
          @Override
          public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) {
            return nameResult;
          }
          @Override
          public Object javaToSqlArg(FieldType fieldType, Object javaObject) {
            return nameArg;
          }
          public Object resultStringToJava(FieldType fieldType, String stringValue, int columnPos) {
            return stringValue;
          }
        });
    expect(databaseType.isEntityNamesMustBeUpCase()).andReturn(false);
    replay(databaseType);
    connectionSource.setDatabaseType(databaseType);
    FieldType fieldType =
        FieldType.createFieldType(connectionSource, LocalFoo.class.getSimpleName(), nameField, LocalFoo.class);
    verify(databaseType);
View Full Code Here

    verify(databaseConnection);
  }

  @Test
  public void testGeneratedIdSequence() throws Exception {
    DatabaseType databaseType = new NeedsSequenceDatabaseType();
    connectionSource.setDatabaseType(databaseType);
    TableInfo<GeneratedId, Integer> tableInfo =
        new TableInfo<GeneratedId, Integer>(connectionSource, null, GeneratedId.class);
    StatementExecutor<GeneratedId, Integer> se =
        new StatementExecutor<GeneratedId, Integer>(databaseType, tableInfo, null);
View Full Code Here

    verify(databaseConnection);
  }

  @Test
  public void testGeneratedIdSequenceLong() throws Exception {
    DatabaseType databaseType = new NeedsSequenceDatabaseType();
    connectionSource.setDatabaseType(databaseType);
    StatementExecutor<GeneratedIdLong, Long> se =
        new StatementExecutor<GeneratedIdLong, Long>(databaseType, new TableInfo<GeneratedIdLong, Long>(
            connectionSource, null, GeneratedIdLong.class), null);
    DatabaseConnection databaseConnection = createMock(DatabaseConnection.class);
View Full Code Here

   *            If set to true then try each statement regardless of {@link SQLException} thrown previously.
   * @return The number of statements executed to do so.
   */
  public static <T, ID> int dropTable(ConnectionSource connectionSource, Class<T> dataClass, boolean ignoreErrors)
      throws SQLException {
    DatabaseType databaseType = connectionSource.getDatabaseType();
    Dao<T, ID> dao = DaoManager.createDao(connectionSource, dataClass);
    if (dao instanceof BaseDaoImpl<?, ?>) {
      return doDropTable(databaseType, connectionSource, ((BaseDaoImpl<?, ?>) dao).getTableInfo(), ignoreErrors);
    } else {
      TableInfo<T, ID> tableInfo = new TableInfo<T, ID>(connectionSource, null, dataClass);
View Full Code Here

   *            If set to true then try each statement regardless of {@link SQLException} thrown previously.
   * @return The number of statements executed to do so.
   */
  public static <T, ID> int dropTable(ConnectionSource connectionSource, DatabaseTableConfig<T> tableConfig,
      boolean ignoreErrors) throws SQLException {
    DatabaseType databaseType = connectionSource.getDatabaseType();
    Dao<T, ID> dao = DaoManager.createDao(connectionSource, tableConfig);
    if (dao instanceof BaseDaoImpl<?, ?>) {
      return doDropTable(databaseType, connectionSource, ((BaseDaoImpl<?, ?>) dao).getTableInfo(), ignoreErrors);
    } else {
      tableConfig.extractFieldTypes(connectionSource);
View Full Code Here

      return doCreateTable(connectionSource, tableInfo, ifNotExists);
    }
  }

  private static <T> int clearTable(ConnectionSource connectionSource, String tableName) throws SQLException {
    DatabaseType databaseType = connectionSource.getDatabaseType();
    StringBuilder sb = new StringBuilder(48);
    if (databaseType.isTruncateSupported()) {
      sb.append("TRUNCATE TABLE ");
    } else {
      sb.append("DELETE FROM ");
    }
    databaseType.appendEscapedEntityName(sb, tableName);
    String statement = sb.toString();
    logger.info("clearing table '{}' with '{}", tableName, statement);
    CompiledStatement compiledStmt = null;
    DatabaseConnection connection = connectionSource.getReadWriteConnection();
    try {
View Full Code Here

    statements.addAll(statementsAfter);
  }

  private static <T, ID> int doCreateTable(ConnectionSource connectionSource, TableInfo<T, ID> tableInfo,
      boolean ifNotExists) throws SQLException {
    DatabaseType databaseType = connectionSource.getDatabaseType();
    logger.info("creating table '{}'", tableInfo.getTableName());
    List<String> statements = new ArrayList<String>();
    List<String> queriesAfter = new ArrayList<String>();
    addCreateTableStatements(databaseType, tableInfo, statements, queriesAfter, ifNotExists);
    DatabaseConnection connection = connectionSource.getReadWriteConnection();
    try {
      int stmtC =
          doStatements(connection, "create", statements, false, databaseType.isCreateTableReturnsNegative(),
              databaseType.isCreateTableReturnsZero());
      stmtC += doCreateTestQueries(connection, databaseType, queriesAfter);
      return stmtC;
    } finally {
      connectionSource.releaseConnection(connection);
    }
View Full Code Here

TOP

Related Classes of com.j256.ormlite.db.DatabaseType

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.