labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joc...@apache.org
Subject svn commit: r680187 [4/6] - in /labs/jaxmas/trunk/JaxMas: ./ .settings/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/labs/ src/main/java/org/apache/labs/jaxmas/ src/main/java/org/apache/labs/jaxmas...
Date Sun, 27 Jul 2008 21:13:03 GMT
Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/ServiceImpl.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/ServiceImpl.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/ServiceImpl.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/ServiceImpl.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.infomodel;
+
+import java.util.Collection;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.Service;
+import javax.xml.registry.infomodel.ServiceBinding;
+
+import org.apache.labs.jaxmas.registry.accessor.ROAccessor;
+import org.apache.labs.jaxmas.registry.accessor.ServiceAccessor;
+
+
+
+/**
+ * Implementation of {@link Service}.
+ */
+public class ServiceImpl extends RegistryEntryImpl<Service> implements Service {
+    /**
+     * Creates a new instance with the given registry service and key.
+     */
+    public ServiceImpl(RegistryServiceImpl pRegistryService, Key pKey) {
+        super(pRegistryService, pKey);
+    }
+
+    @Override
+    public void addServiceBinding(ServiceBinding pServiceBinding)
+            throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void addServiceBindings(Collection pServiceBindings)
+            throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @Override
+    public Organization getProvidingOrganization() throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Collection getServiceBindings() throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @Override
+    public void removeServiceBinding(ServiceBinding pServiceBinding)
+            throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void removeServiceBindings(Collection pServiceBindings)
+            throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @Override
+    public void setProvidingOrganization(Organization pOrganization)
+            throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @Override
+    public ROAccessor<Service> getROLoader() {
+        return ServiceAccessor.getInstance();
+    }
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/SlotImpl.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/SlotImpl.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/SlotImpl.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/SlotImpl.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.infomodel;
+
+import java.util.Collection;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.infomodel.Slot;
+
+
+/**
+ * Default implementation of {@link Slot}.
+ */
+public class SlotImpl implements Slot {
+	private String name;
+	private String slotType;
+	private Collection<?> values;
+
+	@Override
+	public String getName() throws JAXRException {
+		return name;
+	}
+
+	@Override
+	public void setName(String pName) throws JAXRException {
+		name = pName;
+	}
+
+	@Override
+	public String getSlotType() throws JAXRException {
+		return slotType;
+	}
+
+	@Override
+	public void setSlotType(String pSlotType) throws JAXRException {
+		slotType = pSlotType;
+	}
+
+	@Override
+	public Collection<?> getValues() throws JAXRException {
+		return values;
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public void setValues(Collection pValues) throws JAXRException {
+		values = pValues;
+	}
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/SpecificationLinkImpl.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/SpecificationLinkImpl.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/SpecificationLinkImpl.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/SpecificationLinkImpl.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.infomodel;
+
+import java.util.Collection;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.infomodel.InternationalString;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.RegistryObject;
+import javax.xml.registry.infomodel.ServiceBinding;
+import javax.xml.registry.infomodel.SpecificationLink;
+
+import org.apache.labs.jaxmas.registry.accessor.ROAccessor;
+import org.apache.labs.jaxmas.registry.accessor.SpecificationLinkAccessor;
+
+
+/**
+ * Implementtion of {@link SpecificationLink}.
+ */
+public class SpecificationLinkImpl extends RegistryObjectImpl<SpecificationLink> implements SpecificationLink {
+    /**
+     * Creates a new instance with the given registry service and key.
+     */
+    public SpecificationLinkImpl(RegistryServiceImpl pRegistryService, Key pKey) {
+        super(pRegistryService, pKey);
+    }
+
+    @Override
+    public ROAccessor<SpecificationLink> getROLoader() {
+        return SpecificationLinkAccessor.getInstance();
+    }
+
+    @Override
+    public ServiceBinding getServiceBinding() throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @Override
+    public RegistryObject getSpecificationObject() throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @Override
+    public InternationalString getUsageDescription() throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Collection getUsageParameters() throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @Override
+    public void setSpecificationObject(RegistryObject pObj)
+            throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @Override
+    public void setUsageDescription(InternationalString pUsageDescription)
+            throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void setUsageParameters(Collection pUsageParameters)
+            throws JAXRException {
+        throw new JAXRException(NLSStrings.OPERATION_NOT_IMPLEMENTED);
+    }
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/TelephoneNumberImpl.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/TelephoneNumberImpl.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/TelephoneNumberImpl.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/TelephoneNumberImpl.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.infomodel;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.infomodel.TelephoneNumber;
+
+
+/**
+ * Default implementation of {@link TelephoneNumber}.
+ */
+public class TelephoneNumberImpl implements TelephoneNumber {
+	private String areaCode, countryCode, extension, number, type, url;
+
+	@Override
+	public String getAreaCode() throws JAXRException {
+		return areaCode;
+	}
+
+	@Override
+	public String getCountryCode() throws JAXRException {
+		return countryCode;
+	}
+
+	@Override
+	public String getExtension() throws JAXRException {
+		return extension;
+	}
+
+	@Override
+	public String getNumber() throws JAXRException {
+		return number;
+	}
+
+	@Override
+	public String getType() throws JAXRException {
+		return type;
+	}
+
+	@Override
+	public String getUrl() throws JAXRException {
+		return url;
+	}
+
+	@Override
+	public void setAreaCode(String pAreaCode) throws JAXRException {
+		areaCode = pAreaCode;
+	}
+
+	@Override
+	public void setCountryCode(String pCountryCode) throws JAXRException {
+		countryCode = pCountryCode;
+	}
+
+	@Override
+	public void setExtension(String pExtension) throws JAXRException {
+		extension = pExtension;
+	}
+
+	@Override
+	public void setNumber(String pNumber) throws JAXRException {
+		number = pNumber;
+	}
+
+	@Override
+	public void setType(String pType) throws JAXRException {
+		type = pType;
+	}
+
+	@Override
+	public void setUrl(String pUrl) throws JAXRException {
+		url = pUrl;
+	}
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/UserImpl.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/UserImpl.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/UserImpl.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/infomodel/UserImpl.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,144 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.infomodel;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.infomodel.EmailAddress;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.PersonName;
+import javax.xml.registry.infomodel.PostalAddress;
+import javax.xml.registry.infomodel.TelephoneNumber;
+import javax.xml.registry.infomodel.User;
+
+import org.apache.labs.jaxmas.registry.accessor.ROAccessor;
+import org.apache.labs.jaxmas.registry.accessor.UserAccessor;
+
+
+/**
+ * Default implementation of {@link User}.
+ */
+public class UserImpl extends RegistryObjectImpl<User> implements User {
+    private URL url;
+	private String type;
+	private Organization organization;
+	private PersonName personName;
+	private Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
+	private Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
+	private Collection<TelephoneNumber> telephoneNumbers = new ArrayList<TelephoneNumber>();
+
+	/**
+	 * Creates a new instance.
+	 */
+	public UserImpl(RegistryServiceImpl pRegistryService, Key pKey) {
+		super(pRegistryService, pKey);
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public Collection getEmailAddresses() throws JAXRException {
+		return emailAddresses;
+	}
+
+	@Override
+	public Organization getOrganization() throws JAXRException {
+		return organization;
+	}
+
+	@Override
+	public PersonName getPersonName() throws JAXRException {
+		return personName;
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public Collection getPostalAddresses() throws JAXRException {
+		return postalAddresses;
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public Collection getTelephoneNumbers(String pPhoneType) throws JAXRException {
+		return telephoneNumbers;
+	}
+
+	@Override
+	public String getType() throws JAXRException {
+		return type;
+	}
+
+	@Override
+	public URL getUrl() throws JAXRException {
+		return url;
+	}
+
+	@SuppressWarnings({"unchecked", "cast"})
+	@Override
+	public void setEmailAddresses(Collection pAddresses) throws JAXRException {
+		if (pAddresses == null) {
+			emailAddresses.clear();
+		} else {
+			emailAddresses = (Collection<EmailAddress>) pAddresses;
+		}
+	}
+
+	@Override
+	public void setPersonName(PersonName pPersonName) throws JAXRException {
+		personName = pPersonName;
+	}
+
+	@SuppressWarnings({"unchecked", "cast"})
+	@Override
+	public void setPostalAddresses(Collection pAddresses) throws JAXRException {
+		if (pAddresses == null) {
+			postalAddresses.clear();
+		} else {
+			postalAddresses = (Collection<PostalAddress>) pAddresses;
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public void setTelephoneNumbers(Collection pPhoneNumbers) throws JAXRException {
+		if (pPhoneNumbers == null) {
+			telephoneNumbers.clear();
+		} else {
+			telephoneNumbers = pPhoneNumbers;
+		}
+	}
+
+	@Override
+	public void setType(String pType) throws JAXRException {
+		type = pType;
+	}
+
+	@Override
+	public void setUrl(URL pUrl) throws JAXRException {
+		url = pUrl;
+	}
+
+	@Override
+    public ROAccessor<User> getROLoader() {
+	    return UserAccessor.getInstance();
+	}
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/DbInitializer.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/DbInitializer.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/DbInitializer.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/DbInitializer.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,238 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.schema;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.RegistryService;
+
+import org.apache.labs.jaxmas.registry.infomodel.ConnectionImpl;
+import org.apache.labs.jaxmas.registry.infomodel.RegistryServiceImpl;
+import org.apache.labs.jaxmas.registry.sql.DbDriver;
+import org.apache.labs.jaxmas.registry.util.DefaultLoggerFactory;
+import org.apache.labs.jaxmas.registry.util.Logger;
+import org.apache.labs.jaxmas.registry.util.Strings;
+
+/**
+ * The database initializer is invoked at startup. It checks,
+ * whether the database structure is as expected and updates
+ * it, if required.
+ */
+public class DbInitializer {
+	private static final Logger log = DefaultLoggerFactory.getInstance().newLogger(DbInitializer.class);
+
+	private ConnectionImpl connection;
+
+	/**
+	 * Creates a new instance, which uses the given connection to
+	 * initialize the database.
+	 */
+	public DbInitializer(ConnectionImpl pConnection) {
+		connection = pConnection;
+	}
+
+	/**
+	 * Returns the connection.
+	 */
+	protected ConnectionImpl getConnection() {
+		return connection;
+	}
+
+	/**
+	 * Returns the registry service.
+	 */
+	protected RegistryService getRegistryService() throws JAXRException {
+		return connection.getRegistryService();
+	}
+
+	/**
+	 * Returns the database driver.
+	 */
+	protected DbDriver getDbDriver() throws JAXRException {
+		return ((RegistryServiceImpl) getRegistryService()).getDbDriver();
+	}
+
+	/**
+	 * Returns, whether the character sequence contains a string, which
+	 * ends with the character ';'. Terminating white space is ignored.
+	 */
+	private boolean endsWithSemicolon(CharSequence pCharSequence) {
+		for (int i = pCharSequence.length()-1;  i >= 0;  i--) {
+			char c = pCharSequence.charAt(i);
+			if (!Character.isWhitespace(c)) {
+				return c == ';';
+			}
+		}
+		return false; // Only white space found
+	}
+
+	private String replaceProperties(String pCommand) throws JAXRException {
+	    String command = pCommand;
+	    for (;;) {
+	        int offset = command.indexOf("${"); //$NON-NLS-1$
+	        if (offset == -1) {
+	            return command;
+	        }
+	        int end = command.indexOf('}', offset+2);
+	        if (offset == -1) {
+	            throw new IllegalStateException("Failed to parse command: " + command); //$NON-NLS-1$
+	        }
+	        final String property = command.substring(offset+2, end);
+	        command = command.substring(0, offset) + getDbDriver().getDbProperty(property) + command.substring(end+1);
+	    }
+	}
+
+	/**
+	 * Runs a single SQL command.
+	 */
+	protected void sql(Connection pConnection, String pCommand) throws SQLException, JAXRException {
+		final String mName = "sql"; //$NON-NLS-1$
+		if (Strings.isTrimmedEmpty(pCommand)) {
+			return;
+		}
+		final String command = replaceProperties(pCommand);
+		final int offset = command.lastIndexOf(';');
+		final String cmd = command.substring(0, offset);
+		log.debug(mName, cmd);
+		PreparedStatement stmt = null;
+		try {
+			stmt = pConnection.prepareStatement(cmd);
+			stmt.executeUpdate();
+			stmt.close();
+			stmt = null;
+		} catch (SQLException e) {
+            // Ignore "Table does not exist" messages in DROP TABLE statements.
+		    if (RegistryServiceImpl.getDbDriver(connection.getRegistryService()).isUnknownTableError(e)) {
+		        return;
+		    }
+            throw e;
+		} finally {
+			if (stmt != null) { try { stmt.close(); } catch (Throwable t) { /* Ignore me */ } }
+		}
+	}
+
+	/**
+	 * Updates the database by applying a schema update.
+	 */
+	protected void initialize(Connection pConnection, BufferedReader pReader)
+	        throws IOException, SQLException, JAXRException {
+		final StringBuilder sb = new StringBuilder();
+		for (;;) {
+			final String s = pReader.readLine();
+			if (s == null) {
+				sql(pConnection, sb.toString());
+				return;
+			}
+			sb.append(s);
+			sb.append('\n');
+			if (endsWithSemicolon(sb)) {
+				sql(pConnection, sb.toString());
+				sb.setLength(0);
+			}
+		}
+	}
+
+	/**
+	 * Updates the database by applying a schema update.
+	 */
+	protected void initialize(SchemaUpdater pSchemaUpdater, URL pSchemaFile) throws JAXRException {
+		Connection conn = connection.getConnection();
+		InputStream stream = null;
+		Reader reader = null;
+		BufferedReader bReader = null;
+		try {
+			conn.setAutoCommit(false);
+			stream = pSchemaFile.openStream();
+			reader = new InputStreamReader(stream, "UTF-8"); //$NON-NLS-1$
+			bReader = new BufferedReader(reader);
+			if (pSchemaUpdater != null) {
+				pSchemaUpdater.beforeUpdate(conn, connection.getRegistryService());
+			}
+			initialize(conn, bReader);
+			if (pSchemaUpdater != null) {
+				pSchemaUpdater.afterUpdate(conn, connection.getRegistryService());
+			}
+			bReader.close();
+			bReader = null;
+			reader.close();
+			reader = null;
+			stream.close();
+			stream = null;
+			conn.commit();
+			conn = null;
+		} catch (IOException e) {
+			throw new JAXRException(e);
+		} catch (SQLException e) {
+			throw new JAXRException(e);
+		} finally {
+			if (bReader != null) { try { bReader.close(); } catch (Throwable t) { /* Ignore me */ } }
+			if (reader != null) { try { reader.close(); } catch (Throwable t) { /* Ignore me */ } }
+			if (stream != null) { try { stream.close(); } catch (Throwable t) { /* Ignore me */ } }
+			if (conn != null) { try { conn.rollback(); } catch (Throwable t) { /* Ignore me */ } }
+		}
+	}
+
+	private String getSchemaUpdaterClassName(int pNum) {
+		final String className = getClass().getName();
+		int offset = className.lastIndexOf('.');
+		if (offset == -1) {
+			throw new IllegalStateException("Failed to parse package name: " + className); //$NON-NLS-1$
+		}
+		return className.substring(0, offset) + ".SchemaUpdater" + pNum; //$NON-NLS-1$
+	}
+
+	private SchemaUpdater getSchemaUpdater(int pNum) throws JAXRException {
+		final Class<?> cl;
+		try {
+			cl = Class.forName(getSchemaUpdaterClassName(pNum+1));
+		} catch (ClassNotFoundException e) {
+			return null;
+		}
+		try {
+			return (SchemaUpdater) cl.newInstance();
+		} catch (InstantiationException e) {
+			throw new JAXRException(e);
+		} catch (IllegalAccessException e) {
+			throw new JAXRException(e);
+		}
+	}
+
+	/**
+	 * Initializes the database schema.
+	 */
+	public void initialize() throws JAXRException {
+		int schemaVersion = getDbDriver().getSchemaVersion();
+		for (int i = schemaVersion;  ;  i++) {
+			final URL url = getClass().getResource("schema-update." + (i+1) + ".sql"); //$NON-NLS-1$ //$NON-NLS-2$
+			if (url == null) {
+				break;
+			}
+			initialize(getSchemaUpdater(i), url);
+		}
+	}
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/SchemaUpdater.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/SchemaUpdater.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/SchemaUpdater.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/SchemaUpdater.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.schema;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.RegistryService;
+
+
+/**
+ * Interface of a schema updater. A schema updater is a an object, which
+ * is invoked before and/or after schema updates.
+ */
+public interface SchemaUpdater {
+	/**
+	 * Called before a schema update is applied.
+	 * @param pConnection The database connection to use for the schema
+	 *   update. {@link Connection#setAutoCommit(boolean) AutoCommit} has been turned off
+	 *   for the connection.
+	 */
+	void beforeUpdate(Connection pConnection, RegistryService pRegistryService) throws JAXRException, SQLException, IOException;
+
+	/**
+	 * Called after a schema update has been applied.
+	 * @param pConnection The database connection to use for the schema
+	 *   update. {@link Connection#setAutoCommit(boolean) AutoCommit} has been turned off
+	 *   for the connection.
+	 */
+	void afterUpdate(Connection pConnection, RegistryService pRegistryService) throws JAXRException, SQLException, IOException;
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/SchemaUpdater1.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/SchemaUpdater1.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/SchemaUpdater1.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/SchemaUpdater1.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.schema;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import javax.xml.registry.BusinessLifeCycleManager;
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.RegistryService;
+import javax.xml.registry.infomodel.ClassificationScheme;
+import javax.xml.registry.infomodel.InternationalString;
+
+
+/**
+ * This schema updater creates the default classification schemes
+ * and association types.
+ */
+public class SchemaUpdater1 implements SchemaUpdater {
+	@Override
+	public void beforeUpdate(Connection pConnection, RegistryService pRegistryService) throws JAXRException, SQLException, IOException {
+		// Nothing to do, the schema is still to be created.
+	}
+
+	@Override
+	public void afterUpdate(Connection pConnection, RegistryService pRegistryService) throws JAXRException, SQLException, IOException {
+		final List<ClassificationScheme> clSchemes = new ArrayList<ClassificationScheme>();
+		pRegistryService.getBusinessLifeCycleManager().saveClassificationSchemes(clSchemes);
+	}
+
+	/**
+	 * Creates an international string with the given value for the default locale and the
+	 * US locale.
+	 */
+	protected InternationalString createInternationalString(RegistryService pRegistryService,
+			String pValue) throws JAXRException {
+		final BusinessLifeCycleManager blcm = pRegistryService.getBusinessLifeCycleManager();
+		final InternationalString is = blcm.createInternationalString(pValue);
+		is.addLocalizedString(blcm.createLocalizedString(Locale.ENGLISH, pValue));
+		if (!Locale.getDefault().equals(Locale.ENGLISH)) {
+			is.addLocalizedString(blcm.createLocalizedString(Locale.getDefault(), pValue));
+		}
+		return is;
+	}
+
+	/**
+	 * Creates a new classification scheme with the given name and description.
+	 */
+	protected ClassificationScheme createClassificationScheme(RegistryService pRegistryService,
+			String pName, String pDescription) throws JAXRException {
+		final InternationalString name = createInternationalString(pRegistryService, pName);
+		final InternationalString descr = createInternationalString(pRegistryService, pDescription);
+		return pRegistryService.getBusinessLifeCycleManager().createClassificationScheme(name, descr);
+	}
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/schema-update.1.sql
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/schema-update.1.sql?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/schema-update.1.sql (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/schema/schema-update.1.sql Sun Jul 27 14:13:00 2008
@@ -0,0 +1,237 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you 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.
+--
+
+DROP TABLE DbInfo;
+CREATE TABLE DbInfo (
+    version INT NOT NULL
+);
+
+
+DROP TABLE RegistryObjects;
+CREATE TABLE RegistryObjects (
+    roKey VARCHAR(32) NOT NULL PRIMARY KEY,
+    roOwner VARCHAR(32),
+    pos INT,
+    roType INT NOT NULL,
+    CONSTRAINT FK_RegistryObjects_Owner FOREIGN KEY (roOwner) REFERENCES RegistryObjects ON DELETE CASCADE
+);
+
+DROP TABLE LocalizedStrings;
+CREATE TABLE LocalizedStrings (
+    roKey VARCHAR(32) NOT NULL,
+    lsType INT NOT NULL,
+    locale VARCHAR(32) NOT NULL,
+    charset VARCHAR(32) NOT NULL,
+    val ${CLOB} NOT NULL,
+    CONSTRAINT FK_LocalizedStrings_RO FOREIGN KEY (roKey) REFERENCES RegistryObjects ON DELETE CASCADE
+);
+CREATE INDEX LocalizedStrings_roKey_locale ON LocalizedStrings (roKey, locale);
+
+DROP TABLE RegistryEntries;
+CREATE TABLE RegistryEntries (
+    roKey VARCHAR(32) NOT NULL PRIMARY KEY,
+    expiration TIMESTAMP,
+    status INT NOT NULL,
+    stability INT NOT NULL,
+    majorVersion INT NOT NULL,
+    minorVersion INT NOT NULL,
+    userVersion VARCHAR(255),
+    CONSTRAINT FK_RegistryEntries_RO FOREIGN KEY (roKey) REFERENCES RegistryObjects ON DELETE CASCADE
+);
+
+DROP TABLE RegistryObjectSlots;
+CREATE TABLE RegistryObjectSlots (
+    id BIGINT NOT NULL PRIMARY KEY,
+    roKey VARCHAR(32) NOT NULL,
+    name ${CLOB} NOT NULL,
+    slotType ${CLOB},
+    CONSTRAINT FK_RegistryObjectSlots_RO FOREIGN KEY (roKey) REFERENCES RegistryObjects ON DELETE CASCADE
+);
+
+DROP TABLE RegistryObjectSlotValues;
+CREATE TABLE RegistryObjectSlotValues (
+    id BIGINT NOT NULL,
+    val ${CLOB} NOT NULL,
+    CONSTRAINT FK_RegistryObjectSlotValues_Slot FOREIGN KEY (id) REFERENCES RegistryObjectSlots ON DELETE CASCADE
+);
+
+DROP TABLE Ids;
+CREATE TABLE Ids (
+    name VARCHAR(32) NOT NULL PRIMARY KEY,
+    nextValue BIGINT NOT NULL
+);
+
+DROP TABLE Concepts;
+CREATE TABLE Concepts (
+    roKey VARCHAR(32) NOT NULL PRIMARY KEY,
+    value ${CLOB},
+    CONSTRAINT FK_Concepts_RO FOREIGN KEY (roKey) REFERENCES RegistryObjects ON DELETE CASCADE
+);
+
+DROP TABLE Associations;
+CREATE TABLE Associations (
+    roKey VARCHAR(32) NOT NULL PRIMARY KEY,
+    roKeyTarget VARCHAR(32) NOT NULL,
+    roKeyType VARCHAR(32) NOT NULL,
+    CONSTRAINT FK_Associations_RO FOREIGN KEY (roKey) REFERENCES RegistryObjects ON DELETE CASCADE,
+    CONSTRAINT FK_Associations_Target FOREIGN KEY (roKeyTarget) REFERENCES RegistryObjects ON DELETE RESTRICT
+);
+
+DROP TABLE Classifications;
+CREATE TABLE Classifications (
+    roKey VARCHAR(32) NOT NULL PRIMARY KEY,
+    roKeyConcept VARCHAR(32) NOT NULL,
+    CONSTRAINT FK_Classifications_RO FOREIGN KEY (roKey) REFERENCES RegistryObjects ON DELETE CASCADE,
+    CONSTRAINT FK_Classifications_Concept FOREIGN KEY (roKeyConcept) REFERENCES RegistryObjects ON DELETE RESTRICT
+);
+
+INSERT INTO Ids (name, nextValue) VALUES ('keys', 8000);
+INSERT INTO Ids (name, nextValue) VALUES ('Slots', 0);
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000001', null, 0, 0);
+INSERT INTO RegistryEntries (roKey, expiration, status, stability, majorVersion, minorVersion, userVersion) VALUES ('00000000000000000000000000000001', null, 0, 0, 1, 0, '1.0');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000001', 0, 'en', 'UTF-8', 'ObjectType');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000001', 1, 'en', 'UTF-8', 'The taxonomy of object types. Object types are categories below this taxonomy.');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000002', null, 0, 0);
+INSERT INTO RegistryEntries (roKey, expiration, status, stability, majorVersion, minorVersion, userVersion) VALUES ('00000000000000000000000000000002', null, 0, 0, 1, 0, '1.0');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000002', 0, 'en', 'UTF-8', 'AssociationType');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000002', 1, 'en', 'UTF-8', 'The taxonomy of association types. Association types are categories below this taxonomy.');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000003', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000003', 'Association');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000003', 0, 'en', 'UTF-8', 'Association');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000004', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000004', 'AuditableEvent');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000004', 0, 'en', 'UTF-8', 'AuditableEvent');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000005', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000005', 'Classification');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000005', 0, 'en', 'UTF-8', 'Classification');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000006', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000006', 'ExternalIdentifier');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000006', 0, 'en', 'UTF-8', 'ExternalIdentifier');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000007', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000007', 'ExternalLink');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000007', 0, 'en', 'UTF-8', 'ExternalLink');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000008', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000008', 'Package');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000008', 0, 'en', 'UTF-8', 'Package');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000009', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000009', 'RegistryEntry');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000009', 0, 'en', 'UTF-8', 'RegistryEntry');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000010', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000010', 'Service');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000010', 0, 'en', 'UTF-8', 'Service');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000011', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000011', 'Taxonomy');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000011', 0, 'en', 'UTF-8', 'Taxonomy');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000012', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000012', 'User');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000012', 0, 'en', 'UTF-8', 'User');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000013', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000013', 'WSDL');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000013', 0, 'en', 'UTF-8', 'WSDL');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000014', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000014', 'WSPolicy');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000014', 0, 'en', 'UTF-8', 'WSPolicy');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000015', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000015', 'Organization');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000015', 0, 'en', 'UTF-8', 'Organization');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000016', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000016', 'Category');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000016', 0, 'en', 'UTF-8', 'Category');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000017', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000017', 'BelongsTo');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000017', 0, 'en', 'UTF-8', 'BelongsTo');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000018', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000018', 'Contains');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000018', 0, 'en', 'UTF-8', 'Contains');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000019', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000019', 'EquivalentTo');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000019', 0, 'en', 'UTF-8', 'EquivalentTo');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000020', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000020', 'Extends');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000020', 0, 'en', 'UTF-8', 'Extends');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000021', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000021', 'HasChild');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000021', 0, 'en', 'UTF-8', 'HasChild');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000022', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000022', 'HasParent');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000022', 0, 'en', 'UTF-8', 'HasParent');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000023', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000023', 'Implements');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000023', 0, 'en', 'UTF-8', 'Implements');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000024', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000024', 'InstanceOf');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000024', 0, 'en', 'UTF-8', 'InstanceOf');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000025', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000025', 'IsCompositionOf');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000025', 0, 'en', 'UTF-8', 'IsCompositionOf');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000026', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000026', 'Replaces');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000026', 0, 'en', 'UTF-8', 'Replaces');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000027', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000027', 'RelatedTo');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000027', 0, 'en', 'UTF-8', 'RelatedTo');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000028', '00000000000000000000000000000002', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000028', 'Supersedes');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000028', 0, 'en', 'UTF-8', 'Supersedes');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000029', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000029', 'ServiceBinding');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000029', 0, 'en', 'UTF-8', 'ServiceBinding');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000030', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000030', 'SpecificationLink');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000030', 0, 'en', 'UTF-8', 'SpecificationLink');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000031', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000031', 'RegistryPackage');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000031', 0, 'en', 'UTF-8', 'RegistryPackage');
+
+INSERT INTO RegistryObjects (roKey, roOwner, pos, roType) VALUES ('00000000000000000000000000000032', '00000000000000000000000000000001', 0, 1);
+INSERT INTO Concepts (roKey, value) VALUES ('00000000000000000000000000000032', 'ExtrinsicObject');
+INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES ('00000000000000000000000000000032', 0, 'en', 'UTF-8', 'ExtrinsicObject');
+
+INSERT INTO DbInfo (version) VALUES (1);

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AbstractDbDriver.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AbstractDbDriver.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AbstractDbDriver.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AbstractDbDriver.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,460 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.sql;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.RegistryService;
+import javax.xml.registry.infomodel.Association;
+import javax.xml.registry.infomodel.Classification;
+import javax.xml.registry.infomodel.Concept;
+import javax.xml.registry.infomodel.InternationalString;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.LocalizedString;
+import javax.xml.registry.infomodel.RegistryEntry;
+import javax.xml.registry.infomodel.RegistryObject;
+import javax.xml.registry.infomodel.Slot;
+
+import org.apache.labs.jaxmas.registry.accessor.AssociationAccessor;
+import org.apache.labs.jaxmas.registry.accessor.ClassificationAccessor;
+import org.apache.labs.jaxmas.registry.infomodel.AssociationImpl;
+import org.apache.labs.jaxmas.registry.infomodel.ClassificationImpl;
+import org.apache.labs.jaxmas.registry.infomodel.ConceptImpl;
+import org.apache.labs.jaxmas.registry.infomodel.InternationalStringController;
+import org.apache.labs.jaxmas.registry.infomodel.InternationalStringImpl;
+import org.apache.labs.jaxmas.registry.infomodel.LocalizedStringImpl;
+import org.apache.labs.jaxmas.registry.infomodel.NLSStrings;
+import org.apache.labs.jaxmas.registry.infomodel.OwnedRegistryObject;
+import org.apache.labs.jaxmas.registry.infomodel.ROState;
+import org.apache.labs.jaxmas.registry.infomodel.RegistryEntryImpl;
+import org.apache.labs.jaxmas.registry.infomodel.RegistryObjectImpl;
+import org.apache.labs.jaxmas.registry.infomodel.RegistryServiceImpl;
+import org.apache.labs.jaxmas.registry.infomodel.SlotImpl;
+import org.apache.labs.jaxmas.registry.util.Locales;
+
+
+/**
+ * Default implementation of {@link DbDriver}.
+ */
+public abstract class AbstractDbDriver implements DbDriver {
+    private final RegistryService registryService;
+
+	/**
+	 * Creates a new instance with the given registry service.
+	 */
+	protected AbstractDbDriver(RegistryService pRegistryService) {
+		registryService = pRegistryService;
+	}
+
+	/**
+	 * Returns the drivers registry service.
+	 */
+	protected RegistryService getRegistryService() {
+		return registryService;
+	}
+
+	/**
+	 * Called to perform the given prepared statement with the given parameters.
+	 */
+	protected void run(String pStmt, Object... pParams) throws JAXRException {
+		Sql.run(getRegistryService(), pStmt, pParams);
+	}
+
+	/**
+	 * Called to run the given {@link ConnUser}.
+	 */
+	protected void run(ConnUser<?> pConnUser) throws JAXRException {
+		pConnUser.run(getRegistryService());
+	}
+
+	@Override
+	public long newId(String pName) throws JAXRException {
+		run("UPDATE ids SET nextValue = nextValue + 1 WHERE name = ?", pName); //$NON-NLS-1$
+		final QueryUser<Long> query = new QueryUser<Long>("SELECT nextValue FROM ids WHERE name = ?", pName){ //$NON-NLS-1$
+			@Override
+			protected void action(ResultSet pResultSet) throws JAXRException, SQLException {
+				boolean hasNext = pResultSet.next();
+				assert(hasNext);
+				final long l = pResultSet.getLong(1);
+				assert(!pResultSet.wasNull());
+				hasNext = pResultSet.next();
+				assert(!hasNext);
+				setResult(new Long(l));
+				if (pResultSet.next()) {
+					throw new JAXRException("Unexpected result row"); //$NON-NLS-1$
+				}
+			}
+			@Override
+			protected void action(Connection pConnection) throws JAXRException, SQLException {
+				super.action(pConnection);
+			}
+		};
+		query.run(getRegistryService());
+		return query.getResult().longValue();
+	}
+
+	@Override
+	public void deleteSlots(RegistryObject pRegistryObject) throws JAXRException {
+	    // No need to delete anything, because the slots are deleted by ON DELETE CASCASE.
+	}
+
+	private void saveSlots(final RegistryObject pRegistryObject) throws JAXRException {
+	    new ObjStmtUser("DELETE FROM RegistryObjectSlots WHERE roKey=?", pRegistryObject.getKey()){ //$NON-NLS-1$
+            @Override
+            protected void action(PreparedStatement pStatement) throws JAXRException, SQLException {
+                pStatement.executeUpdate();
+                final Collection<?> slots = pRegistryObject.getSlots();
+                if (slots != null  &&  slots.size() > 0) {
+                    final String q = "INSERT INTO RegistryObjectSlots (roKey, id, name, slotType) VALUES (?, ?, ?, ?)"; //$NON-NLS-1$
+                    final String q2 = "INSERT INTO RegistryObjectSlotValues (id, val) VALUES (?, ?)"; //$NON-NLS-1$
+                    PreparedStatement stmt = pStatement.getConnection().prepareStatement(q);
+                    PreparedStatement stmt2 = null;
+                    try {
+                        stmt.setString(1, pRegistryObject.getKey().getId());
+                        for (Object o : slots) {
+                            final Slot slot = (Slot) o;
+                            final long id = newId("Slots"); //$NON-NLS-1$
+                            stmt.setLong(2, id);
+                            stmt.setString(3, slot.getName());
+                            stmt.setString(4, slot.getSlotType());
+                            stmt.executeUpdate();
+                            for (Object v : slot.getValues()) {
+                                if (stmt2 == null) {
+                                    stmt2 = pStatement.getConnection().prepareStatement(q2);
+                                }
+                                stmt2.setLong(1, id);
+                                stmt2.setString(2, v == null ? null : v.toString());
+                                stmt2.executeUpdate();
+                            }
+                        }
+                        if (stmt2 != null) {
+                            stmt2.close();
+                            stmt2 = null;
+                        }
+                        stmt.close();
+                        stmt = null;
+                    } finally {
+                        if (stmt2 != null) { try { stmt2.close(); } catch (Throwable t) { /* Ignore me */ } }
+                        if (stmt != null) { try { stmt.close(); } catch (Throwable t) { /* Ignore me */ } }
+                    }
+                }
+            }
+	    }.run(getRegistryService());
+	}
+	
+	@SuppressWarnings("unchecked")
+    private static Collection<String> asStringCollection(Collection<?> pCollection) {
+	    return (Collection<String>) pCollection;
+	}
+
+	@Override
+	public Map<String, Slot> getSlots(RegistryObject pRegistryObject) throws JAXRException {
+	    final Map<Long,Slot> slots = new HashMap<Long,Slot>();
+
+	    final String q1 = "SELECT id, name, slotType FROM RegistryObjectSlots WHERE roKey=?"; //$NON-NLS-1$
+		new ObjQueryUser(q1, pRegistryObject.getKey()){
+			@Override
+			protected void action(ResultSet pResultSet) throws JAXRException, SQLException {
+			    while (pResultSet.next()) {
+			        final Long id = new Long(pResultSet.getLong(1));
+			        assert(!pResultSet.wasNull());
+			        Slot slot = slots.get(id);
+			        if (slot == null) {
+			            slot = new SlotImpl();
+			            slots.put(id, slot); 
+			            slot.setName(pResultSet.getString(2));
+			            assert(slot.getName() != null);
+			            slot.setSlotType(pResultSet.getString(3));
+			            slot.setValues(new ArrayList<String>());
+			        }
+			    }
+			}
+		}.run(getRegistryService());
+
+		final String q2 = "SELECT ros.id, rosv.val FROM RegistryObjectSlots ros JOIN RegistryObjectSlotValues rosv ON ros.id=rosv.id WHERE ros.roKey=?"; //$NON-NLS-1$
+		new ObjQueryUser(q2, pRegistryObject.getKey()) {
+            @Override
+            protected void action(ResultSet pResultSet) throws JAXRException, SQLException {
+                while (pResultSet.next()) {
+                    final Long id = new Long(pResultSet.getLong(1));
+                    assert(!pResultSet.wasNull());
+                    final Slot slot = slots.get(id);
+                    assert(slot != null);
+                    asStringCollection(slot.getValues()).add(pResultSet.getString(2));
+                }
+            }
+		}.run(getRegistryService());
+
+		final Map<String,Slot> result = new HashMap<String,Slot>();
+		for (Slot slot : slots.values()) {
+		    result.put(slot.getName(), slot);
+		}
+		return result;
+	}
+
+	public void deleteInternationalString(Key pKey, InternationalStringImpl.Type pType) throws JAXRException {
+		run("DELETE FROM LocalizedStrings WHERE roKey=? AND lsType=?", pKey, pType); //$NON-NLS-1$
+	}
+
+	public void updateInternationalString(Key pKey, InternationalStringImpl.Type pType, final InternationalString pValue) throws JAXRException {
+	    deleteInternationalString(pKey, pType);
+        insertInternationalString(pKey, pType, pValue);
+	}
+
+	public void insertInternationalString(final Key pKey, final InternationalStringImpl.Type pType,
+	        final InternationalString pValue) throws JAXRException {
+	    if (pValue != null) {
+	        new ObjStmtUser("INSERT INTO LocalizedStrings (roKey, lsType, locale, charset, val) VALUES (?, ?, ?, ?, ?)"){ //$NON-NLS-1$
+	            @Override
+	            protected void action(PreparedStatement pStatement) throws JAXRException, SQLException {
+	                pStatement.setString(1, pKey.getId());
+	                pStatement.setInt(2, pType.ordinal());
+	                for (Object o : pValue.getLocalizedStrings()) {
+	                    LocalizedString ls = (LocalizedString) o;
+	                    pStatement.setString(3, ls.getLocale().toString());
+	                    pStatement.setString(4, ls.getCharsetName());
+	                    pStatement.setString(5, ls.getValue());
+	                    pStatement.executeUpdate();
+	                }
+                }
+	        }.run(getRegistryService());
+	    }
+    }
+
+	@SuppressWarnings("unchecked")
+    private static final Collection<Classification> asClassificationCollection(Collection<?> pCollection) {
+	    return (Collection<Classification>) pCollection;
+	}
+
+	@SuppressWarnings("unchecked")
+	private static final Collection<Association> asAssociationCollection(Collection<?> pCollection) {
+	    return (Collection<Association>) pCollection;
+    }
+
+	@Override
+	public void insert(RegistryObject pObject, int pRegistryObjectType)
+			throws JAXRException {
+		final RegistryObjectImpl<?> ro = (RegistryObjectImpl<?>) pObject;
+		assert(ro.getState() == ROState.created);
+		final Key key = pObject.getKey();
+		final Key owner;
+		final Integer pos;
+		if (ro instanceof OwnedRegistryObject) {
+		    final OwnedRegistryObject<?> oro = (OwnedRegistryObject<?>) ro;
+		    final RegistryObject roOwner = oro.getOwner();
+		    owner = roOwner == null ? null : roOwner.getKey();
+		    pos = Integer.valueOf(oro.getPosition());
+		} else {
+		    owner = null;
+		    pos = null;
+		}
+		final String s = "INSERT INTO RegistryObjects (roKey, roType, pos, roOwner) VALUES (?, ?, ?, ?)"; //$NON-NLS-1$
+		run(s, key, Integer.valueOf(pRegistryObjectType), pos, owner);
+
+		final InternationalStringController name = ro.getNameController();
+        name.save();
+        final InternationalStringController description = ro.getDescriptionController();
+        description.save();
+
+		if (pObject instanceof RegistryEntry) {
+			RegistryEntryImpl<?> re = (RegistryEntryImpl<?>) pObject;
+			run("INSERT INTO RegistryEntries (roKey, expiration, status, stability, majorVersion, minorVersion, userVersion) VALUES (?, ?, ?, ?, ?, ?, ?)", //$NON-NLS-1$
+					key, re.getExpiration(), new Integer(re.getStatus()), new Integer(re.getStability()),
+					new Integer(re.getMajorVersion()), new Integer(re.getMinorVersion()),
+					re.getUserVersion());
+		}
+
+		if (pObject instanceof Concept) {
+			final ConceptImpl concept = (ConceptImpl) pObject;
+			final String value = concept.getValue();
+			if (value == null) {
+				throw new JAXRException(RegistryServiceImpl.getNLSStrings(getRegistryService()).format(NLSStrings.CONCEPT_VALUE_MISSING));
+			}
+			run("INSERT INTO Concepts (roKey, value) VALUES (?, ?)", //$NON-NLS-1$
+			        concept.getKey(), value);
+		}
+
+		if (pObject instanceof Classification) {
+		    final ClassificationImpl cl = (ClassificationImpl) pObject;
+            final Concept concept = cl.getConcept();
+            assert(concept != null);
+            run("INSERT INTO Classifications (roKey, roKeyConcept) VALUES (?, ?)", //$NON-NLS-1$
+                    cl.getKey(), concept.getKey());
+		}
+
+		if (pObject instanceof Association) {
+		    final AssociationImpl assoc = (AssociationImpl) pObject;
+		    final Concept assocType = assoc.getAssociationType();
+		    assert(assocType != null);
+		    final RegistryObject target = assoc.getTargetObject();
+		    assert(target != null);
+		    run("INSERT INTO Associations (roKey, roKeyType, roKeyTarget) VALUES (?, ?, ?)", //$NON-NLS-1$
+		            assoc.getKey(), assocType.getKey(), target.getKey());
+		}
+		
+		for (Classification cl : asClassificationCollection(ro.getClassifications())) {
+		    ((ClassificationImpl) cl).getROLoader().save(getRegistryService(), cl);
+		}
+
+		for (Association assoc : asAssociationCollection(ro.getAssociations())) {
+            ((AssociationImpl) assoc).getROLoader().save(getRegistryService(), assoc);
+        }
+	}
+
+	@Override
+	public void update(RegistryObject pObject) throws JAXRException {
+		final RegistryObjectImpl<?> ro = (RegistryObjectImpl<?>) pObject;
+		final String key = pObject.getKey().getId();
+
+		final InternationalStringController name = ro.getNameController();
+		name.save();
+		final InternationalStringController description = ro.getDescriptionController();
+		description.save();
+
+		this.saveSlots(pObject);
+		
+		if (pObject instanceof RegistryEntry) {
+			RegistryEntry re = (RegistryEntry) pObject;
+			run("UPDATE RegistryEntries SET expiration=?, status=?, stability=?, majorVersion=?, minorVersion=?, userVersion=? WHERE roKey=?", //$NON-NLS-1$
+					re.getExpiration(), new Integer(re.getStatus()), new Integer(re.getStability()),
+					new Integer(re.getMajorVersion()), new Integer(re.getMinorVersion()),
+					re.getUserVersion(), key);
+		}
+
+		if (pObject instanceof Concept) {
+		    final ConceptImpl concept = (ConceptImpl) pObject;
+		    switch (concept.getState()) {
+		        case created:
+		            throw new IllegalStateException("This object must be inserted, not updated."); //$NON-NLS-1$
+		        case loaded:
+	                final String value = concept.getValue();
+	                if (value == null) {
+	                    throw new JAXRException(RegistryServiceImpl.getNLSStrings(getRegistryService()).format(NLSStrings.CONCEPT_VALUE_MISSING));
+	                }
+	                run("UPDATE Concepts SET value=? WHERE roKey=?", //$NON-NLS-1$
+	                        value, concept.getKey());
+	                break;
+		        case referenced:
+		            // Nothing to do
+		            break;
+		        case deleted:
+		            throw new IllegalStateException("A deleted object cannot be updated."); //$NON-NLS-1$
+		    }
+		}
+
+		if (pObject instanceof Classification) {
+		    final ClassificationImpl cl = (ClassificationImpl) pObject;
+            final Concept concept = cl.getConcept();
+            assert(concept != null);
+            run("UPDATE Classifications SET roKeyConcept=? WHERE roKey=?", //$NON-NLS-1$
+                    concept.getKey(), cl.getKey());
+        }
+
+		if (pObject instanceof Association) {
+		    final AssociationImpl assoc = (AssociationImpl) pObject;
+		    final Concept assocType = assoc.getAssociationType();
+		    assert(assocType != null);
+		    final RegistryObject target = assoc.getTargetObject();
+		    assert(target != null);
+		    run("UPDATE Associations SET roKeyType=?, roKeyTarget=? WHERE roKey=?", //$NON-NLS-1$
+                    assocType.getKey(), target.getKey(), assoc.getKey());
+        }
+
+		final Collection<Key> loadedClassificationKeys = ro.getLoadedClassificationKeys();
+		if (loadedClassificationKeys != null) {
+		    final Set<Key> currentClassificationKeys = new HashSet<Key>();
+	        for (Classification cl : asClassificationCollection(ro.getClassifications())) {
+	            ClassificationAccessor.getInstance().save(getRegistryService(), cl);
+	            currentClassificationKeys.add(cl.getKey());
+	            loadedClassificationKeys.remove(cl.getKey());
+	        }
+	        ro.setLoadedClassificationKeys(currentClassificationKeys);
+	        for (Key k : loadedClassificationKeys) {
+	            deleteRegistryObject(k);
+	        }
+		}
+
+		final Collection<Key> loadedAssociationKeys = ro.getLoadedAssociationKeys();
+		if (loadedAssociationKeys != null) {
+		    final Set<Key> currentAssociationKeys = new HashSet<Key>();
+		    for (Association assoc : asAssociationCollection(ro.getAssociations())) {
+		        AssociationAccessor.getInstance().save(getRegistryService(), assoc);
+		        currentAssociationKeys.add(assoc.getKey());
+		        loadedAssociationKeys.remove(assoc.getKey());
+            }
+		    ro.setLoadedAssociationKeys(currentAssociationKeys);
+		    for (Key k : loadedAssociationKeys) {
+		        deleteRegistryObject(k);
+            }
+        }
+	} 
+
+	@Override
+	public InternationalString loadInternationalString(Key pKey, InternationalStringImpl.Type pType) throws JAXRException {
+		final InternationalString is = new InternationalStringImpl();
+		new ObjQueryUser("SELECT locale, charset, val FROM LocalizedStrings WHERE roKey=? AND lsType=?", pKey, pType) { //$NON-NLS-1$
+			@Override
+			protected void action(ResultSet pResultSet) throws JAXRException, SQLException {
+				while (pResultSet.next()) {
+					final Locale locale = Locales.getLocale(pResultSet.getString(1));
+					final String charset = pResultSet.getString(2);
+					final String val = pResultSet.getString(3);
+					final LocalizedStringImpl ls = new LocalizedStringImpl();
+					ls.setLocale(locale);
+					ls.setCharsetName(charset);
+					ls.setValue(val);
+					is.addLocalizedString(ls);
+				}
+			}
+		}.run(getRegistryService());
+		return is;
+	}
+
+    @Override
+    public void deleteRegistryObject(Key pKey) throws JAXRException {
+        Sql.run(getRegistryService(), "DELETE FROM RegistryObjects WHERE roKey=?", pKey); //$NON-NLS-1$
+    }
+
+    @Override
+    public int getSchemaVersion() throws JAXRException {
+        final String s = "SELECT version FROM DbInfo"; //$NON-NLS-1$
+        try {
+            return Sql.intQuery(getRegistryService(), s);
+        } catch (JAXRException e) {
+            Throwable t = e.getCause();
+            if (t != null  &&  t instanceof SQLException) {
+                if (isUnknownTableError((SQLException) t)) {
+                    return 0;
+                }
+            }
+            throw e;
+        }
+    }
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationSourcePredicate.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationSourcePredicate.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationSourcePredicate.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationSourcePredicate.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.sql;
+
+import javax.xml.registry.infomodel.Key;
+
+
+/**
+ * A predicate for searching associations by source.
+ */
+public class AssociationSourcePredicate extends OwnerPredicate {
+    /**
+     * Creates a new instance, which searches for associations with
+     * the given source id.
+     */
+    public AssociationSourcePredicate(Key pKey) {
+        super(pKey);
+    }
+
+    /**
+     * Creates a new instance, which searches for associations with
+     * the given source id.
+     */
+    public AssociationSourcePredicate(String pKey) {
+        super(pKey);
+    }
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationTargetPredicate.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationTargetPredicate.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationTargetPredicate.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationTargetPredicate.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.sql;
+
+import java.sql.SQLException;
+import java.util.List;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.infomodel.Key;
+
+
+/**
+ * A predicate for searching associations by target.
+ */
+public class AssociationTargetPredicate implements Predicate {
+    private final Object key;
+
+    /**
+     * Creates a new instance with the target key.
+     */
+    public AssociationTargetPredicate(Key pKey) {
+        assert(pKey != null);
+        key = pKey;
+    }
+
+    /**
+     * Creates a new instance with the target key.
+     */
+    public AssociationTargetPredicate(String pKey) {
+        assert(pKey != null);
+        key = pKey;
+    }
+
+    @Override
+    public void add(StringBuilder pBuffer, List<Object> pParameters) throws SQLException, JAXRException {
+        pBuffer.append("assoc.roKeyTarget=?"); //$NON-NLS-1$
+        pParameters.add(key);
+    }
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationTypePredicate.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationTypePredicate.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationTypePredicate.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/AssociationTypePredicate.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.sql;
+
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.List;
+
+import javax.xml.registry.JAXRException;
+
+
+/**
+ * A predicate for searching associations by target.
+ */
+public class AssociationTypePredicate implements Predicate {
+    private final Collection<?> keys;
+
+    /**
+     * Creates a new instance with the target key.
+     */
+    public AssociationTypePredicate(Collection<?> pKeys) {
+        assert(pKeys != null);
+        keys = pKeys;
+    }
+
+    @Override
+    public void add(StringBuilder pBuffer, List<Object> pParameters) throws SQLException, JAXRException {
+        if (keys.size() == 1) {
+            final Object o = keys.iterator().next();
+            pBuffer.append("assoc.roKeyType=?"); //$NON-NLS-1$
+            pParameters.add(o);
+        } else {
+            pBuffer.append("("); //$NON-NLS-1$
+            boolean first = true;
+            for (Object o : keys) {
+                if (first) {
+                    first = false;
+                } else {
+                    pBuffer.append(" OR "); //$NON-NLS-1$
+                }
+                pBuffer.append("assoc.roKeyType=?"); //$NON-NLS-1$
+                pParameters.add(o);
+            }
+            pBuffer.append(")"); //$NON-NLS-1$
+        }
+    }
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/ConnUser.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/ConnUser.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/ConnUser.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/ConnUser.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.sql;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.RegistryService;
+
+import org.apache.labs.jaxmas.registry.infomodel.RegistryServiceImpl;
+import org.apache.labs.jaxmas.registry.util.DefaultLoggerFactory;
+import org.apache.labs.jaxmas.registry.util.Logger;
+
+/**
+ * Abstract base class of an object, which performs an operation
+ * by using a database connection.
+ */
+public abstract class ConnUser<O extends Object> {
+	private static final Logger log = DefaultLoggerFactory.getInstance().newLogger(ConnUser.class);
+
+	private O result;
+
+	/**
+	 * Sets the result object.
+	 */
+	protected void setResult(O pResult) {
+		result = pResult;
+	}
+
+	/**
+	 * Returns the result object.
+	 */
+	public O getResult() {
+		return result;
+	}
+
+	/**
+	 * This method must be implemented to perform the actual operation.
+	 * It is called from within {@link #run(Connection)}.
+	 */
+	protected abstract void action(Connection pConnection) throws JAXRException, SQLException;
+	
+	/**
+	 * Called to perform the database connection.
+	 */
+	public void run(RegistryService pRegistryService) throws JAXRException {
+		run(((RegistryServiceImpl) pRegistryService).getConnection().getConnection());
+	}
+
+	/**
+	 * Logs, that the connection user is entering the method with the given name.
+	 */
+	protected void logEntering(Logger pLog, String pName) {
+		pLog.entering(pName);
+	}
+
+    /**
+     * Logs, that the connection user is leaving the method with the given name.
+     */
+	protected void logExiting(Logger pLog, String pName) {
+		pLog.exiting(pName);
+	}
+
+	/**
+     * Logs, that the connection user is leaving the method with the given name.
+     * The given result is returned.
+	 */
+	protected void logExiting(Logger pLog, String pName, String pMsg) {
+	    pLog.exiting(pName, pMsg);
+	}
+
+	/**
+	 * Returns the result with the given index as a Long.
+	 */
+	protected Long getLong(ResultSet pResultSet, int pIndex) throws SQLException {
+		long l = pResultSet.getLong(pIndex);
+		return pResultSet.wasNull() ? null : new Long(l);
+	}
+	
+	/**
+	 * Called to perform the database connection.
+	 */
+	public void run(Connection pConnection) throws JAXRException {
+		final String mName = "run"; //$NON-NLS-1$
+		logEntering(log, mName);
+		try {
+			action(pConnection);
+		} catch (SQLException e) {
+			throw new JAXRException(e);
+		}
+		final Object o = getResult();
+		if (o == null) {
+		    logExiting(log, mName);
+		} else {
+		    logExiting(log, mName, String.valueOf(o));
+		}
+	}
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/DbDriver.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/DbDriver.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/DbDriver.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/DbDriver.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,108 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.sql;
+
+import java.sql.SQLException;
+import java.util.Map;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.infomodel.InternationalString;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.RegistryObject;
+import javax.xml.registry.infomodel.Slot;
+
+import org.apache.labs.jaxmas.registry.infomodel.InternationalStringImpl;
+
+
+/**
+ * Database drivers are used to hide database specific details.
+ * The intention is to support different databases by using different
+ * drivers.
+ */
+public interface DbDriver {
+	/**
+	 * Creates a new id.
+	 */
+	long newId(String pName) throws JAXRException;
+
+	/**
+	 * Reads a registry objects slots.
+	 */
+	Map<String, Slot> getSlots(RegistryObject pRegistryObject) throws JAXRException;
+
+	/**
+	 * Returns the current schema version.
+	 */
+	int getSchemaVersion() throws JAXRException;
+
+	/**
+	 * Inserts the given object into the registry.
+	 */
+	void insert(RegistryObject pObject, int pRegistryObjectType) throws JAXRException;
+
+	/**
+	 * Updates the given object in the registry.
+	 */
+	void update(RegistryObject pObject) throws JAXRException;
+
+	/**
+	 * Loads the given {@link InternationalString} from the registry.
+	 */
+	InternationalString loadInternationalString(Key pKey, InternationalStringImpl.Type pType) throws JAXRException;
+
+	/**
+	 * Inserts the given {@link InternationalString} into the registry.
+	 */
+	void insertInternationalString(Key pKey, InternationalStringImpl.Type pType, InternationalString pString) throws JAXRException;
+
+	/**
+	 * Deletes the given {@link InternationalString} from the registry.
+	 */
+	void deleteInternationalString(Key pKey, InternationalStringImpl.Type pType) throws JAXRException;
+
+	/**
+	 * Updates the given {@link InternationalString} in the registry.
+	 */
+	void updateInternationalString(Key pKey, InternationalStringImpl.Type pType, InternationalString pString) throws JAXRException;
+
+	/**
+	 * Removes the given {@link RegistryObject} from the registry.
+	 */
+    void deleteRegistryObject(Key pKey) throws JAXRException;
+
+    /**
+     * Removes the given registry objects {@link Slot slots} from the registry.
+     */
+    void deleteSlots(RegistryObject pRegistryObject) throws JAXRException;
+
+    /**
+     * Called to shutdown the registry. This is mainly useful for unit tests.
+     */
+    void shutdown() throws JAXRException;
+
+    /**
+     * Returns, whether a DROP TABLE command failed, because the table does not exist.
+     */
+    boolean isUnknownTableError(SQLException pE);
+
+    /**
+     * Returns a database property, for example the database specific CLOB type.
+     */
+    String getDbProperty(String pProperty);
+}

Added: labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/DerbyDbDriver.java
URL: http://svn.apache.org/viewvc/labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/DerbyDbDriver.java?rev=680187&view=auto
==============================================================================
--- labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/DerbyDbDriver.java (added)
+++ labs/jaxmas/trunk/JaxMas/src/main/java/org/apache/labs/jaxmas/registry/sql/DerbyDbDriver.java Sun Jul 27 14:13:00 2008
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.labs.jaxmas.registry.sql;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.RegistryService;
+
+import org.apache.labs.jaxmas.registry.infomodel.ConnectionImpl;
+import org.apache.labs.jaxmas.registry.infomodel.RegistryServiceImpl;
+
+
+/**
+ * Implementation of {@link DbDriver} for Apache Derby.
+ */
+public class DerbyDbDriver extends AbstractDbDriver {
+	/**
+	 * Creates a new instance.
+	 */
+	public DerbyDbDriver(RegistryService pRegistryService) {
+		super(pRegistryService);
+	}
+
+	@Override
+	public void shutdown() throws JAXRException {
+	    try {
+	        final RegistryServiceImpl rs = (RegistryServiceImpl) getRegistryService();
+	        if (rs != null) {
+	            final ConnectionImpl connImpl = rs.getConnection();
+	            if (connImpl != null) {
+	                final Connection conn = connImpl.getConnection();
+	                if (conn != null) {
+	                    conn.close();
+	                }
+	            }
+	        }
+	    } catch (SQLException e) {
+	        throw new JAXRException(e);
+	    }
+	}
+
+    @Override
+    public boolean isUnknownTableError(SQLException pException) {
+        return "42Y55".equals(pException.getSQLState()); //$NON-NLS-1$
+    }
+
+    @Override
+    public String getDbProperty(String pProperty) {
+        if ("CLOB".equals(pProperty)) { //$NON-NLS-1$
+            return pProperty;
+        }
+        throw new IllegalArgumentException("Unknown property name: " + pProperty); //$NON-NLS-1$
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message