@@ -41,6 +41,8 @@ public class JMountDaogenDB implements JMount, Serializable {
4141
4242 private EntityDbJvfsFileFacade facade ;
4343
44+ private String rootParentPath ;
45+
4446 public JMountDaogenDB (DataSource ds , EntityDbJvfsFileFacade facade ) throws DAOException {
4547 this ( ConnectionFactoryImpl .newInstance ( ds ), facade );
4648 }
@@ -49,6 +51,7 @@ public JMountDaogenDB(ConnectionFactory cf, EntityDbJvfsFileFacade facade) {
4951 super ();
5052 this .cf = cf ;
5153 this .facade = facade ;
54+ this .rootParentPath = JFile .SEPARATOR +JFile .SEPARATOR ;
5255 }
5356
5457 public static JVFS createJVFSWithPrefix ( ConnectionFactory cf , String prefix ) throws IOException {
@@ -71,12 +74,28 @@ public static JVFS createJVFS( ConnectionFactory cf ) throws IOException {
7174 }
7275 }
7376
77+ public String getParentPath ( PathDescriptor descriptor ) {
78+ String parentPath = descriptor .getParentPath ();
79+ if ( this .rootParentPath != null && JFileUtils .isRoot ( descriptor .getPath () ) ) {
80+ parentPath = this .rootParentPath ;
81+ }
82+ return parentPath ;
83+ }
84+
85+ public String checkParentPath ( String parentPath ) {
86+ String path = parentPath ;
87+ if ( this .rootParentPath != null && this .rootParentPath .equals ( parentPath ) ) {
88+ path = "" ;
89+ }
90+ return path ;
91+ }
92+
7493 @ Override
7594 public JFile getJFile (JVFS jvfs , String point , String relPath ) {
7695 JFile file = null ;
7796 try ( CloseableDAOContext context = this .newContext () ) {
7897 PathDescriptor descriptor = JFileUtils .pathDescriptor (relPath );
79- ModelDbJvfsFile model = this .facade .loadById ( context , descriptor .getName (), descriptor .getParentPath () );
98+ ModelDbJvfsFile model = this .facade .loadById ( context , descriptor .getName (), this .getParentPath (descriptor ) );
8099 file = new DaogenJFileDB (relPath , jvfs , model , this );
81100 } catch (Exception e ) {
82101 throw new ConfigRuntimeException ( "Error loading file " +relPath , e );
@@ -106,8 +125,10 @@ public JFile[] listFiles( DaogenJFileDB file ) throws IOException {
106125 BasicDaoResult <ModelDbJvfsFile > res = this .facade .loadAllByFinder ( context , finder );
107126 if ( res .isResultOk () ) {
108127 list = res .getList ().stream ().map (
109- dbf -> new DaogenJFileDB ( JFileUtils .createPath ( dbf .getParentPath (), dbf .getFileName () ), file .getJVFS (), dbf , this )
128+ dbf -> new DaogenJFileDB ( JFileUtils .createPath ( this . checkParentPath ( dbf .getParentPath () ), dbf .getFileName () ), file .getJVFS (), dbf , this )
110129 ).collect ( Collectors .toList () ).toArray ( new JFile [0 ] );
130+ } else {
131+ throw new DAOException ( "Failed to created listing : " +res );
111132 }
112133 } catch (Exception e ) {
113134 throw new IOException ( "Failed to created directory listing : " +file );
@@ -154,13 +175,13 @@ public boolean updateOrCreate( DaogenJFileDB file, byte[] data ) throws IOExcep
154175 boolean updated = false ;
155176 try ( CloseableDAOContext context = newContext () ) {
156177 PathDescriptor descriptor = JFileUtils .pathDescriptor ( file .getPath () );
157- ModelDbJvfsFile model = this .facade .loadById ( context , descriptor .getName (), descriptor .getParentPath () );
178+ ModelDbJvfsFile model = this .facade .loadById ( context , descriptor .getName (), this .getParentPath (descriptor ) );
158179 boolean create = ( model == null );
159180 Date currentTime = new Date ();
160181 if ( create ) {
161182 model = new HelperDbJvfsFile ();
162183 model .setFileName ( descriptor .getName () );
163- model .setParentPath ( descriptor .getParentPath () );
184+ model .setParentPath ( this .getParentPath (descriptor ) );
164185 model .setCreationTime ( currentTime );
165186 file .setDbFile ( model );
166187 }
0 commit comments