List of usage examples for java.util UUID UUID
public UUID(long mostSigBits, long leastSigBits)
From source file:info.archinnov.achilles.it.TestDSLEntityWithClusterings.java
@Test public void should_dsl_select_slice_with_clusterings_IN_same_partition() throws Exception { //Given/*from w w w. jav a2 s . c o m*/ final Map<String, Object> values = new HashMap<>(); final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); values.put("id1", id); values.put("id2", id); values.put("id3", id); values.put("id4", id); values.put("id5", id); final UUID uuid1 = new UUID(0L, 0L); final UUID uuid2 = new UUID(0L, 1L); values.put("uuid1", uuid1); values.put("uuid2", uuid1); values.put("uuid3", uuid1); values.put("uuid4", uuid2); values.put("uuid5", uuid2); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); final Date date3 = dateFormat.parse("2015-10-03 00:00:00 GMT"); final Date date5 = dateFormat.parse("2015-10-05 00:00:00 GMT"); values.put("date1", "'2015-10-01 00:00:00+0000'"); values.put("date2", "'2015-10-02 00:00:00+0000'"); values.put("date3", "'2015-10-03 00:00:00+0000'"); values.put("date4", "'2015-10-04 00:00:00+0000'"); values.put("date5", "'2015-10-05 00:00:00+0000'"); scriptExecutor.executeScriptTemplate("EntityWithClusteringColumns/insert_many_rows.cql", values); /* Data are ordered as: uuid1, date3, uuid1, date2, uuid1, date1, uuid2, date5, uuid2, date4 because date is ORDERED BY DESC natively */ //When final List<EntityWithClusteringColumns> list = manager.dsl().select().uuid().date().value().fromBaseTable() .where().id_Eq(id).uuid_IN(uuid1, uuid2).date_IN(date3, date5).getList(); //Then assertThat(list).hasSize(2); assertThat(list.stream().map(EntityWithClusteringColumns::getValue).sorted().collect(toList())) .containsExactly("val3", "val5"); }
From source file:net.e2.bw.idreg.db2ldif.Db2Ldif.java
/** * Generate LDIF for all groups/*from w w w . jav a 2 s. c o m*/ * @param db the database * @param ldif the LDIF file to append to */ @SuppressWarnings("all") private void importGroups(TeamworkDB db, StringBuilder ldif, Map<String, String> userNames) { long t0 = System.currentTimeMillis(); String sql = loadResourceText("/groups.sql"); Map<String, StringBuilder> groups = new LinkedHashMap<>(); Connection conn = null; PreparedStatement stmt = null; try { conn = db.getConnection(); stmt = conn.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); int index = 0; while (rs.next()) { String userId = TeamworkDB.getString(rs, "userId"); String companyName = TeamworkDB.getString(rs, "companyName"); String entryUUID = TeamworkDB.getString(rs, "companyId"); String companyId = companyId(companyName); StringBuilder g = groups.get(companyName); if (!groups.containsKey(companyName)) { g = new StringBuilder(); groups.put(companyName, g); Company company = companyData.get(companyId); g.append("dn: cn=").append(companyName).append(",").append(groupsDN).append(NL); g.append("objectClass: top").append(NL); g.append("objectClass: groupOfUniqueNames").append(NL); g.append("objectclass: maritimeResource").append(NL); g.append("objectclass: maritimeOrganization").append(NL); g.append("cn: ").append(companyName).append(NL); g.append("uid: ").append(companyId).append(NL); g.append("mrn: ").append("urn:mrn:mc:org:").append(companyId.toLowerCase().replace(' ', '_')) .append(NL); g.append("entryUUID: ").append(new UUID(Long.parseLong(entryUUID), 0L).toString()).append(NL); if (company != null) { if (company.country.length() == 2) { g.append("c: ").append(company.country).append(NL); } g.append("labeledURI: ").append(company.www).append(NL); g.append("description: ").append(company.description).append(NL); if (includePhotos && company.logo != null) { byte[] img = fetchPhoto(getClass().getResourceAsStream(company.logo), null); if (img != null) { wrapLine(g, "photo:: ", Base64.getEncoder().encodeToString(img)); } } } } String userName = userNames.get(userId); g.append("uniqueMember: uid=").append(userName).append(",").append(peopleDN).append(NL); index++; } rs.close(); groups.values().stream().forEach(g -> ldif.append(g).append(NL)); System.out.println( String.format("Fetched %d groups in %d ms", groups.size(), System.currentTimeMillis() - t0)); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (stmt != null) stmt.close(); } catch (Exception ex) { } try { if (conn != null) conn.close(); } catch (Exception ex) { } } }
From source file:org.cloudgraph.hbase.graph.DefaultAssembler.java
protected UUID fetchUUID(PlasmaType type, long targetSequence, EdgeReader edgeReader, RowReader rowReader) throws IOException { byte[] uuidValue = this.getMetaDataColumnValue(type, targetSequence, EntityMetaKey.UUID, rowReader.getTableReader().getTableConfig(), rowReader); String uuidStr = null;/* w w w. ja va2s. com*/ uuidStr = new String(uuidValue, rowReader.getTableReader().getTableConfig().getCharset()); UUID uuid = null; if (uuidStr.length() == 22) { byte[] bytes = Base64.decodeBase64(uuidStr); ByteBuffer bb = ByteBuffer.wrap(bytes); uuid = new UUID(bb.getLong(), bb.getLong()); } else { uuid = UUID.fromString(uuidStr); } return uuid; }
From source file:com.hp.autonomy.hod.client.api.userstore.user.UserStoreUsersServiceImplITCase.java
@Test public void deleteNonExistentUser() throws HodErrorException { testErrorCode(HodErrorCode.USER_NOT_FOUND, () -> service.delete(getTokenProxy(), getUserStore(), new UUID(0, 0))); }
From source file:org.eclipse.dirigible.runtime.scripting.AbstractScriptExecutor.java
@Override public void registerDefaultVariables(HttpServletRequest request, HttpServletResponse response, Object input, Map<Object, Object> executionContext, IRepository repository, Object scope) { InjectedAPIBuilder apiBuilder = new InjectedAPIBuilder(); if (executionContext == null) { // in case executionContext is not provided from outside executionContext = new HashMap<Object, Object>(); }//from www . ja va 2s.co m // Objects // put the execution context registerDefaultVariable(scope, IInjectedAPIAliases.EXECUTION_CONTEXT, executionContext); apiBuilder.setExecutionContext(executionContext); // put the console Console console = new Console(); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.CONSOLE, console); apiBuilder.setConsole(console); // put the system out registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.SYSTEM_OUTPUT, System.out); apiBuilder.setSystemOutput(System.out); // put the default data source DataSource dataSource = null; dataSource = registerDefaultDatasource(request, executionContext, scope, apiBuilder); // put request registerRequest(request, executionContext, scope, apiBuilder); // put response registerResponse(response, executionContext, scope, apiBuilder); // put repository registerRepository(executionContext, repository, scope, apiBuilder); // user name registerUserName(request, executionContext, scope, apiBuilder); // the input from the execution chain if any registerRequestInput(input, executionContext, scope, apiBuilder); // put JNDI registerInitialContext(request, executionContext, scope, apiBuilder); // Simple binary storage registerBinaryStorage(executionContext, scope, apiBuilder, dataSource); // Simple file storage registerFileStorage(executionContext, scope, apiBuilder, dataSource); // Simple configuration storage registerConfigurationStorage(executionContext, scope, apiBuilder, dataSource); // Services // put mail sender registerMailService(request, executionContext, scope, apiBuilder); // Extension Manager registerExtensionManager(request, executionContext, repository, scope, apiBuilder, dataSource); // Apache Lucene Indexer registerIndexingService(executionContext, scope, apiBuilder); // Connectivity Configuration service registerConnectivityService(executionContext, scope, apiBuilder); // Document service registerDocumentService(executionContext, scope, apiBuilder); // Messaging Service registerMessagingService(request, executionContext, scope, apiBuilder, dataSource); // Templating Service registerTemplatingService(executionContext, scope, apiBuilder); // Executing Service registerExecutingService(executionContext, scope, apiBuilder); // Generation Service registerGenerationService(executionContext, scope, apiBuilder); // Lifecycle Service registerLifecycleService(executionContext, scope, apiBuilder); // Workspaces Service registerWorkspacesService(executionContext, scope, apiBuilder); // Utils // put Apache Commons IOUtils IOUtils ioUtils = new IOUtils(); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.IO_UTILS, ioUtils); apiBuilder.setIOUtils(ioUtils); // put Apache Commons HttpClient and related classes wrapped with a factory like HttpUtils HttpUtils httpUtils = new HttpUtils(); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.HTTP_UTILS, httpUtils); apiBuilder.setHttpUtils(httpUtils); // put Apache Commons Codecs Base64 base64Codec = new Base64(); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.BASE64_UTILS, base64Codec); apiBuilder.setBase64Utils(base64Codec); Hex hexCodec = new Hex(); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.HEX_UTILS, hexCodec); apiBuilder.setHexUtils(hexCodec); DigestUtils digestUtils = new DigestUtils(); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.DIGEST_UTILS, digestUtils); apiBuilder.setDigestUtils(digestUtils); // standard URLEncoder and URLDecoder functionality URLUtils urlUtils = new URLUtils(); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.URL_UTILS, urlUtils); apiBuilder.setUrlUtils(urlUtils); // file upload ServletFileUpload fileUpload = new ServletFileUpload(new DiskFileItemFactory()); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.UPLOAD_UTILS, fileUpload); apiBuilder.setUploadUtils(fileUpload); // UUID UUID uuid = new UUID(0, 0); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.UUID_UTILS, uuid); apiBuilder.setUuidUtils(uuid); // DbUtils DbUtils dbUtils = new DbUtils(dataSource); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.DB_UTILS, dbUtils); apiBuilder.setDatabaseUtils(dbUtils); // EscapeUtils StringEscapeUtils stringEscapeUtils = new StringEscapeUtils(); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.XSS_UTILS, stringEscapeUtils); apiBuilder.setXssUtils(stringEscapeUtils); // XML to JSON and vice-versa XMLUtils xmlUtils = new XMLUtils(); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.XML_UTILS, xmlUtils); apiBuilder.setXmlUtils(xmlUtils); // ExceptionUtils ExceptionUtils exceptionUtils = new ExceptionUtils(); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.EXCEPTION_UTILS, exceptionUtils); apiBuilder.setExceptionUtils(exceptionUtils); // Named DataSources Utils NamedDataSourcesUtils namedDataSourcesUtils = new NamedDataSourcesUtils(request); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.DATASOURCES_UTILS, namedDataSourcesUtils); apiBuilder.setNamedDataSourcesUtils(namedDataSourcesUtils); // register objects via extension try { BundleContext context = RuntimeActivator.getContext(); if (context != null) { Collection<ServiceReference<IContextService>> serviceReferences = context .getServiceReferences(IContextService.class, null); for (ServiceReference<IContextService> serviceReference : serviceReferences) { try { IContextService contextService = context.getService(serviceReference); registerDefaultVariableInContextAndScope(executionContext, scope, contextService.getName(), contextService.getInstance()); apiBuilder.set(contextService.getName(), contextService.getInstance()); } catch (Throwable t) { logger.error(t.getMessage(), t); } } } } catch (InvalidSyntaxException e) { logger.error(e.getMessage(), e); } InjectedAPIWrapper api = new InjectedAPIWrapper(apiBuilder); registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.API, api); }
From source file:org.apache.tinkerpop.gremlin.structure.util.star.StarGraphTest.java
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY) public void shouldAttachWithCreateMethod() { final Random random = new Random(234335l); StarGraph starGraph = StarGraph.open(); Vertex starVertex = starGraph.addVertex(T.label, "person", "name", "stephen", "name", "spmallete"); starVertex.property("acl", true, "timestamp", random.nextLong(), "creator", "marko"); for (int i = 0; i < 100; i++) { starVertex.addEdge("knows", starGraph.addVertex("person", "name", new UUID(random.nextLong(), random.nextLong()), "since", random.nextLong())); starGraph.addVertex(T.label, "project").addEdge("developedBy", starVertex, "public", random.nextBoolean());/*ww w . j a v a 2 s. c om*/ } final Vertex createdVertex = starGraph.getStarVertex().attach(Attachable.Method.create(graph)); starGraph.getStarVertex().edges(Direction.BOTH).forEachRemaining(edge -> ((Attachable<Edge>) edge) .attach(Attachable.Method.create(random.nextBoolean() ? graph : createdVertex))); TestHelper.validateEquality(starVertex, createdVertex); }
From source file:org.cloudgraph.hbase.graph.DefaultAssembler.java
protected UUID findRootUUID(TableReader childTableReader, GraphColumnKeyFactory keyFactory, PlasmaType subType, CellValues childResult) {/* w w w . j a v a 2s . c o m*/ byte[] uuidQual = keyFactory.createColumnKey(subType, EntityMetaKey.UUID); byte[] rootUuid = childResult .getColumnValue(childTableReader.getTableConfig().getDataColumnFamilyNameBytes(), uuidQual); if (rootUuid != null) { String uuidStr = null; uuidStr = new String(rootUuid, childTableReader.getTableConfig().getCharset()); UUID uuid = null; if (uuidStr.length() == 22) { byte[] bytes = Base64.decodeBase64(uuidStr); ByteBuffer bb = ByteBuffer.wrap(bytes); uuid = new UUID(bb.getLong(), bb.getLong()); } else { uuid = UUID.fromString(uuidStr); } return uuid; } return null; }
From source file:com.codelanx.codelanxlib.util.auth.UUIDFetcher.java
/** * Returns a {@link UUID} from a byte array * //from w w w . j a v a2 s . c om * @since 0.0.1 * @version 0.1.0 * * @param array The byte array to convert * @return The new {@link UUID} object * @throws IllegalArgumentException if the array length is not 16 */ public static UUID fromBytes(byte[] array) { Validate.isTrue(array.length == 16, "Illegal byte array length: " + array.length); ByteBuffer byteBuffer = ByteBuffer.wrap(array); long mostSignificant = byteBuffer.getLong(); long leastSignificant = byteBuffer.getLong(); return new UUID(mostSignificant, leastSignificant); }
From source file:org.openmrs.module.DeIdentifiedPatientDataExportModule.api.impl.DeIdentifiedExportServiceImpl.java
private Patient setPatientIdentifier(Patient patient) { UUID u = new UUID(1, 0); try {/* ww w . j a v a 2 s.c om*/ UUID randomUUID = u.randomUUID(); PatientIdentifier pi = new PatientIdentifier(); pi.setIdentifier(randomUUID.toString()); patient.addIdentifier(pi); } catch (Exception e) { e.printStackTrace(); } return patient; }
From source file:com.github.nlloyd.hornofmongo.util.BSONizer.java
@SuppressWarnings("deprecation") private static Object convertScriptableMongoToBSON(ScriptableMongoObject jsMongoObj, boolean isJsObj, String dateFormat) {//from ww w .j a v a 2 s . com Object bsonObject = null; if (jsMongoObj instanceof ObjectId) { bsonObject = ((ObjectId) jsMongoObj).getRealObjectId(); } else if (jsMongoObj instanceof BinData) { BinData binData = (BinData) jsMongoObj; byte type = new Integer(binData.getType()).byteValue(); byte[] data = binData.getDataBytes(); if (type == BSON.B_UUID) { ByteBuffer dataBuffer = ByteBuffer.wrap(data); // mongodb wire protocol is little endian dataBuffer.order(ByteOrder.LITTLE_ENDIAN); long mostSigBits = dataBuffer.getLong(); long leastSigBits = dataBuffer.getLong(); bsonObject = new UUID(mostSigBits, leastSigBits); } else bsonObject = new org.bson.types.Binary(type, data); } else if (jsMongoObj instanceof MinKey) { bsonObject = new org.bson.types.MinKey(); } else if (jsMongoObj instanceof MaxKey) { bsonObject = new org.bson.types.MaxKey(); } else if (jsMongoObj instanceof NumberInt) { bsonObject = Integer.valueOf(((NumberInt) jsMongoObj).getRealInt()); } else if (jsMongoObj instanceof NumberLong) { bsonObject = Long.valueOf(((NumberLong) jsMongoObj).getRealLong()); } else if (jsMongoObj instanceof DBRef) { DBRef jsRef = (DBRef) jsMongoObj; Object id = convertJStoBSON(jsRef.getId(), isJsObj, dateFormat); bsonObject = new com.mongodb.DBRef(jsRef.getNs(), id); } else if (jsMongoObj instanceof Timestamp) { bsonObject = convertTimestampToBSONTimestamp((Timestamp) jsMongoObj); } return bsonObject; }