Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
44
Issues
44
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
bff07d26
Commit
bff07d26
authored
Apr 15, 2016
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle BINARY(16) as UUID in Downloads
parent
e424f399
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
201 additions
and
2 deletions
+201
-2
src/main/java/org/genesys2/server/service/impl/CSVResultSetHelper.java
.../org/genesys2/server/service/impl/CSVResultSetHelper.java
+184
-0
src/main/java/org/genesys2/server/service/impl/GenesysServiceImpl.java
.../org/genesys2/server/service/impl/GenesysServiceImpl.java
+1
-1
src/main/java/org/genesys2/util/NumberUtils.java
src/main/java/org/genesys2/util/NumberUtils.java
+16
-1
No files found.
src/main/java/org/genesys2/server/service/impl/CSVResultSetHelper.java
0 → 100644
View file @
bff07d26
package
org.genesys2.server.service.impl
;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.math.BigDecimal
;
import
java.sql.Clob
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
import
org.genesys2.util.NumberUtils
;
import
au.com.bytecode.opencsv.ResultSetHelperService
;
/**
* This class extends {@link ResultSetHelperService} by adding support for UUID.
* Copied straigth from superclass.
*/
public
class
CSVResultSetHelper
extends
ResultSetHelperService
{
public
static
final
int
CLOBBUFFERSIZE
=
2048
;
// note: we want to maintain compatibility with Java 5 VM's
// These types don't exist in Java 5
private
static
final
int
NVARCHAR
=
-
9
;
private
static
final
int
NCHAR
=
-
15
;
private
static
final
int
LONGNVARCHAR
=
-
16
;
private
static
final
int
NCLOB
=
2011
;
/// Copied straight from superclass
@Override
public
String
[]
getColumnValues
(
ResultSet
rs
)
throws
SQLException
,
IOException
{
List
<
String
>
values
=
new
ArrayList
<
String
>();
ResultSetMetaData
metadata
=
rs
.
getMetaData
();
for
(
int
i
=
0
;
i
<
metadata
.
getColumnCount
();
i
++)
{
values
.
add
(
getColumnValue
(
rs
,
metadata
.
getColumnType
(
i
+
1
),
i
+
1
));
}
String
[]
valueArray
=
new
String
[
values
.
size
()];
return
values
.
toArray
(
valueArray
);
}
private
String
handleObject
(
Object
obj
)
{
return
obj
==
null
?
""
:
String
.
valueOf
(
obj
);
}
private
String
handleBigDecimal
(
BigDecimal
decimal
)
{
return
decimal
==
null
?
""
:
decimal
.
toString
();
}
private
String
handleLong
(
ResultSet
rs
,
int
columnIndex
)
throws
SQLException
{
long
lv
=
rs
.
getLong
(
columnIndex
);
return
rs
.
wasNull
()
?
""
:
Long
.
toString
(
lv
);
}
private
String
handleInteger
(
ResultSet
rs
,
int
columnIndex
)
throws
SQLException
{
int
i
=
rs
.
getInt
(
columnIndex
);
return
rs
.
wasNull
()
?
""
:
Integer
.
toString
(
i
);
}
private
String
handleDate
(
ResultSet
rs
,
int
columnIndex
)
throws
SQLException
{
java
.
sql
.
Date
date
=
rs
.
getDate
(
columnIndex
);
String
value
=
null
;
if
(
date
!=
null
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"dd-MMM-yyyy"
);
value
=
dateFormat
.
format
(
date
);
}
return
value
;
}
private
String
handleBinary
(
ResultSet
rs
,
int
colIndex
)
throws
SQLException
{
byte
[]
bs
=
rs
.
getBytes
(
colIndex
);
if
(
bs
==
null
)
{
return
null
;
}
if
(
bs
.
length
==
16
)
{
// UUID?
UUID
uuid
=
NumberUtils
.
toUUID
(
bs
);
return
uuid
.
toString
();
}
else
{
// TODO FIXME What to do with other binary?
return
""
;
}
}
private
String
handleTime
(
Time
time
)
{
return
time
==
null
?
null
:
time
.
toString
();
}
private
String
handleTimestamp
(
Timestamp
timestamp
)
{
SimpleDateFormat
timeFormat
=
new
SimpleDateFormat
(
"dd-MMM-yyyy HH:mm:ss"
);
return
timestamp
==
null
?
null
:
timeFormat
.
format
(
timestamp
);
}
private
String
getColumnValue
(
ResultSet
rs
,
int
colType
,
int
colIndex
)
throws
SQLException
,
IOException
{
String
value
=
""
;
switch
(
colType
)
{
case
Types
.
BIT
:
case
Types
.
JAVA_OBJECT
:
value
=
handleObject
(
rs
.
getObject
(
colIndex
));
break
;
case
Types
.
BOOLEAN
:
boolean
b
=
rs
.
getBoolean
(
colIndex
);
value
=
Boolean
.
valueOf
(
b
).
toString
();
break
;
case
NCLOB:
// todo : use rs.getNClob
case
Types
.
CLOB
:
Clob
c
=
rs
.
getClob
(
colIndex
);
if
(
c
!=
null
)
{
value
=
read
(
c
);
}
break
;
case
Types
.
BIGINT
:
value
=
handleLong
(
rs
,
colIndex
);
break
;
case
Types
.
DECIMAL
:
case
Types
.
DOUBLE
:
case
Types
.
FLOAT
:
case
Types
.
REAL
:
case
Types
.
NUMERIC
:
value
=
handleBigDecimal
(
rs
.
getBigDecimal
(
colIndex
));
break
;
case
Types
.
INTEGER
:
case
Types
.
TINYINT
:
case
Types
.
SMALLINT
:
value
=
handleInteger
(
rs
,
colIndex
);
break
;
case
Types
.
DATE
:
value
=
handleDate
(
rs
,
colIndex
);
break
;
case
Types
.
TIME
:
value
=
handleTime
(
rs
.
getTime
(
colIndex
));
break
;
case
Types
.
TIMESTAMP
:
value
=
handleTimestamp
(
rs
.
getTimestamp
(
colIndex
));
break
;
case
NVARCHAR:
// todo : use rs.getNString
case
NCHAR:
// todo : use rs.getNString
case
LONGNVARCHAR:
// todo : use rs.getNString
case
Types
.
LONGVARCHAR
:
case
Types
.
VARCHAR
:
case
Types
.
CHAR
:
value
=
rs
.
getString
(
colIndex
);
break
;
case
Types
.
BINARY
:
value
=
handleBinary
(
rs
,
colIndex
);
break
;
default
:
// System.err.println("SQLType not handled " + colType);
value
=
""
;
}
if
(
value
==
null
)
{
value
=
""
;
}
return
value
;
}
private
static
String
read
(
Clob
c
)
throws
SQLException
,
IOException
{
StringBuilder
sb
=
new
StringBuilder
((
int
)
c
.
length
());
Reader
r
=
c
.
getCharacterStream
();
char
[]
cbuf
=
new
char
[
CLOBBUFFERSIZE
];
int
n
;
while
((
n
=
r
.
read
(
cbuf
,
0
,
cbuf
.
length
))
!=
-
1
)
{
sb
.
append
(
cbuf
,
0
,
n
);
}
return
sb
.
toString
();
}
}
src/main/java/org/genesys2/server/service/impl/GenesysServiceImpl.java
View file @
bff07d26
...
@@ -1209,7 +1209,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
...
@@ -1209,7 +1209,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
csv
.
writeNext
(
new
String
[]
{
"genesysId"
,
"uuid"
,
"instCode"
,
"acceNumb"
,
"genus"
,
"species"
,
"fullTaxa"
,
"orgCty"
,
"acqSrc"
,
"acqDate"
,
"mlsStat"
,
csv
.
writeNext
(
new
String
[]
{
"genesysId"
,
"uuid"
,
"instCode"
,
"acceNumb"
,
"genus"
,
"species"
,
"fullTaxa"
,
"orgCty"
,
"acqSrc"
,
"acqDate"
,
"mlsStat"
,
"available"
,
"historic"
,
"storage"
,
"sampStat"
,
"duplSite"
,
"createdBy"
,
"createdDate"
,
"lastModifiedBy"
,
"lastModifiedDate"
});
"available"
,
"historic"
,
"storage"
,
"sampStat"
,
"duplSite"
,
"createdBy"
,
"createdDate"
,
"lastModifiedBy"
,
"lastModifiedDate"
});
final
ResultSetHelper
csvResultsetHelper
=
new
ResultSetHelperService
();
final
ResultSetHelper
csvResultsetHelper
=
new
CSVResultSetHelper
();
// Write accession information
// Write accession information
genesysLowlevelRepository
.
listAccessions
(
filters
,
new
RowCallbackHandler
()
{
genesysLowlevelRepository
.
listAccessions
(
filters
,
new
RowCallbackHandler
()
{
...
...
src/main/java/org/genesys2/util/NumberUtils.java
View file @
bff07d26
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
package
org.genesys2.util
;
package
org.genesys2.util
;
import
java.util.UUID
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
...
@@ -96,7 +97,21 @@ public abstract class NumberUtils {
...
@@ -96,7 +97,21 @@ public abstract class NumberUtils {
}
}
v
+=
d
;
v
+=
d
;
}
}
return
v
;
return
v
;
}
}
/**
* UUID from byte[]
*/
public
static
UUID
toUUID
(
byte
[]
data
)
{
long
msb
=
0
;
long
lsb
=
0
;
assert
data
.
length
==
16
:
"data must be 16 bytes in length"
;
for
(
int
i
=
0
;
i
<
8
;
i
++)
msb
=
(
msb
<<
8
)
|
(
data
[
i
]
&
0xff
);
for
(
int
i
=
8
;
i
<
16
;
i
++)
lsb
=
(
lsb
<<
8
)
|
(
data
[
i
]
&
0xff
);
return
new
UUID
(
msb
,
lsb
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment