この値を変更するには、SET LOCK_TIMEOUTを使う。
接続時に値を変更する場合は、下のようにURLの後にLOCK_TIMEOUTを指定する。
jdbc:h2:test;LOCK_TIMEOUT=10000
jdbc:h2:test;LOCK_TIMEOUT=10000
{ "number": 123456789012, "decimal": 1.1 }
result = {number=123456789012, decimal=1.1} number = java.lang.Long decimal = java.lang.Double
objectMapper.enable(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS); objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
result = {number=123456789012, decimal=1.1} number = java.math.BigInteger decimal = java.math.BigDecimal
final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS); objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); final TypeFactory factory = objectMapper.getTypeFactory(); final Mapresult = objectMapper.readValue(inputStream, factory.constructType(Map.class)); System.out.println("result = " + result); outputType(result, "number"); outputType(result, "decimal");
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.3'
public class SampleBean { private Enum value; public Enum getValue() { return value; } public void setValue(final Enum value) { this.value = value; } } enum Enum { A(1), B(2), C(3),; private int value; Enum(final int value) { this.value = value; } @JsonValue public int toValue() { return value; } @JsonCreator public static Enum fromValue(int value) { return Arrays.stream(values()) .filter(v -> v.value == value) .findFirst() .orElseThrow(() -> new IllegalArgumentException(String.valueOf(value))); } }
{"value": 2}
final ObjectMapper objectMapper = new ObjectMapper(); final SampleBean bean = objectMapper.readValue("{\"value\": 2}", SampleBean.class); System.out.println("bean.getValue() = " + bean.getValue()); final String json = objectMapper.writeValueAsString(bean); System.out.println("json = " + json);
bean.getValue() = B json = {"value":2}
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.1'
{"name": "あいうえお"}
class Sample { private String name; private int age; @Override public String toString() { return "Sample{" + "name='" + name + '\'' + ", age=" + age + '}'; } }
final ObjectMapper mapper = new ObjectMapper(); // beanに存在しない属性があっても無視する(例外を発生させない) mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); final String content = "{\"name\": \"あいうえお\"}"; final Sample sample = mapper.readValue(content, Sample.class); System.out.println("sample = " + sample);
sample = Sample{name='null', age=0}
new Expectations() {{ mockList.add("hoge"); minTimes = 0; mockList.get(0); result = "1"; minTimes = 0; }};
@Mocked private ListmockList; @Test public void sample() throws Exception { mockList.add("hoge"); new Verifications() {{ mockList.add(withArgThat(is("hoge"))); }}; }
create context sample_ctx using sample_ctx_manager;
CREATE OR REPLACE PROCEDURE sample_ctx_mgr IS BEGIN dbms_session.set_context( namespace => 'sample_ctx', attribute => 'sample_key', value => 'sample_value' ); END;
07:23:44 SQL> r 1* select * from session_context NAMESPACE ATTRIBUTE VALUE ------------------------------ ------------------------------ ------------------------------ SAMPLE_CTX SAMPLE_KEY sample_value
select sys_context('sample_ctx', 'sample_key') from dual;
set serveroutput on declare segment_owner varchar2(30) := '&owner'; segment_name varchar2(30) := '&table'; segment_type varchar2(30) := 'TABLE'; unformatted_blocks number; unformatted_bytes number; fs1_blocks number; fs1_bytes number; fs2_blocks number; fs2_bytes number; fs3_blocks number; fs3_bytes number; fs4_blocks number; fs4_bytes number; full_blocks number; full_bytes number; begin DBMS_SPACE.SPACE_USAGE( segment_owner, segment_name, segment_type, unformatted_blocks, unformatted_bytes, fs1_blocks, fs1_bytes, fs2_blocks, fs2_bytes, fs3_blocks, fs3_bytes, fs4_blocks, fs4_bytes, full_blocks, full_bytes ); dbms_output.put_line('空き領域が0-25% Blocks = ' || rpad(fs1_blocks, 15) || ' Bytes = ' || fs1_bytes); dbms_output.put_line('空き領域が25-50% Blocks = ' || rpad(fs2_blocks, 15) || ' Bytes = ' || fs2_bytes); dbms_output.put_line('空き領域が50-75% Blocks = ' || rpad(fs3_blocks, 15) || ' Bytes = ' || fs3_bytes); dbms_output.put_line('空き領域が75-100% Blocks = ' || rpad(fs4_blocks, 15) || ' Bytes = ' || fs4_bytes); dbms_output.put_line('一杯になったもの Blocks = ' || rpad(full_blocks, 15) || ' Bytes = ' || full_bytes); end;
空き領域が0-25% Blocks = 0 Bytes = 0 空き領域が25-50% Blocks = 0 Bytes = 0 空き領域が50-75% Blocks = 0 Bytes = 0 空き領域が75-100% Blocks = 22 Bytes = 180224 一杯になったもの Blocks = 286 Bytes = 2342912
空き領域が0-25% Blocks = 0 Bytes = 0 空き領域が25-50% Blocks = 0 Bytes = 0 空き領域が50-75% Blocks = 0 Bytes = 0 空き領域が75-100% Blocks = 308 Bytes = 2523136 一杯になったもの Blocks = 0 Bytes = 0
空き領域が0-25% Blocks = 0 Bytes = 0 空き領域が25-50% Blocks = 0 Bytes = 0 空き領域が50-75% Blocks = 0 Bytes = 0 空き領域が75-100% Blocks = 0 Bytes = 0 一杯になったもの Blocks = 0 Bytes = 0
SQL> create role sample_role identified using hoge.activation_sample_role; Role created.
create or REPLACE PROCEDURE activation_sample_role authid CURRENT_USER AS BEGIN if (SYS_CONTEXT('USERENV','MODULE') = 'SQL*Plus') THEN DBMS_SESSION.set_role('sample_role'); END IF; END;
SQL> grant select on hr.jobs to sample_role; Grant succeeded. SQL> grant sample_role to hoge; Grant succeeded.
SQL> sho user USER is "HOGE" -- ログイン直後のロールの確認 -- sample_roleは付与されていない SQL> select * from session_roles; ROLE -------------------------------------------------------------------------------- RESOURCE -- ロールに与えているオブジェクト権限で参照できるテーブルへアクセスしてみるがエラーとなる。 SQL> select* from hr.jobs; select* from hr.jobs * ERROR at line 1: ORA-00942: table or view does not exist -- ロール有効化のPL/SQLを実行 SQL> execute activation_sample_role; PL/SQL procedure successfully completed. -- ロールの確認 -- 有効になっていることがわかる SQL> select * from session_roles; ROLE -------------------------------------------------------------------------------- SAMPLE_ROLE -- ロールに値ている権限で参照できるテーブルも見れるようになる。 SQL> select* from hr.jobs; JOB_ID JOB_TITLE MIN_SALARY MAX_SALARY ---------- ----------------------------------- ---------- ---------- AD_PRES President 20080 40000
alter user hr password expire;
1* select username, account_status from dba_users where username = 'HR' USERNAME ACCOUNT_STATUS ------------------------------ -------------------------------- HR EXPIRED
08:16:41 SQL> conn hr/password ERROR: ORA-28001: the password has expired hrに対するパスワードを変更しています。 新規パスワード: 新規パスワードを再入力してください: パスワードが変更されました。 接続されました。
@Component @ConfigurationProperties(prefix = "sample") public class SampleConfiguration { private String name; private String hoge; // setterとgetterは省略 }
buildscript { repositories { mavenCentral() maven { url 'https://repo.spring.io/plugins-release' } } dependencies { classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.7' } } configure(allprojects) { apply plugin: 'propdeps' apply plugin: 'propdeps-maven' apply plugin: 'propdeps-idea' apply plugin: 'propdeps-eclipse' } dependencies { optional "org.springframework.boot:spring-boot-configuration-processor" } compileJava.dependsOn(processResources)
{ "groups": [{ "name": "sample", "type": "com.example.SampleConfiguration", "sourceType": "com.example.SampleConfiguration" }], "properties": [ { "name": "sample.hoge", "type": "java.lang.String", "description": "ほげ", "sourceType": "com.example.SampleConfiguration" }, { "name": "sample.name", "type": "java.lang.String", "description": "名前", "sourceType": "com.example.SampleConfiguration" } ], "hints": [] }
configurations.all { resolutionStrategy { force 'junit:junit:4.11' } }
ALTER PROFILE default LIMIT PASSWORD_VERIFY_FUNCTION ora12c_verify_function;
select profile, resource_name, resource_type, limit from dba_profiles where profile = 'DEFAULT' and resource_name='PASSWORD_VERIFY_FUNCTION'
PROFILE RESOURCE_NAME RESOURCE_TYPE LIMIT --------------- ------------------------------ --------------- --------------- DEFAULT PASSWORD_VERIFY_FUNCTION PASSWORD ORA12C_VERIFY_F UNCTION
insert into hoge (binary) values (X'3031323334353637383930');
Hoge.java:3: エラー: 自己終了要素は使用できません
gradlew help --task タスク名
$ ./gradlew help --task dependencyInsight :help Detailed task information for dependencyInsight Path :dependencyInsight Type DependencyInsightReportTask (org.gradle.api.tasks.diagnostics.DependencyInsightReportTask) Options --configuration Looks for the dependency in given configuration. --dependency Shows the details of given dependency. Description Displays the insight into a specific dependency in root project 'spring-boot-in-action'. Group help
Return a result set that contains the last generated auto-increment key for this connection, if there was one. If no key was generated by the last modification statement, then an empty result set is returned. The returned result set only contains the data for the very last row.
compile 'com.h2database:h2:1.3.176'
jdbcDataSource.connection.use {connection -> connection.createStatement().use {statement -> statement.execute("create table test(id bigint auto_increment, name varchar(255))") } connection.prepareStatement("insert into test (name) values (?)").use { ps -> for (i in 1..10) { ps.setString(1, "name_$i") ps.addBatch(); } ps.executeBatch() ps.generatedKeys.use { while (it.next()) { println("it.getInt(1) = ${it.getInt(1)}") } } } }
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.7.2'
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
System.out.println(objectMapper.writeValueAsString(LocalDate.now()));
[ 2016, 3, 8 ]
final ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
// formatを指定してLocalDateSerializerを登録する。
module.addSerializer(new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyyMMdd")));
objectMapper.registerModule(module);
System.out.println(objectMapper.writeValueAsString(LocalDate.now()));
"20160308"
final Sample sample = new Sample(); sample.setName("aa "); sample.setAge(100); // 型とシリアライザのマッピングを定義 final SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(String.class, new TrimSpaceSerializer()); final ObjectMapper objectMapper = new ObjectMapper(); // ObjectMapperにシリアライザの定義を持つモジュールを追加 objectMapper.registerModule(simpleModule); final String result = objectMapper.writeValueAsString(sample); // カスタムなシリアライザ private static class TrimSpaceSerializer extends JsonSerializer{ @Override public void serialize( String value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeString(value.trim()); } }
{"name":"aa","age":100}
Sample sample = new Sample(); sample.setName("aaaa "); StringWriter writer = new StringWriter(); objectMapper.writeValue(writer, sample);
{"name":"aaaa "}
private static class TrimSpaceSerializer extends JsonSerializer<String> { @Override public void serialize( String value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeString(value.trim()); } }
private static class Sample { private String name; @JsonSerialize(using = TrimSpaceSerializer.class) public String getName() { return name; } public void setName(String name) { this.name = name; } }
{"name":"aaaa"}
<p>{{ app.name }}</p> <p>{{ ::app.name }}</p> <input type="text" ng-model="app.name"> <div ng-repeat="user in ::app.users"> <p>{{ user.name }}</p> </div>
■コミット前のステータス $ git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: fuga.txt new file: hoge.txt ■コミット $ git commit -m 'add' -- hoge.txt [master (root-commit) fb9d957] add 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 hoge.txt ■コミット後のステータス $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: fuga.txt ■複数ファイルの場合はスペースで区切る $ git commit -m 'mod' -- hoge.txt piyo.txt
@Entity public class HogeEntity { @Id @GeneratedValue public Long id; @Column(insertable = false, updatable = false) @Generated(GenerationTime.ALWAYS) public Timestamp lastModified; @Override public String toString() { return "HogeEntity{" + "id=" + id + ", lastModified=" + lastModified + '}'; } }
CREATE TABLE `HogeEntity` ( `id` bigint(20) NOT NULL, `lastModified` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) )
HogeEntity entity = new HogeEntity() em.persist(entity) em.flush() System.out.println("entity = " + entity)上のコードを実行した結果は、このようになる。
entity = HogeEntity{id=1, lastModified=2015-12-13 01:29:35.981}
@Rule public ExpectedException expectedException = ExpectedException.none();
@Test public void nullPointerException() throws Exception { expectedException.expect(NullPointerException.class); expectedException.expectMessage("error"); throw new NullPointerException("error"); }
expectedException.expect(CustomException.class); expectedException.expectCause(instanceOf(NullPointerException.class)); throw new CustomException(new NullPointerException());
public static class IsSqlErrorCode extends TypeSafeMatcher{ private final int expectedSqlErrorCode; public IsSqlErrorCode(int expectedSqlErrorCode) { this.expectedSqlErrorCode = expectedSqlErrorCode; } public static IsSqlErrorCode isSqlErrorCode(int expectedSqlErrorCode) { return new IsSqlErrorCode(expectedSqlErrorCode); } @Override protected boolean matchesSafely(SQLException e) { return e.getErrorCode() == expectedSqlErrorCode; } @Override public void describeTo(Description description) { description.appendText("exception with the error code ") .appendValue(expectedSqlErrorCode); } @Override protected void describeMismatchSafely(SQLException item, Description mismatchDescription) { mismatchDescription.appendText("error code was ") .appendValue(item.getErrorCode()); } }
expectedException.expect(SQLException.class); expectedException.expect(IsSqlErrorCode.isSqlErrorCode(1)); throw new SQLException("sql error", null, 1);
// zipのダウンロード String url = "http://www.post.japanpost.jp/zipcode/dl/oogaki/zip/10gumma.zip"; final Path zip = Paths.get("10gumma.zip"); try (InputStream stream = new URL(url).openStream()) { Files.copy(stream, zip, StandardCopyOption.REPLACE_EXISTING); } // zip内のcsvデータを標準出力に出力 try (FileSystem fileSystem = FileSystems.newFileSystem(zip, null)) { Files.walkFileTree(fileSystem.getPath("/"), new SimpleFileVisitor() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { try (BufferedReader reader = Files.newBufferedReader(file, Charset.forName("windows-31j"))) { reader.lines().forEach(System.out::println); } return FileVisitResult.CONTINUE; } }); }