Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.text.DateFormat;
- import java.text.DecimalFormat;
- import java.text.SimpleDateFormat;
- import java.time.ZoneId;
- import java.time.ZonedDateTime;
- import java.time.temporal.ChronoUnit;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Random;
- public class Generator {
- private static final String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
- private static final String DB_CONNECTION = "jdbc:oracle:thin:@localhost:1521:orcl";
- private static final String DB_USER = "admin";
- private static final String DB_PASSWORD = "admin";
- private static final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
- /////////////////////////////////
- private static final List<String> cities = Arrays.asList("Jefferson Hills", "Looney", "Daphna", "Pohick Park",
- "Berkley", "Eldoradania", "Cape Carlyn", "Winterpock", "Buffalo Forge", "Lindau Woods", "Tye River",
- "Maces Spring", "Mount Blanco", "Penhook", "Sleepy Hollow Estates", "Carrol Mill", "Clarkton", "Ocala",
- "Athens", "Oaklands", "East Courthouse Estates", "Oak Terrace", "Fox", "Patna", "Rocky Gap", "Cedar Forest",
- "Monaskon", "Spivey Mill", "Hinnom", "Reynolds Corner", "Cedar Green", "Todds Tavern", "Carrsville",
- "Rock Run", "Colony", "Putneys Mill", "Shiloh", "Allison Gap", "Prospect", "County Line Cross Roads");
- private static final List<String> streets = Arrays.asList("Clear Hollow", "Quaking Willow Green", "Sleepy Chase",
- "Dusty Sky Turnabout", "Hidden Square", "Fallen Branch Place", "Thunder Gate Port", "Indian Hickory Mount",
- "Foggy Apple Arbor", "High Treasure Close", "Rustic Towers", "Emerald Elk Landing", "Cozy Rise Pathway",
- "Cotton Avenue", "Wishing Wagon Byway", "Silent Carrefour", "Shady Walk", "Velvet Edge", "Old Point",
- "Colonial Dell", "Red Loop", "Quiet Round", "Tawny Glade", "Middle Thicket", "Hazy Log Highlands",
- "Lazy Trail", "Heather Oak Dale", "Grand Prairie Knoll", "Crystal Rise", "Umber Maze", "Jagged Crescent",
- "Green Blossom Plaza", "Lost Forest Subdivision", "Bright Anchor Estates", "Gentle Autumn Vale",
- "Harvest Pond Route", "Easy Timber Orchard", "Golden Deer Manor", "Burning Hills Link", "Sunny Vista",
- "Stony Corners", "Honey Bend", "Noble Fox Bank", "Cinder Spring Circle", "Blue Embers Jetty", "Amber Ramp",
- "Little Crossing", "Misty Heights", "Pleasant Pioneer Boulevard", "Rocky Highway");
- private static final List<String> postalCodes = Arrays.asList("1");
- private static final List<String> genders = Arrays.asList("f", "m");
- private static final List<String> maritalStatus = Arrays.asList("single", "married");
- private static final List<String> position = Arrays.asList("junior", "regular", "senior");
- private static Connection getDBConnection() {
- Connection dbConnection = null;
- try {
- Class.forName(DB_DRIVER);
- } catch (ClassNotFoundException e) {
- System.out.println(e.getMessage());
- }
- try {
- dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);
- return dbConnection;
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- return dbConnection;
- }
- public static void fillWithDataBiuro() throws SQLException {
- Connection dbConnection = null;
- PreparedStatement preparedStatement = null;
- Random rand = new Random();
- try {
- dbConnection = getDBConnection();
- String insertTableSQL = "INSERT INTO BIURO(idbiura, miasto, ulica, kodpocztowy) VALUES (?,?,?,?)";
- preparedStatement = dbConnection.prepareStatement(insertTableSQL);
- for (int i = 0; i < 1500000; i++) {
- System.out.println(i);
- preparedStatement.setInt(1, i);
- preparedStatement.setString(2, cities.get(rand.nextInt(cities.size())));
- preparedStatement.setString(3, streets.get(rand.nextInt(streets.size())));
- preparedStatement.setString(4, "22-400");
- preparedStatement.addBatch();
- //preparedStatement.execute();
- //statement.executeUpdate(insertTableSQL);
- //dbConnection.commit();
- }
- preparedStatement.executeBatch();
- dbConnection.commit();
- System.out.println("Record is inserted into Biuro table!");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- if (preparedStatement != null) {
- preparedStatement.close();
- }
- if (dbConnection != null) {
- dbConnection.close();
- }
- }
- System.out.println("STOP BIURO");
- }
- public static void fillWithDataKlient() throws SQLException {
- Connection dbConnection = null;
- PreparedStatement preparedStatement = null;
- Random rand = new Random();
- try {
- dbConnection = getDBConnection();
- String insertTableSQL = "INSERT INTO KLIENT(idklienta, imie, nazwisko, miasto, ulica, telefon, wiek, stancywilny, plec) VALUES (?,?,?,?,?,?,?,?,?)";
- preparedStatement = dbConnection.prepareStatement(insertTableSQL);
- for (int i = 0; i < 1500000; i++) {
- System.out.println(i);
- preparedStatement.setInt(1, i);
- preparedStatement.setString(2, "X");
- preparedStatement.setString(3, "Y");
- preparedStatement.setString(4, cities.get(rand.nextInt(cities.size())));
- preparedStatement.setString(5, streets.get(rand.nextInt(streets.size())));
- preparedStatement.setString(6, "22-400");
- preparedStatement.setInt(7, rand.nextInt((80 - 18) + 1) + 18);
- preparedStatement.setString(8, maritalStatus.get(rand.nextInt(maritalStatus.size())));
- preparedStatement.setString(9, genders.get(rand.nextInt(genders.size())));
- preparedStatement.addBatch();
- //preparedStatement.execute();
- //statement.executeUpdate(insertTableSQL);
- //dbConnection.commit();
- }
- preparedStatement.executeBatch();
- dbConnection.commit();
- System.out.println("Record is inserted into Klient table!");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- if (preparedStatement != null) {
- preparedStatement.close();
- }
- if (dbConnection != null) {
- dbConnection.close();
- }
- }
- System.out.println("STOP Klient");
- }
- public static void fillWithDataNieruchomosc() throws SQLException {
- Connection dbConnection = null;
- PreparedStatement preparedStatement = null;
- Random rand = new Random();
- try {
- dbConnection = getDBConnection();
- String insertTableSQL = "INSERT INTO nieruchomosc(idnieruchomosci, miasto, ulica, liczbapokoi, kodpocztowy, powierzchnia,odcentrum, rokbudowy, pietro, piwnica, balkon, wlasciciel_idwlasciciela,pracownik_idpracownika) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
- preparedStatement = dbConnection.prepareStatement(insertTableSQL);
- for (int i = 0; i < 1000000; i++) {
- System.out.println(i);
- int surface = rand.nextInt((150 - 25) + 1) + 25;
- int numbersOfRoom;
- if(surface>=25 && surface <60){
- numbersOfRoom = rand.nextInt((4 - 1) + 1) + 1;
- } else if (surface >= 60 && surface <= 90){
- numbersOfRoom = rand.nextInt((6 - 3) + 1) + 3;
- } else if(surface >90 && surface <150){
- numbersOfRoom = rand.nextInt((8 - 5) + 1) + 5;
- } else {
- numbersOfRoom = rand.nextInt((8 - 1) + 1) + 1;
- }
- double fromTheCenter = 15*rand.nextDouble();
- DecimalFormat df = new DecimalFormat("#.#");
- fromTheCenter = Double.valueOf(df.format(fromTheCenter));
- preparedStatement.setInt(1, i);
- preparedStatement.setString(2, cities.get(rand.nextInt(cities.size())));
- preparedStatement.setString(3, streets.get(rand.nextInt(streets.size())));
- preparedStatement.setInt(4, numbersOfRoom);
- preparedStatement.setString(5, "22-400");
- preparedStatement.setInt(6, surface);
- preparedStatement.setDouble(7, fromTheCenter);
- preparedStatement.setInt(8,rand.nextInt((2018 - 1980) + 1) + 1980);
- preparedStatement.setInt(9,rand.nextInt((11 - 1) + 1) + 1);
- preparedStatement.setString(10,rand.nextInt(2) == 1? "t" : "f");
- preparedStatement.setString(11, rand.nextInt(2) == 1? "t" : "f");
- preparedStatement.setInt(12, rand.nextInt(1200000));
- preparedStatement.setInt(13, rand.nextInt(1200000));
- preparedStatement.addBatch();
- //preparedStatement.execute();
- //statement.executeUpdate(insertTableSQL);
- //dbConnection.commit();
- }
- preparedStatement.executeBatch();
- dbConnection.commit();
- System.out.println("Record is inserted into Nieruchomosc table!");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- if (preparedStatement != null) {
- preparedStatement.close();
- }
- if (dbConnection != null) {
- dbConnection.close();
- }
- }
- System.out.println("STOP Nieruchomosc");
- }
- public static void fillWithDataPracownik() throws SQLException {
- Connection dbConnection = null;
- PreparedStatement preparedStatement = null;
- Random rand = new Random();
- try {
- dbConnection = getDBConnection();
- String insertTableSQL = "INSERT INTO pracownik(idpracownika, imie, nazwisko, stanowisko, pensja, biuro_idbiura) VALUES (?,?,?,?,?,?)";
- preparedStatement = dbConnection.prepareStatement(insertTableSQL);
- for (int i = 0; i < 1500000; i++) {
- System.out.println(i);
- preparedStatement.setInt(1, i);
- preparedStatement.setString(2, "X");
- preparedStatement.setString(3, "Y");
- preparedStatement.setString(4, position.get(rand.nextInt(position.size())));
- preparedStatement.setDouble(5, rand.nextInt((10000 - 2000) + 1) + 2000);
- preparedStatement.setInt(6, rand.nextInt(1500000));
- preparedStatement.addBatch();
- //preparedStatement.execute();
- //statement.executeUpdate(insertTableSQL);
- //dbConnection.commit();
- }
- preparedStatement.executeBatch();
- dbConnection.commit();
- System.out.println("Record is inserted into Pracownik table!");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- if (preparedStatement != null) {
- preparedStatement.close();
- }
- if (dbConnection != null) {
- dbConnection.close();
- }
- }
- System.out.println("STOP Pracownik");
- }
- public static void fillWithDataSprzedaz() throws SQLException{
- Connection dbConnection = null;
- PreparedStatement preparedStatement = null;
- Random rand = new Random();
- try {
- dbConnection = getDBConnection();
- String insertTableSQL = "INSERT INTO sprzedaz(idsprzedazy, datasprzedazy, cena, klient_idklienta, nieruchomosc_idnieruchomosci) VALUES (?,?,?,?,?)";
- preparedStatement = dbConnection.prepareStatement(insertTableSQL);
- for (int i = 0; i < 1500000; i++) {
- System.out.println(i);
- long offset = Timestamp.valueOf("2009-01-01 00:00:00").getTime();
- long end = Timestamp.valueOf("2019-01-01 00:00:00").getTime();
- long diff = end - offset + 1;
- Timestamp randomDate = new Timestamp(offset + (long)(Math.random() * diff));
- preparedStatement.setInt(1, i);
- preparedStatement.setTimestamp(2, randomDate);
- preparedStatement.setInt(3, rand.nextInt((500000 - 200000) + 1) + 200000);
- preparedStatement.setInt(4, rand.nextInt(1200000));
- preparedStatement.setInt(5, rand.nextInt(1000000));
- preparedStatement.addBatch();
- //preparedStatement.execute();
- //statement.executeUpdate(insertTableSQL);
- //dbConnection.commit();
- }
- preparedStatement.executeBatch();
- dbConnection.commit();
- System.out.println("Record is inserted into Sprzedaz table!");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- if (preparedStatement != null) {
- preparedStatement.close();
- }
- if (dbConnection != null) {
- dbConnection.close();
- }
- }
- System.out.println("STOP Sprzedaz");
- }
- public static void fillWithDataWizyta() throws SQLException{
- Connection dbConnection = null;
- PreparedStatement preparedStatement = null;
- Random rand = new Random();
- try {
- dbConnection = getDBConnection();
- String insertTableSQL = "INSERT INTO wizyta(idwizyty, datawizyty, uwagi, klient_idklienta, nieruchomosc_idnieruchomosci) VALUES (?,?,?,?,?)";
- preparedStatement = dbConnection.prepareStatement(insertTableSQL);
- for (int i = 0; i < 1500000; i++) {
- System.out.println(i);
- long offset = Timestamp.valueOf("2009-01-01 00:00:00").getTime();
- long end = Timestamp.valueOf("2019-01-01 00:00:00").getTime();
- long diff = end - offset + 1;
- Timestamp randomDate = new Timestamp(offset + (long)(Math.random() * diff));
- preparedStatement.setInt(1, i);
- preparedStatement.setTimestamp(2, randomDate);
- preparedStatement.setString(3, "X");
- preparedStatement.setInt(4, rand.nextInt(1200000));
- preparedStatement.setInt(5, rand.nextInt(1000000));
- preparedStatement.addBatch();
- //preparedStatement.execute();
- //statement.executeUpdate(insertTableSQL);
- //dbConnection.commit();
- }
- preparedStatement.executeBatch();
- dbConnection.commit();
- System.out.println("Record is inserted into Wizyta table!");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- if (preparedStatement != null) {
- preparedStatement.close();
- }
- if (dbConnection != null) {
- dbConnection.close();
- }
- }
- System.out.println("STOP Wizyta");
- }
- public static void fillWithDataWlasciciel() throws SQLException {
- Connection dbConnection = null;
- PreparedStatement preparedStatement = null;
- Random rand = new Random();
- try {
- dbConnection = getDBConnection();
- String insertTableSQL = "INSERT INTO wlasciciel(idwlasciciela, imie, nazwisko, miasto, telefon, ulica) VALUES (?,?,?,?,?,?)";
- preparedStatement = dbConnection.prepareStatement(insertTableSQL);
- for (int i = 0; i < 1500000; i++) {
- System.out.println(i);
- preparedStatement.setInt(1, i);
- preparedStatement.setString(2, "X");
- preparedStatement.setString(3, "Y");
- preparedStatement.setString(4, cities.get(rand.nextInt(cities.size())));
- preparedStatement.setString(5, "22-400");
- preparedStatement.setString(6, streets.get(rand.nextInt(streets.size())));
- preparedStatement.addBatch();
- //preparedStatement.execute();
- //statement.executeUpdate(insertTableSQL);
- //dbConnection.commit();
- }
- preparedStatement.executeBatch();
- dbConnection.commit();
- System.out.println("Record is inserted into Wlasciciel table!");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- if (preparedStatement != null) {
- preparedStatement.close();
- }
- if (dbConnection != null) {
- dbConnection.close();
- }
- }
- System.out.println("STOP Wlasciciel");
- }
- public static void fillWithDataWynajem() throws SQLException{
- Connection dbConnection = null;
- PreparedStatement preparedStatement = null;
- Random rand = new Random();
- try {
- dbConnection = getDBConnection();
- String insertTableSQL = "INSERT INTO wynajem(idwynajmu, cena, poczatekwynajmu, koniecwynajmu, kaucja, klient_idklienta, nieruchomosc_idnieruchomosci) VALUES (?,?,?,?,?,?,?)";
- preparedStatement = dbConnection.prepareStatement(insertTableSQL);
- for (int i = 0; i < 1500000; i++) {
- System.out.println(i);
- long offset = Timestamp.valueOf("2009-01-01 00:00:00").getTime();
- long end = Timestamp.valueOf("2019-01-01 00:00:00").getTime();
- long diff = end - offset + 1;
- Timestamp beginningOfRental = new Timestamp(offset + (long)(Math.random() * diff));
- ZonedDateTime zonedDateTime = beginningOfRental.toInstant().atZone(ZoneId.of("UTC"));
- Timestamp endOfRental = Timestamp.from(zonedDateTime.plus(6, ChronoUnit.MONTHS).toInstant());
- preparedStatement.setInt(1, i);
- preparedStatement.setInt(2, rand.nextInt((5000 - 500) + 1) + 500);
- preparedStatement.setTimestamp(3,beginningOfRental);
- preparedStatement.setTimestamp(4,endOfRental);
- preparedStatement.setInt(5,rand.nextInt((1500 - 500) + 1) + 500);
- preparedStatement.setInt(6, rand.nextInt(1200000));
- preparedStatement.setInt(7, rand.nextInt(1000000));
- preparedStatement.addBatch();
- //preparedStatement.execute();
- //statement.executeUpdate(insertTableSQL);
- //dbConnection.commit();
- }
- preparedStatement.executeBatch();
- dbConnection.commit();
- System.out.println("Record is inserted into Wynajem table!");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- if (preparedStatement != null) {
- preparedStatement.close();
- }
- if (dbConnection != null) {
- dbConnection.close();
- }
- }
- System.out.println("STOP Wynajem");
- }
- }
Add Comment
Please, Sign In to add comment