package io.ebeaninternal.extraddl.model;
import io.ebean.annotation.Platform;
import io.ebean.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.IOException;
import java.io.InputStream;
public class {
private static final Logger logger = LoggerFactory.getLogger(ExtraDdlXmlReader.class);
private static final String = Platform.SQLSERVER.name().toLowerCase();
public static String (String platformName, boolean drops) {
ExtraDdl read = ExtraDdlXmlReader.read("/extra-ddl.xml");
return buildExtra(platformName, drops, read);
}
public static String (String platformName) {
return buildExtra(platformName, false, readBuiltinTablePartitioning());
}
private static String (String platformName, boolean drops, ExtraDdl read) {
if (read == null) {
return null;
}
StringBuilder sb = new StringBuilder(300);
for (DdlScript script : read.getDdlScript()) {
if (script.isDrop() == drops && matchPlatform(platformName, script.getPlatforms())) {
logger.debug("include script {}", script.getName());
String value = script.getValue();
sb.append(value);
if (value.lastIndexOf(';') == -1) {
sb.append(";");
}
sb.append("\n");
}
}
return sb.toString();
}
public static boolean (String platformName, String platforms) {
if (platforms == null || platforms.trim().isEmpty()) {
return true;
}
String genericMatch = genericPlatformMatch(platformName);
for (String name : StringHelper.splitNames(platforms)) {
if (name.toLowerCase().contains(platformName)) {
return true;
} else if (genericMatch != null && genericMatch.equals(name.toLowerCase())) {
return true;
}
}
return false;
}
private static String (String platformName) {
switch (platformName) {
case "sqlserver17":
return SQLSERVER;
case "sqlserver16":
return SQLSERVER;
default:
return null;
}
}
public static ExtraDdl () {
return read("/io/ebeaninternal/dbmigration/builtin-extra-ddl.xml");
}
public static ExtraDdl () {
return read("/io/ebeaninternal/dbmigration/builtin-extra-ddl-partitioning.xml");
}
public static ExtraDdl () {
return read("/extra-ddl.xml");
}
private static ExtraDdl (String resourcePath) {
try (InputStream is = ExtraDdlXmlReader.class.getResourceAsStream(resourcePath)) {
if (is == null) {
return null;
}
return read(is);
} catch (IOException e) {
throw new IllegalStateException("Error on auto close of " + resourcePath, e);
}
}
public static ExtraDdl (InputStream is) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(ExtraDdl.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return (ExtraDdl) unmarshaller.unmarshal(is);
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
}