Search in sources :

Example 1 with MCRStreamQuery

use of org.mycore.backend.jpa.MCRStreamQuery in project mycore by MyCoRe-Org.

the class MCRIFSCommands method moveContentToNewStore.

private static List<String> moveContentToNewStore(String source_store, String target_store, String select_key, String select_value) {
    // check stores
    MCRContentStore from_store = MCRContentStoreFactory.getStore(source_store);
    @SuppressWarnings("unused") MCRContentStore to_store = MCRContentStoreFactory.getStore(target_store);
    EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
    MCRStreamQuery<MCRFSNODES> streamQuery = MCRStreamQuery.getInstance(em, "from MCRFSNODES where storeid=:storeid and " + select_key + "=:selectValue order by owner", MCRFSNODES.class).setParameter("storeid", from_store.getID()).setParameter("selectValue", select_value);
    try (Stream<MCRFSNODES> resultStream = streamQuery.getResultStream()) {
        return resultStream.peek(em::detach).map(MCRFSNODES::getId).map(ifsId -> String.format(Locale.ROOT, "move ifs node %s to store %s", ifsId, target_store)).collect(Collectors.toList());
    }
}
Also used : Transformer(javax.xml.transform.Transformer) Arrays(java.util.Arrays) Date(java.util.Date) StreamResult(javax.xml.transform.stream.StreamResult) FileTime(java.nio.file.attribute.FileTime) MCRStreamQuery(org.mycore.backend.jpa.MCRStreamQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) MCRXMLMetadataManager(org.mycore.datamodel.common.MCRXMLMetadataManager) MCRFSNODES(org.mycore.backend.hibernate.tables.MCRFSNODES) URI(java.net.URI) Method(java.lang.reflect.Method) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ParameterExpression(javax.persistence.criteria.ParameterExpression) GregorianCalendar(java.util.GregorianCalendar) TimeZone(java.util.TimeZone) StandardOpenOption(java.nio.file.StandardOpenOption) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) MCREntityManagerProvider(org.mycore.backend.jpa.MCREntityManagerProvider) MCRUtils(org.mycore.common.MCRUtils) List(java.util.List) Attributes2Impl(org.xml.sax.ext.Attributes2Impl) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) SAXException(org.xml.sax.SAXException) MCRContentStoreFactory(org.mycore.datamodel.ifs.MCRContentStoreFactory) Session(org.hibernate.Session) MCRConfiguration(org.mycore.common.config.MCRConfiguration) TypedQuery(javax.persistence.TypedQuery) MCRException(org.mycore.common.MCRException) MessageFormat(java.text.MessageFormat) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) MCRFSNODES_(org.mycore.backend.hibernate.tables.MCRFSNODES_) Charset(java.nio.charset.Charset) MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) MCRContentStore(org.mycore.datamodel.ifs.MCRContentStore) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) MCRCommandGroup(org.mycore.frontend.cli.annotation.MCRCommandGroup) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) Root(javax.persistence.criteria.Root) MCRFile(org.mycore.datamodel.ifs.MCRFile) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) NotDirectoryException(java.nio.file.NotDirectoryException) MCRHIBConnection(org.mycore.backend.hibernate.MCRHIBConnection) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) EntityManager(javax.persistence.EntityManager) OutputKeys(javax.xml.transform.OutputKeys) Field(java.lang.reflect.Field) File(java.io.File) NameFileComparator(org.apache.commons.io.comparator.NameFileComparator) TransformerHandler(javax.xml.transform.sax.TransformerHandler) LogManager(org.apache.logging.log4j.LogManager) EntityManager(javax.persistence.EntityManager) MCRContentStore(org.mycore.datamodel.ifs.MCRContentStore) MCRFSNODES(org.mycore.backend.hibernate.tables.MCRFSNODES)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 Files (java.nio.file.Files)1 NotDirectoryException (java.nio.file.NotDirectoryException)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 FileTime (java.nio.file.attribute.FileTime)1 MessageFormat (java.text.MessageFormat)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1