@@ -44,51 +44,81 @@ public String isDatabaseInitialized() {
44
44
return "SELECT count(*) AS count FROM information_schema.tables WHERE table_name = 'artifacts'" ;
45
45
}
46
46
47
+ @ Override
48
+ public String upsertBranch () {
49
+ return """
50
+ MERGE INTO branches AS target
51
+ USING (VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)) AS source (groupId, artifactId, branchId, description, systemDefined, owner, createdOn, modifiedBy, modifiedOn)
52
+ ON (target.groupId = source.groupId AND target.artifactId = source.artifactId AND target.branchId = source.branchId)
53
+ WHEN NOT MATCHED THEN
54
+ INSERT (groupId, artifactId, branchId, description, systemDefined, owner, createdOn, modifiedBy, modifiedOn)
55
+ VALUES (source.groupId, source.artifactId, source.branchId, source.description, source.systemDefined, source.owner, source.createdOn, source.modifiedBy, source.modifiedOn)
56
+ """ ;
57
+ }
58
+
47
59
/**
48
60
* @see io.apicurio.registry.storage.impl.sql.SqlStatements#upsertContent()
49
61
*/
50
62
@ Override
51
63
public String upsertContent () {
52
- return String .join (" " , "MERGE INTO content AS target" ,
53
- "USING (VALUES (?, ?, ?, ?, ?, ?)) AS source (contentId, canonicalHash, contentHash, contentType, content, refs)" ,
54
- "ON (target.contentHash = source.contentHash)" , "WHEN NOT MATCHED THEN" ,
55
- "INSERT (contentId, canonicalHash, contentHash, contentType, content, refs)" ,
56
- "VALUES (source.contentId, source.canonicalHash, source.contentHash, source.contentType, source.content, source.refs);" );
64
+ return """
65
+ MERGE INTO content AS target
66
+ USING (VALUES (?, ?, ?, ?, ?, ?)) AS source (contentId, canonicalHash, contentHash, contentType, content, refs)
67
+ ON (target.contentHash = source.contentHash)
68
+ WHEN NOT MATCHED THEN
69
+ INSERT (contentId, canonicalHash, contentHash, contentType, content, refs)
70
+ VALUES (source.contentId, source.canonicalHash, source.contentHash, source.contentType, source.content, source.refs)
71
+ """ ;
57
72
}
58
73
59
74
/**
60
75
* @see io.apicurio.registry.storage.impl.sql.SqlStatements#getNextSequenceValue()
61
76
*/
62
77
@ Override
63
78
public String getNextSequenceValue () {
64
- return String .join (" " , "MERGE INTO sequences AS target" , "USING (VALUES (?)) AS source (seqName)" ,
65
- "ON (target.seqName = source.seqName)" , "WHEN MATCHED THEN" ,
66
- "UPDATE SET seqValue = target.seqValue + 1" , "WHEN NOT MATCHED THEN" ,
67
- "INSERT (seqName, seqValue)" , "VALUES (source.seqName, 1)" , "OUTPUT INSERTED.seqValue;" );
79
+ return """
80
+ MERGE INTO sequences AS target
81
+ USING (VALUES (?)) AS source (seqName)
82
+ ON (target.seqName = source.seqName)
83
+ WHEN MATCHED THEN
84
+ UPDATE SET seqValue = target.seqValue + 1
85
+ WHEN NOT MATCHED THEN
86
+ INSERT (seqName, seqValue)
87
+ VALUES (source.seqName, 1)
88
+ OUTPUT INSERTED.seqValue
89
+ """ ;
68
90
}
69
91
70
92
/**
71
93
* @see io.apicurio.registry.storage.impl.sql.SqlStatements#resetSequenceValue()
72
94
*/
73
95
@ Override
74
96
public String resetSequenceValue () {
75
- return String .join (" " , "MERGE INTO sequences AS target" ,
76
- "USING (VALUES (?, ?)) AS source (seqName, seqValue)" , "ON (target.seqName = source.seqName)" ,
77
- "WHEN MATCHED THEN" , "UPDATE SET seqValue = ?" , "WHEN NOT MATCHED THEN" ,
78
- "INSERT (seqName, seqValue)" , "VALUES (source.seqName, source.seqValue)" ,
79
- "OUTPUT INSERTED.seqValue;" );
97
+ return """
98
+ MERGE INTO sequences AS target
99
+ USING (VALUES (?, ?)) AS source (seqName, seqValue)
100
+ ON (target.seqName = source.seqName)
101
+ WHEN MATCHED THEN
102
+ UPDATE SET seqValue = ?
103
+ WHEN NOT MATCHED THEN
104
+ INSERT (seqName, seqValue)
105
+ VALUES (source.seqName, source.seqValue)
106
+ OUTPUT INSERTED.seqValue
107
+ """ ;
80
108
}
81
109
82
110
/**
83
111
* @see SqlStatements#upsertContentReference()
84
112
*/
85
113
@ Override
86
114
public String upsertContentReference () {
87
- return String .join (" " , "MERGE INTO content_references AS target" ,
88
- "USING (VALUES (?, ?, ?, ?, ?)) AS source (contentId, groupId, artifactId, version, name)" ,
89
- "ON (target.contentId = source.contentId AND target.name = source.name)" ,
90
- "WHEN NOT MATCHED THEN" , "INSERT (contentId, groupId, artifactId, version, name)" ,
91
- "VALUES (source.contentId, source.groupId, source.artifactId, source.version, source.name);" );
115
+ return """
116
+ MERGE INTO content_references AS target
117
+ USING (VALUES (?, ?, ?, ?, ?)) AS source (contentId, groupId, artifactId, version, name)
118
+ ON (target.contentId = source.contentId AND target.name = source.name)
119
+ WHEN NOT MATCHED THEN", "INSERT (contentId, groupId, artifactId, version, name)
120
+ VALUES (source.contentId, source.groupId, source.artifactId, source.version, source.name)
121
+ """ ;
92
122
}
93
123
94
124
/**
0 commit comments