-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
At deploy time derive a BindMaxLength property to use per BeanProperty
- Loading branch information
Showing
7 changed files
with
136 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
ebean-core/src/main/java/io/ebeaninternal/server/deploy/BindMaxLength.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.ebeaninternal.server.deploy; | ||
|
||
import io.ebean.core.type.InputStreamInfo; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public interface BindMaxLength { | ||
|
||
/** | ||
* Return a UTF8 based implementation. | ||
*/ | ||
static BindMaxLength ofUtf8() { | ||
return new UTF8(); | ||
} | ||
|
||
/** | ||
* Return a standard implementation. | ||
*/ | ||
static BindMaxLength ofStandard() { | ||
return new Standard(); | ||
} | ||
|
||
/** | ||
* Return the length of the object. | ||
*/ | ||
long length(int dbLength, Object obj); | ||
|
||
final class UTF8 implements BindMaxLength { | ||
|
||
@Override | ||
public long length(int dbLength, Object obj) { | ||
if (obj instanceof String) { | ||
String s = (String) obj; | ||
int stringLength = s.length(); | ||
if (stringLength > dbLength) { | ||
return stringLength; | ||
} else if (stringLength * 4 <= dbLength) { | ||
return -1; | ||
} else { | ||
return s.getBytes(StandardCharsets.UTF_8).length; | ||
} | ||
|
||
} else if (obj instanceof byte[]) { | ||
return ((byte[]) obj).length; | ||
} else if (obj instanceof InputStreamInfo) { | ||
return ((InputStreamInfo) obj).length(); | ||
} else { | ||
return -1; | ||
} | ||
} | ||
} | ||
|
||
final class Standard implements BindMaxLength { | ||
|
||
@Override | ||
public long length(int dbLength, Object obj) { | ||
if (obj instanceof String) { | ||
return ((String) obj).length(); | ||
} else if (obj instanceof byte[]) { | ||
return ((byte[]) obj).length; | ||
} else if (obj instanceof InputStreamInfo) { | ||
return ((InputStreamInfo) obj).length(); | ||
} else { | ||
return -1; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters