Create marker table if it doesn't exist.

        Using a separate connection since the transaction might have to be reset.
499534
def create_marker_table(self):
        
        connection = self.connect()
        connection.autocommit = True
        cursor = connection.cursor()
        if self.use_db_timestamps:
            sql = """ CREATE TABLE {marker_table} (
                      update_id TEXT PRIMARY KEY,
                      target_table TEXT,
                      inserted TIMESTAMP DEFAULT NOW())
                  """.format(marker_table=self.marker_table)
        else:
            sql = """ CREATE TABLE {marker_table} (
                      update_id TEXT PRIMARY KEY,
                      target_table TEXT,
                      inserted TIMESTAMP);
                  """.format(marker_table=self.marker_table)

        try:
            cursor.execute(sql)
        except psycopg2.ProgrammingError as e:
            if e.pgcode == psycopg2.errorcodes.DUPLICATE_TABLE:
                pass
            else:
                raise
        connection.close()
884684
def if_not_exists(self):
        
        if self.model._has_counter:
            raise IfNotExistsWithCounterColumn('if_not_exists cannot be used with tables containing counter columns')
        clone = copy.deepcopy(self)
        clone._if_not_exists = True
        return clone
1371242
def create_marker_index(self):
        
        if not self.es.indices.exists(index=self.marker_index):
            self.es.indices.create(index=self.marker_index)
1349417
public void checkAndCreateTable(String tabName, String colFamName) throws IOException {
        HBaseAdmin hba;
        try {
            hba = new HBaseAdmin(this.getHbcfg());
            if (hba.tableExists(tabName) == false) {
                logger.debug("creating table " + tabName);
                final HTableDescriptor tableDescriptor = new HTableDescriptor(tabName);
                final HColumnDescriptor columnDescriptor = new HColumnDescriptor(colFamName);
		columnDescriptor.setMaxVersions(MAX_VALUE);
		tableDescriptor.addFamily(columnDescriptor);
                hba.createTable(tableDescriptor);
            } else {
                logger.debug("already existent table " + tabName);
            }
            hba.close();
        } catch (MasterNotRunningException e) {
            throw new IOException(e);
        } catch (ZooKeeperConnectionException e) {
            throw new IOException(e);
        } catch (IOException e) {
            throw new IOException(e);
        }
    }
315699
def _create_table(self, packet_defn):
        ''' 
        '''
        cols = ('%s %s' % (defn.name, self._getTypename(defn)) for defn in packet_defn.fields)
        sql  = 'CREATE TABLE IF NOT EXISTS %s (%s)' % (packet_defn.name, ', '.join(cols))

        self._conn.execute(sql)
        self._conn.commit()
88277
function createTransaction(dbInfo, mode, callback, retries) {
    if (retries === undefined) {
        retries = 1;
    }

    try {
        var tx = dbInfo.db.transaction(dbInfo.storeName, mode);
        callback(null, tx);
    } catch (err) {
        if (retries > 0 && (!dbInfo.db || err.name === 'InvalidStateError' || err.name === 'NotFoundError')) {
            return Promise$1.resolve().then(function () {
                if (!dbInfo.db || err.name === 'NotFoundError' && !dbInfo.db.objectStoreNames.contains(dbInfo.storeName) && dbInfo.version <= dbInfo.db.version) {
                    // increase the db version, to create the new ObjectStore
                    if (dbInfo.db) {
                        dbInfo.version = dbInfo.db.version + 1;
                    }
                    // Reopen the database for upgrading.
                    return _getUpgradedConnection(dbInfo);
                }
            }).then(function () {
                return _tryReconnect(dbInfo).then(function () {
                    createTransaction(dbInfo, mode, callback, retries - 1);
                });
            })["catch"](callback);
        }

        callback(err);
    }
}
75001
function createDbTable(t, dbInfo, callback, errorCallback) {
    t.executeSql('CREATE TABLE IF NOT EXISTS ' + dbInfo.storeName + ' ' + '(id INTEGER PRIMARY KEY, key unique, value)', [], callback, errorCallback);
}
979958
public static boolean createTableIfNotExists(final Connection conn, final String tableName, final String schema) {
        if (doesTableExist(conn, tableName)) {
            return false;
        }

        try {
            execute(conn, schema);

            return true;
        } catch (SQLException e) {
            return false;
        }
    }
1203885
def __create_table_if_not_exists(self):
        # type: () -> None
        
        if self.create_table:
            try:
                self.dynamodb.create_table(
                    TableName=self.table_name,
                    KeySchema=[
                        {
                            'AttributeName': self.partition_key_name,
                            'KeyType': 'HASH'
                        }
                    ],
                    AttributeDefinitions=[
                        {
                            'AttributeName': self.partition_key_name,
                            'AttributeType': 'S'
                        }

                    ],
                    ProvisionedThroughput={
                        'ReadCapacityUnits': 5,
                        'WriteCapacityUnits': 5
                    }
                )
            except Exception as e:
                if e.__class__.__name__ != "ResourceInUseException":
                    raise PersistenceException(
                        "Create table if not exists request "
                        "failed: Exception of type {} "
                        "occurred: {}".format(
                            type(e).__name__, str(e)))
244314
def touch(self, connection=None):
        
        self.create_marker_table()

        if connection is None:
            # TODO: test this
            connection = self.connect()
            connection.autocommit = True  # if connection created here, we commit it here

        if self.use_db_timestamps:
            connection.cursor().execute(
                """INSERT INTO {marker_table} (update_id, target_table)
                   VALUES (%s, %s)
                """.format(marker_table=self.marker_table),
                (self.update_id, self.table))
        else:
            connection.cursor().execute(
                """INSERT INTO {marker_table} (update_id, target_table, inserted)
                         VALUES (%s, %s, %s);
                    """.format(marker_table=self.marker_table),
                (self.update_id, self.table,
                 datetime.datetime.now()))
659694
def run(self):
        
        if not (self.table):
            raise Exception("table need to be specified")

        path = self.s3_load_path()
        output = self.output()
        connection = output.connect()
        cursor = connection.cursor()

        self.init_copy(connection)
        self.copy(cursor, path)
        self.post_copy(cursor)

        if self.enable_metadata_columns:
            self.post_copy_metacolumns(cursor)

        # update marker table
        output.touch(connection)
        connection.commit()

        # commit and clean up
        connection.close()
1249587
public boolean createTableIfNotExists(final String tableName, final String schema) {
        Connection conn = getConnection();

        try {
            return JdbcUtil.createTableIfNotExists(conn, tableName, schema);
        } finally {
            closeQuietly(conn);
        }
    }
997937
def ensure_segment_table(connection):
    """"""

    count = connection.cursor().execute("SELECT count(*) FROM sqlite_master WHERE name='segment'").fetchone()[0]

    if count == 0:
        print >>sys.stderr, "WARNING: None of the loaded files contain a segment table"
        theClass  = lsctables.TableByName['segment']
        statement = "CREATE TABLE IF NOT EXISTS segment (" + ", ".join(map(lambda key: "%s %s" % (key, ligolwtypes.ToSQLiteType[theClass.validcolumns[key]]), theClass.validcolumns)) + ")"

        connection.cursor().execute(statement)
762024
public static TransactionEdit createCheckpoint(long writePointer, long parentWritePointer) {
    return new TransactionEdit(writePointer, 0L, State.CHECKPOINT, 0L, null, 0L, false, null, null, 0L,
        parentWritePointer, null);
  }
477244
public void createCheckpoint() {
		if (logger.isLoggable(Level.INFO))
			logger.info("Start creating checkpoint");
		if (MY_METHOD == METHOD_MONITOR) {
			if (VanillaDb.txMgr().getNextTxNum() - lastTxNum > TX_COUNT_TO_CHECKPOINT) {
				Transaction tx = VanillaDb.txMgr().newTransaction(
						Connection.TRANSACTION_SERIALIZABLE, false);
				VanillaDb.txMgr().createCheckpoint(tx);
				tx.commit();
				lastTxNum = VanillaDb.txMgr().getNextTxNum();
			}
		} else if (MY_METHOD == METHOD_PERIODIC) {
			Transaction tx = VanillaDb.txMgr().newTransaction(
					Connection.TRANSACTION_SERIALIZABLE, false);
			VanillaDb.txMgr().createCheckpoint(tx);
			tx.commit();
		}
		if (logger.isLoggable(Level.INFO))
			logger.info("A checkpoint created");
	}
819268
protected void create(List<TableInfo> tableInfos)
    {
        try
        {
            if (admin.isTableAvailable(databaseName))
            {
                addColumnFamilies(tableInfos, admin.getTableDescriptor(databaseName.getBytes()), false);
            }
            else
            {
                createTable(tableInfos);
            }
            if (admin.isTableDisabled(databaseName))
            {
                admin.enableTable(databaseName);
            }
        }
        catch (TableNotFoundException e)
        {
            logger.info("creating table " + databaseName);
        }
        catch (IOException ioex)
        {
            logger.error("Either table isn't in enabled state or some network problem, Caused by: ", ioex);
            throw new SchemaGenerationException(ioex, "Hbase");
        }
    }
1042307
private void createTables(Collection<HTableDescriptor> tableDescriptors)
      throws InterruptedException {
    try {
      Set<String> tablesCreated = Sets.newHashSet();
      Multimap<String, HTableDescriptor> pendingTableUpdates = ArrayListMultimap
          .create();
      for (HTableDescriptor tableDescriptor : tableDescriptors) {
        String tableName = Bytes.toString(tableDescriptor.getName());
        if (tablesCreated.contains(tableName)) {
          // We have to wait for the table async creation to modify
          // Just add the required columns to be added
          pendingTableUpdates.put(tableName, tableDescriptor);
        } else {
          LOG.info("Creating table " + tableName);
          hbaseAdmin.createTableAsync(tableDescriptor, new byte[][] {});
          tablesCreated.add(tableName);
        }
      }

      // Wait for the tables to be online
      for (int waitCount = 0;
           waitCount < MAX_SECOND_WAIT_FOR_TABLE_CREATION; waitCount++) {
        Iterator<String> iterator = tablesCreated.iterator();
        while (iterator.hasNext()) {
          String table = iterator.next();
          if (hbaseAdmin.isTableAvailable(table)) {
            // Perform any updates scheduled on the table
            if (pendingTableUpdates.containsKey(table)) {
              for (HTableDescriptor tableDescriptor : pendingTableUpdates
                  .get(table)) {
                // Add the new columns - synchronous calls
                modifyTable(table, tableDescriptor);
              }
            }
            iterator.remove();
          }
        }
        // If all tables are available, then break
        if (tablesCreated.isEmpty()) {
          break;
        }
        // Sleep for a second before checking again
        Thread.sleep(1000);
      }
    } catch (IOException e) {
      throw new DatasetException(e);
    }
  }