daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Feb 16th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ```xml
  2.         <dependency>
  3.             <groupId>com.datastax.oss</groupId>
  4.             <artifactId>java-driver-core</artifactId>
  5.             <version>4.0.0-beta1</version>
  6.             <scope>test</scope>
  7.         </dependency>
  8. ```
  9.  
  10. ```java
  11.         session.execute("CREATE TABLE " + table + " (" +
  12.                 " key text PRIMARY KEY, " +
  13.                 " typelist frozen<list<" + typeName + ">>, " +
  14.                 " typemap frozen<map<int, " + typeName + ">>, " +
  15.                 " typeset frozen<set<" + typeName + ">>, " +
  16.                 " typefrozen frozen <" + typeName + ">, " +
  17.                 ")");
  18.  
  19.         UserDefinedType udt =
  20.                 new UserDefinedTypeBuilder(table.getSchemaName(), typeName)
  21.                         .withField("fieldtext", DataTypes.TEXT)
  22.                         .withField("fieldinteger", DataTypes.INT)
  23.                         .withField("fieldset", DataTypes.DOUBLE)
  24.                         .build();
  25.         UdtValue udtValue = udt.newValue().setString(0, "hello").setInt(1, 1).setDouble(2, 1.2);
  26.  
  27.         RegularStatement regularStatement = QueryBuilder.insertInto(table.getSchemaName(), table.getTableName());
  28.  
  29.  
  30.         for (int rowNumber = 1; rowNumber <= rowsCount; rowNumber++) {
  31.             PreparedStatement preparedStatement = session.prepare(regularStatement);
  32.             preparedStatement.bind()
  33.                     .setString("key", "key " + rowNumber)
  34.                     .setList("typelist", List.of(1))
  35.                     .setMap("typemap", ImmutableMap.of(1))
  36.                     .setSet("typeset", new Set<>{""})
  37.                     .setUDTValue("typefrozen", udt.newValue().setString(0, "hello").setInt(1, rowNumber).setDouble(2, 1.2))
  38.                     ;
  39.  
  40.             session.execute("INSERT INTO " + table + "(key, typelist, typemap, typeset, typefrozen) VALUES (" +
  41.                     String.format("'key %s', ", rowNumber) +
  42.                     String.format("[ { fieldtext: 'text %s', fieldinteger: %s, fieldset: 0.%s } ], ", rowNumber, rowNumber, rowNumber) +
  43.                     String.format("{ %s: { fieldtext: 'fieldText', fieldinteger: 0, fieldset: 0.0 } }, ", rowNumber) +
  44.                     "{{fieldtext: 'fieldText', fieldinteger: 0, fieldset: 0.0 }}, " +
  45.                     udt.newValue().setString(0, "hello").setInt(1, rowNumber).setDouble(2, 1.2) +
  46.                     ");");
  47.  
  48. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top