[#3593] Add support for packages and routines in XMLDatabase
This commit is contained in:
parent
477fda656c
commit
5e1b413a1c
@ -35,7 +35,9 @@
|
||||
|
||||
package org.jooq.util.xml;
|
||||
|
||||
import static org.jooq.tools.StringUtils.defaultIfBlank;
|
||||
import static org.jooq.tools.StringUtils.defaultIfNull;
|
||||
import static org.jooq.tools.StringUtils.isBlank;
|
||||
import static org.jooq.util.xml.jaxb.TableConstraintType.PRIMARY_KEY;
|
||||
import static org.jooq.util.xml.jaxb.TableConstraintType.UNIQUE;
|
||||
|
||||
@ -49,7 +51,9 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
import javax.xml.transform.Transformer;
|
||||
@ -82,6 +86,7 @@ import org.jooq.util.UDTDefinition;
|
||||
import org.jooq.util.xml.jaxb.InformationSchema;
|
||||
import org.jooq.util.xml.jaxb.KeyColumnUsage;
|
||||
import org.jooq.util.xml.jaxb.ReferentialConstraint;
|
||||
import org.jooq.util.xml.jaxb.Routine;
|
||||
import org.jooq.util.xml.jaxb.Schema;
|
||||
import org.jooq.util.xml.jaxb.Sequence;
|
||||
import org.jooq.util.xml.jaxb.Table;
|
||||
@ -378,12 +383,40 @@ public class XMLDatabase extends AbstractDatabase {
|
||||
@Override
|
||||
protected List<RoutineDefinition> getRoutines0() {
|
||||
List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
|
||||
|
||||
for (Routine routine : info().getRoutines()) {
|
||||
if (isBlank(routine.getSpecificPackage()) && isBlank(routine.getRoutinePackage())) {
|
||||
String schemaName = defaultIfBlank(routine.getSpecificSchema(), routine.getRoutineSchema());
|
||||
|
||||
if (getInputSchemata().contains(schemaName)) {
|
||||
SchemaDefinition schema = getSchema(schemaName);
|
||||
|
||||
result.add(new XMLRoutineDefinition(schema, null, info(), routine));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PackageDefinition> getPackages0() {
|
||||
List<PackageDefinition> result = new ArrayList<PackageDefinition>();
|
||||
|
||||
Set<String> packages = new HashSet<String>();
|
||||
for (Routine routine : info().getRoutines()) {
|
||||
String schemaName = defaultIfBlank(routine.getSpecificSchema(), routine.getRoutineSchema());
|
||||
|
||||
if (getInputSchemata().contains(schemaName)) {
|
||||
SchemaDefinition schema = getSchema(schemaName);
|
||||
String packageName = defaultIfBlank(routine.getSpecificPackage(), routine.getRoutinePackage());
|
||||
|
||||
if (packages.add(packageName)) {
|
||||
result.add(new XMLPackageDefinition(schema, info(), packageName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.util.xml;
|
||||
|
||||
import static org.jooq.tools.StringUtils.defaultIfBlank;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jooq.util.AbstractPackageDefinition;
|
||||
import org.jooq.util.AttributeDefinition;
|
||||
import org.jooq.util.RoutineDefinition;
|
||||
import org.jooq.util.SchemaDefinition;
|
||||
import org.jooq.util.xml.jaxb.InformationSchema;
|
||||
import org.jooq.util.xml.jaxb.Routine;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class XMLPackageDefinition extends AbstractPackageDefinition {
|
||||
|
||||
private final InformationSchema info;
|
||||
|
||||
public XMLPackageDefinition(SchemaDefinition schema, InformationSchema info, String packageName) {
|
||||
super(schema, packageName, "");
|
||||
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<RoutineDefinition> getRoutines0() throws SQLException {
|
||||
List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
|
||||
|
||||
for (Routine routine : info.getRoutines()) {
|
||||
String routineName = defaultIfBlank(routine.getSpecificPackage(), routine.getRoutinePackage());
|
||||
|
||||
if (getName().equals(routineName)) {
|
||||
result.add(new XMLRoutineDefinition(getSchema(), this, info, routine));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AttributeDefinition> getConstants0() throws SQLException {
|
||||
List<AttributeDefinition> result = new ArrayList<AttributeDefinition>();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.util.xml;
|
||||
|
||||
import static org.jooq.tools.StringUtils.isBlank;
|
||||
|
||||
import org.jooq.util.AbstractRoutineDefinition;
|
||||
import org.jooq.util.DataTypeDefinition;
|
||||
import org.jooq.util.DefaultDataTypeDefinition;
|
||||
import org.jooq.util.DefaultParameterDefinition;
|
||||
import org.jooq.util.PackageDefinition;
|
||||
import org.jooq.util.SchemaDefinition;
|
||||
import org.jooq.util.xml.jaxb.InformationSchema;
|
||||
import org.jooq.util.xml.jaxb.Routine;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class XMLRoutineDefinition extends AbstractRoutineDefinition {
|
||||
|
||||
private final InformationSchema info;
|
||||
private final Routine routine;
|
||||
|
||||
public XMLRoutineDefinition(SchemaDefinition schema, PackageDefinition pkg, InformationSchema info, Routine routine) {
|
||||
super(schema, pkg, routine.getRoutineName(), "", null);
|
||||
|
||||
this.info = info;
|
||||
this.routine = routine;
|
||||
|
||||
if (!isBlank(routine.getDataType())) {
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(
|
||||
getDatabase(),
|
||||
schema,
|
||||
routine.getDataType(),
|
||||
routine.getCharacterMaximumLength(),
|
||||
routine.getNumericPrecision(),
|
||||
routine.getNumericScale(),
|
||||
null,
|
||||
(String) null
|
||||
);
|
||||
|
||||
this.returnValue = new DefaultParameterDefinition(this, "RETURN_VALUE", -1, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init0() {
|
||||
for (Object parameter : info.getParameters()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user