List of usage examples for java.util UUID nameUUIDFromBytes
public static UUID nameUUIDFromBytes(byte[] name)
From source file:org.apache.kylin.source.jdbc.JdbcExplorer.java
@Override public ColumnDesc[] evalQueryMetadata(String query) { if (StringUtils.isEmpty(query)) { throw new RuntimeException("Evaluate query shall not be empty."); }//from www. jav a 2s . c o m KylinConfig config = KylinConfig.getInstanceFromEnv(); String tmpDatabase = config.getHiveDatabaseForIntermediateTable(); String tmpView = tmpDatabase + ".kylin_eval_query_" + UUID.nameUUIDFromBytes(query.getBytes(StandardCharsets.UTF_8)).toString().replaceAll("-", ""); String dropViewSql = "DROP VIEW IF EXISTS " + tmpView; String evalViewSql = "CREATE VIEW " + tmpView + " as " + query; Connection con = null; ResultSet rs = null; try { logger.debug("Removing duplicate view {}", tmpView); executeSQL(dropViewSql); logger.debug("Creating view {} for query: {}", tmpView, query); executeSQL(evalViewSql); logger.debug("Evaluating query columns' metadata"); con = SqlUtil.getConnection(dbconf); DatabaseMetaData dbmd = con.getMetaData(); rs = dbmd.getColumns(null, tmpDatabase, tmpView, null); ColumnDesc[] result = extractColumnFromMeta(rs); return result; } catch (SQLException e) { throw new RuntimeException("Cannot evaluate metadata of query: " + query, e); } finally { DBUtils.closeQuietly(con); DBUtils.closeQuietly(rs); try { logger.debug("Cleaning up temp view."); executeSQL(dropViewSql); } catch (SQLException e) { logger.warn("Failed to clean up temp view of query: {}", query, e); } } }
From source file:org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.java
/** @return UUID for composite key */ public static UUID keyID(Object... objects) { if (objects.length == 1) { Object obj = objects[0];/*from w w w . j a v a 2 s . c o m*/ if (obj instanceof UUID) { return (UUID) obj; } } String keyStr = key(objects).toString(); if (keyStr.length() == 0) { return NULL_ID; } UUID uuid = UUID.nameUUIDFromBytes(keyStr.getBytes()); logger.debug("Key {} equals UUID {}", keyStr, uuid); return uuid; }
From source file:com.edgenius.wiki.plugin.PluginServiceImpl.java
public String getPluginUuid(String pluginClz) { return UUID.nameUUIDFromBytes(pluginClz.getBytes()).toString(); }
From source file:org.wso2.andes.mqtt.utils.MQTTUtils.java
/** * Generate a unique UUID for a given client who has subscribed to a given topic with given qos and given clean * session.//from ww w .j a va 2 s .com * * @param clientId The MQTT client Id * @param topic The topic subscribed to * @param qos The Quality of Service level subscribed to * @param cleanSession Clean session value of the client * @return A unique UUID for the given arguments */ public static UUID generateSubscriptionChannelID(String clientId, String topic, int qos, boolean cleanSession) { return UUID.nameUUIDFromBytes((clientId + topic + qos + cleanSession).getBytes()); }
From source file:cz.mzk.editor.server.handler.ScanFolderHandler.java
private ScanFolderResult handlePdf(String pdfPath) throws ActionException { String uuid = UUID.nameUUIDFromBytes(new File(pdfPath).getAbsolutePath().getBytes()).toString(); String newPdfPath = configuration.getImagesPath() + uuid + Constants.PDF_EXTENSION; try {/*w w w . j a v a 2 s .c o m*/ IOUtils.copyFile(pdfPath, newPdfPath); LOGGER.info("Pdf file " + pdfPath + " has been copied to " + newPdfPath); } catch (IOException e) { LOGGER.error(e.getMessage()); e.printStackTrace(); throw new ActionException(e); } ArrayList<ImageItem> result = new ArrayList<ImageItem>(1); result.add(new ImageItem(uuid, newPdfPath, pdfPath)); try { imageResolverDAO.insertItems(result); } catch (DatabaseException e) { e.printStackTrace(); throw new ActionException(e); } return new ScanFolderResult(result, null, new ServerActionResult(SERVER_ACTION_RESULT.OK_PDF)); }
From source file:fr.gael.dhus.service.MetadataTypeService.java
/** * Default constructor loading metadata types associated to all item classes * known by the current DRB Cortex model. * <p>//from ww w. j a va 2 s .c o m * The access to the default DRB Cortex model is required during this * initialization. Otherwise, the initialization is aborted and the Service * will not return any metadata type. * </p> * <p> * The initialization loops among all item class of the DRB Cortex model. The * classes with no attached metadata type definitions i.e. * <code>metadataTypes</code> property, are discarded to same memory * footprint. For the others, the metadata type definitions in XML are parsed * and the resulting classes are stored in an instance of the multi-indexed * {@link ItemClassMetadataTypes} according to the type identifier and the * type name for performance purpose. Also for performance purpose, the * metadata type XML definitions are parsed only once and the result are * shared between {@link ItemClassMetadataTypes} thanks to a cache based on a * UUID hash. * </p> */ public MetadataTypeService() { // Log initialization start logger.info("Initializing Metadata Typing Service..."); // Get a time stamps of the initialization start final Date start_time = new Date(); // Initialize an empty map this.mapItemClassByUri = new ConcurrentHashMap<String, ItemClassMetadataTypes>(); // Get current DRB Cortex Model DrbCortexModel model = null; try { model = DrbCortexModel.getDefaultModel(); } catch (final IOException exception) { logger.error("Error while getting current DRB Cortex model " + "(aborting Metadata Typing service).", exception); logger.info("Aborting MetadataTypeService inititialization " + "with no metadata type defined!"); return; } // Get an iterator over all DRB Cortex classes final ExtendedIterator ont_class_iterator = model.getCortexModel().getOntModel().listClasses(); // Prepare a map of parsed metadata type declarations final Map<UUID, List<MetadataType>> cached_metadata_types = new ConcurrentHashMap<UUID, List<MetadataType>>(); // Prepare a parser for XML definitions of metadata types MetadataTypeParser metadata_type_parser; try { metadata_type_parser = new MetadataTypeParser(); } catch (final JAXBException exception) { logger.error("Cannot create a parser for the XML definitions of " + "metadata types.", exception); logger.info("Aborting MetadataTypeService inititialization " + "with no metadata type defined!"); return; } // Loop among Ontology classes while (ont_class_iterator.hasNext()) { // Extracts current class from the iterator final OntClass ont_class = (OntClass) ont_class_iterator.next(); // Get current class URI final String uri = ont_class.getURI(); // Skip classes without URI - case unforeseen by theory if (uri == null) { if (logger.isDebugEnabled()) { logger.debug("Skipping current Ontology class that has no URI " + "(local name = \"" + ont_class.getLocalName() + "\")."); } continue; } if (logger.isDebugEnabled()) { logger.debug("Processing Ontology class \"" + uri + "\""); } // Get corresponding DRB Cortex class final DrbCortexItemClass item_class = DrbCortexItemClass.getCortexItemClassByName(uri); // Check resulting item class if (item_class == null) { logger.error("Cannot derive DRB Cortex item class from URI " + "\"" + uri + "\"."); continue; } // Prepare a container for the current item class metadata types final ItemClassMetadataTypes class_metadata_types = new ItemClassMetadataTypes(uri, item_class.getLabel()); // Get all URIs of matadataTypes property describing the present item // class or any of its ancestors final Collection<String> xml_metadata_types_list = item_class .listPropertyStrings(DHUS_NAMESPACE + METADATA_TYPES_PROPERTY, false); // Loop immediately if the current item class has no attached // metadataTypes if ((xml_metadata_types_list == null) || xml_metadata_types_list.isEmpty()) { if (logger.isDebugEnabled()) { logger.debug("Item class \"" + item_class.getLabel() + "\" (" + uri + ") has no attached metadata type definition " + "(skipped)."); } continue; } // Prepare the list of metadata types to be parsed or retrieved from // the cache final List<MetadataType> metadata_types = new ArrayList<>(); // Loop among XML definitions of metadata types for (final String xml_metadata_types : xml_metadata_types_list) { if (logger.isDebugEnabled()) { logger.debug("Found metadataTypes string \"" + xml_metadata_types.substring(0, 30) + "...\""); } // Get a unique identifier of the current xml content final UUID uuid = UUID.nameUUIDFromBytes(xml_metadata_types.getBytes()); // Get the already parsed types if cached if (cached_metadata_types.containsKey(uuid)) { logger.debug("Metadata Types already parsed (copied from cache)"); metadata_types.addAll(cached_metadata_types.get(uuid)); } else { logger.debug("Parsing XML definition of Metadata Types..."); List<MetadataType> parsed_metadata_types = null; final String rooted_xml_metadata_types = "<" + METADATA_TYPES_ELEMENT_NAME + ">" + xml_metadata_types + "</" + METADATA_TYPES_ELEMENT_NAME + ">"; try { parsed_metadata_types = metadata_type_parser.parse(rooted_xml_metadata_types); } catch (NullPointerException | IllegalStateException | JAXBException exception) { logger.error("Cannot parse XML metadata type definition of " + "class \"" + uri + "\" (" + rooted_xml_metadata_types + ") - skipped.", exception); continue; } if (parsed_metadata_types != null) { if (logger.isDebugEnabled()) { logger.debug("Parsed " + parsed_metadata_types.size() + " metadata types."); } metadata_types.addAll(parsed_metadata_types); cached_metadata_types.put(uuid, parsed_metadata_types); } } } // Loop among XML definitions of metadata types // Index metadata types in the item class representative if (!metadata_types.isEmpty()) { class_metadata_types.addAllMetadataTypes(metadata_types); logger.info("Item class \"" + class_metadata_types.getLabel() + "\" (" + class_metadata_types.getUri() + ") has " + metadata_types.size() + " metadata types."); this.mapItemClassByUri.put(uri, class_metadata_types); } } // Loop among Ontology classes logger.info("Metadata Typing Service initialized in " + (new Date().getTime() - start_time.getTime()) + " ms with " + this.mapItemClassByUri.size() + " item class(es)."); }
From source file:org.apache.nifi.web.api.ApplicationResource.java
protected String generateUuid() { final Optional<String> seed = getIdGenerationSeed(); UUID uuid;//from w w w .java 2s. co m if (seed.isPresent()) { try { UUID seedId = UUID.fromString(seed.get()); uuid = new UUID(seedId.getMostSignificantBits(), seed.get().hashCode()); } catch (Exception e) { logger.warn( "Provided 'seed' does not represent UUID. Will not be able to extract most significant bits for ID generation."); uuid = UUID.nameUUIDFromBytes(seed.get().getBytes(StandardCharsets.UTF_8)); } } else { uuid = ComponentIdGenerator.generateId(); } return uuid.toString(); }
From source file:org.nuxeo.apidoc.documentation.DocumentationComponent.java
@Override public DocumentationItem createDocumentationItem(CoreSession session, NuxeoArtifact item, String title, String content, String type, List<String> applicableVersions, boolean approved, String renderingType) { DocumentModel doc = session.createDocumentModel(DocumentationItem.TYPE_NAME); String name = title + '-' + item.getId(); name = IdUtils.generateId(name, "-", true, 64); UUID docUUID = UUID.nameUUIDFromBytes(name.getBytes()); doc.setPathInfo(getDocumentationRoot(session).getPathAsString(), name); doc.setPropertyValue("dc:title", title); Blob blob = Blobs.createBlob(content); blob.setFilename(type);//from www. j a v a 2 s . c o m doc.setPropertyValue("file:content", (Serializable) blob); doc.setPropertyValue(DocumentationItem.PROP_TARGET, item.getId()); doc.setPropertyValue(DocumentationItem.PROP_TARGET_TYPE, item.getArtifactType()); doc.setPropertyValue(DocumentationItem.PROP_DOCUMENTATION_ID, docUUID.toString()); doc.setPropertyValue(DocumentationItem.PROP_NUXEO_APPROVED, Boolean.valueOf(approved)); doc.setPropertyValue(DocumentationItem.PROP_TYPE, type); doc.setPropertyValue(DocumentationItem.PROP_RENDERING_TYPE, renderingType); doc.setPropertyValue(DocumentationItem.PROP_APPLICABLE_VERSIONS, (Serializable) applicableVersions); doc = session.createDocument(doc); session.save(); return doc.getAdapter(DocumentationItem.class); }
From source file:com.orange.clara.cloud.servicedbdumper.fake.cloudfoundry.CloudFoundryClientFake.java
@Override public CloudService getService(String service) { if (service.equals(SERVICE_NOT_ACCESSIBLE)) { return null; }/*from w w w. j a va 2 s . c om*/ return new CloudService( new CloudEntity.Meta(UUID.nameUUIDFromBytes(service.getBytes()), new Date(), new Date()), service); }
From source file:org.springframework.amqp.rabbit.stocks.context.RefreshScope.java
/** * If the bean factory is a DefaultListableBeanFactory then it can serialize scoped beans and deserialize them in * another context (even in another JVM), as long as the ids of the bean factories match. This method sets up the * serialization id to be either the id provided to the scope instance, or if that is null, a hash of all the bean * names./* w w w.j a va 2 s . co m*/ * * @param beanFactory the bean factory to configure */ private void setSerializationId(ConfigurableListableBeanFactory beanFactory) { if (beanFactory instanceof DefaultListableBeanFactory) { String id = this.id; if (id == null) { String names = Arrays.asList(beanFactory.getBeanDefinitionNames()).toString(); logger.debug("Generating bean factory id from names: " + names); id = UUID.nameUUIDFromBytes(names.getBytes()).toString(); } logger.info("BeanFactory id=" + id); ((DefaultListableBeanFactory) beanFactory).setSerializationId(id); } else { logger.warn("BeanFactory was not a DefaultListableBeanFactory, so RefreshScope beans " + "cannot be serialized reliably and passed to a remote JVM."); } }