Package net.sf.hajdbc

Examples of net.sf.hajdbc.IdentityColumnSupport


        }
      }
     
      if (cluster.isIdentityColumnDetectionEnabled())
      {
        IdentityColumnSupport support = cluster.getDialect().getIdentityColumnSupport();
       
        if (support != null)
        {
          String table = support.parseInsertTable(sql);
         
          if (table != null)
          {
            TableProperties tableProperties = this.getDatabaseProperties().findTable(table);
           
View Full Code Here


  }

  @Test
  public void parseInsertTable() throws SQLException
  {
    IdentityColumnSupport support = this.dialect.getIdentityColumnSupport();
   
    if (support != null)
    {
      assertEquals("table", support.parseInsertTable("INSERT INTO table (column1, column2) VALUES (1, 2)"));
      assertEquals("table", support.parseInsertTable("INSERT INTO table VALUES (1, 2)"));
      assertEquals("table", support.parseInsertTable("INSERT table (column1, column2) VALUES (1, 2)"));
      assertEquals("table", support.parseInsertTable("INSERT table VALUES (1, 2)"));
      assertEquals("table", support.parseInsertTable("INSERT INTO table (column1, column2) SELECT column1, column2 FROM dummy"));
      assertEquals("table", support.parseInsertTable("INSERT INTO table SELECT column1, column2 FROM dummy"));
      assertEquals("table", support.parseInsertTable("INSERT table (column1, column2) SELECT column1, column2 FROM dummy"));
      assertEquals("table", support.parseInsertTable("INSERT table SELECT column1, column2 FROM dummy"));
      assertNull(support.parseInsertTable("SELECT * FROM table WHERE 0=1"));
      assertNull(support.parseInsertTable("UPDATE table SET column = 0"));
    }
  }
View Full Code Here

  }

  @Test
  public void getAlterIdentityColumnSQL() throws SQLException
  {
    IdentityColumnSupport support = this.dialect.getIdentityColumnSupport();
   
    if (support != null)
    {
      TableProperties table = mock(TableProperties.class);
      ColumnProperties column = mock(ColumnProperties.class);
      QualifiedName name = mock(QualifiedName.class);
     
      when(table.getName()).thenReturn(name);
      when(name.getDDLName()).thenReturn("table");
      when(column.getName()).thenReturn("column");
     
      String result = support.getAlterIdentityColumnSQL(table, column, 1000L);
     
      assertEquals("ALTER TABLE table ALTER COLUMN column RESTART WITH 1000", result);
    }
  }
View Full Code Here

   * @see net.sf.hajdbc.sync.SynchronizationSupport#synchronizeIdentityColumns()
   */
  @Override
  public void synchronizeIdentityColumns() throws SQLException
  {
    IdentityColumnSupport support = this.context.getDialect().getIdentityColumnSupport();
   
    if (support != null)
    {
      Statement sourceStatement = this.context.getConnection(this.context.getSourceDatabase()).createStatement();
      try
      {
        Statement targetStatement = this.context.getConnection(this.context.getTargetDatabase()).createStatement();
        try
        {
          for (TableProperties table: this.context.getSourceDatabaseProperties().getTables())
          {
            Collection<String> columns = table.getIdentityColumns();
           
            if (!columns.isEmpty())
            {
              String selectSQL = MessageFormat.format("SELECT max({0}) FROM {1}", Strings.join(columns, "), max("), table.getName()); //$NON-NLS-1$ //$NON-NLS-2$
             
              this.logger.log(Level.DEBUG, selectSQL);
             
              Map<String, Long> map = new HashMap<String, Long>();
              ResultSet resultSet = sourceStatement.executeQuery(selectSQL);
              try
              {
                if (resultSet.next())
                {
                  int i = 0;
                 
                  for (String column: columns)
                  {
                    map.put(column, resultSet.getLong(++i));
                  }
                }
              }
              finally
              {
                Resources.close(resultSet);
              }
             
              if (!map.isEmpty())
              {
                for (Map.Entry<String, Long> mapEntry: map.entrySet())
                {
                  String alterSQL = support.getAlterIdentityColumnSQL(table, table.getColumnProperties(mapEntry.getKey()), mapEntry.getValue() + 1);
                 
                  if (alterSQL != null)
                  {
                    this.logger.log(Level.DEBUG, alterSQL);
                   
View Full Code Here

  }

  @Test
  public void parseInsertTable() throws SQLException
  {
    IdentityColumnSupport support = this.dialect.getIdentityColumnSupport();
   
    if (support != null)
    {
      assertEquals("table", support.parseInsertTable("INSERT INTO table (column1, column2) VALUES (1, 2)"));
      assertEquals("table", support.parseInsertTable("INSERT INTO table VALUES (1, 2)"));
      assertEquals("table", support.parseInsertTable("INSERT table (column1, column2) VALUES (1, 2)"));
      assertEquals("table", support.parseInsertTable("INSERT table VALUES (1, 2)"));
      assertEquals("table", support.parseInsertTable("INSERT INTO table (column1, column2) SELECT column1, column2 FROM dummy"));
      assertEquals("table", support.parseInsertTable("INSERT INTO table SELECT column1, column2 FROM dummy"));
      assertEquals("table", support.parseInsertTable("INSERT table (column1, column2) SELECT column1, column2 FROM dummy"));
      assertEquals("table", support.parseInsertTable("INSERT table SELECT column1, column2 FROM dummy"));
      assertNull(support.parseInsertTable("SELECT * FROM table WHERE 0=1"));
      assertNull(support.parseInsertTable("UPDATE table SET column = 0"));
    }
  }
View Full Code Here

  }

  @Test
  public void getAlterIdentityColumnSQL() throws SQLException
  {
    IdentityColumnSupport support = this.dialect.getIdentityColumnSupport();
   
    if (support != null)
    {
      TableProperties table = mock(TableProperties.class);
      ColumnProperties column = mock(ColumnProperties.class);
      QualifiedName name = mock(QualifiedName.class);
     
      when(table.getName()).thenReturn(name);
      when(name.getDDLName()).thenReturn("table");
      when(column.getName()).thenReturn("column");
     
      String result = support.getAlterIdentityColumnSQL(table, column, 1000L);
     
      assertEquals("ALTER TABLE table ALTER COLUMN column RESTART WITH 1000", result);
    }
  }
View Full Code Here

TOP

Related Classes of net.sf.hajdbc.IdentityColumnSupport

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.